gomtm 0.0.385 → 0.0.387
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
export interface DemoChildrenProps {
|
|
3
|
+
originPropsList?: any;
|
|
4
|
+
designMode?: boolean;
|
|
5
|
+
overrideData?: any;
|
|
6
|
+
}
|
|
7
|
+
export interface DemoChildrenState extends DemoChildrenProps {
|
|
8
|
+
setOriginPropsList: (debugData: any) => void;
|
|
9
|
+
setDesignMode: (designMode: boolean) => void;
|
|
10
|
+
setOverrideData: (overrideData: any) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare const blockContext: import("react").Context<import("zustand").StoreApi<DemoChildrenState> | null>;
|
|
13
|
+
export declare const DemoChildrenProvider: (props: PropsWithChildren<DemoChildrenProps>) => import("react").JSX.Element;
|
|
14
|
+
export declare function useDemoChildrenBlock<T>(selector: (state: DemoChildrenState) => T): T;
|
|
15
|
+
export declare const BlockPage: (props: any) => import("react").JSX.Element;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
34
|
+
import { cn } from "mtxuilib/lib/utils";
|
|
35
|
+
import { Dialog, DialogContent, DialogTrigger } from "mtxuilib/ui/dialog";
|
|
36
|
+
import { MtButton } from "mtxuilib/ui/ui-mt/Button";
|
|
37
|
+
import { Children, createContext, createElement, useContext, useMemo, useRef, useState } from "react";
|
|
38
|
+
import { useHotkeys } from "react-hotkeys-hook";
|
|
39
|
+
import { createStore, useStore } from "zustand";
|
|
40
|
+
import { MtBlockRender, getComponentName } from "./blockRegister";
|
|
41
|
+
import { HOTKEY_Design_mode } from "./consts";
|
|
42
|
+
const createDemoChildrenStore = (initProps) => {
|
|
43
|
+
return createStore()((set, get) => __spreadProps(__spreadValues({}, initProps), {
|
|
44
|
+
setOriginPropsList: (debugData) => set({ originPropsList: debugData }),
|
|
45
|
+
setDesignMode: (designMode) => set({ designMode }),
|
|
46
|
+
setOverrideData: (overrideData) => set({ overrideData })
|
|
47
|
+
}));
|
|
48
|
+
};
|
|
49
|
+
const blockContext = createContext(null);
|
|
50
|
+
const DemoChildrenProvider = (props) => {
|
|
51
|
+
const _a = props, { children } = _a, etc = __objRest(_a, ["children"]);
|
|
52
|
+
const storeRef = useRef();
|
|
53
|
+
if (!storeRef.current) {
|
|
54
|
+
storeRef.current = createDemoChildrenStore(props);
|
|
55
|
+
}
|
|
56
|
+
return /* @__PURE__ */ jsxs(blockContext.Provider, { value: storeRef.current, children: [
|
|
57
|
+
/* @__PURE__ */ jsx(BlockDesignToolbar, {}),
|
|
58
|
+
children,
|
|
59
|
+
/* @__PURE__ */ jsx(BlockPageSetup, {})
|
|
60
|
+
] });
|
|
61
|
+
};
|
|
62
|
+
function useDemoChildrenBlock(selector) {
|
|
63
|
+
const store = useContext(blockContext);
|
|
64
|
+
if (!store)
|
|
65
|
+
throw new Error("useDemoChildrenBlock Missing DemoChildrenProvider in the tree");
|
|
66
|
+
return useStore(store, selector);
|
|
67
|
+
}
|
|
68
|
+
const BlockPage = (props) => {
|
|
69
|
+
const { children } = props;
|
|
70
|
+
if (!children) {
|
|
71
|
+
return /* @__PURE__ */ jsx("div", { children: "no children" });
|
|
72
|
+
}
|
|
73
|
+
return /* @__PURE__ */ jsx(DemoChildrenProvider, { children: /* @__PURE__ */ jsx(ChildrenDebugInner, { children }) });
|
|
74
|
+
};
|
|
75
|
+
const BlockPageSetup = () => {
|
|
76
|
+
const setDesignMode = useDemoChildrenBlock((x) => x.setDesignMode);
|
|
77
|
+
const designMode = useDemoChildrenBlock((x) => x.designMode);
|
|
78
|
+
useHotkeys(HOTKEY_Design_mode, () => {
|
|
79
|
+
setDesignMode(!designMode);
|
|
80
|
+
}, [setDesignMode]);
|
|
81
|
+
return null;
|
|
82
|
+
};
|
|
83
|
+
const ChildrenDebugInner = (props) => {
|
|
84
|
+
const { children } = props;
|
|
85
|
+
const originPropsList = useDemoChildrenBlock((x) => x.originPropsList);
|
|
86
|
+
const setDebugData = useDemoChildrenBlock((x) => x.setOriginPropsList);
|
|
87
|
+
const designMode = useDemoChildrenBlock((x) => x.designMode);
|
|
88
|
+
useMemo(() => {
|
|
89
|
+
let data2 = [];
|
|
90
|
+
{
|
|
91
|
+
Children.map(children, (child) => {
|
|
92
|
+
const compName = getComponentName(child.type);
|
|
93
|
+
const debugData = {
|
|
94
|
+
"blockType": compName,
|
|
95
|
+
"props": child.props
|
|
96
|
+
};
|
|
97
|
+
data2 = [...data2, debugData];
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
setDebugData(data2);
|
|
101
|
+
}, [children, setDebugData]);
|
|
102
|
+
if (!children) {
|
|
103
|
+
return /* @__PURE__ */ jsx("div", { children: "no children" });
|
|
104
|
+
}
|
|
105
|
+
return /* @__PURE__ */ jsx("div", { className: cn(
|
|
106
|
+
designMode && "bg-red-300 shadow-md outline"
|
|
107
|
+
), children: Children.map(children, (child, i) => {
|
|
108
|
+
return designMode ? /* @__PURE__ */ jsx(ChildrenEditMode, { child, i }) : /* @__PURE__ */ jsx(ChildrenOrigin, { child, i });
|
|
109
|
+
}) });
|
|
110
|
+
};
|
|
111
|
+
function ChildrenOrigin(props) {
|
|
112
|
+
const { child, i } = props;
|
|
113
|
+
const originPropsList = useDemoChildrenBlock((x) => x.originPropsList);
|
|
114
|
+
const overProps = useMemo(() => originPropsList && originPropsList[i].props, [i, originPropsList]);
|
|
115
|
+
return /* @__PURE__ */ jsx(Fragment, { children: createElement(child.type, __spreadValues(__spreadValues({}, child.props), overProps)) });
|
|
116
|
+
}
|
|
117
|
+
function ChildrenEditMode(props) {
|
|
118
|
+
var _a;
|
|
119
|
+
const { child, i } = props;
|
|
120
|
+
const [open, setOpen] = useState(false);
|
|
121
|
+
const originPropsList = useDemoChildrenBlock((x) => x.originPropsList);
|
|
122
|
+
const setOriginPropsList = useDemoChildrenBlock((x) => x.setOriginPropsList);
|
|
123
|
+
const oriProps = useMemo(() => {
|
|
124
|
+
return originPropsList[i];
|
|
125
|
+
}, [i, originPropsList]);
|
|
126
|
+
const Editor = (_a = child.type) == null ? void 0 : _a.Editor;
|
|
127
|
+
const overProps = useMemo(() => originPropsList && originPropsList[i].props, [i, originPropsList]);
|
|
128
|
+
return /* @__PURE__ */ jsxs("div", { className: " relative", children: [
|
|
129
|
+
/* @__PURE__ */ jsxs(
|
|
130
|
+
MtButton,
|
|
131
|
+
{
|
|
132
|
+
className: " absolute right-0 top-0",
|
|
133
|
+
onClick: () => {
|
|
134
|
+
setOpen(true);
|
|
135
|
+
},
|
|
136
|
+
children: [
|
|
137
|
+
"ed(",
|
|
138
|
+
i,
|
|
139
|
+
")"
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
),
|
|
143
|
+
createElement(child.type, __spreadValues(__spreadValues({}, child.props), overProps)),
|
|
144
|
+
/* @__PURE__ */ jsx(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(DialogContent, { children: [
|
|
145
|
+
"editor",
|
|
146
|
+
Editor && /* @__PURE__ */ jsx(Editor, { preProps: oriProps, setNewProps: (values) => {
|
|
147
|
+
console.log("\u8BBE\u7F6E\u65B0\u503C", values);
|
|
148
|
+
setOriginPropsList(originPropsList.map((item, j) => {
|
|
149
|
+
if (i == j) {
|
|
150
|
+
return { props: values };
|
|
151
|
+
}
|
|
152
|
+
return item;
|
|
153
|
+
}));
|
|
154
|
+
} })
|
|
155
|
+
] }) })
|
|
156
|
+
] });
|
|
157
|
+
}
|
|
158
|
+
const BlockDesignToolbar = () => {
|
|
159
|
+
const debugData = useDemoChildrenBlock((x) => x.originPropsList);
|
|
160
|
+
const designMode = useDemoChildrenBlock((x) => x.designMode);
|
|
161
|
+
const setDesignMode = useDemoChildrenBlock((x) => x.setDesignMode);
|
|
162
|
+
if (!designMode) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-1 bg-slate-600 p-2", children: [
|
|
166
|
+
/* @__PURE__ */ jsx(MtButton, { onClick: () => {
|
|
167
|
+
setDesignMode(!designMode);
|
|
168
|
+
}, children: "edit" }),
|
|
169
|
+
/* @__PURE__ */ jsxs(Dialog, { children: [
|
|
170
|
+
/* @__PURE__ */ jsx(DialogTrigger, { asChild: true, children: /* @__PURE__ */ jsx(MtButton, { children: "info" }) }),
|
|
171
|
+
/* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsx("pre", { children: JSON.stringify(debugData, null, 2) }) })
|
|
172
|
+
] }),
|
|
173
|
+
/* @__PURE__ */ jsxs(Dialog, { children: [
|
|
174
|
+
/* @__PURE__ */ jsx(DialogTrigger, { asChild: true, children: /* @__PURE__ */ jsx(MtButton, { children: "reRender" }) }),
|
|
175
|
+
/* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsx(RenderByPresistData, { data: debugData }) })
|
|
176
|
+
] })
|
|
177
|
+
] });
|
|
178
|
+
};
|
|
179
|
+
function RenderByPresistData(props) {
|
|
180
|
+
const { data } = props;
|
|
181
|
+
const items = data;
|
|
182
|
+
return /* @__PURE__ */ jsx("div", { className: "bg-yellow-100 p-2", children: items.map((item, i) => {
|
|
183
|
+
return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(MtBlockRender, { type: item.blockType, compProps: item.props }) }, i);
|
|
184
|
+
}) });
|
|
185
|
+
}
|
|
186
|
+
export {
|
|
187
|
+
BlockPage,
|
|
188
|
+
DemoChildrenProvider,
|
|
189
|
+
blockContext,
|
|
190
|
+
useDemoChildrenBlock
|
|
191
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const HOTKEY_Design_mode = "alt+d";
|