@premieroctet/next-admin
Version:
Next-Admin provides a customizable and turnkey admin dashboard for applications built with Next.js and powered by the Prisma ORM. It aims to simplify the development process by providing a turnkey admin system that can be easily integrated into your proje
220 lines (219 loc) • 13.7 kB
JavaScript
;
var __webpack_require__ = {};
(()=>{
__webpack_require__.n = (module)=>{
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
__webpack_require__.d(getter, {
a: getter
});
return getter;
};
})();
(()=>{
__webpack_require__.d = (exports1, definition)=>{
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
enumerable: true,
get: definition[key]
});
};
})();
(()=>{
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
__webpack_require__.r = (exports1)=>{
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
value: 'Module'
});
Object.defineProperty(exports1, '__esModule', {
value: true
});
};
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
default: ()=>RichText_RichTextField
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_clsx_namespaceObject = require("clsx");
var external_clsx_default = /*#__PURE__*/ __webpack_require__.n(external_clsx_namespaceObject);
const external_react_namespaceObject = require("react");
const external_slate_namespaceObject = require("slate");
const external_slate_history_namespaceObject = require("slate-history");
const external_slate_react_namespaceObject = require("slate-react");
const RichTextActions_js_namespaceObject = require("../../../assets/icons/RichTextActions.js");
const external_components_js_namespaceObject = require("./components.js");
const external_utils_js_namespaceObject = require("./utils.js");
const RichTextField = ({ schema, onChange, disabled, required, ...props })=>{
const { value } = props;
const format = schema?.format?.split("-")[1];
const deserializedValue = (0, external_utils_js_namespaceObject.deserialize)(value, format);
const editor = (0, external_react_namespaceObject.useMemo)(()=>(0, external_slate_history_namespaceObject.withHistory)((0, external_slate_react_namespaceObject.withReact)((0, external_slate_namespaceObject.createEditor)())), []);
let initialValue = deserializedValue;
const handleChange = (value)=>{
const isAstChange = editor.operations.some((op)=>"set_selection" !== op.type);
if (isAstChange) {
const serializedValue = (0, external_utils_js_namespaceObject.serialize)(value, format);
onChange?.({
target: {
value: serializedValue
}
});
}
};
const inputValue = (0, external_react_namespaceObject.useMemo)(()=>{
if (required) {
if ("html" === format && value === external_utils_js_namespaceObject.DEFAULT_HTML_VALUE) return "";
try {
if ("json" === format && value === JSON.stringify(external_utils_js_namespaceObject.DEFAULT_JSON_VALUE)) return "";
} catch {
return value;
}
}
return value ?? "";
}, [
value
]);
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_slate_react_namespaceObject.Slate, {
editor: editor,
initialValue: initialValue,
onChange: handleChange,
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
className: "relative",
children: [
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("input", {
name: props.name,
value: inputValue,
className: "absolute inset-0 -z-10 h-full w-full opacity-0",
required: required,
readOnly: true
}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_components_js_namespaceObject.EditorContainer, {
children: [
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_components_js_namespaceObject.Toolbar, {
children: [
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Button, {
format: "bold",
icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RichTextActions_js_namespaceObject.Bold, {}),
title: "Bold",
disabled: disabled
}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Button, {
format: "italic",
icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RichTextActions_js_namespaceObject.Italic, {}),
title: "Italic",
disabled: disabled
}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Button, {
format: "underline",
icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RichTextActions_js_namespaceObject.Underline, {}),
title: "Underline",
disabled: disabled
}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Button, {
format: "strikethrough",
icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RichTextActions_js_namespaceObject.Strikethrough, {}),
title: "Strikethrough",
disabled: disabled
}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Button, {
format: "code",
icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RichTextActions_js_namespaceObject.Code, {}),
title: "Code",
disabled: disabled
}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Separator, {}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Button, {
format: "blockquote",
icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RichTextActions_js_namespaceObject.Quote, {}),
title: "Blockquote",
disabled: disabled
}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Button, {
format: "bulleted-list",
icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RichTextActions_js_namespaceObject.BullettedList, {}),
title: "Bulleted list",
disabled: disabled
}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Button, {
format: "numbered-list",
icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RichTextActions_js_namespaceObject.NumberedList, {}),
title: "Numbered list",
disabled: disabled
}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Separator, {}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Button, {
format: "heading-one",
icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RichTextActions_js_namespaceObject.Heading, {
level: 1
}),
title: "Heading 1",
disabled: disabled
}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Button, {
format: "heading-two",
icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RichTextActions_js_namespaceObject.Heading, {
level: 2
}),
title: "Heading 2",
disabled: disabled
}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Button, {
format: "heading-three",
icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RichTextActions_js_namespaceObject.Heading, {
level: 3
}),
title: "Heading 3",
disabled: disabled
}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Separator, {}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Button, {
format: "left",
icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RichTextActions_js_namespaceObject.AlignLeft, {}),
title: "Align left",
disabled: disabled
}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Button, {
format: "center",
icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RichTextActions_js_namespaceObject.AlignCenter, {}),
title: "Align center",
disabled: disabled
}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Button, {
format: "right",
icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RichTextActions_js_namespaceObject.AlignRight, {}),
title: "Align right",
disabled: disabled
}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_components_js_namespaceObject.Button, {
format: "justify",
icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RichTextActions_js_namespaceObject.AlignJustify, {}),
title: "Align justify",
disabled: disabled
})
]
}),
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_slate_react_namespaceObject.Editable, {
spellCheck: true,
renderElement: external_utils_js_namespaceObject.renderElement,
renderLeaf: external_utils_js_namespaceObject.renderLeaf,
readOnly: disabled,
className: external_clsx_default()("border-nextadmin-border-default dark:border-dark-nextadmin-border-default bg-nextadmin-background-default text-nextadmin-content-inverted", "ring-nextadmin-border-default", "focus:ring-nextadmin-brand-default", "dark:focus:ring-dark-nextadmin-brand-default", "dark:ring-dark-nextadmin-border-strong", "dark:text-dark-nextadmin-content-inverted", "dark:bg-dark-nextadmin-background-subtle min-h-[150px] rounded-bl-md p-3 shadow-sm ring-1 focus:ring-2 focus-visible:outline-none", {
"cursor-not-allowed opacity-50": disabled
}, "h-[150px] overflow-y-auto", "resize-y")
})
]
})
]
})
});
};
const RichText_RichTextField = RichTextField;
exports["default"] = __webpack_exports__["default"];
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
"default"
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
Object.defineProperty(exports, '__esModule', {
value: true
});