@mhome/ui 0.1.7 → 0.1.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mhome/ui",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "description": "mHome UI Component Library",
6
6
  "main": "dist/index.cjs.js",
@@ -2,24 +2,26 @@ import * as React from "react";
2
2
  import { cn } from "../lib/utils";
3
3
  import { TextField } from "./text-field";
4
4
  import * as dayjsModule from "dayjs";
5
- // Handle dayjs import - it may be a function or an object with default
5
+
6
6
  // Ensure dayjs is a function at runtime
7
- const getDayjs = () => {
8
- if (typeof dayjsModule === "function") {
9
- return dayjsModule;
10
- }
11
- if (dayjsModule.default && typeof dayjsModule.default === "function") {
12
- return dayjsModule.default;
13
- }
7
+ // Handle both ESM and CJS dayjs exports
8
+ let dayjs;
9
+ if (typeof dayjsModule === "function") {
10
+ dayjs = dayjsModule;
11
+ } else if (dayjsModule.default && typeof dayjsModule.default === "function") {
12
+ dayjs = dayjsModule.default;
13
+ } else {
14
14
  // Fallback: try to get the function from the module
15
- const dayjsFn = dayjsModule.default || dayjsModule;
16
- if (typeof dayjsFn === "function") {
17
- return dayjsFn;
15
+ dayjs = dayjsModule.default || dayjsModule;
16
+ // If still not a function, this is an error
17
+ if (typeof dayjs !== "function") {
18
+ console.error("dayjs is not a function. Module:", dayjsModule);
19
+ // Create a fallback that throws an error
20
+ dayjs = function() {
21
+ throw new Error("dayjs is not properly initialized");
22
+ };
18
23
  }
19
- // Last resort: if it's an object, try to access the function
20
- return dayjsFn;
21
- };
22
- const dayjs = getDayjs();
24
+ }
23
25
 
24
26
  const DatePicker = React.forwardRef(
25
27
  (
@@ -122,20 +124,17 @@ const DatePicker = React.forwardRef(
122
124
 
123
125
  // Generate calendar days
124
126
  const getCalendarDays = () => {
125
- const startOfMonth = selectedDate
126
- ? selectedDate.startOf("month")
127
- : dayjs().startOf("month");
128
- const endOfMonth = selectedDate
129
- ? selectedDate.endOf("month")
130
- : dayjs().endOf("month");
131
- const startDate = startOfMonth.startOf("week");
132
- const endDate = endOfMonth.endOf("week");
127
+ const baseDate = selectedDate || dayjs();
128
+ const startOfMonth = dayjs(baseDate).startOf("month");
129
+ const endOfMonth = dayjs(baseDate).endOf("month");
130
+ const startDate = dayjs(startOfMonth).startOf("week");
131
+ const endDate = dayjs(endOfMonth).endOf("week");
133
132
  const days = [];
134
133
  let currentDate = startDate;
135
134
 
136
135
  while (currentDate.isBefore(endDate) || currentDate.isSame(endDate)) {
137
- days.push(currentDate);
138
- currentDate = currentDate.add(1, "day");
136
+ days.push(dayjs(currentDate));
137
+ currentDate = dayjs(currentDate).add(1, "day");
139
138
  }
140
139
 
141
140
  return days;
@@ -147,14 +146,14 @@ const DatePicker = React.forwardRef(
147
146
 
148
147
  const handlePrevMonth = () => {
149
148
  const newDate = selectedDate
150
- ? selectedDate.subtract(1, "month")
149
+ ? dayjs(selectedDate).subtract(1, "month")
151
150
  : dayjs().subtract(1, "month");
152
151
  setSelectedDate(newDate);
153
152
  };
154
153
 
155
154
  const handleNextMonth = () => {
156
155
  const newDate = selectedDate
157
- ? selectedDate.add(1, "month")
156
+ ? dayjs(selectedDate).add(1, "month")
158
157
  : dayjs().add(1, "month");
159
158
  setSelectedDate(newDate);
160
159
  };
@@ -265,7 +264,7 @@ const DatePicker = React.forwardRef(
265
264
  if (viewMode === "year") {
266
265
  setSelectedDate(
267
266
  selectedDate
268
- ? selectedDate.subtract(10, "year")
267
+ ? dayjs(selectedDate).subtract(10, "year")
269
268
  : dayjs().subtract(10, "year")
270
269
  );
271
270
  } else {
@@ -351,7 +350,7 @@ const DatePicker = React.forwardRef(
351
350
  type="button"
352
351
  onClick={() => {
353
352
  const newDate = selectedDate
354
- ? selectedDate.year(year)
353
+ ? dayjs(selectedDate).year(year)
355
354
  : dayjs().year(year).month(currentMonth);
356
355
  setSelectedDate(newDate);
357
356
  setShowYearPicker(false);
@@ -389,7 +388,7 @@ const DatePicker = React.forwardRef(
389
388
  if (viewMode === "year") {
390
389
  setSelectedDate(
391
390
  selectedDate
392
- ? selectedDate.add(10, "year")
391
+ ? dayjs(selectedDate).add(10, "year")
393
392
  : dayjs().add(10, "year")
394
393
  );
395
394
  } else {
@@ -498,7 +497,7 @@ const DatePicker = React.forwardRef(
498
497
  type="button"
499
498
  onClick={() => {
500
499
  const newDate = selectedDate
501
- ? selectedDate.month(monthIndex)
500
+ ? dayjs(selectedDate).month(monthIndex)
502
501
  : dayjs().month(monthIndex).year(currentYear);
503
502
  setSelectedDate(newDate);
504
503
  setViewMode("month");