@mybricks/to-code-taro 1.1.8 → 1.2.1

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.
Files changed (64) hide show
  1. package/dist/cjs/generate/generateTaroProjectJson.js +11 -11
  2. package/dist/cjs/handleModule.js +1 -1
  3. package/dist/cjs/index.js +1 -0
  4. package/dist/cjs/taro-template.json +6 -6008
  5. package/dist/cjs/utils/logic/handleProcess.js +1 -1
  6. package/dist/esm/generate/generateTaroProjectJson.js +12 -12
  7. package/dist/esm/handleModule.js +1 -1
  8. package/dist/esm/index.js +2 -1
  9. package/dist/esm/taro-template.json +6 -6008
  10. package/dist/esm/utils/logic/handleProcess.js +1 -1
  11. package/package.json +2 -9
  12. package/README.md +0 -58
  13. package/dist/cjs/core/mybricks/MyBricksDescriptor.js +0 -213
  14. package/dist/cjs/core/mybricks/Subject.js +0 -119
  15. package/dist/cjs/core/mybricks/constant.js +0 -70
  16. package/dist/cjs/core/mybricks/context.js +0 -33
  17. package/dist/cjs/core/mybricks/createEnv.js +0 -39
  18. package/dist/cjs/core/mybricks/createJSHandle.js +0 -191
  19. package/dist/cjs/core/mybricks/createModuleEventsHandle.js +0 -49
  20. package/dist/cjs/core/mybricks/createReactiveInputHandler.js +0 -63
  21. package/dist/cjs/core/mybricks/event.js +0 -70
  22. package/dist/cjs/core/mybricks/index.js +0 -871
  23. package/dist/cjs/core/mybricks/log.js +0 -37
  24. package/dist/cjs/core/mybricks/utils.js +0 -69
  25. package/dist/cjs/core/mybricks/variables.js +0 -217
  26. package/dist/cjs/core/utils/ComContext.js +0 -51
  27. package/dist/cjs/core/utils/PopupRenderer.js +0 -63
  28. package/dist/cjs/core/utils/comRefResolver.js +0 -112
  29. package/dist/cjs/core/utils/event.js +0 -53
  30. package/dist/cjs/core/utils/hooks.js +0 -238
  31. package/dist/cjs/core/utils/index.js +0 -77
  32. package/dist/cjs/core/utils/pageRouter.js +0 -104
  33. package/dist/cjs/core/utils/pool.js +0 -63
  34. package/dist/cjs/core/utils/popupRouter.js +0 -98
  35. package/dist/cjs/core/utils/slots.js +0 -183
  36. package/dist/cjs/core/utils/tabbar.js +0 -56
  37. package/dist/cjs/core/utils/useContext.js +0 -112
  38. package/dist/cjs/core/utils/with.js +0 -109
  39. package/dist/esm/core/mybricks/MyBricksDescriptor.js +0 -232
  40. package/dist/esm/core/mybricks/Subject.js +0 -149
  41. package/dist/esm/core/mybricks/constant.js +0 -18
  42. package/dist/esm/core/mybricks/context.js +0 -5
  43. package/dist/esm/core/mybricks/createEnv.js +0 -9
  44. package/dist/esm/core/mybricks/createJSHandle.js +0 -189
  45. package/dist/esm/core/mybricks/createModuleEventsHandle.js +0 -26
  46. package/dist/esm/core/mybricks/createReactiveInputHandler.js +0 -40
  47. package/dist/esm/core/mybricks/event.js +0 -44
  48. package/dist/esm/core/mybricks/index.js +0 -952
  49. package/dist/esm/core/mybricks/log.js +0 -8
  50. package/dist/esm/core/mybricks/utils.js +0 -41
  51. package/dist/esm/core/mybricks/variables.js +0 -190
  52. package/dist/esm/core/utils/ComContext.js +0 -16
  53. package/dist/esm/core/utils/PopupRenderer.js +0 -27
  54. package/dist/esm/core/utils/comRefResolver.js +0 -134
  55. package/dist/esm/core/utils/event.js +0 -32
  56. package/dist/esm/core/utils/hooks.js +0 -287
  57. package/dist/esm/core/utils/index.js +0 -12
  58. package/dist/esm/core/utils/pageRouter.js +0 -112
  59. package/dist/esm/core/utils/pool.js +0 -52
  60. package/dist/esm/core/utils/popupRouter.js +0 -117
  61. package/dist/esm/core/utils/slots.js +0 -194
  62. package/dist/esm/core/utils/tabbar.js +0 -47
  63. package/dist/esm/core/utils/useContext.js +0 -100
  64. package/dist/esm/core/utils/with.js +0 -115
@@ -1,183 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
29
- // src/core/utils/slots.tsx
30
- var slots_exports = {};
31
- __export(slots_exports, {
32
- ScopedComContextProvider: () => ScopedComContextProvider,
33
- useEnhancedSlots: () => useEnhancedSlots,
34
- useResolvedParentSlot: () => useResolvedParentSlot
35
- });
36
- module.exports = __toCommonJS(slots_exports);
37
- var import_react = __toESM(require("react"));
38
- var import_ComContext = __toESM(require("./ComContext"));
39
- var import_createReactiveInputHandler = require("../mybricks/createReactiveInputHandler");
40
- var import_hooks = require("./hooks");
41
- function shallowEqual(a, b) {
42
- if (a === b)
43
- return true;
44
- if (!a || !b)
45
- return false;
46
- const keysA = Object.keys(a);
47
- const keysB = Object.keys(b);
48
- if (keysA.length !== keysB.length)
49
- return false;
50
- return keysA.every((key) => a[key] === b[key]);
51
- }
52
- function mergeSlotParams(stateInputValues, params) {
53
- const hasStateInputValues = stateInputValues && Object.keys(stateInputValues).length > 0;
54
- const hasParamsInputValues = (params == null ? void 0 : params.inputValues) && Object.keys(params.inputValues).length > 0;
55
- if (!hasStateInputValues && !hasParamsInputValues) {
56
- return params || {};
57
- }
58
- return {
59
- ...params || {},
60
- inputValues: {
61
- ...stateInputValues || {},
62
- ...(params == null ? void 0 : params.inputValues) || {}
63
- }
64
- };
65
- }
66
- function createScopeId(id, slotKey, rawScope) {
67
- return `${id}.${slotKey}::${String(rawScope)}`;
68
- }
69
- function createPenetratingComRefs(parentComRefs, todoPool, index = 0) {
70
- const localTarget = { $inputs: {}, $outputs: {}, $index: index };
71
- return { current: (0, import_hooks.proxyRefs)(localTarget, parentComRefs, todoPool) };
72
- }
73
- function SlotParamsBridge(props) {
74
- var _a, _b;
75
- const parentSlot = (0, import_ComContext.useParentSlot)();
76
- const mergedParams = ((_a = props.params) == null ? void 0 : _a.inputValues) === void 0 && ((_b = parentSlot == null ? void 0 : parentSlot.params) == null ? void 0 : _b.inputValues) ? { ...props.params || {}, inputValues: parentSlot.params.inputValues } : props.params;
77
- const SlotComp = props.render;
78
- const content = SlotComp ? /* @__PURE__ */ import_react.default.createElement(SlotComp, { ...mergedParams || {} }) : props.children ?? null;
79
- return /* @__PURE__ */ import_react.default.createElement(import_ComContext.SlotProvider, { value: { ...props.state, params: mergedParams } }, content);
80
- }
81
- function createChannelProxy(title, onInputCall) {
82
- const handlersMap = {};
83
- return new Proxy(
84
- {},
85
- {
86
- get: (_t, pin) => {
87
- return (arg) => {
88
- if (typeof arg === "function") {
89
- handlersMap[pin] = arg;
90
- return;
91
- }
92
- onInputCall == null ? void 0 : onInputCall(pin, arg);
93
- const handler = handlersMap[pin];
94
- if (typeof handler === "function") {
95
- return (0, import_createReactiveInputHandler.createReactiveInputHandler)({
96
- input: handler,
97
- value: arg,
98
- rels: {},
99
- title
100
- });
101
- }
102
- };
103
- }
104
- }
105
- );
106
- }
107
- function useEnhancedSlots(rawSlots, id) {
108
- const { comRefs: parentComRefs, todoPool } = (0, import_ComContext.useAppContext)();
109
- const slotStoreRef = (0, import_react.useRef)({});
110
- const [, forceUpdate] = (0, import_react.useState)({});
111
- return (0, import_react.useMemo)(() => {
112
- if (!rawSlots)
113
- return {};
114
- const nextSlots = {};
115
- Object.entries(rawSlots).forEach(([slotKey, slotDef]) => {
116
- const onInputCall = (pin, value) => {
117
- const state2 = slotStoreRef.current[slotKey];
118
- if (state2) {
119
- if (!state2._inputValues)
120
- state2._inputValues = {};
121
- state2._inputValues[pin] = value;
122
- forceUpdate({});
123
- }
124
- };
125
- const state = slotStoreRef.current[slotKey] || (slotStoreRef.current[slotKey] = {
126
- inputs: createChannelProxy(`${id}.${slotKey}.inputs`, onInputCall),
127
- outputs: createChannelProxy(`${id}.${slotKey}.outputs`),
128
- _inputs: createChannelProxy(`${id}.${slotKey}._inputs`),
129
- _scopedComRefs: {},
130
- _inputValues: {},
131
- _render: void 0,
132
- render: (params) => {
133
- var _a, _b, _c, _d;
134
- const r = state._render;
135
- const mergedParams = mergeSlotParams(state._inputValues, params);
136
- if (state._lastMergedParams && shallowEqual(mergedParams == null ? void 0 : mergedParams.inputValues, (_a = state._lastMergedParams) == null ? void 0 : _a.inputValues)) {
137
- } else {
138
- state._lastMergedParams = mergedParams;
139
- }
140
- const stableParams = state._lastMergedParams;
141
- const rawScope = ((_b = stableParams == null ? void 0 : stableParams.inputValues) == null ? void 0 : _b.index) ?? (params == null ? void 0 : params.key);
142
- if (rawScope === void 0 || rawScope === null) {
143
- return /* @__PURE__ */ import_react.default.createElement(SlotParamsBridge, { state, params: stableParams, render: r });
144
- }
145
- const scopeId = createScopeId(id, slotKey, rawScope);
146
- const index = ((_c = stableParams == null ? void 0 : stableParams.inputValues) == null ? void 0 : _c.index) ?? 0;
147
- const scopedComRefs = (_d = state._scopedComRefs)[scopeId] || (_d[scopeId] = createPenetratingComRefs(parentComRefs, todoPool, index));
148
- return /* @__PURE__ */ import_react.default.createElement(ScopedComContextProvider, { comRefs: scopedComRefs, scopeId }, /* @__PURE__ */ import_react.default.createElement(SlotParamsBridge, { state, params: stableParams, render: r }));
149
- }
150
- });
151
- state._render = slotDef == null ? void 0 : slotDef.render;
152
- nextSlots[slotKey] = {
153
- ...slotDef || {},
154
- render: state.render,
155
- inputs: state.inputs,
156
- outputs: state.outputs,
157
- _inputs: state._inputs
158
- };
159
- });
160
- return nextSlots;
161
- }, [rawSlots, id, parentComRefs, todoPool]);
162
- }
163
- function ScopedComContextProvider(props) {
164
- const parent = (0, import_ComContext.useAppContext)();
165
- const value = (0, import_react.useMemo)(() => {
166
- return {
167
- ...parent,
168
- comRefs: props.comRefs || parent.comRefs,
169
- $scopeId: props.scopeId
170
- };
171
- }, [parent, props.comRefs, props.scopeId]);
172
- return /* @__PURE__ */ import_react.default.createElement(import_ComContext.default.Provider, { value }, props.children);
173
- }
174
- function useResolvedParentSlot(parentSlotProp) {
175
- const parentSlotFromCtx = (0, import_ComContext.useParentSlot)();
176
- return parentSlotProp ?? parentSlotFromCtx;
177
- }
178
- // Annotate the CommonJS export names for ESM import in node:
179
- 0 && (module.exports = {
180
- ScopedComContextProvider,
181
- useEnhancedSlots,
182
- useResolvedParentSlot
183
- });
@@ -1,56 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/core/utils/tabbar.ts
20
- var tabbar_exports = {};
21
- __export(tabbar_exports, {
22
- tabbarIns: () => tabbarIns
23
- });
24
- module.exports = __toCommonJS(tabbar_exports);
25
- var import_event = require("./event");
26
- var isDefine = (val) => val !== void 0 && val !== null && val !== "";
27
- var TabbarInstance = class {
28
- constructor() {
29
- this.list = [];
30
- this.eventEmitter = new import_event.EventEmitter();
31
- this.setTabBarBadge = ({ index, text }) => new Promise((resolve, reject) => {
32
- if (isDefine(index)) {
33
- this.list[index].active = true;
34
- this.list[index].activeText = text;
35
- console.log("change", this.list);
36
- this.eventEmitter.dispatch("change", this.list);
37
- }
38
- });
39
- this.hideTabBarRedDot = ({ index }) => new Promise((resolve, reject) => {
40
- if (isDefine(index)) {
41
- this.list[index].active = false;
42
- this.list[index].activeText = 0;
43
- this.eventEmitter.dispatch("change", this.list);
44
- }
45
- });
46
- this.removeTabBarBadge = this.hideTabBarRedDot;
47
- this.initWithLength = (len) => {
48
- this.list = new Array(len).fill((t) => null).map(() => ({ active: false, activeText: "" }));
49
- };
50
- }
51
- };
52
- var tabbarIns = new TabbarInstance();
53
- // Annotate the CommonJS export names for ESM import in node:
54
- 0 && (module.exports = {
55
- tabbarIns
56
- });
@@ -1,112 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
29
- // src/core/utils/useContext.ts
30
- var useContext_exports = {};
31
- __export(useContext_exports, {
32
- useAppCreateContext: () => useAppCreateContext
33
- });
34
- module.exports = __toCommonJS(useContext_exports);
35
- var import_react = require("react");
36
- var Taro = __toESM(require("@tarojs/taro"));
37
- var import_request = require("@/common/request");
38
- var import_tabbar = require("@/core/utils/tabbar");
39
- var import_rootConfig = __toESM(require("@/common/rootConfig"));
40
- var import_hooks = require("./hooks");
41
- var import_pool = require("./pool");
42
- function useAppCreateContext(id) {
43
- const todoPool = (0, import_react.useMemo)(() => new import_pool.TodoPool(), []);
44
- const comRefs = (0, import_react.useRef)((0, import_hooks.proxyRefs)({ $inputs: {}, $outputs: {} }, void 0, todoPool));
45
- const $vars = (0, import_react.useRef)({});
46
- const $fxs = (0, import_react.useRef)({});
47
- const [popupState, setPopupState] = (0, import_react.useState)({
48
- visible: false,
49
- name: "",
50
- value: null,
51
- controller: null
52
- });
53
- const appContext = (0, import_react.useRef)({
54
- canvas: {
55
- id
56
- },
57
- runtime: {
58
- debug: false
59
- },
60
- env: {
61
- runtime: true,
62
- request: (connector, params, config) => (0, import_request.request)(connector, params, config, { $vars }),
63
- tabbar: import_tabbar.tabbarIns,
64
- uploadFile: (params) => {
65
- var _a, _b, _c, _d;
66
- let header = {};
67
- let mybricksGlobalHeaders = Taro.getStorageSync(
68
- "_MYBRICKS_GLOBAL_HEADERS_"
69
- );
70
- if (mybricksGlobalHeaders) {
71
- header = {
72
- ...mybricksGlobalHeaders,
73
- ...header
74
- };
75
- }
76
- if (!/^(http|https):\/\/.*/.test(params.url) && ((_b = (_a = import_rootConfig.default) == null ? void 0 : _a.status) == null ? void 0 : _b.defaultCallServiceHost)) {
77
- params.url = `${(_d = (_c = import_rootConfig.default) == null ? void 0 : _c.status) == null ? void 0 : _d.defaultCallServiceHost}${params.url}`;
78
- }
79
- const { success, fail, ...rest } = params;
80
- Taro.uploadFile({
81
- ...rest,
82
- success: (res) => success == null ? void 0 : success(res),
83
- fail: (err) => fail == null ? void 0 : fail(err)
84
- });
85
- }
86
- },
87
- rootScroll: {},
88
- edit: false,
89
- isH5: false,
90
- isDesigner: false,
91
- isPreview: false,
92
- isRelease: false,
93
- isDebug: false,
94
- isLocal: false,
95
- isTest: false,
96
- tabBar: [],
97
- useTabBar: false
98
- }).current;
99
- return (0, import_react.useMemo)(() => ({
100
- comRefs,
101
- $vars,
102
- $fxs,
103
- todoPool,
104
- appContext,
105
- popupState,
106
- setPopupState
107
- }), [popupState]);
108
- }
109
- // Annotate the CommonJS export names for ESM import in node:
110
- 0 && (module.exports = {
111
- useAppCreateContext
112
- });
@@ -1,109 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
29
- // src/core/utils/with.tsx
30
- var with_exports = {};
31
- __export(with_exports, {
32
- WithCom: () => WithCom,
33
- WithWrapper: () => WithWrapper
34
- });
35
- module.exports = __toCommonJS(with_exports);
36
- var import_react = __toESM(require("react"));
37
- var import_components = require("@tarojs/components");
38
- var import_index = require("./index");
39
- var import_useContext = require("./useContext");
40
- var import_ComContext = __toESM(require("./ComContext"));
41
- var import_slots = require("./slots");
42
- var import_taro = require("@tarojs/taro");
43
- var WithCom = (props) => {
44
- var _a;
45
- const { component: Component, id = "", data, className, style, ...rest } = props;
46
- const { comRefs, appContext } = (0, import_ComContext.useAppContext)();
47
- const env = appContext;
48
- const isPopup = Component.isPopup;
49
- const [show, setShow] = (0, import_react.useState)(true);
50
- const [dynamicStyle, setDynamicStyle] = (0, import_react.useState)({});
51
- const _data = (0, import_index.useModel)(data || {});
52
- const { slots: rawSlots, parentSlot: parentSlotProp, ...restProps } = rest;
53
- const parentSlot = (0, import_slots.useResolvedParentSlot)(parentSlotProp);
54
- const enhancedSlots = (0, import_slots.useEnhancedSlots)(rawSlots, id);
55
- const handlers = (0, import_index.useBuiltinHandlers)({ data: _data, setDynamicStyle, setShow, isPopup });
56
- const inputProxy = (0, import_index.useBindInputs)(comRefs, id, handlers);
57
- const outputProxy = (0, import_index.useBindOutputs)(comRefs, id, restProps, enhancedSlots, {
58
- id,
59
- name: props.name || id,
60
- parentSlot
61
- });
62
- const jsx = /* @__PURE__ */ import_react.default.createElement(
63
- Component,
64
- {
65
- ...restProps,
66
- inputs: inputProxy,
67
- outputs: outputProxy,
68
- slots: enhancedSlots,
69
- parentSlot,
70
- data: _data,
71
- env,
72
- id,
73
- style
74
- }
75
- );
76
- if ((_a = parentSlot == null ? void 0 : parentSlot.params) == null ? void 0 : _a.itemWrap) {
77
- return parentSlot.params.itemWrap({
78
- id,
79
- name: props.name || id,
80
- jsx,
81
- def: Component.def,
82
- inputs: inputProxy,
83
- outputs: outputProxy,
84
- style
85
- });
86
- }
87
- return show || isPopup ? /* @__PURE__ */ import_react.default.createElement(import_components.View, { id, className, style: { ...style, ...dynamicStyle } }, jsx, props.children) : null;
88
- };
89
- var WithWrapper = (id, Component) => {
90
- return function WrappedComponent(props) {
91
- const contextStore = (0, import_useContext.useAppCreateContext)(id);
92
- const { setPopupState } = contextStore;
93
- const isPopup = Component.isPopup;
94
- (0, import_react.useEffect)(() => {
95
- return (0, import_index.subscribePopupRouter)((state) => setPopupState(state));
96
- }, [setPopupState]);
97
- (0, import_taro.useTabItemTap)(() => {
98
- if (isPopup)
99
- return;
100
- (0, import_index.closeActivePopupRouter)();
101
- });
102
- return /* @__PURE__ */ import_react.default.createElement(import_ComContext.default.Provider, { value: contextStore }, /* @__PURE__ */ import_react.default.createElement(Component, { ...props }));
103
- };
104
- };
105
- // Annotate the CommonJS export names for ESM import in node:
106
- 0 && (module.exports = {
107
- WithCom,
108
- WithWrapper
109
- });
@@ -1,232 +0,0 @@
1
- import { VARS_MARK, SUBJECT_VALUE, BASECONTROLLER_MARK, MYBRICKS_DESCRIPTOR, CONTROLLER_CONTEXT } from "./constant";
2
- import { createModuleEventsHandle } from "./createModuleEventsHandle";
3
- import { log } from "./log";
4
- var DEFAULT_GETVAR_RESULT = {
5
- setValue: function setValue(value) {
6
- log("setValue - 变量未定义,请检查");
7
- },
8
- getValue: function getValue() {
9
- log("getValue - 变量未定义,请检查");
10
- return;
11
- }
12
- };
13
- var getVar = function getVar(_ref) {
14
- var that = _ref.that,
15
- varName = _ref.varName;
16
- var myBricksDescriptor = that[MYBRICKS_DESCRIPTOR];
17
- if (!myBricksDescriptor) {
18
- return DEFAULT_GETVAR_RESULT;
19
- }
20
- var vars = myBricksDescriptor.vars,
21
- params = myBricksDescriptor.params,
22
- parent = myBricksDescriptor.parent;
23
- var var0 = vars === null || vars === void 0 ? void 0 : vars[varName];
24
- if (var0) {
25
- return var0.ext();
26
- }
27
- if (["page", "popup", "module"].includes(params.type)) {
28
- var _params$appContext;
29
- // 模块、页面、弹窗是最上层,不再继续向上查
30
- var _var = (_params$appContext = params.appContext) === null || _params$appContext === void 0 || (_params$appContext = _params$appContext.globalVars) === null || _params$appContext === void 0 ? void 0 : _params$appContext[varName];
31
- if (_var) {
32
- return _var.ext();
33
- }
34
- return DEFAULT_GETVAR_RESULT;
35
- }
36
- return getVar({
37
- that: parent,
38
- varName: varName
39
- });
40
- };
41
- var DEFAULT_GETOUTPUT_RESULT = {
42
- setValue: function setValue(value) {
43
- log("setValue - 输出未定义,请检查");
44
- }
45
- };
46
- var getOutput = function getOutput(_ref2) {
47
- var that = _ref2.that,
48
- outputName = _ref2.outputName;
49
- var myBricksDescriptor = that[MYBRICKS_DESCRIPTOR];
50
- if (!myBricksDescriptor) {
51
- return DEFAULT_GETOUTPUT_RESULT;
52
- }
53
- var params = myBricksDescriptor.params,
54
- controller = myBricksDescriptor.controller,
55
- parent = myBricksDescriptor.parent;
56
- var type = params.type,
57
- outputNameMap = params.outputNameMap,
58
- pageId = params.pageId;
59
- var outputKey = outputNameMap ? outputNameMap[outputName] || outputName : outputName;
60
- if (type === "module") {
61
- var _controller$events;
62
- if ((_controller$events = controller.events) !== null && _controller$events !== void 0 && _controller$events[outputKey]) {
63
- return {
64
- setValue: function setValue(value) {
65
- var _controller$events2;
66
- (_controller$events2 = controller.events) === null || _controller$events2 === void 0 || _controller$events2[outputKey](value);
67
- }
68
- };
69
- }
70
- } else if (type === "popup") {
71
- if (["commit", "apply", "cancel", "close"].includes(outputKey)) {
72
- return {
73
- setValue: function setValue(value) {
74
- var _params$appContext2;
75
- (_params$appContext2 = params.appContext) === null || _params$appContext2 === void 0 || (_params$appContext2 = _params$appContext2.page) === null || _params$appContext2 === void 0 || _params$appContext2[outputKey](pageId, value);
76
- }
77
- };
78
- }
79
- } else if (type === "slot") {
80
- if (that.params.outputs && outputKey in that.params.outputs) {
81
- return {
82
- setValue: function setValue(value) {
83
- that.params.outputs[outputKey](value);
84
- }
85
- };
86
- }
87
- }
88
- if (["page", "popup", "module"].includes(type)) {
89
- // 模块、页面、弹窗是最上层,不再继续向上查
90
- return DEFAULT_GETOUTPUT_RESULT;
91
- }
92
- return getOutput({
93
- that: parent,
94
- outputName: outputName
95
- });
96
- };
97
- var DEFAULT_GETINPUT_RESULT = {
98
- getValue: function getValue(value) {
99
- log("getValue - 输入未定义,请检查");
100
- }
101
- };
102
- var getInput = function getInput(_ref3) {
103
- var that = _ref3.that,
104
- inputName = _ref3.inputName;
105
- var myBricksDescriptor = that[MYBRICKS_DESCRIPTOR];
106
- if (!myBricksDescriptor) {
107
- return DEFAULT_GETINPUT_RESULT;
108
- }
109
- var params = myBricksDescriptor.params,
110
- controller = myBricksDescriptor.controller,
111
- parent = myBricksDescriptor.parent;
112
- var type = params.type,
113
- inputNameMap = params.inputNameMap,
114
- pageId = params.pageId;
115
- var inputKey = (inputNameMap ? inputNameMap[inputName] : inputName) || inputName;
116
- if (type === "slot") {
117
- if (inputKey in that.params.inputValues) {
118
- return {
119
- getValue: function getValue() {
120
- return that.params.inputValues[inputKey];
121
- }
122
- };
123
- }
124
- } else if (type === "page" || type === "popup") {
125
- if (inputKey === "open") {
126
- return {
127
- getValue: function getValue() {
128
- var _params$appContext3;
129
- return (_params$appContext3 = params.appContext) === null || _params$appContext3 === void 0 || (_params$appContext3 = _params$appContext3.page) === null || _params$appContext3 === void 0 || (_params$appContext3 = _params$appContext3.getParams(pageId)) === null || _params$appContext3 === void 0 ? void 0 : _params$appContext3[SUBJECT_VALUE];
130
- }
131
- };
132
- }
133
- return DEFAULT_GETINPUT_RESULT;
134
- } else if (type === "module") {
135
- return {
136
- getValue: function getValue() {
137
- var _controller$controlle;
138
- if (inputKey in controller.data) {
139
- return controller.data[inputKey];
140
- }
141
- return (_controller$controlle = controller.controller) === null || _controller$controlle === void 0 || (_controller$controlle = _controller$controlle[inputKey]) === null || _controller$controlle === void 0 ? void 0 : _controller$controlle[SUBJECT_VALUE];
142
- }
143
- };
144
- }
145
- if (["page", "popup", "module"].includes(type)) {
146
- // 模块、页面、弹窗是最上层,不再继续向上查
147
- return DEFAULT_GETINPUT_RESULT;
148
- }
149
- return getInput({
150
- that: parent,
151
- inputName: inputName
152
- });
153
- };
154
- export function MyBricksDescriptor(params) {
155
- return function (target, key, descriptor) {
156
- var originalMethod = descriptor.value;
157
- descriptor.value = function () {
158
- var _this = this;
159
- var controller = null;
160
- var vars = null;
161
- Object.keys(this.__proto__).filter(function (key) {
162
- return !key.startsWith("__ob_");
163
- }).forEach(function (key) {
164
- // 过滤出当前组件自身声明的Provider
165
- var value = _this[key];
166
- if (value !== null && value !== void 0 && value[BASECONTROLLER_MARK]) {
167
- var _descriptor = Object.getOwnPropertyDescriptor(_this, key);
168
- if (!(_descriptor !== null && _descriptor !== void 0 && _descriptor.get)) {
169
- controller = value;
170
- }
171
- } else if (value !== null && value !== void 0 && value[VARS_MARK]) {
172
- var _descriptor2 = Object.getOwnPropertyDescriptor(_this, key);
173
- if (!(_descriptor2 !== null && _descriptor2 !== void 0 && _descriptor2.get)) {
174
- vars = value;
175
- }
176
- }
177
- });
178
- this[MYBRICKS_DESCRIPTOR] = {
179
- controller: controller,
180
- vars: vars,
181
- params: params,
182
- parent: this.getParent()
183
- };
184
- if (controller) {
185
- if (this.events) {
186
- controller.events = createModuleEventsHandle({
187
- that: this,
188
- appContext: params.appContext
189
- });
190
- }
191
- if (this.data) {
192
- controller.data = this.data;
193
- }
194
- if (this.controller) {
195
- controller.controller = this.controller;
196
- }
197
- var classController = controller;
198
- Object.getOwnPropertyNames(classController).forEach(function (key) {
199
- var controllerContext = classController[key][CONTROLLER_CONTEXT];
200
- if (controllerContext) {
201
- controllerContext["this"] = _this;
202
- controllerContext['getVar'] = function (varName) {
203
- return getVar({
204
- that: _this,
205
- varName: varName
206
- });
207
- };
208
- controllerContext['getOutput'] = function (outputName) {
209
- return getOutput({
210
- that: _this,
211
- outputName: outputName
212
- });
213
- };
214
- controllerContext['getInput'] = function (inputName) {
215
- return getInput({
216
- that: _this,
217
- inputName: inputName
218
- });
219
- };
220
- controllerContext['appContext'] = params.appContext;
221
- }
222
- });
223
- }
224
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
225
- args[_key] = arguments[_key];
226
- }
227
- var result = originalMethod.apply(this, args);
228
- return result;
229
- };
230
- return descriptor;
231
- };
232
- }