@tuya-miniapp/smart-ui 2.1.7 → 2.1.8-beta-2

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,6 +46,9 @@ interface DialogInputOptions extends DialogOptions {
46
46
  placeholder?: string;
47
47
  maxlength?: number;
48
48
  }
49
+ export declare const contextRef: {
50
+ value: DialogContext | null;
51
+ };
49
52
  declare const Dialog: {
50
53
  (options: DialogOptions): Promise<WechatMiniprogram.Component.TrivialInstance>;
51
54
  alert(options: DialogOptions): Promise<WechatMiniprogram.Component.TrivialInstance>;
@@ -1,3 +1,4 @@
1
+ import { getCurrentPage } from '../common/utils';
1
2
  let queue = [];
2
3
  const defaultOptions = {
3
4
  show: false,
@@ -28,15 +29,16 @@ const defaultOptions = {
28
29
  maxlength: 20,
29
30
  };
30
31
  let currentOptions = Object.assign({}, defaultOptions);
31
- function getContext() {
32
- const pages = getCurrentPages();
33
- return pages[pages.length - 1];
34
- }
32
+ export const contextRef = {
33
+ value: null,
34
+ };
35
35
  const Dialog = (options) => {
36
36
  options = Object.assign(Object.assign({}, currentOptions), options);
37
37
  return new Promise((resolve, reject) => {
38
38
  var _a;
39
- const context = (typeof options.context === 'function' ? options.context() : options.context) || getContext();
39
+ const context = (typeof options.context === 'function' ? options.context() : options.context) ||
40
+ contextRef.value ||
41
+ getCurrentPage();
40
42
  const selector = options.selector;
41
43
  const dialog = context.selectComponent(options.selector);
42
44
  if ((queue === null || queue === void 0 ? void 0 : queue.length) > 0 && ((_a = queue === null || queue === void 0 ? void 0 : queue[0]) === null || _a === void 0 ? void 0 : _a.id) === (dialog === null || dialog === void 0 ? void 0 : dialog.id)) {
@@ -1,7 +1,8 @@
1
1
  import warningIcon from '@tuya-miniapp/icons/dist/svg/Warning';
2
2
  import { SmartComponent } from '../common/component';
3
3
  import { button } from '../mixins/button';
4
- import { toPromise } from '../common/utils';
4
+ import { getCurrentPage, toPromise } from '../common/utils';
5
+ import { contextRef } from './dialog';
5
6
  SmartComponent({
6
7
  mixins: [button],
7
8
  classes: ['cancle-button-class', 'confirm-button-class'],
@@ -90,6 +91,9 @@ SmartComponent({
90
91
  },
91
92
  callback: (() => { }),
92
93
  },
94
+ mounted: function () {
95
+ contextRef.value = getCurrentPage();
96
+ },
93
97
  methods: {
94
98
  onConfirm() {
95
99
  this.handleAction('confirm');
@@ -1,6 +1,7 @@
1
1
  import { SmartComponent } from '../common/component';
2
2
  import { WHITE } from '../common/color';
3
- import { getSystemInfoSync } from '../common/utils';
3
+ import { getCurrentPage, getSystemInfoSync } from '../common/utils';
4
+ import { contextRef } from './notify';
4
5
  SmartComponent({
5
6
  props: {
6
7
  message: String,
@@ -45,6 +46,9 @@ SmartComponent({
45
46
  const { statusBarHeight } = getSystemInfoSync();
46
47
  this.setData({ statusBarHeight });
47
48
  },
49
+ mounted: function () {
50
+ contextRef.value = getCurrentPage();
51
+ },
48
52
  methods: {
49
53
  show() {
50
54
  const { duration, onOpened } = this.data;
@@ -1,3 +1,6 @@
1
+ /// <reference types="miniprogram-api-typings" />
2
+ /// <reference types="miniprogram-api-typings" />
3
+ type NotifyContext = WechatMiniprogram.Component.TrivialInstance | WechatMiniprogram.Page.TrivialInstance;
1
4
  interface NotifyOptions {
2
5
  type?: 'primary' | 'success' | 'danger' | 'warning';
3
6
  transition?: 'fade' | 'fade-up' | 'fade-down' | 'fade-left' | 'fade-right' | 'slide-up' | 'slide-down' | 'slide-left' | 'slide-right';
@@ -14,6 +17,9 @@ interface NotifyOptions {
14
17
  onOpened?: () => void;
15
18
  onClose?: () => void;
16
19
  }
20
+ export declare const contextRef: {
21
+ value: NotifyContext | null;
22
+ };
17
23
  declare function Notify(options: NotifyOptions | string): any;
18
24
  declare namespace Notify {
19
25
  var clear: (options?: NotifyOptions | undefined) => void;
@@ -1,3 +1,4 @@
1
+ import { getCurrentPage } from '../common/utils';
1
2
  import { WHITE } from '../common/color';
2
3
  const defaultOptions = {
3
4
  selector: '#smart-notify',
@@ -20,13 +21,14 @@ function parseOptions(message) {
20
21
  }
21
22
  return typeof message === 'string' ? { message } : message;
22
23
  }
23
- function getContext() {
24
- const pages = getCurrentPages();
25
- return pages[pages.length - 1];
26
- }
24
+ export const contextRef = {
25
+ value: null,
26
+ };
27
27
  export default function Notify(options) {
28
28
  options = Object.assign(Object.assign({}, currentOptions), parseOptions(options));
29
- const context = options.context || getContext();
29
+ const context = (typeof options.context === 'function' ? options.context() : options.context) ||
30
+ contextRef.value ||
31
+ getCurrentPage();
30
32
  const notify = context.selectComponent(options.selector);
31
33
  delete options.context;
32
34
  delete options.selector;
@@ -39,7 +41,9 @@ export default function Notify(options) {
39
41
  }
40
42
  Notify.clear = function (options) {
41
43
  options = Object.assign(Object.assign({}, defaultOptions), parseOptions(options));
42
- const context = options.context || getContext();
44
+ const context = (typeof options.context === 'function' ? options.context() : options.context) ||
45
+ contextRef.value ||
46
+ getCurrentPage();
43
47
  const notify = context.selectComponent(options.selector);
44
48
  if (notify) {
45
49
  notify.hide();
@@ -1,5 +1,7 @@
1
1
  import { Success, Alarm, Error } from './icons';
2
2
  import { SmartComponent } from '../common/component';
3
+ import { contextRef } from './toast';
4
+ import { getCurrentPage } from '../common/utils';
3
5
  SmartComponent({
4
6
  props: {
5
7
  show: Boolean,
@@ -10,7 +12,6 @@ SmartComponent({
10
12
  type: Number,
11
13
  value: 1000,
12
14
  },
13
- //
14
15
  type: {
15
16
  type: String,
16
17
  value: 'text',
@@ -32,6 +33,9 @@ SmartComponent({
32
33
  error: Error,
33
34
  warn: Alarm,
34
35
  },
36
+ mounted: function () {
37
+ contextRef.value = getCurrentPage();
38
+ },
35
39
  methods: {
36
40
  // for prevent touchmove
37
41
  noop() { },
@@ -14,6 +14,7 @@
14
14
  catch:touchmove="noop"
15
15
  style="{{ width ? ('width: ' + width + 'px') : '' }}"
16
16
  >
17
+
17
18
  <!-- text only -->
18
19
  <text wx:if="{{ type === 'text' }}">{{ message }}</text>
19
20
 
@@ -17,6 +17,9 @@ interface ToastOptions {
17
17
  onClose?: () => void;
18
18
  width?: number;
19
19
  }
20
+ export declare const contextRef: {
21
+ value: ToastContext | null;
22
+ };
20
23
  declare function Toast(toastOptions: ToastOptions | ToastMessage): WechatMiniprogram.Component.TrivialInstance | undefined;
21
24
  declare namespace Toast {
22
25
  var loading: (options: ToastMessage | ToastOptions) => WechatMiniprogram.Component.TrivialInstance | undefined;
@@ -1,3 +1,4 @@
1
+ import { getCurrentPage } from '../common/utils';
1
2
  import { isObj } from '../common/validator';
2
3
  const defaultOptions = {
3
4
  type: 'text',
@@ -18,13 +19,14 @@ let currentOptions = Object.assign({}, defaultOptions);
18
19
  function parseOptions(message) {
19
20
  return isObj(message) ? message : { message };
20
21
  }
21
- function getContext() {
22
- const pages = getCurrentPages();
23
- return pages[pages.length - 1];
24
- }
22
+ export const contextRef = {
23
+ value: null,
24
+ };
25
25
  function Toast(toastOptions) {
26
26
  const options = Object.assign(Object.assign({}, currentOptions), parseOptions(toastOptions));
27
- const context = (typeof options.context === 'function' ? options.context() : options.context) || getContext();
27
+ const context = (typeof options.context === 'function' ? options.context() : options.context) ||
28
+ contextRef.value ||
29
+ getCurrentPage();
28
30
  const toast = context.selectComponent(options.selector);
29
31
  if (!toast) {
30
32
  console.warn('未找到 smart-toast 节点,请确认 selector 及 context 是否正确');
@@ -46,6 +46,9 @@ interface DialogInputOptions extends DialogOptions {
46
46
  placeholder?: string;
47
47
  maxlength?: number;
48
48
  }
49
+ export declare const contextRef: {
50
+ value: DialogContext | null;
51
+ };
49
52
  declare const Dialog: {
50
53
  (options: DialogOptions): Promise<WechatMiniprogram.Component.TrivialInstance>;
51
54
  alert(options: DialogOptions): Promise<WechatMiniprogram.Component.TrivialInstance>;
@@ -11,6 +11,8 @@ var __assign = (this && this.__assign) || function () {
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.contextRef = void 0;
15
+ var utils_1 = require("../common/utils");
14
16
  var queue = [];
15
17
  var defaultOptions = {
16
18
  show: false,
@@ -41,15 +43,16 @@ var defaultOptions = {
41
43
  maxlength: 20,
42
44
  };
43
45
  var currentOptions = __assign({}, defaultOptions);
44
- function getContext() {
45
- var pages = getCurrentPages();
46
- return pages[pages.length - 1];
47
- }
46
+ exports.contextRef = {
47
+ value: null,
48
+ };
48
49
  var Dialog = function (options) {
49
50
  options = __assign(__assign({}, currentOptions), options);
50
51
  return new Promise(function (resolve, reject) {
51
52
  var _a;
52
- var context = (typeof options.context === 'function' ? options.context() : options.context) || getContext();
53
+ var context = (typeof options.context === 'function' ? options.context() : options.context) ||
54
+ exports.contextRef.value ||
55
+ (0, utils_1.getCurrentPage)();
53
56
  var selector = options.selector;
54
57
  var dialog = context.selectComponent(options.selector);
55
58
  if ((queue === null || queue === void 0 ? void 0 : queue.length) > 0 && ((_a = queue === null || queue === void 0 ? void 0 : queue[0]) === null || _a === void 0 ? void 0 : _a.id) === (dialog === null || dialog === void 0 ? void 0 : dialog.id)) {
@@ -7,6 +7,7 @@ var Warning_1 = __importDefault(require("@tuya-miniapp/icons/dist/svg/Warning"))
7
7
  var component_1 = require("../common/component");
8
8
  var button_1 = require("../mixins/button");
9
9
  var utils_1 = require("../common/utils");
10
+ var dialog_1 = require("./dialog");
10
11
  (0, component_1.SmartComponent)({
11
12
  mixins: [button_1.button],
12
13
  classes: ['cancle-button-class', 'confirm-button-class'],
@@ -95,6 +96,9 @@ var utils_1 = require("../common/utils");
95
96
  },
96
97
  callback: (function () { }),
97
98
  },
99
+ mounted: function () {
100
+ dialog_1.contextRef.value = (0, utils_1.getCurrentPage)();
101
+ },
98
102
  methods: {
99
103
  onConfirm: function () {
100
104
  this.handleAction('confirm');
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var component_1 = require("../common/component");
4
4
  var color_1 = require("../common/color");
5
5
  var utils_1 = require("../common/utils");
6
+ var notify_1 = require("./notify");
6
7
  (0, component_1.SmartComponent)({
7
8
  props: {
8
9
  message: String,
@@ -47,6 +48,9 @@ var utils_1 = require("../common/utils");
47
48
  var statusBarHeight = (0, utils_1.getSystemInfoSync)().statusBarHeight;
48
49
  this.setData({ statusBarHeight: statusBarHeight });
49
50
  },
51
+ mounted: function () {
52
+ notify_1.contextRef.value = (0, utils_1.getCurrentPage)();
53
+ },
50
54
  methods: {
51
55
  show: function () {
52
56
  var _this = this;
@@ -1,3 +1,6 @@
1
+ /// <reference types="miniprogram-api-typings" />
2
+ /// <reference types="miniprogram-api-typings" />
3
+ type NotifyContext = WechatMiniprogram.Component.TrivialInstance | WechatMiniprogram.Page.TrivialInstance;
1
4
  interface NotifyOptions {
2
5
  type?: 'primary' | 'success' | 'danger' | 'warning';
3
6
  transition?: 'fade' | 'fade-up' | 'fade-down' | 'fade-left' | 'fade-right' | 'slide-up' | 'slide-down' | 'slide-left' | 'slide-right';
@@ -14,6 +17,9 @@ interface NotifyOptions {
14
17
  onOpened?: () => void;
15
18
  onClose?: () => void;
16
19
  }
20
+ export declare const contextRef: {
21
+ value: NotifyContext | null;
22
+ };
17
23
  declare function Notify(options: NotifyOptions | string): any;
18
24
  declare namespace Notify {
19
25
  var clear: (options?: NotifyOptions | undefined) => void;
@@ -11,6 +11,8 @@ var __assign = (this && this.__assign) || function () {
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.contextRef = void 0;
15
+ var utils_1 = require("../common/utils");
14
16
  var color_1 = require("../common/color");
15
17
  var defaultOptions = {
16
18
  selector: '#smart-notify',
@@ -33,13 +35,14 @@ function parseOptions(message) {
33
35
  }
34
36
  return typeof message === 'string' ? { message: message } : message;
35
37
  }
36
- function getContext() {
37
- var pages = getCurrentPages();
38
- return pages[pages.length - 1];
39
- }
38
+ exports.contextRef = {
39
+ value: null,
40
+ };
40
41
  function Notify(options) {
41
42
  options = __assign(__assign({}, currentOptions), parseOptions(options));
42
- var context = options.context || getContext();
43
+ var context = (typeof options.context === 'function' ? options.context() : options.context) ||
44
+ exports.contextRef.value ||
45
+ (0, utils_1.getCurrentPage)();
43
46
  var notify = context.selectComponent(options.selector);
44
47
  delete options.context;
45
48
  delete options.selector;
@@ -53,7 +56,9 @@ function Notify(options) {
53
56
  exports.default = Notify;
54
57
  Notify.clear = function (options) {
55
58
  options = __assign(__assign({}, defaultOptions), parseOptions(options));
56
- var context = options.context || getContext();
59
+ var context = (typeof options.context === 'function' ? options.context() : options.context) ||
60
+ exports.contextRef.value ||
61
+ (0, utils_1.getCurrentPage)();
57
62
  var notify = context.selectComponent(options.selector);
58
63
  if (notify) {
59
64
  notify.hide();
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var icons_1 = require("./icons");
4
4
  var component_1 = require("../common/component");
5
+ var toast_1 = require("./toast");
6
+ var utils_1 = require("../common/utils");
5
7
  (0, component_1.SmartComponent)({
6
8
  props: {
7
9
  show: Boolean,
@@ -12,7 +14,6 @@ var component_1 = require("../common/component");
12
14
  type: Number,
13
15
  value: 1000,
14
16
  },
15
- //
16
17
  type: {
17
18
  type: String,
18
19
  value: 'text',
@@ -34,6 +35,9 @@ var component_1 = require("../common/component");
34
35
  error: icons_1.Error,
35
36
  warn: icons_1.Alarm,
36
37
  },
38
+ mounted: function () {
39
+ toast_1.contextRef.value = (0, utils_1.getCurrentPage)();
40
+ },
37
41
  methods: {
38
42
  // for prevent touchmove
39
43
  noop: function () { },
@@ -14,6 +14,7 @@
14
14
  catch:touchmove="noop"
15
15
  style="{{ width ? ('width: ' + width + 'px') : '' }}"
16
16
  >
17
+
17
18
  <!-- text only -->
18
19
  <text wx:if="{{ type === 'text' }}">{{ message }}</text>
19
20
 
@@ -17,6 +17,9 @@ interface ToastOptions {
17
17
  onClose?: () => void;
18
18
  width?: number;
19
19
  }
20
+ export declare const contextRef: {
21
+ value: ToastContext | null;
22
+ };
20
23
  declare function Toast(toastOptions: ToastOptions | ToastMessage): WechatMiniprogram.Component.TrivialInstance | undefined;
21
24
  declare namespace Toast {
22
25
  var loading: (options: ToastMessage | ToastOptions) => WechatMiniprogram.Component.TrivialInstance | undefined;
@@ -11,6 +11,8 @@ var __assign = (this && this.__assign) || function () {
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.contextRef = void 0;
15
+ var utils_1 = require("../common/utils");
14
16
  var validator_1 = require("../common/validator");
15
17
  var defaultOptions = {
16
18
  type: 'text',
@@ -31,13 +33,14 @@ var currentOptions = __assign({}, defaultOptions);
31
33
  function parseOptions(message) {
32
34
  return (0, validator_1.isObj)(message) ? message : { message: message };
33
35
  }
34
- function getContext() {
35
- var pages = getCurrentPages();
36
- return pages[pages.length - 1];
37
- }
36
+ exports.contextRef = {
37
+ value: null,
38
+ };
38
39
  function Toast(toastOptions) {
39
40
  var options = __assign(__assign({}, currentOptions), parseOptions(toastOptions));
40
- var context = (typeof options.context === 'function' ? options.context() : options.context) || getContext();
41
+ var context = (typeof options.context === 'function' ? options.context() : options.context) ||
42
+ exports.contextRef.value ||
43
+ (0, utils_1.getCurrentPage)();
41
44
  var toast = context.selectComponent(options.selector);
42
45
  if (!toast) {
43
46
  console.warn('未找到 smart-toast 节点,请确认 selector 及 context 是否正确');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-miniapp/smart-ui",
3
- "version": "2.1.7",
3
+ "version": "2.1.8-beta-2",
4
4
  "author": "MiniApp Team",
5
5
  "license": "MIT",
6
6
  "miniprogram": "lib",