@frontify/fondue
Version:
Design system of Frontify
37 lines (36 loc) • 1.31 kB
JavaScript
import { isHotkey as c } from "@udecode/plate-core";
import { someNode as f, getNodeEntries as u, isBlock as i } from "@udecode/slate";
import { KEY_ELEMENT_BREAK_AFTER_COLUMN as p } from "./createColumnBreakPlugin.es.js";
import { getColumnBreakCount as g } from "./utils/getColumnBreakCount.es.js";
import { setColumnBreaks as r } from "./utils/setColumnBreaks.es.js";
import { updateColumnBreaks as C } from "./utils/updateColumnBreaks.es.js";
const k = (o, n, e) => {
if (e.preventDefault(), e.stopPropagation(), !!(o != null && o.selection) && f(o, { match: (t) => !!t.breakAfterColumn }))
r(o, { value: void 0 });
else {
const t = g(o), s = Math.max(n - t - 1, 0);
if (s === 0)
return;
const a = Array.from(
u(o, {
at: o.selection,
match: (l) => i(o, l),
mode: "lowest"
})
).slice(-s);
for (const l of a)
r(o, { value: "active", at: l[1] });
}
C(o, n);
}, _ = (o, { options: { hotkey: n } }) => (e) => {
var m;
if (!e.defaultPrevented && n && c(n, e)) {
const t = o.plugins.find((a) => a.key === p), s = ((m = t == null ? void 0 : t.options) == null ? void 0 : m.columns) ?? 1;
k(o, s, e);
}
};
export {
_ as onKeyDownColumnBreak,
k as toggleColumnBreak
};
//# sourceMappingURL=onKeyDownColumnBreak.es.js.map