gomtm 0.0.384 → 0.0.386
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.
- package/dist/esm/block/ChildrenDebug.d.ts +7 -3
- package/dist/esm/block/ChildrenDebug.js +95 -29
- package/dist/esm/block/MtBlockSS.js +1 -2
- package/dist/esm/block/blockRegister.d.ts +7 -2
- package/dist/esm/block/blockRegister.js +23 -13
- package/dist/esm/block/blocks/HelloBlock.d.ts +5 -0
- package/dist/esm/block/blocks/HelloBlock.js +14 -0
- package/dist/esm/block/blocks/hello/Hello.d.ts +4 -0
- package/dist/esm/block/blocks/hello/Hello.js +11 -0
- package/dist/esm/block/blocks/hello/edit.d.ts +5 -0
- package/dist/esm/block/blocks/hello/edit.js +16 -0
- package/dist/esm/block/blocks/hello/index.d.ts +10 -0
- package/dist/esm/block/blocks/hello/index.js +29 -0
- package/dist/esm/block/blocks/hello2/index.d.ts +4 -0
- package/dist/esm/block/blocks/hello2/index.js +12 -0
- package/dist/tsconfig.type.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { PropsWithChildren } from "react";
|
|
2
2
|
export interface DemoChildrenProps {
|
|
3
|
-
|
|
3
|
+
originPropsList?: any;
|
|
4
|
+
designMode?: boolean;
|
|
5
|
+
overrideData?: any;
|
|
4
6
|
}
|
|
5
7
|
export interface DemoChildrenState extends DemoChildrenProps {
|
|
6
|
-
|
|
8
|
+
setOriginPropsList: (debugData: any) => void;
|
|
9
|
+
setDesignMode: (designMode: boolean) => void;
|
|
10
|
+
setOverrideData: (overrideData: any) => void;
|
|
7
11
|
}
|
|
8
12
|
export declare const blockContext: import("react").Context<import("zustand").StoreApi<DemoChildrenState> | null>;
|
|
9
13
|
export declare const DemoChildrenProvider: (props: PropsWithChildren<DemoChildrenProps>) => import("react").JSX.Element;
|
|
10
14
|
export declare function useDemoChildrenBlock<T>(selector: (state: DemoChildrenState) => T): T;
|
|
11
|
-
export declare const
|
|
15
|
+
export declare const BlockCanva: (props: any) => import("react").JSX.Element;
|
|
@@ -31,11 +31,17 @@ var __objRest = (source, exclude) => {
|
|
|
31
31
|
return target;
|
|
32
32
|
};
|
|
33
33
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
34
|
-
import {
|
|
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";
|
|
35
38
|
import { createStore, useStore } from "zustand";
|
|
39
|
+
import { MtBlockRender, getComponentName } from "./blockRegister";
|
|
36
40
|
const createDemoChildrenStore = (initProps) => {
|
|
37
41
|
return createStore()((set, get) => __spreadProps(__spreadValues({}, initProps), {
|
|
38
|
-
|
|
42
|
+
setOriginPropsList: (debugData) => set({ originPropsList: debugData }),
|
|
43
|
+
setDesignMode: (designMode) => set({ designMode }),
|
|
44
|
+
setOverrideData: (overrideData) => set({ overrideData })
|
|
39
45
|
}));
|
|
40
46
|
};
|
|
41
47
|
const blockContext = createContext(null);
|
|
@@ -46,8 +52,8 @@ const DemoChildrenProvider = (props) => {
|
|
|
46
52
|
storeRef.current = createDemoChildrenStore(props);
|
|
47
53
|
}
|
|
48
54
|
return /* @__PURE__ */ jsxs(blockContext.Provider, { value: storeRef.current, children: [
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
/* @__PURE__ */ jsx(BlockDesignToolbar, {}),
|
|
56
|
+
children
|
|
51
57
|
] });
|
|
52
58
|
};
|
|
53
59
|
function useDemoChildrenBlock(selector) {
|
|
@@ -56,7 +62,7 @@ function useDemoChildrenBlock(selector) {
|
|
|
56
62
|
throw new Error("useDemoChildrenBlock Missing DemoChildrenProvider in the tree");
|
|
57
63
|
return useStore(store, selector);
|
|
58
64
|
}
|
|
59
|
-
const
|
|
65
|
+
const BlockCanva = (props) => {
|
|
60
66
|
const { children } = props;
|
|
61
67
|
if (!children) {
|
|
62
68
|
return /* @__PURE__ */ jsx("div", { children: "no children" });
|
|
@@ -65,46 +71,106 @@ const ChildrenDebug = (props) => {
|
|
|
65
71
|
};
|
|
66
72
|
const ChildrenDebugInner = (props) => {
|
|
67
73
|
const { children } = props;
|
|
68
|
-
const
|
|
74
|
+
const originPropsList = useDemoChildrenBlock((x) => x.originPropsList);
|
|
75
|
+
const setDebugData = useDemoChildrenBlock((x) => x.setOriginPropsList);
|
|
76
|
+
const designMode = useDemoChildrenBlock((x) => x.designMode);
|
|
69
77
|
useMemo(() => {
|
|
78
|
+
let data2 = [];
|
|
70
79
|
{
|
|
71
80
|
Children.map(children, (child) => {
|
|
72
|
-
|
|
81
|
+
const compName = getComponentName(child.type);
|
|
73
82
|
const debugData = {
|
|
74
|
-
"
|
|
75
|
-
|
|
76
|
-
"\u5176\u4ED6\u5C5E\u6027": child.props
|
|
83
|
+
"blockType": compName,
|
|
84
|
+
"props": child.props
|
|
77
85
|
};
|
|
78
|
-
|
|
86
|
+
data2 = [...data2, debugData];
|
|
79
87
|
});
|
|
80
88
|
}
|
|
89
|
+
setDebugData(data2);
|
|
81
90
|
}, [children, setDebugData]);
|
|
82
91
|
if (!children) {
|
|
83
92
|
return /* @__PURE__ */ jsx("div", { children: "no children" });
|
|
84
93
|
}
|
|
85
|
-
return /* @__PURE__ */ jsx(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"children.type": children.type,
|
|
90
|
-
"\u5176\u4ED6\u5C5E\u6027": children.props
|
|
91
|
-
};
|
|
92
|
-
console.log(debugData);
|
|
93
|
-
return child.props.name ? createElement(child.type, __spreadValues({}, __spreadProps(__spreadValues({}, child.props), {
|
|
94
|
-
// register: methods.register,
|
|
95
|
-
key: child.props.name
|
|
96
|
-
}))) : child;
|
|
94
|
+
return /* @__PURE__ */ jsx("div", { className: cn(
|
|
95
|
+
designMode && "bg-red-300 shadow-md outline"
|
|
96
|
+
), children: Children.map(children, (child, i) => {
|
|
97
|
+
return designMode ? /* @__PURE__ */ jsx(ChildrenEditMode, { child, i }) : /* @__PURE__ */ jsx(ChildrenOrigin, { child, i });
|
|
97
98
|
}) });
|
|
98
99
|
};
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
function ChildrenOrigin(props) {
|
|
101
|
+
const { child, i } = props;
|
|
102
|
+
const originPropsList = useDemoChildrenBlock((x) => x.originPropsList);
|
|
103
|
+
const overProps = useMemo(() => originPropsList && originPropsList[i].props, [i, originPropsList]);
|
|
104
|
+
return /* @__PURE__ */ jsx(Fragment, { children: createElement(child.type, __spreadValues(__spreadValues({}, child.props), overProps)) });
|
|
105
|
+
}
|
|
106
|
+
function ChildrenEditMode(props) {
|
|
107
|
+
var _a;
|
|
108
|
+
const { child, i } = props;
|
|
109
|
+
const [open, setOpen] = useState(false);
|
|
110
|
+
const originPropsList = useDemoChildrenBlock((x) => x.originPropsList);
|
|
111
|
+
const setOriginPropsList = useDemoChildrenBlock((x) => x.setOriginPropsList);
|
|
112
|
+
const oriProps = useMemo(() => {
|
|
113
|
+
return originPropsList[i];
|
|
114
|
+
}, [i, originPropsList]);
|
|
115
|
+
const Editor = (_a = child.type) == null ? void 0 : _a.Editor;
|
|
116
|
+
const overProps = useMemo(() => originPropsList && originPropsList[i].props, [i, originPropsList]);
|
|
117
|
+
return /* @__PURE__ */ jsxs("div", { className: " relative", children: [
|
|
118
|
+
/* @__PURE__ */ jsxs(
|
|
119
|
+
MtButton,
|
|
120
|
+
{
|
|
121
|
+
className: " absolute right-0 top-0",
|
|
122
|
+
onClick: () => {
|
|
123
|
+
setOpen(true);
|
|
124
|
+
},
|
|
125
|
+
children: [
|
|
126
|
+
"ed(",
|
|
127
|
+
i,
|
|
128
|
+
")"
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
),
|
|
132
|
+
createElement(child.type, __spreadValues(__spreadValues({}, child.props), overProps)),
|
|
133
|
+
/* @__PURE__ */ jsx(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(DialogContent, { children: [
|
|
134
|
+
"editor",
|
|
135
|
+
Editor && /* @__PURE__ */ jsx(Editor, { preProps: oriProps, setNewProps: (values) => {
|
|
136
|
+
console.log("\u8BBE\u7F6E\u65B0\u503C", values);
|
|
137
|
+
setOriginPropsList(originPropsList.map((item, j) => {
|
|
138
|
+
if (i == j) {
|
|
139
|
+
return { props: values };
|
|
140
|
+
}
|
|
141
|
+
return item;
|
|
142
|
+
}));
|
|
143
|
+
} })
|
|
144
|
+
] }) })
|
|
145
|
+
] });
|
|
146
|
+
}
|
|
147
|
+
const BlockDesignToolbar = () => {
|
|
148
|
+
const debugData = useDemoChildrenBlock((x) => x.originPropsList);
|
|
149
|
+
const designMode = useDemoChildrenBlock((x) => x.designMode);
|
|
150
|
+
const setDesignMode = useDemoChildrenBlock((x) => x.setDesignMode);
|
|
151
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-1 bg-slate-600 p-2", children: [
|
|
152
|
+
/* @__PURE__ */ jsx(MtButton, { onClick: () => {
|
|
153
|
+
setDesignMode(!designMode);
|
|
154
|
+
}, children: "edit" }),
|
|
155
|
+
/* @__PURE__ */ jsxs(Dialog, { children: [
|
|
156
|
+
/* @__PURE__ */ jsx(DialogTrigger, { asChild: true, children: /* @__PURE__ */ jsx(MtButton, { children: "info" }) }),
|
|
157
|
+
/* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsx("pre", { children: JSON.stringify(debugData, null, 2) }) })
|
|
158
|
+
] }),
|
|
159
|
+
/* @__PURE__ */ jsxs(Dialog, { children: [
|
|
160
|
+
/* @__PURE__ */ jsx(DialogTrigger, { asChild: true, children: /* @__PURE__ */ jsx(MtButton, { children: "reRender" }) }),
|
|
161
|
+
/* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsx(RenderByPresistData, { data: debugData }) })
|
|
162
|
+
] })
|
|
104
163
|
] });
|
|
105
164
|
};
|
|
165
|
+
function RenderByPresistData(props) {
|
|
166
|
+
const { data } = props;
|
|
167
|
+
const items = data;
|
|
168
|
+
return /* @__PURE__ */ jsx("div", { className: "bg-yellow-100 p-2", children: items.map((item, i) => {
|
|
169
|
+
return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(MtBlockRender, { type: item.blockType, compProps: item.props }) }, i);
|
|
170
|
+
}) });
|
|
171
|
+
}
|
|
106
172
|
export {
|
|
107
|
-
|
|
173
|
+
BlockCanva,
|
|
108
174
|
DemoChildrenProvider,
|
|
109
175
|
blockContext,
|
|
110
176
|
useDemoChildrenBlock
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Suspense } from "react";
|
|
3
3
|
import { BlockProvider } from "./block-store";
|
|
4
|
-
import { MtBlockRender } from "./blockRegister";
|
|
5
4
|
function MtBlock(props) {
|
|
6
5
|
const { id, type, blockProps } = props;
|
|
7
|
-
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("div", { children: "loading block" }), children: /* @__PURE__ */ jsx(BlockProvider, { id, type
|
|
6
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("div", { children: "loading block" }), children: /* @__PURE__ */ jsx(BlockProvider, { id, type }) }) });
|
|
8
7
|
}
|
|
9
8
|
export {
|
|
10
9
|
MtBlock
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { ComponentType } from "react";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare
|
|
2
|
+
export declare const getComponentName: (comp: any) => any;
|
|
3
|
+
export declare const registerBlock: (comp: ComponentType<any>, type?: string) => void;
|
|
4
|
+
export declare const registAllBlock: () => void;
|
|
5
|
+
export declare function MtBlockRender(props: {
|
|
6
|
+
type: string;
|
|
7
|
+
compProps: any;
|
|
8
|
+
}): import("react").JSX.Element;
|
|
@@ -16,20 +16,28 @@ var __spreadValues = (a, b) => {
|
|
|
16
16
|
return a;
|
|
17
17
|
};
|
|
18
18
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
-
import
|
|
20
|
-
import
|
|
19
|
+
import HelloBlock from "./blocks/hello";
|
|
20
|
+
import Hello2Block from "./blocks/hello2";
|
|
21
|
+
const getComponentName = (comp) => {
|
|
22
|
+
let name1 = comp.blockName;
|
|
23
|
+
if (!name1) {
|
|
24
|
+
name1 = comp == null ? void 0 : comp.name;
|
|
25
|
+
}
|
|
26
|
+
return name1;
|
|
27
|
+
};
|
|
21
28
|
const blocks = {};
|
|
22
|
-
const registerBlock = (
|
|
23
|
-
|
|
29
|
+
const registerBlock = (comp, type) => {
|
|
30
|
+
const name = getComponentName(comp);
|
|
31
|
+
console.log("registerBlock", name);
|
|
32
|
+
blocks[name] = comp;
|
|
33
|
+
};
|
|
34
|
+
const registAllBlock = () => {
|
|
35
|
+
registerBlock(HelloBlock);
|
|
36
|
+
registerBlock(Hello2Block);
|
|
24
37
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
registerBlock("hello2", LzHello2Block);
|
|
29
|
-
function MtBlockRender() {
|
|
30
|
-
const id = useBlock((x) => x.id);
|
|
31
|
-
const type = useBlock((x) => x.type);
|
|
32
|
-
const blockProps = useBlock((x) => x.props);
|
|
38
|
+
registAllBlock();
|
|
39
|
+
function MtBlockRender(props) {
|
|
40
|
+
const { compProps, type } = props;
|
|
33
41
|
const BlockComp = blocks[type];
|
|
34
42
|
if (!BlockComp) {
|
|
35
43
|
return /* @__PURE__ */ jsxs("div", { className: "bg-600 mx-auto p-8", children: [
|
|
@@ -37,9 +45,11 @@ function MtBlockRender() {
|
|
|
37
45
|
type
|
|
38
46
|
] });
|
|
39
47
|
}
|
|
40
|
-
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(BlockComp, __spreadValues({},
|
|
48
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(BlockComp, __spreadValues({}, compProps)) });
|
|
41
49
|
}
|
|
42
50
|
export {
|
|
43
51
|
MtBlockRender,
|
|
52
|
+
getComponentName,
|
|
53
|
+
registAllBlock,
|
|
44
54
|
registerBlock
|
|
45
55
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs } from "react/jsx-runtime";
|
|
3
|
+
function HelloBlock(props) {
|
|
4
|
+
const { id, text } = props;
|
|
5
|
+
return /* @__PURE__ */ jsxs("div", { className: "bg-slate-100 p-2", children: [
|
|
6
|
+
"hello block: ",
|
|
7
|
+
id,
|
|
8
|
+
",text:",
|
|
9
|
+
text
|
|
10
|
+
] });
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
HelloBlock as default
|
|
14
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
function HelloBlock(props) {
|
|
3
|
+
const { text } = props;
|
|
4
|
+
return /* @__PURE__ */ jsxs("div", { className: "border bg-slate-100 p-2 shadow-md outline", children: [
|
|
5
|
+
/* @__PURE__ */ jsx("h1", { children: "hello-block" }),
|
|
6
|
+
/* @__PURE__ */ jsx("div", { className: "bg-slate-300 p-2", children: text })
|
|
7
|
+
] });
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
HelloBlock as default
|
|
11
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { MtButton } from "mtxuilib/ui/ui-mt/Button";
|
|
3
|
+
function HelloBlockEditor(props) {
|
|
4
|
+
const { preProps, setNewProps } = props;
|
|
5
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
6
|
+
/* @__PURE__ */ jsx("h1", { children: "hello editor" }),
|
|
7
|
+
/* @__PURE__ */ jsx(MtButton, { onClick: () => {
|
|
8
|
+
console.log("todo set text");
|
|
9
|
+
setNewProps({ text: "new text-------------------" });
|
|
10
|
+
}, children: "set text" }),
|
|
11
|
+
/* @__PURE__ */ jsx("pre", { children: JSON.stringify(preProps, null, 2) })
|
|
12
|
+
] });
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
HelloBlockEditor as default
|
|
16
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
declare function HelloBlock(props: {
|
|
3
|
+
id: string;
|
|
4
|
+
text?: string;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
6
|
+
declare namespace HelloBlock {
|
|
7
|
+
var blockName: string;
|
|
8
|
+
var Editor: import("react").LazyExoticComponent<typeof import("./edit").default>;
|
|
9
|
+
}
|
|
10
|
+
export default HelloBlock;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __spreadValues = (a, b) => {
|
|
8
|
+
for (var prop in b || (b = {}))
|
|
9
|
+
if (__hasOwnProp.call(b, prop))
|
|
10
|
+
__defNormalProp(a, prop, b[prop]);
|
|
11
|
+
if (__getOwnPropSymbols)
|
|
12
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
13
|
+
if (__propIsEnum.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
}
|
|
16
|
+
return a;
|
|
17
|
+
};
|
|
18
|
+
import { jsx } from "react/jsx-runtime";
|
|
19
|
+
import { lazy } from "react";
|
|
20
|
+
const LzHelloBlock = lazy(() => import("./Hello"));
|
|
21
|
+
const LzEdit = lazy(() => import("./edit"));
|
|
22
|
+
function HelloBlock(props) {
|
|
23
|
+
return /* @__PURE__ */ jsx(LzHelloBlock, __spreadValues({}, props));
|
|
24
|
+
}
|
|
25
|
+
HelloBlock.blockName = "hello-block";
|
|
26
|
+
HelloBlock.Editor = LzEdit;
|
|
27
|
+
export {
|
|
28
|
+
HelloBlock as default
|
|
29
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs } from "react/jsx-runtime";
|
|
3
|
+
function Hello2Block(props) {
|
|
4
|
+
const { id } = props;
|
|
5
|
+
return /* @__PURE__ */ jsxs("div", { className: "mx-auto flex gap-2 bg-blue-100 p-2", children: [
|
|
6
|
+
"hello2 block: ",
|
|
7
|
+
id
|
|
8
|
+
] });
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
Hello2Block as default
|
|
12
|
+
};
|