Initial RuneStone project
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { StateEffect, StateField } from "@codemirror/state";
|
||||
|
||||
export const trackImageDrop = StateEffect.define<{ id: symbol; from: number; to: number }>();
|
||||
export const clearImageDrop = StateEffect.define<symbol>();
|
||||
export const imageDrops = StateField.define<Map<symbol, { from: number; to: number }>>({
|
||||
create: () => new Map(),
|
||||
update(value, transaction) {
|
||||
const next = new Map([...value].map(([id, range]) => [id, {
|
||||
from: transaction.changes.mapPos(range.from, 1),
|
||||
to: transaction.changes.mapPos(range.to, 1),
|
||||
}]));
|
||||
for (const effect of transaction.effects) {
|
||||
if (effect.is(trackImageDrop)) next.set(effect.value.id, effect.value);
|
||||
if (effect.is(clearImageDrop)) next.delete(effect.value);
|
||||
}
|
||||
return next;
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user