mt-flowbite-react
Version:
Official React components built for Flowbite and Tailwind CSS
94 lines (93 loc) • 3.79 kB
JavaScript
'use client';
Object.defineProperty(exports, "__esModule", { value: true });
exports.DebugFab = exports.DebugObject = exports.useDebugStore = exports.DebugProvider = exports.DebugObjectService = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const dialog_1 = require("@/components/ui/dialog");
const react_1 = require("@monaco-editor/react");
const lucide_react_1 = require("lucide-react");
const react_2 = require("react");
const zustand_1 = require("zustand");
const middleware_1 = require("zustand/middleware");
exports.DebugObjectService = {
ready: false,
count: {
builtin: 0,
},
init(builtinPrompts) {
if (this.ready) {
return;
}
this.ready = true;
},
};
const createDebugStore = (initProps) => {
const DEFAULT_PROPS = {
debugData: {},
};
return (0, zustand_1.create)()((0, middleware_1.persist)((set, get) => ({
...DEFAULT_PROPS,
...initProps,
setItem(key, data) {
const state = get();
const newState = { ...state, debugData: { ...state.debugData, [key]: data } };
console.log('set debug item2', key, get(), newState);
set(newState); //报错:
},
}), {
name: 'debug-store',
version: 3,
skipHydration: true,
onRehydrateStorage(state) {
// console.log("onRehydrateStorage", state)
},
migrate(persistedState, version) {
// console.log("version", version)
// console.log("persistedState", persistedState)
return persistedState;
},
}));
};
//--------------------------------------------------------------------------
const Context = (0, react_2.createContext)(null);
function DebugProvider({ children, ...props }) {
const storeRef = (0, react_2.useRef)();
if (!storeRef.current) {
storeRef.current = createDebugStore(props);
}
return (0, jsx_runtime_1.jsx)(Context.Provider, { value: storeRef.current, children: children });
}
exports.DebugProvider = DebugProvider;
function useDebugStore(selector, equals) {
const store = (0, react_2.useContext)(Context);
if (!store)
throw new Error('Missing Post Context.Provider in the tree');
if (selector) {
// eslint-disable-next-line
return (0, zustand_1.useStore)(store, selector, equals);
}
else {
return store;
}
}
exports.useDebugStore = useDebugStore;
const DebugObject = ({ id, data }) => {
const setItem = useDebugStore((x) => x.setItem);
(0, react_2.useEffect)(() => {
console.log('[DBG]', id, data);
setItem(id, data);
}, [id, data]);
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
};
exports.DebugObject = DebugObject;
/**
* 调试浮动按钮
* @param param0
* @returns
*/
const DebugFab = () => {
const [open, setOpen] = (0, react_2.useState)(false);
const debugItems = useDebugStore((x) => x.debugData);
return ((0, jsx_runtime_1.jsxs)(dialog_1.Dialog, { onOpenChange: setOpen, open: open, children: [(0, jsx_runtime_1.jsx)(dialog_1.DialogTrigger, { asChild: true, children: (0, jsx_runtime_1.jsx)("button", { className: "z-90 fixed bottom-2 right-2 flex h-8 w-8 items-center justify-center rounded-full bg-gradient-to-br from-blue-100 to-indigo-300 text-white shadow-lg", children: (0, jsx_runtime_1.jsx)(lucide_react_1.Bug, {}) }) }), (0, jsx_runtime_1.jsxs)(dialog_1.DialogContent, { className: "dlg-content sm:max-w-2lg h-screen max-h-full p-0 pl-8", children: [(0, jsx_runtime_1.jsx)(dialog_1.DialogHeader, {}), (0, jsx_runtime_1.jsx)(react_1.Editor, { height: "90vh", defaultLanguage: "json", value: JSON.stringify(debugItems, null, 2) })] })] }));
};
exports.DebugFab = DebugFab;
;