sard-uniapp 1.1.4 → 1.1.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.
package/changelog.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [1.1.5](https://github.com/sutras/sard-uniapp/compare/v1.1.4...v1.1.5) (2024-05-18)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * 修复toast&dialog不显示问题 ([9e49c67](https://github.com/sutras/sard-uniapp/commit/9e49c6772e7d0cff8976133b1dc05fa69b51d7ea))
7
+
8
+
9
+
1
10
  ## [1.1.4](https://github.com/sutras/sard-uniapp/compare/v1.1.3...v1.1.4) (2024-05-17)
2
11
 
3
12
 
@@ -10,6 +10,10 @@ page {
10
10
  --sar-accordion-item-title-font-size: var(--sar-text-base);
11
11
  --sar-accordion-item-title-line-height: var(--sar-leading-snug);
12
12
 
13
+ --sar-accordion-item-arrow-margin-left: 16rpx;
14
+ --sar-accordion-item-arrow-font-size: var(--sar-text-base);
15
+ --sar-accordion-item-arrow-color: var(--sar-tertiary-color);
16
+
13
17
  --sar-accordion-item-body-padding-x: 32rpx;
14
18
  --sar-accordion-item-body-padding-y: 32rpx;
15
19
  }
@@ -8,8 +8,8 @@
8
8
  >
9
9
  <view :class="bem.e('title')">{{ title }}</view>
10
10
  <view v-if="value" :class="bem.e('value')">{{ value }}</view>
11
- <view :class="bem.e('icon')">
12
- <sar-icon :name="iconName" />
11
+ <view :class="bem.e('arrow')">
12
+ <sar-icon :name="arrowName" />
13
13
  </view>
14
14
  </view>
15
15
  <sar-collapse :visible="visible">
@@ -66,7 +66,7 @@ export default _defineComponent({
66
66
  const visible = computed(() => {
67
67
  return context.multiple ? (context.value || []).includes(props.name) : context.value === props.name;
68
68
  });
69
- const iconName = computed(() => {
69
+ const arrowName = computed(() => {
70
70
  return visible.value ? "up" : "down";
71
71
  });
72
72
  const accordionItemClass = computed(() => {
@@ -75,7 +75,7 @@ export default _defineComponent({
75
75
  const accordionItemStyle = computed(() => {
76
76
  return stringifyStyle(props.rootStyle);
77
77
  });
78
- const __returned__ = { props, emit, bem, context, onClick, visible, iconName, accordionItemClass, accordionItemStyle, get classNames() {
78
+ const __returned__ = { props, emit, bem, context, onClick, visible, arrowName, accordionItemClass, accordionItemStyle, get classNames() {
79
79
  return classNames;
80
80
  }, SarCollapse, SarIcon };
81
81
  return __returned__;
@@ -42,6 +42,15 @@
42
42
  line-height: var(--sar-accordion-item-title-line-height);
43
43
  }
44
44
 
45
+ @include e(arrow) {
46
+ @include universal;
47
+ align-items: center;
48
+ justify-content: center;
49
+ margin-left: var(--sar-accordion-item-arrow-margin-left);
50
+ font-size: var(--sar-accordion-item-arrow-font-size);
51
+ color: var(--sar-accordion-item-arrow-color);
52
+ }
53
+
45
54
  @include e(body) {
46
55
  @include universal;
47
56
  padding: var(--sar-accordion-item-body-padding-y)
@@ -11,10 +11,11 @@ export declare const dialogAgentPropsDefaults: {
11
11
  overlayClosable: boolean;
12
12
  duration: number;
13
13
  };
14
- export declare const mapIdImperatives: Record<string, {
15
- show(props: Record<string, any>): void;
14
+ export declare const imperativeName = "dialog";
15
+ export interface DialogImperative {
16
+ show(newProps: Record<string, any>): void;
16
17
  hide(): void;
17
- }[]>;
18
+ }
18
19
  export type DialogOptions = DialogAgentProps;
19
20
  export interface DialogSimpleShowFunction {
20
21
  (options: DialogOptions): void;
@@ -1,10 +1,11 @@
1
1
  import { dialogPropsDefaults } from '../dialog/common';
2
2
  import { defaultConfig } from '../config';
3
+ import { getAllImperatives, getAvailableImperative, getImperatives, } from '../../use/useImperative';
3
4
  export const dialogAgentPropsDefaults = {
4
5
  ...dialogPropsDefaults,
5
6
  ...defaultConfig.dialogAgent,
6
7
  };
7
- export const mapIdImperatives = {};
8
+ export const imperativeName = 'dialog';
8
9
  const defaultDialogOptions = {
9
10
  headed: false,
10
11
  buttonType: 'text',
@@ -19,9 +20,9 @@ const show = (optionsOrTitle, options = {}, internalOptions) => {
19
20
  }
20
21
  options = Object.assign({}, defaultDialogOptions, options, internalOptions);
21
22
  const { id = defaultConfig.dialogAgent.id } = options;
22
- const imperatives = mapIdImperatives[id];
23
- if (imperatives && imperatives.length > 0) {
24
- imperatives[imperatives.length - 1].show(options);
23
+ const imperative = getAvailableImperative(imperativeName, id);
24
+ if (imperative) {
25
+ imperative.show(options);
25
26
  }
26
27
  };
27
28
  const dialog = (optionsOrTitle, options) => {
@@ -36,15 +37,18 @@ const confirm = (optionsOrTitle, options) => {
36
37
  });
37
38
  };
38
39
  const hide = (id = defaultConfig.dialogAgent.id) => {
39
- const imperatives = mapIdImperatives[id];
40
+ const imperatives = getImperatives(imperativeName, id);
40
41
  if (imperatives && imperatives.length > 0) {
41
- imperatives.forEach((imperative) => {
42
- imperative.hide();
42
+ imperatives.forEach((item) => {
43
+ item.imperative.hide();
43
44
  });
44
45
  }
45
46
  };
46
47
  const hideAll = () => {
47
- Object.keys(mapIdImperatives).forEach(hide);
48
+ const mapImperatives = getAllImperatives()[imperativeName];
49
+ if (mapImperatives) {
50
+ Object.keys(mapImperatives).forEach(hide);
51
+ }
48
52
  };
49
53
  dialog.alert = alert;
50
54
  dialog.confirm = confirm;
@@ -18,12 +18,13 @@
18
18
 
19
19
  <script>
20
20
  import { mergeDefaults as _mergeDefaults, defineComponent as _defineComponent } from "vue";
21
- import { onMounted, onUnmounted, ref } from "vue";
21
+ import { computed, ref } from "vue";
22
22
  import SarDialog from "../dialog/dialog.vue";
23
23
  import {
24
24
  dialogAgentPropsDefaults,
25
- mapIdImperatives
25
+ imperativeName
26
26
  } from "./common";
27
+ import { useImperative } from "../../use/useImperative";
27
28
  export default _defineComponent({
28
29
  ...{
29
30
  options: {
@@ -68,23 +69,11 @@ export default _defineComponent({
68
69
  };
69
70
  }
70
71
  };
71
- onMounted(() => {
72
- const id = innerProps.value.id;
73
- if (id) {
74
- mapIdImperatives[id] ??= [];
75
- mapIdImperatives[id].push(imperative);
76
- }
77
- });
78
- onUnmounted(() => {
79
- const id = innerProps.value.id;
80
- if (id) {
81
- const imperatives = mapIdImperatives[id];
82
- const index = imperatives.indexOf(imperative);
83
- if (index !== -1) {
84
- imperatives.splice(imperatives.indexOf(imperative), 1);
85
- }
86
- }
87
- });
72
+ useImperative(
73
+ imperativeName,
74
+ imperative,
75
+ computed(() => innerProps.value.id)
76
+ );
88
77
  const __returned__ = { props, innerProps, imperative, SarDialog };
89
78
  return __returned__;
90
79
  }
@@ -10,10 +10,11 @@ export declare const toastAgentPropsDefaults: {
10
10
  timeout: number;
11
11
  duration: number;
12
12
  };
13
- export declare const mapIdImperatives: Record<string, {
14
- show(props: Record<string, any>): void;
13
+ export declare const imperativeName = "toast";
14
+ export interface ToastImperative {
15
+ show(newProps: Record<string, any>): void;
15
16
  hide(): void;
16
- }[]>;
17
+ }
17
18
  export type ToastOptions = ToastAgentProps;
18
19
  export interface ToastSimpleShowFunction {
19
20
  (options: ToastOptions): void;
@@ -1,10 +1,11 @@
1
+ import { getAllImperatives, getAvailableImperative, getImperatives, } from '../../use/useImperative';
1
2
  import { defaultConfig } from '../config';
2
3
  import { toastPropsDefaults } from '../toast/common';
3
4
  export const toastAgentPropsDefaults = {
4
5
  ...toastPropsDefaults,
5
6
  ...defaultConfig.toastAgent,
6
7
  };
7
- export const mapIdImperatives = {};
8
+ export const imperativeName = 'toast';
8
9
  const show = (optionsOrTitle, options = {}, internalType) => {
9
10
  if (optionsOrTitle && typeof optionsOrTitle === 'object') {
10
11
  options = optionsOrTitle;
@@ -14,9 +15,9 @@ const show = (optionsOrTitle, options = {}, internalType) => {
14
15
  }
15
16
  options.type = internalType;
16
17
  const { id = defaultConfig.toastAgent.id } = options;
17
- const imperatives = mapIdImperatives[id];
18
- if (imperatives && imperatives.length > 0) {
19
- imperatives[imperatives.length - 1].show(options);
18
+ const imperative = getAvailableImperative(imperativeName, id);
19
+ if (imperative) {
20
+ imperative.show(options);
20
21
  }
21
22
  };
22
23
  const toast = (optionsOrTitle, options) => {
@@ -32,15 +33,18 @@ const loading = (optionsOrTitle, options) => {
32
33
  show(optionsOrTitle, options, 'loading');
33
34
  };
34
35
  const hide = (id = defaultConfig.toastAgent.id) => {
35
- const imperatives = mapIdImperatives[id];
36
+ const imperatives = getImperatives(imperativeName, id);
36
37
  if (imperatives && imperatives.length > 0) {
37
- imperatives.forEach((imperative) => {
38
- imperative.hide();
38
+ imperatives.forEach((item) => {
39
+ item.imperative.hide();
39
40
  });
40
41
  }
41
42
  };
42
43
  const hideAll = () => {
43
- Object.keys(mapIdImperatives).forEach(hide);
44
+ const mapImperatives = getAllImperatives()[imperativeName];
45
+ if (mapImperatives) {
46
+ Object.keys(mapImperatives).forEach(hide);
47
+ }
44
48
  };
45
49
  toast.success = success;
46
50
  toast.fail = fail;
@@ -14,12 +14,13 @@
14
14
 
15
15
  <script>
16
16
  import { mergeDefaults as _mergeDefaults, defineComponent as _defineComponent } from "vue";
17
- import { onMounted, onUnmounted, ref } from "vue";
17
+ import { computed, ref } from "vue";
18
18
  import SarToast from "../toast/toast.vue";
19
19
  import {
20
- mapIdImperatives,
20
+ imperativeName,
21
21
  toastAgentPropsDefaults
22
22
  } from "./common";
23
+ import { useImperative } from "../../use/useImperative";
23
24
  export default _defineComponent({
24
25
  ...{
25
26
  options: {
@@ -63,23 +64,11 @@ export default _defineComponent({
63
64
  elRef.value?.cancelHide();
64
65
  }
65
66
  };
66
- onMounted(() => {
67
- const id = innerProps.value.id;
68
- if (id) {
69
- mapIdImperatives[id] ??= [];
70
- mapIdImperatives[id].push(imperative);
71
- }
72
- });
73
- onUnmounted(() => {
74
- const id = innerProps.value.id;
75
- if (id) {
76
- const imperatives = mapIdImperatives[id];
77
- const index = imperatives.indexOf(imperative);
78
- if (index !== -1) {
79
- imperatives.splice(imperatives.indexOf(imperative), 1);
80
- }
81
- }
82
- });
67
+ useImperative(
68
+ imperativeName,
69
+ imperative,
70
+ computed(() => innerProps.value.id)
71
+ );
83
72
  const __returned__ = { props, innerProps, elRef, imperative, SarToast };
84
73
  return __returned__;
85
74
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "id": "sard-uniapp",
3
3
  "name": "sard-uniapp",
4
4
  "displayName": "sard-uniapp",
5
- "version": "1.1.4",
5
+ "version": "1.1.5",
6
6
  "description": "sard-uniapp 是一套基于 Uniapp + Vue3 框架开发的兼容多端的 UI 组件库",
7
7
  "keywords": [
8
8
  "uniapp",
package/use/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './useTransition';
2
2
  export * from './useSetTimeout';
3
3
  export * from './useZIndex';
4
+ export * from './useImperative';
package/use/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './useTransition';
2
2
  export * from './useSetTimeout';
3
3
  export * from './useZIndex';
4
+ export * from './useImperative';
@@ -0,0 +1,11 @@
1
+ import { Ref } from 'vue';
2
+ type ImperativeItem<T = any> = {
3
+ show: boolean;
4
+ imperative: T;
5
+ };
6
+ type AllImperatives<T = any> = Record<string, Record<string, ImperativeItem<T>[] | undefined> | undefined>;
7
+ export declare function useImperative<T = any>(name: string, imperative: T, id: Ref<string>): void;
8
+ export declare function getAvailableImperative<T = any>(name: string, id: string): T | void;
9
+ export declare function getImperatives<T = any>(name: string, id: string): ImperativeItem<T>[] | undefined;
10
+ export declare function getAllImperatives<T = any>(): AllImperatives<T>;
11
+ export {};
@@ -0,0 +1,70 @@
1
+ import { onMounted, onUnmounted } from 'vue';
2
+ import { onHide, onShow } from '@dcloudio/uni-app';
3
+ const allImperatives = {};
4
+ export function useImperative(name, imperative, id) {
5
+ onMounted(() => {
6
+ if (id.value) {
7
+ const imperativeItems = ((allImperatives[name] ??= {})[id.value] ??= []);
8
+ const index = imperativeItems.findIndex((item) => item.imperative === imperative);
9
+ if (index === -1) {
10
+ imperativeItems.push({
11
+ imperative,
12
+ show: true,
13
+ });
14
+ }
15
+ }
16
+ });
17
+ onUnmounted(() => {
18
+ if (id.value) {
19
+ const imperativeItems = allImperatives[name]?.[id.value];
20
+ if (imperativeItems) {
21
+ const index = imperativeItems.findIndex((item) => item.imperative === imperative);
22
+ if (index !== -1) {
23
+ imperativeItems.splice(index, 1);
24
+ if (imperativeItems.length === 0) {
25
+ delete allImperatives[name]?.[id.value];
26
+ }
27
+ }
28
+ }
29
+ }
30
+ });
31
+ onShow(() => {
32
+ if (id.value) {
33
+ const imperativeItems = allImperatives[name]?.[id.value];
34
+ if (imperativeItems) {
35
+ const imperativeItem = imperativeItems.find((item) => item.imperative === imperative);
36
+ if (imperativeItem) {
37
+ imperativeItem.show = true;
38
+ }
39
+ }
40
+ }
41
+ });
42
+ onHide(() => {
43
+ if (id.value) {
44
+ const imperativeItems = allImperatives[name]?.[id.value];
45
+ if (imperativeItems) {
46
+ const imperativeItem = imperativeItems.find((item) => item.imperative === imperative);
47
+ if (imperativeItem) {
48
+ imperativeItem.show = false;
49
+ }
50
+ }
51
+ }
52
+ });
53
+ }
54
+ export function getAvailableImperative(name, id) {
55
+ const imperativeItems = allImperatives[name]?.[id];
56
+ if (imperativeItems) {
57
+ for (let i = imperativeItems.length - 1; i >= 0; i--) {
58
+ const imperativeItem = imperativeItems[i];
59
+ if (imperativeItem.show) {
60
+ return imperativeItem.imperative;
61
+ }
62
+ }
63
+ }
64
+ }
65
+ export function getImperatives(name, id) {
66
+ return allImperatives[name]?.[id];
67
+ }
68
+ export function getAllImperatives() {
69
+ return allImperatives;
70
+ }