@undermuz/react-json-form
Version:
Generate JSON-based forms with react
122 lines (120 loc) • 4.73 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/flat-form/form-input/input.tsx
var input_exports = {};
__export(input_exports, {
default: () => input_default
});
module.exports = __toCommonJS(input_exports);
var import_underscore = require("underscore");
var import_types = require("../../types.js");
var import_ui = require("../../contexts/ui.js");
var import_inputWIdget = __toESM(require("../../inputs/inputWIdget.js"));
var import_context = require("../../custom-components/context.js");
var import_input_select = require("./input-select.js");
var import_jsx_runtime = require("react/jsx-runtime");
var Input = (props) => {
const {
name,
value = "",
type,
title,
settings = {},
children,
onFormsRef
} = props;
const { onChange = import_underscore.noop, onError = import_underscore.noop } = props;
const Ui = (0, import_ui.useJsonFormUi)();
const customComponents = (0, import_context.useJsonFormCustomComponents)();
try {
if (type == import_types.EnumSchemeItemType.Files) {
if (!Ui?.Controls?.FileInput) {
console.error("No Ui.Controls.FileInput provided");
return null;
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Ui.Controls.FileInput, { ...props });
}
if (type == import_types.EnumSchemeItemType.Widget) {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_inputWIdget.default,
{
name,
value,
title,
settings,
onRef: onFormsRef,
onChange,
onError,
children
}
);
}
if (type == import_types.EnumSchemeItemType.Select) {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_input_select.InputSelect, { ...props });
}
if (type === import_types.EnumSchemeItemType.Date) {
if (!Ui?.Controls?.Date) {
console.error("No Ui.Controls.Date provided");
return null;
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Ui.Controls.Date, { ...props });
}
if (type === import_types.EnumSchemeItemType.Checkbox) {
if (!Ui?.Controls?.CheckBox) {
console.error("No Ui.Controls.CheckBox provided");
return null;
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Ui.Controls.CheckBox, { ...props });
}
if (type == import_types.EnumSchemeItemType.TextBlock) {
if (!Ui?.Controls?.TextBlock) {
console.error("No Ui.Controls.TextBlock provided");
return null;
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Ui.Controls.TextBlock, { ...props });
}
if (customComponents && customComponents[type]) {
const CustomCmp = customComponents[type];
if (CustomCmp)
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CustomCmp, { ...props });
}
if (!Ui?.Controls?.Input) {
console.error("No Ui.Controls.Input provided");
return null;
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Ui.Controls.Input, { ...props });
} catch (e) {
console.error(`Error <Input {...${JSON.stringify(props)} }>:`);
console.error(e);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "alert alert-danger", children: e.message });
}
};
var input_default = Input;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});