@mieweb/ui 0.7.1-dev.16 → 0.7.1-dev.18
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/{chunk-QOBNYNKZ.js → chunk-3SRBIXQX.js} +3 -3
- package/dist/{chunk-QOBNYNKZ.js.map → chunk-3SRBIXQX.js.map} +1 -1
- package/dist/{chunk-RGRSJYZF.js → chunk-EGWWTIWS.js} +116 -72
- package/dist/chunk-EGWWTIWS.js.map +1 -0
- package/dist/{chunk-GLRLOJMV.cjs → chunk-OAHORW4N.cjs} +115 -71
- package/dist/chunk-OAHORW4N.cjs.map +1 -0
- package/dist/{chunk-3G2HFPCC.cjs → chunk-VWCMOWGH.cjs} +6 -6
- package/dist/{chunk-3G2HFPCC.cjs.map → chunk-VWCMOWGH.cjs.map} +1 -1
- package/dist/components/DateInput/index.cjs +2 -2
- package/dist/components/DateInput/index.d.cts +3 -1
- package/dist/components/DateInput/index.d.ts +3 -1
- package/dist/components/DateInput/index.js +1 -1
- package/dist/esheet.cjs +5 -5
- package/dist/esheet.js +2 -2
- package/dist/index.cjs +358 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -2
- package/dist/index.d.ts +16 -2
- package/dist/index.js +325 -8
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +6 -6
- package/dist/chunk-GLRLOJMV.cjs.map +0 -1
- package/dist/chunk-RGRSJYZF.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -2832,6 +2832,8 @@ interface BusinessHoursProps extends VariantProps<typeof containerVariants$1> {
|
|
|
2832
2832
|
useShortDayNames?: boolean;
|
|
2833
2833
|
/** Use 24-hour time format */
|
|
2834
2834
|
use24Hour?: boolean;
|
|
2835
|
+
/** Group days sharing identical hours into one row (e.g. "Mon, Wed, Fri · 8:00 AM - 11:00 AM") */
|
|
2836
|
+
groupDays?: boolean;
|
|
2835
2837
|
/** Show header with icon */
|
|
2836
2838
|
showHeader?: boolean;
|
|
2837
2839
|
/** Custom header text */
|
|
@@ -2839,7 +2841,7 @@ interface BusinessHoursProps extends VariantProps<typeof containerVariants$1> {
|
|
|
2839
2841
|
/** Additional CSS classes */
|
|
2840
2842
|
className?: string;
|
|
2841
2843
|
}
|
|
2842
|
-
declare function BusinessHours({ schedule, variant, size, showStatus, highlightToday, useShortDayNames, use24Hour, showHeader, headerText, className, }: BusinessHoursProps): react_jsx_runtime.JSX.Element;
|
|
2844
|
+
declare function BusinessHours({ schedule, variant, size, showStatus, highlightToday, useShortDayNames, use24Hour, groupDays, showHeader, headerText, className, }: BusinessHoursProps): react_jsx_runtime.JSX.Element;
|
|
2843
2845
|
interface CompactHoursProps {
|
|
2844
2846
|
/** Business hours schedule data */
|
|
2845
2847
|
schedule: BusinessHoursSchedule;
|
|
@@ -2873,11 +2875,19 @@ interface DaySchedule {
|
|
|
2873
2875
|
day: number;
|
|
2874
2876
|
hours: TimeSlot[];
|
|
2875
2877
|
}
|
|
2878
|
+
|
|
2876
2879
|
interface BusinessHoursEditorProps {
|
|
2877
2880
|
/** Current schedule data */
|
|
2878
2881
|
value: DaySchedule[];
|
|
2879
2882
|
/** Callback when schedule changes */
|
|
2880
2883
|
onChange: (schedule: DaySchedule[]) => void;
|
|
2884
|
+
/**
|
|
2885
|
+
* Editing layout:
|
|
2886
|
+
* - 'days' (default): one section per weekday, add hours per day
|
|
2887
|
+
* - 'rules': compact rows where one time range applies to multiple days
|
|
2888
|
+
* (e.g. Mon/Wed/Fri 8:00–11:00). Emits the same DaySchedule[] shape.
|
|
2889
|
+
*/
|
|
2890
|
+
variant?: 'days' | 'rules';
|
|
2881
2891
|
/** Whether the editor is disabled */
|
|
2882
2892
|
disabled?: boolean;
|
|
2883
2893
|
/** Whether to show description field for each time slot */
|
|
@@ -2894,8 +2904,12 @@ interface BusinessHoursEditorProps {
|
|
|
2894
2904
|
/**
|
|
2895
2905
|
* BusinessHoursEditor provides an editable interface for managing business hours.
|
|
2896
2906
|
* Supports multiple time slots per day with optional descriptions.
|
|
2907
|
+
*
|
|
2908
|
+
* The 'rules' variant edits the same schedule as grouped rows — each row is a
|
|
2909
|
+
* set of day toggles plus one time range — which is faster when several days
|
|
2910
|
+
* share the same hours.
|
|
2897
2911
|
*/
|
|
2898
|
-
declare function BusinessHoursEditor({
|
|
2912
|
+
declare function BusinessHoursEditor({ variant, ...props }: BusinessHoursEditorProps): react_jsx_runtime.JSX.Element;
|
|
2899
2913
|
declare function createDefaultSchedule(): DaySchedule[];
|
|
2900
2914
|
declare function create24HourSchedule(): DaySchedule[];
|
|
2901
2915
|
declare function createWeekdaySchedule(start?: string, end?: string): DaySchedule[];
|
package/dist/index.d.ts
CHANGED
|
@@ -2832,6 +2832,8 @@ interface BusinessHoursProps extends VariantProps<typeof containerVariants$1> {
|
|
|
2832
2832
|
useShortDayNames?: boolean;
|
|
2833
2833
|
/** Use 24-hour time format */
|
|
2834
2834
|
use24Hour?: boolean;
|
|
2835
|
+
/** Group days sharing identical hours into one row (e.g. "Mon, Wed, Fri · 8:00 AM - 11:00 AM") */
|
|
2836
|
+
groupDays?: boolean;
|
|
2835
2837
|
/** Show header with icon */
|
|
2836
2838
|
showHeader?: boolean;
|
|
2837
2839
|
/** Custom header text */
|
|
@@ -2839,7 +2841,7 @@ interface BusinessHoursProps extends VariantProps<typeof containerVariants$1> {
|
|
|
2839
2841
|
/** Additional CSS classes */
|
|
2840
2842
|
className?: string;
|
|
2841
2843
|
}
|
|
2842
|
-
declare function BusinessHours({ schedule, variant, size, showStatus, highlightToday, useShortDayNames, use24Hour, showHeader, headerText, className, }: BusinessHoursProps): react_jsx_runtime.JSX.Element;
|
|
2844
|
+
declare function BusinessHours({ schedule, variant, size, showStatus, highlightToday, useShortDayNames, use24Hour, groupDays, showHeader, headerText, className, }: BusinessHoursProps): react_jsx_runtime.JSX.Element;
|
|
2843
2845
|
interface CompactHoursProps {
|
|
2844
2846
|
/** Business hours schedule data */
|
|
2845
2847
|
schedule: BusinessHoursSchedule;
|
|
@@ -2873,11 +2875,19 @@ interface DaySchedule {
|
|
|
2873
2875
|
day: number;
|
|
2874
2876
|
hours: TimeSlot[];
|
|
2875
2877
|
}
|
|
2878
|
+
|
|
2876
2879
|
interface BusinessHoursEditorProps {
|
|
2877
2880
|
/** Current schedule data */
|
|
2878
2881
|
value: DaySchedule[];
|
|
2879
2882
|
/** Callback when schedule changes */
|
|
2880
2883
|
onChange: (schedule: DaySchedule[]) => void;
|
|
2884
|
+
/**
|
|
2885
|
+
* Editing layout:
|
|
2886
|
+
* - 'days' (default): one section per weekday, add hours per day
|
|
2887
|
+
* - 'rules': compact rows where one time range applies to multiple days
|
|
2888
|
+
* (e.g. Mon/Wed/Fri 8:00–11:00). Emits the same DaySchedule[] shape.
|
|
2889
|
+
*/
|
|
2890
|
+
variant?: 'days' | 'rules';
|
|
2881
2891
|
/** Whether the editor is disabled */
|
|
2882
2892
|
disabled?: boolean;
|
|
2883
2893
|
/** Whether to show description field for each time slot */
|
|
@@ -2894,8 +2904,12 @@ interface BusinessHoursEditorProps {
|
|
|
2894
2904
|
/**
|
|
2895
2905
|
* BusinessHoursEditor provides an editable interface for managing business hours.
|
|
2896
2906
|
* Supports multiple time slots per day with optional descriptions.
|
|
2907
|
+
*
|
|
2908
|
+
* The 'rules' variant edits the same schedule as grouped rows — each row is a
|
|
2909
|
+
* set of day toggles plus one time range — which is faster when several days
|
|
2910
|
+
* share the same hours.
|
|
2897
2911
|
*/
|
|
2898
|
-
declare function BusinessHoursEditor({
|
|
2912
|
+
declare function BusinessHoursEditor({ variant, ...props }: BusinessHoursEditorProps): react_jsx_runtime.JSX.Element;
|
|
2899
2913
|
declare function createDefaultSchedule(): DaySchedule[];
|
|
2900
2914
|
declare function create24HourSchedule(): DaySchedule[];
|
|
2901
2915
|
declare function createWeekdaySchedule(start?: string, end?: string): DaySchedule[];
|
package/dist/index.js
CHANGED
|
@@ -75,8 +75,8 @@ import './chunk-IQ4KQJAO.js';
|
|
|
75
75
|
export { Breadcrumb, BreadcrumbSlash } from './chunk-5Y5FSR4N.js';
|
|
76
76
|
import { evaluateDue, completedKeys, normalizeOrders } from './chunk-Y5KEFV5O.js';
|
|
77
77
|
export { buildChartOrderRows, buildEncounterOrderRows, dueForOrder, evaluateDue, evaluateProgram, isApplicable } from './chunk-Y5KEFV5O.js';
|
|
78
|
-
import { useCodeLookupConfig, RowActionToolbar, RowIconButton, toolbarKeyNav, parseSig, labelToMedicationFields, MedicationEditor } from './chunk-
|
|
79
|
-
export { ALLERGY_TYPE_LABELS, AllergyList, AllergyManager, CodeLookupProvider, MEDICATION_STATUS_LABELS, MedicationEditor, MedicationList, MedicationReconciliation, RowActionToolbar, RowIconButton, labelToMedicationFields, lookupToMedicationFields, parseMedicationLabel, parseSig, toolbarKeyNav, useCodeLookupConfig } from './chunk-
|
|
78
|
+
import { useCodeLookupConfig, RowActionToolbar, RowIconButton, toolbarKeyNav, parseSig, labelToMedicationFields, MedicationEditor } from './chunk-3SRBIXQX.js';
|
|
79
|
+
export { ALLERGY_TYPE_LABELS, AllergyList, AllergyManager, CodeLookupProvider, MEDICATION_STATUS_LABELS, MedicationEditor, MedicationList, MedicationReconciliation, RowActionToolbar, RowIconButton, labelToMedicationFields, lookupToMedicationFields, parseMedicationLabel, parseSig, toolbarKeyNav, useCodeLookupConfig } from './chunk-3SRBIXQX.js';
|
|
80
80
|
import { Textarea } from './chunk-AFGADE3B.js';
|
|
81
81
|
export { Textarea, textareaVariants } from './chunk-AFGADE3B.js';
|
|
82
82
|
import { Tooltip } from './chunk-FJ7YPVKV.js';
|
|
@@ -89,8 +89,8 @@ import { Select } from './chunk-DLBV42JD.js';
|
|
|
89
89
|
export { Select, selectTriggerVariants } from './chunk-DLBV42JD.js';
|
|
90
90
|
import { Card, CardHeader, CardContent, CardTitle } from './chunk-QYSUYB3S.js';
|
|
91
91
|
export { Card, CardActions, CardBadge, CardCollapsible, CardContent, CardDescription, CardDivider, CardFooter, CardHeader, CardMedia, CardStat, CardTitle, cardAccentVariants, cardVariants } from './chunk-QYSUYB3S.js';
|
|
92
|
-
import { DateInput } from './chunk-
|
|
93
|
-
export { DateInput } from './chunk-
|
|
92
|
+
import { DateInput } from './chunk-EGWWTIWS.js';
|
|
93
|
+
export { DateInput } from './chunk-EGWWTIWS.js';
|
|
94
94
|
import { Modal, ModalHeader, ModalTitle, ModalClose, ModalBody, ModalFooter } from './chunk-XMCIXHGH.js';
|
|
95
95
|
export { Modal, ModalBody, ModalClose, ModalFooter, ModalHeader, ModalTitle, modalContentVariants, modalOverlayVariants } from './chunk-XMCIXHGH.js';
|
|
96
96
|
import { Input, inputVariants } from './chunk-YXCE2HSK.js';
|
|
@@ -10013,6 +10013,50 @@ function LoadingSpinner({ className }) {
|
|
|
10013
10013
|
}
|
|
10014
10014
|
);
|
|
10015
10015
|
}
|
|
10016
|
+
|
|
10017
|
+
// src/components/BusinessHoursEditor/scheduleRules.ts
|
|
10018
|
+
function generateId2() {
|
|
10019
|
+
return Math.random().toString(36).substring(2, 9);
|
|
10020
|
+
}
|
|
10021
|
+
function ruleSignature(slot) {
|
|
10022
|
+
return `${slot.start}\0${slot.end}\0${slot.description ?? ""}`;
|
|
10023
|
+
}
|
|
10024
|
+
function scheduleToRules(schedule) {
|
|
10025
|
+
const rulesBySignature = /* @__PURE__ */ new Map();
|
|
10026
|
+
const orderedRules = [];
|
|
10027
|
+
for (const day of schedule) {
|
|
10028
|
+
for (const slot of day.hours) {
|
|
10029
|
+
const signature = ruleSignature(slot);
|
|
10030
|
+
const candidates = rulesBySignature.get(signature) ?? [];
|
|
10031
|
+
let rule = candidates.find((r) => !r.days.includes(day.day));
|
|
10032
|
+
if (!rule) {
|
|
10033
|
+
rule = {
|
|
10034
|
+
id: `rule-${orderedRules.length}`,
|
|
10035
|
+
days: [],
|
|
10036
|
+
start: slot.start,
|
|
10037
|
+
end: slot.end,
|
|
10038
|
+
description: slot.description
|
|
10039
|
+
};
|
|
10040
|
+
candidates.push(rule);
|
|
10041
|
+
rulesBySignature.set(signature, candidates);
|
|
10042
|
+
orderedRules.push(rule);
|
|
10043
|
+
}
|
|
10044
|
+
rule.days.push(day.day);
|
|
10045
|
+
}
|
|
10046
|
+
}
|
|
10047
|
+
return orderedRules;
|
|
10048
|
+
}
|
|
10049
|
+
function rulesToSchedule(rules) {
|
|
10050
|
+
return Array.from({ length: 7 }, (_, day) => ({
|
|
10051
|
+
day,
|
|
10052
|
+
hours: rules.filter((rule) => rule.days.includes(day)).map((rule, index) => ({
|
|
10053
|
+
id: `slot-${day}-${index}`,
|
|
10054
|
+
start: rule.start,
|
|
10055
|
+
end: rule.end,
|
|
10056
|
+
...rule.description ? { description: rule.description } : {}
|
|
10057
|
+
}))
|
|
10058
|
+
}));
|
|
10059
|
+
}
|
|
10016
10060
|
var DAY_NAMES = {
|
|
10017
10061
|
0: "Sunday",
|
|
10018
10062
|
1: "Monday",
|
|
@@ -10280,6 +10324,63 @@ function DayScheduleRow({
|
|
|
10280
10324
|
}
|
|
10281
10325
|
);
|
|
10282
10326
|
}
|
|
10327
|
+
function GroupedScheduleRows({
|
|
10328
|
+
officeHours,
|
|
10329
|
+
useShortDayNames = false,
|
|
10330
|
+
use24Hour = false
|
|
10331
|
+
}) {
|
|
10332
|
+
const normalized = officeHours.map((dayHours) => ({
|
|
10333
|
+
day: parseDayToNumber(dayHours.day),
|
|
10334
|
+
hours: (dayHours.hours ?? []).map((range) => ({
|
|
10335
|
+
start: range.start ?? "",
|
|
10336
|
+
end: range.end ?? "",
|
|
10337
|
+
...range.description ? { description: range.description } : {}
|
|
10338
|
+
}))
|
|
10339
|
+
}));
|
|
10340
|
+
const rules = scheduleToRules(normalized);
|
|
10341
|
+
const closedDays = normalized.filter((dayHours) => dayHours.hours.length === 0).map((dayHours) => dayHours.day);
|
|
10342
|
+
const dayNames = useShortDayNames ? DAY_NAMES_SHORT : DAY_NAMES;
|
|
10343
|
+
const formatDays = (days) => days.map((day) => dayNames[day]).join(", ");
|
|
10344
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
10345
|
+
rules.map((rule) => /* @__PURE__ */ jsxs(
|
|
10346
|
+
"div",
|
|
10347
|
+
{
|
|
10348
|
+
"data-slot": "business-hours-grouped-row",
|
|
10349
|
+
className: cn(dayRowVariants({ isToday: false })),
|
|
10350
|
+
children: [
|
|
10351
|
+
/* @__PURE__ */ jsx(
|
|
10352
|
+
"span",
|
|
10353
|
+
{
|
|
10354
|
+
"data-slot": "business-hours-day-name",
|
|
10355
|
+
className: "min-w-[80px] font-medium",
|
|
10356
|
+
children: formatDays(rule.days)
|
|
10357
|
+
}
|
|
10358
|
+
),
|
|
10359
|
+
/* @__PURE__ */ jsx("div", { "data-slot": "business-hours-day-hours", className: "text-end", children: /* @__PURE__ */ jsx(TimeRangeDisplay, { range: rule, use24Hour }) })
|
|
10360
|
+
]
|
|
10361
|
+
},
|
|
10362
|
+
rule.id
|
|
10363
|
+
)),
|
|
10364
|
+
closedDays.length > 0 && /* @__PURE__ */ jsxs(
|
|
10365
|
+
"div",
|
|
10366
|
+
{
|
|
10367
|
+
"data-slot": "business-hours-grouped-row",
|
|
10368
|
+
className: cn(dayRowVariants({ isToday: false })),
|
|
10369
|
+
children: [
|
|
10370
|
+
/* @__PURE__ */ jsx(
|
|
10371
|
+
"span",
|
|
10372
|
+
{
|
|
10373
|
+
"data-slot": "business-hours-day-name",
|
|
10374
|
+
className: "min-w-[80px] font-medium",
|
|
10375
|
+
children: formatDays(closedDays)
|
|
10376
|
+
}
|
|
10377
|
+
),
|
|
10378
|
+
/* @__PURE__ */ jsx("div", { "data-slot": "business-hours-day-hours", className: "text-end", children: /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "Closed" }) })
|
|
10379
|
+
]
|
|
10380
|
+
}
|
|
10381
|
+
)
|
|
10382
|
+
] });
|
|
10383
|
+
}
|
|
10283
10384
|
function BusinessHours({
|
|
10284
10385
|
schedule,
|
|
10285
10386
|
variant = "default",
|
|
@@ -10288,6 +10389,7 @@ function BusinessHours({
|
|
|
10288
10389
|
highlightToday = true,
|
|
10289
10390
|
useShortDayNames = false,
|
|
10290
10391
|
use24Hour = false,
|
|
10392
|
+
groupDays = false,
|
|
10291
10393
|
showHeader = true,
|
|
10292
10394
|
headerText = "Hours",
|
|
10293
10395
|
className
|
|
@@ -10423,7 +10525,14 @@ function BusinessHours({
|
|
|
10423
10525
|
{
|
|
10424
10526
|
"data-slot": "business-hours-schedule",
|
|
10425
10527
|
className: "space-y-1 divide-y divide-neutral-100 dark:divide-neutral-800",
|
|
10426
|
-
children:
|
|
10528
|
+
children: groupDays ? /* @__PURE__ */ jsx(
|
|
10529
|
+
GroupedScheduleRows,
|
|
10530
|
+
{
|
|
10531
|
+
officeHours: schedule.officeHours,
|
|
10532
|
+
useShortDayNames,
|
|
10533
|
+
use24Hour
|
|
10534
|
+
}
|
|
10535
|
+
) : schedule.officeHours.map((dayHours, idx) => /* @__PURE__ */ jsx(
|
|
10427
10536
|
DayScheduleRow,
|
|
10428
10537
|
{
|
|
10429
10538
|
dayHours,
|
|
@@ -10560,9 +10669,6 @@ var DAY_NAMES2 = [
|
|
|
10560
10669
|
"Saturday"
|
|
10561
10670
|
];
|
|
10562
10671
|
var DAY_NAMES_SHORT2 = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
10563
|
-
function generateId2() {
|
|
10564
|
-
return Math.random().toString(36).substring(2, 9);
|
|
10565
|
-
}
|
|
10566
10672
|
function getOrderedDays(weekStartsOn) {
|
|
10567
10673
|
if (weekStartsOn === 1) {
|
|
10568
10674
|
return [1, 2, 3, 4, 5, 6, 0];
|
|
@@ -10578,6 +10684,15 @@ function ensureAllDays(schedule) {
|
|
|
10578
10684
|
return result;
|
|
10579
10685
|
}
|
|
10580
10686
|
function BusinessHoursEditor({
|
|
10687
|
+
variant = "days",
|
|
10688
|
+
...props
|
|
10689
|
+
}) {
|
|
10690
|
+
if (variant === "rules") {
|
|
10691
|
+
return /* @__PURE__ */ jsx(BusinessHoursRulesEditor, { ...props });
|
|
10692
|
+
}
|
|
10693
|
+
return /* @__PURE__ */ jsx(BusinessHoursDaysEditor, { ...props });
|
|
10694
|
+
}
|
|
10695
|
+
function BusinessHoursDaysEditor({
|
|
10581
10696
|
value,
|
|
10582
10697
|
onChange,
|
|
10583
10698
|
disabled = false,
|
|
@@ -10847,6 +10962,208 @@ function BusinessHoursEditor({
|
|
|
10847
10962
|
}
|
|
10848
10963
|
);
|
|
10849
10964
|
}
|
|
10965
|
+
function normalizeSchedule(schedule) {
|
|
10966
|
+
return JSON.stringify(
|
|
10967
|
+
ensureAllDays(schedule).map((day) => ({
|
|
10968
|
+
day: day.day,
|
|
10969
|
+
hours: day.hours.map((slot) => ({
|
|
10970
|
+
start: slot.start,
|
|
10971
|
+
end: slot.end,
|
|
10972
|
+
description: slot.description ?? ""
|
|
10973
|
+
}))
|
|
10974
|
+
}))
|
|
10975
|
+
);
|
|
10976
|
+
}
|
|
10977
|
+
function BusinessHoursRulesEditor({
|
|
10978
|
+
value,
|
|
10979
|
+
onChange,
|
|
10980
|
+
disabled = false,
|
|
10981
|
+
showDescription = true,
|
|
10982
|
+
use24Hour = false,
|
|
10983
|
+
weekStartsOn = 0,
|
|
10984
|
+
className,
|
|
10985
|
+
addHoursLabel = "Add Hours"
|
|
10986
|
+
}) {
|
|
10987
|
+
const [rules, setRules] = React10.useState(
|
|
10988
|
+
() => scheduleToRules(value)
|
|
10989
|
+
);
|
|
10990
|
+
const timeFormat = use24Hour ? "24-hour" : "12-hour";
|
|
10991
|
+
const lastScheduleRef = React10.useRef(normalizeSchedule(value));
|
|
10992
|
+
React10.useEffect(() => {
|
|
10993
|
+
const incoming = normalizeSchedule(value);
|
|
10994
|
+
if (incoming !== lastScheduleRef.current) {
|
|
10995
|
+
lastScheduleRef.current = incoming;
|
|
10996
|
+
setRules(scheduleToRules(value));
|
|
10997
|
+
}
|
|
10998
|
+
}, [value]);
|
|
10999
|
+
const emit = useCallback(
|
|
11000
|
+
(nextRules) => {
|
|
11001
|
+
setRules(nextRules);
|
|
11002
|
+
const schedule = rulesToSchedule(nextRules);
|
|
11003
|
+
const normalized = normalizeSchedule(schedule);
|
|
11004
|
+
if (normalized !== lastScheduleRef.current) {
|
|
11005
|
+
lastScheduleRef.current = normalized;
|
|
11006
|
+
onChange(schedule);
|
|
11007
|
+
}
|
|
11008
|
+
},
|
|
11009
|
+
[onChange]
|
|
11010
|
+
);
|
|
11011
|
+
const handleAddRule = useCallback(() => {
|
|
11012
|
+
emit([
|
|
11013
|
+
...rules,
|
|
11014
|
+
{ id: generateId2(), days: [], start: "09:00", end: "17:00" }
|
|
11015
|
+
]);
|
|
11016
|
+
}, [emit, rules]);
|
|
11017
|
+
const handleRemoveRule = useCallback(
|
|
11018
|
+
(ruleId) => {
|
|
11019
|
+
emit(rules.filter((rule) => rule.id !== ruleId));
|
|
11020
|
+
},
|
|
11021
|
+
[emit, rules]
|
|
11022
|
+
);
|
|
11023
|
+
const handleToggleDay = useCallback(
|
|
11024
|
+
(ruleId, day) => {
|
|
11025
|
+
emit(
|
|
11026
|
+
rules.map(
|
|
11027
|
+
(rule) => rule.id === ruleId ? {
|
|
11028
|
+
...rule,
|
|
11029
|
+
days: rule.days.includes(day) ? rule.days.filter((d) => d !== day) : [...rule.days, day]
|
|
11030
|
+
} : rule
|
|
11031
|
+
)
|
|
11032
|
+
);
|
|
11033
|
+
},
|
|
11034
|
+
[emit, rules]
|
|
11035
|
+
);
|
|
11036
|
+
const handleRuleChange = useCallback(
|
|
11037
|
+
(ruleId, field, value2) => {
|
|
11038
|
+
emit(
|
|
11039
|
+
rules.map(
|
|
11040
|
+
(rule) => rule.id === ruleId ? { ...rule, [field]: value2 } : rule
|
|
11041
|
+
)
|
|
11042
|
+
);
|
|
11043
|
+
},
|
|
11044
|
+
[emit, rules]
|
|
11045
|
+
);
|
|
11046
|
+
const orderedDays = getOrderedDays(weekStartsOn);
|
|
11047
|
+
return /* @__PURE__ */ jsxs(
|
|
11048
|
+
"div",
|
|
11049
|
+
{
|
|
11050
|
+
"data-slot": "business-hours-editor",
|
|
11051
|
+
className: cn("business-hours-editor space-y-3", className),
|
|
11052
|
+
children: [
|
|
11053
|
+
rules.map((rule) => /* @__PURE__ */ jsxs(
|
|
11054
|
+
"fieldset",
|
|
11055
|
+
{
|
|
11056
|
+
"data-slot": "business-hours-rule",
|
|
11057
|
+
className: "flex flex-wrap items-center gap-2 border-b border-gray-200 pb-3 last:border-0 dark:border-gray-700",
|
|
11058
|
+
children: [
|
|
11059
|
+
/* @__PURE__ */ jsx("legend", { className: "sr-only", children: "Availability rule" }),
|
|
11060
|
+
/* @__PURE__ */ jsx(
|
|
11061
|
+
"div",
|
|
11062
|
+
{
|
|
11063
|
+
"data-slot": "business-hours-rule-days",
|
|
11064
|
+
className: "flex shrink-0 gap-1",
|
|
11065
|
+
children: orderedDays.map((day) => {
|
|
11066
|
+
const selected = rule.days.includes(day);
|
|
11067
|
+
return /* @__PURE__ */ jsx(
|
|
11068
|
+
"button",
|
|
11069
|
+
{
|
|
11070
|
+
type: "button",
|
|
11071
|
+
"aria-pressed": selected,
|
|
11072
|
+
"aria-label": DAY_NAMES2[day],
|
|
11073
|
+
disabled,
|
|
11074
|
+
onClick: () => handleToggleDay(rule.id, day),
|
|
11075
|
+
className: cn(
|
|
11076
|
+
"inline-flex h-7 w-9 items-center justify-center rounded-full border text-xs font-medium transition-colors",
|
|
11077
|
+
"focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none",
|
|
11078
|
+
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
11079
|
+
selected ? "border-primary-800 bg-primary-800 text-white" : "border-border text-muted-foreground hover:bg-muted hover:text-foreground"
|
|
11080
|
+
),
|
|
11081
|
+
children: DAY_NAMES_SHORT2[day]
|
|
11082
|
+
},
|
|
11083
|
+
day
|
|
11084
|
+
);
|
|
11085
|
+
})
|
|
11086
|
+
}
|
|
11087
|
+
),
|
|
11088
|
+
/* @__PURE__ */ jsx("div", { className: "w-32 sm:w-36", children: /* @__PURE__ */ jsx(
|
|
11089
|
+
DateInput,
|
|
11090
|
+
{
|
|
11091
|
+
inputType: "time",
|
|
11092
|
+
timeFormat,
|
|
11093
|
+
minuteStep: 15,
|
|
11094
|
+
value: rule.start,
|
|
11095
|
+
onChange: (time) => handleRuleChange(rule.id, "start", time),
|
|
11096
|
+
disabled,
|
|
11097
|
+
size: "sm",
|
|
11098
|
+
className: "text-sm",
|
|
11099
|
+
label: "Start time",
|
|
11100
|
+
hideLabel: true
|
|
11101
|
+
}
|
|
11102
|
+
) }),
|
|
11103
|
+
/* @__PURE__ */ jsx("span", { "data-slot": "business-hours-separator", className: "text-gray-400", children: "\u2013" }),
|
|
11104
|
+
/* @__PURE__ */ jsx("div", { className: "w-32 sm:w-36", children: /* @__PURE__ */ jsx(
|
|
11105
|
+
DateInput,
|
|
11106
|
+
{
|
|
11107
|
+
inputType: "time",
|
|
11108
|
+
timeFormat,
|
|
11109
|
+
minuteStep: 15,
|
|
11110
|
+
value: rule.end,
|
|
11111
|
+
onChange: (time) => handleRuleChange(rule.id, "end", time),
|
|
11112
|
+
disabled,
|
|
11113
|
+
size: "sm",
|
|
11114
|
+
className: "text-sm",
|
|
11115
|
+
label: "End time",
|
|
11116
|
+
hideLabel: true
|
|
11117
|
+
}
|
|
11118
|
+
) }),
|
|
11119
|
+
showDescription && /* @__PURE__ */ jsx("div", { className: "min-w-[120px] flex-1", children: /* @__PURE__ */ jsx(
|
|
11120
|
+
Input,
|
|
11121
|
+
{
|
|
11122
|
+
type: "text",
|
|
11123
|
+
value: rule.description || "",
|
|
11124
|
+
onChange: (e) => handleRuleChange(rule.id, "description", e.target.value),
|
|
11125
|
+
placeholder: "Description (optional)",
|
|
11126
|
+
disabled,
|
|
11127
|
+
className: "text-sm",
|
|
11128
|
+
"aria-label": "Description"
|
|
11129
|
+
}
|
|
11130
|
+
) }),
|
|
11131
|
+
/* @__PURE__ */ jsx(
|
|
11132
|
+
Button,
|
|
11133
|
+
{
|
|
11134
|
+
type: "button",
|
|
11135
|
+
variant: "ghost",
|
|
11136
|
+
size: "sm",
|
|
11137
|
+
onClick: () => handleRemoveRule(rule.id),
|
|
11138
|
+
disabled,
|
|
11139
|
+
className: "text-red-500 hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-900/20",
|
|
11140
|
+
"aria-label": "Remove availability rule",
|
|
11141
|
+
children: /* @__PURE__ */ jsx(XIcon, { className: "h-4 w-4" })
|
|
11142
|
+
}
|
|
11143
|
+
)
|
|
11144
|
+
]
|
|
11145
|
+
},
|
|
11146
|
+
rule.id
|
|
11147
|
+
)),
|
|
11148
|
+
/* @__PURE__ */ jsxs(
|
|
11149
|
+
Button,
|
|
11150
|
+
{
|
|
11151
|
+
type: "button",
|
|
11152
|
+
variant: "ghost",
|
|
11153
|
+
size: "sm",
|
|
11154
|
+
onClick: handleAddRule,
|
|
11155
|
+
disabled,
|
|
11156
|
+
className: "text-xs",
|
|
11157
|
+
children: [
|
|
11158
|
+
/* @__PURE__ */ jsx(PlusIcon2, { className: "me-1 h-3 w-3" }),
|
|
11159
|
+
addHoursLabel
|
|
11160
|
+
]
|
|
11161
|
+
}
|
|
11162
|
+
)
|
|
11163
|
+
]
|
|
11164
|
+
}
|
|
11165
|
+
);
|
|
11166
|
+
}
|
|
10850
11167
|
function createDefaultSchedule() {
|
|
10851
11168
|
return [
|
|
10852
11169
|
{ day: 0, hours: [] },
|