accomadesc 0.3.30 → 0.3.32

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.
@@ -5,9 +5,9 @@
5
5
  import Notes from './basic/Notes.svelte';
6
6
  import Spinner from './basic/Spinner.svelte';
7
7
  import TextInput from './basic/TextInput.svelte';
8
- import { OCCUPATION_STATE, OccupationState } from './occuplan/state.svelte.js';
8
+ import { getOccupationState, OccupationState } from './occuplan/state.svelte.js';
9
9
  import OccuPlanPicker from './occuplan/OccuPlanPicker.svelte';
10
- import { slide } from 'svelte/transition';
10
+ import { fade } from 'svelte/transition';
11
11
  import type { DateTime } from 'luxon';
12
12
  import { randomID } from './names/gen.js';
13
13
 
@@ -55,9 +55,7 @@
55
55
  let sending = $state(false);
56
56
  let disabled = $derived(preview || errored || successfullySent);
57
57
 
58
- const url = calUrl;
59
- const oStateID = `i-${url}-${OCCUPATION_STATE}`;
60
- let occupationState: OccupationState = $state(getContext(oStateID));
58
+ let occupationState: OccupationState = getOccupationState(calUrl);
61
59
  let invalid = $derived(
62
60
  occupationState && arrival && leave ? occupationState.validRequest(arrival, leave) : false,
63
61
  );
@@ -161,8 +159,8 @@
161
159
  </label>
162
160
  <div class="input-wrapper" class:disabled>
163
161
  {#if inputDatesEngaged}
164
- <div transition:slide style="min-width: 32rem;" class="picker-wrapper">
165
- <OccuPlanPicker {arrival} {leave} {url} aborted={abortDateInput} {dateSelected} />
162
+ <div transition:fade style="min-width: 32rem;" class="picker-wrapper">
163
+ <OccuPlanPicker {arrival} {leave} url={calUrl} aborted={abortDateInput} {dateSelected} />
166
164
  </div>
167
165
  {/if}
168
166
  <div class="date-input-wrapper" id="engage-date-buttons">
@@ -243,9 +241,10 @@
243
241
  }
244
242
  }
245
243
  form {
244
+ position: relative;
246
245
  display: grid;
247
246
  grid-template-columns: [start] 1fr [gap-start] 0.5fr [gap-end] 3fr [end];
248
- row-gap: 0.5rem;
247
+ row-gap: 1rem;
249
248
 
250
249
  label {
251
250
  align-content: center;
@@ -272,6 +271,8 @@
272
271
  justify-content: flex-start;
273
272
  }
274
273
  div.picker-wrapper {
274
+ bottom: 2rem;
275
+ right: -3rem;
275
276
  position: absolute;
276
277
  z-index: 9999;
277
278
  background-color: var(--main-bg-color);
@@ -40,7 +40,7 @@
40
40
 
41
41
  width: 100%;
42
42
  max-width: 800px;
43
- min-height: 5rem;
43
+ min-height: 8rem;
44
44
  height: 100%;
45
45
 
46
46
  border: none;
@@ -1,15 +1,13 @@
1
1
  <script lang="ts">
2
2
  import { DateTime } from 'luxon';
3
3
  import { normalizeDate } from '../helpers/normalizeDate.js';
4
- import { getContext, onMount, setContext, type Snippet } from 'svelte';
4
+ import { onMount, type Snippet } from 'svelte';
5
5
  import {
6
- OCCUPATION_STATE,
7
6
  OccupationState,
8
7
  getOccupationState,
9
8
  type AvailableSpans,
10
9
  } from './state.svelte.js';
11
10
  import Spinner from '../basic/Spinner.svelte';
12
- import { browser } from '$app/environment';
13
11
 
14
12
  let {
15
13
  url,
@@ -25,16 +23,13 @@
25
23
  children: Snippet<[AvailableSpans]>;
26
24
  } = $props();
27
25
 
28
- const oStateID = `i-${url}-${OCCUPATION_STATE}`;
29
- let occupationState: OccupationState = $state(getContext(oStateID));
30
- onMount(() => {
31
- if (!occupationState && browser) {
32
- occupationState = getOccupationState(url, debug);
33
- setContext(oStateID, occupationState);
34
- }
35
- });
26
+ let occupationState: OccupationState = getOccupationState(url, debug);
36
27
 
37
28
  let av = $derived(occupationState ? occupationState.calcAvailability(search, maxFutureDate) : {});
29
+
30
+ onMount(() => {
31
+ occupationState.loadOccupations();
32
+ });
38
33
  </script>
39
34
 
40
35
  {#if !occupationState || occupationState.loading}
@@ -4,7 +4,6 @@
4
4
  defaultMonthHeaderFormat,
5
5
  defaultMonthLabels,
6
6
  defaultWeekdayLabels,
7
- OCCUPATION_STATE,
8
7
  OccupationState,
9
8
  getOccupationState,
10
9
  occupationTypeFormatting,
@@ -13,11 +12,10 @@
13
12
  type OccupationType,
14
13
  type OccuplanTranslations,
15
14
  } from './state.svelte.js';
16
- import { getContext, onMount, setContext } from 'svelte';
17
15
  import Button from '../basic/Button.svelte';
18
- import { browser } from '$app/environment';
19
16
  import Spinner from '../basic/Spinner.svelte';
20
17
  import { randomID } from '../names/gen.js';
18
+ import { onMount } from 'svelte';
21
19
 
22
20
  let {
23
21
  url,
@@ -51,14 +49,7 @@
51
49
 
52
50
  const id = randomID();
53
51
 
54
- const oStateID = `i-${url}-${OCCUPATION_STATE}`;
55
- let occupationState: OccupationState = $state(getContext(oStateID));
56
- onMount(() => {
57
- if (!occupationState && browser) {
58
- occupationState = getOccupationState(url, debug);
59
- setContext(oStateID, occupationState);
60
- }
61
- });
52
+ let occupationState: OccupationState = getOccupationState(url, debug);
62
53
 
63
54
  //let formatFun = $derived(Sqrl.compile(monthHeaderFormat, { useWith: true }));
64
55
  const monthHeader = (monthNum: MonthNumbers, year: number): string => {
@@ -71,7 +62,9 @@
71
62
  };
72
63
 
73
64
  let page: number = $state(0);
74
- let rfMonth: DateTime = $derived(realFirstMonth(firstMonth, numberOfMonth, page));
65
+ let rfMonth: DateTime = $derived(
66
+ realFirstMonth(firstMonth, DateTime.utc().get('year'), numberOfMonth, page),
67
+ );
75
68
 
76
69
  let currentMaxDate = $derived(rfMonth.plus({ month: numberOfMonth }));
77
70
 
@@ -153,6 +146,10 @@
153
146
  return res;
154
147
  }, [] as OccupationType[]),
155
148
  );
149
+
150
+ onMount(() => {
151
+ occupationState.loadOccupations();
152
+ });
156
153
  </script>
157
154
 
158
155
  {#if !occupationState || occupationState.loading}
@@ -4,15 +4,13 @@
4
4
  defaultMonthHeaderFormat,
5
5
  defaultMonthLabels,
6
6
  defaultWeekdayLabels,
7
- OCCUPATION_STATE,
8
7
  OccupationState,
9
8
  getOccupationState,
10
9
  realFirstMonth,
11
10
  type OccuplanTranslations,
12
11
  } from './state.svelte.js';
13
- import { getContext, onMount, setContext, untrack } from 'svelte';
12
+ import { onMount, untrack } from 'svelte';
14
13
  import Button from '../basic/Button.svelte';
15
- import { browser } from '$app/environment';
16
14
  import Spinner from '../basic/Spinner.svelte';
17
15
  import { normalizeDate } from '../helpers/normalizeDate.js';
18
16
 
@@ -58,14 +56,7 @@
58
56
  dateSelected?: (arrival: DateTime, leave: DateTime) => void;
59
57
  } = $props();
60
58
 
61
- const oStateID = `i-${url}-${OCCUPATION_STATE}`;
62
- let occupationState: OccupationState = $state(getContext(oStateID));
63
- onMount(() => {
64
- if (!occupationState && browser) {
65
- occupationState = getOccupationState(url, debug);
66
- setContext(oStateID, occupationState);
67
- }
68
- });
59
+ let occupationState: OccupationState = getOccupationState(url, debug);
69
60
 
70
61
  const monthHeader = (monthNum: MonthNumbers, year: number): string => {
71
62
  const monthLabel = monthLabels[monthNum];
@@ -83,6 +74,7 @@
83
74
  let rfMonth: DateTime = $derived(
84
75
  realFirstMonth(
85
76
  (arrival?.month ? arrival.month : minDate.month) as MonthNumbers,
77
+ arrival?.year ? arrival.year : minDate.year,
86
78
  numberOfMonth,
87
79
  page,
88
80
  ),
@@ -200,6 +192,10 @@
200
192
  let firstDayOfWeek = w.startOf('week');
201
193
  return lastDayOfMonth < firstDayOfWeek;
202
194
  };
195
+
196
+ onMount(() => {
197
+ occupationState.loadOccupations();
198
+ });
203
199
  </script>
204
200
 
205
201
  {#if !occupationState || occupationState.loading}
@@ -209,6 +205,7 @@
209
205
  <div class="wrapper">
210
206
  <section class="occuplan-wrapper" style="max-width: {maxWidth}; width: 100%;">
211
207
  <header class="occupation-plan-header">
208
+ {rfMonth}
212
209
  <div class="header-controls">
213
210
  {#if rfMonth >= minDate}
214
211
  <Button text={prevPage} clicked={prevClicked} preventDefault={true} />
@@ -8,16 +8,15 @@
8
8
  occupationTypeFormatting,
9
9
  type OccupationType,
10
10
  type OccuplanTranslations,
11
- OCCUPATION_STATE,
12
11
  type DayHelper,
13
12
  type FirstMonth,
14
13
  realFirstMonth,
15
14
  } from './state.svelte.js';
16
15
  import Button from '../basic/Button.svelte';
17
16
  import { browser } from '$app/environment';
18
- import { getContext, onMount, setContext } from 'svelte';
19
17
  import Spinner from '../basic/Spinner.svelte';
20
18
  import { randomID } from '../names/gen.js';
19
+ import { onMount } from 'svelte';
21
20
 
22
21
  let {
23
22
  url,
@@ -48,17 +47,12 @@
48
47
 
49
48
  const id = randomID();
50
49
 
51
- const oStateID = `i-${url}-${OCCUPATION_STATE}`;
52
- let occupationState: OccupationState = $state(getContext(oStateID));
53
- onMount(() => {
54
- if (!occupationState && browser) {
55
- occupationState = getOccupationState(url, debug);
56
- setContext(oStateID, occupationState);
57
- }
58
- });
50
+ let occupationState: OccupationState = getOccupationState(url, debug);
59
51
 
60
52
  let page: number = $state(0);
61
- let rfMonth: number | DateTime = $derived(realFirstMonth(firstMonth, numberOfMonth, page));
53
+ let rfMonth: number | DateTime = $derived(
54
+ realFirstMonth(firstMonth, DateTime.utc().get('year'), numberOfMonth, page),
55
+ );
62
56
 
63
57
  let currentMaxDate = $derived(rfMonth.plus({ month: numberOfMonth }));
64
58
 
@@ -134,6 +128,10 @@
134
128
  }, [] as OccupationType[])
135
129
  : [],
136
130
  );
131
+
132
+ onMount(() => {
133
+ occupationState.loadOccupations();
134
+ });
137
135
  </script>
138
136
 
139
137
  {#if !occupationState || occupationState.loading}
@@ -30,7 +30,7 @@ export interface DayHelper {
30
30
  year: number;
31
31
  }
32
32
  export declare const firstMonthValid: (value: string | number) => boolean;
33
- export declare const realFirstMonth: (firstMonth: FirstMonth, numberOfMonth: number, page: number) => DateTime;
33
+ export declare const realFirstMonth: (firstMonth: FirstMonth, firstMonthYear: number, numberOfMonth: number, page: number) => DateTime;
34
34
  export interface OccuplanTranslations {
35
35
  arrivalLabel?: string;
36
36
  leaveLabel?: string;
@@ -74,7 +74,7 @@ export declare class OccupationState {
74
74
  loading: boolean;
75
75
  debug: boolean;
76
76
  constructor(iCalURL: string, debug?: boolean);
77
- private loadOccupations;
77
+ loadOccupations: () => Promise<boolean>;
78
78
  private eventsIncomingCallback;
79
79
  private dayKey;
80
80
  private updateOccupiedDays;
@@ -2,6 +2,7 @@ import { normalizeDate } from '../helpers/normalizeDate.js';
2
2
  import { getEvents } from '../helpers/readICS.js';
3
3
  import { DateTime } from 'luxon';
4
4
  import { DateTime as luxon } from 'luxon';
5
+ import { getContext, setContext } from 'svelte';
5
6
  export const OCCUPATION_STATE = 'occupation-state';
6
7
  export const occupationTypeFormattingByOccupation = (o) => {
7
8
  return occupationTypeFormatting(o?.type);
@@ -74,16 +75,20 @@ export const firstMonthValid = (value) => {
74
75
  }
75
76
  return false;
76
77
  };
77
- export const realFirstMonth = (firstMonth, numberOfMonth, page) => {
78
+ export const realFirstMonth = (firstMonth, firstMonthYear, numberOfMonth, page) => {
78
79
  const monthToAdd = page * numberOfMonth;
80
+ console.log(firstMonth, firstMonthYear, numberOfMonth, page);
79
81
  if (typeof firstMonth === 'number') {
80
82
  const intValue = firstMonth;
81
83
  if (intValue >= 1 && intValue <= 12) {
82
84
  const tDate = normalizeDate(DateTime.utc())
83
- .set({ month: intValue })
85
+ .set({ month: intValue, year: firstMonthYear })
84
86
  .plus({ month: monthToAdd });
85
87
  return tDate;
86
88
  }
89
+ else {
90
+ return normalizeDate(DateTime.utc()).plus(monthToAdd);
91
+ }
87
92
  }
88
93
  else if (typeof firstMonth === 'string' && firstMonth.length > 1) {
89
94
  //check + sign
@@ -93,10 +98,14 @@ export const realFirstMonth = (firstMonth, numberOfMonth, page) => {
93
98
  const intValue = parseInt(toParse);
94
99
  if (intValue >= 1 && intValue <= 12) {
95
100
  const tDate = normalizeDate(DateTime.utc())
101
+ .set({ year: firstMonthYear })
96
102
  .plus({ month: intValue })
97
103
  .plus({ month: monthToAdd });
98
104
  return tDate;
99
105
  }
106
+ else {
107
+ return normalizeDate(DateTime.utc()).plus(monthToAdd);
108
+ }
100
109
  }
101
110
  catch (e) {
102
111
  console.log('casting error', e);
@@ -109,10 +118,14 @@ export const realFirstMonth = (firstMonth, numberOfMonth, page) => {
109
118
  const intValue = parseInt(toParse);
110
119
  if (intValue >= 0 && intValue <= 12) {
111
120
  const tDate = normalizeDate(DateTime.utc())
121
+ .set({ year: firstMonthYear })
112
122
  .minus({ month: intValue })
113
123
  .plus({ month: monthToAdd });
114
124
  return tDate;
115
125
  }
126
+ else {
127
+ return normalizeDate(DateTime.utc()).plus(monthToAdd);
128
+ }
116
129
  }
117
130
  catch (e) {
118
131
  console.log('casting error', e);
@@ -124,7 +137,7 @@ export const realFirstMonth = (firstMonth, numberOfMonth, page) => {
124
137
  const intValue = parseInt(firstMonth);
125
138
  //current dynamic month
126
139
  if (intValue == 0) {
127
- return normalizeDate(DateTime.utc()).plus({ month: monthToAdd });
140
+ return normalizeDate(DateTime.utc()).set({ year: firstMonthYear }).plus({ month: monthToAdd });
128
141
  }
129
142
  //static month of current year
130
143
  if (intValue >= 1 && intValue <= 12) {
@@ -133,13 +146,16 @@ export const realFirstMonth = (firstMonth, numberOfMonth, page) => {
133
146
  .plus({ month: monthToAdd });
134
147
  return tDate;
135
148
  }
149
+ else {
150
+ return normalizeDate(DateTime.utc()).set({ year: firstMonthYear }).plus(monthToAdd);
151
+ }
136
152
  }
137
153
  catch (e) {
138
154
  console.log('casting error', e);
139
155
  }
140
156
  }
141
157
  //first month of current year ... default
142
- return normalizeDate(DateTime.utc()).set({ month: 1 }).plus({ month: monthToAdd });
158
+ return normalizeDate(DateTime.utc()).set({ month: 1, year: firstMonthYear }).plus({ month: monthToAdd });
143
159
  };
144
160
  const validDay = (d) => {
145
161
  const today = luxon.utc();
@@ -185,7 +201,7 @@ export class OccupationState {
185
201
  if (this.debug)
186
202
  console.log('Constructing OState with CalUrl: ', iCalURL);
187
203
  this.iCalURL = iCalURL;
188
- this.loadOccupations();
204
+ //this.loadOccupations();
189
205
  }
190
206
  loadOccupations = async () => {
191
207
  if (this.debug)
@@ -392,14 +408,13 @@ export class OccupationState {
392
408
  `;
393
409
  };
394
410
  }
395
- let _instances = {};
396
411
  export const getOccupationState = (url, debug = false) => {
397
412
  if (debug)
398
413
  console.log('Get OState /w url', url);
399
- const currentInstance = _instances[url];
400
- if (currentInstance)
401
- return currentInstance;
402
- const newInstance = new OccupationState(url, debug);
403
- _instances[url] = newInstance;
404
- return _instances[url];
414
+ const stateID = `i-${url}-${OCCUPATION_STATE}`;
415
+ let _instance = getContext(stateID);
416
+ if (_instance)
417
+ return _instance;
418
+ setContext(stateID, new OccupationState(url, debug));
419
+ return getContext(stateID);
405
420
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "accomadesc",
3
- "version": "0.3.30",
3
+ "version": "0.3.32",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",
@@ -26,16 +26,16 @@
26
26
  "devDependencies": {
27
27
  "@sveltejs/adapter-auto": "^3.3.1",
28
28
  "@sveltejs/adapter-static": "^3.0.10",
29
- "@sveltejs/kit": "^2.47.3",
30
- "@sveltejs/package": "^2.5.4",
29
+ "@sveltejs/kit": "^2.49.0",
30
+ "@sveltejs/package": "^2.5.6",
31
31
  "@sveltejs/vite-plugin-svelte": "^5.1.1",
32
32
  "@types/luxon": "^3.7.1",
33
33
  "gdpr-cooco-banner": "^0.0.11",
34
34
  "prettier": "^3.6.2",
35
35
  "prettier-plugin-svelte": "^3.4.0",
36
36
  "publint": "^0.3.15",
37
- "svelte": "^5.41.4",
38
- "svelte-check": "^4.3.3",
37
+ "svelte": "^5.43.14",
38
+ "svelte-check": "^4.3.4",
39
39
  "typescript": "^5.9.3",
40
40
  "vite": "^6.4.1"
41
41
  },