accomadesc 0.3.36 → 0.3.38

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.
@@ -36,13 +36,7 @@
36
36
  </a>
37
37
  </div>
38
38
  {:else}
39
- <a
40
- href={path}
41
- {onclick}
42
- data-sveltekit-keepfocus
43
- data-sveltekit-noscroll
44
- class:disabled={gs.disableLinks}
45
- >
39
+ <a href={path} {onclick} class:disabled={gs.disableLinks}>
46
40
  {translateFunc ? translateFunc(n.key) : ''}
47
41
  </a>
48
42
  {/if}
@@ -66,7 +66,7 @@
66
66
  gridTemplateColumns = '1fr 1fr';
67
67
  padding = originalPadding;
68
68
  } else {
69
- if (!!columnCount && columnCount > 1) {
69
+ if (!!columnCount) {
70
70
  gridTemplateColumns = `repeat(${columnCount}, 1fr)`;
71
71
  }
72
72
  padding = originalPadding;
@@ -1,31 +1,32 @@
1
- import { type I18nFacade, type OccuplanTranslations } from 'accomadesc';
2
1
  import type { CookieSelection, Translation as CookieTranslation } from 'gdpr-cooco-banner';
3
2
  import { DateTime } from 'luxon';
4
- import type { SiteConfig } from './types.ts';
3
+ import type { FormatSpec, I18nFacade, SiteConfig } from './types.ts';
4
+ import type { OccuplanTranslations } from './occuplan/state.svelte.ts';
5
5
  interface FullTranslation {
6
6
  calendar: OccuplanTranslations;
7
7
  cookies: CookieTranslation;
8
8
  site: Record<string, string>;
9
9
  }
10
10
  export declare class SiteState implements I18nFacade {
11
- fullTranslations: Record<string, FullTranslation>;
12
- calendarTranslations: Record<string, OccuplanTranslations>;
13
- cookieTranslations: Record<string, CookieTranslation>;
14
- siteTranslations: Record<string, Record<string, string>>;
15
- supportedLangs: string[];
16
- isMenuOpen: boolean;
11
+ _getSiteConfigFn: () => SiteConfig;
12
+ get fullTranslations(): Record<string, FullTranslation>;
13
+ get calendarTranslations(): Record<string, OccuplanTranslations>;
14
+ get cookieTranslations(): Record<string, CookieTranslation>;
15
+ get siteTranslations(): Record<string, Record<string, string>>;
16
+ get supportedLangs(): string[];
17
17
  cookieSelection: CookieSelection;
18
18
  currentLang: string;
19
- translations: Record<string, Record<string, string>>;
20
- calendarTranslation: OccuplanTranslations;
21
- cookieTranslation: CookieTranslation;
22
- formats: Record<string, Record<string, any>>;
19
+ get translations(): Record<string, Record<string, string>>;
20
+ get calendarTranslation(): OccuplanTranslations;
21
+ get cookieTranslation(): CookieTranslation;
22
+ get formats(): Record<string, FormatSpec>;
23
23
  selectedTheme: 'light' | 'dark';
24
24
  selectedThemeInitialized: boolean;
25
- constructor(siteConfig: SiteConfig, lang: string | undefined);
25
+ constructor(getSiteConfig: () => SiteConfig, lang: string | undefined);
26
26
  updateCurrentLang: (lang: string) => string;
27
27
  translateFunc: (ref: string) => string;
28
28
  formatFunc: (ref: string, props: Record<string, any>) => string;
29
29
  formatDateFunc: (d: DateTime | string) => string;
30
+ translateWithLangFunc: (ref: string, lang: string) => string;
30
31
  }
31
32
  export {};
@@ -1,12 +1,33 @@
1
- import { format } from 'accomadesc';
2
1
  import { DateTime } from 'luxon';
2
+ import { format } from './helpers/format.ts';
3
3
  export class SiteState {
4
- fullTranslations = {};
5
- calendarTranslations = {};
6
- cookieTranslations = {};
7
- siteTranslations = {};
8
- supportedLangs = $state(['en']);
9
- isMenuOpen = $state(false);
4
+ _getSiteConfigFn;
5
+ //fullTranslations: Record<string, FullTranslation> = $derived(this._getSiteConfigFn().lang.translations);
6
+ get fullTranslations() {
7
+ return this._getSiteConfigFn().lang.translations;
8
+ }
9
+ get calendarTranslations() {
10
+ return Object.entries(this.fullTranslations).reduce((s, e) => {
11
+ s[e[0]] = e[1].calendar;
12
+ return s;
13
+ }, {});
14
+ }
15
+ ;
16
+ get cookieTranslations() {
17
+ return Object.entries(this.fullTranslations).reduce((s, e) => {
18
+ s[e[0]] = e[1].cookies;
19
+ return s;
20
+ }, {});
21
+ }
22
+ get siteTranslations() {
23
+ return Object.entries(this.fullTranslations).reduce((s, e) => {
24
+ s[e[0]] = e[1].site;
25
+ return s;
26
+ }, {});
27
+ }
28
+ get supportedLangs() {
29
+ return this._getSiteConfigFn().lang.supportedLangs;
30
+ }
10
31
  cookieSelection = $state({
11
32
  analytics: false,
12
33
  marketing: false,
@@ -14,32 +35,33 @@ export class SiteState {
14
35
  necessary: true,
15
36
  });
16
37
  currentLang = $state('en');
17
- translations = $state(this.siteTranslations);
18
- calendarTranslation = $derived(this.calendarTranslations[this.currentLang]);
19
- cookieTranslation = $state(this.cookieTranslations[this.currentLang]);
20
- formats = $state({});
38
+ get translations() {
39
+ return this.siteTranslations;
40
+ }
41
+ get calendarTranslation() {
42
+ return this.calendarTranslations[this.currentLang];
43
+ }
44
+ get cookieTranslation() {
45
+ return this.cookieTranslations[this.currentLang];
46
+ }
47
+ get formats() {
48
+ return this._getSiteConfigFn().lang.formats;
49
+ }
21
50
  selectedTheme = $state('light');
22
51
  selectedThemeInitialized = $state(false);
23
- constructor(siteConfig, lang) {
24
- if (!lang || !siteConfig.lang.supportedLangs.includes(lang)) {
25
- this.currentLang = siteConfig.lang.defaultLang;
52
+ constructor(getSiteConfig, lang) {
53
+ this._getSiteConfigFn = getSiteConfig;
54
+ if (!lang || !getSiteConfig().lang.supportedLangs.includes(lang)) {
55
+ this.currentLang = getSiteConfig().lang.defaultLang;
26
56
  }
27
57
  else {
28
58
  this.currentLang = lang;
29
59
  }
30
- this.fullTranslations = siteConfig.lang.translations;
31
- for (const lang in this.fullTranslations) {
32
- this.calendarTranslations[lang] = this.fullTranslations[lang].calendar;
33
- this.siteTranslations[lang] = this.fullTranslations[lang].site;
34
- this.cookieTranslations[lang] = this.fullTranslations[lang].cookies;
35
- }
36
- this.supportedLangs = siteConfig.lang.supportedLangs;
37
- this.formats = siteConfig.lang.formats;
38
60
  }
39
61
  updateCurrentLang = (lang) => (this.currentLang = lang);
40
62
  translateFunc = (ref) => {
41
63
  if (!ref)
42
- return 'UNDEF';
64
+ return '[UNDEF]';
43
65
  const current = this.translations[this.currentLang];
44
66
  if (!current[ref])
45
67
  return '';
@@ -48,22 +70,44 @@ export class SiteState {
48
70
  formatFunc = (ref, props) => {
49
71
  const fString = this.formats[this.currentLang][ref];
50
72
  if (!fString) {
51
- console.log('missing formatFunc', ref);
52
- return '';
73
+ console.warn(`[Missing formatFunc: ${ref}]`);
74
+ return '[UNDEF]';
53
75
  }
54
76
  let formatted = format(fString, props);
55
77
  return formatted;
56
78
  };
57
79
  formatDateFunc = (d) => {
80
+ if (!d)
81
+ return this.translateFunc("invalid");
82
+ const formatSpecs = this.formats[this.currentLang];
58
83
  let f = 'yyyy-MM-dd';
59
- if (this.formats[this.currentLang]?.dateFormat) {
60
- f = this.formats[this.currentLang].dateFormat;
84
+ if (formatSpecs?.dateFormat) {
85
+ f = formatSpecs.dateFormat;
61
86
  }
62
87
  let date;
63
88
  if (typeof d === 'string')
64
89
  date = DateTime.fromISO(d);
65
90
  else
66
91
  date = d;
67
- return date.toFormat(f);
92
+ // if d was invalid to begin with or
93
+ // translformation from ISO didn't yield a valid DateTime object
94
+ if (date.isValid)
95
+ return this.translateFunc("invalid");
96
+ return date.setLocale(formatSpecs.locale).toFormat(f);
97
+ };
98
+ translateWithLangFunc = (ref, lang) => {
99
+ const translation = this.translations[lang];
100
+ if (!translation) {
101
+ console.error(`[Tried to access unknown translation: ${lang}]`);
102
+ return "[UNDEF]";
103
+ }
104
+ const res = translation[ref];
105
+ if (res === undefined) {
106
+ console.warn(`[Missing Translation for: ${ref}]`);
107
+ return '[UNDEF]';
108
+ }
109
+ else {
110
+ return res;
111
+ }
68
112
  };
69
113
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { randomName, randomID } from './names/gen.js';
2
2
  import { format } from './helpers/format.js';
3
3
  import { MoneyFormats } from './helpers/moneyFormats.js';
4
+ import { SiteState } from './SiteState.svelte.js';
4
5
  import Avatar from './basic/Avatar.svelte';
5
6
  import Button from './basic/Button.svelte';
6
7
  import Icon from './basic/Icon.svelte';
@@ -28,4 +29,4 @@ import PageComponent from './PageComponent.svelte';
28
29
  export type { OccuplanTranslations } from './occuplan/state.svelte';
29
30
  export type { GridPhoto, LeafletMap as LeafletMapI, LeafletMapContent, Calendar as CalendarI, CalendarContent, CalendarAvailable as CalendarAvailableI, CalendarAvailableContent, CalendarGrid as CalendarGridI, CalendarGridContent, CalendarRows as CalendarRowsI, CalendarRowsContent, Text as TextI, TextContent, Weather as WeatherI, WeatherContent, Photo as PhotoI, PhotoContent, PhotoGallery as PhotoGalleryI, PhotoGalleryContent, Pricing as PricingI, PricingContent, PricingShort as PricingShortI, PricingShortContent, PricingEntry, PricingRange, PricingColumn, StaticRangeDate, StaticPricingRange, AmenitiesCore as AmenitiesCoreI, AmenitiesCoreContent, AccoCard as AccoCardI, AccoCardContent, ContactForm as ContactFormI, ContactFormContent, BookingRequest as BookingRequestI, BookingRequestContent, AccoDescription as AccoDescriptionI, AccoDescriptionContent, Section as SectionI, I18nFacade, AccoBlock, Block, PageProps, PageConfig, Nav as NavI, Style, NavItem, FormatSpec, FormatTemplateName, SiteConfig, LangConfig, CookieConfig, SiteFonts, SiteTranslation, FontSpec, Hero, } from './types.js';
30
31
  export { PRICING_COLUMNS, BLOCK_KINDS, isAccoCard, isText, isPhoto, isGallery, isLeafletMap, isWeather, isAmenitiesCore, isCalendarAvailable, isCalendar, isCalendarGrid, isCalendarRows, isPricing, isPricingShort, isAccoDescription, isBookingRequest, isContactForm, isAccoBlock, } from './types.js';
31
- export { randomID, randomName, format, MoneyFormats, Avatar, Button, Icon, Spinner, TextInput, AccoCard, AccoDescription, AmenitiesCore, Calendar, CalendarAvailable, LeafletMap, Photo, PhotoGallery, Pricing, PricingShort, Section, Text, Weather, BookingRequest, ContactForm, CalendarRows, CalendarGrid, Notes, PageComponent, };
32
+ export { randomID, randomName, format, MoneyFormats, Avatar, Button, Icon, Spinner, TextInput, AccoCard, AccoDescription, AmenitiesCore, Calendar, CalendarAvailable, LeafletMap, Photo, PhotoGallery, Pricing, PricingShort, Section, Text, Weather, BookingRequest, ContactForm, CalendarRows, CalendarGrid, Notes, PageComponent, SiteState, };
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { randomName, randomID } from './names/gen.js';
3
3
  import { format } from './helpers/format.js';
4
4
  import { MoneyFormats } from './helpers/moneyFormats.js';
5
+ import { SiteState } from './SiteState.svelte.js';
5
6
  import Avatar from './basic/Avatar.svelte';
6
7
  import Button from './basic/Button.svelte';
7
8
  import Icon from './basic/Icon.svelte';
@@ -27,4 +28,4 @@ import Text from './Text.svelte';
27
28
  import Weather from './Weather.svelte';
28
29
  import PageComponent from './PageComponent.svelte';
29
30
  export { PRICING_COLUMNS, BLOCK_KINDS, isAccoCard, isText, isPhoto, isGallery, isLeafletMap, isWeather, isAmenitiesCore, isCalendarAvailable, isCalendar, isCalendarGrid, isCalendarRows, isPricing, isPricingShort, isAccoDescription, isBookingRequest, isContactForm, isAccoBlock, } from './types.js';
30
- export { randomID, randomName, format, MoneyFormats, Avatar, Button, Icon, Spinner, TextInput, AccoCard, AccoDescription, AmenitiesCore, Calendar, CalendarAvailable, LeafletMap, Photo, PhotoGallery, Pricing, PricingShort, Section, Text, Weather, BookingRequest, ContactForm, CalendarRows, CalendarGrid, Notes, PageComponent, };
31
+ export { randomID, randomName, format, MoneyFormats, Avatar, Button, Icon, Spinner, TextInput, AccoCard, AccoDescription, AmenitiesCore, Calendar, CalendarAvailable, LeafletMap, Photo, PhotoGallery, Pricing, PricingShort, Section, Text, Weather, BookingRequest, ContactForm, CalendarRows, CalendarGrid, Notes, PageComponent, SiteState, };
@@ -0,0 +1,157 @@
1
+ export declare const DefaultCalTranslations: {
2
+ es: {
3
+ weekdayLabels: {
4
+ 1: string;
5
+ 2: string;
6
+ 3: string;
7
+ 4: string;
8
+ 5: string;
9
+ 6: string;
10
+ 7: string;
11
+ };
12
+ monthLabels: {
13
+ 1: string;
14
+ 2: string;
15
+ 3: string;
16
+ 4: string;
17
+ 5: string;
18
+ 6: string;
19
+ 7: string;
20
+ 8: string;
21
+ 9: string;
22
+ 10: string;
23
+ 11: string;
24
+ 12: string;
25
+ };
26
+ weekendLabel: string;
27
+ typeLabels: {
28
+ one: string;
29
+ two: string;
30
+ three: string;
31
+ };
32
+ };
33
+ fr: {
34
+ weekdayLabels: {
35
+ 1: string;
36
+ 2: string;
37
+ 3: string;
38
+ 4: string;
39
+ 5: string;
40
+ 6: string;
41
+ 7: string;
42
+ };
43
+ monthLabels: {
44
+ 1: string;
45
+ 2: string;
46
+ 3: string;
47
+ 4: string;
48
+ 5: string;
49
+ 6: string;
50
+ 7: string;
51
+ 8: string;
52
+ 9: string;
53
+ 10: string;
54
+ 11: string;
55
+ 12: string;
56
+ };
57
+ weekendLabel: string;
58
+ typeLabels: {
59
+ one: string;
60
+ two: string;
61
+ three: string;
62
+ };
63
+ };
64
+ pl: {
65
+ weekdayLabels: {
66
+ 1: string;
67
+ 2: string;
68
+ 3: string;
69
+ 4: string;
70
+ 5: string;
71
+ 6: string;
72
+ 7: string;
73
+ };
74
+ monthLabels: {
75
+ 1: string;
76
+ 2: string;
77
+ 3: string;
78
+ 4: string;
79
+ 5: string;
80
+ 6: string;
81
+ 7: string;
82
+ 8: string;
83
+ 9: string;
84
+ 10: string;
85
+ 11: string;
86
+ 12: string;
87
+ };
88
+ weekendLabel: string;
89
+ typeLabels: {
90
+ one: string;
91
+ two: string;
92
+ three: string;
93
+ };
94
+ };
95
+ en: {
96
+ weekdayLabels: {
97
+ 1: string;
98
+ 2: string;
99
+ 3: string;
100
+ 4: string;
101
+ 5: string;
102
+ 6: string;
103
+ 7: string;
104
+ };
105
+ monthLabels: {
106
+ 1: string;
107
+ 2: string;
108
+ 3: string;
109
+ 4: string;
110
+ 5: string;
111
+ 6: string;
112
+ 7: string;
113
+ 8: string;
114
+ 9: string;
115
+ 10: string;
116
+ 11: string;
117
+ 12: string;
118
+ };
119
+ weekendLabel: string;
120
+ typeLabels: {
121
+ one: string;
122
+ two: string;
123
+ three: string;
124
+ };
125
+ };
126
+ de: {
127
+ weekdayLabels: {
128
+ 1: string;
129
+ 2: string;
130
+ 3: string;
131
+ 4: string;
132
+ 5: string;
133
+ 6: string;
134
+ 7: string;
135
+ };
136
+ monthLabels: {
137
+ 1: string;
138
+ 2: string;
139
+ 3: string;
140
+ 4: string;
141
+ 5: string;
142
+ 6: string;
143
+ 7: string;
144
+ 8: string;
145
+ 9: string;
146
+ 10: string;
147
+ 11: string;
148
+ 12: string;
149
+ };
150
+ weekendLabel: string;
151
+ typeLabels: {
152
+ one: string;
153
+ two: string;
154
+ three: string;
155
+ };
156
+ };
157
+ };
@@ -0,0 +1,157 @@
1
+ export const DefaultCalTranslations = {
2
+ es: {
3
+ weekdayLabels: {
4
+ 1: 'Lu',
5
+ 2: 'Ma',
6
+ 3: 'Mi',
7
+ 4: 'Ju',
8
+ 5: 'Vi',
9
+ 6: 'Sa',
10
+ 7: 'Do',
11
+ },
12
+ monthLabels: {
13
+ 1: 'Ene',
14
+ 2: 'Feb',
15
+ 3: 'Mar',
16
+ 4: 'Abr',
17
+ 5: 'May',
18
+ 6: 'Jun',
19
+ 7: 'Jul',
20
+ 8: 'Ago',
21
+ 9: 'Sep',
22
+ 10: 'Oct',
23
+ 11: 'Nov',
24
+ 12: 'Dic',
25
+ },
26
+ weekendLabel: 'Fin de Semana',
27
+ typeLabels: {
28
+ one: 'Ocupado',
29
+ two: 'Ocupade',
30
+ three: '',
31
+ },
32
+ },
33
+ fr: {
34
+ weekdayLabels: {
35
+ 1: 'Lu',
36
+ 2: 'Ma',
37
+ 3: 'Me',
38
+ 4: 'Je',
39
+ 5: 'Ve',
40
+ 6: 'Sa',
41
+ 7: 'Di',
42
+ },
43
+ monthLabels: {
44
+ 1: 'Jan',
45
+ 2: 'Fév',
46
+ 3: 'Mar',
47
+ 4: 'Avr',
48
+ 5: 'Mai',
49
+ 6: 'Juin',
50
+ 7: 'Juil',
51
+ 8: 'Août',
52
+ 9: 'Sept',
53
+ 10: 'Oct',
54
+ 11: 'Nov',
55
+ 12: 'Déc',
56
+ },
57
+ weekendLabel: 'Week-end',
58
+ typeLabels: {
59
+ one: 'Occupé',
60
+ two: 'Occupé',
61
+ three: '',
62
+ },
63
+ },
64
+ pl: {
65
+ weekdayLabels: {
66
+ 1: 'Pon',
67
+ 2: 'Wt',
68
+ 3: 'Śr',
69
+ 4: 'Czw',
70
+ 5: 'Pt',
71
+ 6: 'Sob',
72
+ 7: 'Ndz',
73
+ },
74
+ monthLabels: {
75
+ 1: 'Sty',
76
+ 2: 'Lut',
77
+ 3: 'Mar',
78
+ 4: 'Kwi',
79
+ 5: 'Maj',
80
+ 6: 'Cze',
81
+ 7: 'Lip',
82
+ 8: 'Sie',
83
+ 9: 'Wrz',
84
+ 10: 'Paź',
85
+ 11: 'Lis',
86
+ 12: 'Gru',
87
+ },
88
+ weekendLabel: 'Weekend',
89
+ typeLabels: {
90
+ one: 'Zajęty',
91
+ two: 'Zajęty',
92
+ three: '',
93
+ },
94
+ },
95
+ en: {
96
+ weekdayLabels: {
97
+ 1: 'Mo',
98
+ 2: 'Tu',
99
+ 3: 'We',
100
+ 4: 'Th',
101
+ 5: 'Fr',
102
+ 6: 'Sa',
103
+ 7: 'Su',
104
+ },
105
+ monthLabels: {
106
+ 1: 'Jan',
107
+ 2: 'Feb',
108
+ 3: 'Mar',
109
+ 4: 'Apr',
110
+ 5: 'May',
111
+ 6: 'Jun',
112
+ 7: 'Jul',
113
+ 8: 'Aug',
114
+ 9: 'Sep',
115
+ 10: 'Oct',
116
+ 11: 'Nov',
117
+ 12: 'Dec',
118
+ },
119
+ weekendLabel: 'Weekend',
120
+ typeLabels: {
121
+ one: 'Occupied',
122
+ two: 'Blocked',
123
+ three: 'Requested',
124
+ },
125
+ },
126
+ de: {
127
+ weekdayLabels: {
128
+ 1: 'Mo',
129
+ 2: 'Di',
130
+ 3: 'Mi',
131
+ 4: 'Do',
132
+ 5: 'Fr',
133
+ 6: 'Sa',
134
+ 7: 'So',
135
+ },
136
+ monthLabels: {
137
+ 1: 'Jan',
138
+ 2: 'Feb',
139
+ 3: 'Mär',
140
+ 4: 'Apr',
141
+ 5: 'Mai',
142
+ 6: 'Jun',
143
+ 7: 'Jul',
144
+ 8: 'Aug',
145
+ 9: 'Sep',
146
+ 10: 'Okt',
147
+ 11: 'Nov',
148
+ 12: 'Dez',
149
+ },
150
+ weekendLabel: 'Wochenende',
151
+ typeLabels: {
152
+ one: 'Belegt',
153
+ two: 'Geblockt',
154
+ three: 'Anfrage',
155
+ },
156
+ },
157
+ };
@@ -411,7 +411,7 @@ export class OccupationState {
411
411
  export const getOccupationState = (url, debug = false) => {
412
412
  if (debug)
413
413
  console.log('Get OState /w url', url);
414
- const stateID = Symbol(`i-${url}-${OCCUPATION_STATE}`);
414
+ const stateID = `i-${url}-${OCCUPATION_STATE}`;
415
415
  let _instance = getContext(stateID);
416
416
  if (_instance)
417
417
  return _instance;
package/dist/types.d.ts CHANGED
@@ -396,6 +396,7 @@ export interface I18nFacade {
396
396
  supportedLangs?: string[];
397
397
  calendarTranslation?: OccuplanTranslations;
398
398
  translateFunc?: (ref: string) => string;
399
+ translateWithLangFunc?: (ref: string, lang: string) => string;
399
400
  formatFunc?: (formatter: string, props: Record<string, any>) => string;
400
401
  formatMoneyFunc?: (d: number) => string;
401
402
  formatDateFunc?: (d: DateTime | string) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "accomadesc",
3
- "version": "0.3.36",
3
+ "version": "0.3.38",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",
@@ -30,7 +30,7 @@
30
30
  "@sveltejs/package": "^2.5.7",
31
31
  "@sveltejs/vite-plugin-svelte": "^5.1.1",
32
32
  "@types/luxon": "^3.7.1",
33
- "gdpr-cooco-banner": "^0.0.11",
33
+ "gdpr-cooco-banner": "^0.0.12",
34
34
  "prettier": "^3.7.4",
35
35
  "prettier-plugin-svelte": "^3.4.1",
36
36
  "publint": "^0.3.16",