@next-core/brick-kit 2.136.0 → 2.137.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/CHANGELOG.md +30 -0
- package/dist/index.bundle.js +140 -62
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +140 -62
- package/dist/index.esm.js.map +1 -1
- package/dist/types/core/BrickNode.d.ts +1 -0
- package/dist/types/core/BrickNode.d.ts.map +1 -1
- package/dist/types/core/CollectContracts.d.ts +2 -0
- package/dist/types/core/CollectContracts.d.ts.map +1 -1
- package/dist/types/core/CustomForms/CustomFormContext.d.ts +8 -0
- package/dist/types/core/CustomForms/CustomFormContext.d.ts.map +1 -0
- package/dist/types/core/CustomForms/ExpandCustomForm.d.ts +2 -2
- package/dist/types/core/CustomForms/ExpandCustomForm.d.ts.map +1 -1
- package/dist/types/core/CustomForms/constants.d.ts +4 -0
- package/dist/types/core/CustomForms/constants.d.ts.map +1 -1
- package/dist/types/core/CustomTemplates/expandCustomTemplate.d.ts.map +1 -1
- package/dist/types/core/LocationContext.d.ts.map +1 -1
- package/dist/types/core/Router.d.ts.map +1 -1
- package/dist/types/core/StoryboardContext.d.ts.map +1 -1
- package/dist/types/internal/bindListeners.d.ts +1 -1
- package/dist/types/internal/bindListeners.d.ts.map +1 -1
- package/dist/types/internal/evaluate.d.ts +1 -0
- package/dist/types/internal/evaluate.d.ts.map +1 -1
- package/dist/types/internal/setProperties.d.ts.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,36 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.137.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.136.2...@next-core/brick-kit@2.137.0) (2022-09-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* support to use contract in widgets ([25b3337](https://github.com/easyops-cn/next-core/commit/25b333724f9c45131b209845a7caef3e8597888d))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [2.136.2](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.136.1...@next-core/brick-kit@2.136.2) (2022-09-06)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @next-core/brick-kit
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## [2.136.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.136.0...@next-core/brick-kit@2.136.1) (2022-09-05)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* fix missing runtime brick in event callback ([a5b70be](https://github.com/easyops-cn/next-core/commit/a5b70be68bc6a856b78992320518d0a0e6a41128))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
6
36
|
# [2.136.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.135.1...@next-core/brick-kit@2.136.0) (2022-09-05)
|
|
7
37
|
|
|
8
38
|
|
package/dist/index.bundle.js
CHANGED
|
@@ -2034,7 +2034,7 @@
|
|
|
2034
2034
|
}
|
|
2035
2035
|
|
|
2036
2036
|
if (callback) {
|
|
2037
|
-
var callbackFactory = eventCallbackFactory(callback, () => this.getResolveOptions(_internalApiGetCurrentContext()).mergedContext);
|
|
2037
|
+
var callbackFactory = eventCallbackFactory(callback, () => this.getResolveOptions(_internalApiGetCurrentContext()).mergedContext, null);
|
|
2038
2038
|
promise.then(val => {
|
|
2039
2039
|
callbackFactory("success")({
|
|
2040
2040
|
value: val
|
|
@@ -2343,6 +2343,22 @@
|
|
|
2343
2343
|
});
|
|
2344
2344
|
var getMedia = () => MEDIA;
|
|
2345
2345
|
|
|
2346
|
+
var FormContextMap = new Map();
|
|
2347
|
+
class CustomFormContext {
|
|
2348
|
+
constructor() {
|
|
2349
|
+
_defineProperty__default["default"](this, "formState", void 0);
|
|
2350
|
+
|
|
2351
|
+
_defineProperty__default["default"](this, "id", _.uniqueId("form-ctx-"));
|
|
2352
|
+
|
|
2353
|
+
FormContextMap.set(this.id, this);
|
|
2354
|
+
this.formState = new StoryboardContextWrapper();
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2357
|
+
}
|
|
2358
|
+
function getCustomFormContext(formContextId) {
|
|
2359
|
+
return FormContextMap.get(formContextId);
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2346
2362
|
var symbolForRaw = Symbol.for("pre.evaluated.raw");
|
|
2347
2363
|
var symbolForContext = Symbol.for("pre.evaluated.context");
|
|
2348
2364
|
function isPreEvaluated(raw) {
|
|
@@ -2415,6 +2431,7 @@
|
|
|
2415
2431
|
var attemptToVisitData = attemptToVisitGlobals.has("DATA");
|
|
2416
2432
|
var attemptToVisitTpl = attemptToVisitGlobals.has("TPL");
|
|
2417
2433
|
var attemptToVisitState = attemptToVisitGlobals.has("STATE");
|
|
2434
|
+
var attemptToVisitFormState = attemptToVisitGlobals.has("FORM_STATE");
|
|
2418
2435
|
var attemptToVisitTplOrState = attemptToVisitTpl || attemptToVisitState; // Ignore evaluating if `event` is missing in context.
|
|
2419
2436
|
// Since it should be evaluated during events handling.
|
|
2420
2437
|
|
|
@@ -2466,6 +2483,20 @@
|
|
|
2466
2483
|
}
|
|
2467
2484
|
}
|
|
2468
2485
|
|
|
2486
|
+
if (attemptToVisitFormState && runtimeContext.formContextId) {
|
|
2487
|
+
var formContext = getCustomFormContext(runtimeContext.formContextId);
|
|
2488
|
+
globalVariables.FORM_STATE = getDynamicReadOnlyProxy({
|
|
2489
|
+
get(target, key) {
|
|
2490
|
+
return formContext.formState.getValue(key);
|
|
2491
|
+
},
|
|
2492
|
+
|
|
2493
|
+
ownKeys() {
|
|
2494
|
+
return Array.from(formContext.formState.get().keys());
|
|
2495
|
+
}
|
|
2496
|
+
|
|
2497
|
+
});
|
|
2498
|
+
}
|
|
2499
|
+
|
|
2469
2500
|
var {
|
|
2470
2501
|
app: currentApp,
|
|
2471
2502
|
query,
|
|
@@ -2919,7 +2950,7 @@
|
|
|
2919
2950
|
|
|
2920
2951
|
if (preEvaluated || brickUtils.isEvaluable(value)) {
|
|
2921
2952
|
var runtimeContext = {};
|
|
2922
|
-
var keys = ["event", "tplContextId", "overrideApp", "appendI18nNamespace"];
|
|
2953
|
+
var keys = ["event", "tplContextId", "overrideApp", "appendI18nNamespace", "formContextId"];
|
|
2923
2954
|
|
|
2924
2955
|
for (var key of keys) {
|
|
2925
2956
|
if (context !== null && context !== void 0 && context[key]) {
|
|
@@ -6023,13 +6054,25 @@
|
|
|
6023
6054
|
}();
|
|
6024
6055
|
|
|
6025
6056
|
var contractsMap = new Map();
|
|
6026
|
-
|
|
6057
|
+
var widgetContractMap = new Map();
|
|
6058
|
+
|
|
6059
|
+
var addContract = (contracts, map) => {
|
|
6027
6060
|
contracts === null || contracts === void 0 ? void 0 : contracts.forEach(contract => {
|
|
6028
|
-
|
|
6061
|
+
map.set("".concat(contract.namespaceId, ".").concat(contract.name), contract);
|
|
6029
6062
|
});
|
|
6063
|
+
};
|
|
6064
|
+
|
|
6065
|
+
function collectContract(contracts) {
|
|
6066
|
+
addContract(contracts, contractsMap);
|
|
6067
|
+
}
|
|
6068
|
+
function collectWidgetContract(contracts) {
|
|
6069
|
+
addContract(contracts, widgetContractMap);
|
|
6070
|
+
}
|
|
6071
|
+
function clearCollectWidgetContract() {
|
|
6072
|
+
widgetContractMap.clear();
|
|
6030
6073
|
}
|
|
6031
6074
|
function getContract(name) {
|
|
6032
|
-
return contractsMap.get(name);
|
|
6075
|
+
return contractsMap.get(name) || widgetContractMap.get(name);
|
|
6033
6076
|
}
|
|
6034
6077
|
|
|
6035
6078
|
var flowApiDefinitionPromiseMap = new Map(); // Legacy Custom API: `${namespace}@${name}`
|
|
@@ -6692,7 +6735,7 @@
|
|
|
6692
6735
|
};
|
|
6693
6736
|
}
|
|
6694
6737
|
|
|
6695
|
-
function eventCallbackFactory(callback, getContext) {
|
|
6738
|
+
function eventCallbackFactory(callback, getContext, runtimeBrick) {
|
|
6696
6739
|
return function callbackFactory(type) {
|
|
6697
6740
|
return function (result) {
|
|
6698
6741
|
if (callback !== null && callback !== void 0 && callback[type]) {
|
|
@@ -6702,7 +6745,7 @@
|
|
|
6702
6745
|
});
|
|
6703
6746
|
var context = getContext();
|
|
6704
6747
|
[].concat(callback[type]).forEach(eachHandler => {
|
|
6705
|
-
listenerFactory(eachHandler, context,
|
|
6748
|
+
listenerFactory(eachHandler, context, runtimeBrick)(event);
|
|
6706
6749
|
});
|
|
6707
6750
|
} catch (err) {
|
|
6708
6751
|
// Do not throw errors in `callback.success` or `callback.progress`,
|
|
@@ -6756,7 +6799,7 @@
|
|
|
6756
6799
|
return;
|
|
6757
6800
|
}
|
|
6758
6801
|
|
|
6759
|
-
var callbackFactory = eventCallbackFactory(handler.callback, () => context);
|
|
6802
|
+
var callbackFactory = eventCallbackFactory(handler.callback, () => context, runtimeBrick);
|
|
6760
6803
|
var pollableCallback = {
|
|
6761
6804
|
progress: callbackFactory("progress"),
|
|
6762
6805
|
success: callbackFactory("success"),
|
|
@@ -8275,6 +8318,7 @@
|
|
|
8275
8318
|
|
|
8276
8319
|
var formRenderer = "form-renderer.form-renderer";
|
|
8277
8320
|
var filterProperties = ["instanceId", "brick", "slots", "properties", "events", "if", "context", "bricks", "mountPoint"];
|
|
8321
|
+
var symbolForFormContextId = Symbol.for("form.contextId");
|
|
8278
8322
|
|
|
8279
8323
|
function collectRefsInTemplate(template) {
|
|
8280
8324
|
var refMap = new Map();
|
|
@@ -8373,7 +8417,8 @@
|
|
|
8373
8417
|
var {
|
|
8374
8418
|
bricks,
|
|
8375
8419
|
proxy,
|
|
8376
|
-
state
|
|
8420
|
+
state,
|
|
8421
|
+
contracts
|
|
8377
8422
|
} = template;
|
|
8378
8423
|
|
|
8379
8424
|
var {
|
|
@@ -8389,6 +8434,11 @@
|
|
|
8389
8434
|
proxyBrick.proxy = proxyCopy;
|
|
8390
8435
|
proxyBrick.proxyRefs = new Map();
|
|
8391
8436
|
proxyBrick.stateNames = state === null || state === void 0 ? void 0 : state.map(item => item.name);
|
|
8437
|
+
|
|
8438
|
+
if (contracts) {
|
|
8439
|
+
collectWidgetContract(contracts);
|
|
8440
|
+
}
|
|
8441
|
+
|
|
8392
8442
|
var refToBrickConf = collectRefsInTemplate(template); // Reversed proxies are used for expand storyboard before rendering page.
|
|
8393
8443
|
|
|
8394
8444
|
var reversedProxies = {
|
|
@@ -9956,58 +10006,73 @@
|
|
|
9956
10006
|
}
|
|
9957
10007
|
}
|
|
9958
10008
|
|
|
9959
|
-
function ExpandCustomForm(
|
|
9960
|
-
|
|
9961
|
-
|
|
9962
|
-
|
|
9963
|
-
|
|
9964
|
-
|
|
9965
|
-
|
|
9966
|
-
|
|
9967
|
-
|
|
9968
|
-
|
|
10009
|
+
function ExpandCustomForm(_x, _x2, _x3, _x4) {
|
|
10010
|
+
return _ExpandCustomForm.apply(this, arguments);
|
|
10011
|
+
}
|
|
10012
|
+
|
|
10013
|
+
function _ExpandCustomForm() {
|
|
10014
|
+
_ExpandCustomForm = _asyncToGenerator__default["default"](function* (formData, brickConf, isPreview, context) {
|
|
10015
|
+
var errorBrick = {
|
|
10016
|
+
brick: "presentational-bricks.brick-illustration",
|
|
10017
|
+
properties: {
|
|
10018
|
+
category: "default",
|
|
10019
|
+
header: {
|
|
10020
|
+
title: "参数错误"
|
|
10021
|
+
},
|
|
10022
|
+
mode: "guide",
|
|
10023
|
+
name: "search-empty"
|
|
10024
|
+
}
|
|
10025
|
+
};
|
|
10026
|
+
var formContext = new CustomFormContext();
|
|
10027
|
+
|
|
10028
|
+
if (Array.isArray(formData.context)) {
|
|
10029
|
+
yield formContext.formState.define(formData.context, _objectSpread__default["default"](_objectSpread__default["default"]({}, context), {}, {
|
|
10030
|
+
formContextId: formContext.id
|
|
10031
|
+
}), {});
|
|
9969
10032
|
}
|
|
9970
|
-
};
|
|
9971
10033
|
|
|
9972
|
-
|
|
9973
|
-
|
|
9974
|
-
|
|
9975
|
-
|
|
9976
|
-
|
|
9977
|
-
|
|
9978
|
-
|
|
9979
|
-
|
|
9980
|
-
|
|
9981
|
-
|
|
9982
|
-
|
|
9983
|
-
|
|
9984
|
-
|
|
9985
|
-
|
|
9986
|
-
|
|
9987
|
-
|
|
9988
|
-
|
|
9989
|
-
|
|
10034
|
+
try {
|
|
10035
|
+
var formStoryboard = getStoryboard([formData.formSchema], [], formData.fields, isPreview, formContext.id);
|
|
10036
|
+
formStoryboard[0] = ___default["default"].isEmpty(formStoryboard[0]) ? errorBrick : formStoryboard[0];
|
|
10037
|
+
return _objectSpread__default["default"](_objectSpread__default["default"]({}, brickConf), {}, {
|
|
10038
|
+
brick: "div",
|
|
10039
|
+
slots: {
|
|
10040
|
+
"": {
|
|
10041
|
+
bricks: [{
|
|
10042
|
+
brick: "basic-bricks.micro-view",
|
|
10043
|
+
properties: {
|
|
10044
|
+
style: {
|
|
10045
|
+
padding: "12px"
|
|
10046
|
+
}
|
|
10047
|
+
},
|
|
10048
|
+
slots: {
|
|
10049
|
+
content: {
|
|
10050
|
+
bricks: formStoryboard,
|
|
10051
|
+
type: "bricks"
|
|
10052
|
+
}
|
|
9990
10053
|
}
|
|
9991
|
-
}
|
|
9992
|
-
|
|
9993
|
-
|
|
10054
|
+
}],
|
|
10055
|
+
type: "bricks"
|
|
10056
|
+
}
|
|
9994
10057
|
}
|
|
9995
|
-
}
|
|
9996
|
-
})
|
|
9997
|
-
|
|
9998
|
-
|
|
9999
|
-
|
|
10000
|
-
|
|
10001
|
-
|
|
10002
|
-
|
|
10003
|
-
|
|
10004
|
-
|
|
10005
|
-
|
|
10058
|
+
});
|
|
10059
|
+
} catch (error) {
|
|
10060
|
+
// eslint-disable-next-line no-console
|
|
10061
|
+
console.warn(error.message);
|
|
10062
|
+
return {
|
|
10063
|
+
brick: "div",
|
|
10064
|
+
slots: {
|
|
10065
|
+
"": {
|
|
10066
|
+
bricks: [errorBrick],
|
|
10067
|
+
type: "bricks"
|
|
10068
|
+
}
|
|
10006
10069
|
}
|
|
10007
|
-
}
|
|
10008
|
-
}
|
|
10009
|
-
}
|
|
10070
|
+
};
|
|
10071
|
+
}
|
|
10072
|
+
});
|
|
10073
|
+
return _ExpandCustomForm.apply(this, arguments);
|
|
10010
10074
|
}
|
|
10075
|
+
|
|
10011
10076
|
function getDefaultProperties(_name, fields) {
|
|
10012
10077
|
var field = fields.filter(item => item.fieldId === _name)[0];
|
|
10013
10078
|
|
|
@@ -10240,7 +10305,7 @@
|
|
|
10240
10305
|
return defaultValue;
|
|
10241
10306
|
} else return {};
|
|
10242
10307
|
}
|
|
10243
|
-
function getStoryboard(datasource, result, fields, isPreview) {
|
|
10308
|
+
function getStoryboard(datasource, result, fields, isPreview, formContextId) {
|
|
10244
10309
|
var _loop = function (i) {
|
|
10245
10310
|
var dataItem = datasource[i];
|
|
10246
10311
|
var resultItem = {}; //数据初始化:根据id,字段类型获取默认属性
|
|
@@ -10282,7 +10347,7 @@
|
|
|
10282
10347
|
if (Array.isArray(dataItem.bricks)) {
|
|
10283
10348
|
var _Object$keys;
|
|
10284
10349
|
|
|
10285
|
-
resultItem["slots"] = ___default["default"].groupBy(getStoryboard(dataItem.bricks, [], fields, isPreview), "mountPoint");
|
|
10350
|
+
resultItem["slots"] = ___default["default"].groupBy(getStoryboard(dataItem.bricks, [], fields, isPreview, formContextId), "mountPoint");
|
|
10286
10351
|
(_Object$keys = Object.keys(resultItem["slots"])) === null || _Object$keys === void 0 ? void 0 : _Object$keys.forEach(item => {
|
|
10287
10352
|
resultItem.slots[item] = {
|
|
10288
10353
|
bricks: resultItem.slots[item],
|
|
@@ -10291,6 +10356,9 @@
|
|
|
10291
10356
|
});
|
|
10292
10357
|
}
|
|
10293
10358
|
|
|
10359
|
+
resultItem = _objectSpread__default["default"](_objectSpread__default["default"]({}, resultItem), {}, {
|
|
10360
|
+
[symbolForFormContextId]: formContextId
|
|
10361
|
+
});
|
|
10294
10362
|
result[i] = resultItem;
|
|
10295
10363
|
};
|
|
10296
10364
|
|
|
@@ -10347,7 +10415,8 @@
|
|
|
10347
10415
|
getContext(_ref) {
|
|
10348
10416
|
var {
|
|
10349
10417
|
match,
|
|
10350
|
-
tplContextId
|
|
10418
|
+
tplContextId,
|
|
10419
|
+
formContextId
|
|
10351
10420
|
} = _ref;
|
|
10352
10421
|
var auth = getAuth();
|
|
10353
10422
|
var context = {
|
|
@@ -10367,7 +10436,8 @@
|
|
|
10367
10436
|
flags: this.kernel.getFeatureFlags(),
|
|
10368
10437
|
segues: this.segues,
|
|
10369
10438
|
storyboardContext: this.storyboardContextWrapper.get(),
|
|
10370
|
-
tplContextId
|
|
10439
|
+
tplContextId,
|
|
10440
|
+
formContextId
|
|
10371
10441
|
};
|
|
10372
10442
|
return context;
|
|
10373
10443
|
}
|
|
@@ -10707,10 +10777,12 @@
|
|
|
10707
10777
|
|
|
10708
10778
|
var tplStack = _arguments.length > 4 && _arguments[4] !== undefined ? _arguments[4] : [];
|
|
10709
10779
|
var tplContextId = brickConf[symbolForTplContextId];
|
|
10780
|
+
var formContextId = brickConf[symbolForFormContextId];
|
|
10710
10781
|
|
|
10711
10782
|
var context = _this6.getContext({
|
|
10712
10783
|
match,
|
|
10713
|
-
tplContextId
|
|
10784
|
+
tplContextId,
|
|
10785
|
+
formContextId
|
|
10714
10786
|
}); // First, check whether the brick should be rendered.
|
|
10715
10787
|
|
|
10716
10788
|
|
|
@@ -10740,6 +10812,10 @@
|
|
|
10740
10812
|
tplStack.push(tplTagName);
|
|
10741
10813
|
}
|
|
10742
10814
|
|
|
10815
|
+
if (brickConf.brick === formRenderer) {
|
|
10816
|
+
brickConf.properties.formData = JSON.stringify(brickConf.properties.formData);
|
|
10817
|
+
}
|
|
10818
|
+
|
|
10743
10819
|
var brick = {};
|
|
10744
10820
|
yield _this6.storyboardContextWrapper.define(brickConf.context, context, brick);
|
|
10745
10821
|
yield _this6.preCheckPermissions(brickConf, context);
|
|
@@ -10753,6 +10829,7 @@
|
|
|
10753
10829
|
slotId,
|
|
10754
10830
|
refForProxy: brickConf[symbolForRefForProxy],
|
|
10755
10831
|
tplContextId,
|
|
10832
|
+
formContextId,
|
|
10756
10833
|
iid: brickConf.iid
|
|
10757
10834
|
}, (_brickConf$lifeCycle = brickConf.lifeCycle) !== null && _brickConf$lifeCycle !== void 0 && _brickConf$lifeCycle.onScrollIntoView ? {
|
|
10758
10835
|
lifeCycle: {
|
|
@@ -10798,8 +10875,8 @@
|
|
|
10798
10875
|
}
|
|
10799
10876
|
|
|
10800
10877
|
if (brick.type === formRenderer) {
|
|
10801
|
-
var formData = brick.properties.formData;
|
|
10802
|
-
expandedBrickConf = ExpandCustomForm(formData, brickConf, brick.properties.isPreview);
|
|
10878
|
+
var formData = JSON.parse(brick.properties.formData);
|
|
10879
|
+
expandedBrickConf = yield ExpandCustomForm(formData, brickConf, brick.properties.isPreview, context);
|
|
10803
10880
|
yield _this6.kernel.loadDynamicBricksInBrickConf(expandedBrickConf);
|
|
10804
10881
|
}
|
|
10805
10882
|
|
|
@@ -11866,6 +11943,7 @@
|
|
|
11866
11943
|
_this3.renderId = _.uniqueId("render-id-");
|
|
11867
11944
|
resetAllInjected();
|
|
11868
11945
|
clearPollTimeout();
|
|
11946
|
+
clearCollectWidgetContract();
|
|
11869
11947
|
|
|
11870
11948
|
if (_this3.locationContext) {
|
|
11871
11949
|
_this3.locationContext.resolver.resetRefreshQueue();
|