@yh-ui/hooks 0.1.25 → 0.1.28

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/dist/dayjs.cjs ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var dayjsModule = _interopRequireWildcard(require("dayjs"));
8
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
9
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
10
+ const dayjs = "default" in dayjsModule ? dayjsModule.default ?? dayjsModule : dayjsModule;
11
+ module.exports = dayjs;
@@ -0,0 +1,3 @@
1
+ import type dayjsType from 'dayjs';
2
+ declare const dayjs: typeof dayjsType;
3
+ export default dayjs;
package/dist/dayjs.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import * as dayjsModule from "dayjs";
2
+ const dayjs = "default" in dayjsModule ? dayjsModule.default ?? dayjsModule : dayjsModule;
3
+ export default dayjs;
@@ -16,7 +16,7 @@ export declare const configProviderContextKey: InjectionKey<ComputedRef<ConfigPr
16
16
  */
17
17
  export declare const useConfig: () => {
18
18
  config: ComputedRef<ConfigProviderContext> | null;
19
- globalSize: ComputedRef<"small" | "default" | "large">;
19
+ globalSize: ComputedRef<"default" | "small" | "large">;
20
20
  globalZIndex: ComputedRef<number>;
21
21
  globalLocale: ComputedRef<Language | undefined>;
22
22
  };
@@ -4,11 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.updateDayjsMonths = exports.setDayjsLocaleSync = exports.setDayjsLocale = exports.getDayjsLocale = void 0;
7
- var _dayjs = _interopRequireWildcard(require("dayjs"));
7
+ var _dayjs = _interopRequireDefault(require("../dayjs.cjs"));
8
8
  require("dayjs/locale/en");
9
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
- const dayjs = _dayjs.default || _dayjs;
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
10
  const dayjsLocales = import.meta.glob(["../../../../node_modules/dayjs/locale/*.js", "!../../../../node_modules/dayjs/locale/en.js"], {
13
11
  eager: false
14
12
  });
@@ -82,42 +80,54 @@ const localeMapping = {
82
80
  my: "my",
83
81
  te: "te"
84
82
  };
83
+ const loadDayjsLocale = async dayjsLocale => {
84
+ const path = `../../../../node_modules/dayjs/locale/${dayjsLocale}.js`;
85
+ const loader = dayjsLocales[path];
86
+ if (loader) {
87
+ await loader();
88
+ return true;
89
+ }
90
+ try {
91
+ await Promise.resolve(`dayjs/locale/${dayjsLocale}.js`).then(s => require(s));
92
+ return true;
93
+ } catch {
94
+ return false;
95
+ }
96
+ };
85
97
  const getDayjsLocale = localeCode => {
86
- return localeMapping[localeCode] || "en";
98
+ return localeMapping[localeCode.toLowerCase()] || "en";
87
99
  };
88
100
  exports.getDayjsLocale = getDayjsLocale;
89
101
  const setDayjsLocale = async localeCode => {
90
102
  const dayjsLocale = getDayjsLocale(localeCode);
91
103
  if (loadedLocales.has(dayjsLocale)) {
92
- dayjs.locale(dayjsLocale);
104
+ _dayjs.default.locale(dayjsLocale);
93
105
  return;
94
106
  }
95
107
  if (dayjsLocale === "en") {
96
- dayjs.locale("en");
108
+ _dayjs.default.locale("en");
97
109
  return;
98
110
  }
99
- const path = `../../../../node_modules/dayjs/locale/${dayjsLocale}.js`;
100
- const loader = dayjsLocales[path];
101
- if (loader) {
102
- try {
103
- await loader();
104
- loadedLocales.add(dayjsLocale);
105
- dayjs.locale(dayjsLocale);
106
- } catch {
107
- dayjs.locale("en");
111
+ try {
112
+ const loaded = await loadDayjsLocale(dayjsLocale);
113
+ if (!loaded) {
114
+ _dayjs.default.locale("en");
115
+ return;
108
116
  }
109
- } else {
110
- dayjs.locale("en");
117
+ loadedLocales.add(dayjsLocale);
118
+ _dayjs.default.locale(dayjsLocale);
119
+ } catch {
120
+ _dayjs.default.locale("en");
111
121
  }
112
122
  };
113
123
  exports.setDayjsLocale = setDayjsLocale;
114
124
  const setDayjsLocaleSync = localeCode => {
115
125
  const dayjsLocale = getDayjsLocale(localeCode);
116
126
  if (loadedLocales.has(dayjsLocale)) {
117
- dayjs.locale(dayjsLocale);
127
+ _dayjs.default.locale(dayjsLocale);
118
128
  } else {
119
- dayjs.locale("en");
120
- setDayjsLocale(localeCode);
129
+ _dayjs.default.locale("en");
130
+ void setDayjsLocale(localeCode);
121
131
  }
122
132
  };
123
133
  exports.setDayjsLocaleSync = setDayjsLocaleSync;
@@ -125,8 +135,9 @@ const updateDayjsMonths = (localeCode, months) => {
125
135
  const dayjsLocale = getDayjsLocale(localeCode);
126
136
  const monthsArray = [months.jan, months.feb, months.mar, months.apr, months.may, months.jun, months.jul, months.aug, months.sep, months.oct, months.nov, months.dec];
127
137
  try {
128
- if (dayjs.updateLocale) {
129
- dayjs.updateLocale(dayjsLocale, {
138
+ const updateLocale = _dayjs.default.updateLocale;
139
+ if (updateLocale) {
140
+ updateLocale(dayjsLocale, {
130
141
  months: monthsArray,
131
142
  monthsShort: monthsArray
132
143
  });
@@ -1,5 +1,4 @@
1
- import * as _dayjs from "dayjs";
2
- const dayjs = _dayjs.default || _dayjs;
1
+ import dayjs from "../dayjs.mjs";
3
2
  import "dayjs/locale/en";
4
3
  const dayjsLocales = import.meta.glob(
5
4
  ["../../../../node_modules/dayjs/locale/*.js", "!../../../../node_modules/dayjs/locale/en.js"],
@@ -75,8 +74,25 @@ const localeMapping = {
75
74
  my: "my",
76
75
  te: "te"
77
76
  };
77
+ const loadDayjsLocale = async (dayjsLocale) => {
78
+ const path = `../../../../node_modules/dayjs/locale/${dayjsLocale}.js`;
79
+ const loader = dayjsLocales[path];
80
+ if (loader) {
81
+ await loader();
82
+ return true;
83
+ }
84
+ try {
85
+ await import(
86
+ /* @vite-ignore */
87
+ `dayjs/locale/${dayjsLocale}.js`
88
+ );
89
+ return true;
90
+ } catch {
91
+ return false;
92
+ }
93
+ };
78
94
  export const getDayjsLocale = (localeCode) => {
79
- return localeMapping[localeCode] || "en";
95
+ return localeMapping[localeCode.toLowerCase()] || "en";
80
96
  };
81
97
  export const setDayjsLocale = async (localeCode) => {
82
98
  const dayjsLocale = getDayjsLocale(localeCode);
@@ -88,17 +104,15 @@ export const setDayjsLocale = async (localeCode) => {
88
104
  dayjs.locale("en");
89
105
  return;
90
106
  }
91
- const path = `../../../../node_modules/dayjs/locale/${dayjsLocale}.js`;
92
- const loader = dayjsLocales[path];
93
- if (loader) {
94
- try {
95
- await loader();
96
- loadedLocales.add(dayjsLocale);
97
- dayjs.locale(dayjsLocale);
98
- } catch {
107
+ try {
108
+ const loaded = await loadDayjsLocale(dayjsLocale);
109
+ if (!loaded) {
99
110
  dayjs.locale("en");
111
+ return;
100
112
  }
101
- } else {
113
+ loadedLocales.add(dayjsLocale);
114
+ dayjs.locale(dayjsLocale);
115
+ } catch {
102
116
  dayjs.locale("en");
103
117
  }
104
118
  };
@@ -108,7 +122,7 @@ export const setDayjsLocaleSync = (localeCode) => {
108
122
  dayjs.locale(dayjsLocale);
109
123
  } else {
110
124
  dayjs.locale("en");
111
- setDayjsLocale(localeCode);
125
+ void setDayjsLocale(localeCode);
112
126
  }
113
127
  };
114
128
  export const updateDayjsMonths = (localeCode, months) => {
@@ -128,8 +142,9 @@ export const updateDayjsMonths = (localeCode, months) => {
128
142
  months.dec
129
143
  ];
130
144
  try {
131
- if (dayjs.updateLocale) {
132
- dayjs.updateLocale(dayjsLocale, {
145
+ const updateLocale = dayjs.updateLocale;
146
+ if (updateLocale) {
147
+ updateLocale(dayjsLocale, {
133
148
  months: monthsArray,
134
149
  monthsShort: monthsArray
135
150
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yh-ui/hooks",
3
- "version": "0.1.25",
3
+ "version": "0.1.28",
4
4
  "description": "YH-UI composition hooks",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -23,9 +23,9 @@
23
23
  "dist"
24
24
  ],
25
25
  "dependencies": {
26
- "dayjs": "^1.11.19",
27
- "@yh-ui/locale": "0.1.25",
28
- "@yh-ui/utils": "0.1.25"
26
+ "@yh-ui/locale": "^0.1.28",
27
+ "@yh-ui/utils": "^0.1.28",
28
+ "dayjs": "^1.11.19"
29
29
  },
30
30
  "devDependencies": {
31
31
  "vue": "^3.5.27",