UNPKG

tweak-tools

Version:

Tweak your React projects until awesomeness

50 lines (49 loc) 2.39 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Control = void 0; const react_1 = __importDefault(require("react")); const ControlInput_1 = require("./ControlInput"); const log_1 = require("../../utils/log"); const plugin_1 = require("../../plugin"); const Button_1 = require("../Button"); const ButtonGroup_1 = require("../ButtonGroup"); const Monitor_1 = require("../Monitor"); const hooks_1 = require("../../hooks"); const types_1 = require("../../types"); const specialComponents = { [types_1.SpecialInputs.BUTTON]: Button_1.Button, [types_1.SpecialInputs.BUTTON_GROUP]: ButtonGroup_1.ButtonGroup, [types_1.SpecialInputs.MONITOR]: Monitor_1.Monitor, }; exports.Control = react_1.default.memo(({ path }) => { const [input, { set, setSettings, disable, storeId, emitOnEditStart, emitOnEditEnd }] = (0, hooks_1.useInput)(path); if (!input) return null; const { type, label, key } = input, inputProps = __rest(input, ["type", "label", "key"]); if (type in types_1.SpecialInputs) { // @ts-expect-error const SpecialInputForType = specialComponents[type]; return react_1.default.createElement(SpecialInputForType, Object.assign({ label: label, path: path }, inputProps)); } if (!(type in plugin_1.Plugins)) { console.info(log_1.TweakErrors.UNSUPPORTED_INPUT, type, path); return null; } return ( // @ts-expect-error react_1.default.createElement(ControlInput_1.ControlInput, Object.assign({ key: storeId + path, type: type, label: label, storeId: storeId, path: path, valueKey: key, setValue: set, setSettings: setSettings, disable: disable, emitOnEditStart: emitOnEditStart, emitOnEditEnd: emitOnEditEnd }, inputProps))); });