mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
Typings fixes in terms and sessions
This commit is contained in:
parent
5ea676a7d5
commit
d232ec27c0
3 changed files with 41 additions and 35 deletions
24
lib/hyper.d.ts
vendored
24
lib/hyper.d.ts
vendored
|
|
@ -8,7 +8,7 @@ declare global {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ITermGroup = {
|
export type ITermGroup = {
|
||||||
uid: string | null;
|
uid: string;
|
||||||
sessionUid: string | null;
|
sessionUid: string | null;
|
||||||
parentUid: string | null;
|
parentUid: string | null;
|
||||||
direction: string | null;
|
direction: string | null;
|
||||||
|
|
@ -108,20 +108,20 @@ export type uiState = {
|
||||||
export type IUiReducer = Reducer<Immutable<uiState>>;
|
export type IUiReducer = Reducer<Immutable<uiState>>;
|
||||||
export type session = {
|
export type session = {
|
||||||
cleared: boolean;
|
cleared: boolean;
|
||||||
cols: null;
|
cols: number | null;
|
||||||
pid: null;
|
pid: number | null;
|
||||||
resizeAt: number;
|
resizeAt?: number;
|
||||||
rows: null;
|
rows: number | null;
|
||||||
search: boolean;
|
search: boolean;
|
||||||
shell: string;
|
shell: string;
|
||||||
title: string;
|
title: string;
|
||||||
uid: string;
|
uid: string;
|
||||||
url: null;
|
url: string | null;
|
||||||
splitDirection: string;
|
splitDirection?: string;
|
||||||
activeUid: string;
|
activeUid?: string;
|
||||||
};
|
};
|
||||||
export type sessionState = {
|
export type sessionState = {
|
||||||
sessions: Record<string, Partial<session>>;
|
sessions: Record<string, session>;
|
||||||
activeUid: string | null;
|
activeUid: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -144,9 +144,9 @@ export type hyperPlugin = {
|
||||||
mapTermsState: any;
|
mapTermsState: any;
|
||||||
middleware: any;
|
middleware: any;
|
||||||
onRendererWindow: any;
|
onRendererWindow: any;
|
||||||
reduceSessions: any;
|
reduceSessions: ISessionReducer;
|
||||||
reduceTermGroups: any;
|
reduceTermGroups: ITermGroupReducer;
|
||||||
reduceUI: any;
|
reduceUI: IUiReducer;
|
||||||
};
|
};
|
||||||
|
|
||||||
import rootReducer from './reducers/index';
|
import rootReducer from './reducers/index';
|
||||||
|
|
|
||||||
|
|
@ -13,15 +13,15 @@ import {
|
||||||
SESSION_SEARCH,
|
SESSION_SEARCH,
|
||||||
SESSION_SEARCH_CLOSE
|
SESSION_SEARCH_CLOSE
|
||||||
} from '../constants/sessions';
|
} from '../constants/sessions';
|
||||||
import {sessionState} from '../hyper';
|
import {sessionState, session} from '../hyper';
|
||||||
|
|
||||||
const initialState: ImmutableType<sessionState> = Immutable({
|
const initialState: ImmutableType<sessionState> = Immutable({
|
||||||
sessions: {},
|
sessions: {},
|
||||||
activeUid: null
|
activeUid: null
|
||||||
});
|
});
|
||||||
|
|
||||||
function Session(obj: Immutable.DeepPartial<sessionState['sessions']>) {
|
function Session(obj: Immutable.DeepPartial<session>) {
|
||||||
return Immutable({
|
const x: session = {
|
||||||
uid: '',
|
uid: '',
|
||||||
title: '',
|
title: '',
|
||||||
cols: null,
|
cols: null,
|
||||||
|
|
@ -31,7 +31,8 @@ function Session(obj: Immutable.DeepPartial<sessionState['sessions']>) {
|
||||||
search: false,
|
search: false,
|
||||||
shell: '',
|
shell: '',
|
||||||
pid: null
|
pid: null
|
||||||
}).merge(obj);
|
};
|
||||||
|
return Immutable(x).merge(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteSession(state: ImmutableType<sessionState>, uid: string) {
|
function deleteSession(state: ImmutableType<sessionState>, uid: string) {
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,15 @@ const initialState = Immutable<ITermState>({
|
||||||
});
|
});
|
||||||
|
|
||||||
function TermGroup(obj: Immutable.DeepPartial<ITermGroup>) {
|
function TermGroup(obj: Immutable.DeepPartial<ITermGroup>) {
|
||||||
return Immutable({
|
const x: ITermGroup = {
|
||||||
uid: null,
|
uid: '',
|
||||||
sessionUid: null,
|
sessionUid: null,
|
||||||
parentUid: null,
|
parentUid: null,
|
||||||
direction: null,
|
direction: null,
|
||||||
sizes: null,
|
sizes: null,
|
||||||
children: []
|
children: []
|
||||||
} as ITermGroup).merge(obj);
|
};
|
||||||
|
return Immutable(x).merge(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recurse upwards until we find a root term group (no parent).
|
// Recurse upwards until we find a root term group (no parent).
|
||||||
|
|
@ -40,8 +41,8 @@ const setActiveGroup = (state: ImmutableType<ITermState>, action: {uid: string})
|
||||||
}
|
}
|
||||||
|
|
||||||
const childGroup = findBySession(state, action.uid)!;
|
const childGroup = findBySession(state, action.uid)!;
|
||||||
const rootGroup = findRootGroup(state.termGroups, childGroup.uid!);
|
const rootGroup = findRootGroup(state.termGroups, childGroup.uid);
|
||||||
return state.set('activeRootGroup', rootGroup.uid).setIn(['activeSessions', rootGroup.uid as string], action.uid);
|
return state.set('activeRootGroup', rootGroup.uid).setIn(['activeSessions', rootGroup.uid], action.uid);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Reduce existing sizes to fit a new split:
|
// Reduce existing sizes to fit a new split:
|
||||||
|
|
@ -65,7 +66,7 @@ const removalRebalance = (oldSizes: ImmutableType<number[]>, index: number) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const splitGroup = (state: ImmutableType<ITermState>, action: {splitDirection: any; uid: any; activeUid: any}) => {
|
const splitGroup = (state: ImmutableType<ITermState>, action: {splitDirection: any; uid: string; activeUid: any}) => {
|
||||||
const {splitDirection, uid, activeUid} = action;
|
const {splitDirection, uid, activeUid} = action;
|
||||||
const activeGroup = findBySession(state, activeUid)!;
|
const activeGroup = findBySession(state, activeUid)!;
|
||||||
// If we're splitting in the same direction as the current active
|
// If we're splitting in the same direction as the current active
|
||||||
|
|
@ -90,7 +91,7 @@ const splitGroup = (state: ImmutableType<ITermState>, action: {splitDirection: a
|
||||||
parentUid: parentGroup.uid
|
parentUid: parentGroup.uid
|
||||||
});
|
});
|
||||||
|
|
||||||
state = state.setIn(['termGroups', newSession.uid as string], newSession);
|
state = state.setIn(['termGroups', newSession.uid], newSession);
|
||||||
if (parentGroup.sessionUid) {
|
if (parentGroup.sessionUid) {
|
||||||
const existingSession = TermGroup({
|
const existingSession = TermGroup({
|
||||||
uid: uuid.v4(),
|
uid: uuid.v4(),
|
||||||
|
|
@ -98,22 +99,22 @@ const splitGroup = (state: ImmutableType<ITermState>, action: {splitDirection: a
|
||||||
parentUid: parentGroup.uid
|
parentUid: parentGroup.uid
|
||||||
});
|
});
|
||||||
|
|
||||||
return state.setIn(['termGroups', existingSession.uid as string], existingSession).setIn(
|
return state.setIn(['termGroups', existingSession.uid], existingSession).setIn(
|
||||||
['termGroups', parentGroup.uid!],
|
['termGroups', parentGroup.uid],
|
||||||
parentGroup.merge({
|
parentGroup.merge({
|
||||||
sessionUid: '',
|
sessionUid: '',
|
||||||
direction: splitDirection,
|
direction: splitDirection,
|
||||||
children: [existingSession.uid!, newSession.uid!]
|
children: [existingSession.uid, newSession.uid]
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const {children} = parentGroup;
|
const {children} = parentGroup;
|
||||||
// Insert the new child pane right after the active one:
|
// Insert the new child pane right after the active one:
|
||||||
const index = children.indexOf(activeGroup.uid!) + 1;
|
const index = children.indexOf(activeGroup.uid) + 1;
|
||||||
const newChildren = [...children.slice(0, index).asMutable(), newSession.uid!, ...children.slice(index).asMutable()];
|
const newChildren = [...children.slice(0, index).asMutable(), newSession.uid, ...children.slice(index).asMutable()];
|
||||||
state = state.setIn(
|
state = state.setIn(
|
||||||
['termGroups', parentGroup.uid!],
|
['termGroups', parentGroup.uid],
|
||||||
parentGroup.merge({
|
parentGroup.merge({
|
||||||
direction: splitDirection,
|
direction: splitDirection,
|
||||||
children: newChildren
|
children: newChildren
|
||||||
|
|
@ -122,7 +123,7 @@ const splitGroup = (state: ImmutableType<ITermState>, action: {splitDirection: a
|
||||||
|
|
||||||
if (parentGroup.sizes) {
|
if (parentGroup.sizes) {
|
||||||
const newSizes = insertRebalance(parentGroup.sizes, index);
|
const newSizes = insertRebalance(parentGroup.sizes, index);
|
||||||
state = state.setIn(['termGroups', parentGroup.uid!, 'sizes'], newSizes);
|
state = state.setIn(['termGroups', parentGroup.uid, 'sizes'], newSizes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
|
@ -131,19 +132,23 @@ const splitGroup = (state: ImmutableType<ITermState>, action: {splitDirection: a
|
||||||
// Replace the parent by the given child in the tree,
|
// Replace the parent by the given child in the tree,
|
||||||
// used when we remove another child and we're left
|
// used when we remove another child and we're left
|
||||||
// with a one-to-one mapping between parent and child.
|
// with a one-to-one mapping between parent and child.
|
||||||
const replaceParent = (state: ImmutableType<ITermState>, parent: ImmutableType<ITermGroup>, child: {uid: any}) => {
|
const replaceParent = (
|
||||||
|
state: ImmutableType<ITermState>,
|
||||||
|
parent: ImmutableType<ITermGroup>,
|
||||||
|
child: ImmutableType<ITermGroup>
|
||||||
|
) => {
|
||||||
if (parent.parentUid) {
|
if (parent.parentUid) {
|
||||||
const parentParent = state.termGroups[parent.parentUid];
|
const parentParent = state.termGroups[parent.parentUid];
|
||||||
// If the parent we're replacing has a parent,
|
// If the parent we're replacing has a parent,
|
||||||
// we need to change the uid in its children array
|
// we need to change the uid in its children array
|
||||||
// with `child`:
|
// with `child`:
|
||||||
const newChildren = parentParent.children.map((uid: any) => (uid === parent.uid ? child.uid : uid));
|
const newChildren = parentParent.children.map((uid: string) => (uid === parent.uid ? child.uid : uid));
|
||||||
|
|
||||||
state = state.setIn(['termGroups', parentParent.uid!, 'children'], newChildren);
|
state = state.setIn(['termGroups', parentParent.uid, 'children'], newChildren);
|
||||||
} else {
|
} else {
|
||||||
// This means the given child will be
|
// This means the given child will be
|
||||||
// a root group, so we need to set it up as such:
|
// a root group, so we need to set it up as such:
|
||||||
const newSessions = state.activeSessions.without(parent.uid!).set(child.uid, state.activeSessions[parent.uid!]);
|
const newSessions = state.activeSessions.without(parent.uid).set(child.uid, state.activeSessions[parent.uid]);
|
||||||
|
|
||||||
state = state
|
state = state
|
||||||
.set('activeTermGroup', child.uid)
|
.set('activeTermGroup', child.uid)
|
||||||
|
|
@ -152,7 +157,7 @@ const replaceParent = (state: ImmutableType<ITermState>, parent: ImmutableType<I
|
||||||
}
|
}
|
||||||
|
|
||||||
return state
|
return state
|
||||||
.set('termGroups', state.termGroups.without(parent.uid!))
|
.set('termGroups', state.termGroups.without(parent.uid))
|
||||||
.setIn(['termGroups', child.uid, 'parentUid'], parent.parentUid);
|
.setIn(['termGroups', child.uid, 'parentUid'], parent.parentUid);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue