UNPKG

onwards

Version:

<p align="center"> <img alt='magoon-face' src='https://user-images.githubusercontent.com/14088342/230068165-5e013e79-2ff8-4fb5-a1f0-fd5b13e028a9.png' width='250'/> <h1 align="center">ONWARDS</h1> <p align="center">👏 Super simple shareable portforwa

85 lines (84 loc) 3.13 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; exports.__esModule = true; exports.navDownAtom = exports.navUpAtom = exports.navLeftAtom = exports.navRightAtom = exports.useRow = exports.useSelected = exports.coordinateAtom = exports.setBoundsAtom = exports.navAtom = void 0; var jotai_1 = require("jotai"); var ORIGO = 0; var INCREMENT = 1; exports.navAtom = (0, jotai_1.atom)({ x: 0, y: 0, xBound: 0, yBound: 0 }); var interpolateCoordinate = function (_a) { var coordinate = _a.coordinate, bound = _a.bound; return coordinate > bound ? bound : coordinate; }; exports.setBoundsAtom = (0, jotai_1.atom)(null, function (get, set, _a) { var x = _a.x, y = _a.y; var current = get(exports.navAtom); var xBound = x !== undefined ? x : current.xBound; var yBound = y !== undefined ? y : current.yBound; set(exports.navAtom, { x: interpolateCoordinate({ coordinate: current.x, bound: xBound }), y: interpolateCoordinate({ coordinate: current.y, bound: yBound }), xBound: xBound, yBound: yBound }); }); exports.coordinateAtom = (0, jotai_1.atom)(function (get) { var _a = get(exports.navAtom), x = _a.x, y = _a.y; return { x: x, y: y }; }); var useSelected = function () { var _a = (0, jotai_1.useAtom)(exports.coordinateAtom)[0], currentX = _a.x, currentY = _a.y; return function (_a) { var x = _a.x, _b = _a.y, y = _b === void 0 ? 0 : _b; return x === currentX && y === currentY; }; }; exports.useSelected = useSelected; var useRow = function (_a) { var y = _a.y; var currentY = (0, jotai_1.useAtom)(exports.coordinateAtom)[0].y; return y === currentY; }; exports.useRow = useRow; exports.navRightAtom = (0, jotai_1.atom)(null, function (get, set) { var current = get(exports.navAtom); if (current.x < current.xBound) { set(exports.navAtom, __assign(__assign({}, current), { x: current.x + INCREMENT })); } }); exports.navLeftAtom = (0, jotai_1.atom)(null, function (get, set) { var current = get(exports.navAtom); if (current.x > ORIGO) { set(exports.navAtom, __assign(__assign({}, current), { x: current.x - INCREMENT })); } }); exports.navUpAtom = (0, jotai_1.atom)(null, function (get, set) { var current = get(exports.navAtom); if (current.y > ORIGO) { set(exports.navAtom, __assign(__assign({}, current), { y: current.y - INCREMENT })); } }); exports.navDownAtom = (0, jotai_1.atom)(null, function (get, set) { var current = get(exports.navAtom); if (current.y < current.yBound) { set(exports.navAtom, __assign(__assign({}, current), { y: current.y + INCREMENT })); } });