gomtm 0.0.382 → 0.0.384

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,11 @@
1
+ import { PropsWithChildren } from "react";
2
+ export interface DemoChildrenProps {
3
+ debugData?: any;
4
+ }
5
+ export interface DemoChildrenState extends DemoChildrenProps {
6
+ setDebugData: (debugData: any) => void;
7
+ }
8
+ export declare const blockContext: import("react").Context<import("zustand").StoreApi<DemoChildrenState> | null>;
9
+ export declare const DemoChildrenProvider: (props: PropsWithChildren<DemoChildrenProps>) => import("react").JSX.Element;
10
+ export declare function useDemoChildrenBlock<T>(selector: (state: DemoChildrenState) => T): T;
11
+ export declare const ChildrenDebug: (props: any) => import("react").JSX.Element;
@@ -0,0 +1,111 @@
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 { Children, createContext, createElement, useContext, useMemo, useRef } from "react";
35
+ import { createStore, useStore } from "zustand";
36
+ const createDemoChildrenStore = (initProps) => {
37
+ return createStore()((set, get) => __spreadProps(__spreadValues({}, initProps), {
38
+ setDebugData: (debugData) => set({ debugData })
39
+ }));
40
+ };
41
+ const blockContext = createContext(null);
42
+ const DemoChildrenProvider = (props) => {
43
+ const _a = props, { children } = _a, etc = __objRest(_a, ["children"]);
44
+ const storeRef = useRef();
45
+ if (!storeRef.current) {
46
+ storeRef.current = createDemoChildrenStore(props);
47
+ }
48
+ return /* @__PURE__ */ jsxs(blockContext.Provider, { value: storeRef.current, children: [
49
+ children,
50
+ /* @__PURE__ */ jsx(ChildrenDebugInnerInfo, {})
51
+ ] });
52
+ };
53
+ function useDemoChildrenBlock(selector) {
54
+ const store = useContext(blockContext);
55
+ if (!store)
56
+ throw new Error("useDemoChildrenBlock Missing DemoChildrenProvider in the tree");
57
+ return useStore(store, selector);
58
+ }
59
+ const ChildrenDebug = (props) => {
60
+ const { children } = props;
61
+ if (!children) {
62
+ return /* @__PURE__ */ jsx("div", { children: "no children" });
63
+ }
64
+ return /* @__PURE__ */ jsx(DemoChildrenProvider, { children: /* @__PURE__ */ jsx(ChildrenDebugInner, { children }) });
65
+ };
66
+ const ChildrenDebugInner = (props) => {
67
+ const { children } = props;
68
+ const setDebugData = useDemoChildrenBlock((x) => x.setDebugData);
69
+ useMemo(() => {
70
+ {
71
+ Children.map(children, (child) => {
72
+ var _a;
73
+ const debugData = {
74
+ "\u7EC4\u4EF6\u540D\u79F0": (_a = child.type) == null ? void 0 : _a.name,
75
+ // "children.type": child.type,
76
+ "\u5176\u4ED6\u5C5E\u6027": child.props
77
+ };
78
+ setDebugData(debugData);
79
+ });
80
+ }
81
+ }, [children, setDebugData]);
82
+ if (!children) {
83
+ return /* @__PURE__ */ jsx("div", { children: "no children" });
84
+ }
85
+ return /* @__PURE__ */ jsx(Fragment, { children: Children.map(children, (child) => {
86
+ var _a;
87
+ const debugData = {
88
+ "\u7EC4\u4EF6\u540D\u79F0": (_a = children.type) == null ? void 0 : _a.name,
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;
97
+ }) });
98
+ };
99
+ const ChildrenDebugInnerInfo = () => {
100
+ const debugData = useDemoChildrenBlock((x) => x.debugData);
101
+ return /* @__PURE__ */ jsxs("div", { children: [
102
+ "ChildrenDebugInner",
103
+ /* @__PURE__ */ jsx("pre", { children: JSON.stringify(debugData, null, 2) })
104
+ ] });
105
+ };
106
+ export {
107
+ ChildrenDebug,
108
+ DemoChildrenProvider,
109
+ blockContext,
110
+ useDemoChildrenBlock
111
+ };