2022-03-07 13:06:11 +01:00
|
|
|
import { get, writable } from "svelte/store"
|
2022-02-11 12:55:35 +01:00
|
|
|
|
|
|
|
const createRowSelectionStore = () => {
|
2022-02-22 16:18:08 +01:00
|
|
|
const store = writable({})
|
2022-02-11 12:55:35 +01:00
|
|
|
|
2022-03-07 13:06:11 +01:00
|
|
|
function updateSelection(componentId, tableId, selectedRows) {
|
2022-02-11 12:55:35 +01:00
|
|
|
store.update(state => {
|
2024-02-13 17:44:21 +01:00
|
|
|
state[componentId] = { tableId, selectedRows }
|
2022-02-11 12:55:35 +01:00
|
|
|
return state
|
|
|
|
})
|
|
|
|
}
|
2022-02-22 16:18:08 +01:00
|
|
|
|
2022-03-08 13:58:05 +01:00
|
|
|
function getSelection(tableComponentId) {
|
2022-03-07 13:06:11 +01:00
|
|
|
const selection = get(store)
|
|
|
|
const componentId = Object.keys(selection).find(
|
2022-03-08 13:58:05 +01:00
|
|
|
componentId => componentId === tableComponentId
|
2022-03-07 13:06:11 +01:00
|
|
|
)
|
2024-04-08 17:17:22 +02:00
|
|
|
return selection[componentId]
|
2022-03-07 13:06:11 +01:00
|
|
|
}
|
|
|
|
|
2022-02-11 12:55:35 +01:00
|
|
|
return {
|
|
|
|
subscribe: store.subscribe,
|
2022-02-22 16:18:08 +01:00
|
|
|
set: store.set,
|
2022-02-11 12:55:35 +01:00
|
|
|
actions: {
|
2022-02-22 16:18:08 +01:00
|
|
|
updateSelection,
|
2022-03-07 13:06:11 +01:00
|
|
|
getSelection,
|
2022-02-11 12:55:35 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const rowSelectionStore = createRowSelectionStore()
|