/* Essentials YOOtheme Pro 2.2.16 build 0813.1608; ZOOlanders https://www.zoolanders.com; Copyright (C) Joolanders, SL; http://www.gnu.org/licenses/gpl.html GNU/GPL */

import { StateEffect, StateField } from '@codemirror/state';

export const setActiveWidget = StateEffect.define();
export const setDraggedWidget = StateEffect.define();
export const removeWidget = StateEffect.define();

export const widgetSelect = StateEffect.define();
export const widgetHoverIn = StateEffect.define();
export const widgetHoverOut = StateEffect.define();

export const composed = StateField.define({
    create: () => ({ sources: {}, conditions: {} }),
    update: (v) => v,
});

export const activeWidget = StateField.define({
    create: () => null,
    update(v, tr) {
        for (const e of tr.effects) {
            if (e.is(setActiveWidget)) {
                return e.value;
            }
        }

        return v;
    },
});

export const draggedWidget = StateField.define({
    create: () => null,
    update(v, tr) {
        for (const e of tr.effects) {
            if (e.is(setDraggedWidget)) {
                return e.value;
            }
        }

        return v;
    },
});
