@mybricks/to-code-taro 1.1.8 → 1.2.2
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/cjs/generate/generateTaroProjectJson.js +11 -11
- package/dist/cjs/handleModule.js +1 -1
- package/dist/cjs/taro-template.json +6 -6008
- package/dist/cjs/utils/logic/handleProcess.js +1 -1
- package/dist/esm/generate/generateTaroProjectJson.js +12 -12
- package/dist/esm/handleModule.js +1 -1
- package/dist/esm/taro-template.json +6 -6008
- package/dist/esm/utils/logic/handleProcess.js +1 -1
- package/package.json +3 -9
- package/README.md +0 -58
- package/dist/cjs/core/mybricks/MyBricksDescriptor.js +0 -213
- package/dist/cjs/core/mybricks/Subject.js +0 -119
- package/dist/cjs/core/mybricks/constant.js +0 -70
- package/dist/cjs/core/mybricks/context.js +0 -33
- package/dist/cjs/core/mybricks/createEnv.js +0 -39
- package/dist/cjs/core/mybricks/createJSHandle.js +0 -191
- package/dist/cjs/core/mybricks/createModuleEventsHandle.js +0 -49
- package/dist/cjs/core/mybricks/createReactiveInputHandler.js +0 -63
- package/dist/cjs/core/mybricks/event.js +0 -70
- package/dist/cjs/core/mybricks/index.js +0 -871
- package/dist/cjs/core/mybricks/log.js +0 -37
- package/dist/cjs/core/mybricks/utils.js +0 -69
- package/dist/cjs/core/mybricks/variables.js +0 -217
- package/dist/cjs/core/utils/ComContext.js +0 -51
- package/dist/cjs/core/utils/PopupRenderer.js +0 -63
- package/dist/cjs/core/utils/comRefResolver.js +0 -112
- package/dist/cjs/core/utils/event.js +0 -53
- package/dist/cjs/core/utils/hooks.js +0 -238
- package/dist/cjs/core/utils/index.js +0 -77
- package/dist/cjs/core/utils/pageRouter.js +0 -104
- package/dist/cjs/core/utils/pool.js +0 -63
- package/dist/cjs/core/utils/popupRouter.js +0 -98
- package/dist/cjs/core/utils/slots.js +0 -183
- package/dist/cjs/core/utils/tabbar.js +0 -56
- package/dist/cjs/core/utils/useContext.js +0 -112
- package/dist/cjs/core/utils/with.js +0 -109
- package/dist/esm/core/mybricks/MyBricksDescriptor.js +0 -232
- package/dist/esm/core/mybricks/Subject.js +0 -149
- package/dist/esm/core/mybricks/constant.js +0 -18
- package/dist/esm/core/mybricks/context.js +0 -5
- package/dist/esm/core/mybricks/createEnv.js +0 -9
- package/dist/esm/core/mybricks/createJSHandle.js +0 -189
- package/dist/esm/core/mybricks/createModuleEventsHandle.js +0 -26
- package/dist/esm/core/mybricks/createReactiveInputHandler.js +0 -40
- package/dist/esm/core/mybricks/event.js +0 -44
- package/dist/esm/core/mybricks/index.js +0 -952
- package/dist/esm/core/mybricks/log.js +0 -8
- package/dist/esm/core/mybricks/utils.js +0 -41
- package/dist/esm/core/mybricks/variables.js +0 -190
- package/dist/esm/core/utils/ComContext.js +0 -16
- package/dist/esm/core/utils/PopupRenderer.js +0 -27
- package/dist/esm/core/utils/comRefResolver.js +0 -134
- package/dist/esm/core/utils/event.js +0 -32
- package/dist/esm/core/utils/hooks.js +0 -287
- package/dist/esm/core/utils/index.js +0 -12
- package/dist/esm/core/utils/pageRouter.js +0 -112
- package/dist/esm/core/utils/pool.js +0 -52
- package/dist/esm/core/utils/popupRouter.js +0 -117
- package/dist/esm/core/utils/slots.js +0 -194
- package/dist/esm/core/utils/tabbar.js +0 -47
- package/dist/esm/core/utils/useContext.js +0 -100
- package/dist/esm/core/utils/with.js +0 -115
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
-
import React, { useMemo, useRef, useState } from "react";
|
|
4
|
-
import ComContext, { SlotProvider, useAppContext, useParentSlot } from "./ComContext";
|
|
5
|
-
import { createReactiveInputHandler } from "../mybricks/createReactiveInputHandler";
|
|
6
|
-
import { proxyRefs } from "./hooks";
|
|
7
|
-
|
|
8
|
-
/** Channel Proxy 类型 */
|
|
9
|
-
|
|
10
|
-
/** Slot 渲染函数类型 */
|
|
11
|
-
|
|
12
|
-
/** 浅比较两个对象的第一层 key-value */
|
|
13
|
-
function shallowEqual(a, b) {
|
|
14
|
-
if (a === b) return true;
|
|
15
|
-
if (!a || !b) return false;
|
|
16
|
-
var keysA = Object.keys(a);
|
|
17
|
-
var keysB = Object.keys(b);
|
|
18
|
-
if (keysA.length !== keysB.length) return false;
|
|
19
|
-
return keysA.every(function (key) {
|
|
20
|
-
return a[key] === b[key];
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 合并 slot 参数
|
|
26
|
-
* 只有当有实际的 inputValues 时才合并,否则保持 undefined 以便从父级继承
|
|
27
|
-
*/
|
|
28
|
-
function mergeSlotParams(stateInputValues, params) {
|
|
29
|
-
var hasStateInputValues = stateInputValues && Object.keys(stateInputValues).length > 0;
|
|
30
|
-
var hasParamsInputValues = (params === null || params === void 0 ? void 0 : params.inputValues) && Object.keys(params.inputValues).length > 0;
|
|
31
|
-
if (!hasStateInputValues && !hasParamsInputValues) {
|
|
32
|
-
return params || {};
|
|
33
|
-
}
|
|
34
|
-
return _objectSpread(_objectSpread({}, params || {}), {}, {
|
|
35
|
-
inputValues: _objectSpread(_objectSpread({}, stateInputValues || {}), (params === null || params === void 0 ? void 0 : params.inputValues) || {})
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 生成作用域 ID
|
|
41
|
-
*/
|
|
42
|
-
function createScopeId(id, slotKey, rawScope) {
|
|
43
|
-
return "".concat(id, ".").concat(slotKey, "::").concat(String(rawScope));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 创建一个具有"向上渗透"和"隔离 Todo 池"能力的 comRefs 对象
|
|
48
|
-
*/
|
|
49
|
-
function createPenetratingComRefs(parentComRefs, todoPool) {
|
|
50
|
-
var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
51
|
-
var localTarget = {
|
|
52
|
-
$inputs: {},
|
|
53
|
-
$outputs: {},
|
|
54
|
-
$index: index
|
|
55
|
-
};
|
|
56
|
-
return {
|
|
57
|
-
current: proxyRefs(localTarget, parentComRefs, todoPool)
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
function SlotParamsBridge(props) {
|
|
61
|
-
var _props$params, _parentSlot$params, _props$children;
|
|
62
|
-
var parentSlot = useParentSlot();
|
|
63
|
-
var mergedParams = ((_props$params = props.params) === null || _props$params === void 0 ? void 0 : _props$params.inputValues) === undefined && parentSlot !== null && parentSlot !== void 0 && (_parentSlot$params = parentSlot.params) !== null && _parentSlot$params !== void 0 && _parentSlot$params.inputValues ? _objectSpread(_objectSpread({}, props.params || {}), {}, {
|
|
64
|
-
inputValues: parentSlot.params.inputValues
|
|
65
|
-
}) : props.params;
|
|
66
|
-
var SlotComp = props.render;
|
|
67
|
-
var content = SlotComp ? /*#__PURE__*/React.createElement(SlotComp, mergedParams || {}) : (_props$children = props.children) !== null && _props$children !== void 0 ? _props$children : null;
|
|
68
|
-
return /*#__PURE__*/React.createElement(SlotProvider, {
|
|
69
|
-
value: _objectSpread(_objectSpread({}, props.state), {}, {
|
|
70
|
-
params: mergedParams
|
|
71
|
-
})
|
|
72
|
-
}, content);
|
|
73
|
-
}
|
|
74
|
-
function createChannelProxy(title, onInputCall) {
|
|
75
|
-
var handlersMap = {};
|
|
76
|
-
return new Proxy({}, {
|
|
77
|
-
get: function get(_t, pin) {
|
|
78
|
-
return function (arg) {
|
|
79
|
-
if (typeof arg === "function") {
|
|
80
|
-
handlersMap[pin] = arg;
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
// 通知外部有输入调用(用于 scope 插槽的 inputValues 更新)
|
|
84
|
-
onInputCall === null || onInputCall === void 0 || onInputCall(pin, arg);
|
|
85
|
-
var handler = handlersMap[pin];
|
|
86
|
-
if (typeof handler === "function") {
|
|
87
|
-
return createReactiveInputHandler({
|
|
88
|
-
input: handler,
|
|
89
|
-
value: arg,
|
|
90
|
-
rels: {},
|
|
91
|
-
title: title
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
export function useEnhancedSlots(rawSlots, id) {
|
|
99
|
-
var _useAppContext = useAppContext(),
|
|
100
|
-
parentComRefs = _useAppContext.comRefs,
|
|
101
|
-
todoPool = _useAppContext.todoPool;
|
|
102
|
-
var slotStoreRef = useRef({});
|
|
103
|
-
// 用于触发重渲染的状态
|
|
104
|
-
var _useState = useState({}),
|
|
105
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
106
|
-
forceUpdate = _useState2[1];
|
|
107
|
-
return useMemo(function () {
|
|
108
|
-
if (!rawSlots) return {};
|
|
109
|
-
var nextSlots = {};
|
|
110
|
-
Object.entries(rawSlots).forEach(function (_ref) {
|
|
111
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
112
|
-
slotKey = _ref2[0],
|
|
113
|
-
slotDef = _ref2[1];
|
|
114
|
-
// 创建输入回调,当 inputs 被调用时更新 inputValues 并触发重渲染
|
|
115
|
-
var onInputCall = function onInputCall(pin, value) {
|
|
116
|
-
var state = slotStoreRef.current[slotKey];
|
|
117
|
-
if (state) {
|
|
118
|
-
if (!state._inputValues) state._inputValues = {};
|
|
119
|
-
state._inputValues[pin] = value;
|
|
120
|
-
// 触发重渲染
|
|
121
|
-
forceUpdate({});
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
var state = slotStoreRef.current[slotKey] || (slotStoreRef.current[slotKey] = {
|
|
125
|
-
inputs: createChannelProxy("".concat(id, ".").concat(slotKey, ".inputs"), onInputCall),
|
|
126
|
-
outputs: createChannelProxy("".concat(id, ".").concat(slotKey, ".outputs")),
|
|
127
|
-
_inputs: createChannelProxy("".concat(id, ".").concat(slotKey, "._inputs")),
|
|
128
|
-
_scopedComRefs: {},
|
|
129
|
-
_inputValues: {},
|
|
130
|
-
_render: undefined,
|
|
131
|
-
render: function render(params) {
|
|
132
|
-
var _state$_lastMergedPar, _stableParams$inputVa, _stableParams$inputVa2, _stableParams$inputVa3, _stableParams$inputVa4, _state$_scopedComRefs;
|
|
133
|
-
var r = state._render;
|
|
134
|
-
var mergedParams = mergeSlotParams(state._inputValues, params);
|
|
135
|
-
|
|
136
|
-
// 浅比较 inputValues,内容不变时复用上次引用,避免 useEffect 死循环
|
|
137
|
-
if (state._lastMergedParams && shallowEqual(mergedParams === null || mergedParams === void 0 ? void 0 : mergedParams.inputValues, (_state$_lastMergedPar = state._lastMergedParams) === null || _state$_lastMergedPar === void 0 ? void 0 : _state$_lastMergedPar.inputValues)) {
|
|
138
|
-
// 内容没变,复用旧引用
|
|
139
|
-
} else {
|
|
140
|
-
state._lastMergedParams = mergedParams;
|
|
141
|
-
}
|
|
142
|
-
var stableParams = state._lastMergedParams;
|
|
143
|
-
|
|
144
|
-
// 只有存在 key 或 index 时才认为是"多实例作用域插槽",需要实例隔离
|
|
145
|
-
var rawScope = (_stableParams$inputVa = stableParams === null || stableParams === void 0 || (_stableParams$inputVa2 = stableParams.inputValues) === null || _stableParams$inputVa2 === void 0 ? void 0 : _stableParams$inputVa2.index) !== null && _stableParams$inputVa !== void 0 ? _stableParams$inputVa : params === null || params === void 0 ? void 0 : params.key;
|
|
146
|
-
if (rawScope === undefined || rawScope === null) {
|
|
147
|
-
return /*#__PURE__*/React.createElement(SlotParamsBridge, {
|
|
148
|
-
state: state,
|
|
149
|
-
params: stableParams,
|
|
150
|
-
render: r
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
var scopeId = createScopeId(id, slotKey, rawScope);
|
|
154
|
-
var index = (_stableParams$inputVa3 = stableParams === null || stableParams === void 0 || (_stableParams$inputVa4 = stableParams.inputValues) === null || _stableParams$inputVa4 === void 0 ? void 0 : _stableParams$inputVa4.index) !== null && _stableParams$inputVa3 !== void 0 ? _stableParams$inputVa3 : 0;
|
|
155
|
-
var scopedComRefs = (_state$_scopedComRefs = state._scopedComRefs)[scopeId] || (_state$_scopedComRefs[scopeId] = createPenetratingComRefs(parentComRefs, todoPool, index));
|
|
156
|
-
return /*#__PURE__*/React.createElement(ScopedComContextProvider, {
|
|
157
|
-
comRefs: scopedComRefs,
|
|
158
|
-
scopeId: scopeId
|
|
159
|
-
}, /*#__PURE__*/React.createElement(SlotParamsBridge, {
|
|
160
|
-
state: state,
|
|
161
|
-
params: stableParams,
|
|
162
|
-
render: r
|
|
163
|
-
}));
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
state._render = slotDef === null || slotDef === void 0 ? void 0 : slotDef.render;
|
|
167
|
-
nextSlots[slotKey] = _objectSpread(_objectSpread({}, slotDef || {}), {}, {
|
|
168
|
-
render: state.render,
|
|
169
|
-
inputs: state.inputs,
|
|
170
|
-
outputs: state.outputs,
|
|
171
|
-
_inputs: state._inputs
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
return nextSlots;
|
|
175
|
-
}, [rawSlots, id, parentComRefs, todoPool]);
|
|
176
|
-
}
|
|
177
|
-
export function ScopedComContextProvider(props) {
|
|
178
|
-
var parent = useAppContext();
|
|
179
|
-
var value = useMemo(function () {
|
|
180
|
-
return _objectSpread(_objectSpread({}, parent), {}, {
|
|
181
|
-
comRefs: props.comRefs || parent.comRefs,
|
|
182
|
-
$scopeId: props.scopeId
|
|
183
|
-
});
|
|
184
|
-
}, [parent, props.comRefs, props.scopeId]);
|
|
185
|
-
return /*#__PURE__*/React.createElement(ComContext.Provider, {
|
|
186
|
-
value: value
|
|
187
|
-
}, props.children);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/** parentSlot 解析:props 优先,其次用 SlotProvider 注入的 context */
|
|
191
|
-
export function useResolvedParentSlot(parentSlotProp) {
|
|
192
|
-
var parentSlotFromCtx = useParentSlot();
|
|
193
|
-
return parentSlotProp !== null && parentSlotProp !== void 0 ? parentSlotProp : parentSlotFromCtx;
|
|
194
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
-
import { EventEmitter } from "./event";
|
|
5
|
-
var isDefine = function isDefine(val) {
|
|
6
|
-
return val !== undefined && val !== null && val !== '';
|
|
7
|
-
};
|
|
8
|
-
var TabbarInstance = /*#__PURE__*/_createClass(function TabbarInstance() {
|
|
9
|
-
var _this = this;
|
|
10
|
-
_classCallCheck(this, TabbarInstance);
|
|
11
|
-
_defineProperty(this, "list", []);
|
|
12
|
-
_defineProperty(this, "eventEmitter", new EventEmitter());
|
|
13
|
-
_defineProperty(this, "setTabBarBadge", function (_ref) {
|
|
14
|
-
var index = _ref.index,
|
|
15
|
-
text = _ref.text;
|
|
16
|
-
return new Promise(function (resolve, reject) {
|
|
17
|
-
if (isDefine(index)) {
|
|
18
|
-
_this.list[index].active = true;
|
|
19
|
-
_this.list[index].activeText = text;
|
|
20
|
-
console.log('change', _this.list);
|
|
21
|
-
_this.eventEmitter.dispatch('change', _this.list);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
_defineProperty(this, "hideTabBarRedDot", function (_ref2) {
|
|
26
|
-
var index = _ref2.index;
|
|
27
|
-
return new Promise(function (resolve, reject) {
|
|
28
|
-
if (isDefine(index)) {
|
|
29
|
-
_this.list[index].active = false;
|
|
30
|
-
_this.list[index].activeText = 0;
|
|
31
|
-
_this.eventEmitter.dispatch('change', _this.list);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
_defineProperty(this, "removeTabBarBadge", this.hideTabBarRedDot);
|
|
36
|
-
_defineProperty(this, "initWithLength", function (len) {
|
|
37
|
-
_this.list = new Array(len).fill(function (t) {
|
|
38
|
-
return null;
|
|
39
|
-
}).map(function () {
|
|
40
|
-
return {
|
|
41
|
-
active: false,
|
|
42
|
-
activeText: ''
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
export var tabbarIns = new TabbarInstance();
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
-
var _excluded = ["success", "fail"];
|
|
5
|
-
import { useRef, useState, useMemo } from 'react';
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
import * as Taro from '@tarojs/taro';
|
|
8
|
-
// @ts-ignore
|
|
9
|
-
import { request as _request } from '@/common/request';
|
|
10
|
-
import { tabbarIns } from "@/core/utils/tabbar";
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
import rootConfig from '@/common/rootConfig';
|
|
13
|
-
import { proxyRefs } from "./hooks";
|
|
14
|
-
import { TodoPool } from "./pool";
|
|
15
|
-
export function useAppCreateContext(id) {
|
|
16
|
-
var todoPool = useMemo(function () {
|
|
17
|
-
return new TodoPool();
|
|
18
|
-
}, []);
|
|
19
|
-
var comRefs = useRef(proxyRefs({
|
|
20
|
-
$inputs: {},
|
|
21
|
-
$outputs: {}
|
|
22
|
-
}, undefined, todoPool));
|
|
23
|
-
var $vars = useRef({});
|
|
24
|
-
var $fxs = useRef({});
|
|
25
|
-
var _useState = useState({
|
|
26
|
-
visible: false,
|
|
27
|
-
name: '',
|
|
28
|
-
value: null,
|
|
29
|
-
controller: null
|
|
30
|
-
}),
|
|
31
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
32
|
-
popupState = _useState2[0],
|
|
33
|
-
setPopupState = _useState2[1];
|
|
34
|
-
var appContext = useRef({
|
|
35
|
-
canvas: {
|
|
36
|
-
id: id
|
|
37
|
-
},
|
|
38
|
-
runtime: {
|
|
39
|
-
debug: false
|
|
40
|
-
},
|
|
41
|
-
env: {
|
|
42
|
-
runtime: true,
|
|
43
|
-
request: function request(connector, params, config) {
|
|
44
|
-
return _request(connector, params, config, {
|
|
45
|
-
$vars: $vars
|
|
46
|
-
});
|
|
47
|
-
},
|
|
48
|
-
tabbar: tabbarIns,
|
|
49
|
-
uploadFile: function uploadFile(params) {
|
|
50
|
-
var _rootConfig$status;
|
|
51
|
-
var header = {};
|
|
52
|
-
var mybricksGlobalHeaders = Taro.getStorageSync("_MYBRICKS_GLOBAL_HEADERS_");
|
|
53
|
-
if (mybricksGlobalHeaders) {
|
|
54
|
-
header = _objectSpread(_objectSpread({}, mybricksGlobalHeaders), header);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 如果 url 不以 http 开头,添加默认域名
|
|
59
|
-
*/
|
|
60
|
-
if (!/^(http|https):\/\/.*/.test(params.url) && rootConfig !== null && rootConfig !== void 0 && (_rootConfig$status = rootConfig.status) !== null && _rootConfig$status !== void 0 && _rootConfig$status.defaultCallServiceHost) {
|
|
61
|
-
var _rootConfig$status2;
|
|
62
|
-
params.url = "".concat(rootConfig === null || rootConfig === void 0 || (_rootConfig$status2 = rootConfig.status) === null || _rootConfig$status2 === void 0 ? void 0 : _rootConfig$status2.defaultCallServiceHost).concat(params.url);
|
|
63
|
-
}
|
|
64
|
-
var _success = params.success,
|
|
65
|
-
_fail = params.fail,
|
|
66
|
-
rest = _objectWithoutProperties(params, _excluded);
|
|
67
|
-
Taro.uploadFile(_objectSpread(_objectSpread({}, rest), {}, {
|
|
68
|
-
success: function success(res) {
|
|
69
|
-
return _success === null || _success === void 0 ? void 0 : _success(res);
|
|
70
|
-
},
|
|
71
|
-
fail: function fail(err) {
|
|
72
|
-
return _fail === null || _fail === void 0 ? void 0 : _fail(err);
|
|
73
|
-
}
|
|
74
|
-
}));
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
rootScroll: {},
|
|
78
|
-
edit: false,
|
|
79
|
-
isH5: false,
|
|
80
|
-
isDesigner: false,
|
|
81
|
-
isPreview: false,
|
|
82
|
-
isRelease: false,
|
|
83
|
-
isDebug: false,
|
|
84
|
-
isLocal: false,
|
|
85
|
-
isTest: false,
|
|
86
|
-
tabBar: [],
|
|
87
|
-
useTabBar: false
|
|
88
|
-
}).current;
|
|
89
|
-
return useMemo(function () {
|
|
90
|
-
return {
|
|
91
|
-
comRefs: comRefs,
|
|
92
|
-
$vars: $vars,
|
|
93
|
-
$fxs: $fxs,
|
|
94
|
-
todoPool: todoPool,
|
|
95
|
-
appContext: appContext,
|
|
96
|
-
popupState: popupState,
|
|
97
|
-
setPopupState: setPopupState
|
|
98
|
-
};
|
|
99
|
-
}, [popupState]);
|
|
100
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
|
-
var _excluded = ["component", "id", "data", "className", "style"],
|
|
6
|
-
_excluded2 = ["slots", "parentSlot"];
|
|
7
|
-
import React, { useState, useEffect } from 'react';
|
|
8
|
-
// @ts-ignore 运行时由宿主项目提供 @tarojs/components
|
|
9
|
-
import { View } from '@tarojs/components';
|
|
10
|
-
import { useModel, useBindInputs, useBuiltinHandlers, useBindOutputs, subscribePopupRouter, closeActivePopupRouter } from "./index";
|
|
11
|
-
import { useAppCreateContext } from "./useContext";
|
|
12
|
-
import ComContext, { useAppContext } from "./ComContext";
|
|
13
|
-
import { useEnhancedSlots, useResolvedParentSlot } from "./slots";
|
|
14
|
-
// @ts-ignore 运行时由宿主项目提供 @tarojs/taro
|
|
15
|
-
import { useTabItemTap } from '@tarojs/taro';
|
|
16
|
-
export var WithCom = function WithCom(props) {
|
|
17
|
-
var _parentSlot$params;
|
|
18
|
-
var Component = props.component,
|
|
19
|
-
_props$id = props.id,
|
|
20
|
-
id = _props$id === void 0 ? '' : _props$id,
|
|
21
|
-
data = props.data,
|
|
22
|
-
className = props.className,
|
|
23
|
-
style = props.style,
|
|
24
|
-
rest = _objectWithoutProperties(props, _excluded);
|
|
25
|
-
var _useAppContext = useAppContext(),
|
|
26
|
-
comRefs = _useAppContext.comRefs,
|
|
27
|
-
appContext = _useAppContext.appContext;
|
|
28
|
-
var env = appContext; //TODO: 需要根据实际情况修改
|
|
29
|
-
|
|
30
|
-
var isPopup = Component.isPopup;
|
|
31
|
-
var _useState = useState(true),
|
|
32
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
33
|
-
show = _useState2[0],
|
|
34
|
-
setShow = _useState2[1];
|
|
35
|
-
var _useState3 = useState({}),
|
|
36
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
37
|
-
dynamicStyle = _useState4[0],
|
|
38
|
-
setDynamicStyle = _useState4[1];
|
|
39
|
-
|
|
40
|
-
//数据模型
|
|
41
|
-
var _data = useModel(data || {});
|
|
42
|
-
var _ref = rest,
|
|
43
|
-
rawSlots = _ref.slots,
|
|
44
|
-
parentSlotProp = _ref.parentSlot,
|
|
45
|
-
restProps = _objectWithoutProperties(_ref, _excluded2);
|
|
46
|
-
var parentSlot = useResolvedParentSlot(parentSlotProp);
|
|
47
|
-
var enhancedSlots = useEnhancedSlots(rawSlots, id);
|
|
48
|
-
|
|
49
|
-
// ---- inputs ----
|
|
50
|
-
var handlers = useBuiltinHandlers({
|
|
51
|
-
data: _data,
|
|
52
|
-
setDynamicStyle: setDynamicStyle,
|
|
53
|
-
setShow: setShow,
|
|
54
|
-
isPopup: isPopup
|
|
55
|
-
});
|
|
56
|
-
var inputProxy = useBindInputs(comRefs, id, handlers);
|
|
57
|
-
|
|
58
|
-
// ---- outputs ----
|
|
59
|
-
var outputProxy = useBindOutputs(comRefs, id, restProps, enhancedSlots, {
|
|
60
|
-
id: id,
|
|
61
|
-
name: props.name || id,
|
|
62
|
-
parentSlot: parentSlot
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// ---- render ----
|
|
66
|
-
var jsx = /*#__PURE__*/React.createElement(Component, _extends({}, restProps, {
|
|
67
|
-
inputs: inputProxy,
|
|
68
|
-
outputs: outputProxy,
|
|
69
|
-
slots: enhancedSlots,
|
|
70
|
-
parentSlot: parentSlot,
|
|
71
|
-
data: _data,
|
|
72
|
-
env: env,
|
|
73
|
-
id: id,
|
|
74
|
-
style: style
|
|
75
|
-
}));
|
|
76
|
-
if (parentSlot !== null && parentSlot !== void 0 && (_parentSlot$params = parentSlot.params) !== null && _parentSlot$params !== void 0 && _parentSlot$params.itemWrap) {
|
|
77
|
-
return parentSlot.params.itemWrap({
|
|
78
|
-
id: id,
|
|
79
|
-
name: props.name || id,
|
|
80
|
-
jsx: jsx,
|
|
81
|
-
def: Component.def,
|
|
82
|
-
inputs: inputProxy,
|
|
83
|
-
outputs: outputProxy,
|
|
84
|
-
style: style
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
return show || isPopup ? /*#__PURE__*/React.createElement(View, {
|
|
88
|
-
id: id,
|
|
89
|
-
className: className,
|
|
90
|
-
style: _objectSpread(_objectSpread({}, style), dynamicStyle)
|
|
91
|
-
}, jsx, props.children) : null;
|
|
92
|
-
};
|
|
93
|
-
export var WithWrapper = function WithWrapper(id, Component) {
|
|
94
|
-
return function WrappedComponent(props) {
|
|
95
|
-
var contextStore = useAppCreateContext(id);
|
|
96
|
-
var setPopupState = contextStore.setPopupState;
|
|
97
|
-
var isPopup = Component.isPopup;
|
|
98
|
-
|
|
99
|
-
// 通过发布订阅模式解耦弹窗状态变化
|
|
100
|
-
useEffect(function () {
|
|
101
|
-
return subscribePopupRouter(function (state) {
|
|
102
|
-
return setPopupState(state);
|
|
103
|
-
});
|
|
104
|
-
}, [setPopupState]);
|
|
105
|
-
|
|
106
|
-
// 点击 TabBar 时自动关闭弹窗(自定义 TabBar 或原生 TabBar 点击均会触发)
|
|
107
|
-
useTabItemTap(function () {
|
|
108
|
-
if (isPopup) return;
|
|
109
|
-
closeActivePopupRouter();
|
|
110
|
-
});
|
|
111
|
-
return /*#__PURE__*/React.createElement(ComContext.Provider, {
|
|
112
|
-
value: contextStore
|
|
113
|
-
}, /*#__PURE__*/React.createElement(Component, props));
|
|
114
|
-
};
|
|
115
|
-
};
|