@mybricks/to-code-taro 1.0.0
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/abstractEventTypeDef.d.ts +11 -0
- package/dist/cjs/abstractEventTypeDef.js +93 -0
- package/dist/cjs/core/comlib/Index.js +45 -0
- package/dist/cjs/core/comlib/_ScanQrcode.js +60 -0
- package/dist/cjs/core/comlib/_SetStorage.js +76 -0
- package/dist/cjs/core/comlib/_ShowToast.js +96 -0
- package/dist/cjs/core/mybricks/MyBricksDescriptor.js +213 -0
- package/dist/cjs/core/mybricks/Subject.js +115 -0
- package/dist/cjs/core/mybricks/constant.js +70 -0
- package/dist/cjs/core/mybricks/context.js +33 -0
- package/dist/cjs/core/mybricks/createEnv.js +39 -0
- package/dist/cjs/core/mybricks/createJSHandle.js +150 -0
- package/dist/cjs/core/mybricks/createModuleEventsHandle.js +49 -0
- package/dist/cjs/core/mybricks/createReactiveInputHandler.js +63 -0
- package/dist/cjs/core/mybricks/event.js +70 -0
- package/dist/cjs/core/mybricks/index.js +871 -0
- package/dist/cjs/core/mybricks/log.js +38 -0
- package/dist/cjs/core/mybricks/utils.js +69 -0
- package/dist/cjs/core/mybricks/variables.js +217 -0
- package/dist/cjs/core/utils/ComContext.js +39 -0
- package/dist/cjs/core/utils/index.js +88 -0
- package/dist/cjs/core/utils/useContext.js +53 -0
- package/dist/cjs/core/utils/with.js +84 -0
- package/dist/cjs/generate/generateTaroProjectJson.d.ts +24 -0
- package/dist/cjs/generate/generateTaroProjectJson.js +101 -0
- package/dist/cjs/generate/generateTaroTempalteJson.d.ts +15 -0
- package/dist/cjs/generate/generateTaroTempalteJson.js +103 -0
- package/dist/cjs/generate/utils/appConfig.d.ts +21 -0
- package/dist/cjs/generate/utils/appConfig.js +47 -0
- package/dist/cjs/generate/utils/commonDir.d.ts +21 -0
- package/dist/cjs/generate/utils/commonDir.js +50 -0
- package/dist/cjs/generate/utils/fileNode.d.ts +17 -0
- package/dist/cjs/generate/utils/fileNode.js +57 -0
- package/dist/cjs/generate/utils/index.d.ts +7 -0
- package/dist/cjs/generate/utils/index.js +29 -0
- package/dist/cjs/generate/utils/tabBarImages.d.ts +14 -0
- package/dist/cjs/generate/utils/tabBarImages.js +36 -0
- package/dist/cjs/handleCom.d.ts +31 -0
- package/dist/cjs/handleCom.js +260 -0
- package/dist/cjs/handleDom.d.ts +19 -0
- package/dist/cjs/handleDom.js +86 -0
- package/dist/cjs/handleExtension.d.ts +10 -0
- package/dist/cjs/handleExtension.js +300 -0
- package/dist/cjs/handleGlobal.d.ts +21 -0
- package/dist/cjs/handleGlobal.js +155 -0
- package/dist/cjs/handleModule.d.ts +15 -0
- package/dist/cjs/handleModule.js +108 -0
- package/dist/cjs/handleSlot.d.ts +27 -0
- package/dist/cjs/handleSlot.js +197 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +44 -0
- package/dist/cjs/taro-template.json +5370 -0
- package/dist/cjs/toCodeTaro.d.ts +130 -0
- package/dist/cjs/toCodeTaro.js +427 -0
- package/dist/cjs/utils/code/component.d.ts +19 -0
- package/dist/cjs/utils/code/component.js +85 -0
- package/dist/cjs/utils/code/index.d.ts +18 -0
- package/dist/cjs/utils/code/index.js +71 -0
- package/dist/cjs/utils/code/renderManager.d.ts +22 -0
- package/dist/cjs/utils/code/renderManager.js +80 -0
- package/dist/cjs/utils/code/scene.d.ts +19 -0
- package/dist/cjs/utils/code/scene.js +82 -0
- package/dist/cjs/utils/convertNamespace.d.ts +11 -0
- package/dist/cjs/utils/convertNamespace.js +43 -0
- package/dist/cjs/utils/genJSModules.d.ts +12 -0
- package/dist/cjs/utils/genJSModules.js +116 -0
- package/dist/cjs/utils/getComponentClassName.d.ts +16 -0
- package/dist/cjs/utils/getComponentClassName.js +47 -0
- package/dist/cjs/utils/handlePageConfig.d.ts +24 -0
- package/dist/cjs/utils/handlePageConfig.js +73 -0
- package/dist/cjs/utils/handleProcess.d.ts +9 -0
- package/dist/cjs/utils/handleProcess.js +370 -0
- package/dist/cjs/utils/index.d.ts +62 -0
- package/dist/cjs/utils/index.js +321 -0
- package/dist/cjs/utils/pageConfig/converter.d.ts +17 -0
- package/dist/cjs/utils/pageConfig/converter.js +83 -0
- package/dist/cjs/utils/pageConfig/index.d.ts +10 -0
- package/dist/cjs/utils/pageConfig/index.js +33 -0
- package/dist/cjs/utils/pageConfig/pageConfig.d.ts +10 -0
- package/dist/cjs/utils/pageConfig/pageConfig.js +87 -0
- package/dist/cjs/utils/pageConfig/saveBase64Image.d.ts +14 -0
- package/dist/cjs/utils/pageConfig/saveBase64Image.js +81 -0
- package/dist/cjs/utils/pageConfig/tabBarConfig.d.ts +13 -0
- package/dist/cjs/utils/pageConfig/tabBarConfig.js +74 -0
- package/dist/cjs/utils/pageConfig/types.d.ts +68 -0
- package/dist/cjs/utils/pageConfig/types.js +17 -0
- package/dist/cjs/utils/pageConfig/validator.d.ts +13 -0
- package/dist/cjs/utils/pageConfig/validator.js +67 -0
- package/dist/cjs/utils/pxtransform.d.ts +28 -0
- package/dist/cjs/utils/pxtransform.js +102 -0
- package/dist/esm/abstractEventTypeDef.d.ts +11 -0
- package/dist/esm/abstractEventTypeDef.js +63 -0
- package/dist/esm/core/comlib/Index.js +3 -0
- package/dist/esm/core/comlib/_ScanQrcode.js +27 -0
- package/dist/esm/core/comlib/_SetStorage.js +52 -0
- package/dist/esm/core/comlib/_ShowToast.js +68 -0
- package/dist/esm/core/mybricks/MyBricksDescriptor.js +232 -0
- package/dist/esm/core/mybricks/Subject.js +143 -0
- package/dist/esm/core/mybricks/constant.js +18 -0
- package/dist/esm/core/mybricks/context.js +5 -0
- package/dist/esm/core/mybricks/createEnv.js +9 -0
- package/dist/esm/core/mybricks/createJSHandle.js +138 -0
- package/dist/esm/core/mybricks/createModuleEventsHandle.js +26 -0
- package/dist/esm/core/mybricks/createReactiveInputHandler.js +40 -0
- package/dist/esm/core/mybricks/event.js +44 -0
- package/dist/esm/core/mybricks/index.js +952 -0
- package/dist/esm/core/mybricks/log.js +12 -0
- package/dist/esm/core/mybricks/utils.js +41 -0
- package/dist/esm/core/mybricks/variables.js +190 -0
- package/dist/esm/core/utils/ComContext.js +10 -0
- package/dist/esm/core/utils/index.js +57 -0
- package/dist/esm/core/utils/useContext.js +24 -0
- package/dist/esm/core/utils/with.js +67 -0
- package/dist/esm/generate/generateTaroProjectJson.d.ts +24 -0
- package/dist/esm/generate/generateTaroProjectJson.js +102 -0
- package/dist/esm/generate/generateTaroTempalteJson.d.ts +15 -0
- package/dist/esm/generate/generateTaroTempalteJson.js +94 -0
- package/dist/esm/generate/utils/appConfig.d.ts +21 -0
- package/dist/esm/generate/utils/appConfig.js +30 -0
- package/dist/esm/generate/utils/commonDir.d.ts +21 -0
- package/dist/esm/generate/utils/commonDir.js +36 -0
- package/dist/esm/generate/utils/fileNode.d.ts +17 -0
- package/dist/esm/generate/utils/fileNode.js +49 -0
- package/dist/esm/generate/utils/index.d.ts +7 -0
- package/dist/esm/generate/utils/index.js +8 -0
- package/dist/esm/generate/utils/tabBarImages.d.ts +14 -0
- package/dist/esm/generate/utils/tabBarImages.js +15 -0
- package/dist/esm/handleCom.d.ts +31 -0
- package/dist/esm/handleCom.js +297 -0
- package/dist/esm/handleDom.d.ts +19 -0
- package/dist/esm/handleDom.js +63 -0
- package/dist/esm/handleExtension.d.ts +10 -0
- package/dist/esm/handleExtension.js +243 -0
- package/dist/esm/handleGlobal.d.ts +21 -0
- package/dist/esm/handleGlobal.js +117 -0
- package/dist/esm/handleModule.d.ts +15 -0
- package/dist/esm/handleModule.js +78 -0
- package/dist/esm/handleSlot.d.ts +27 -0
- package/dist/esm/handleSlot.js +205 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/taro-template.json +5370 -0
- package/dist/esm/toCodeTaro.d.ts +130 -0
- package/dist/esm/toCodeTaro.js +452 -0
- package/dist/esm/utils/code/component.d.ts +19 -0
- package/dist/esm/utils/code/component.js +54 -0
- package/dist/esm/utils/code/index.d.ts +18 -0
- package/dist/esm/utils/code/index.js +51 -0
- package/dist/esm/utils/code/renderManager.d.ts +22 -0
- package/dist/esm/utils/code/renderManager.js +62 -0
- package/dist/esm/utils/code/scene.d.ts +19 -0
- package/dist/esm/utils/code/scene.js +47 -0
- package/dist/esm/utils/convertNamespace.d.ts +11 -0
- package/dist/esm/utils/convertNamespace.js +27 -0
- package/dist/esm/utils/genJSModules.d.ts +12 -0
- package/dist/esm/utils/genJSModules.js +44 -0
- package/dist/esm/utils/getComponentClassName.d.ts +16 -0
- package/dist/esm/utils/getComponentClassName.js +37 -0
- package/dist/esm/utils/handlePageConfig.d.ts +24 -0
- package/dist/esm/utils/handlePageConfig.js +68 -0
- package/dist/esm/utils/handleProcess.d.ts +9 -0
- package/dist/esm/utils/handleProcess.js +379 -0
- package/dist/esm/utils/index.d.ts +62 -0
- package/dist/esm/utils/index.js +345 -0
- package/dist/esm/utils/pageConfig/converter.d.ts +17 -0
- package/dist/esm/utils/pageConfig/converter.js +105 -0
- package/dist/esm/utils/pageConfig/index.d.ts +10 -0
- package/dist/esm/utils/pageConfig/index.js +11 -0
- package/dist/esm/utils/pageConfig/pageConfig.d.ts +10 -0
- package/dist/esm/utils/pageConfig/pageConfig.js +60 -0
- package/dist/esm/utils/pageConfig/saveBase64Image.d.ts +14 -0
- package/dist/esm/utils/pageConfig/saveBase64Image.js +105 -0
- package/dist/esm/utils/pageConfig/tabBarConfig.d.ts +13 -0
- package/dist/esm/utils/pageConfig/tabBarConfig.js +82 -0
- package/dist/esm/utils/pageConfig/types.d.ts +68 -0
- package/dist/esm/utils/pageConfig/types.js +1 -0
- package/dist/esm/utils/pageConfig/validator.d.ts +13 -0
- package/dist/esm/utils/pageConfig/validator.js +64 -0
- package/dist/esm/utils/pxtransform.d.ts +28 -0
- package/dist/esm/utils/pxtransform.js +121 -0
- package/package.json +74 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export var log = function log() {
|
|
2
|
+
var _console;
|
|
3
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4
|
+
args[_key] = arguments[_key];
|
|
5
|
+
}
|
|
6
|
+
(_console = console).log.apply(_console, ["[MyBricks]"].concat(args));
|
|
7
|
+
};
|
|
8
|
+
export var logger = {
|
|
9
|
+
info: log,
|
|
10
|
+
warn: log,
|
|
11
|
+
error: log
|
|
12
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,190 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
var ComContext = /*#__PURE__*/createContext(undefined);
|
|
3
|
+
export function useAppContext() {
|
|
4
|
+
var context = useContext(ComContext);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error('useAppContext must be used within a ComContext.Provider');
|
|
7
|
+
}
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export default ComContext;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { useState, useRef, useMemo } from 'react';
|
|
3
|
+
export function useModel(rawData) {
|
|
4
|
+
var _useState = useState({}),
|
|
5
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
6
|
+
forceUpdate = _useState2[1];
|
|
7
|
+
var dataRef = useRef(rawData || {});
|
|
8
|
+
return useMemo(function () {
|
|
9
|
+
return new Proxy(dataRef.current, {
|
|
10
|
+
get: function get(target, key) {
|
|
11
|
+
return Reflect.get(target, key);
|
|
12
|
+
},
|
|
13
|
+
set: function set(target, key, value) {
|
|
14
|
+
var result = Reflect.set(target, key, value);
|
|
15
|
+
forceUpdate({});
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}, []);
|
|
20
|
+
}
|
|
21
|
+
export function useBindInputs(scope, id) {
|
|
22
|
+
return useMemo(function () {
|
|
23
|
+
var controller = scope[id] = scope[id] || {};
|
|
24
|
+
return new Proxy({}, {
|
|
25
|
+
get: function get(_target, pin) {
|
|
26
|
+
return function (arg) {
|
|
27
|
+
if (typeof arg === 'function') {
|
|
28
|
+
controller[pin] = arg;
|
|
29
|
+
} else {
|
|
30
|
+
var callback = controller[pin];
|
|
31
|
+
if (typeof callback === 'function') {
|
|
32
|
+
callback(arg);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}, [scope, id]);
|
|
39
|
+
}
|
|
40
|
+
export function useBindEvents(props) {
|
|
41
|
+
return useMemo(function () {
|
|
42
|
+
var _events = {};
|
|
43
|
+
Object.keys(props).forEach(function (key) {
|
|
44
|
+
if (key.startsWith('on')) {
|
|
45
|
+
var handler = props[key];
|
|
46
|
+
if (typeof handler === 'function') {
|
|
47
|
+
_events[key] = handler;
|
|
48
|
+
_events[key].getConnections = function () {
|
|
49
|
+
return [1];
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return _events;
|
|
55
|
+
}, [props]);
|
|
56
|
+
}
|
|
57
|
+
export { WithCom, WithWrapper } from "./with";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
export function useAppCreateContext() {
|
|
3
|
+
var comRefs = useRef({});
|
|
4
|
+
var appContext = {
|
|
5
|
+
canvas: {
|
|
6
|
+
id: "u_7VvVn" // 使用 data 中的 id
|
|
7
|
+
},
|
|
8
|
+
runtime: {
|
|
9
|
+
debug: false
|
|
10
|
+
},
|
|
11
|
+
edit: false,
|
|
12
|
+
isH5: false,
|
|
13
|
+
isDesigner: false,
|
|
14
|
+
isPreview: false,
|
|
15
|
+
isRelease: false,
|
|
16
|
+
isDebug: false,
|
|
17
|
+
isLocal: false,
|
|
18
|
+
isTest: false
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
comRefs: comRefs,
|
|
22
|
+
appContext: appContext
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["component", "id", "data", "className", "style"];
|
|
5
|
+
import React, { useEffect, useState } from 'react';
|
|
6
|
+
import { View } from '@tarojs/components';
|
|
7
|
+
import { useModel, useBindInputs, useBindEvents } from "./index";
|
|
8
|
+
import { useAppCreateContext } from "./useContext";
|
|
9
|
+
import ComContext, { useAppContext } from "./ComContext";
|
|
10
|
+
export var WithCom = function WithCom(props) {
|
|
11
|
+
var Component = props.component,
|
|
12
|
+
_props$id = props.id,
|
|
13
|
+
id = _props$id === void 0 ? '' : _props$id,
|
|
14
|
+
data = props.data,
|
|
15
|
+
className = props.className,
|
|
16
|
+
style = props.style,
|
|
17
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
18
|
+
var _useAppContext = useAppContext(),
|
|
19
|
+
comRefs = _useAppContext.comRefs,
|
|
20
|
+
appContext = _useAppContext.appContext;
|
|
21
|
+
var env = appContext; //TODO: 需要根据实际情况修改
|
|
22
|
+
|
|
23
|
+
var _useState = useState(true),
|
|
24
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
25
|
+
show = _useState2[0],
|
|
26
|
+
setShow = _useState2[1];
|
|
27
|
+
|
|
28
|
+
//默认事件注册
|
|
29
|
+
useEffect(function () {
|
|
30
|
+
comRefs.current[id].hide(function () {
|
|
31
|
+
setShow(false);
|
|
32
|
+
});
|
|
33
|
+
comRefs.current[id].show(function () {
|
|
34
|
+
setShow(true);
|
|
35
|
+
});
|
|
36
|
+
comRefs.current[id].showOrHide(function () {
|
|
37
|
+
setShow(function (prev) {
|
|
38
|
+
return !prev;
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}, [comRefs]);
|
|
42
|
+
|
|
43
|
+
//数据模型
|
|
44
|
+
var _data = useModel(data || {});
|
|
45
|
+
var inputProxy = useBindInputs(comRefs, id);
|
|
46
|
+
var eventProxy = useBindEvents(rest);
|
|
47
|
+
comRefs.current[id] = inputProxy;
|
|
48
|
+
return show ? /*#__PURE__*/React.createElement(View, {
|
|
49
|
+
className: className,
|
|
50
|
+
style: style
|
|
51
|
+
}, /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
|
|
52
|
+
inputs: inputProxy,
|
|
53
|
+
outputs: eventProxy,
|
|
54
|
+
data: _data,
|
|
55
|
+
env: env,
|
|
56
|
+
id: id,
|
|
57
|
+
style: style
|
|
58
|
+
}))) : null;
|
|
59
|
+
};
|
|
60
|
+
export var WithWrapper = function WithWrapper(Component) {
|
|
61
|
+
return function WrappedComponent(props) {
|
|
62
|
+
var contextStore = useAppCreateContext();
|
|
63
|
+
return /*#__PURE__*/React.createElement(ComContext.Provider, {
|
|
64
|
+
value: contextStore
|
|
65
|
+
}, /*#__PURE__*/React.createElement(Component, props));
|
|
66
|
+
};
|
|
67
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
interface FileNode {
|
|
2
|
+
path: string;
|
|
3
|
+
content: string | null;
|
|
4
|
+
children?: FileNode[];
|
|
5
|
+
}
|
|
6
|
+
interface GenerateItem {
|
|
7
|
+
type: string;
|
|
8
|
+
content?: string;
|
|
9
|
+
cssContent?: string;
|
|
10
|
+
pageConfigContent?: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
importManager?: {
|
|
13
|
+
toCode: () => string;
|
|
14
|
+
};
|
|
15
|
+
tabBarConfig?: string;
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 根据数组生成文件结构 JSON 对象
|
|
20
|
+
* @param items 包含 content、cssContent、pageConfigContent、tabBarConfig 等信息的数组
|
|
21
|
+
* @returns 返回文件结构的 JSON 对象数组
|
|
22
|
+
*/
|
|
23
|
+
declare const generateTaroProjectJson: (items?: GenerateItem[]) => FileNode[];
|
|
24
|
+
export default generateTaroProjectJson;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { findDir, ensureDir } from "./utils/fileNode";
|
|
5
|
+
import { handleCommonDir } from "./utils/commonDir";
|
|
6
|
+
import { handleTabBarImages } from "./utils/tabBarImages";
|
|
7
|
+
import { updateAppConfig } from "./utils/appConfig";
|
|
8
|
+
/**
|
|
9
|
+
* 根据数组生成文件结构 JSON 对象
|
|
10
|
+
* @param items 包含 content、cssContent、pageConfigContent、tabBarConfig 等信息的数组
|
|
11
|
+
* @returns 返回文件结构的 JSON 对象数组
|
|
12
|
+
*/
|
|
13
|
+
var generateTaroProjectJson = function generateTaroProjectJson() {
|
|
14
|
+
var _pagesDir$children, _srcDir$children;
|
|
15
|
+
var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
16
|
+
// 读取模板 JSON 文件
|
|
17
|
+
var templateJsonPath = path.join(__dirname, '../taro-template.json');
|
|
18
|
+
if (!fs.existsSync(templateJsonPath)) {
|
|
19
|
+
throw new Error("\u6A21\u677F\u6587\u4EF6\u4E0D\u5B58\u5728: ".concat(templateJsonPath));
|
|
20
|
+
}
|
|
21
|
+
var templateJson = JSON.parse(fs.readFileSync(templateJsonPath, 'utf-8'));
|
|
22
|
+
|
|
23
|
+
// 找到 src 目录
|
|
24
|
+
var srcDir = templateJson.find(function (node) {
|
|
25
|
+
return node.path === 'src';
|
|
26
|
+
});
|
|
27
|
+
srcDir.children = srcDir.children || [];
|
|
28
|
+
|
|
29
|
+
// 找到 pages 目录
|
|
30
|
+
var pagesDir = findDir(templateJson, 'src/pages');
|
|
31
|
+
if (!pagesDir) {
|
|
32
|
+
throw new Error('未找到 pages 目录');
|
|
33
|
+
}
|
|
34
|
+
pagesDir.children = pagesDir.children || [];
|
|
35
|
+
|
|
36
|
+
// 确保 common 目录存在
|
|
37
|
+
var commonDir = ensureDir(srcDir, 'src/common');
|
|
38
|
+
|
|
39
|
+
// 确保 assets/tabbar 目录存在
|
|
40
|
+
var assetsDir = ensureDir(srcDir, 'src/assets');
|
|
41
|
+
var tabbarDir = ensureDir(assetsDir, 'src/assets/tabbar');
|
|
42
|
+
|
|
43
|
+
// 从 items 的扩展字段中获取 TabBar 图片文件信息
|
|
44
|
+
var imageFiles = items.__tabBarImageFiles || [];
|
|
45
|
+
|
|
46
|
+
// 过滤出类型为 normal 的项
|
|
47
|
+
var normalItems = items.filter(function (item) {
|
|
48
|
+
return item.type === 'normal';
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// 处理所有 normal 类型的项,生成页面节点数组
|
|
52
|
+
var generatedPages = normalItems.map(function (item) {
|
|
53
|
+
var _item$importManager;
|
|
54
|
+
var pageName = item.meta.id;
|
|
55
|
+
|
|
56
|
+
// 生成完整的文件内容:import 语句 + content
|
|
57
|
+
var importCode = ((_item$importManager = item.importManager) === null || _item$importManager === void 0 ? void 0 : _item$importManager.toCode()) || '';
|
|
58
|
+
var fileContent = item.content || '';
|
|
59
|
+
var fullContent = importCode ? "".concat(importCode, "\n").concat(fileContent) : fileContent;
|
|
60
|
+
|
|
61
|
+
// 使用 item 中的 pageConfigContent,如果没有则使用默认配置
|
|
62
|
+
var configContent = item.pageConfigContent || "export default definePageConfig({\n navigationBarTitleText: '\u9875\u9762'\n})";
|
|
63
|
+
|
|
64
|
+
// 固定生成三个文件节点
|
|
65
|
+
var pageChildren = [{
|
|
66
|
+
path: "src/pages/".concat(pageName, "/index.config.ts"),
|
|
67
|
+
content: configContent
|
|
68
|
+
}, {
|
|
69
|
+
path: "src/pages/".concat(pageName, "/index.less"),
|
|
70
|
+
content: item.cssContent || ''
|
|
71
|
+
}, {
|
|
72
|
+
path: "src/pages/".concat(pageName, "/index.tsx"),
|
|
73
|
+
content: fullContent
|
|
74
|
+
}];
|
|
75
|
+
|
|
76
|
+
// 返回页面目录节点
|
|
77
|
+
return {
|
|
78
|
+
path: "src/pages/".concat(pageName),
|
|
79
|
+
content: null,
|
|
80
|
+
children: pageChildren
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// 一次性将所有生成的页面添加到 pages 目录
|
|
85
|
+
(_pagesDir$children = pagesDir.children).push.apply(_pagesDir$children, _toConsumableArray(generatedPages));
|
|
86
|
+
|
|
87
|
+
// 更新 app.config.ts
|
|
88
|
+
var appConfigFile = (_srcDir$children = srcDir.children) === null || _srcDir$children === void 0 ? void 0 : _srcDir$children.find(function (node) {
|
|
89
|
+
return node.path === 'src/app.config.ts';
|
|
90
|
+
});
|
|
91
|
+
if (appConfigFile) {
|
|
92
|
+
updateAppConfig(appConfigFile, normalItems, items);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 处理 TabBar 图片文件
|
|
96
|
+
handleTabBarImages(tabbarDir, imageFiles);
|
|
97
|
+
|
|
98
|
+
// 处理 common 目录下的文件
|
|
99
|
+
handleCommonDir(commonDir, items);
|
|
100
|
+
return templateJson;
|
|
101
|
+
};
|
|
102
|
+
export default generateTaroProjectJson;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface FileNode {
|
|
2
|
+
path: string;
|
|
3
|
+
content: string | null;
|
|
4
|
+
children?: FileNode[];
|
|
5
|
+
}
|
|
6
|
+
interface TemplateJson {
|
|
7
|
+
rootDir: string;
|
|
8
|
+
files: FileNode[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 递归遍历目录并生成文件树结构
|
|
12
|
+
* @param templateDir 模板目录路径,默认为当前文件所在目录下的 template 目录
|
|
13
|
+
*/
|
|
14
|
+
declare const generateTaroTemplateJson: (templateDir?: string) => TemplateJson;
|
|
15
|
+
export default generateTaroTemplateJson;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
var _templateDir = path.join(__dirname, '../_template');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 递归遍历目录并生成文件树结构
|
|
9
|
+
* @param templateDir 模板目录路径,默认为当前文件所在目录下的 template 目录
|
|
10
|
+
*/
|
|
11
|
+
var generateTaroTemplateJson = function generateTaroTemplateJson() {
|
|
12
|
+
var templateDir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _templateDir;
|
|
13
|
+
var rootDir = path.basename(templateDir);
|
|
14
|
+
var files = [];
|
|
15
|
+
|
|
16
|
+
// 需要忽略的目录和文件
|
|
17
|
+
var ignoreList = ['node_modules', 'dist', '.git', '.husky', '.swc', 'yarn.lock', 'package-lock.json'];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 递归读取目录
|
|
21
|
+
*/
|
|
22
|
+
var readDirectory = function readDirectory(dirPath) {
|
|
23
|
+
var relativePath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
24
|
+
var items = [];
|
|
25
|
+
var entries = fs.readdirSync(dirPath, {
|
|
26
|
+
withFileTypes: true
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// 按名称排序,目录在前
|
|
30
|
+
entries.sort(function (a, b) {
|
|
31
|
+
if (a.isDirectory() && !b.isDirectory()) return -1;
|
|
32
|
+
if (!a.isDirectory() && b.isDirectory()) return 1;
|
|
33
|
+
return a.name.localeCompare(b.name);
|
|
34
|
+
});
|
|
35
|
+
var _iterator = _createForOfIteratorHelper(entries),
|
|
36
|
+
_step;
|
|
37
|
+
try {
|
|
38
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
39
|
+
var entry = _step.value;
|
|
40
|
+
// 跳过忽略列表中的项
|
|
41
|
+
if (ignoreList.includes(entry.name)) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
var fullPath = path.join(dirPath, entry.name);
|
|
45
|
+
var itemRelativePath = relativePath ? "".concat(relativePath, "/").concat(entry.name) : entry.name;
|
|
46
|
+
if (entry.isDirectory()) {
|
|
47
|
+
// 递归读取子目录
|
|
48
|
+
var children = readDirectory(fullPath, itemRelativePath);
|
|
49
|
+
items.push({
|
|
50
|
+
path: itemRelativePath,
|
|
51
|
+
content: null,
|
|
52
|
+
children: children.length > 0 ? children : undefined
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
// 读取文件内容
|
|
56
|
+
try {
|
|
57
|
+
var content = fs.readFileSync(fullPath, 'utf-8');
|
|
58
|
+
items.push({
|
|
59
|
+
path: itemRelativePath,
|
|
60
|
+
content: content,
|
|
61
|
+
children: undefined
|
|
62
|
+
});
|
|
63
|
+
} catch (error) {
|
|
64
|
+
// 如果读取失败(如二进制文件),内容设为空字符串
|
|
65
|
+
items.push({
|
|
66
|
+
path: itemRelativePath,
|
|
67
|
+
content: '',
|
|
68
|
+
children: undefined
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} catch (err) {
|
|
74
|
+
_iterator.e(err);
|
|
75
|
+
} finally {
|
|
76
|
+
_iterator.f();
|
|
77
|
+
}
|
|
78
|
+
return items;
|
|
79
|
+
};
|
|
80
|
+
files.push.apply(files, _toConsumableArray(readDirectory(templateDir)));
|
|
81
|
+
// console.log(files);
|
|
82
|
+
|
|
83
|
+
// 写入 JSON 文件,如果已存在则先删除
|
|
84
|
+
var jsonFilePath = path.join(__dirname, '../taro-template.json');
|
|
85
|
+
if (fs.existsSync(jsonFilePath)) {
|
|
86
|
+
fs.unlinkSync(jsonFilePath);
|
|
87
|
+
}
|
|
88
|
+
fs.writeFileSync(jsonFilePath, JSON.stringify(files, null, 2));
|
|
89
|
+
return {
|
|
90
|
+
rootDir: rootDir,
|
|
91
|
+
files: files
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
export default generateTaroTemplateJson;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* app.config.ts 更新工具
|
|
3
|
+
*/
|
|
4
|
+
interface FileNode {
|
|
5
|
+
path: string;
|
|
6
|
+
content: string | null;
|
|
7
|
+
children?: FileNode[];
|
|
8
|
+
}
|
|
9
|
+
interface GenerateItem {
|
|
10
|
+
type: string;
|
|
11
|
+
tabBarConfig?: string;
|
|
12
|
+
meta?: {
|
|
13
|
+
id: string;
|
|
14
|
+
};
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 更新 app.config.ts
|
|
19
|
+
*/
|
|
20
|
+
export declare function updateAppConfig(appConfigFile: FileNode, normalItems: GenerateItem[], items: GenerateItem[]): void;
|
|
21
|
+
export {};
|