@next-core/brick-kit 2.119.1 → 2.121.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,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.121.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.120.1...@next-core/brick-kit@2.121.0) (2022-06-01)
7
+
8
+
9
+ ### Features
10
+
11
+ * **MessageDispatcher:** call error callbacks on WS error event ([d89a993](https://github.com/easyops-cn/next-core/commit/d89a993347107b8bc15e2e54cce68a620374d451))
12
+
13
+
14
+
15
+
16
+
17
+ ## [2.120.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.120.0...@next-core/brick-kit@2.120.1) (2022-05-27)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * theme dark ([8ff6958](https://github.com/easyops-cn/next-core/commit/8ff6958e134c199e58ec4e026003839dcbc5ea57))
23
+ * 兼容message事件传多个参数的情况 ([fbde026](https://github.com/easyops-cn/next-core/commit/fbde026b51f8bd2d4a83b3c2ac3ac93bf6515179))
24
+ * 支持message.*传任意多个参数 ([abbfaeb](https://github.com/easyops-cn/next-core/commit/abbfaeb4752b408005a82e6a6cf57505b9d3aeb8))
25
+
26
+
27
+
28
+
29
+
30
+ # [2.120.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.119.1...@next-core/brick-kit@2.120.0) (2022-05-26)
31
+
32
+
33
+ ### Features
34
+
35
+ * support lifeCycle.onScrollIntoView ([4e3a4ec](https://github.com/easyops-cn/next-core/commit/4e3a4ec99a78b312c6efe595d82e214a843458d0))
36
+
37
+
38
+
39
+
40
+
6
41
  ## [2.119.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.119.0...@next-core/brick-kit@2.119.1) (2022-05-13)
7
42
 
8
43
  **Note:** Version bump only for package @next-core/brick-kit
@@ -4071,8 +4071,16 @@
4071
4071
  }
4072
4072
 
4073
4073
  class WebSocketService {
4074
+ get retryCount() {
4075
+ return this._retryCount;
4076
+ }
4077
+
4078
+ set retryCount(value) {
4079
+ this._retryCount = value;
4080
+ }
4081
+
4074
4082
  constructor(options) {
4075
- _defineProperty__default["default"](this, "retryCount", 0);
4083
+ _defineProperty__default["default"](this, "_retryCount", 0);
4076
4084
 
4077
4085
  _defineProperty__default["default"](this, "ws", null);
4078
4086
 
@@ -4141,7 +4149,18 @@
4141
4149
  };
4142
4150
 
4143
4151
  this.ws.onerror = event => {
4144
- this.onError(event); // eslint-disable-next-line no-console
4152
+ var {
4153
+ options,
4154
+ retryCount,
4155
+ state,
4156
+ readyState
4157
+ } = this;
4158
+ this.onError(event, {
4159
+ options: getReadOnlyProxy(options),
4160
+ retryCount,
4161
+ state,
4162
+ readyState
4163
+ }); // eslint-disable-next-line no-console
4145
4164
 
4146
4165
  console.log("WebSocket encountered error: ", event);
4147
4166
  this.reconnect();
@@ -4201,7 +4220,7 @@
4201
4220
 
4202
4221
  onClose(event) {}
4203
4222
 
4204
- onError(event) {}
4223
+ onError(event, data) {}
4205
4224
 
4206
4225
  onMessage(message) {}
4207
4226
 
@@ -5471,8 +5490,27 @@
5471
5490
  }
5472
5491
 
5473
5492
  subscribe(channel, topic, callback) {
5493
+ var _this$ws;
5494
+
5474
5495
  var req = new WebsocketMessageRequest(PluginWebSocketMessageEvent.SUB, topic);
5475
- this.setMessageCallbackHandlers(req.identity, callback); // Prevent repeated subscriptions to the same topic.
5496
+ this.setMessageCallbackHandlers(req.identity, callback);
5497
+
5498
+ if (((_this$ws = this.ws) === null || _this$ws === void 0 ? void 0 : _this$ws.state) === "finished") {
5499
+ var {
5500
+ options,
5501
+ retryCount,
5502
+ state,
5503
+ readyState
5504
+ } = this.ws;
5505
+ this.handleError({
5506
+ options: getReadOnlyProxy(options),
5507
+ retryCount,
5508
+ state,
5509
+ readyState
5510
+ });
5511
+ return;
5512
+ } // Prevent repeated subscriptions to the same topic.
5513
+
5476
5514
 
5477
5515
  if (!this.channels.has(req.topic)) {
5478
5516
  this.channels.set(req.topic, channel);
@@ -5485,7 +5523,7 @@
5485
5523
 
5486
5524
  if (!t) {
5487
5525
  // eslint-disable-next-line no-console
5488
- console.error("Message channel\uFF1A\"".concat(channel, "\" not found. "));
5526
+ console.error("Message channel: \"".concat(channel, "\" not found. "));
5489
5527
  return;
5490
5528
  }
5491
5529
 
@@ -5516,6 +5554,10 @@
5516
5554
  createWebsocketService() {
5517
5555
  this.ws = createWebSocket();
5518
5556
 
5557
+ this.ws.onError = (_event, data) => {
5558
+ this.handleError(data);
5559
+ };
5560
+
5519
5561
  this.ws.onMessage = message => {
5520
5562
  this.reducer(message);
5521
5563
  };
@@ -5525,6 +5567,19 @@
5525
5567
  };
5526
5568
  }
5527
5569
 
5570
+ handleError(data) {
5571
+ var event = new CustomEvent("callback.error", {
5572
+ detail: _objectSpread__default["default"]({
5573
+ payload: {
5574
+ message: {}
5575
+ }
5576
+ }, data)
5577
+ });
5578
+ this.messageCallbackHandlers.forEach(callbacks => {
5579
+ this.messageSubscribeCallbacksHandler(callbacks, "error", event);
5580
+ });
5581
+ }
5582
+
5528
5583
  onClose(event) {
5529
5584
  _internalApiMessageCloseHandler(event);
5530
5585
  }
@@ -5611,19 +5666,22 @@
5611
5666
  }
5612
5667
  }
5613
5668
 
5614
- messageSubscribeResponseEventHandler(response, method, event) {
5615
- var callbacks = this.messageCallbackHandlers.get(response.identity);
5616
-
5669
+ messageSubscribeCallbacksHandler(callbacks, method, event) {
5617
5670
  if (Array.isArray(callbacks)) {
5618
5671
  for (var handler of callbacks) {
5619
- var e = new CustomEvent(event, {
5620
- detail: response.message
5621
- });
5622
- this.dispatch(e, handler.runtimeBrick, handler.context, [].concat(handler === null || handler === void 0 ? void 0 : handler[method]).filter(Boolean));
5672
+ this.dispatch(event, handler.runtimeBrick, handler.context, [].concat(handler === null || handler === void 0 ? void 0 : handler[method]).filter(Boolean));
5623
5673
  }
5624
5674
  }
5625
5675
  }
5626
5676
 
5677
+ messageSubscribeResponseEventHandler(response, method, event) {
5678
+ var callbacks = this.messageCallbackHandlers.get(response.identity);
5679
+ var e = new CustomEvent(event, {
5680
+ detail: response.message
5681
+ });
5682
+ this.messageSubscribeCallbacksHandler(callbacks, method, e);
5683
+ }
5684
+
5627
5685
  }
5628
5686
 
5629
5687
  var timeoutIdList = new Set();
@@ -6667,7 +6725,14 @@
6667
6725
  return;
6668
6726
  }
6669
6727
 
6670
- antd.message[method](...argsFactory(args, context, event));
6728
+ var processArg = argsFactory(args, context, event);
6729
+ var contentNode = /*#__PURE__*/React__default["default"].createElement("span", null, "".concat(processArg[0]));
6730
+ var argProp = {
6731
+ content: contentNode,
6732
+ className: "ant-message-notice-".concat(method)
6733
+ };
6734
+ processArg[0] = argProp;
6735
+ antd.message[method](...processArg);
6671
6736
  };
6672
6737
  }
6673
6738
 
@@ -9076,12 +9141,16 @@
9076
9141
 
9077
9142
  _defineProperty__default["default"](this, "messageHandlers", []);
9078
9143
 
9144
+ _defineProperty__default["default"](this, "scrollIntoViewHandlersMap", new Map());
9145
+
9079
9146
  _defineProperty__default["default"](this, "segues", {});
9080
9147
 
9081
9148
  _defineProperty__default["default"](this, "currentMatch", void 0);
9082
9149
 
9083
9150
  _defineProperty__default["default"](this, "storyboardContextWrapper", new StoryboardContextWrapper());
9084
9151
 
9152
+ _defineProperty__default["default"](this, "observersList", []);
9153
+
9085
9154
  this.kernel = kernel;
9086
9155
  this.location = location;
9087
9156
  this.resolver = new Resolver(kernel);
@@ -9448,7 +9517,7 @@
9448
9517
  _this6 = this;
9449
9518
 
9450
9519
  return _asyncToGenerator__default["default"](function* () {
9451
- var _this6$kernel$nextApp;
9520
+ var _this6$kernel$nextApp, _brickConf$lifeCycle, _brick$lifeCycle;
9452
9521
 
9453
9522
  var tplStack = _arguments.length > 4 && _arguments[4] !== undefined ? _arguments[4] : [];
9454
9523
  var tplContextId = brickConf[symbolForTplContextId];
@@ -9489,7 +9558,7 @@
9489
9558
  yield _this6.storyboardContextWrapper.define(brickConf.context, context, brick);
9490
9559
  yield _this6.preCheckPermissions(brickConf, context);
9491
9560
  var trackingContextList = [];
9492
- Object.assign(brick, {
9561
+ Object.assign(brick, _objectSpread__default["default"]({
9493
9562
  type: tplTagName || brickConf.brick,
9494
9563
  properties: computeRealProperties(brickConf.properties, context, brickConf.injectDeep !== false, trackingContextList),
9495
9564
  events: brickUtils.isObject(brickConf.events) ? brickConf.events : {},
@@ -9499,7 +9568,11 @@
9499
9568
  refForProxy: brickConf[symbolForRefForProxy],
9500
9569
  tplContextId,
9501
9570
  iid: brickConf.iid
9502
- });
9571
+ }, (_brickConf$lifeCycle = brickConf.lifeCycle) !== null && _brickConf$lifeCycle !== void 0 && _brickConf$lifeCycle.onScrollIntoView ? {
9572
+ lifeCycle: {
9573
+ onScrollIntoView: brickConf.lifeCycle.onScrollIntoView
9574
+ }
9575
+ } : {}));
9503
9576
 
9504
9577
  if (brickConf[symbolForComputedPropsFromProxy]) {
9505
9578
  Object.entries(brickConf[symbolForComputedPropsFromProxy]).forEach(_ref2 => {
@@ -9514,7 +9587,11 @@
9514
9587
  brick.refForProxy.brick = brick;
9515
9588
  }
9516
9589
 
9517
- _this6.registerHandlersFromLifeCycle(brickConf.lifeCycle, brick, match, tplContextId); // Then, resolve the brick.
9590
+ _this6.registerHandlersFromLifeCycle(brickConf.lifeCycle, brick, match, tplContextId);
9591
+
9592
+ if ((_brick$lifeCycle = brick.lifeCycle) !== null && _brick$lifeCycle !== void 0 && _brick$lifeCycle.onScrollIntoView) {
9593
+ _this6.brickBindObserver(brick);
9594
+ } // Then, resolve the brick.
9518
9595
 
9519
9596
 
9520
9597
  yield _this6.resolver.resolve(brickConf, brick, context);
@@ -9589,7 +9666,8 @@
9589
9666
  onAnchorUnload,
9590
9667
  onMediaChange,
9591
9668
  onMessage,
9592
- onMessageClose
9669
+ onMessageClose,
9670
+ onScrollIntoView
9593
9671
  } = lifeCycle !== null && lifeCycle !== void 0 ? lifeCycle : {};
9594
9672
 
9595
9673
  if (onBeforePageLoad) {
@@ -9672,6 +9750,15 @@
9672
9750
  handler: onMessageClose
9673
9751
  });
9674
9752
  }
9753
+
9754
+ if (onScrollIntoView) {
9755
+ this.scrollIntoViewHandlersMap.set(brick.iid, {
9756
+ brick,
9757
+ match,
9758
+ tplContextId,
9759
+ handler: onScrollIntoView.handlers
9760
+ });
9761
+ }
9675
9762
  }
9676
9763
 
9677
9764
  handleBeforePageLoad() {
@@ -9726,6 +9813,17 @@
9726
9813
  }), this.messageCloseHandlers);
9727
9814
  }
9728
9815
 
9816
+ handleScrollIntoView(id) {
9817
+ var currentHandlers = this.scrollIntoViewHandlersMap.get(id);
9818
+ this.dispatchLifeCycleEvent(new CustomEvent("scroll.into.view"), [currentHandlers]);
9819
+ }
9820
+
9821
+ handleBrickBindObserver() {
9822
+ this.observersList.forEach(value => {
9823
+ value.$$observe();
9824
+ });
9825
+ }
9826
+
9729
9827
  getCurrentMatch() {
9730
9828
  return this.currentMatch;
9731
9829
  }
@@ -9758,6 +9856,27 @@
9758
9856
  })();
9759
9857
  }
9760
9858
 
9859
+ brickBindObserver(brick) {
9860
+ var _brick$lifeCycle$onSc;
9861
+
9862
+ var threshold = (_brick$lifeCycle$onSc = brick.lifeCycle.onScrollIntoView.threshold) !== null && _brick$lifeCycle$onSc !== void 0 ? _brick$lifeCycle$onSc : 0.1;
9863
+ var observer = new IntersectionObserver((entries, observer) => {
9864
+ entries.forEach(entry => {
9865
+ if (entry.isIntersecting) {
9866
+ if (entry.intersectionRatio >= threshold) {
9867
+ this.handleScrollIntoView(brick.iid);
9868
+ observer.disconnect();
9869
+ }
9870
+ }
9871
+ });
9872
+ }, {
9873
+ threshold
9874
+ });
9875
+ this.observersList.push({
9876
+ $$observe: () => observer.observe(brick.element)
9877
+ });
9878
+ }
9879
+
9761
9880
  }
9762
9881
 
9763
9882
  function unmountTree(mountPoint) {
@@ -10637,6 +10756,8 @@
10637
10756
  window.scrollTo(0, 0);
10638
10757
 
10639
10758
  if (!failed) {
10759
+ _this3.locationContext.handleBrickBindObserver();
10760
+
10640
10761
  _this3.locationContext.handlePageLoad();
10641
10762
 
10642
10763
  _this3.locationContext.handleAnchorLoad();