first attempt with deleting rows. deep diff algorithm needs more time in the cooker
This commit is contained in:
parent
041de66c64
commit
6d1e011621
2 changed files with 33 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { Accessor, Component, createContext, createEffect, createMemo, createRenderEffect, createSignal, createUniqueId, For, onMount, ParentComponent, Show, useContext } from "solid-js";
|
import { Accessor, Component, createContext, createEffect, createMemo, createRenderEffect, createSignal, createUniqueId, For, onMount, ParentComponent, Show, useContext } from "solid-js";
|
||||||
import { createStore, unwrap } from "solid-js/store";
|
import { createStore, produce, unwrap } from "solid-js/store";
|
||||||
import { SelectionProvider, useSelection, selectable } from "../selectable";
|
import { SelectionProvider, useSelection, selectable } from "../selectable";
|
||||||
import { debounce, deepCopy, deepDiff, Mutation } from "~/utilities";
|
import { debounce, deepCopy, deepDiff, Mutation } from "~/utilities";
|
||||||
import css from './grid.module.css';
|
import css from './grid.module.css';
|
||||||
|
@ -17,6 +17,7 @@ export interface GridContextType {
|
||||||
readonly mutations: Accessor<Mutation[]>;
|
readonly mutations: Accessor<Mutation[]>;
|
||||||
readonly selection: Accessor<SelectionItem[]>;
|
readonly selection: Accessor<SelectionItem[]>;
|
||||||
mutate(prop: string, lang: string, value: string): void;
|
mutate(prop: string, lang: string, value: string): void;
|
||||||
|
remove(props: string[]): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GridApi {
|
export interface GridApi {
|
||||||
|
@ -25,6 +26,7 @@ export interface GridApi {
|
||||||
readonly mutations: Accessor<Mutation[]>;
|
readonly mutations: Accessor<Mutation[]>;
|
||||||
selectAll(): void;
|
selectAll(): void;
|
||||||
clear(): void;
|
clear(): void;
|
||||||
|
remove(keys: string[]): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const GridContext = createContext<GridContextType>();
|
const GridContext = createContext<GridContextType>();
|
||||||
|
@ -60,6 +62,20 @@ const GridProvider: ParentComponent<{ rows: Rows }> = (props) => {
|
||||||
mutate(prop: string, lang: string, value: string) {
|
mutate(prop: string, lang: string, value: string) {
|
||||||
setState('rows', prop, lang, value);
|
setState('rows', prop, lang, value);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
remove(props: string[]) {
|
||||||
|
console.log(props);
|
||||||
|
|
||||||
|
|
||||||
|
setState('rows', produce(rows => {
|
||||||
|
for (const prop of props) {
|
||||||
|
delete rows[prop];
|
||||||
|
}
|
||||||
|
|
||||||
|
return rows;
|
||||||
|
}));
|
||||||
|
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return <GridContext.Provider value={ctx}>
|
return <GridContext.Provider value={ctx}>
|
||||||
|
@ -124,6 +140,9 @@ const Api: Component<{ api: undefined | ((api: GridApi) => any) }> = (props) =>
|
||||||
clear() {
|
clear() {
|
||||||
selectionContext.clear();
|
selectionContext.clear();
|
||||||
},
|
},
|
||||||
|
remove(props: string[]) {
|
||||||
|
gridContext.remove(props);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
|
|
|
@ -146,6 +146,10 @@ const Editor: Component<{ root: FileSystemDirectoryHandle }> = (props) => {
|
||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
console.log(mutations());
|
||||||
|
});
|
||||||
|
|
||||||
const commands = {
|
const commands = {
|
||||||
close: createCommand('close folder', async () => {
|
close: createCommand('close folder', async () => {
|
||||||
filesContext.remove('__root__');
|
filesContext.remove('__root__');
|
||||||
|
@ -183,7 +187,13 @@ const Editor: Component<{ root: FileSystemDirectoryHandle }> = (props) => {
|
||||||
api()?.clear();
|
api()?.clear();
|
||||||
}),
|
}),
|
||||||
delete: createCommand('delete selected items', () => {
|
delete: createCommand('delete selected items', () => {
|
||||||
console.log(api()?.selection())
|
const { selection, remove } = api() ?? {};
|
||||||
|
|
||||||
|
if (!selection || !remove) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
remove(Object.keys(selection()));
|
||||||
}, { key: 'delete', modifier: Modifier.None }),
|
}, { key: 'delete', modifier: Modifier.None }),
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
@ -242,6 +252,8 @@ const Editor: Component<{ root: FileSystemDirectoryHandle }> = (props) => {
|
||||||
}}>{file().name}</Context.Handle>;
|
}}>{file().name}</Context.Handle>;
|
||||||
},
|
},
|
||||||
] as const}</Tree>
|
] as const}</Tree>
|
||||||
|
|
||||||
|
<span>Total mutation: {mutations().length}</span>
|
||||||
</Sidebar>
|
</Sidebar>
|
||||||
|
|
||||||
<Tabs active={setActive} onClose={commands.closeTab}>
|
<Tabs active={setActive} onClose={commands.closeTab}>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue