File size: 3,336 Bytes
bc20498
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<script>import { melt } from "@melt-ui/svelte";
import { setCtx } from "../ctx.js";
import { createDispatcher } from "../../../internal/events.js";
import { onMount } from "svelte";
import { handleCalendarInitialFocus } from "../../../internal/focus.js";
export let placeholder = void 0;
export let onPlaceholderChange = void 0;
export let value = void 0;
export let onValueChange = void 0;
export let preventDeselect = void 0;
export let minValue = void 0;
export let maxValue = void 0;
export let pagedNavigation = void 0;
export let weekStartsOn = void 0;
export let locale = void 0;
export let isDateUnavailable = void 0;
export let isDateDisabled = void 0;
export let disabled = void 0;
export let readonly = void 0;
export let fixedWeeks = void 0;
export let calendarLabel = void 0;
export let asChild = false;
export let id = void 0;
export let weekdayFormat = void 0;
export let initialFocus = false;
export let startValue = void 0;
export let numberOfMonths = void 0;
export let el = void 0;
onMount(() => {
  if (!initialFocus || !el)
    return;
  handleCalendarInitialFocus(el);
});
const {
  elements: { calendar },
  states: {
    value: localValue,
    placeholder: localPlaceholder,
    months: localMonths,
    weekdays,
    startValue: localStartValue,
    endValue
  },
  updateOption,
  ids,
  getAttrs
} = setCtx({
  defaultPlaceholder: placeholder,
  defaultValue: value,
  preventDeselect,
  minValue,
  maxValue,
  pagedNavigation,
  weekStartsOn,
  locale,
  isDateUnavailable,
  isDateDisabled,
  disabled,
  readonly,
  fixedWeeks,
  calendarLabel,
  weekdayFormat,
  numberOfMonths,
  onPlaceholderChange: ({ next }) => {
    if (placeholder !== next) {
      onPlaceholderChange?.(next);
      placeholder = next;
    }
    return next;
  },
  onValueChange: ({ next }) => {
    if (value !== next) {
      onValueChange?.(next);
      value = next;
    }
    return next;
  }
});
$:
  if (id) {
    ids.calendar.set(id);
  }
$:
  startValue = $localStartValue;
$:
  value !== void 0 && localValue.set(value);
$:
  placeholder !== void 0 && localPlaceholder.set(placeholder);
$:
  updateOption("preventDeselect", preventDeselect);
$:
  updateOption("minValue", minValue);
$:
  updateOption("maxValue", maxValue);
$:
  updateOption("pagedNavigation", pagedNavigation);
$:
  updateOption("weekStartsOn", weekStartsOn);
$:
  updateOption("locale", locale);
$:
  updateOption("isDateUnavailable", isDateUnavailable);
$:
  updateOption("isDateDisabled", isDateDisabled);
$:
  updateOption("disabled", disabled);
$:
  updateOption("readonly", readonly);
$:
  updateOption("fixedWeeks", fixedWeeks);
$:
  updateOption("calendarLabel", calendarLabel);
$:
  updateOption("weekdayFormat", weekdayFormat);
$:
  updateOption("numberOfMonths", numberOfMonths);
const attrs = getAttrs("root");
const dispatch = createDispatcher();
$:
  builder = $calendar;
$:
  Object.assign(builder, attrs);
let months = $localMonths;
$:
  months = $localMonths;
</script>

{#if asChild}
	<slot
		{builder}
		{months}
		weekdays={$weekdays}
		startValue={$localStartValue}
		endValue={$endValue}
	/>
{:else}
	<div {...builder} use:builder.action {...$$restProps} on:m-keydown={dispatch} bind:this={el}>
		<slot
			{builder}
			{months}
			weekdays={$weekdays}
			startValue={$localStartValue}
			endValue={$endValue}
		/>
	</div>
{/if}