@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,8 +0,0 @@
1
- export var log = function log() {
2
- // console.log("[MyBricks]", ...args)
3
- };
4
- export var logger = {
5
- info: log,
6
- warn: log,
7
- error: log
8
- };
@@ -1,41 +0,0 @@
1
- import _typeof from "@babel/runtime/helpers/esm/typeof";
2
- export var safeSetByPath = function safeSetByPath(params) {
3
- var data = params.data,
4
- path = params.path,
5
- value = params.value;
6
- var nextIndex = path.length - 1;
7
- var current = data;
8
- var errorFlag = false;
9
- for (var i = 0; i < nextIndex; i++) {
10
- try {
11
- current = current[path[i]];
12
- } catch (error) {
13
- errorFlag = true;
14
- break;
15
- }
16
- }
17
- if (!errorFlag) {
18
- current[path[nextIndex]] = value;
19
- }
20
- };
21
- export var safeGetByPath = function safeGetByPath(params) {
22
- var data = params.data,
23
- path = params.path;
24
- var current = data;
25
- var errorFlag = false;
26
- for (var i = 0; i < path.length; i++) {
27
- try {
28
- current = current[path[i]];
29
- } catch (error) {
30
- errorFlag = true;
31
- break;
32
- }
33
- }
34
- if (!errorFlag) {
35
- return current;
36
- }
37
- return undefined;
38
- };
39
- export var isObject = function isObject(value) {
40
- return value && _typeof(value) === "object";
41
- };
@@ -1,190 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { Subject } from "./Subject";
3
- import { context } from "./context";
4
- import { safeSetByPath, safeGetByPath } from "./utils";
5
- import { SUBJECT_NEXT, SUBJECT_SUBSCRIBE, SUBJECT_VALUE, SUBJECT_EMPTY, SUBJECT_SETVALUE } from "./constant";
6
-
7
- /** 创建变量 */
8
- export var createVariable = function createVariable() {
9
- var hasDefaultValue = arguments.length > 0;
10
- var initValue = arguments.length <= 0 ? undefined : arguments[0];
11
- var value = new Subject();
12
- if (hasDefaultValue) {
13
- value[SUBJECT_NEXT](initValue);
14
- }
15
- var ref = {
16
- value: value,
17
- callBacksMap: new Map(),
18
- // 注册change后,设置一个subject,用于触发change
19
- changeValues: new Set(),
20
- // change到上述subject的映射
21
- changeValuesMap: new Map()
22
- };
23
- var variable = {
24
- /** 读取 */get: function get(value, path) {
25
- var nextValue = new Subject();
26
- var next = function next() {
27
- nextValue[SUBJECT_NEXT](path ? safeGetByPath({
28
- data: ref.value[SUBJECT_VALUE],
29
- path: path.split(".")
30
- }) : ref.value[SUBJECT_VALUE]);
31
- };
32
- if (value !== null && value !== void 0 && value[SUBJECT_SUBSCRIBE]) {
33
- value[SUBJECT_SUBSCRIBE](function () {
34
- next();
35
- });
36
- } else {
37
- next();
38
- }
39
- return nextValue;
40
- },
41
- /** 赋值 */set: function set(value, path) {
42
- var nextValue = new Subject();
43
- var next = function next(value, extra) {
44
- if (path) {
45
- var isEmpty = ref.value[SUBJECT_EMPTY];
46
- if (isEmpty) {
47
- ref.value[SUBJECT_SETVALUE]({});
48
- }
49
- safeSetByPath({
50
- data: ref.value[SUBJECT_VALUE],
51
- path: path.split("."),
52
- value: value
53
- });
54
- value = ref.value[SUBJECT_VALUE];
55
- }
56
- ref.value[SUBJECT_NEXT](value, extra);
57
- ref.changeValues.forEach(function (changeValue) {
58
- changeValue[SUBJECT_NEXT](value, extra);
59
- });
60
- nextValue[SUBJECT_NEXT](value, extra);
61
- };
62
- if (value !== null && value !== void 0 && value[SUBJECT_SUBSCRIBE]) {
63
- value[SUBJECT_SUBSCRIBE](function (value, extra) {
64
- next(value, extra);
65
- });
66
- } else {
67
- next(value);
68
- }
69
- return nextValue;
70
- },
71
- /** 重置 */reset: function reset(value) {
72
- var nextValue = new Subject();
73
- var next = function next() {
74
- ref.value[SUBJECT_NEXT](initValue);
75
- ref.changeValues.forEach(function (changeValue) {
76
- changeValue[SUBJECT_NEXT](initValue);
77
- });
78
- nextValue[SUBJECT_NEXT](initValue);
79
- };
80
- if (value !== null && value !== void 0 && value[SUBJECT_SUBSCRIBE]) {
81
- value[SUBJECT_SUBSCRIBE](function () {
82
- next();
83
- });
84
- } else {
85
- next();
86
- }
87
- return nextValue;
88
- },
89
- /** 值变更监听 */changed: function changed() {
90
- var changeValue = new Subject();
91
- ref.changeValues.add(changeValue);
92
- var result = _defineProperty({
93
- destroy: function destroy() {
94
- ref.changeValues.delete(changeValue);
95
- }
96
- }, SUBJECT_SUBSCRIBE, function (next) {
97
- changeValue[SUBJECT_SUBSCRIBE](next);
98
- });
99
- if (context.apiRun) {
100
- if (!context.apiRunVariablesSubject[context.apiRun]) {
101
- context.apiRunVariablesSubject[context.apiRun] = [result];
102
- } else {
103
- context.apiRunVariablesSubject[context.apiRun].push(result);
104
- }
105
- }
106
- return result;
107
- },
108
- bind: function bind(callBack) {
109
- if (!ref.callBacksMap.has("")) {
110
- ref.callBacksMap.set("", new Set());
111
- }
112
- var callBacks = ref.callBacksMap.get("");
113
- callBacks.add(callBack);
114
- // 默认触发一次
115
- callBack(ref.value[SUBJECT_VALUE]);
116
- },
117
- ext: function ext() {
118
- return {
119
- setValue: function setValue(value) {
120
- variable.set(value);
121
- },
122
- getValue: function getValue() {
123
- return ref.value[SUBJECT_VALUE];
124
- }
125
- };
126
- },
127
- registerChange: function registerChange(change) {
128
- var changeValue = new Subject();
129
- // 默认执行,进行初始化动作
130
- change(changeValue);
131
- ref.changeValues.add(changeValue);
132
- ref.changeValuesMap.set(change, changeValue);
133
- if (!ref.value[SUBJECT_EMPTY]) {
134
- // 有值就默认执行
135
- changeValue[SUBJECT_NEXT](ref.value[SUBJECT_VALUE]);
136
- }
137
- },
138
- unregisterChange: function unregisterChange(change) {
139
- var changeValue = ref.changeValuesMap.get(change);
140
- ref.changeValues.delete(changeValue);
141
- ref.changeValuesMap.delete(change);
142
- },
143
- // 内置的赋值操作
144
- setTrue: function setTrue() {
145
- return variable.set(true);
146
- },
147
- setFalse: function setFalse() {
148
- return variable.set(false);
149
- },
150
- setAryAdd: function setAryAdd(value) {
151
- var nextValue = new Subject();
152
- if (Array.isArray(ref.value[SUBJECT_VALUE])) {
153
- var next = function next(value) {
154
- var arrayValue = ref.value[SUBJECT_VALUE].concat(value);
155
- ref.value[SUBJECT_NEXT](arrayValue);
156
- ref.changeValues.forEach(function (changeValue) {
157
- changeValue[SUBJECT_NEXT](value);
158
- });
159
- nextValue[SUBJECT_NEXT](arrayValue);
160
- };
161
- if (value !== null && value !== void 0 && value[SUBJECT_SUBSCRIBE]) {
162
- value[SUBJECT_SUBSCRIBE](function (value) {
163
- next(value);
164
- });
165
- } else {
166
- next(value);
167
- }
168
- }
169
- return nextValue;
170
- }
171
- };
172
- return new Proxy({}, {
173
- get: function get(_, key) {
174
- return variable[key];
175
- }
176
- });
177
- };
178
-
179
- /** 创建变量map */
180
- export var createVars = function createVars(vars) {
181
- return new Proxy(vars, {
182
- get: function get(target, key) {
183
- var value = target[key];
184
- if (value) {
185
- return value.get()[SUBJECT_VALUE];
186
- }
187
- return value;
188
- }
189
- });
190
- };
@@ -1,16 +0,0 @@
1
- import { createContext, useContext } from 'react';
2
- export { pageRouter } from "./pageRouter";
3
- var ComContext = /*#__PURE__*/createContext(undefined);
4
- var SlotContext = /*#__PURE__*/createContext(null);
5
- export function useAppContext() {
6
- var context = useContext(ComContext);
7
- if (!context) {
8
- throw new Error('useAppContext must be used within a ComContext.Provider');
9
- }
10
- return context;
11
- }
12
- export function useParentSlot() {
13
- return useContext(SlotContext);
14
- }
15
- export var SlotProvider = SlotContext.Provider;
16
- export default ComContext;
@@ -1,27 +0,0 @@
1
- import React from 'react';
2
- import { View } from '@tarojs/components';
3
- import { useAppContext } from "./ComContext";
4
- export var PopupRenderer = function PopupRenderer(_ref) {
5
- var popupMap = _ref.popupMap;
6
- var _useAppContext = useAppContext(),
7
- popupState = _useAppContext.popupState;
8
- var ActivePopup = popupState.visible && popupMap[popupState.name] ? popupMap[popupState.name] : null;
9
- if (!ActivePopup) return /*#__PURE__*/React.createElement(View, null);
10
- return /*#__PURE__*/React.createElement(View, {
11
- className: "global-popup-container",
12
- style: {
13
- position: 'fixed',
14
- top: 0,
15
- left: 0,
16
- right: 0,
17
- bottom: 0,
18
- zIndex: 999999,
19
- pointerEvents: 'auto'
20
- }
21
- }, /*#__PURE__*/React.createElement(View, {
22
- style: {
23
- width: '100%',
24
- height: '100%'
25
- }
26
- }, /*#__PURE__*/React.createElement(ActivePopup, null)));
27
- };
@@ -1,134 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import { TodoPool } from "./pool";
4
-
5
- /**
6
- * 组件引用解析器
7
- *
8
- * 职责单一:管理组件引用的查找、创建和注册
9
- *
10
- * 核心机制:
11
- * 1. 查找真实引用时,优先本地,再查父级
12
- * 2. 未找到时创建影子对象,影子对象调用时会动态查找真实引用
13
- * 3. 注册真实引用时,向上渗透到父级
14
- */
15
- export var ComRefResolver = /*#__PURE__*/function () {
16
- function ComRefResolver(registry, parent, todoPool) {
17
- var scopeIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
18
- _classCallCheck(this, ComRefResolver);
19
- this.registry = registry;
20
- this.parent = parent;
21
- this.todoPool = todoPool;
22
- this.scopeIndex = scopeIndex;
23
- }
24
-
25
- /**
26
- * 获取组件引用
27
- * @returns 真实引用或影子对象
28
- */
29
- _createClass(ComRefResolver, [{
30
- key: "get",
31
- value: function get(id) {
32
- var _this$parent, _this$registry$id;
33
- // 1. 优先检查本地是否有真实引用
34
- if (this.registry[id] && !this.registry[id].__isShadow) {
35
- return this.registry[id];
36
- }
37
-
38
- // 2. 检查父级是否有真实引用
39
- var parentRef = (_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.findRealRef(id);
40
- if (parentRef) {
41
- return parentRef;
42
- }
43
-
44
- // 3. 如果已有影子对象,直接返回
45
- if ((_this$registry$id = this.registry[id]) !== null && _this$registry$id !== void 0 && _this$registry$id.__isShadow) {
46
- return this.registry[id];
47
- }
48
-
49
- // 4. 创建影子对象
50
- return this.createShadowProxy(id);
51
- }
52
-
53
- /**
54
- * 注册真实引用
55
- */
56
- }, {
57
- key: "set",
58
- value: function set(id, ref) {
59
- var _this$parent2;
60
- this.registry[id] = ref;
61
- // 向上渗透到父级
62
- (_this$parent2 = this.parent) === null || _this$parent2 === void 0 || _this$parent2.set(id, ref);
63
- }
64
-
65
- /**
66
- * 删除引用
67
- */
68
- }, {
69
- key: "delete",
70
- value: function _delete(id) {
71
- var _this$parent3;
72
- delete this.registry[id];
73
- (_this$parent3 = this.parent) === null || _this$parent3 === void 0 || _this$parent3.delete(id);
74
- }
75
-
76
- /**
77
- * 查找真实引用(仅用于父级链查找)
78
- */
79
- }, {
80
- key: "findRealRef",
81
- value: function findRealRef(id) {
82
- var _this$parent$findReal, _this$parent4;
83
- var local = this.registry[id];
84
- if (local && !local.__isShadow) {
85
- return local;
86
- }
87
- return (_this$parent$findReal = (_this$parent4 = this.parent) === null || _this$parent4 === void 0 ? void 0 : _this$parent4.findRealRef(id)) !== null && _this$parent$findReal !== void 0 ? _this$parent$findReal : null;
88
- }
89
-
90
- /**
91
- * 创建影子对象
92
- * 关键:影子对象的方法被调用时,会动态查找真实引用
93
- */
94
- }, {
95
- key: "createShadowProxy",
96
- value: function createShadowProxy(id) {
97
- var resolver = this;
98
- var registry = this.registry;
99
- var todoPool = this.todoPool;
100
- var scopeIndex = this.scopeIndex;
101
- var shadow = new Proxy({
102
- __isShadow: true
103
- }, {
104
- get: function get(_, method) {
105
- if (method === '__isShadow') return true;
106
- return function () {
107
- // 动态检查是否已有真实引用
108
- // 注意:这里直接检查 registry[id],因为真实引用注册时会覆盖它
109
- var realRef = registry[id];
110
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
111
- args[_key] = arguments[_key];
112
- }
113
- if (realRef && !realRef.__isShadow) {
114
- if (typeof realRef[method] === 'function') {
115
- return realRef[method].apply(realRef, args);
116
- }
117
- return;
118
- }
119
-
120
- // 未找到真实引用,缓冲到 TodoPool
121
- if (todoPool instanceof TodoPool) {
122
- todoPool.push(id, scopeIndex, method, args);
123
- }
124
- };
125
- }
126
- });
127
-
128
- // 存储影子对象
129
- this.registry[id] = shadow;
130
- return shadow;
131
- }
132
- }]);
133
- return ComRefResolver;
134
- }();
@@ -1,32 +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
- export var EventEmitter = /*#__PURE__*/_createClass(function EventEmitter() {
5
- var _this = this;
6
- _classCallCheck(this, EventEmitter);
7
- _defineProperty(this, "eventsCache", {});
8
- _defineProperty(this, "addEventListner", function (evtName, listner) {
9
- if (!_this.eventsCache[evtName]) {
10
- _this.eventsCache[evtName] = new Set([listner]);
11
- return;
12
- }
13
- _this.eventsCache[evtName].add(listner);
14
- });
15
- _defineProperty(this, "removeEventListner", function (evtName, listner) {
16
- if (_this.eventsCache[evtName]) {
17
- _this.eventsCache[evtName].delete(listner);
18
- }
19
- });
20
- _defineProperty(this, "dispatch", function (evtName, detail) {
21
- var _this$eventsCache$evt;
22
- if (!_this.eventsCache[evtName]) {
23
- // console.warn(`no listner on this ${evtName}`);
24
- return;
25
- }
26
- var hasPreventDefault = false;
27
- ((_this$eventsCache$evt = _this.eventsCache[evtName]) !== null && _this$eventsCache$evt !== void 0 ? _this$eventsCache$evt : []).forEach(function (listner) {
28
- return listner(detail);
29
- });
30
- return hasPreventDefault;
31
- });
32
- });