@next-core/brick-kit 2.115.1 → 2.116.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 CHANGED
@@ -3,6 +3,17 @@
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.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)
7
+
8
+
9
+ ### Features
10
+
11
+ * support re-registering custom templates ([ea91d7d](https://github.com/easyops-cn/next-core/commit/ea91d7de23e0a9d3a935c01a9a103fb44b8cdfb3))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [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
18
 
8
19
  **Note:** Version bump only for package @next-core/brick-kit
@@ -7903,7 +7903,9 @@
7903
7903
  var storyboard = this.bootstrapData.storyboards.find(item => item.app.id === appId);
7904
7904
  Object.assign(storyboard, _objectSpread__default["default"](_objectSpread__default["default"]({}, storyboardPatch), {}, {
7905
7905
  $$fulfilling: Promise.resolve(),
7906
- $$fulfilled: true
7906
+ $$fulfilled: true,
7907
+ $$registerCustomTemplateProcessed: false,
7908
+ $$depsProcessed: false
7907
7909
  }));
7908
7910
  this.postProcessStoryboard(storyboard);
7909
7911
  }
@@ -10966,37 +10968,37 @@
10966
10968
  }
10967
10969
 
10968
10970
  function registerCustomTemplate(tplName, tplConstructor, appId) {
10969
- var _tplConstructor$proxy;
10970
-
10971
10971
  var tagName = tplName; // When a template is registered by an app, its namespace maybe missed.
10972
10972
 
10973
10973
  if (appId && !tplName.includes(".")) {
10974
10974
  tagName = "".concat(appId, ".").concat(tplName);
10975
10975
  }
10976
10976
 
10977
- if (customTemplateRegistry.has(tagName)) {
10977
+ var registered = customTemplateRegistry.has(tagName);
10978
+
10979
+ if (registered) {
10978
10980
  // When open launchpad, the storyboard will be updated.
10979
10981
  // However, we can't *undefine* a custom element.
10980
10982
  // Just ignore re-registering custom templates.
10981
10983
  if (!appId || appRegistered.has(appId)) {
10982
10984
  // eslint-disable-next-line no-console
10983
- console.error("Custom template of \"".concat(tagName, "\" already registered."));
10985
+ console.warn("Custom template of \"".concat(tagName, "\" already registered."));
10984
10986
  }
10987
+ } else {
10988
+ registered = !!customElements.get(tagName);
10985
10989
 
10986
- return;
10987
- }
10990
+ if (registered) {
10991
+ // eslint-disable-next-line no-console
10992
+ console.warn("Custom template of \"".concat(tagName, "\" already defined by customElements."));
10993
+ }
10994
+ } // Now we allow re-register custom template
10988
10995
 
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
10996
 
10995
10997
  customTemplateRegistry.set(tagName, _objectSpread__default["default"](_objectSpread__default["default"]({}, tplConstructor), {}, {
10996
10998
  name: tagName
10997
10999
  })); // Collect defined properties of the template.
10998
11000
 
10999
- var props = Object.keys(((_tplConstructor$proxy = tplConstructor.proxy) === null || _tplConstructor$proxy === void 0 ? void 0 : _tplConstructor$proxy.properties) || {});
11001
+ var props = getPropsOfCustomTemplate(tagName);
11000
11002
  var nativeProp = props.find(prop => prop in HTMLElement.prototype); // istanbul ignore if
11001
11003
 
11002
11004
  if (nativeProp !== undefined) {
@@ -11004,13 +11006,17 @@
11004
11006
  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
11007
  }
11006
11008
 
11009
+ if (registered) {
11010
+ return;
11011
+ }
11012
+
11007
11013
  customElements.define(tagName, class TplElement extends HTMLElement {
11008
11014
  get $$typeof() {
11009
11015
  return "custom-template";
11010
11016
  }
11011
11017
 
11012
11018
  static get _dev_only_definedProperties() {
11013
- return props;
11019
+ return getPropsOfCustomTemplate(tagName);
11014
11020
  }
11015
11021
 
11016
11022
  connectedCallback() {
@@ -11028,6 +11034,16 @@
11028
11034
  }
11029
11035
  }
11030
11036
 
11037
+ function getPropsOfCustomTemplate(tagName) {
11038
+ var _state$map, _proxy$properties;
11039
+
11040
+ var {
11041
+ state,
11042
+ proxy
11043
+ } = customTemplateRegistry.get(tagName);
11044
+ 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 : {}));
11045
+ }
11046
+
11031
11047
  var customProcessorRegistry = new Map();
11032
11048
  function registerCustomProcessor(processorFullName, processorFunc) {
11033
11049
  // `namespace` should be the camelCase of the package name.