@alipay/ams-checkout 0.0.1691743027-dev.3 → 0.0.1691743027-dev.5

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.
@@ -15,31 +15,23 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
15
15
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
16
16
  */
17
17
  /* eslint-disable no-console */
18
- import { closeImg, COMPONENTPLUGINID, ERRORMESSAGE, EVENT } from "../../constant";
18
+ import { COMPONENTPLUGINID, COMPONENT_CLOSE_BLOCK_ID, COMPONENT_CONTAINER_ID, COMPONENT_RETENTION_ID, COMPONENT_SECTION_ID, ERRORMESSAGE, EVENT, LISTENER_PREFIX, LOADING_ID, LOADTIME_LIMIT, MOCKUP_ID } from "../../constant";
19
19
  import { queryPaymentInfo } from "../../service";
20
- import { componentSignEnum, messageName, platformEnum, productSceneEnum, renderDisplayTypeEnum, targetEnum } from "../../types";
21
- import { addSetFontSizeEvent, amsSetSize, getDesignFontSize, getType, isJsonString, isPC } from "../../util";
20
+ import { componentSignEnum, eventCodeEnum, messageName, platformEnum, productSceneEnum, renderDisplayTypeEnum, targetEnum } from "../../types";
21
+ import { getType, isJsonString, isPC } from "../../util";
22
22
  import { isLocalMock } from "../../util/mock";
23
23
  import { createIframe, getAppDomain, getIframeUrl } from "./cashierApp";
24
- import { componentAddCSS, inlineComponentAddCss, showInlineLoading } from "./component.style";
24
+ import { addInlineLoading, createInlineBaseElement } from "./component.inline.style";
25
+ import { addPopupLoading, createBaseElement, createMockup, createRetentionPopup, hideRetentionPopup, removeRetentionPopup as _removeRetentionPopup } from "./component.popup.style";
25
26
  var _window = window,
26
27
  innerHeight = _window.innerHeight;
27
- var componentContainerId = 'ams-component-container';
28
- var componentSectionId = 'ams-component-section';
29
- var componentCloseBlockId = 'asm-component-close-block';
30
- var componentRetentionId = 'ams-component-retention';
31
- var mockupId = 'ams-component-mockup';
32
- var loadingId = 'ams-component-loading';
33
- var listenerPrefix = '_ams_sdk_component_listener';
34
- var inlineBaseStyleId = 'ams-inline-component-style';
35
- var loadTimeLimit = 15000;
36
28
  var ComponentApp = /*#__PURE__*/function () {
37
29
  function ComponentApp() {
38
30
  _classCallCheck(this, ComponentApp);
39
31
  _defineProperty(this, "app", void 0);
40
- _defineProperty(this, "appDomain", void 0);
41
32
  _defineProperty(this, "AMSSDK", void 0);
42
33
  _defineProperty(this, "platform", void 0);
34
+ _defineProperty(this, "appDomain", void 0);
43
35
  _defineProperty(this, "createIframeNode", void 0);
44
36
  _defineProperty(this, "_selector", void 0);
45
37
  _defineProperty(this, "_appVersion", void 0);
@@ -54,7 +46,7 @@ var ComponentApp = /*#__PURE__*/function () {
54
46
  _defineProperty(this, "_renderDisplayType", renderDisplayTypeEnum.popup);
55
47
  this._appVersion = '1.5.0';
56
48
  this._isInitComponent = false;
57
- this._selector = "#".concat(componentSectionId);
49
+ this._selector = "#".concat(COMPONENT_SECTION_ID);
58
50
  this.createIframeNode = function () {
59
51
  return Promise.resolve();
60
52
  };
@@ -111,40 +103,51 @@ var ComponentApp = /*#__PURE__*/function () {
111
103
  this._componentSign = componentSign;
112
104
  if (renderParams !== null && renderParams !== void 0 && renderParams.selector) this._selector = renderParams.selector;
113
105
  this._renderDisplayType = renderParams.renderDisplayType;
114
- var insertedNode = this._renderDisplayType === renderDisplayTypeEnum.inline ? "#".concat(componentContainerId) : this._selector;
106
+ var insertedNode = this._renderDisplayType === renderDisplayTypeEnum.inline ? "#".concat(COMPONENT_CONTAINER_ID) : this._selector;
115
107
  this._performanceData.push({
116
108
  key: 'sdk_create_component',
117
109
  value: Date.now()
118
110
  });
111
+ this.dispatchToSDK(EVENT.eventCallback.name, {
112
+ code: eventCodeEnum.SDK_START_OF_LOADING
113
+ });
119
114
  if (this._renderDisplayType === renderDisplayTypeEnum.inline) {
120
- this.createInlineBaseElement(renderParams);
115
+ var container = createInlineBaseElement(this._selector);
116
+ if (container) this.renderInlineLoading(renderParams, container);
121
117
  }
122
118
  if (this._renderDisplayType === renderDisplayTypeEnum.popup) {
123
- this.createBaseElement();
124
- this.setContainerClass();
125
- this.createRetentionPopup();
126
- this.createMockup();
119
+ createBaseElement(this.platform, this.closeBtnFunc);
120
+ createRetentionPopup(this.platform, this.hideRetentionPopupFunc, this.retentionPopupLeaveFunc);
121
+ createMockup();
127
122
  this.renderPopupLoading(renderParams);
128
123
  }
129
124
  this.createApp(renderParams);
130
- return Promise.all([this.createActionQueryPromise(), this.createIframeNode(this, insertedNode, this._renderDisplayType), this.createLoadAppPromise()]).catch(function (error) {
125
+ return Promise.all([this.createActionQueryPromise(), this.createIframeNode(this, insertedNode, this._renderDisplayType), this.createLoadAppPromise()]).then(function () {
126
+ return Promise.resolve();
127
+ }).catch(function (error) {
131
128
  _this._isInitComponent = false;
132
129
  _this.cleanContainer();
133
130
  return Promise.reject(error);
134
131
  });
135
132
  }
136
133
  }, {
137
- key: "renderPopupLoading",
138
- value: function renderPopupLoading(renderParams) {
134
+ key: "renderInlineLoading",
135
+ value: function renderInlineLoading(renderParams, selector) {
139
136
  var _renderParams$appeara;
140
137
  var showLoading = renderParams === null || renderParams === void 0 ? void 0 : (_renderParams$appeara = renderParams.appearance) === null || _renderParams$appeara === void 0 ? void 0 : _renderParams$appeara.showLoading;
141
138
  showLoading = typeof showLoading === 'boolean' ? showLoading : true;
139
+ if (showLoading) addInlineLoading(selector, this.platform);
140
+ }
141
+ }, {
142
+ key: "renderPopupLoading",
143
+ value: function renderPopupLoading(renderParams) {
144
+ var _renderParams$appeara2;
145
+ var showLoading = renderParams === null || renderParams === void 0 ? void 0 : (_renderParams$appeara2 = renderParams.appearance) === null || _renderParams$appeara2 === void 0 ? void 0 : _renderParams$appeara2.showLoading;
146
+ showLoading = typeof showLoading === 'boolean' ? showLoading : true;
142
147
  if (!showLoading) return;
143
- if (this._renderDisplayType === renderDisplayTypeEnum.popup) {
144
- var mockup = document.getElementById(mockupId);
145
- if (mockup) mockup.style.display = 'block';
146
- return this.showPopupLoading();
147
- }
148
+ var mockup = document.getElementById(MOCKUP_ID);
149
+ if (mockup) mockup.style.display = 'block';
150
+ addPopupLoading();
148
151
  }
149
152
  }, {
150
153
  key: "createLoadAppPromise",
@@ -154,7 +157,7 @@ var ComponentApp = /*#__PURE__*/function () {
154
157
  _this2._loadAppPromiseResolve = resolve;
155
158
  setTimeout(function () {
156
159
  reject(ERRORMESSAGE.CREATECOMPONENT_ERROR.LOAD_APP_TIMEOUT);
157
- }, loadTimeLimit);
160
+ }, LOADTIME_LIMIT);
158
161
  }).catch(function (error) {
159
162
  _this2.dispatchToSDK(EVENT.error.name, {
160
163
  code: ERRORMESSAGE.CREATECOMPONENT_ERROR.code,
@@ -261,16 +264,32 @@ var ComponentApp = /*#__PURE__*/function () {
261
264
  return this._actionQueryPromise;
262
265
  }
263
266
  }, {
264
- key: "cleanApp",
265
- value: function cleanApp() {
267
+ key: "cleanElement",
268
+ value: function cleanElement() {
266
269
  try {
267
- this.app = null;
268
- this._removeEventListener();
270
+ var _document$getElementB;
271
+ // selector and container
269
272
  if (getType(this._selector) === 'string') {
270
273
  var selectorDom = document.querySelector(this._selector);
271
274
  if (selectorDom) selectorDom.innerHTML = '';
272
275
  }
273
- // eslint-disable-next-line no-empty
276
+ var container = document.getElementById(COMPONENT_CONTAINER_ID);
277
+ if (container) container === null || container === void 0 ? void 0 : container.remove();
278
+
279
+ // animation
280
+ (_document$getElementB = document.getElementById("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation-style"))) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
281
+
282
+ // mockup
283
+ var body = document.getElementsByTagName('body')[0];
284
+ body.style.overflow = 'auto';
285
+ var mockup = document.getElementById(MOCKUP_ID);
286
+ mockup === null || mockup === void 0 ? void 0 : mockup.remove();
287
+
288
+ // retentionPopup
289
+ this.removeRetentionPopup(this.platform);
290
+
291
+ // listener
292
+ this._removeEventListener();
274
293
  } catch (error) {
275
294
  console.error(error);
276
295
  }
@@ -343,7 +362,7 @@ var ComponentApp = /*#__PURE__*/function () {
343
362
  }, {
344
363
  key: "resizeListener",
345
364
  value: function resizeListener() {
346
- var cashier = document.getElementById(componentContainerId);
365
+ var cashier = document.getElementById(COMPONENT_CONTAINER_ID);
347
366
  cashier.style.transition = 'none';
348
367
  this.dispatchToApp({
349
368
  context: {
@@ -363,16 +382,16 @@ var ComponentApp = /*#__PURE__*/function () {
363
382
  key: "_addEventListener",
364
383
  value: function _addEventListener() {
365
384
  this._removeEventListener();
366
- window["".concat(listenerPrefix, "_").concat(this.AMSSDK._instanceId)] = this.listener.bind(this);
367
- window["".concat(listenerPrefix, "_").concat(this.AMSSDK._instanceId, "_resize")] = this.resizeListener.bind(this);
368
- window.addEventListener('message', window["".concat(listenerPrefix, "_").concat(this.AMSSDK._instanceId)]);
369
- window.addEventListener('resize', window["".concat(listenerPrefix, "_").concat(this.AMSSDK._instanceId, "_resize")]);
385
+ window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId)] = this.listener.bind(this);
386
+ window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId, "_resize")] = this.resizeListener.bind(this);
387
+ window.addEventListener('message', window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId)]);
388
+ window.addEventListener('resize', window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId, "_resize")]);
370
389
  }
371
390
  }, {
372
391
  key: "_removeEventListener",
373
392
  value: function _removeEventListener() {
374
- window.removeEventListener('message', window["".concat(listenerPrefix, "_").concat(this.AMSSDK._instanceId)]);
375
- window.removeEventListener('resize', window["".concat(listenerPrefix, "_").concat(this.AMSSDK._instanceId, "_resize")]);
393
+ window.removeEventListener('message', window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId)]);
394
+ window.removeEventListener('resize', window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId, "_resize")]);
376
395
  }
377
396
 
378
397
  /**
@@ -441,29 +460,28 @@ var ComponentApp = /*#__PURE__*/function () {
441
460
  value: function handleSizeChanged(data) {
442
461
  var _data$context$data2;
443
462
  if (((_data$context$data2 = data.context.data) === null || _data$context$data2 === void 0 ? void 0 : _data$context$data2.height) <= 1) return;
444
- var cashier = document.getElementById(componentContainerId);
463
+ var cashier = document.getElementById(COMPONENT_CONTAINER_ID);
445
464
  cashier.style.height = "".concat(data.context.data.height, "px");
446
465
  if (this._renderDisplayType === renderDisplayTypeEnum.popup) {
447
- var _document$getElementB;
448
- var mockup = document.getElementById(mockupId);
466
+ var _document$getElementB2;
467
+ var mockup = document.getElementById(MOCKUP_ID);
449
468
  if (mockup) {
450
- mockup.style.background = '#000000';
451
- mockup.style.opacity = '0.6';
469
+ mockup.style.background = 'rgb(0, 0, 0, 0.6)';
452
470
  mockup.style.display = 'block';
453
471
  }
454
- (_document$getElementB = document.getElementById(loadingId)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
472
+ (_document$getElementB2 = document.getElementById(LOADING_ID)) === null || _document$getElementB2 === void 0 ? void 0 : _document$getElementB2.remove();
455
473
  if (this.platform === 'desktop') {
456
- cashier.classList.add("".concat(componentContainerId, "-").concat(this.platform, "-animation"));
474
+ cashier.classList.add("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation"));
457
475
  if (data.context.data.width) cashier.style.width = "".concat(data.context.data.width, "px");
458
476
  }
459
477
  if (this.platform === 'mobile') {
460
- cashier.classList.add("".concat(componentContainerId, "-").concat(this.platform, "-animation"));
461
- var animationStyleId = "".concat(componentContainerId, "-").concat(this.platform, "-animation-style");
478
+ cashier.classList.add("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation"));
479
+ var animationStyleId = "".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation-style");
462
480
  var animationStyle = document.getElementById(animationStyleId);
463
481
  if (animationStyle) animationStyle === null || animationStyle === void 0 ? void 0 : animationStyle.remove();
464
482
 
465
483
  // 弹出和弹入动画
466
- var runkeyframes = "@keyframes ".concat(componentContainerId, "-slide-in {\n 0% {\n height: 1px;\n }\n 100% {\n height: ").concat(data.context.data.height, "px;\n }\n }\n @keyframes ").concat(componentContainerId, "-slide-out {\n 0% {\n height: ").concat(data.context.data.height, "px;\n opacity: 1;\n }\n 50% {\n opacity: 1;\n }\n 100% {\n height: 1px;\n opacity: 0;\n }\n }");
484
+ var runkeyframes = "@keyframes ".concat(COMPONENT_CONTAINER_ID, "-slide-in {\n 0% {\n height: 1px;\n }\n 100% {\n height: ").concat(data.context.data.height, "px;\n }\n }\n @keyframes ").concat(COMPONENT_CONTAINER_ID, "-slide-out {\n 0% {\n height: ").concat(data.context.data.height, "px;\n opacity: 1;\n }\n 50% {\n opacity: 1;\n }\n 100% {\n height: 1px;\n opacity: 0;\n }\n }");
467
485
  // 创建style标签
468
486
  var style = document.createElement('style');
469
487
  style.id = animationStyleId;
@@ -481,8 +499,8 @@ var ComponentApp = /*#__PURE__*/function () {
481
499
  }
482
500
  }
483
501
  if (this._renderDisplayType === renderDisplayTypeEnum.inline) {
484
- var _document$getElementB2;
485
- (_document$getElementB2 = document.getElementById(loadingId)) === null || _document$getElementB2 === void 0 ? void 0 : _document$getElementB2.remove();
502
+ var _document$getElementB3;
503
+ (_document$getElementB3 = document.getElementById(LOADING_ID)) === null || _document$getElementB3 === void 0 ? void 0 : _document$getElementB3.remove();
486
504
  }
487
505
  this.app.style.height = "".concat(data.context.data.height, "px");
488
506
  this.app.style.opacity = '1';
@@ -501,13 +519,13 @@ var ComponentApp = /*#__PURE__*/function () {
501
519
  };
502
520
  var successCallback = function successCallback(type, url) {
503
521
  _this4.dispatchToSDK(EVENT.eventCallback.name, {
504
- code: 'SDK_CALL_URL_SUCCESS',
522
+ code: eventCodeEnum.SDK_CALL_URL_SUCCESS,
505
523
  message: "Successfully opened the app,".concat(type, ": ").concat(url)
506
524
  });
507
525
  };
508
526
  var failCallback = function failCallback() {
509
527
  _this4.dispatchToSDK(EVENT.eventCallback.name, {
510
- code: 'SDK_CALL_URL_ERROR',
528
+ code: eventCodeEnum.SDK_CALL_URL_SUCCESS,
511
529
  message: "Failed to open app,applinkUrl: ".concat(_data === null || _data === void 0 ? void 0 : _data.applinkUrl, " schemeUrl: ").concat(_data === null || _data === void 0 ? void 0 : _data.schemeUrl, " normalUrl: ").concat(_data === null || _data === void 0 ? void 0 : _data.normalUrl)
512
530
  });
513
531
  };
@@ -547,21 +565,21 @@ var ComponentApp = /*#__PURE__*/function () {
547
565
  closeDialogData = _ref3$closeDialogData === void 0 ? {} : _ref3$closeDialogData;
548
566
  try {
549
567
  if (closeDialogData) {
550
- var retentionTitle = document.getElementById("".concat(componentRetentionId, "-title"));
568
+ var retentionTitle = document.getElementById("".concat(COMPONENT_RETENTION_ID, "-title"));
551
569
  if (retentionTitle) {
552
570
  var _closeDialogData$titl, _closeDialogData$titl2, _closeDialogData$titl3;
553
571
  retentionTitle.style.fontSize = "".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$titl = closeDialogData.title) === null || _closeDialogData$titl === void 0 ? void 0 : _closeDialogData$titl.fontSize, "px");
554
572
  retentionTitle.style.color = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$titl2 = closeDialogData.title) === null || _closeDialogData$titl2 === void 0 ? void 0 : _closeDialogData$titl2.fontColor;
555
573
  retentionTitle.innerHTML = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$titl3 = closeDialogData.title) === null || _closeDialogData$titl3 === void 0 ? void 0 : _closeDialogData$titl3.text;
556
574
  }
557
- var retentionMessage = document.getElementById("".concat(componentRetentionId, "-sub-title"));
575
+ var retentionMessage = document.getElementById("".concat(COMPONENT_RETENTION_ID, "-sub-title"));
558
576
  if (retentionMessage) {
559
577
  var _closeDialogData$mess, _closeDialogData$mess2, _closeDialogData$mess3;
560
578
  retentionMessage.style.fontSize = "".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$mess = closeDialogData.message) === null || _closeDialogData$mess === void 0 ? void 0 : _closeDialogData$mess.fontSize, "px");
561
579
  retentionMessage.style.color = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$mess2 = closeDialogData.message) === null || _closeDialogData$mess2 === void 0 ? void 0 : _closeDialogData$mess2.fontColor;
562
580
  retentionMessage.innerHTML = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$mess3 = closeDialogData.message) === null || _closeDialogData$mess3 === void 0 ? void 0 : _closeDialogData$mess3.text;
563
581
  }
564
- var remainBtn = document.getElementById("".concat(componentRetentionId, "-remain"));
582
+ var remainBtn = document.getElementById("".concat(COMPONENT_RETENTION_ID, "-remain"));
565
583
  if (remainBtn) {
566
584
  var _closeDialogData$btnO, _closeDialogData$btnO2, _closeDialogData$btnO3, _closeDialogData$btnO4, _closeDialogData$btnO5, _closeDialogData$btnO7;
567
585
  remainBtn.innerHTML = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO = closeDialogData.btnOK) === null || _closeDialogData$btnO === void 0 ? void 0 : _closeDialogData$btnO.text;
@@ -573,7 +591,7 @@ var ComponentApp = /*#__PURE__*/function () {
573
591
  remainBtn.style.border = "1px solid ".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO6 = closeDialogData.btnOK) === null || _closeDialogData$btnO6 === void 0 ? void 0 : _closeDialogData$btnO6.bg);
574
592
  } else remainBtn.style.backgroundColor = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO7 = closeDialogData.btnOK) === null || _closeDialogData$btnO7 === void 0 ? void 0 : _closeDialogData$btnO7.bg;
575
593
  }
576
- var leaveBrn = document.getElementById("".concat(componentRetentionId, "-leave"));
594
+ var leaveBrn = document.getElementById("".concat(COMPONENT_RETENTION_ID, "-leave"));
577
595
  if (leaveBrn) {
578
596
  var _closeDialogData$btnC, _closeDialogData$btnC2, _closeDialogData$btnC3, _closeDialogData$btnC4, _closeDialogData$btnC5, _closeDialogData$btnC7;
579
597
  leaveBrn.innerHTML = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnC = closeDialogData.btnCancel) === null || _closeDialogData$btnC === void 0 ? void 0 : _closeDialogData$btnC.text;
@@ -593,11 +611,11 @@ var ComponentApp = /*#__PURE__*/function () {
593
611
  }, {
594
612
  key: "handleCloseBtnShow",
595
613
  value: function handleCloseBtnShow(showClose) {
596
- var closeBlock = document.getElementById(componentCloseBlockId);
614
+ var closeBlock = document.getElementById(COMPONENT_CLOSE_BLOCK_ID);
597
615
  if (showClose) {
598
- closeBlock === null || closeBlock === void 0 ? void 0 : closeBlock.classList.remove("".concat(componentCloseBlockId, "-hidden"));
616
+ closeBlock === null || closeBlock === void 0 ? void 0 : closeBlock.classList.remove("".concat(COMPONENT_CLOSE_BLOCK_ID, "-hidden"));
599
617
  } else if (showClose === false) {
600
- closeBlock === null || closeBlock === void 0 ? void 0 : closeBlock.classList.add("".concat(componentCloseBlockId, "-hidden"));
618
+ closeBlock === null || closeBlock === void 0 ? void 0 : closeBlock.classList.add("".concat(COMPONENT_CLOSE_BLOCK_ID, "-hidden"));
601
619
  }
602
620
  }
603
621
 
@@ -711,71 +729,39 @@ var ComponentApp = /*#__PURE__*/function () {
711
729
  }
712
730
  return sendRenderEvent;
713
731
  }()
714
- }, {
715
- key: "showPopupLoading",
716
- value: function showPopupLoading() {
717
- var loading = document.createElement('div');
718
- loading === null || loading === void 0 ? void 0 : loading.classList.add(loadingId);
719
- loading.id = loadingId;
720
- loading.innerHTML = '<div class="line"><div></div><div></div><div></div><div></div></div>';
721
- loading.style.fontSize = "".concat(getDesignFontSize(), "px");
722
- var body = document.getElementsByTagName('body')[0];
723
- body === null || body === void 0 ? void 0 : body.appendChild(loading);
724
- }
725
-
726
- /**
727
- * @description show cashier
728
- */
729
- }, {
730
- key: "setContainerClass",
731
- value: function setContainerClass() {
732
- var cashier = document.getElementById(componentContainerId);
733
- cashier === null || cashier === void 0 ? void 0 : cashier.classList.remove("".concat(componentContainerId, "-hidden-").concat(this.platform));
734
- cashier === null || cashier === void 0 ? void 0 : cashier.classList.add("".concat(componentContainerId, "-").concat(this.platform));
735
- }
736
-
737
732
  /**
738
733
  * @description close cashier
739
734
  */
740
735
  }, {
741
736
  key: "cleanContainer",
742
737
  value: function cleanContainer() {
743
- var _document$getElementB3;
738
+ var _document$getElementB4,
739
+ _this5 = this;
744
740
  var immediately = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
745
741
  this._loadAppPromiseResolve && this._loadAppPromiseResolve(true);
746
742
  this._performanceData = [];
747
743
  this._isInitComponent = false;
748
- (_document$getElementB3 = document.getElementById(loadingId)) === null || _document$getElementB3 === void 0 ? void 0 : _document$getElementB3.remove();
749
- this.hideComponentAndCleanDom(immediately);
744
+ this.app = null;
745
+ (_document$getElementB4 = document.getElementById(LOADING_ID)) === null || _document$getElementB4 === void 0 ? void 0 : _document$getElementB4.remove();
746
+ this.hideComponentAnimation();
747
+ var mockup = document.getElementById(MOCKUP_ID);
748
+ mockup === null || mockup === void 0 ? void 0 : mockup.classList.add("".concat(MOCKUP_ID, "-hidden"));
749
+ if (immediately) this.cleanElement();else {
750
+ setTimeout(function () {
751
+ _this5.cleanElement();
752
+ }, 300);
753
+ }
750
754
  }
751
755
  }, {
752
- key: "hideComponentAndCleanDom",
753
- value: function hideComponentAndCleanDom() {
754
- var _this5 = this;
755
- var immediately = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
756
- var container = document.getElementById(componentContainerId);
756
+ key: "hideComponentAnimation",
757
+ value: function hideComponentAnimation() {
758
+ var container = document.getElementById(COMPONENT_CONTAINER_ID);
757
759
  if (container) {
758
760
  // size变化动画取消
759
761
  container.style.transition = '';
760
- container === null || container === void 0 ? void 0 : container.classList.remove("".concat(componentContainerId, "-").concat(this.platform));
761
- container === null || container === void 0 ? void 0 : container.classList.remove("".concat(componentContainerId, "-").concat(this.platform, "-animation"));
762
- container === null || container === void 0 ? void 0 : container.classList.add("".concat(componentContainerId, "-hidden-").concat(this.platform));
763
- }
764
- var removeMockupAndApp = function removeMockupAndApp() {
765
- var _document$getElementB4;
766
- var body = document.getElementsByTagName('body')[0];
767
- body.style.overflow = 'auto';
768
- var mockup = document.getElementById(mockupId);
769
- mockup === null || mockup === void 0 ? void 0 : mockup.remove();
770
- if (container) container.style.height = '';
771
- (_document$getElementB4 = document.getElementById("".concat(componentContainerId, "-").concat(_this5.platform, "-animation-style"))) === null || _document$getElementB4 === void 0 ? void 0 : _document$getElementB4.remove();
772
- _this5.removeRetentionPopup();
773
- _this5.cleanApp();
774
- };
775
- if (immediately) removeMockupAndApp();else {
776
- setTimeout(function () {
777
- removeMockupAndApp();
778
- }, 300);
762
+ container === null || container === void 0 ? void 0 : container.classList.remove("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform));
763
+ container === null || container === void 0 ? void 0 : container.classList.remove("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation"));
764
+ container === null || container === void 0 ? void 0 : container.classList.add("".concat(COMPONENT_CONTAINER_ID, "-hidden-").concat(this.platform));
779
765
  }
780
766
  }
781
767
  }, {
@@ -787,143 +773,33 @@ var ComponentApp = /*#__PURE__*/function () {
787
773
  this.dispatchToSDK(EVENT.close.name, {});
788
774
  }
789
775
  }
790
-
791
- /**
792
- * @description create mount node
793
- */
794
- }, {
795
- key: "createBaseElement",
796
- value: function createBaseElement() {
797
- if (document.getElementById(componentContainerId)) return;
798
- componentAddCSS();
799
- addSetFontSizeEvent();
800
- var amsComponentContainer = document.createElement('div');
801
- amsComponentContainer.className = "".concat(componentContainerId, "-hidden-").concat(this.platform);
802
- amsComponentContainer.id = componentContainerId;
803
- amsSetSize(null, amsComponentContainer);
804
- document.body.appendChild(amsComponentContainer);
805
- var amsComponentSection = document.createElement('div');
806
- amsComponentSection.className = "ams-component-section-".concat(this.platform);
807
- amsComponentSection.id = componentSectionId;
808
- amsComponentContainer.appendChild(amsComponentSection);
809
- this.createCloseBtn();
810
- }
811
- }, {
812
- key: "createInlineBaseElement",
813
- value: function createInlineBaseElement(renderParams) {
814
- var _renderParams$appeara2;
815
- var inlineBaseStyle = document.getElementById(inlineBaseStyleId);
816
- if (!inlineBaseStyle) inlineComponentAddCss();
817
- if (document.getElementById(componentContainerId)) return;
818
- var amsComponentContainer = document.createElement('div');
819
- amsComponentContainer.className = "".concat(componentContainerId, "-inline");
820
- amsComponentContainer.id = componentContainerId;
821
- var selectorDom = document.querySelector(this._selector);
822
- if (selectorDom) selectorDom.appendChild(amsComponentContainer);
823
- var showLoading = renderParams === null || renderParams === void 0 ? void 0 : (_renderParams$appeara2 = renderParams.appearance) === null || _renderParams$appeara2 === void 0 ? void 0 : _renderParams$appeara2.showLoading;
824
- showLoading = typeof showLoading === 'boolean' ? showLoading : true;
825
- if (showLoading) showInlineLoading(amsComponentContainer, this.platform);
826
- }
827
- }, {
828
- key: "createCloseBtn",
829
- value: function createCloseBtn() {
830
- var _this6 = this;
831
- var container = document.getElementById(componentContainerId);
832
- // close btn
833
- var closeBtnHTML = "<img class='".concat(componentCloseBlockId, "-btn-").concat(this.platform, "' src=\"").concat(closeImg, "\"/>");
834
- var closeBlock = document.createElement('div');
835
- closeBlock.classList.add("".concat(componentCloseBlockId, "-").concat(this.platform), "".concat(componentCloseBlockId, "-hidden"));
836
- closeBlock.id = componentCloseBlockId;
837
- closeBlock.innerHTML = closeBtnHTML;
838
- closeBlock.addEventListener(this._clickEventName, function () {
839
- _this6.closeBtnFunc();
840
- });
841
- if (container) container.appendChild(closeBlock);
842
- }
843
- }, {
844
- key: "createRetentionPopup",
845
- value: function createRetentionPopup() {
846
- // retention popup
847
- var retentionPopup = document.createElement('div');
848
- retentionPopup.id = componentRetentionId;
849
- retentionPopup.classList.add("".concat(componentRetentionId, "-").concat(this.platform));
850
- retentionPopup.innerHTML = "\n <span id=\"".concat(componentRetentionId, "-title\" class=\"").concat(componentRetentionId, "-title-").concat(this.platform, "\">\n Are you sure you want to leave?\n </span>\n <span\n id=\"").concat(componentRetentionId, "-sub-title\"\n class=\"").concat(componentRetentionId, "-sub-title-").concat(this.platform, "\"\n >\n If you leave this page, you'll have to start over again.\n </span>\n <div class=\"").concat(componentRetentionId, "-btn-block-").concat(this.platform, "\">\n <div id=\"").concat(componentRetentionId, "-remain\" class=\"").concat(componentRetentionId, "-remain-").concat(this.platform, "\">\n Continue Payment\n </div>\n <div id=\"").concat(componentRetentionId, "-leave\" class=\"").concat(componentRetentionId, "-leave-").concat(this.platform, "\">\n Leave\n </div>\n </div>");
851
- document.body.appendChild(retentionPopup);
852
- var remainBtn = document.getElementById("".concat(componentRetentionId, "-remain"));
853
- if (remainBtn) {
854
- remainBtn.addEventListener(this._clickEventName, this.hideRetentionPopup.bind(this));
855
- }
856
- var leaveBtn = document.getElementById("".concat(componentRetentionId, "-leave"));
857
- if (leaveBtn) {
858
- leaveBtn.addEventListener(this._clickEventName, this.retentionPopupLeaveFunc.bind(this));
859
- }
860
- }
861
776
  }, {
862
777
  key: "retentionPopupLeaveFunc",
863
778
  value: function retentionPopupLeaveFunc() {
864
779
  this.dispatchToSDK(EVENT.close.name, {});
865
- this.hideRetentionPopup();
780
+ this.hideRetentionPopupFunc();
866
781
  this.cleanContainer();
867
782
  }
868
783
  }, {
869
784
  key: "removeRetentionPopup",
870
- value: function removeRetentionPopup() {
871
- var _document$getElementB5;
872
- var remainBtn = document.getElementById("".concat(componentRetentionId, "-remain"));
873
- if (remainBtn) {
874
- remainBtn.removeEventListener(this._clickEventName, this.hideRetentionPopup);
875
- }
876
- var leaveBtn = document.getElementById("".concat(componentRetentionId, "-leave"));
877
- if (leaveBtn) {
878
- leaveBtn.removeEventListener(this._clickEventName, this.retentionPopupLeaveFunc);
879
- }
880
- (_document$getElementB5 = document.getElementById(componentRetentionId)) === null || _document$getElementB5 === void 0 ? void 0 : _document$getElementB5.remove();
785
+ value: function removeRetentionPopup(platform) {
786
+ _removeRetentionPopup(platform, this.hideRetentionPopupFunc, this.retentionPopupLeaveFunc);
881
787
  }
882
788
  }, {
883
789
  key: "showRetentionPopup",
884
790
  value: function showRetentionPopup() {
885
- var retentionPopup = document.getElementById(componentRetentionId);
886
- var container = document.getElementById(componentContainerId);
791
+ var retentionPopup = document.getElementById(COMPONENT_RETENTION_ID);
792
+ var container = document.getElementById(COMPONENT_CONTAINER_ID);
887
793
  if (retentionPopup) {
888
- container === null || container === void 0 ? void 0 : container.classList.add("".concat(componentContainerId, "-opacity"));
889
- retentionPopup.classList.remove("".concat(componentRetentionId, "-hidden"));
890
- retentionPopup.classList.add("".concat(componentRetentionId, "-show"));
794
+ container === null || container === void 0 ? void 0 : container.classList.add("".concat(COMPONENT_CONTAINER_ID, "-opacity"));
795
+ retentionPopup.classList.remove("".concat(COMPONENT_RETENTION_ID, "-hidden"));
796
+ retentionPopup.classList.add("".concat(COMPONENT_RETENTION_ID, "-show"));
891
797
  }
892
798
  }
893
799
  }, {
894
- key: "hideRetentionPopup",
895
- value: function hideRetentionPopup() {
896
- var retentionPopup = document.getElementById(componentRetentionId);
897
- var container = document.getElementById(componentContainerId);
898
- if (retentionPopup) {
899
- retentionPopup.classList.remove("".concat(componentRetentionId, "-show"));
900
- retentionPopup.classList.add("".concat(componentRetentionId, "-hidden"));
901
- setTimeout(function () {
902
- retentionPopup.classList.remove("".concat(componentRetentionId, "-hidden"));
903
- container === null || container === void 0 ? void 0 : container.classList.remove("".concat(componentContainerId, "-opacity"));
904
- }, 300);
905
- }
906
- }
907
- /**
908
- * @description create mockup
909
- */
910
- }, {
911
- key: "createMockup",
912
- value: function createMockup() {
913
- var body = document.getElementsByTagName('body')[0];
914
- body.style.overflow = 'hidden';
915
- var mockup = document.createElement('div');
916
- mockup.style.width = '100vw';
917
- mockup.style.height = '100vh';
918
- mockup.style.position = 'fixed';
919
- mockup.style.top = '0';
920
- mockup.style.left = '0';
921
- mockup.style.zIndex = '1000';
922
- mockup.style.background = '#ffffff';
923
- mockup.style.opacity = '0.5';
924
- mockup.style.display = 'none';
925
- mockup.id = mockupId;
926
- body.appendChild(mockup);
800
+ key: "hideRetentionPopupFunc",
801
+ value: function hideRetentionPopupFunc() {
802
+ hideRetentionPopup();
927
803
  }
928
804
  }, {
929
805
  key: "submitForm",
@@ -235,6 +235,16 @@ export interface CashierSdkActionQueryResult {
235
235
  schemeUrl?: string;
236
236
  authUrl?: string;
237
237
  }
238
+ export declare enum eventCodeEnum {
239
+ SDK_START_OF_LOADING = "SDK_START_OF_LOADING",
240
+ SDK_END_OF_LOADING = "SDK_END_OF_LOADING",
241
+ SDK_INTERNAL_ERROR = "SDK_INTERNAL_ERROR",
242
+ SDK_CREATEPAYMENT_PARAMETER_ERROR = "SDK_CREATEPAYMENT_PARAMETER_ERROR",
243
+ SDK_INIT_PARAMETER_ERROR = "SDK_INIT_PARAMETER_ERROR",
244
+ SDK_CREATECOMPONENT_ERROR = "SDK_CREATECOMPONENT_ERROR",
245
+ SDK_CALL_URL_ERROR = "SDK_CALL_URL_ERROR",
246
+ SDK_CALL_URL_SUCCESS = "SDK_CALL_URL_SUCCESS"
247
+ }
238
248
  declare global {
239
249
  interface Window {
240
250
  [key: string]: any;
@@ -120,4 +120,15 @@ export var errorEnum = /*#__PURE__*/function (errorEnum) {
120
120
  errorEnum["SIGNIN"] = "SIGNIN";
121
121
  errorEnum["GETSIGNPARAMSERROR"] = "GETSIGNPARAMSERROR";
122
122
  return errorEnum;
123
+ }({});
124
+ export var eventCodeEnum = /*#__PURE__*/function (eventCodeEnum) {
125
+ eventCodeEnum["SDK_START_OF_LOADING"] = "SDK_START_OF_LOADING";
126
+ eventCodeEnum["SDK_END_OF_LOADING"] = "SDK_END_OF_LOADING";
127
+ eventCodeEnum["SDK_INTERNAL_ERROR"] = "SDK_INTERNAL_ERROR";
128
+ eventCodeEnum["SDK_CREATEPAYMENT_PARAMETER_ERROR"] = "SDK_CREATEPAYMENT_PARAMETER_ERROR";
129
+ eventCodeEnum["SDK_INIT_PARAMETER_ERROR"] = "SDK_INIT_PARAMETER_ERROR";
130
+ eventCodeEnum["SDK_CREATECOMPONENT_ERROR"] = "SDK_CREATECOMPONENT_ERROR";
131
+ eventCodeEnum["SDK_CALL_URL_ERROR"] = "SDK_CALL_URL_ERROR";
132
+ eventCodeEnum["SDK_CALL_URL_SUCCESS"] = "SDK_CALL_URL_SUCCESS";
133
+ return eventCodeEnum;
123
134
  }({});
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@alipay/ams-checkout","version":"0.0.1691743027-dev.3","description":"","author":"","main":"esm/index.js","module":"esm/index.js","typings":"esm/index.d.ts","files":["dist","esm","LEGAL.md","LICENSE","README.md"],"scripts":{"build":"father build","ci":"npm run lint","cov":"jest --coverage","format":"prettier --write --no-error-on-unmatched-pattern \"**/*.{js,jsx,ts,tsx,md,json,css,less}\"","lint":"eslint ./src","test":"jest"},"dependencies":{"axios":"^1.3.4","uuid":"^9.0.0"},"devDependencies":{"@babel/core":"^7.20.7","@babel/preset-env":"^7.20.2","@testing-library/jest-dom":"^5.1.1","@testing-library/react":"^9.5.0","@types/jest":"^29.2.4","@types/uuid":"^9.0.0","@typescript-eslint/parser":"^5.60.0","babel-jest":"^29.3.1","babel-loader":"^9.1.0","babel-plugin-import":"^1.13.0","eslint":"^8.36.0","father":"^4.2.3","jest":"^29.5.0","jest-environment-jsdom":"^29.3.1","prettier":"^2.8.4","prettier-plugin-organize-imports":"^3.2.3","prettier-plugin-packagejson":"^2.4.5","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"^4.9.5"},"engines":{},"publishConfig":{"access":"public"}}
1
+ {"name":"@alipay/ams-checkout","version":"0.0.1691743027-dev.5","description":"","author":"","main":"esm/index.js","module":"esm/index.js","typings":"esm/index.d.ts","files":["dist","esm","LEGAL.md","LICENSE","README.md"],"scripts":{"build":"father build","ci":"npm run lint","cov":"jest --coverage","format":"prettier --write --no-error-on-unmatched-pattern \"**/*.{js,jsx,ts,tsx,md,json,css,less}\"","lint":"eslint ./src","test":"jest"},"dependencies":{"axios":"^1.3.4","uuid":"^9.0.0"},"devDependencies":{"@babel/core":"^7.20.7","@babel/preset-env":"^7.20.2","@testing-library/jest-dom":"^5.1.1","@testing-library/react":"^9.5.0","@types/jest":"^29.2.4","@types/uuid":"^9.0.0","@typescript-eslint/parser":"^5.60.0","babel-jest":"^29.3.1","babel-loader":"^9.1.0","babel-plugin-import":"^1.13.0","eslint":"^8.36.0","father":"^4.2.3","jest":"^29.5.0","jest-environment-jsdom":"^29.3.1","prettier":"^2.8.4","prettier-plugin-organize-imports":"^3.2.3","prettier-plugin-packagejson":"^2.4.5","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"^4.9.5"},"engines":{},"publishConfig":{"access":"public"}}