gomtm 0.0.383 → 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.
@@ -1,2 +1,11 @@
1
- /// <reference types="react" />
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;
2
11
  export declare const ChildrenDebug: (props: any) => import("react").JSX.Element;
@@ -18,29 +18,94 @@ var __spreadValues = (a, b) => {
18
18
  return a;
19
19
  };
20
20
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- import { Fragment, jsx } from "react/jsx-runtime";
22
- import { Children, createElement } from "react";
23
- import { useForm } from "react-hook-form";
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
+ }
24
59
  const ChildrenDebug = (props) => {
25
60
  const { children } = props;
26
- const methods = useForm({});
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]);
27
82
  if (!children) {
28
83
  return /* @__PURE__ */ jsx("div", { children: "no children" });
29
84
  }
30
85
  return /* @__PURE__ */ jsx(Fragment, { children: Children.map(children, (child) => {
31
86
  var _a;
32
- console.log({
33
- "\u5B50\u7EC4\u4EF6\u540D\u79F0": child.props.name,
34
- "\u5B50\u7EC4\u4EF6\u7C7B\u578B": children.type,
35
- "\u5176\u4ED6\u5C5E\u6027": children.props,
36
- "\u7EC4\u4EF6\u540D\u79F0": (_a = children.type) == null ? void 0 : _a.name
37
- });
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);
38
93
  return child.props.name ? createElement(child.type, __spreadValues({}, __spreadProps(__spreadValues({}, child.props), {
39
- register: methods.register,
94
+ // register: methods.register,
40
95
  key: child.props.name
41
96
  }))) : child;
42
97
  }) });
43
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
+ };
44
106
  export {
45
- ChildrenDebug
107
+ ChildrenDebug,
108
+ DemoChildrenProvider,
109
+ blockContext,
110
+ useDemoChildrenBlock
46
111
  };