@next-core/brick-kit 2.115.1 → 2.117.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 +35 -0
- package/dist/index.bundle.js +162 -36
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +163 -37
- package/dist/index.esm.js.map +1 -1
- package/dist/types/core/CollectContracts.d.ts +4 -0
- package/dist/types/core/CollectContracts.d.ts.map +1 -0
- package/dist/types/core/CustomTemplates/registerCustomTemplate.d.ts.map +1 -1
- package/dist/types/core/FlowApi.d.ts.map +1 -1
- package/dist/types/core/Kernel.d.ts +1 -0
- package/dist/types/core/Kernel.d.ts.map +1 -1
- package/dist/types/core/Router.d.ts.map +1 -1
- package/dist/types/core/Runtime.d.ts +1 -0
- package/dist/types/core/Runtime.d.ts.map +1 -1
- package/dist/types/core/interfaces.d.ts +3 -1
- package/dist/types/core/interfaces.d.ts.map +1 -1
- package/dist/types/developHelper.d.ts +2 -1
- package/dist/types/developHelper.d.ts.map +1 -1
- package/dist/types/providers/CustomApi.d.ts +7 -1
- package/dist/types/providers/CustomApi.d.ts.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,41 @@
|
|
|
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.117.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.116.1...@next-core/brick-kit@2.117.0) (2022-04-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* contract refactor ([a506766](https://github.com/easyops-cn/next-core/commit/a5067664253a51a007b8fea96ddf7efefd7da7d8))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* support previewing template by settings ([b1fa0f9](https://github.com/easyops-cn/next-core/commit/b1fa0f9e4d774a6b4162643348ca49402bde1479))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [2.116.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.116.0...@next-core/brick-kit@2.116.1) (2022-04-06)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @next-core/brick-kit
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# [2.116.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.115.1...@next-core/brick-kit@2.116.0) (2022-04-01)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Features
|
|
34
|
+
|
|
35
|
+
* support re-registering custom templates ([ea91d7d](https://github.com/easyops-cn/next-core/commit/ea91d7de23e0a9d3a935c01a9a103fb44b8cdfb3))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
6
41
|
## [2.115.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.115.0...@next-core/brick-kit@2.115.1) (2022-03-30)
|
|
7
42
|
|
|
8
43
|
**Note:** Version bump only for package @next-core/brick-kit
|
package/dist/index.bundle.js
CHANGED
|
@@ -3175,6 +3175,11 @@
|
|
|
3175
3175
|
function _dev_only_updateStoryboard(appId, storyboardPatch) {
|
|
3176
3176
|
kernel._dev_only_updateStoryboard(appId, storyboardPatch);
|
|
3177
3177
|
}
|
|
3178
|
+
/* istanbul ignore next */
|
|
3179
|
+
|
|
3180
|
+
function _dev_only_updateTemplatePreviewSettings(appId, templateId, settings) {
|
|
3181
|
+
kernel._dev_only_updateTemplatePreviewSettings(appId, templateId, settings);
|
|
3182
|
+
}
|
|
3178
3183
|
class Runtime {
|
|
3179
3184
|
constructor() {
|
|
3180
3185
|
_defineProperty__default["default"](this, "registerBrickTemplate", registerBrickTemplate);
|
|
@@ -5590,6 +5595,16 @@
|
|
|
5590
5595
|
return;
|
|
5591
5596
|
};
|
|
5592
5597
|
|
|
5598
|
+
var contractsMap = new Map();
|
|
5599
|
+
function collectContract(contracts) {
|
|
5600
|
+
contracts === null || contracts === void 0 ? void 0 : contracts.forEach(contract => {
|
|
5601
|
+
contractsMap.set("".concat(contract.namespaceId, ".").concat(contract.name), contract);
|
|
5602
|
+
});
|
|
5603
|
+
}
|
|
5604
|
+
function getContract(name) {
|
|
5605
|
+
return contractsMap.get(name);
|
|
5606
|
+
}
|
|
5607
|
+
|
|
5593
5608
|
var flowApiDefinitionPromiseMap = new Map(); // Legacy Custom API: `${namespace}@${name}`
|
|
5594
5609
|
// Flow API: `${namespace}@${name}:${version}`
|
|
5595
5610
|
|
|
@@ -5623,6 +5638,7 @@
|
|
|
5623
5638
|
var {
|
|
5624
5639
|
uri,
|
|
5625
5640
|
method,
|
|
5641
|
+
ext_fields,
|
|
5626
5642
|
name,
|
|
5627
5643
|
namespace,
|
|
5628
5644
|
responseWrapper,
|
|
@@ -5642,12 +5658,14 @@
|
|
|
5642
5658
|
return isFileType ? [fileName, {
|
|
5643
5659
|
url,
|
|
5644
5660
|
method,
|
|
5661
|
+
ext_fields,
|
|
5645
5662
|
responseWrapper: false
|
|
5646
5663
|
}, ...args, {
|
|
5647
5664
|
responseType: "blob"
|
|
5648
5665
|
}] : [{
|
|
5649
5666
|
url,
|
|
5650
5667
|
method,
|
|
5668
|
+
ext_fields,
|
|
5651
5669
|
responseWrapper
|
|
5652
5670
|
}, ...args];
|
|
5653
5671
|
}
|
|
@@ -5671,7 +5689,8 @@
|
|
|
5671
5689
|
}) : api.contract;
|
|
5672
5690
|
var {
|
|
5673
5691
|
uri,
|
|
5674
|
-
method = "GET"
|
|
5692
|
+
method = "GET",
|
|
5693
|
+
ext_fields
|
|
5675
5694
|
} = (_contract$endpoint = contract === null || contract === void 0 ? void 0 : contract.endpoint) !== null && _contract$endpoint !== void 0 ? _contract$endpoint : {};
|
|
5676
5695
|
var responseWrapper = contract !== null && contract !== void 0 && contract.response ? contract.response.wrapper !== false : false;
|
|
5677
5696
|
|
|
@@ -5682,6 +5701,7 @@
|
|
|
5682
5701
|
return {
|
|
5683
5702
|
uri,
|
|
5684
5703
|
method: method.toLowerCase() === "list" ? "get" : method,
|
|
5704
|
+
ext_fields,
|
|
5685
5705
|
name: api.name,
|
|
5686
5706
|
namespace: api.namespace,
|
|
5687
5707
|
version: api.version,
|
|
@@ -5742,25 +5762,39 @@
|
|
|
5742
5762
|
};
|
|
5743
5763
|
}
|
|
5744
5764
|
} else {
|
|
5745
|
-
var
|
|
5746
|
-
contractData
|
|
5747
|
-
} = yield ContractApi_searchSingleContract({
|
|
5748
|
-
contractName: "".concat(namespaceName, ".").concat(name),
|
|
5749
|
-
version
|
|
5750
|
-
}); // return undefined if don't found contract
|
|
5751
|
-
|
|
5752
|
-
if (contractData) {
|
|
5753
|
-
var _contractData$namespa, _contractData$namespa2;
|
|
5765
|
+
var contract;
|
|
5754
5766
|
|
|
5767
|
+
if (contract = getContract("".concat(namespaceName, ".").concat(name))) {
|
|
5755
5768
|
return {
|
|
5756
|
-
name:
|
|
5757
|
-
namespace:
|
|
5758
|
-
version:
|
|
5769
|
+
name: contract.name,
|
|
5770
|
+
namespace: contract.namespaceId,
|
|
5771
|
+
version: contract.version,
|
|
5759
5772
|
contract: {
|
|
5760
|
-
endpoint:
|
|
5761
|
-
response:
|
|
5773
|
+
endpoint: contract.endpoint,
|
|
5774
|
+
response: contract.response
|
|
5762
5775
|
}
|
|
5763
5776
|
};
|
|
5777
|
+
} else {
|
|
5778
|
+
var {
|
|
5779
|
+
contractData
|
|
5780
|
+
} = yield ContractApi_searchSingleContract({
|
|
5781
|
+
contractName: "".concat(namespaceName, ".").concat(name),
|
|
5782
|
+
version
|
|
5783
|
+
}); // return undefined if don't found contract
|
|
5784
|
+
|
|
5785
|
+
if (contractData) {
|
|
5786
|
+
var _contractData$namespa, _contractData$namespa2;
|
|
5787
|
+
|
|
5788
|
+
return {
|
|
5789
|
+
name: contractData.name,
|
|
5790
|
+
namespace: (_contractData$namespa = contractData.namespace) === null || _contractData$namespa === void 0 ? void 0 : (_contractData$namespa2 = _contractData$namespa[0]) === null || _contractData$namespa2 === void 0 ? void 0 : _contractData$namespa2.name,
|
|
5791
|
+
version: contractData.version,
|
|
5792
|
+
contract: {
|
|
5793
|
+
endpoint: contractData.endpoint,
|
|
5794
|
+
response: contractData.response
|
|
5795
|
+
}
|
|
5796
|
+
};
|
|
5797
|
+
}
|
|
5764
5798
|
}
|
|
5765
5799
|
}
|
|
5766
5800
|
});
|
|
@@ -6639,26 +6673,74 @@
|
|
|
6639
6673
|
}
|
|
6640
6674
|
|
|
6641
6675
|
var CUSTOM_API_PROVIDER = "brick-kit.provider-custom-api";
|
|
6642
|
-
function
|
|
6676
|
+
function processExtFields(ext_fields) {
|
|
6677
|
+
|
|
6678
|
+
var hasFields = type => {
|
|
6679
|
+
return ext_fields.some(item => item.source === type);
|
|
6680
|
+
};
|
|
6681
|
+
|
|
6682
|
+
var hasQueryParams = hasFields("query");
|
|
6683
|
+
var HasBodyParams = hasFields("body");
|
|
6684
|
+
|
|
6685
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
6686
|
+
args[_key - 1] = arguments[_key];
|
|
6687
|
+
}
|
|
6688
|
+
|
|
6689
|
+
if (hasQueryParams && HasBodyParams) {
|
|
6690
|
+
var [_data, params, _options] = args;
|
|
6691
|
+
return {
|
|
6692
|
+
data: _data,
|
|
6693
|
+
options: _objectSpread__default["default"]({
|
|
6694
|
+
params: params
|
|
6695
|
+
}, _options)
|
|
6696
|
+
};
|
|
6697
|
+
}
|
|
6698
|
+
|
|
6699
|
+
if (hasQueryParams) {
|
|
6700
|
+
var [_params, _options2] = args;
|
|
6701
|
+
return {
|
|
6702
|
+
data: {},
|
|
6703
|
+
options: _objectSpread__default["default"]({
|
|
6704
|
+
params: _params
|
|
6705
|
+
}, _options2)
|
|
6706
|
+
};
|
|
6707
|
+
} // only hasBodyParams or default
|
|
6708
|
+
|
|
6709
|
+
|
|
6710
|
+
var [data, options] = args;
|
|
6711
|
+
return {
|
|
6712
|
+
data,
|
|
6713
|
+
options
|
|
6714
|
+
};
|
|
6715
|
+
}
|
|
6716
|
+
function CustomApi(_x) {
|
|
6643
6717
|
return _CustomApi.apply(this, arguments);
|
|
6644
6718
|
}
|
|
6645
6719
|
|
|
6646
6720
|
function _CustomApi() {
|
|
6647
|
-
_CustomApi = _asyncToGenerator__default["default"](function* (_ref
|
|
6721
|
+
_CustomApi = _asyncToGenerator__default["default"](function* (_ref) {
|
|
6648
6722
|
var {
|
|
6649
6723
|
url,
|
|
6650
6724
|
method = "GET",
|
|
6651
|
-
responseWrapper = true
|
|
6725
|
+
responseWrapper = true,
|
|
6726
|
+
ext_fields = []
|
|
6652
6727
|
} = _ref;
|
|
6653
6728
|
var isSimpleRequest = ["get", "delete", "head"].includes(method.toLowerCase());
|
|
6654
6729
|
|
|
6730
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
6731
|
+
args[_key2 - 1] = arguments[_key2];
|
|
6732
|
+
}
|
|
6733
|
+
|
|
6655
6734
|
if (isSimpleRequest) {
|
|
6735
|
+
var [data, options] = args;
|
|
6656
6736
|
var response = yield brickHttp.http.simpleRequest(method, url, _objectSpread__default["default"]({
|
|
6657
6737
|
params: data
|
|
6658
6738
|
}, options));
|
|
6659
6739
|
return responseWrapper ? response.data : response;
|
|
6660
6740
|
} else {
|
|
6661
|
-
var
|
|
6741
|
+
var result = processExtFields(ext_fields, ...args);
|
|
6742
|
+
|
|
6743
|
+
var _response = yield brickHttp.http.requestWithBody(method, url, result.data, result.options);
|
|
6662
6744
|
|
|
6663
6745
|
return responseWrapper ? _response.data : _response;
|
|
6664
6746
|
}
|
|
@@ -7903,11 +7985,33 @@
|
|
|
7903
7985
|
var storyboard = this.bootstrapData.storyboards.find(item => item.app.id === appId);
|
|
7904
7986
|
Object.assign(storyboard, _objectSpread__default["default"](_objectSpread__default["default"]({}, storyboardPatch), {}, {
|
|
7905
7987
|
$$fulfilling: Promise.resolve(),
|
|
7906
|
-
$$fulfilled: true
|
|
7988
|
+
$$fulfilled: true,
|
|
7989
|
+
$$registerCustomTemplateProcessed: false,
|
|
7990
|
+
$$depsProcessed: false
|
|
7907
7991
|
}));
|
|
7908
7992
|
this.postProcessStoryboard(storyboard);
|
|
7909
7993
|
}
|
|
7910
7994
|
|
|
7995
|
+
_dev_only_updateTemplatePreviewSettings(appId, templateId, settings) {
|
|
7996
|
+
var {
|
|
7997
|
+
routes
|
|
7998
|
+
} = this.bootstrapData.storyboards.find(item => item.app.id === appId);
|
|
7999
|
+
var previewPath = "${APP.homepage}/_dev_only_/template-preview/".concat(templateId);
|
|
8000
|
+
var previewRouteIndex = routes.findIndex(route => route.path === previewPath);
|
|
8001
|
+
var newPreviewRoute = {
|
|
8002
|
+
path: previewPath,
|
|
8003
|
+
bricks: [_objectSpread__default["default"]({
|
|
8004
|
+
brick: templateId
|
|
8005
|
+
}, lodash.pick(settings, "properties"))]
|
|
8006
|
+
};
|
|
8007
|
+
|
|
8008
|
+
if (previewRouteIndex === -1) {
|
|
8009
|
+
routes.push(newPreviewRoute);
|
|
8010
|
+
} else {
|
|
8011
|
+
routes.splice(previewRouteIndex, 1, newPreviewRoute);
|
|
8012
|
+
}
|
|
8013
|
+
}
|
|
8014
|
+
|
|
7911
8015
|
loadDepsOfStoryboard(storyboard) {
|
|
7912
8016
|
var _this6 = this;
|
|
7913
8017
|
|
|
@@ -9982,7 +10086,7 @@
|
|
|
9982
10086
|
var storyboard = locationContext.matchStoryboard(_this3.kernel.bootstrapData.storyboards);
|
|
9983
10087
|
|
|
9984
10088
|
if (storyboard) {
|
|
9985
|
-
var _storyboard$meta, _storyboard$meta2;
|
|
10089
|
+
var _storyboard$meta, _storyboard$meta2, _storyboard$meta3;
|
|
9986
10090
|
|
|
9987
10091
|
yield _this3.kernel.fulfilStoryboard(storyboard); // 将动态解析后的模板还原,以便重新动态解析。
|
|
9988
10092
|
|
|
@@ -10001,6 +10105,7 @@
|
|
|
10001
10105
|
|
|
10002
10106
|
registerStoryboardFunctions((_storyboard$meta = storyboard.meta) === null || _storyboard$meta === void 0 ? void 0 : _storyboard$meta.functions, storyboard.app);
|
|
10003
10107
|
registerMock((_storyboard$meta2 = storyboard.meta) === null || _storyboard$meta2 === void 0 ? void 0 : _storyboard$meta2.mocks);
|
|
10108
|
+
collectContract((_storyboard$meta3 = storyboard.meta) === null || _storyboard$meta3 === void 0 ? void 0 : _storyboard$meta3.contracts);
|
|
10004
10109
|
}
|
|
10005
10110
|
|
|
10006
10111
|
var {
|
|
@@ -10053,7 +10158,13 @@
|
|
|
10053
10158
|
};
|
|
10054
10159
|
|
|
10055
10160
|
try {
|
|
10056
|
-
yield locationContext.mountRoutes(
|
|
10161
|
+
yield locationContext.mountRoutes( // Concat with a placeholder when loading template preview settings.
|
|
10162
|
+
storyboard.routes.concat({
|
|
10163
|
+
path: "${APP.homepage}/_dev_only_/template-preview/:templateId",
|
|
10164
|
+
bricks: [{
|
|
10165
|
+
brick: "next-previewer.template-preview-loader"
|
|
10166
|
+
}]
|
|
10167
|
+
}), undefined, mountRoutesResult);
|
|
10057
10168
|
} catch (error) {
|
|
10058
10169
|
// eslint-disable-next-line no-console
|
|
10059
10170
|
console.error(error); // Redirect to login page if not logged in.
|
|
@@ -10966,37 +11077,37 @@
|
|
|
10966
11077
|
}
|
|
10967
11078
|
|
|
10968
11079
|
function registerCustomTemplate(tplName, tplConstructor, appId) {
|
|
10969
|
-
var _tplConstructor$proxy;
|
|
10970
|
-
|
|
10971
11080
|
var tagName = tplName; // When a template is registered by an app, its namespace maybe missed.
|
|
10972
11081
|
|
|
10973
11082
|
if (appId && !tplName.includes(".")) {
|
|
10974
11083
|
tagName = "".concat(appId, ".").concat(tplName);
|
|
10975
11084
|
}
|
|
10976
11085
|
|
|
10977
|
-
|
|
11086
|
+
var registered = customTemplateRegistry.has(tagName);
|
|
11087
|
+
|
|
11088
|
+
if (registered) {
|
|
10978
11089
|
// When open launchpad, the storyboard will be updated.
|
|
10979
11090
|
// However, we can't *undefine* a custom element.
|
|
10980
11091
|
// Just ignore re-registering custom templates.
|
|
10981
11092
|
if (!appId || appRegistered.has(appId)) {
|
|
10982
11093
|
// eslint-disable-next-line no-console
|
|
10983
|
-
console.
|
|
11094
|
+
console.warn("Custom template of \"".concat(tagName, "\" already registered."));
|
|
10984
11095
|
}
|
|
11096
|
+
} else {
|
|
11097
|
+
registered = !!customElements.get(tagName);
|
|
10985
11098
|
|
|
10986
|
-
|
|
10987
|
-
|
|
11099
|
+
if (registered) {
|
|
11100
|
+
// eslint-disable-next-line no-console
|
|
11101
|
+
console.warn("Custom template of \"".concat(tagName, "\" already defined by customElements."));
|
|
11102
|
+
}
|
|
11103
|
+
} // Now we allow re-register custom template
|
|
10988
11104
|
|
|
10989
|
-
if (customElements.get(tagName)) {
|
|
10990
|
-
// eslint-disable-next-line no-console
|
|
10991
|
-
console.error("Custom template of \"".concat(tagName, "\" already defined by customElements."));
|
|
10992
|
-
return;
|
|
10993
|
-
}
|
|
10994
11105
|
|
|
10995
11106
|
customTemplateRegistry.set(tagName, _objectSpread__default["default"](_objectSpread__default["default"]({}, tplConstructor), {}, {
|
|
10996
11107
|
name: tagName
|
|
10997
11108
|
})); // Collect defined properties of the template.
|
|
10998
11109
|
|
|
10999
|
-
var props =
|
|
11110
|
+
var props = getPropsOfCustomTemplate(tagName);
|
|
11000
11111
|
var nativeProp = props.find(prop => prop in HTMLElement.prototype); // istanbul ignore if
|
|
11001
11112
|
|
|
11002
11113
|
if (nativeProp !== undefined) {
|
|
@@ -11004,13 +11115,17 @@
|
|
|
11004
11115
|
console.error("In custom template \"".concat(tagName, "\", \"").concat(nativeProp, "\" is a native HTMLElement property, and should be avoid to be used as a brick property."));
|
|
11005
11116
|
}
|
|
11006
11117
|
|
|
11118
|
+
if (registered) {
|
|
11119
|
+
return;
|
|
11120
|
+
}
|
|
11121
|
+
|
|
11007
11122
|
customElements.define(tagName, class TplElement extends HTMLElement {
|
|
11008
11123
|
get $$typeof() {
|
|
11009
11124
|
return "custom-template";
|
|
11010
11125
|
}
|
|
11011
11126
|
|
|
11012
11127
|
static get _dev_only_definedProperties() {
|
|
11013
|
-
return
|
|
11128
|
+
return getPropsOfCustomTemplate(tagName);
|
|
11014
11129
|
}
|
|
11015
11130
|
|
|
11016
11131
|
connectedCallback() {
|
|
@@ -11028,6 +11143,16 @@
|
|
|
11028
11143
|
}
|
|
11029
11144
|
}
|
|
11030
11145
|
|
|
11146
|
+
function getPropsOfCustomTemplate(tagName) {
|
|
11147
|
+
var _state$map, _proxy$properties;
|
|
11148
|
+
|
|
11149
|
+
var {
|
|
11150
|
+
state,
|
|
11151
|
+
proxy
|
|
11152
|
+
} = customTemplateRegistry.get(tagName);
|
|
11153
|
+
return ((_state$map = state === null || state === void 0 ? void 0 : state.map(item => item.name)) !== null && _state$map !== void 0 ? _state$map : []).concat(Object.keys((_proxy$properties = proxy === null || proxy === void 0 ? void 0 : proxy.properties) !== null && _proxy$properties !== void 0 ? _proxy$properties : {}));
|
|
11154
|
+
}
|
|
11155
|
+
|
|
11031
11156
|
var customProcessorRegistry = new Map();
|
|
11032
11157
|
function registerCustomProcessor(processorFullName, processorFunc) {
|
|
11033
11158
|
// `namespace` should be the camelCase of the package name.
|
|
@@ -12952,7 +13077,8 @@
|
|
|
12952
13077
|
|
|
12953
13078
|
/** @deprecated Keep it for backward-compatibility. */
|
|
12954
13079
|
checkoutTplContext: lodash.noop,
|
|
12955
|
-
updateStoryboard: _dev_only_updateStoryboard
|
|
13080
|
+
updateStoryboard: _dev_only_updateStoryboard,
|
|
13081
|
+
updateTemplatePreviewSettings: _dev_only_updateTemplatePreviewSettings
|
|
12956
13082
|
};
|
|
12957
13083
|
|
|
12958
13084
|
var _excluded$2 = ["type"];
|