From 7f9aae4f3159018ec47b3340a6fb82b1191f0b5c Mon Sep 17 00:00:00 2001 From: nahbee10 Date: Thu, 7 Nov 2024 10:59:27 -0500 Subject: [PATCH] refactor the search hbs --- assets/shared-bundle.js | 3264 +++++++++++++++-- assets/tailwind-output.css | 30 +- package.json | 1 + rollup.config.mjs | 1 + src/lib/types.ts | 76 +- .../SearchResultPageModule.tsx | 181 + src/modules/search-result-page/index.ts | 1 + .../renderSearchResults.tsx | 18 + templates/document_head.hbs | 1 + templates/header.hbs | 3 +- templates/search_results.hbs | 320 +- yarn.lock | 5 + 12 files changed, 3346 insertions(+), 555 deletions(-) create mode 100644 src/modules/search-result-page/SearchResultPageModule.tsx create mode 100644 src/modules/search-result-page/index.ts create mode 100644 src/modules/search-result-page/renderSearchResults.tsx diff --git a/assets/shared-bundle.js b/assets/shared-bundle.js index 340a96fcc..0332c3ccb 100644 --- a/assets/shared-bundle.js +++ b/assets/shared-bundle.js @@ -3013,7 +3013,7 @@ const htmlEntities = { const unescapeHtmlEntity = m => htmlEntities[m]; const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity); -let defaultOptions$1 = { +let defaultOptions$2 = { bindI18n: 'languageChanged', bindI18nStore: '', transEmptyNodeValue: '', @@ -3025,12 +3025,12 @@ let defaultOptions$1 = { }; const setDefaults = function () { let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - defaultOptions$1 = { - ...defaultOptions$1, + defaultOptions$2 = { + ...defaultOptions$2, ...options }; }; -const getDefaults = () => defaultOptions$1; +const getDefaults = () => defaultOptions$2; let i18nInstance; const setI18n = instance => { @@ -20444,7 +20444,7 @@ var isArguments = isArguments$1; var is = objectIs; var isRegex = isRegex$1; var flags = regexp_prototype_flags; -var isDate$1 = isDateObject; +var isDate$2 = isDateObject; var getTime = Date.prototype.getTime; @@ -20508,7 +20508,7 @@ function objEquiv(a, b, opts) { return a.source === b.source && flags(a) === flags(b); } - if (isDate$1(a) && isDate$1(b)) { + if (isDate$2(a) && isDate$2(b)) { return getTime.call(a) === getTime.call(b); } @@ -21412,7 +21412,7 @@ function find(arr, check) { * @argument value * @returns index or -1 */ -function findIndex$1(arr, prop, value) { +function findIndex$2(arr, prop, value) { // use native findIndex if supported if (Array.prototype.findIndex) { return arr.findIndex(function (cur) { @@ -21438,7 +21438,7 @@ function findIndex$1(arr, prop, value) { * @returns {dataObject} */ function runModifiers(modifiers, data, ends) { - var modifiersToRun = ends === undefined ? modifiers : modifiers.slice(0, findIndex$1(modifiers, 'name', ends)); + var modifiersToRun = ends === undefined ? modifiers : modifiers.slice(0, findIndex$2(modifiers, 'name', ends)); modifiersToRun.forEach(function (modifier) { if (modifier['function']) { @@ -29087,7 +29087,7 @@ function getMenuPosition(popperPlacement) { * const result = toDate(1392098430000) * //=> Tue Feb 11 2014 11:30:30 */ -function toDate(argument) { +function toDate$1(argument) { const argStr = Object.prototype.toString.call(argument); // Clone the date @@ -29132,7 +29132,7 @@ function toDate(argument) { * //=> Mon Sep 01 2014 00:00:00 */ function startOfMonth(date) { - const _date = toDate(date); + const _date = toDate$1(date); _date.setDate(1); _date.setHours(0, 0, 0, 0); return _date; @@ -29159,17 +29159,17 @@ function startOfMonth(date) { * //=> Tue Sep 30 2014 23:59:59.999 */ function endOfMonth(date) { - const _date = toDate(date); + const _date = toDate$1(date); const month = _date.getMonth(); _date.setFullYear(_date.getFullYear(), month + 1, 0); _date.setHours(23, 59, 59, 999); return _date; } -let defaultOptions = {}; +let defaultOptions$1 = {}; -function getDefaultOptions$1() { - return defaultOptions; +function getDefaultOptions$2() { + return defaultOptions$1; } /** @@ -29202,8 +29202,8 @@ function getDefaultOptions$1() { * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 }) * //=> Mon Sep 01 2014 00:00:00 */ -function startOfWeek(date, options) { - const defaultOptions = getDefaultOptions$1(); +function startOfWeek$1(date, options) { + const defaultOptions = getDefaultOptions$2(); const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? @@ -29211,7 +29211,7 @@ function startOfWeek(date, options) { defaultOptions.locale?.options?.weekStartsOn ?? 0; - const _date = toDate(date); + const _date = toDate$1(date); const day = _date.getDay(); const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn; @@ -29251,7 +29251,7 @@ function startOfWeek(date, options) { * //=> Sun Sep 07 2014 23:59:59.999 */ function endOfWeek(date, options) { - const defaultOptions = getDefaultOptions$1(); + const defaultOptions = getDefaultOptions$2(); const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? @@ -29259,7 +29259,7 @@ function endOfWeek(date, options) { defaultOptions.locale?.options?.weekStartsOn ?? 0; - const _date = toDate(date); + const _date = toDate$1(date); const day = _date.getDay(); const diff = (day < weekStartsOn ? -7 : 0) + 6 - (day - weekStartsOn); @@ -29302,8 +29302,8 @@ function endOfWeek(date, options) { * // ] */ function eachDayOfInterval(interval, options) { - const startDate = toDate(interval.start); - const endDate = toDate(interval.end); + const startDate = toDate$1(interval.start); + const endDate = toDate$1(interval.end); let reversed = +startDate > +endDate; const endTime = reversed ? +startDate : +endDate; @@ -29320,7 +29320,7 @@ function eachDayOfInterval(interval, options) { const dates = []; while (+currentDate <= endTime) { - dates.push(toDate(currentDate)); + dates.push(toDate$1(currentDate)); currentDate.setDate(currentDate.getDate() + step); currentDate.setHours(0, 0, 0, 0); } @@ -29358,7 +29358,7 @@ function eachDayOfInterval(interval, options) { * ) * } */ -function constructFrom(date, value) { +function constructFrom$1(date, value) { if (date instanceof Date) { return new date.constructor(value); } else { @@ -29387,8 +29387,8 @@ function constructFrom(date, value) { * //=> Thu Sep 11 2014 00:00:00 */ function addDays(date, amount) { - const _date = toDate(date); - if (isNaN(amount)) return constructFrom(date, NaN); + const _date = toDate$1(date); + if (isNaN(amount)) return constructFrom$1(date, NaN); if (!amount) { // If 0 days, no-op to avoid changing times in the hour before end of DST return _date; @@ -29428,7 +29428,7 @@ function addDays(date, amount) { * } */ function constructNow(date) { - return constructFrom(date, Date.now()); + return constructFrom$1(date, Date.now()); } /** @@ -29451,8 +29451,8 @@ function constructNow(date) { * const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0)) * //=> Tue Sep 02 2014 00:00:00 */ -function startOfDay(date) { - const _date = toDate(date); +function startOfDay$1(date) { + const _date = toDate$1(date); _date.setHours(0, 0, 0, 0); return _date; } @@ -29488,8 +29488,8 @@ function startOfDay(date) { * //=> false */ function isSameDay(dateLeft, dateRight) { - const dateLeftStartOfDay = startOfDay(dateLeft); - const dateRightStartOfDay = startOfDay(dateRight); + const dateLeftStartOfDay = startOfDay$1(dateLeft); + const dateRightStartOfDay = startOfDay$1(dateRight); return +dateLeftStartOfDay === +dateRightStartOfDay; } @@ -29544,8 +29544,8 @@ function isToday(date) { * //=> false */ function isSameMonth(dateLeft, dateRight) { - const _dateLeft = toDate(dateLeft); - const _dateRight = toDate(dateRight); + const _dateLeft = toDate$1(dateLeft); + const _dateRight = toDate$1(dateRight); return ( _dateLeft.getFullYear() === _dateRight.getFullYear() && _dateLeft.getMonth() === _dateRight.getMonth() @@ -29573,8 +29573,8 @@ function isSameMonth(dateLeft, dateRight) { * //=> false */ function isBefore(date, dateToCompare) { - const _date = toDate(date); - const _dateToCompare = toDate(dateToCompare); + const _date = toDate$1(date); + const _dateToCompare = toDate$1(dateToCompare); return +_date < +_dateToCompare; } @@ -29599,8 +29599,8 @@ function isBefore(date, dateToCompare) { * //=> true */ function isAfter(date, dateToCompare) { - const _date = toDate(date); - const _dateToCompare = toDate(dateToCompare); + const _date = toDate$1(date); + const _dateToCompare = toDate$1(dateToCompare); return _date.getTime() > _dateToCompare.getTime(); } @@ -29624,7 +29624,7 @@ function isAfter(date, dateToCompare) { * //=> 29 */ function getDate(date) { - const _date = toDate(date); + const _date = toDate$1(date); const dayOfMonth = _date.getDate(); return dayOfMonth; } @@ -30102,7 +30102,7 @@ const Calendar = reactExports.forwardRef((_ref, ref) => { const preferredWeekStartsOn = weekStartsOn || getStartOfWeek(locale); const monthStartDate = startOfMonth(state.previewDate); const monthEndDate = endOfMonth(monthStartDate); - const startDate = startOfWeek(monthStartDate, { + const startDate = startOfWeek$1(monthStartDate, { weekStartsOn: preferredWeekStartsOn }); const endDate = endOfWeek(monthEndDate, { @@ -30200,8 +30200,8 @@ Calendar.displayName = 'Calendar'; * //=> Tue Feb 28 2023 00:00:00 */ function addMonths(date, amount) { - const _date = toDate(date); - if (isNaN(amount)) return constructFrom(date, NaN); + const _date = toDate$1(date); + if (isNaN(amount)) return constructFrom$1(date, NaN); if (!amount) { // If 0 months, no-op to avoid changing times in the hour before end of DST return _date; @@ -30216,7 +30216,7 @@ function addMonths(date, amount) { // we'll default to the end of the desired month by adding 1 to the desired // month and using a date of 0 to back up one day to the end of the desired // month. - const endOfDesiredMonth = constructFrom(date, _date.getTime()); + const endOfDesiredMonth = constructFrom$1(date, _date.getTime()); endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0); const daysInMonth = endOfDesiredMonth.getDate(); if (dayOfMonth >= daysInMonth) { @@ -30296,7 +30296,7 @@ function subMonths(date, amount) { * const result = isDate({}) * //=> false */ -function isDate(value) { +function isDate$1(value) { return ( value instanceof Date || (typeof value === "object" && @@ -30337,11 +30337,11 @@ function isDate(value) { * const result = isValid(new Date('')) * //=> false */ -function isValid(date) { - if (!isDate(date) && typeof date !== "number") { +function isValid$1(date) { + if (!isDate$1(date) && typeof date !== "number") { return false; } - const _date = toDate(date); + const _date = toDate$1(date); return !isNaN(Number(_date)); } @@ -30369,11 +30369,11 @@ function isValid(date) { * const result = getDefaultOptions() * //=> { weekStarsOn: 1, firstWeekContainsDate: 4 } */ -function getDefaultOptions() { - return Object.assign({}, getDefaultOptions$1()); +function getDefaultOptions$1() { + return Object.assign({}, getDefaultOptions$2()); } -const formatDistanceLocale = { +const formatDistanceLocale$1 = { lessThanXSeconds: { one: "less than a second", other: "less than {{count}} seconds", @@ -30452,10 +30452,10 @@ const formatDistanceLocale = { }, }; -const formatDistance = (token, count, options) => { +const formatDistance$1 = (token, count, options) => { let result; - const tokenValue = formatDistanceLocale[token]; + const tokenValue = formatDistanceLocale$1[token]; if (typeof tokenValue === "string") { result = tokenValue; } else if (count === 1) { @@ -30475,7 +30475,7 @@ const formatDistance = (token, count, options) => { return result; }; -function buildFormatLongFn(args) { +function buildFormatLongFn$1(args) { return (options = {}) => { // TODO: Remove String() const width = options.width ? String(options.width) : args.defaultWidth; @@ -30484,45 +30484,45 @@ function buildFormatLongFn(args) { }; } -const dateFormats = { +const dateFormats$1 = { full: "EEEE, MMMM do, y", long: "MMMM do, y", medium: "MMM d, y", short: "MM/dd/yyyy", }; -const timeFormats = { +const timeFormats$1 = { full: "h:mm:ss a zzzz", long: "h:mm:ss a z", medium: "h:mm:ss a", short: "h:mm a", }; -const dateTimeFormats = { +const dateTimeFormats$1 = { full: "{{date}} 'at' {{time}}", long: "{{date}} 'at' {{time}}", medium: "{{date}}, {{time}}", short: "{{date}}, {{time}}", }; -const formatLong = { - date: buildFormatLongFn({ - formats: dateFormats, +const formatLong$1 = { + date: buildFormatLongFn$1({ + formats: dateFormats$1, defaultWidth: "full", }), - time: buildFormatLongFn({ - formats: timeFormats, + time: buildFormatLongFn$1({ + formats: timeFormats$1, defaultWidth: "full", }), - dateTime: buildFormatLongFn({ - formats: dateTimeFormats, + dateTime: buildFormatLongFn$1({ + formats: dateTimeFormats$1, defaultWidth: "full", }), }; -const formatRelativeLocale = { +const formatRelativeLocale$1 = { lastWeek: "'last' eeee 'at' p", yesterday: "'yesterday at' p", today: "'today at' p", @@ -30531,8 +30531,8 @@ const formatRelativeLocale = { other: "P", }; -const formatRelative = (token, _date, _baseDate, _options) => - formatRelativeLocale[token]; +const formatRelative$1 = (token, _date, _baseDate, _options) => + formatRelativeLocale$1[token]; /* eslint-disable no-unused-vars */ @@ -30575,7 +30575,7 @@ const formatRelative = (token, _date, _baseDate, _options) => * The tuple of localized month values. The first element represents January. */ -function buildLocalizeFn(args) { +function buildLocalizeFn$1(args) { return (value, options) => { const context = options?.context ? String(options.context) : "standalone"; @@ -30599,13 +30599,13 @@ function buildLocalizeFn(args) { }; } -const eraValues = { +const eraValues$1 = { narrow: ["B", "A"], abbreviated: ["BC", "AD"], wide: ["Before Christ", "Anno Domini"], }; -const quarterValues = { +const quarterValues$1 = { narrow: ["1", "2", "3", "4"], abbreviated: ["Q1", "Q2", "Q3", "Q4"], wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"], @@ -30615,7 +30615,7 @@ const quarterValues = { // If you are making a new locale based on this one, check if the same is true for the language you're working on. // Generally, formatted dates should look like they are in the middle of a sentence, // e.g. in Spanish language the weekdays and months should be in the lowercase. -const monthValues = { +const monthValues$1 = { narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"], abbreviated: [ "Jan", @@ -30648,7 +30648,7 @@ const monthValues = { ], }; -const dayValues = { +const dayValues$1 = { narrow: ["S", "M", "T", "W", "T", "F", "S"], short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], @@ -30663,7 +30663,7 @@ const dayValues = { ], }; -const dayPeriodValues = { +const dayPeriodValues$1 = { narrow: { am: "a", pm: "p", @@ -30696,7 +30696,7 @@ const dayPeriodValues = { }, }; -const formattingDayPeriodValues = { +const formattingDayPeriodValues$1 = { narrow: { am: "a", pm: "p", @@ -30729,7 +30729,7 @@ const formattingDayPeriodValues = { }, }; -const ordinalNumber = (dirtyNumber, _options) => { +const ordinalNumber$1 = (dirtyNumber, _options) => { const number = Number(dirtyNumber); // If ordinal numbers depend on context, for example, @@ -30753,39 +30753,39 @@ const ordinalNumber = (dirtyNumber, _options) => { return number + "th"; }; -const localize = { - ordinalNumber, +const localize$1 = { + ordinalNumber: ordinalNumber$1, - era: buildLocalizeFn({ - values: eraValues, + era: buildLocalizeFn$1({ + values: eraValues$1, defaultWidth: "wide", }), - quarter: buildLocalizeFn({ - values: quarterValues, + quarter: buildLocalizeFn$1({ + values: quarterValues$1, defaultWidth: "wide", argumentCallback: (quarter) => quarter - 1, }), - month: buildLocalizeFn({ - values: monthValues, + month: buildLocalizeFn$1({ + values: monthValues$1, defaultWidth: "wide", }), - day: buildLocalizeFn({ - values: dayValues, + day: buildLocalizeFn$1({ + values: dayValues$1, defaultWidth: "wide", }), - dayPeriod: buildLocalizeFn({ - values: dayPeriodValues, + dayPeriod: buildLocalizeFn$1({ + values: dayPeriodValues$1, defaultWidth: "wide", - formattingValues: formattingDayPeriodValues, + formattingValues: formattingDayPeriodValues$1, defaultFormattingWidth: "wide", }), }; -function buildMatchFn(args) { +function buildMatchFn$1(args) { return (string, options = {}) => { const width = options.width; @@ -30804,9 +30804,9 @@ function buildMatchFn(args) { args.parsePatterns[args.defaultParseWidth]; const key = Array.isArray(parsePatterns) - ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString)) + ? findIndex$1(parsePatterns, (pattern) => pattern.test(matchedString)) : // eslint-disable-next-line @typescript-eslint/no-explicit-any -- I challange you to fix the type - findKey(parsePatterns, (pattern) => pattern.test(matchedString)); + findKey$1(parsePatterns, (pattern) => pattern.test(matchedString)); let value; @@ -30822,7 +30822,7 @@ function buildMatchFn(args) { }; } -function findKey(object, predicate) { +function findKey$1(object, predicate) { for (const key in object) { if ( Object.prototype.hasOwnProperty.call(object, key) && @@ -30834,7 +30834,7 @@ function findKey(object, predicate) { return undefined; } -function findIndex(array, predicate) { +function findIndex$1(array, predicate) { for (let key = 0; key < array.length; key++) { if (predicate(array[key])) { return key; @@ -30843,7 +30843,7 @@ function findIndex(array, predicate) { return undefined; } -function buildMatchPatternFn(args) { +function buildMatchPatternFn$1(args) { return (string, options = {}) => { const matchResult = string.match(args.matchPattern); if (!matchResult) return null; @@ -30864,33 +30864,33 @@ function buildMatchPatternFn(args) { }; } -const matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i; -const parseOrdinalNumberPattern = /\d+/i; +const matchOrdinalNumberPattern$1 = /^(\d+)(th|st|nd|rd)?/i; +const parseOrdinalNumberPattern$1 = /\d+/i; -const matchEraPatterns = { +const matchEraPatterns$1 = { narrow: /^(b|a)/i, abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i, wide: /^(before christ|before common era|anno domini|common era)/i, }; -const parseEraPatterns = { +const parseEraPatterns$1 = { any: [/^b/i, /^(a|c)/i], }; -const matchQuarterPatterns = { +const matchQuarterPatterns$1 = { narrow: /^[1234]/i, abbreviated: /^q[1234]/i, wide: /^[1234](th|st|nd|rd)? quarter/i, }; -const parseQuarterPatterns = { +const parseQuarterPatterns$1 = { any: [/1/i, /2/i, /3/i, /4/i], }; -const matchMonthPatterns = { +const matchMonthPatterns$1 = { narrow: /^[jfmasond]/i, abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i, wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i, }; -const parseMonthPatterns = { +const parseMonthPatterns$1 = { narrow: [ /^j/i, /^f/i, @@ -30922,22 +30922,22 @@ const parseMonthPatterns = { ], }; -const matchDayPatterns = { +const matchDayPatterns$1 = { narrow: /^[smtwf]/i, short: /^(su|mo|tu|we|th|fr|sa)/i, abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i, wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i, }; -const parseDayPatterns = { +const parseDayPatterns$1 = { narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i], any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i], }; -const matchDayPeriodPatterns = { +const matchDayPeriodPatterns$1 = { narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i, any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i, }; -const parseDayPeriodPatterns = { +const parseDayPeriodPatterns$1 = { any: { am: /^a/i, pm: /^p/i, @@ -30950,46 +30950,46 @@ const parseDayPeriodPatterns = { }, }; -const match = { - ordinalNumber: buildMatchPatternFn({ - matchPattern: matchOrdinalNumberPattern, - parsePattern: parseOrdinalNumberPattern, +const match$1 = { + ordinalNumber: buildMatchPatternFn$1({ + matchPattern: matchOrdinalNumberPattern$1, + parsePattern: parseOrdinalNumberPattern$1, valueCallback: (value) => parseInt(value, 10), }), - era: buildMatchFn({ - matchPatterns: matchEraPatterns, + era: buildMatchFn$1({ + matchPatterns: matchEraPatterns$1, defaultMatchWidth: "wide", - parsePatterns: parseEraPatterns, + parsePatterns: parseEraPatterns$1, defaultParseWidth: "any", }), - quarter: buildMatchFn({ - matchPatterns: matchQuarterPatterns, + quarter: buildMatchFn$1({ + matchPatterns: matchQuarterPatterns$1, defaultMatchWidth: "wide", - parsePatterns: parseQuarterPatterns, + parsePatterns: parseQuarterPatterns$1, defaultParseWidth: "any", valueCallback: (index) => index + 1, }), - month: buildMatchFn({ - matchPatterns: matchMonthPatterns, + month: buildMatchFn$1({ + matchPatterns: matchMonthPatterns$1, defaultMatchWidth: "wide", - parsePatterns: parseMonthPatterns, + parsePatterns: parseMonthPatterns$1, defaultParseWidth: "any", }), - day: buildMatchFn({ - matchPatterns: matchDayPatterns, + day: buildMatchFn$1({ + matchPatterns: matchDayPatterns$1, defaultMatchWidth: "wide", - parsePatterns: parseDayPatterns, + parsePatterns: parseDayPatterns$1, defaultParseWidth: "any", }), - dayPeriod: buildMatchFn({ - matchPatterns: matchDayPeriodPatterns, + dayPeriod: buildMatchFn$1({ + matchPatterns: matchDayPeriodPatterns$1, defaultMatchWidth: "any", - parsePatterns: parseDayPeriodPatterns, + parsePatterns: parseDayPeriodPatterns$1, defaultParseWidth: "any", }), }; @@ -31002,20 +31002,20 @@ const match = { * @author Sasha Koss [@kossnocorp](https://github.com/kossnocorp) * @author Lesha Koss [@leshakoss](https://github.com/leshakoss) */ -const enUS = { +const enUS$1 = { code: "en-US", - formatDistance: formatDistance, - formatLong: formatLong, - formatRelative: formatRelative, - localize: localize, - match: match, + formatDistance: formatDistance$1, + formatLong: formatLong$1, + formatRelative: formatRelative$1, + localize: localize$1, + match: match$1, options: { weekStartsOn: 0 /* Sunday */, firstWeekContainsDate: 1, }, }; -const dateLongFormatter = (pattern, formatLong) => { +const dateLongFormatter$1 = (pattern, formatLong) => { switch (pattern) { case "P": return formatLong.date({ width: "short" }); @@ -31029,7 +31029,7 @@ const dateLongFormatter = (pattern, formatLong) => { } }; -const timeLongFormatter = (pattern, formatLong) => { +const timeLongFormatter$1 = (pattern, formatLong) => { switch (pattern) { case "p": return formatLong.time({ width: "short" }); @@ -31043,13 +31043,13 @@ const timeLongFormatter = (pattern, formatLong) => { } }; -const dateTimeLongFormatter = (pattern, formatLong) => { +const dateTimeLongFormatter$1 = (pattern, formatLong) => { const matchResult = pattern.match(/(P+)(p+)?/) || []; const datePattern = matchResult[1]; const timePattern = matchResult[2]; if (!timePattern) { - return dateLongFormatter(pattern, formatLong); + return dateLongFormatter$1(pattern, formatLong); } let dateTimeFormat; @@ -31071,35 +31071,35 @@ const dateTimeLongFormatter = (pattern, formatLong) => { } return dateTimeFormat - .replace("{{date}}", dateLongFormatter(datePattern, formatLong)) - .replace("{{time}}", timeLongFormatter(timePattern, formatLong)); + .replace("{{date}}", dateLongFormatter$1(datePattern, formatLong)) + .replace("{{time}}", timeLongFormatter$1(timePattern, formatLong)); }; -const longFormatters = { - p: timeLongFormatter, - P: dateTimeLongFormatter, +const longFormatters$1 = { + p: timeLongFormatter$1, + P: dateTimeLongFormatter$1, }; -const dayOfYearTokenRE = /^D+$/; -const weekYearTokenRE = /^Y+$/; +const dayOfYearTokenRE$1 = /^D+$/; +const weekYearTokenRE$1 = /^Y+$/; -const throwTokens = ["D", "DD", "YY", "YYYY"]; +const throwTokens$1 = ["D", "DD", "YY", "YYYY"]; -function isProtectedDayOfYearToken(token) { - return dayOfYearTokenRE.test(token); +function isProtectedDayOfYearToken$1(token) { + return dayOfYearTokenRE$1.test(token); } -function isProtectedWeekYearToken(token) { - return weekYearTokenRE.test(token); +function isProtectedWeekYearToken$1(token) { + return weekYearTokenRE$1.test(token); } -function warnOrThrowProtectedError(token, format, input) { - const _message = message(token, format, input); +function warnOrThrowProtectedError$1(token, format, input) { + const _message = message$1(token, format, input); console.warn(_message); - if (throwTokens.includes(token)) throw new RangeError(_message); + if (throwTokens$1.includes(token)) throw new RangeError(_message); } -function message(token, format, input) { +function message$1(token, format, input) { const subject = token[0] === "Y" ? "years" : "days of the month"; return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`; } @@ -31135,7 +31135,7 @@ function message(token, format, input) { function transpose(fromDate, constructor) { const date = constructor instanceof Date - ? constructFrom(constructor, 0) + ? constructFrom$1(constructor, 0) : new constructor(0); date.setFullYear( fromDate.getFullYear(), @@ -31196,7 +31196,7 @@ class DateToSystemTimezoneSetter extends Setter { subPriority = -1; set(date, flags) { if (flags.timestampIsSet) return date; - return constructFrom(date, transpose(date, Date)); + return constructFrom$1(date, transpose(date, Date)); } } @@ -31284,7 +31284,7 @@ class EraParser extends Parser { * @name millisecondsInWeek * @summary Milliseconds in 1 week. */ -const millisecondsInWeek = 604800000; +const millisecondsInWeek$1 = 604800000; /** * @constant @@ -31568,11 +31568,11 @@ class YearParser extends Parser { * const result = getWeekYear(new Date(2004, 11, 26), { firstWeekContainsDate: 4 }) * //=> 2004 */ -function getWeekYear(date, options) { - const _date = toDate(date); +function getWeekYear$1(date, options) { + const _date = toDate$1(date); const year = _date.getFullYear(); - const defaultOptions = getDefaultOptions$1(); + const defaultOptions = getDefaultOptions$2(); const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? @@ -31580,15 +31580,15 @@ function getWeekYear(date, options) { defaultOptions.locale?.options?.firstWeekContainsDate ?? 1; - const firstWeekOfNextYear = constructFrom(date, 0); + const firstWeekOfNextYear = constructFrom$1(date, 0); firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate); firstWeekOfNextYear.setHours(0, 0, 0, 0); - const startOfNextYear = startOfWeek(firstWeekOfNextYear, options); + const startOfNextYear = startOfWeek$1(firstWeekOfNextYear, options); - const firstWeekOfThisYear = constructFrom(date, 0); + const firstWeekOfThisYear = constructFrom$1(date, 0); firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate); firstWeekOfThisYear.setHours(0, 0, 0, 0); - const startOfThisYear = startOfWeek(firstWeekOfThisYear, options); + const startOfThisYear = startOfWeek$1(firstWeekOfThisYear, options); if (_date.getTime() >= startOfNextYear.getTime()) { return year + 1; @@ -31629,7 +31629,7 @@ class LocalWeekYearParser extends Parser { } set(date, flags, value, options) { - const currentYear = getWeekYear(date, options); + const currentYear = getWeekYear$1(date, options); if (value.isTwoDigitYear) { const normalizedTwoDigitYear = normalizeTwoDigitYear( @@ -31642,14 +31642,14 @@ class LocalWeekYearParser extends Parser { options.firstWeekContainsDate, ); date.setHours(0, 0, 0, 0); - return startOfWeek(date, options); + return startOfWeek$1(date, options); } const year = !("era" in flags) || flags.era === 1 ? value.year : 1 - value.year; date.setFullYear(year, 0, options.firstWeekContainsDate); date.setHours(0, 0, 0, 0); - return startOfWeek(date, options); + return startOfWeek$1(date, options); } incompatibleTokens = [ @@ -31691,8 +31691,8 @@ class LocalWeekYearParser extends Parser { * const result = startOfISOWeek(new Date(2014, 8, 2, 11, 55, 0)) * //=> Mon Sep 01 2014 00:00:00 */ -function startOfISOWeek(date) { - return startOfWeek(date, { weekStartsOn: 1 }); +function startOfISOWeek$1(date) { + return startOfWeek$1(date, { weekStartsOn: 1 }); } // ISO week-numbering year @@ -31708,10 +31708,10 @@ class ISOWeekYearParser extends Parser { } set(date, _flags, value) { - const firstWeekOfYear = constructFrom(date, 0); + const firstWeekOfYear = constructFrom$1(date, 0); firstWeekOfYear.setFullYear(value, 0, 4); firstWeekOfYear.setHours(0, 0, 0, 0); - return startOfISOWeek(firstWeekOfYear); + return startOfISOWeek$1(firstWeekOfYear); } incompatibleTokens = [ @@ -32113,8 +32113,8 @@ class StandAloneMonthParser extends Parser { * }) * //=> Mon Jan 03 2005 00:00:00 */ -function startOfWeekYear(date, options) { - const defaultOptions = getDefaultOptions$1(); +function startOfWeekYear$1(date, options) { + const defaultOptions = getDefaultOptions$2(); const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? @@ -32122,11 +32122,11 @@ function startOfWeekYear(date, options) { defaultOptions.locale?.options?.firstWeekContainsDate ?? 1; - const year = getWeekYear(date, options); - const firstWeek = constructFrom(date, 0); + const year = getWeekYear$1(date, options); + const firstWeek = constructFrom$1(date, 0); firstWeek.setFullYear(year, 0, firstWeekContainsDate); firstWeek.setHours(0, 0, 0, 0); - const _date = startOfWeek(firstWeek, options); + const _date = startOfWeek$1(firstWeek, options); return _date; } @@ -32171,14 +32171,14 @@ function startOfWeekYear(date, options) { * //=> 53 */ -function getWeek(date, options) { - const _date = toDate(date); - const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options); +function getWeek$1(date, options) { + const _date = toDate$1(date); + const diff = +startOfWeek$1(_date, options) - +startOfWeekYear$1(_date, options); // Round the number of weeks to the nearest integer because the number of // milliseconds in a week is not constant (e.g. it's different in the week of // the daylight saving time clock shift). - return Math.round(diff / millisecondsInWeek) + 1; + return Math.round(diff / millisecondsInWeek$1) + 1; } /** @@ -32223,8 +32223,8 @@ function getWeek(date, options) { * //=> Sun Jan 4 2004 00:00:00 */ function setWeek(date, week, options) { - const _date = toDate(date); - const diff = getWeek(_date, options) - week; + const _date = toDate$1(date); + const diff = getWeek$1(_date, options) - week; _date.setDate(_date.getDate() - diff * 7); return _date; } @@ -32249,7 +32249,7 @@ class LocalWeekParser extends Parser { } set(date, _flags, value, options) { - return startOfWeek(setWeek(date, value, options), options); + return startOfWeek$1(setWeek(date, value, options), options); } incompatibleTokens = [ @@ -32291,19 +32291,19 @@ class LocalWeekParser extends Parser { * const result = getISOWeekYear(new Date(2005, 0, 2)) * //=> 2004 */ -function getISOWeekYear(date) { - const _date = toDate(date); +function getISOWeekYear$1(date) { + const _date = toDate$1(date); const year = _date.getFullYear(); - const fourthOfJanuaryOfNextYear = constructFrom(date, 0); + const fourthOfJanuaryOfNextYear = constructFrom$1(date, 0); fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4); fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0); - const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear); + const startOfNextYear = startOfISOWeek$1(fourthOfJanuaryOfNextYear); - const fourthOfJanuaryOfThisYear = constructFrom(date, 0); + const fourthOfJanuaryOfThisYear = constructFrom$1(date, 0); fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4); fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0); - const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear); + const startOfThisYear = startOfISOWeek$1(fourthOfJanuaryOfThisYear); if (_date.getTime() >= startOfNextYear.getTime()) { return year + 1; @@ -32337,12 +32337,12 @@ function getISOWeekYear(date) { * const result = startOfISOWeekYear(new Date(2005, 6, 2)) * //=> Mon Jan 03 2005 00:00:00 */ -function startOfISOWeekYear(date) { - const year = getISOWeekYear(date); - const fourthOfJanuary = constructFrom(date, 0); +function startOfISOWeekYear$1(date) { + const year = getISOWeekYear$1(date); + const fourthOfJanuary = constructFrom$1(date, 0); fourthOfJanuary.setFullYear(year, 0, 4); fourthOfJanuary.setHours(0, 0, 0, 0); - return startOfISOWeek(fourthOfJanuary); + return startOfISOWeek$1(fourthOfJanuary); } /** @@ -32366,14 +32366,14 @@ function startOfISOWeekYear(date) { * const result = getISOWeek(new Date(2005, 0, 2)) * //=> 53 */ -function getISOWeek(date) { - const _date = toDate(date); - const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date); +function getISOWeek$1(date) { + const _date = toDate$1(date); + const diff = +startOfISOWeek$1(_date) - +startOfISOWeekYear$1(_date); // Round the number of weeks to the nearest integer because the number of // milliseconds in a week is not constant (e.g. it's different in the week of // the daylight saving time clock shift). - return Math.round(diff / millisecondsInWeek) + 1; + return Math.round(diff / millisecondsInWeek$1) + 1; } /** @@ -32399,8 +32399,8 @@ function getISOWeek(date) { * //=> Sat Jan 01 2005 00:00:00 */ function setISOWeek(date, week) { - const _date = toDate(date); - const diff = getISOWeek(_date) - week; + const _date = toDate$1(date); + const diff = getISOWeek$1(_date) - week; _date.setDate(_date.getDate() - diff * 7); return _date; } @@ -32425,7 +32425,7 @@ class ISOWeekParser extends Parser { } set(date, _flags, value) { - return startOfISOWeek(setISOWeek(date, value)); + return startOfISOWeek$1(setISOWeek(date, value)); } incompatibleTokens = [ @@ -32583,7 +32583,7 @@ class DayOfYearParser extends Parser { * //=> Sun Sep 07 2014 00:00:00 */ function setDay(date, day, options) { - const defaultOptions = getDefaultOptions$1(); + const defaultOptions = getDefaultOptions$2(); const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? @@ -32591,7 +32591,7 @@ function setDay(date, day, options) { defaultOptions.locale?.options?.weekStartsOn ?? 0; - const _date = toDate(date); + const _date = toDate$1(date); const currentDay = _date.getDay(); const remainder = day % 7; @@ -32871,7 +32871,7 @@ class StandAloneLocalDayParser extends Parser { * //=> 7 */ function getISODay(date) { - const _date = toDate(date); + const _date = toDate$1(date); let day = _date.getDay(); if (day === 0) { @@ -32904,7 +32904,7 @@ function getISODay(date) { * //=> Sun Sep 07 2014 00:00:00 */ function setISODay(date, day) { - const _date = toDate(date); + const _date = toDate$1(date); const currentDay = getISODay(_date); const diff = day - currentDay; return addDays(_date, diff); @@ -33374,8 +33374,8 @@ class FractionOfSecondParser extends Parser { * * This function returns the timezone offset in milliseconds that takes seconds in account. */ -function getTimezoneOffsetInMilliseconds(date) { - const _date = toDate(date); +function getTimezoneOffsetInMilliseconds$1(date) { + const _date = toDate$1(date); const utcDate = new Date( Date.UTC( _date.getFullYear(), @@ -33422,9 +33422,9 @@ class ISOTimezoneWithZParser extends Parser { set(date, flags, value) { if (flags.timestampIsSet) return date; - return constructFrom( + return constructFrom$1( date, - date.getTime() - getTimezoneOffsetInMilliseconds(date) - value, + date.getTime() - getTimezoneOffsetInMilliseconds$1(date) - value, ); } @@ -33462,9 +33462,9 @@ class ISOTimezoneParser extends Parser { set(date, flags, value) { if (flags.timestampIsSet) return date; - return constructFrom( + return constructFrom$1( date, - date.getTime() - getTimezoneOffsetInMilliseconds(date) - value, + date.getTime() - getTimezoneOffsetInMilliseconds$1(date) - value, ); } @@ -33479,7 +33479,7 @@ class TimestampSecondsParser extends Parser { } set(date, _flags, value) { - return [constructFrom(date, value * 1000), { timestampIsSet: true }]; + return [constructFrom$1(date, value * 1000), { timestampIsSet: true }]; } incompatibleTokens = "*"; @@ -33493,7 +33493,7 @@ class TimestampMillisecondsParser extends Parser { } set(date, _flags, value) { - return [constructFrom(date, value), { timestampIsSet: true }]; + return [constructFrom$1(date, value), { timestampIsSet: true }]; } incompatibleTokens = "*"; @@ -33592,18 +33592,18 @@ const parsers = { // If there is no matching single quote // then the sequence will continue until the end of the string. // - . matches any single character unmatched by previous parts of the RegExps -const formattingTokensRegExp = +const formattingTokensRegExp$1 = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g; // This RegExp catches symbols escaped by quotes, and also // sequences of symbols P, p, and the combinations like `PPPPPPPppppp` -const longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g; +const longFormattingTokensRegExp$1 = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g; -const escapedStringRegExp = /^'([^]*?)'?$/; -const doubleQuoteRegExp = /''/g; +const escapedStringRegExp$1 = /^'([^]*?)'?$/; +const doubleQuoteRegExp$1 = /''/g; const notWhitespaceRegExp = /\S/; -const unescapedLatinCharacterRegExp = /[a-zA-Z]/; +const unescapedLatinCharacterRegExp$1 = /[a-zA-Z]/; /** * @name parse @@ -33903,8 +33903,8 @@ const unescapedLatinCharacterRegExp = /[a-zA-Z]/; * //=> Sun Feb 28 2010 00:00:00 */ function parse(dateStr, formatStr, referenceDate, options) { - const defaultOptions = getDefaultOptions(); - const locale = options?.locale ?? defaultOptions.locale ?? enUS; + const defaultOptions = getDefaultOptions$1(); + const locale = options?.locale ?? defaultOptions.locale ?? enUS$1; const firstWeekContainsDate = options?.firstWeekContainsDate ?? @@ -33922,9 +33922,9 @@ function parse(dateStr, formatStr, referenceDate, options) { if (formatStr === "") { if (dateStr === "") { - return toDate(referenceDate); + return toDate$1(referenceDate); } else { - return constructFrom(referenceDate, NaN); + return constructFrom$1(referenceDate, NaN); } } @@ -33938,32 +33938,32 @@ function parse(dateStr, formatStr, referenceDate, options) { const setters = [new DateToSystemTimezoneSetter()]; const tokens = formatStr - .match(longFormattingTokensRegExp) + .match(longFormattingTokensRegExp$1) .map((substring) => { const firstCharacter = substring[0]; - if (firstCharacter in longFormatters) { - const longFormatter = longFormatters[firstCharacter]; + if (firstCharacter in longFormatters$1) { + const longFormatter = longFormatters$1[firstCharacter]; return longFormatter(substring, locale.formatLong); } return substring; }) .join("") - .match(formattingTokensRegExp); + .match(formattingTokensRegExp$1); const usedTokens = []; for (let token of tokens) { if ( !options?.useAdditionalWeekYearTokens && - isProtectedWeekYearToken(token) + isProtectedWeekYearToken$1(token) ) { - warnOrThrowProtectedError(token, formatStr, dateStr); + warnOrThrowProtectedError$1(token, formatStr, dateStr); } if ( !options?.useAdditionalDayOfYearTokens && - isProtectedDayOfYearToken(token) + isProtectedDayOfYearToken$1(token) ) { - warnOrThrowProtectedError(token, formatStr, dateStr); + warnOrThrowProtectedError$1(token, formatStr, dateStr); } const firstCharacter = token[0]; @@ -33997,14 +33997,14 @@ function parse(dateStr, formatStr, referenceDate, options) { ); if (!parseResult) { - return constructFrom(referenceDate, NaN); + return constructFrom$1(referenceDate, NaN); } setters.push(parseResult.setter); dateStr = parseResult.rest; } else { - if (firstCharacter.match(unescapedLatinCharacterRegExp)) { + if (firstCharacter.match(unescapedLatinCharacterRegExp$1)) { throw new RangeError( "Format string contains an unescaped latin alphabet character `" + firstCharacter + @@ -34016,21 +34016,21 @@ function parse(dateStr, formatStr, referenceDate, options) { if (token === "''") { token = "'"; } else if (firstCharacter === "'") { - token = cleanEscapedString(token); + token = cleanEscapedString$1(token); } // Cut token from string, or, if string doesn't match the token, return Invalid Date if (dateStr.indexOf(token) === 0) { dateStr = dateStr.slice(token.length); } else { - return constructFrom(referenceDate, NaN); + return constructFrom$1(referenceDate, NaN); } } } // Check if the remaining input contains something other than whitespace if (dateStr.length > 0 && notWhitespaceRegExp.test(dateStr)) { - return constructFrom(referenceDate, NaN); + return constructFrom$1(referenceDate, NaN); } const uniquePrioritySetters = setters @@ -34044,16 +34044,16 @@ function parse(dateStr, formatStr, referenceDate, options) { ) .map((setterArray) => setterArray[0]); - let date = toDate(referenceDate); + let date = toDate$1(referenceDate); if (isNaN(date.getTime())) { - return constructFrom(referenceDate, NaN); + return constructFrom$1(referenceDate, NaN); } const flags = {}; for (const setter of uniquePrioritySetters) { if (!setter.validate(date, subFnOptions)) { - return constructFrom(referenceDate, NaN); + return constructFrom$1(referenceDate, NaN); } const result = setter.set(date, flags, subFnOptions); @@ -34067,11 +34067,11 @@ function parse(dateStr, formatStr, referenceDate, options) { } } - return constructFrom(referenceDate, date); + return constructFrom$1(referenceDate, date); } -function cleanEscapedString(input) { - return input.match(escapedStringRegExp)[1].replace(doubleQuoteRegExp, "'"); +function cleanEscapedString$1(input) { + return input.match(escapedStringRegExp$1)[1].replace(doubleQuoteRegExp$1, "'"); } /** @@ -34091,15 +34091,15 @@ function parseInputValue(_ref) { } const MINIMUM_DATE = new Date(1001, 0, 0); let tryParseDate = parse(inputValue, 'P', new Date()); - if (isValid(tryParseDate) && !isBefore(tryParseDate, MINIMUM_DATE)) { + if (isValid$1(tryParseDate) && !isBefore(tryParseDate, MINIMUM_DATE)) { return tryParseDate; } tryParseDate = parse(inputValue, 'PP', new Date()); - if (isValid(tryParseDate) && !isBefore(tryParseDate, MINIMUM_DATE)) { + if (isValid$1(tryParseDate) && !isBefore(tryParseDate, MINIMUM_DATE)) { return tryParseDate; } tryParseDate = parse(inputValue, 'PPP', new Date()); - if (isValid(tryParseDate) && !isBefore(tryParseDate, MINIMUM_DATE)) { + if (isValid$1(tryParseDate) && !isBefore(tryParseDate, MINIMUM_DATE)) { return tryParseDate; } return new Date(NaN); @@ -34174,7 +34174,7 @@ const datepickerReducer = _ref3 => { inputValue, customParseDate }); - if (onChange && currentDate && isValid(currentDate) && !isSameDay(value, currentDate)) { + if (onChange && currentDate && isValid$1(currentDate) && !isSameDay(value, currentDate)) { onChange(currentDate); } return { @@ -34216,7 +34216,7 @@ const datepickerReducer = _ref3 => { locale, formatDate }); - if (onChange && action.value && isValid(action.value) && !isSameDay(value, action.value)) { + if (onChange && action.value && isValid$1(action.value) && !isSameDay(value, action.value)) { onChange(action.value); } return { @@ -34232,7 +34232,7 @@ const datepickerReducer = _ref3 => { }; function retrieveInitialState(initialProps) { let previewDate = initialProps.value; - if (previewDate === undefined || !isValid(previewDate)) { + if (previewDate === undefined || !isValid$1(previewDate)) { previewDate = new Date(); } let inputValue = ''; @@ -38055,4 +38055,2786 @@ var Oe=(o=>(o[o.Open=0]="Open",o[o.Closed=1]="Closed",o))(Oe||{}),he=(t=>(t[t.Se let E=reactExports.createContext(null);E.displayName="GroupContext";let De=reactExports.Fragment;function ge(n){var u;let[o,s]=reactExports.useState(null),[h,b]=K(),[T,t]=w$3(),p=reactExports.useMemo(()=>({switch:o,setSwitch:s}),[o,s]),y={},S=n,c=L$1();return U$6.createElement(t,{name:"Switch.Description",value:T},U$6.createElement(b,{name:"Switch.Label",value:h,props:{htmlFor:(u=p.switch)==null?void 0:u.id,onClick(d){o&&(d.currentTarget instanceof HTMLLabelElement&&d.preventDefault(),o.click(),o.focus({preventScroll:!0}));}}},U$6.createElement(E.Provider,{value:p},c({ourProps:y,theirProps:S,slot:{},defaultTag:De,name:"Switch.Group"}))))}let ve="button";function xe(n,o){var L;let s=reactExports.useId(),h=u$4(),b=a$a(),{id:T=h||`headlessui-switch-${s}`,disabled:t=b||!1,checked:p,defaultChecked:y,onChange:S,name:c,value:u,form:d,autoFocus:m=!1,...F}=n,_=reactExports.useContext(E),[H,k]=reactExports.useState(null),M=reactExports.useRef(null),U=y$3(M,o,_===null?null:_.setSwitch,k),l=l$3(y),[a,r]=T$3(p,S,l!=null?l:!1),I=p$3(),[P,D]=reactExports.useState(!1),g=o$3(()=>{D(!0),r==null||r(!a),I.nextFrame(()=>{D(!1);});}),B=o$3(e=>{if(r$2(e.currentTarget))return e.preventDefault();e.preventDefault(),g();}),K=o$3(e=>{e.key===o$1.Space?(e.preventDefault(),g()):e.key===o$1.Enter&&p$2(e.currentTarget);}),W=o$3(e=>e.preventDefault()),O=I$3(),N=U$3(),{isFocusVisible:v,focusProps:J}=$f7dceffc5ad7768b$export$4e328f61c538687f({autoFocus:m}),{isHovered:x,hoverProps:V}=$6179b936705e76d3$export$ae780daf29e6d456({isDisabled:t}),{pressed:C,pressProps:X}=w$4({disabled:t}),j=reactExports.useMemo(()=>({checked:a,disabled:t,hover:x,focus:v,active:C,autofocus:m,changing:P}),[a,x,v,C,t,P,m]),$=_$2({id:T,ref:U,role:"switch",type:e$1(n,H),tabIndex:n.tabIndex===-1?0:(L=n.tabIndex)!=null?L:0,"aria-checked":a,"aria-labelledby":O,"aria-describedby":N,disabled:t||void 0,autoFocus:m,onClick:B,onKeyUp:K,onKeyPress:W},J,V,X),q=reactExports.useCallback(()=>{if(l!==void 0)return r==null?void 0:r(l)},[r,l]),z=L$1();return U$6.createElement(U$6.Fragment,null,c!=null&&U$6.createElement(j$2,{disabled:t,data:{[c]:u||"on"},overrides:{type:"checkbox",checked:a},form:d,onReset:q}),z({ourProps:$,theirProps:F,slot:j,defaultTag:ve,name:"Switch"}))}let Ce=K$1(xe),Le=ge,Re=Q,Ge=H$1,Ye=Object.assign(Ce,{Group:Le,Label:Re,Description:Ge}); -export { Button as $, Anchor as A, SvgAlertWarningStroke as B, Close$4 as C, Datepicker as D, MediaInput as E, Field$1 as F, SvgCreditCardStroke as G, Hint$2 as H, Input as I, getColorV8 as J, KEYS as K, Label$3 as L, Message$2 as M, Notification as N, Option as O, Progress as P, Header$1 as Q, SvgCheckCircleStroke as R, Span as S, Title as T, useModalContainer as U, Modal as V, Body as W, Accordion as X, Paragraph as Y, Footer as Z, FooterItem as _, useTranslation as a, Close as a0, addFlashNotification as a1, debounce$3 as a2, Alert as a3, initI18next as a4, loadTranslations as a5, reactDomExports as a6, ThemeProviders as a7, createTheme as a8, FLASH_NOTIFICATIONS_KEY as a9, api as aa, Ye as ab, cn as ac, yt as ad, je as ae, Textarea as b, commonjsGlobal as c, Field as d, Combobox as e, Message as f, getDefaultExportFromCjs as g, Hint as h, Checkbox as i, jsxRuntimeExports as j, Label$1 as k, OptGroup as l, FileList as m, File as n, Tooltip as o, purify as p, mime as q, reactExports as r, styled as s, useDropzone as t, useToast as u, FileUpload as v, useGrid as w, focusStyles as x, FauxInput as y, Tag as z }; +/** + * @module constants + * @summary Useful constants + * @description + * Collection of useful date constants. + * + * The constants could be imported from `date-fns/constants`: + * + * ```ts + * import { maxTime, minTime } from "./constants/date-fns/constants"; + * + * function isAllowedTime(time) { + * return time <= maxTime && time >= minTime; + * } + * ``` + */ + +/** + * @constant + * @name millisecondsInWeek + * @summary Milliseconds in 1 week. + */ +const millisecondsInWeek = 604800000; + +/** + * @constant + * @name millisecondsInDay + * @summary Milliseconds in 1 day. + */ +const millisecondsInDay = 86400000; + +/** + * @constant + * @name constructFromSymbol + * @summary Symbol enabling Date extensions to inherit properties from the reference date. + * + * The symbol is used to enable the `constructFrom` function to construct a date + * using a reference date and a value. It allows to transfer extra properties + * from the reference date to the new date. It's useful for extensions like + * [`TZDate`](https://github.com/date-fns/tz) that accept a time zone as + * a constructor argument. + */ +const constructFromSymbol = Symbol.for("constructDateFrom"); + +/** + * @name constructFrom + * @category Generic Helpers + * @summary Constructs a date using the reference date and the value + * + * @description + * The function constructs a new date using the constructor from the reference + * date and the given value. It helps to build generic functions that accept + * date extensions. + * + * It defaults to `Date` if the passed reference date is a number or a string. + * + * Starting from v3.7.0, it allows to construct a date using `[Symbol.for("constructDateFrom")]` + * enabling to transfer extra properties from the reference date to the new date. + * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz) + * that accept a time zone as a constructor argument. + * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The reference date to take constructor from + * @param value - The value to create the date + * + * @returns Date initialized using the given date and value + * + * @example + * import { constructFrom } from "./constructFrom/date-fns"; + * + * // A function that clones a date preserving the original type + * function cloneDate(date: DateType): DateType { + * return constructFrom( + * date, // Use constructor from the given date + * date.getTime() // Use the date value to create a new date + * ); + * } + */ +function constructFrom(date, value) { + if (typeof date === "function") return date(value); + + if (date && typeof date === "object" && constructFromSymbol in date) + return date[constructFromSymbol](value); + + if (date instanceof Date) return new date.constructor(value); + + return new Date(value); +} + +/** + * @name toDate + * @category Common Helpers + * @summary Convert the given argument to an instance of Date. + * + * @description + * Convert the given argument to an instance of Date. + * + * If the argument is an instance of Date, the function returns its clone. + * + * If the argument is a number, it is treated as a timestamp. + * + * If the argument is none of the above, the function returns Invalid Date. + * + * Starting from v3.7.0, it clones a date using `[Symbol.for("constructDateFrom")]` + * enabling to transfer extra properties from the reference date to the new date. + * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz) + * that accept a time zone as a constructor argument. + * + * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`. + * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments. + * + * @param argument - The value to convert + * + * @returns The parsed date in the local time zone + * + * @example + * // Clone the date: + * const result = toDate(new Date(2014, 1, 11, 11, 30, 30)) + * //=> Tue Feb 11 2014 11:30:30 + * + * @example + * // Convert the timestamp to date: + * const result = toDate(1392098430000) + * //=> Tue Feb 11 2014 11:30:30 + */ +function toDate(argument, context) { + // [TODO] Get rid of `toDate` or `constructFrom`? + return constructFrom(context || argument, argument); +} + +let defaultOptions = {}; + +function getDefaultOptions() { + return defaultOptions; +} + +/** + * The {@link startOfWeek} function options. + */ + +/** + * @name startOfWeek + * @category Week Helpers + * @summary Return the start of a week for the given date. + * + * @description + * Return the start of a week for the given date. + * The result will be in the local timezone. + * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments. + * + * @param date - The original date + * @param options - An object with options + * + * @returns The start of a week + * + * @example + * // The start of a week for 2 September 2014 11:55:00: + * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0)) + * //=> Sun Aug 31 2014 00:00:00 + * + * @example + * // If the week starts on Monday, the start of the week for 2 September 2014 11:55:00: + * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 }) + * //=> Mon Sep 01 2014 00:00:00 + */ +function startOfWeek(date, options) { + const defaultOptions = getDefaultOptions(); + const weekStartsOn = + options?.weekStartsOn ?? + options?.locale?.options?.weekStartsOn ?? + defaultOptions.weekStartsOn ?? + defaultOptions.locale?.options?.weekStartsOn ?? + 0; + + const _date = toDate(date, options?.in); + const day = _date.getDay(); + const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn; + + _date.setDate(_date.getDate() - diff); + _date.setHours(0, 0, 0, 0); + return _date; +} + +/** + * The {@link startOfISOWeek} function options. + */ + +/** + * @name startOfISOWeek + * @category ISO Week Helpers + * @summary Return the start of an ISO week for the given date. + * + * @description + * Return the start of an ISO week for the given date. + * The result will be in the local timezone. + * + * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date + * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments. + * + * @param date - The original date + * @param options - An object with options + * + * @returns The start of an ISO week + * + * @example + * // The start of an ISO week for 2 September 2014 11:55:00: + * const result = startOfISOWeek(new Date(2014, 8, 2, 11, 55, 0)) + * //=> Mon Sep 01 2014 00:00:00 + */ +function startOfISOWeek(date, options) { + return startOfWeek(date, { ...options, weekStartsOn: 1 }); +} + +/** + * The {@link getISOWeekYear} function options. + */ + +/** + * @name getISOWeekYear + * @category ISO Week-Numbering Year Helpers + * @summary Get the ISO week-numbering year of the given date. + * + * @description + * Get the ISO week-numbering year of the given date, + * which always starts 3 days before the year's first Thursday. + * + * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date + * + * @param date - The given date + * + * @returns The ISO week-numbering year + * + * @example + * // Which ISO-week numbering year is 2 January 2005? + * const result = getISOWeekYear(new Date(2005, 0, 2)) + * //=> 2004 + */ +function getISOWeekYear(date, options) { + const _date = toDate(date, options?.in); + const year = _date.getFullYear(); + + const fourthOfJanuaryOfNextYear = constructFrom(_date, 0); + fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4); + fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0); + const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear); + + const fourthOfJanuaryOfThisYear = constructFrom(_date, 0); + fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4); + fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0); + const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear); + + if (_date.getTime() >= startOfNextYear.getTime()) { + return year + 1; + } else if (_date.getTime() >= startOfThisYear.getTime()) { + return year; + } else { + return year - 1; + } +} + +/** + * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds. + * They usually appear for dates that denote time before the timezones were introduced + * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891 + * and GMT+01:00:00 after that date) + * + * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above, + * which would lead to incorrect calculations. + * + * This function returns the timezone offset in milliseconds that takes seconds in account. + */ +function getTimezoneOffsetInMilliseconds(date) { + const _date = toDate(date); + const utcDate = new Date( + Date.UTC( + _date.getFullYear(), + _date.getMonth(), + _date.getDate(), + _date.getHours(), + _date.getMinutes(), + _date.getSeconds(), + _date.getMilliseconds(), + ), + ); + utcDate.setUTCFullYear(_date.getFullYear()); + return +date - +utcDate; +} + +function normalizeDates(context, ...dates) { + const normalize = constructFrom.bind( + null, + context || dates.find((date) => typeof date === "object"), + ); + return dates.map(normalize); +} + +/** + * The {@link startOfDay} function options. + */ + +/** + * @name startOfDay + * @category Day Helpers + * @summary Return the start of a day for the given date. + * + * @description + * Return the start of a day for the given date. + * The result will be in the local timezone. + * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments. + * + * @param date - The original date + * @param options - The options + * + * @returns The start of a day + * + * @example + * // The start of a day for 2 September 2014 11:55:00: + * const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0)) + * //=> Tue Sep 02 2014 00:00:00 + */ +function startOfDay(date, options) { + const _date = toDate(date, options?.in); + _date.setHours(0, 0, 0, 0); + return _date; +} + +/** + * The {@link differenceInCalendarDays} function options. + */ + +/** + * @name differenceInCalendarDays + * @category Day Helpers + * @summary Get the number of calendar days between the given dates. + * + * @description + * Get the number of calendar days between the given dates. This means that the times are removed + * from the dates and then the difference in days is calculated. + * + * @param laterDate - The later date + * @param earlierDate - The earlier date + * @param options - The options object + * + * @returns The number of calendar days + * + * @example + * // How many calendar days are between + * // 2 July 2011 23:00:00 and 2 July 2012 00:00:00? + * const result = differenceInCalendarDays( + * new Date(2012, 6, 2, 0, 0), + * new Date(2011, 6, 2, 23, 0) + * ) + * //=> 366 + * // How many calendar days are between + * // 2 July 2011 23:59:00 and 3 July 2011 00:01:00? + * const result = differenceInCalendarDays( + * new Date(2011, 6, 3, 0, 1), + * new Date(2011, 6, 2, 23, 59) + * ) + * //=> 1 + */ +function differenceInCalendarDays(laterDate, earlierDate, options) { + const [laterDate_, earlierDate_] = normalizeDates( + options?.in, + laterDate, + earlierDate, + ); + + const laterStartOfDay = startOfDay(laterDate_); + const earlierStartOfDay = startOfDay(earlierDate_); + + const laterTimestamp = + +laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay); + const earlierTimestamp = + +earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay); + + // Round the number of days to the nearest integer because the number of + // milliseconds in a day is not constant (e.g. it's different in the week of + // the daylight saving time clock shift). + return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay); +} + +/** + * The {@link startOfISOWeekYear} function options. + */ + +/** + * @name startOfISOWeekYear + * @category ISO Week-Numbering Year Helpers + * @summary Return the start of an ISO week-numbering year for the given date. + * + * @description + * Return the start of an ISO week-numbering year, + * which always starts 3 days before the year's first Thursday. + * The result will be in the local timezone. + * + * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date + * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments. + * + * @param date - The original date + * @param options - An object with options + * + * @returns The start of an ISO week-numbering year + * + * @example + * // The start of an ISO week-numbering year for 2 July 2005: + * const result = startOfISOWeekYear(new Date(2005, 6, 2)) + * //=> Mon Jan 03 2005 00:00:00 + */ +function startOfISOWeekYear(date, options) { + const year = getISOWeekYear(date, options); + const fourthOfJanuary = constructFrom(options?.in || date, 0); + fourthOfJanuary.setFullYear(year, 0, 4); + fourthOfJanuary.setHours(0, 0, 0, 0); + return startOfISOWeek(fourthOfJanuary); +} + +/** + * @name isDate + * @category Common Helpers + * @summary Is the given value a date? + * + * @description + * Returns true if the given value is an instance of Date. The function works for dates transferred across iframes. + * + * @param value - The value to check + * + * @returns True if the given value is a date + * + * @example + * // For a valid date: + * const result = isDate(new Date()) + * //=> true + * + * @example + * // For an invalid date: + * const result = isDate(new Date(NaN)) + * //=> true + * + * @example + * // For some value: + * const result = isDate('2014-02-31') + * //=> false + * + * @example + * // For an object: + * const result = isDate({}) + * //=> false + */ +function isDate(value) { + return ( + value instanceof Date || + (typeof value === "object" && + Object.prototype.toString.call(value) === "[object Date]") + ); +} + +/** + * @name isValid + * @category Common Helpers + * @summary Is the given date valid? + * + * @description + * Returns false if argument is Invalid Date and true otherwise. + * Argument is converted to Date using `toDate`. See [toDate](https://date-fns.org/docs/toDate) + * Invalid Date is a Date, whose time value is NaN. + * + * Time value of Date: http://es5.github.io/#x15.9.1.1 + * + * @param date - The date to check + * + * @returns The date is valid + * + * @example + * // For the valid date: + * const result = isValid(new Date(2014, 1, 31)) + * //=> true + * + * @example + * // For the value, convertible into a date: + * const result = isValid(1393804800000) + * //=> true + * + * @example + * // For the invalid date: + * const result = isValid(new Date('')) + * //=> false + */ +function isValid(date) { + return !((!isDate(date) && typeof date !== "number") || isNaN(+toDate(date))); +} + +/** + * The {@link startOfYear} function options. + */ + +/** + * @name startOfYear + * @category Year Helpers + * @summary Return the start of a year for the given date. + * + * @description + * Return the start of a year for the given date. + * The result will be in the local timezone. + * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments. + * + * @param date - The original date + * @param options - The options + * + * @returns The start of a year + * + * @example + * // The start of a year for 2 September 2014 11:55:00: + * const result = startOfYear(new Date(2014, 8, 2, 11, 55, 00)) + * //=> Wed Jan 01 2014 00:00:00 + */ +function startOfYear(date, options) { + const date_ = toDate(date, options?.in); + date_.setFullYear(date_.getFullYear(), 0, 1); + date_.setHours(0, 0, 0, 0); + return date_; +} + +const formatDistanceLocale = { + lessThanXSeconds: { + one: "less than a second", + other: "less than {{count}} seconds", + }, + + xSeconds: { + one: "1 second", + other: "{{count}} seconds", + }, + + halfAMinute: "half a minute", + + lessThanXMinutes: { + one: "less than a minute", + other: "less than {{count}} minutes", + }, + + xMinutes: { + one: "1 minute", + other: "{{count}} minutes", + }, + + aboutXHours: { + one: "about 1 hour", + other: "about {{count}} hours", + }, + + xHours: { + one: "1 hour", + other: "{{count}} hours", + }, + + xDays: { + one: "1 day", + other: "{{count}} days", + }, + + aboutXWeeks: { + one: "about 1 week", + other: "about {{count}} weeks", + }, + + xWeeks: { + one: "1 week", + other: "{{count}} weeks", + }, + + aboutXMonths: { + one: "about 1 month", + other: "about {{count}} months", + }, + + xMonths: { + one: "1 month", + other: "{{count}} months", + }, + + aboutXYears: { + one: "about 1 year", + other: "about {{count}} years", + }, + + xYears: { + one: "1 year", + other: "{{count}} years", + }, + + overXYears: { + one: "over 1 year", + other: "over {{count}} years", + }, + + almostXYears: { + one: "almost 1 year", + other: "almost {{count}} years", + }, +}; + +const formatDistance = (token, count, options) => { + let result; + + const tokenValue = formatDistanceLocale[token]; + if (typeof tokenValue === "string") { + result = tokenValue; + } else if (count === 1) { + result = tokenValue.one; + } else { + result = tokenValue.other.replace("{{count}}", count.toString()); + } + + if (options?.addSuffix) { + if (options.comparison && options.comparison > 0) { + return "in " + result; + } else { + return result + " ago"; + } + } + + return result; +}; + +function buildFormatLongFn(args) { + return (options = {}) => { + // TODO: Remove String() + const width = options.width ? String(options.width) : args.defaultWidth; + const format = args.formats[width] || args.formats[args.defaultWidth]; + return format; + }; +} + +const dateFormats = { + full: "EEEE, MMMM do, y", + long: "MMMM do, y", + medium: "MMM d, y", + short: "MM/dd/yyyy", +}; + +const timeFormats = { + full: "h:mm:ss a zzzz", + long: "h:mm:ss a z", + medium: "h:mm:ss a", + short: "h:mm a", +}; + +const dateTimeFormats = { + full: "{{date}} 'at' {{time}}", + long: "{{date}} 'at' {{time}}", + medium: "{{date}}, {{time}}", + short: "{{date}}, {{time}}", +}; + +const formatLong = { + date: buildFormatLongFn({ + formats: dateFormats, + defaultWidth: "full", + }), + + time: buildFormatLongFn({ + formats: timeFormats, + defaultWidth: "full", + }), + + dateTime: buildFormatLongFn({ + formats: dateTimeFormats, + defaultWidth: "full", + }), +}; + +const formatRelativeLocale = { + lastWeek: "'last' eeee 'at' p", + yesterday: "'yesterday at' p", + today: "'today at' p", + tomorrow: "'tomorrow at' p", + nextWeek: "eeee 'at' p", + other: "P", +}; + +const formatRelative = (token, _date, _baseDate, _options) => + formatRelativeLocale[token]; + +/** + * The localize function argument callback which allows to convert raw value to + * the actual type. + * + * @param value - The value to convert + * + * @returns The converted value + */ + +/** + * The map of localized values for each width. + */ + +/** + * The index type of the locale unit value. It types conversion of units of + * values that don't start at 0 (i.e. quarters). + */ + +/** + * Converts the unit value to the tuple of values. + */ + +/** + * The tuple of localized era values. The first element represents BC, + * the second element represents AD. + */ + +/** + * The tuple of localized quarter values. The first element represents Q1. + */ + +/** + * The tuple of localized day values. The first element represents Sunday. + */ + +/** + * The tuple of localized month values. The first element represents January. + */ + +function buildLocalizeFn(args) { + return (value, options) => { + const context = options?.context ? String(options.context) : "standalone"; + + let valuesArray; + if (context === "formatting" && args.formattingValues) { + const defaultWidth = args.defaultFormattingWidth || args.defaultWidth; + const width = options?.width ? String(options.width) : defaultWidth; + + valuesArray = + args.formattingValues[width] || args.formattingValues[defaultWidth]; + } else { + const defaultWidth = args.defaultWidth; + const width = options?.width ? String(options.width) : args.defaultWidth; + + valuesArray = args.values[width] || args.values[defaultWidth]; + } + const index = args.argumentCallback ? args.argumentCallback(value) : value; + + // @ts-expect-error - For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it! + return valuesArray[index]; + }; +} + +const eraValues = { + narrow: ["B", "A"], + abbreviated: ["BC", "AD"], + wide: ["Before Christ", "Anno Domini"], +}; + +const quarterValues = { + narrow: ["1", "2", "3", "4"], + abbreviated: ["Q1", "Q2", "Q3", "Q4"], + wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"], +}; + +// Note: in English, the names of days of the week and months are capitalized. +// If you are making a new locale based on this one, check if the same is true for the language you're working on. +// Generally, formatted dates should look like they are in the middle of a sentence, +// e.g. in Spanish language the weekdays and months should be in the lowercase. +const monthValues = { + narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"], + abbreviated: [ + "Jan", + "Feb", + "Mar", + "Apr", + "May", + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec", + ], + + wide: [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", + ], +}; + +const dayValues = { + narrow: ["S", "M", "T", "W", "T", "F", "S"], + short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], + abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], + wide: [ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + ], +}; + +const dayPeriodValues = { + narrow: { + am: "a", + pm: "p", + midnight: "mi", + noon: "n", + morning: "morning", + afternoon: "afternoon", + evening: "evening", + night: "night", + }, + abbreviated: { + am: "AM", + pm: "PM", + midnight: "midnight", + noon: "noon", + morning: "morning", + afternoon: "afternoon", + evening: "evening", + night: "night", + }, + wide: { + am: "a.m.", + pm: "p.m.", + midnight: "midnight", + noon: "noon", + morning: "morning", + afternoon: "afternoon", + evening: "evening", + night: "night", + }, +}; + +const formattingDayPeriodValues = { + narrow: { + am: "a", + pm: "p", + midnight: "mi", + noon: "n", + morning: "in the morning", + afternoon: "in the afternoon", + evening: "in the evening", + night: "at night", + }, + abbreviated: { + am: "AM", + pm: "PM", + midnight: "midnight", + noon: "noon", + morning: "in the morning", + afternoon: "in the afternoon", + evening: "in the evening", + night: "at night", + }, + wide: { + am: "a.m.", + pm: "p.m.", + midnight: "midnight", + noon: "noon", + morning: "in the morning", + afternoon: "in the afternoon", + evening: "in the evening", + night: "at night", + }, +}; + +const ordinalNumber = (dirtyNumber, _options) => { + const number = Number(dirtyNumber); + + // If ordinal numbers depend on context, for example, + // if they are different for different grammatical genders, + // use `options.unit`. + // + // `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear', + // 'day', 'hour', 'minute', 'second'. + + const rem100 = number % 100; + if (rem100 > 20 || rem100 < 10) { + switch (rem100 % 10) { + case 1: + return number + "st"; + case 2: + return number + "nd"; + case 3: + return number + "rd"; + } + } + return number + "th"; +}; + +const localize = { + ordinalNumber, + + era: buildLocalizeFn({ + values: eraValues, + defaultWidth: "wide", + }), + + quarter: buildLocalizeFn({ + values: quarterValues, + defaultWidth: "wide", + argumentCallback: (quarter) => quarter - 1, + }), + + month: buildLocalizeFn({ + values: monthValues, + defaultWidth: "wide", + }), + + day: buildLocalizeFn({ + values: dayValues, + defaultWidth: "wide", + }), + + dayPeriod: buildLocalizeFn({ + values: dayPeriodValues, + defaultWidth: "wide", + formattingValues: formattingDayPeriodValues, + defaultFormattingWidth: "wide", + }), +}; + +function buildMatchFn(args) { + return (string, options = {}) => { + const width = options.width; + + const matchPattern = + (width && args.matchPatterns[width]) || + args.matchPatterns[args.defaultMatchWidth]; + const matchResult = string.match(matchPattern); + + if (!matchResult) { + return null; + } + const matchedString = matchResult[0]; + + const parsePatterns = + (width && args.parsePatterns[width]) || + args.parsePatterns[args.defaultParseWidth]; + + const key = Array.isArray(parsePatterns) + ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString)) + : // [TODO] -- I challenge you to fix the type + findKey(parsePatterns, (pattern) => pattern.test(matchedString)); + + let value; + + value = args.valueCallback ? args.valueCallback(key) : key; + value = options.valueCallback + ? // [TODO] -- I challenge you to fix the type + options.valueCallback(value) + : value; + + const rest = string.slice(matchedString.length); + + return { value, rest }; + }; +} + +function findKey(object, predicate) { + for (const key in object) { + if ( + Object.prototype.hasOwnProperty.call(object, key) && + predicate(object[key]) + ) { + return key; + } + } + return undefined; +} + +function findIndex(array, predicate) { + for (let key = 0; key < array.length; key++) { + if (predicate(array[key])) { + return key; + } + } + return undefined; +} + +function buildMatchPatternFn(args) { + return (string, options = {}) => { + const matchResult = string.match(args.matchPattern); + if (!matchResult) return null; + const matchedString = matchResult[0]; + + const parseResult = string.match(args.parsePattern); + if (!parseResult) return null; + let value = args.valueCallback + ? args.valueCallback(parseResult[0]) + : parseResult[0]; + + // [TODO] I challenge you to fix the type + value = options.valueCallback ? options.valueCallback(value) : value; + + const rest = string.slice(matchedString.length); + + return { value, rest }; + }; +} + +const matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i; +const parseOrdinalNumberPattern = /\d+/i; + +const matchEraPatterns = { + narrow: /^(b|a)/i, + abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i, + wide: /^(before christ|before common era|anno domini|common era)/i, +}; +const parseEraPatterns = { + any: [/^b/i, /^(a|c)/i], +}; + +const matchQuarterPatterns = { + narrow: /^[1234]/i, + abbreviated: /^q[1234]/i, + wide: /^[1234](th|st|nd|rd)? quarter/i, +}; +const parseQuarterPatterns = { + any: [/1/i, /2/i, /3/i, /4/i], +}; + +const matchMonthPatterns = { + narrow: /^[jfmasond]/i, + abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i, + wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i, +}; +const parseMonthPatterns = { + narrow: [ + /^j/i, + /^f/i, + /^m/i, + /^a/i, + /^m/i, + /^j/i, + /^j/i, + /^a/i, + /^s/i, + /^o/i, + /^n/i, + /^d/i, + ], + + any: [ + /^ja/i, + /^f/i, + /^mar/i, + /^ap/i, + /^may/i, + /^jun/i, + /^jul/i, + /^au/i, + /^s/i, + /^o/i, + /^n/i, + /^d/i, + ], +}; + +const matchDayPatterns = { + narrow: /^[smtwf]/i, + short: /^(su|mo|tu|we|th|fr|sa)/i, + abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i, + wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i, +}; +const parseDayPatterns = { + narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i], + any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i], +}; + +const matchDayPeriodPatterns = { + narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i, + any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i, +}; +const parseDayPeriodPatterns = { + any: { + am: /^a/i, + pm: /^p/i, + midnight: /^mi/i, + noon: /^no/i, + morning: /morning/i, + afternoon: /afternoon/i, + evening: /evening/i, + night: /night/i, + }, +}; + +const match = { + ordinalNumber: buildMatchPatternFn({ + matchPattern: matchOrdinalNumberPattern, + parsePattern: parseOrdinalNumberPattern, + valueCallback: (value) => parseInt(value, 10), + }), + + era: buildMatchFn({ + matchPatterns: matchEraPatterns, + defaultMatchWidth: "wide", + parsePatterns: parseEraPatterns, + defaultParseWidth: "any", + }), + + quarter: buildMatchFn({ + matchPatterns: matchQuarterPatterns, + defaultMatchWidth: "wide", + parsePatterns: parseQuarterPatterns, + defaultParseWidth: "any", + valueCallback: (index) => index + 1, + }), + + month: buildMatchFn({ + matchPatterns: matchMonthPatterns, + defaultMatchWidth: "wide", + parsePatterns: parseMonthPatterns, + defaultParseWidth: "any", + }), + + day: buildMatchFn({ + matchPatterns: matchDayPatterns, + defaultMatchWidth: "wide", + parsePatterns: parseDayPatterns, + defaultParseWidth: "any", + }), + + dayPeriod: buildMatchFn({ + matchPatterns: matchDayPeriodPatterns, + defaultMatchWidth: "any", + parsePatterns: parseDayPeriodPatterns, + defaultParseWidth: "any", + }), +}; + +/** + * @category Locales + * @summary English locale (United States). + * @language English + * @iso-639-2 eng + * @author Sasha Koss [@kossnocorp](https://github.com/kossnocorp) + * @author Lesha Koss [@leshakoss](https://github.com/leshakoss) + */ +const enUS = { + code: "en-US", + formatDistance: formatDistance, + formatLong: formatLong, + formatRelative: formatRelative, + localize: localize, + match: match, + options: { + weekStartsOn: 0 /* Sunday */, + firstWeekContainsDate: 1, + }, +}; + +/** + * The {@link getDayOfYear} function options. + */ + +/** + * @name getDayOfYear + * @category Day Helpers + * @summary Get the day of the year of the given date. + * + * @description + * Get the day of the year of the given date. + * + * @param date - The given date + * @param options - The options + * + * @returns The day of year + * + * @example + * // Which day of the year is 2 July 2014? + * const result = getDayOfYear(new Date(2014, 6, 2)) + * //=> 183 + */ +function getDayOfYear(date, options) { + const _date = toDate(date, options?.in); + const diff = differenceInCalendarDays(_date, startOfYear(_date)); + const dayOfYear = diff + 1; + return dayOfYear; +} + +/** + * The {@link getISOWeek} function options. + */ + +/** + * @name getISOWeek + * @category ISO Week Helpers + * @summary Get the ISO week of the given date. + * + * @description + * Get the ISO week of the given date. + * + * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date + * + * @param date - The given date + * @param options - The options + * + * @returns The ISO week + * + * @example + * // Which week of the ISO-week numbering year is 2 January 2005? + * const result = getISOWeek(new Date(2005, 0, 2)) + * //=> 53 + */ +function getISOWeek(date, options) { + const _date = toDate(date, options?.in); + const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date); + + // Round the number of weeks to the nearest integer because the number of + // milliseconds in a week is not constant (e.g. it's different in the week of + // the daylight saving time clock shift). + return Math.round(diff / millisecondsInWeek) + 1; +} + +/** + * The {@link getWeekYear} function options. + */ + +/** + * @name getWeekYear + * @category Week-Numbering Year Helpers + * @summary Get the local week-numbering year of the given date. + * + * @description + * Get the local week-numbering year of the given date. + * The exact calculation depends on the values of + * `options.weekStartsOn` (which is the index of the first day of the week) + * and `options.firstWeekContainsDate` (which is the day of January, which is always in + * the first week of the week-numbering year) + * + * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system + * + * @param date - The given date + * @param options - An object with options. + * + * @returns The local week-numbering year + * + * @example + * // Which week numbering year is 26 December 2004 with the default settings? + * const result = getWeekYear(new Date(2004, 11, 26)) + * //=> 2005 + * + * @example + * // Which week numbering year is 26 December 2004 if week starts on Saturday? + * const result = getWeekYear(new Date(2004, 11, 26), { weekStartsOn: 6 }) + * //=> 2004 + * + * @example + * // Which week numbering year is 26 December 2004 if the first week contains 4 January? + * const result = getWeekYear(new Date(2004, 11, 26), { firstWeekContainsDate: 4 }) + * //=> 2004 + */ +function getWeekYear(date, options) { + const _date = toDate(date, options?.in); + const year = _date.getFullYear(); + + const defaultOptions = getDefaultOptions(); + const firstWeekContainsDate = + options?.firstWeekContainsDate ?? + options?.locale?.options?.firstWeekContainsDate ?? + defaultOptions.firstWeekContainsDate ?? + defaultOptions.locale?.options?.firstWeekContainsDate ?? + 1; + + const firstWeekOfNextYear = constructFrom(options?.in || date, 0); + firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate); + firstWeekOfNextYear.setHours(0, 0, 0, 0); + const startOfNextYear = startOfWeek(firstWeekOfNextYear, options); + + const firstWeekOfThisYear = constructFrom(options?.in || date, 0); + firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate); + firstWeekOfThisYear.setHours(0, 0, 0, 0); + const startOfThisYear = startOfWeek(firstWeekOfThisYear, options); + + if (+_date >= +startOfNextYear) { + return year + 1; + } else if (+_date >= +startOfThisYear) { + return year; + } else { + return year - 1; + } +} + +/** + * The {@link startOfWeekYear} function options. + */ + +/** + * @name startOfWeekYear + * @category Week-Numbering Year Helpers + * @summary Return the start of a local week-numbering year for the given date. + * + * @description + * Return the start of a local week-numbering year. + * The exact calculation depends on the values of + * `options.weekStartsOn` (which is the index of the first day of the week) + * and `options.firstWeekContainsDate` (which is the day of January, which is always in + * the first week of the week-numbering year) + * + * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system + * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * @typeParam ResultDate - The result `Date` type. + * + * @param date - The original date + * @param options - An object with options + * + * @returns The start of a week-numbering year + * + * @example + * // The start of an a week-numbering year for 2 July 2005 with default settings: + * const result = startOfWeekYear(new Date(2005, 6, 2)) + * //=> Sun Dec 26 2004 00:00:00 + * + * @example + * // The start of a week-numbering year for 2 July 2005 + * // if Monday is the first day of week + * // and 4 January is always in the first week of the year: + * const result = startOfWeekYear(new Date(2005, 6, 2), { + * weekStartsOn: 1, + * firstWeekContainsDate: 4 + * }) + * //=> Mon Jan 03 2005 00:00:00 + */ +function startOfWeekYear(date, options) { + const defaultOptions = getDefaultOptions(); + const firstWeekContainsDate = + options?.firstWeekContainsDate ?? + options?.locale?.options?.firstWeekContainsDate ?? + defaultOptions.firstWeekContainsDate ?? + defaultOptions.locale?.options?.firstWeekContainsDate ?? + 1; + + const year = getWeekYear(date, options); + const firstWeek = constructFrom(options?.in || date, 0); + firstWeek.setFullYear(year, 0, firstWeekContainsDate); + firstWeek.setHours(0, 0, 0, 0); + const _date = startOfWeek(firstWeek, options); + return _date; +} + +/** + * The {@link getWeek} function options. + */ + +/** + * @name getWeek + * @category Week Helpers + * @summary Get the local week index of the given date. + * + * @description + * Get the local week index of the given date. + * The exact calculation depends on the values of + * `options.weekStartsOn` (which is the index of the first day of the week) + * and `options.firstWeekContainsDate` (which is the day of January, which is always in + * the first week of the week-numbering year) + * + * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system + * + * @param date - The given date + * @param options - An object with options + * + * @returns The week + * + * @example + * // Which week of the local week numbering year is 2 January 2005 with default options? + * const result = getWeek(new Date(2005, 0, 2)) + * //=> 2 + * + * @example + * // Which week of the local week numbering year is 2 January 2005, + * // if Monday is the first day of the week, + * // and the first week of the year always contains 4 January? + * const result = getWeek(new Date(2005, 0, 2), { + * weekStartsOn: 1, + * firstWeekContainsDate: 4 + * }) + * //=> 53 + */ +function getWeek(date, options) { + const _date = toDate(date, options?.in); + const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options); + + // Round the number of weeks to the nearest integer because the number of + // milliseconds in a week is not constant (e.g. it's different in the week of + // the daylight saving time clock shift). + return Math.round(diff / millisecondsInWeek) + 1; +} + +function addLeadingZeros(number, targetLength) { + const sign = number < 0 ? "-" : ""; + const output = Math.abs(number).toString().padStart(targetLength, "0"); + return sign + output; +} + +/* + * | | Unit | | Unit | + * |-----|--------------------------------|-----|--------------------------------| + * | a | AM, PM | A* | | + * | d | Day of month | D | | + * | h | Hour [1-12] | H | Hour [0-23] | + * | m | Minute | M | Month | + * | s | Second | S | Fraction of second | + * | y | Year (abs) | Y | | + * + * Letters marked by * are not implemented but reserved by Unicode standard. + */ + +const lightFormatters = { + // Year + y(date, token) { + // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens + // | Year | y | yy | yyy | yyyy | yyyyy | + // |----------|-------|----|-------|-------|-------| + // | AD 1 | 1 | 01 | 001 | 0001 | 00001 | + // | AD 12 | 12 | 12 | 012 | 0012 | 00012 | + // | AD 123 | 123 | 23 | 123 | 0123 | 00123 | + // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 | + // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 | + + const signedYear = date.getFullYear(); + // Returns 1 for 1 BC (which is year 0 in JavaScript) + const year = signedYear > 0 ? signedYear : 1 - signedYear; + return addLeadingZeros(token === "yy" ? year % 100 : year, token.length); + }, + + // Month + M(date, token) { + const month = date.getMonth(); + return token === "M" ? String(month + 1) : addLeadingZeros(month + 1, 2); + }, + + // Day of the month + d(date, token) { + return addLeadingZeros(date.getDate(), token.length); + }, + + // AM or PM + a(date, token) { + const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am"; + + switch (token) { + case "a": + case "aa": + return dayPeriodEnumValue.toUpperCase(); + case "aaa": + return dayPeriodEnumValue; + case "aaaaa": + return dayPeriodEnumValue[0]; + case "aaaa": + default: + return dayPeriodEnumValue === "am" ? "a.m." : "p.m."; + } + }, + + // Hour [1-12] + h(date, token) { + return addLeadingZeros(date.getHours() % 12 || 12, token.length); + }, + + // Hour [0-23] + H(date, token) { + return addLeadingZeros(date.getHours(), token.length); + }, + + // Minute + m(date, token) { + return addLeadingZeros(date.getMinutes(), token.length); + }, + + // Second + s(date, token) { + return addLeadingZeros(date.getSeconds(), token.length); + }, + + // Fraction of second + S(date, token) { + const numberOfDigits = token.length; + const milliseconds = date.getMilliseconds(); + const fractionalSeconds = Math.trunc( + milliseconds * Math.pow(10, numberOfDigits - 3), + ); + return addLeadingZeros(fractionalSeconds, token.length); + }, +}; + +const dayPeriodEnum = { + am: "am", + pm: "pm", + midnight: "midnight", + noon: "noon", + morning: "morning", + afternoon: "afternoon", + evening: "evening", + night: "night", +}; + +/* + * | | Unit | | Unit | + * |-----|--------------------------------|-----|--------------------------------| + * | a | AM, PM | A* | Milliseconds in day | + * | b | AM, PM, noon, midnight | B | Flexible day period | + * | c | Stand-alone local day of week | C* | Localized hour w/ day period | + * | d | Day of month | D | Day of year | + * | e | Local day of week | E | Day of week | + * | f | | F* | Day of week in month | + * | g* | Modified Julian day | G | Era | + * | h | Hour [1-12] | H | Hour [0-23] | + * | i! | ISO day of week | I! | ISO week of year | + * | j* | Localized hour w/ day period | J* | Localized hour w/o day period | + * | k | Hour [1-24] | K | Hour [0-11] | + * | l* | (deprecated) | L | Stand-alone month | + * | m | Minute | M | Month | + * | n | | N | | + * | o! | Ordinal number modifier | O | Timezone (GMT) | + * | p! | Long localized time | P! | Long localized date | + * | q | Stand-alone quarter | Q | Quarter | + * | r* | Related Gregorian year | R! | ISO week-numbering year | + * | s | Second | S | Fraction of second | + * | t! | Seconds timestamp | T! | Milliseconds timestamp | + * | u | Extended year | U* | Cyclic year | + * | v* | Timezone (generic non-locat.) | V* | Timezone (location) | + * | w | Local week of year | W* | Week of month | + * | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) | + * | y | Year (abs) | Y | Local week-numbering year | + * | z | Timezone (specific non-locat.) | Z* | Timezone (aliases) | + * + * Letters marked by * are not implemented but reserved by Unicode standard. + * + * Letters marked by ! are non-standard, but implemented by date-fns: + * - `o` modifies the previous token to turn it into an ordinal (see `format` docs) + * - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days, + * i.e. 7 for Sunday, 1 for Monday, etc. + * - `I` is ISO week of year, as opposed to `w` which is local week of year. + * - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year. + * `R` is supposed to be used in conjunction with `I` and `i` + * for universal ISO week-numbering date, whereas + * `Y` is supposed to be used in conjunction with `w` and `e` + * for week-numbering date specific to the locale. + * - `P` is long localized date format + * - `p` is long localized time format + */ + +const formatters = { + // Era + G: function (date, token, localize) { + const era = date.getFullYear() > 0 ? 1 : 0; + switch (token) { + // AD, BC + case "G": + case "GG": + case "GGG": + return localize.era(era, { width: "abbreviated" }); + // A, B + case "GGGGG": + return localize.era(era, { width: "narrow" }); + // Anno Domini, Before Christ + case "GGGG": + default: + return localize.era(era, { width: "wide" }); + } + }, + + // Year + y: function (date, token, localize) { + // Ordinal number + if (token === "yo") { + const signedYear = date.getFullYear(); + // Returns 1 for 1 BC (which is year 0 in JavaScript) + const year = signedYear > 0 ? signedYear : 1 - signedYear; + return localize.ordinalNumber(year, { unit: "year" }); + } + + return lightFormatters.y(date, token); + }, + + // Local week-numbering year + Y: function (date, token, localize, options) { + const signedWeekYear = getWeekYear(date, options); + // Returns 1 for 1 BC (which is year 0 in JavaScript) + const weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear; + + // Two digit year + if (token === "YY") { + const twoDigitYear = weekYear % 100; + return addLeadingZeros(twoDigitYear, 2); + } + + // Ordinal number + if (token === "Yo") { + return localize.ordinalNumber(weekYear, { unit: "year" }); + } + + // Padding + return addLeadingZeros(weekYear, token.length); + }, + + // ISO week-numbering year + R: function (date, token) { + const isoWeekYear = getISOWeekYear(date); + + // Padding + return addLeadingZeros(isoWeekYear, token.length); + }, + + // Extended year. This is a single number designating the year of this calendar system. + // The main difference between `y` and `u` localizers are B.C. years: + // | Year | `y` | `u` | + // |------|-----|-----| + // | AC 1 | 1 | 1 | + // | BC 1 | 1 | 0 | + // | BC 2 | 2 | -1 | + // Also `yy` always returns the last two digits of a year, + // while `uu` pads single digit years to 2 characters and returns other years unchanged. + u: function (date, token) { + const year = date.getFullYear(); + return addLeadingZeros(year, token.length); + }, + + // Quarter + Q: function (date, token, localize) { + const quarter = Math.ceil((date.getMonth() + 1) / 3); + switch (token) { + // 1, 2, 3, 4 + case "Q": + return String(quarter); + // 01, 02, 03, 04 + case "QQ": + return addLeadingZeros(quarter, 2); + // 1st, 2nd, 3rd, 4th + case "Qo": + return localize.ordinalNumber(quarter, { unit: "quarter" }); + // Q1, Q2, Q3, Q4 + case "QQQ": + return localize.quarter(quarter, { + width: "abbreviated", + context: "formatting", + }); + // 1, 2, 3, 4 (narrow quarter; could be not numerical) + case "QQQQQ": + return localize.quarter(quarter, { + width: "narrow", + context: "formatting", + }); + // 1st quarter, 2nd quarter, ... + case "QQQQ": + default: + return localize.quarter(quarter, { + width: "wide", + context: "formatting", + }); + } + }, + + // Stand-alone quarter + q: function (date, token, localize) { + const quarter = Math.ceil((date.getMonth() + 1) / 3); + switch (token) { + // 1, 2, 3, 4 + case "q": + return String(quarter); + // 01, 02, 03, 04 + case "qq": + return addLeadingZeros(quarter, 2); + // 1st, 2nd, 3rd, 4th + case "qo": + return localize.ordinalNumber(quarter, { unit: "quarter" }); + // Q1, Q2, Q3, Q4 + case "qqq": + return localize.quarter(quarter, { + width: "abbreviated", + context: "standalone", + }); + // 1, 2, 3, 4 (narrow quarter; could be not numerical) + case "qqqqq": + return localize.quarter(quarter, { + width: "narrow", + context: "standalone", + }); + // 1st quarter, 2nd quarter, ... + case "qqqq": + default: + return localize.quarter(quarter, { + width: "wide", + context: "standalone", + }); + } + }, + + // Month + M: function (date, token, localize) { + const month = date.getMonth(); + switch (token) { + case "M": + case "MM": + return lightFormatters.M(date, token); + // 1st, 2nd, ..., 12th + case "Mo": + return localize.ordinalNumber(month + 1, { unit: "month" }); + // Jan, Feb, ..., Dec + case "MMM": + return localize.month(month, { + width: "abbreviated", + context: "formatting", + }); + // J, F, ..., D + case "MMMMM": + return localize.month(month, { + width: "narrow", + context: "formatting", + }); + // January, February, ..., December + case "MMMM": + default: + return localize.month(month, { width: "wide", context: "formatting" }); + } + }, + + // Stand-alone month + L: function (date, token, localize) { + const month = date.getMonth(); + switch (token) { + // 1, 2, ..., 12 + case "L": + return String(month + 1); + // 01, 02, ..., 12 + case "LL": + return addLeadingZeros(month + 1, 2); + // 1st, 2nd, ..., 12th + case "Lo": + return localize.ordinalNumber(month + 1, { unit: "month" }); + // Jan, Feb, ..., Dec + case "LLL": + return localize.month(month, { + width: "abbreviated", + context: "standalone", + }); + // J, F, ..., D + case "LLLLL": + return localize.month(month, { + width: "narrow", + context: "standalone", + }); + // January, February, ..., December + case "LLLL": + default: + return localize.month(month, { width: "wide", context: "standalone" }); + } + }, + + // Local week of year + w: function (date, token, localize, options) { + const week = getWeek(date, options); + + if (token === "wo") { + return localize.ordinalNumber(week, { unit: "week" }); + } + + return addLeadingZeros(week, token.length); + }, + + // ISO week of year + I: function (date, token, localize) { + const isoWeek = getISOWeek(date); + + if (token === "Io") { + return localize.ordinalNumber(isoWeek, { unit: "week" }); + } + + return addLeadingZeros(isoWeek, token.length); + }, + + // Day of the month + d: function (date, token, localize) { + if (token === "do") { + return localize.ordinalNumber(date.getDate(), { unit: "date" }); + } + + return lightFormatters.d(date, token); + }, + + // Day of year + D: function (date, token, localize) { + const dayOfYear = getDayOfYear(date); + + if (token === "Do") { + return localize.ordinalNumber(dayOfYear, { unit: "dayOfYear" }); + } + + return addLeadingZeros(dayOfYear, token.length); + }, + + // Day of week + E: function (date, token, localize) { + const dayOfWeek = date.getDay(); + switch (token) { + // Tue + case "E": + case "EE": + case "EEE": + return localize.day(dayOfWeek, { + width: "abbreviated", + context: "formatting", + }); + // T + case "EEEEE": + return localize.day(dayOfWeek, { + width: "narrow", + context: "formatting", + }); + // Tu + case "EEEEEE": + return localize.day(dayOfWeek, { + width: "short", + context: "formatting", + }); + // Tuesday + case "EEEE": + default: + return localize.day(dayOfWeek, { + width: "wide", + context: "formatting", + }); + } + }, + + // Local day of week + e: function (date, token, localize, options) { + const dayOfWeek = date.getDay(); + const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7; + switch (token) { + // Numerical value (Nth day of week with current locale or weekStartsOn) + case "e": + return String(localDayOfWeek); + // Padded numerical value + case "ee": + return addLeadingZeros(localDayOfWeek, 2); + // 1st, 2nd, ..., 7th + case "eo": + return localize.ordinalNumber(localDayOfWeek, { unit: "day" }); + case "eee": + return localize.day(dayOfWeek, { + width: "abbreviated", + context: "formatting", + }); + // T + case "eeeee": + return localize.day(dayOfWeek, { + width: "narrow", + context: "formatting", + }); + // Tu + case "eeeeee": + return localize.day(dayOfWeek, { + width: "short", + context: "formatting", + }); + // Tuesday + case "eeee": + default: + return localize.day(dayOfWeek, { + width: "wide", + context: "formatting", + }); + } + }, + + // Stand-alone local day of week + c: function (date, token, localize, options) { + const dayOfWeek = date.getDay(); + const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7; + switch (token) { + // Numerical value (same as in `e`) + case "c": + return String(localDayOfWeek); + // Padded numerical value + case "cc": + return addLeadingZeros(localDayOfWeek, token.length); + // 1st, 2nd, ..., 7th + case "co": + return localize.ordinalNumber(localDayOfWeek, { unit: "day" }); + case "ccc": + return localize.day(dayOfWeek, { + width: "abbreviated", + context: "standalone", + }); + // T + case "ccccc": + return localize.day(dayOfWeek, { + width: "narrow", + context: "standalone", + }); + // Tu + case "cccccc": + return localize.day(dayOfWeek, { + width: "short", + context: "standalone", + }); + // Tuesday + case "cccc": + default: + return localize.day(dayOfWeek, { + width: "wide", + context: "standalone", + }); + } + }, + + // ISO day of week + i: function (date, token, localize) { + const dayOfWeek = date.getDay(); + const isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek; + switch (token) { + // 2 + case "i": + return String(isoDayOfWeek); + // 02 + case "ii": + return addLeadingZeros(isoDayOfWeek, token.length); + // 2nd + case "io": + return localize.ordinalNumber(isoDayOfWeek, { unit: "day" }); + // Tue + case "iii": + return localize.day(dayOfWeek, { + width: "abbreviated", + context: "formatting", + }); + // T + case "iiiii": + return localize.day(dayOfWeek, { + width: "narrow", + context: "formatting", + }); + // Tu + case "iiiiii": + return localize.day(dayOfWeek, { + width: "short", + context: "formatting", + }); + // Tuesday + case "iiii": + default: + return localize.day(dayOfWeek, { + width: "wide", + context: "formatting", + }); + } + }, + + // AM or PM + a: function (date, token, localize) { + const hours = date.getHours(); + const dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am"; + + switch (token) { + case "a": + case "aa": + return localize.dayPeriod(dayPeriodEnumValue, { + width: "abbreviated", + context: "formatting", + }); + case "aaa": + return localize + .dayPeriod(dayPeriodEnumValue, { + width: "abbreviated", + context: "formatting", + }) + .toLowerCase(); + case "aaaaa": + return localize.dayPeriod(dayPeriodEnumValue, { + width: "narrow", + context: "formatting", + }); + case "aaaa": + default: + return localize.dayPeriod(dayPeriodEnumValue, { + width: "wide", + context: "formatting", + }); + } + }, + + // AM, PM, midnight, noon + b: function (date, token, localize) { + const hours = date.getHours(); + let dayPeriodEnumValue; + if (hours === 12) { + dayPeriodEnumValue = dayPeriodEnum.noon; + } else if (hours === 0) { + dayPeriodEnumValue = dayPeriodEnum.midnight; + } else { + dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am"; + } + + switch (token) { + case "b": + case "bb": + return localize.dayPeriod(dayPeriodEnumValue, { + width: "abbreviated", + context: "formatting", + }); + case "bbb": + return localize + .dayPeriod(dayPeriodEnumValue, { + width: "abbreviated", + context: "formatting", + }) + .toLowerCase(); + case "bbbbb": + return localize.dayPeriod(dayPeriodEnumValue, { + width: "narrow", + context: "formatting", + }); + case "bbbb": + default: + return localize.dayPeriod(dayPeriodEnumValue, { + width: "wide", + context: "formatting", + }); + } + }, + + // in the morning, in the afternoon, in the evening, at night + B: function (date, token, localize) { + const hours = date.getHours(); + let dayPeriodEnumValue; + if (hours >= 17) { + dayPeriodEnumValue = dayPeriodEnum.evening; + } else if (hours >= 12) { + dayPeriodEnumValue = dayPeriodEnum.afternoon; + } else if (hours >= 4) { + dayPeriodEnumValue = dayPeriodEnum.morning; + } else { + dayPeriodEnumValue = dayPeriodEnum.night; + } + + switch (token) { + case "B": + case "BB": + case "BBB": + return localize.dayPeriod(dayPeriodEnumValue, { + width: "abbreviated", + context: "formatting", + }); + case "BBBBB": + return localize.dayPeriod(dayPeriodEnumValue, { + width: "narrow", + context: "formatting", + }); + case "BBBB": + default: + return localize.dayPeriod(dayPeriodEnumValue, { + width: "wide", + context: "formatting", + }); + } + }, + + // Hour [1-12] + h: function (date, token, localize) { + if (token === "ho") { + let hours = date.getHours() % 12; + if (hours === 0) hours = 12; + return localize.ordinalNumber(hours, { unit: "hour" }); + } + + return lightFormatters.h(date, token); + }, + + // Hour [0-23] + H: function (date, token, localize) { + if (token === "Ho") { + return localize.ordinalNumber(date.getHours(), { unit: "hour" }); + } + + return lightFormatters.H(date, token); + }, + + // Hour [0-11] + K: function (date, token, localize) { + const hours = date.getHours() % 12; + + if (token === "Ko") { + return localize.ordinalNumber(hours, { unit: "hour" }); + } + + return addLeadingZeros(hours, token.length); + }, + + // Hour [1-24] + k: function (date, token, localize) { + let hours = date.getHours(); + if (hours === 0) hours = 24; + + if (token === "ko") { + return localize.ordinalNumber(hours, { unit: "hour" }); + } + + return addLeadingZeros(hours, token.length); + }, + + // Minute + m: function (date, token, localize) { + if (token === "mo") { + return localize.ordinalNumber(date.getMinutes(), { unit: "minute" }); + } + + return lightFormatters.m(date, token); + }, + + // Second + s: function (date, token, localize) { + if (token === "so") { + return localize.ordinalNumber(date.getSeconds(), { unit: "second" }); + } + + return lightFormatters.s(date, token); + }, + + // Fraction of second + S: function (date, token) { + return lightFormatters.S(date, token); + }, + + // Timezone (ISO-8601. If offset is 0, output is always `'Z'`) + X: function (date, token, _localize) { + const timezoneOffset = date.getTimezoneOffset(); + + if (timezoneOffset === 0) { + return "Z"; + } + + switch (token) { + // Hours and optional minutes + case "X": + return formatTimezoneWithOptionalMinutes(timezoneOffset); + + // Hours, minutes and optional seconds without `:` delimiter + // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets + // so this token always has the same output as `XX` + case "XXXX": + case "XX": // Hours and minutes without `:` delimiter + return formatTimezone(timezoneOffset); + + // Hours, minutes and optional seconds with `:` delimiter + // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets + // so this token always has the same output as `XXX` + case "XXXXX": + case "XXX": // Hours and minutes with `:` delimiter + default: + return formatTimezone(timezoneOffset, ":"); + } + }, + + // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent) + x: function (date, token, _localize) { + const timezoneOffset = date.getTimezoneOffset(); + + switch (token) { + // Hours and optional minutes + case "x": + return formatTimezoneWithOptionalMinutes(timezoneOffset); + + // Hours, minutes and optional seconds without `:` delimiter + // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets + // so this token always has the same output as `xx` + case "xxxx": + case "xx": // Hours and minutes without `:` delimiter + return formatTimezone(timezoneOffset); + + // Hours, minutes and optional seconds with `:` delimiter + // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets + // so this token always has the same output as `xxx` + case "xxxxx": + case "xxx": // Hours and minutes with `:` delimiter + default: + return formatTimezone(timezoneOffset, ":"); + } + }, + + // Timezone (GMT) + O: function (date, token, _localize) { + const timezoneOffset = date.getTimezoneOffset(); + + switch (token) { + // Short + case "O": + case "OO": + case "OOO": + return "GMT" + formatTimezoneShort(timezoneOffset, ":"); + // Long + case "OOOO": + default: + return "GMT" + formatTimezone(timezoneOffset, ":"); + } + }, + + // Timezone (specific non-location) + z: function (date, token, _localize) { + const timezoneOffset = date.getTimezoneOffset(); + + switch (token) { + // Short + case "z": + case "zz": + case "zzz": + return "GMT" + formatTimezoneShort(timezoneOffset, ":"); + // Long + case "zzzz": + default: + return "GMT" + formatTimezone(timezoneOffset, ":"); + } + }, + + // Seconds timestamp + t: function (date, token, _localize) { + const timestamp = Math.trunc(+date / 1000); + return addLeadingZeros(timestamp, token.length); + }, + + // Milliseconds timestamp + T: function (date, token, _localize) { + return addLeadingZeros(+date, token.length); + }, +}; + +function formatTimezoneShort(offset, delimiter = "") { + const sign = offset > 0 ? "-" : "+"; + const absOffset = Math.abs(offset); + const hours = Math.trunc(absOffset / 60); + const minutes = absOffset % 60; + if (minutes === 0) { + return sign + String(hours); + } + return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2); +} + +function formatTimezoneWithOptionalMinutes(offset, delimiter) { + if (offset % 60 === 0) { + const sign = offset > 0 ? "-" : "+"; + return sign + addLeadingZeros(Math.abs(offset) / 60, 2); + } + return formatTimezone(offset, delimiter); +} + +function formatTimezone(offset, delimiter = "") { + const sign = offset > 0 ? "-" : "+"; + const absOffset = Math.abs(offset); + const hours = addLeadingZeros(Math.trunc(absOffset / 60), 2); + const minutes = addLeadingZeros(absOffset % 60, 2); + return sign + hours + delimiter + minutes; +} + +const dateLongFormatter = (pattern, formatLong) => { + switch (pattern) { + case "P": + return formatLong.date({ width: "short" }); + case "PP": + return formatLong.date({ width: "medium" }); + case "PPP": + return formatLong.date({ width: "long" }); + case "PPPP": + default: + return formatLong.date({ width: "full" }); + } +}; + +const timeLongFormatter = (pattern, formatLong) => { + switch (pattern) { + case "p": + return formatLong.time({ width: "short" }); + case "pp": + return formatLong.time({ width: "medium" }); + case "ppp": + return formatLong.time({ width: "long" }); + case "pppp": + default: + return formatLong.time({ width: "full" }); + } +}; + +const dateTimeLongFormatter = (pattern, formatLong) => { + const matchResult = pattern.match(/(P+)(p+)?/) || []; + const datePattern = matchResult[1]; + const timePattern = matchResult[2]; + + if (!timePattern) { + return dateLongFormatter(pattern, formatLong); + } + + let dateTimeFormat; + + switch (datePattern) { + case "P": + dateTimeFormat = formatLong.dateTime({ width: "short" }); + break; + case "PP": + dateTimeFormat = formatLong.dateTime({ width: "medium" }); + break; + case "PPP": + dateTimeFormat = formatLong.dateTime({ width: "long" }); + break; + case "PPPP": + default: + dateTimeFormat = formatLong.dateTime({ width: "full" }); + break; + } + + return dateTimeFormat + .replace("{{date}}", dateLongFormatter(datePattern, formatLong)) + .replace("{{time}}", timeLongFormatter(timePattern, formatLong)); +}; + +const longFormatters = { + p: timeLongFormatter, + P: dateTimeLongFormatter, +}; + +const dayOfYearTokenRE = /^D+$/; +const weekYearTokenRE = /^Y+$/; + +const throwTokens = ["D", "DD", "YY", "YYYY"]; + +function isProtectedDayOfYearToken(token) { + return dayOfYearTokenRE.test(token); +} + +function isProtectedWeekYearToken(token) { + return weekYearTokenRE.test(token); +} + +function warnOrThrowProtectedError(token, format, input) { + const _message = message(token, format, input); + console.warn(_message); + if (throwTokens.includes(token)) throw new RangeError(_message); +} + +function message(token, format, input) { + const subject = token[0] === "Y" ? "years" : "days of the month"; + return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`; +} + +// This RegExp consists of three parts separated by `|`: +// - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token +// (one of the certain letters followed by `o`) +// - (\w)\1* matches any sequences of the same letter +// - '' matches two quote characters in a row +// - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('), +// except a single quote symbol, which ends the sequence. +// Two quote characters do not end the sequence. +// If there is no matching single quote +// then the sequence will continue until the end of the string. +// - . matches any single character unmatched by previous parts of the RegExps +const formattingTokensRegExp = + /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g; + +// This RegExp catches symbols escaped by quotes, and also +// sequences of symbols P, p, and the combinations like `PPPPPPPppppp` +const longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g; + +const escapedStringRegExp = /^'([^]*?)'?$/; +const doubleQuoteRegExp = /''/g; +const unescapedLatinCharacterRegExp = /[a-zA-Z]/; + +/** + * The {@link format} function options. + */ + +/** + * @name format + * @alias formatDate + * @category Common Helpers + * @summary Format the date. + * + * @description + * Return the formatted date string in the given format. The result may vary by locale. + * + * > ⚠️ Please note that the `format` tokens differ from Moment.js and other libraries. + * > See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md + * + * The characters wrapped between two single quotes characters (') are escaped. + * Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote. + * (see the last example) + * + * Format of the string is based on Unicode Technical Standard #35: + * https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table + * with a few additions (see note 7 below the table). + * + * Accepted patterns: + * | Unit | Pattern | Result examples | Notes | + * |---------------------------------|---------|-----------------------------------|-------| + * | Era | G..GGG | AD, BC | | + * | | GGGG | Anno Domini, Before Christ | 2 | + * | | GGGGG | A, B | | + * | Calendar year | y | 44, 1, 1900, 2017 | 5 | + * | | yo | 44th, 1st, 0th, 17th | 5,7 | + * | | yy | 44, 01, 00, 17 | 5 | + * | | yyy | 044, 001, 1900, 2017 | 5 | + * | | yyyy | 0044, 0001, 1900, 2017 | 5 | + * | | yyyyy | ... | 3,5 | + * | Local week-numbering year | Y | 44, 1, 1900, 2017 | 5 | + * | | Yo | 44th, 1st, 1900th, 2017th | 5,7 | + * | | YY | 44, 01, 00, 17 | 5,8 | + * | | YYY | 044, 001, 1900, 2017 | 5 | + * | | YYYY | 0044, 0001, 1900, 2017 | 5,8 | + * | | YYYYY | ... | 3,5 | + * | ISO week-numbering year | R | -43, 0, 1, 1900, 2017 | 5,7 | + * | | RR | -43, 00, 01, 1900, 2017 | 5,7 | + * | | RRR | -043, 000, 001, 1900, 2017 | 5,7 | + * | | RRRR | -0043, 0000, 0001, 1900, 2017 | 5,7 | + * | | RRRRR | ... | 3,5,7 | + * | Extended year | u | -43, 0, 1, 1900, 2017 | 5 | + * | | uu | -43, 01, 1900, 2017 | 5 | + * | | uuu | -043, 001, 1900, 2017 | 5 | + * | | uuuu | -0043, 0001, 1900, 2017 | 5 | + * | | uuuuu | ... | 3,5 | + * | Quarter (formatting) | Q | 1, 2, 3, 4 | | + * | | Qo | 1st, 2nd, 3rd, 4th | 7 | + * | | QQ | 01, 02, 03, 04 | | + * | | QQQ | Q1, Q2, Q3, Q4 | | + * | | QQQQ | 1st quarter, 2nd quarter, ... | 2 | + * | | QQQQQ | 1, 2, 3, 4 | 4 | + * | Quarter (stand-alone) | q | 1, 2, 3, 4 | | + * | | qo | 1st, 2nd, 3rd, 4th | 7 | + * | | qq | 01, 02, 03, 04 | | + * | | qqq | Q1, Q2, Q3, Q4 | | + * | | qqqq | 1st quarter, 2nd quarter, ... | 2 | + * | | qqqqq | 1, 2, 3, 4 | 4 | + * | Month (formatting) | M | 1, 2, ..., 12 | | + * | | Mo | 1st, 2nd, ..., 12th | 7 | + * | | MM | 01, 02, ..., 12 | | + * | | MMM | Jan, Feb, ..., Dec | | + * | | MMMM | January, February, ..., December | 2 | + * | | MMMMM | J, F, ..., D | | + * | Month (stand-alone) | L | 1, 2, ..., 12 | | + * | | Lo | 1st, 2nd, ..., 12th | 7 | + * | | LL | 01, 02, ..., 12 | | + * | | LLL | Jan, Feb, ..., Dec | | + * | | LLLL | January, February, ..., December | 2 | + * | | LLLLL | J, F, ..., D | | + * | Local week of year | w | 1, 2, ..., 53 | | + * | | wo | 1st, 2nd, ..., 53th | 7 | + * | | ww | 01, 02, ..., 53 | | + * | ISO week of year | I | 1, 2, ..., 53 | 7 | + * | | Io | 1st, 2nd, ..., 53th | 7 | + * | | II | 01, 02, ..., 53 | 7 | + * | Day of month | d | 1, 2, ..., 31 | | + * | | do | 1st, 2nd, ..., 31st | 7 | + * | | dd | 01, 02, ..., 31 | | + * | Day of year | D | 1, 2, ..., 365, 366 | 9 | + * | | Do | 1st, 2nd, ..., 365th, 366th | 7 | + * | | DD | 01, 02, ..., 365, 366 | 9 | + * | | DDD | 001, 002, ..., 365, 366 | | + * | | DDDD | ... | 3 | + * | Day of week (formatting) | E..EEE | Mon, Tue, Wed, ..., Sun | | + * | | EEEE | Monday, Tuesday, ..., Sunday | 2 | + * | | EEEEE | M, T, W, T, F, S, S | | + * | | EEEEEE | Mo, Tu, We, Th, Fr, Sa, Su | | + * | ISO day of week (formatting) | i | 1, 2, 3, ..., 7 | 7 | + * | | io | 1st, 2nd, ..., 7th | 7 | + * | | ii | 01, 02, ..., 07 | 7 | + * | | iii | Mon, Tue, Wed, ..., Sun | 7 | + * | | iiii | Monday, Tuesday, ..., Sunday | 2,7 | + * | | iiiii | M, T, W, T, F, S, S | 7 | + * | | iiiiii | Mo, Tu, We, Th, Fr, Sa, Su | 7 | + * | Local day of week (formatting) | e | 2, 3, 4, ..., 1 | | + * | | eo | 2nd, 3rd, ..., 1st | 7 | + * | | ee | 02, 03, ..., 01 | | + * | | eee | Mon, Tue, Wed, ..., Sun | | + * | | eeee | Monday, Tuesday, ..., Sunday | 2 | + * | | eeeee | M, T, W, T, F, S, S | | + * | | eeeeee | Mo, Tu, We, Th, Fr, Sa, Su | | + * | Local day of week (stand-alone) | c | 2, 3, 4, ..., 1 | | + * | | co | 2nd, 3rd, ..., 1st | 7 | + * | | cc | 02, 03, ..., 01 | | + * | | ccc | Mon, Tue, Wed, ..., Sun | | + * | | cccc | Monday, Tuesday, ..., Sunday | 2 | + * | | ccccc | M, T, W, T, F, S, S | | + * | | cccccc | Mo, Tu, We, Th, Fr, Sa, Su | | + * | AM, PM | a..aa | AM, PM | | + * | | aaa | am, pm | | + * | | aaaa | a.m., p.m. | 2 | + * | | aaaaa | a, p | | + * | AM, PM, noon, midnight | b..bb | AM, PM, noon, midnight | | + * | | bbb | am, pm, noon, midnight | | + * | | bbbb | a.m., p.m., noon, midnight | 2 | + * | | bbbbb | a, p, n, mi | | + * | Flexible day period | B..BBB | at night, in the morning, ... | | + * | | BBBB | at night, in the morning, ... | 2 | + * | | BBBBB | at night, in the morning, ... | | + * | Hour [1-12] | h | 1, 2, ..., 11, 12 | | + * | | ho | 1st, 2nd, ..., 11th, 12th | 7 | + * | | hh | 01, 02, ..., 11, 12 | | + * | Hour [0-23] | H | 0, 1, 2, ..., 23 | | + * | | Ho | 0th, 1st, 2nd, ..., 23rd | 7 | + * | | HH | 00, 01, 02, ..., 23 | | + * | Hour [0-11] | K | 1, 2, ..., 11, 0 | | + * | | Ko | 1st, 2nd, ..., 11th, 0th | 7 | + * | | KK | 01, 02, ..., 11, 00 | | + * | Hour [1-24] | k | 24, 1, 2, ..., 23 | | + * | | ko | 24th, 1st, 2nd, ..., 23rd | 7 | + * | | kk | 24, 01, 02, ..., 23 | | + * | Minute | m | 0, 1, ..., 59 | | + * | | mo | 0th, 1st, ..., 59th | 7 | + * | | mm | 00, 01, ..., 59 | | + * | Second | s | 0, 1, ..., 59 | | + * | | so | 0th, 1st, ..., 59th | 7 | + * | | ss | 00, 01, ..., 59 | | + * | Fraction of second | S | 0, 1, ..., 9 | | + * | | SS | 00, 01, ..., 99 | | + * | | SSS | 000, 001, ..., 999 | | + * | | SSSS | ... | 3 | + * | Timezone (ISO-8601 w/ Z) | X | -08, +0530, Z | | + * | | XX | -0800, +0530, Z | | + * | | XXX | -08:00, +05:30, Z | | + * | | XXXX | -0800, +0530, Z, +123456 | 2 | + * | | XXXXX | -08:00, +05:30, Z, +12:34:56 | | + * | Timezone (ISO-8601 w/o Z) | x | -08, +0530, +00 | | + * | | xx | -0800, +0530, +0000 | | + * | | xxx | -08:00, +05:30, +00:00 | 2 | + * | | xxxx | -0800, +0530, +0000, +123456 | | + * | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | | + * | Timezone (GMT) | O...OOO | GMT-8, GMT+5:30, GMT+0 | | + * | | OOOO | GMT-08:00, GMT+05:30, GMT+00:00 | 2 | + * | Timezone (specific non-locat.) | z...zzz | GMT-8, GMT+5:30, GMT+0 | 6 | + * | | zzzz | GMT-08:00, GMT+05:30, GMT+00:00 | 2,6 | + * | Seconds timestamp | t | 512969520 | 7 | + * | | tt | ... | 3,7 | + * | Milliseconds timestamp | T | 512969520900 | 7 | + * | | TT | ... | 3,7 | + * | Long localized date | P | 04/29/1453 | 7 | + * | | PP | Apr 29, 1453 | 7 | + * | | PPP | April 29th, 1453 | 7 | + * | | PPPP | Friday, April 29th, 1453 | 2,7 | + * | Long localized time | p | 12:00 AM | 7 | + * | | pp | 12:00:00 AM | 7 | + * | | ppp | 12:00:00 AM GMT+2 | 7 | + * | | pppp | 12:00:00 AM GMT+02:00 | 2,7 | + * | Combination of date and time | Pp | 04/29/1453, 12:00 AM | 7 | + * | | PPpp | Apr 29, 1453, 12:00:00 AM | 7 | + * | | PPPppp | April 29th, 1453 at ... | 7 | + * | | PPPPpppp| Friday, April 29th, 1453 at ... | 2,7 | + * Notes: + * 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale + * are the same as "stand-alone" units, but are different in some languages. + * "Formatting" units are declined according to the rules of the language + * in the context of a date. "Stand-alone" units are always nominative singular: + * + * `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'` + * + * `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'` + * + * 2. Any sequence of the identical letters is a pattern, unless it is escaped by + * the single quote characters (see below). + * If the sequence is longer than listed in table (e.g. `EEEEEEEEEEE`) + * the output will be the same as default pattern for this unit, usually + * the longest one (in case of ISO weekdays, `EEEE`). Default patterns for units + * are marked with "2" in the last column of the table. + * + * `format(new Date(2017, 10, 6), 'MMM') //=> 'Nov'` + * + * `format(new Date(2017, 10, 6), 'MMMM') //=> 'November'` + * + * `format(new Date(2017, 10, 6), 'MMMMM') //=> 'N'` + * + * `format(new Date(2017, 10, 6), 'MMMMMM') //=> 'November'` + * + * `format(new Date(2017, 10, 6), 'MMMMMMM') //=> 'November'` + * + * 3. Some patterns could be unlimited length (such as `yyyyyyyy`). + * The output will be padded with zeros to match the length of the pattern. + * + * `format(new Date(2017, 10, 6), 'yyyyyyyy') //=> '00002017'` + * + * 4. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales. + * These tokens represent the shortest form of the quarter. + * + * 5. The main difference between `y` and `u` patterns are B.C. years: + * + * | Year | `y` | `u` | + * |------|-----|-----| + * | AC 1 | 1 | 1 | + * | BC 1 | 1 | 0 | + * | BC 2 | 2 | -1 | + * + * Also `yy` always returns the last two digits of a year, + * while `uu` pads single digit years to 2 characters and returns other years unchanged: + * + * | Year | `yy` | `uu` | + * |------|------|------| + * | 1 | 01 | 01 | + * | 14 | 14 | 14 | + * | 376 | 76 | 376 | + * | 1453 | 53 | 1453 | + * + * The same difference is true for local and ISO week-numbering years (`Y` and `R`), + * except local week-numbering years are dependent on `options.weekStartsOn` + * and `options.firstWeekContainsDate` (compare [getISOWeekYear](https://date-fns.org/docs/getISOWeekYear) + * and [getWeekYear](https://date-fns.org/docs/getWeekYear)). + * + * 6. Specific non-location timezones are currently unavailable in `date-fns`, + * so right now these tokens fall back to GMT timezones. + * + * 7. These patterns are not in the Unicode Technical Standard #35: + * - `i`: ISO day of week + * - `I`: ISO week of year + * - `R`: ISO week-numbering year + * - `t`: seconds timestamp + * - `T`: milliseconds timestamp + * - `o`: ordinal number modifier + * - `P`: long localized date + * - `p`: long localized time + * + * 8. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years. + * You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md + * + * 9. `D` and `DD` tokens represent days of the year but they are often confused with days of the month. + * You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md + * + * @param date - The original date + * @param format - The string of tokens + * @param options - An object with options + * + * @returns The formatted date string + * + * @throws `date` must not be Invalid Date + * @throws `options.locale` must contain `localize` property + * @throws `options.locale` must contain `formatLong` property + * @throws use `yyyy` instead of `YYYY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md + * @throws use `yy` instead of `YY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md + * @throws use `d` instead of `D` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md + * @throws use `dd` instead of `DD` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md + * @throws format string contains an unescaped latin alphabet character + * + * @example + * // Represent 11 February 2014 in middle-endian format: + * const result = format(new Date(2014, 1, 11), 'MM/dd/yyyy') + * //=> '02/11/2014' + * + * @example + * // Represent 2 July 2014 in Esperanto: + * import { eoLocale } from 'date-fns/locale/eo' + * const result = format(new Date(2014, 6, 2), "do 'de' MMMM yyyy", { + * locale: eoLocale + * }) + * //=> '2-a de julio 2014' + * + * @example + * // Escape string by single quote characters: + * const result = format(new Date(2014, 6, 2, 15), "h 'o''clock'") + * //=> "3 o'clock" + */ +function format(date, formatStr, options) { + const defaultOptions = getDefaultOptions(); + const locale = options?.locale ?? defaultOptions.locale ?? enUS; + + const firstWeekContainsDate = + options?.firstWeekContainsDate ?? + options?.locale?.options?.firstWeekContainsDate ?? + defaultOptions.firstWeekContainsDate ?? + defaultOptions.locale?.options?.firstWeekContainsDate ?? + 1; + + const weekStartsOn = + options?.weekStartsOn ?? + options?.locale?.options?.weekStartsOn ?? + defaultOptions.weekStartsOn ?? + defaultOptions.locale?.options?.weekStartsOn ?? + 0; + + const originalDate = toDate(date, options?.in); + + if (!isValid(originalDate)) { + throw new RangeError("Invalid time value"); + } + + let parts = formatStr + .match(longFormattingTokensRegExp) + .map((substring) => { + const firstCharacter = substring[0]; + if (firstCharacter === "p" || firstCharacter === "P") { + const longFormatter = longFormatters[firstCharacter]; + return longFormatter(substring, locale.formatLong); + } + return substring; + }) + .join("") + .match(formattingTokensRegExp) + .map((substring) => { + // Replace two single quote characters with one single quote character + if (substring === "''") { + return { isToken: false, value: "'" }; + } + + const firstCharacter = substring[0]; + if (firstCharacter === "'") { + return { isToken: false, value: cleanEscapedString(substring) }; + } + + if (formatters[firstCharacter]) { + return { isToken: true, value: substring }; + } + + if (firstCharacter.match(unescapedLatinCharacterRegExp)) { + throw new RangeError( + "Format string contains an unescaped latin alphabet character `" + + firstCharacter + + "`", + ); + } + + return { isToken: false, value: substring }; + }); + + // invoke localize preprocessor (only for french locales at the moment) + if (locale.localize.preprocessor) { + parts = locale.localize.preprocessor(originalDate, parts); + } + + const formatterOptions = { + firstWeekContainsDate, + weekStartsOn, + locale, + }; + + return parts + .map((part) => { + if (!part.isToken) return part.value; + + const token = part.value; + + if ( + (!options?.useAdditionalWeekYearTokens && + isProtectedWeekYearToken(token)) || + (!options?.useAdditionalDayOfYearTokens && + isProtectedDayOfYearToken(token)) + ) { + warnOrThrowProtectedError(token, formatStr, String(date)); + } + + const formatter = formatters[token[0]]; + return formatter(originalDate, token, locale.localize, formatterOptions); + }) + .join(""); +} + +function cleanEscapedString(input) { + const matched = input.match(escapedStringRegExp); + + if (!matched) { + return input; + } + + return matched[1].replace(doubleQuoteRegExp, "'"); +} + +export { Button as $, Anchor as A, SvgAlertWarningStroke as B, Close$4 as C, Datepicker as D, MediaInput as E, Field$1 as F, SvgCreditCardStroke as G, Hint$2 as H, Input as I, getColorV8 as J, KEYS as K, Label$3 as L, Message$2 as M, Notification as N, Option as O, Progress as P, Header$1 as Q, SvgCheckCircleStroke as R, Span as S, Title as T, useModalContainer as U, Modal as V, Body as W, Accordion as X, Paragraph as Y, Footer as Z, FooterItem as _, useTranslation as a, Close as a0, addFlashNotification as a1, debounce$3 as a2, Alert as a3, initI18next as a4, loadTranslations as a5, reactDomExports as a6, ThemeProviders as a7, createTheme as a8, FLASH_NOTIFICATIONS_KEY as a9, api as aa, Ye as ab, cn as ac, yt as ad, je as ae, format as af, Textarea as b, commonjsGlobal as c, Field as d, Combobox as e, Message as f, getDefaultExportFromCjs as g, Hint as h, Checkbox as i, jsxRuntimeExports as j, Label$1 as k, OptGroup as l, FileList as m, File as n, Tooltip as o, purify as p, mime as q, reactExports as r, styled as s, useDropzone as t, useToast as u, FileUpload as v, useGrid as w, focusStyles as x, FauxInput as y, Tag as z }; diff --git a/assets/tailwind-output.css b/assets/tailwind-output.css index e7b8a89e2..08bf49cba 100644 --- a/assets/tailwind-output.css +++ b/assets/tailwind-output.css @@ -789,6 +789,10 @@ video { margin-bottom: 0.1875rem; } +.ml-0\.5 { + margin-left: 0.125rem; +} + .ml-2 { margin-left: 0.5rem; } @@ -853,6 +857,10 @@ video { margin-top: 1.875rem; } +.mt-\[1\.92rem\] { + margin-top: 1.92rem; +} + .mt-margin-mobile { margin-top: 1.5rem; } @@ -1048,6 +1056,11 @@ video { width: 3.75rem; } +.w-fit { + width: -moz-fit-content; + width: fit-content; +} + .w-full { width: 100%; } @@ -1302,6 +1315,10 @@ video { border-radius: 0.25rem; } +.rounded-\[0\.25rem\] { + border-radius: 0.25rem; +} + .rounded-\[1\.25rem\] { border-radius: 1.25rem; } @@ -1650,6 +1667,11 @@ video { padding-bottom: 0.75rem !important; } +.px-1\.5 { + padding-left: 0.375rem; + padding-right: 0.375rem; +} + .px-2 { padding-left: 0.5rem; padding-right: 0.5rem; @@ -3379,10 +3401,6 @@ html:has(.ArticlePage) { margin-top: 1.5rem; } -.last\:hidden:last-child { - display: none; -} - .focus-within\:\!border-light-surface-3:focus-within { border-color: rgba(34,34,34,0.05) !important; } @@ -3520,6 +3538,10 @@ html:has(.ArticlePage) { opacity: 1; } +.peer:focus-within ~ .peer-focus-within\:hidden { + display: none; +} + .data-\[active\]\:bg-light-surface-3[data-active] { background-color: rgba(34,34,34,0.05); } diff --git a/package.json b/package.json index a7296c2d4..cacead1ae 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "@zendeskgarden/react-typography": "8.76.2", "@zendeskgarden/svg-icons": "^6.34.0", "classnames": "^2.5.1", + "date-fns": "^4.1.0", "dompurify": "3.0.11", "eslint-plugin-check-file": "^2.6.2", "i18next": "^23.10.1", diff --git a/rollup.config.mjs b/rollup.config.mjs index 6b6af3c2f..b61c8787c 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -42,6 +42,7 @@ export default defineConfig([ 'category-page': 'src/modules/category-page/index.ts', 'section-page': 'src/modules/section-page/index.ts', 'side-nav': 'src/modules/side-nav/index.ts', + "search-result-page": "src/modules/search-result-page/index.ts", }, output: { dir: 'assets', diff --git a/src/lib/types.ts b/src/lib/types.ts index 3714eed8a..c118e0efb 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -1,4 +1,4 @@ -import { ColoredCardsIcon } from "../svgs/Icons"; +import { ColoredCardsIcon } from '../svgs/Icons'; export type Tag = { title: string; @@ -9,35 +9,35 @@ export type GlobalSettings = { navigationTopics: Tag[] | null; topNavigationApp: { id: string; - key: string | ""; // Label of the link - value: string | ""; // URL of the link + key: string | ''; // Label of the link + value: string | ''; // URL of the link } | null; footerLinksTopics: | { id: string; - key: string | ""; // Label of the link - value: string | ""; // URL of the link + key: string | ''; // Label of the link + value: string | ''; // URL of the link }[] | null; footerLinksEcosystem: | { id: string; - key: string | ""; // Label of the link - value: string | ""; // URL of the link + key: string | ''; // Label of the link + value: string | ''; // URL of the link }[] | null; footerLinksCompany: | { id: string; - key: string | ""; // Label of the link - value: string | ""; // URL of the link + key: string | ''; // Label of the link + value: string | ''; // URL of the link }[] | null; footerLinksHelp: | { id: string; - key: string | ""; // Label of the link - value: string | ""; // URL of the link + key: string | ''; // Label of the link + value: string | ''; // URL of the link }[] | null; footerGithubLink: string | null; @@ -47,14 +47,14 @@ export type GlobalSettings = { connectBlockSupportTitle: string; connectBlockSupportButton: { id: string; - key: string | ""; // Label of the link - value: string | ""; // URL of the link + key: string | ''; // Label of the link + value: string | ''; // URL of the link }; connectBlockSocialTitle: string; connectBlockSocialButton: { id: string; - key: string | ""; // Label of the link - value: string | ""; // URL of the link + key: string | ''; // Label of the link + value: string | ''; // URL of the link }; connectBlockNewsletterTitle: string; }; @@ -161,7 +161,7 @@ export interface Navigation { export type Link = { name: string; url: string; - target?: "_blank" | "_self"; + target?: '_blank' | '_self'; }; export type FooterPageData = { @@ -183,7 +183,7 @@ export type ConnectBlock = { newsletterTitle: string; }; -export type ColoredCardsColor = "pink" | "green" | "blue" | "orange"; +export type ColoredCardsColor = 'pink' | 'green' | 'blue' | 'orange'; export type HomepageData = { heros: { @@ -253,3 +253,45 @@ export type NavState = { section?: number; article?: number; }; + +export type SearchPageData = { + query: string; + results: SearchResult[]; + typeFilters: TypeFilter[]; +}; + +export type SearchResult = { + url: string; + title: string; + text: string; + vote_sum: number; + created_at: string; + edited_at: string | null; + comment_count: number; + meta: string; + type: string; + path_steps: { + url: string; + name: string; + target: string; + }[]; + author: { + name: string; + url: string; + agent: boolean; + avatar_url: string; + signed_in: boolean; + id: number; + role: string; + }; + is_external: boolean; +}; + +type TypeFilter = { + identifier: string; + url: string; + name: string; + selected: boolean; + label: string; + count: number; +}; diff --git a/src/modules/search-result-page/SearchResultPageModule.tsx b/src/modules/search-result-page/SearchResultPageModule.tsx new file mode 100644 index 000000000..59f61c3a8 --- /dev/null +++ b/src/modules/search-result-page/SearchResultPageModule.tsx @@ -0,0 +1,181 @@ +import { FC, useRef, useEffect } from 'react'; +import { SearchPageData } from '../../lib/types'; +import { format } from 'date-fns'; + +type Props = { + searchPageData: SearchPageData; +}; + +const parseTextWithEmphasis = (text: string): (string | JSX.Element)[] => { + const parts = text.split(/(.*?<\/em>)/g); + return parts.map((part, index) => + part.startsWith('') && part.endsWith('') ? ( + {part.slice(4, -5)} + ) : ( + part + ) + ); +}; + +const formatDate = (dateStr: string): string => { + const date = new Date(dateStr); + return format(date, 'MMMM dd, yyyy HH:mm'); +}; + +const ChevronIcon: FC = () => ( + + + +); + +const Breadcrumbs: FC<{ pathSteps: { url: string; name: string; target: string }[] }> = ({ + pathSteps, +}) => ( +
    + {pathSteps.map((step, index) => ( +
  1. + + {step.name} + + {index < pathSteps.length - 1 && } +
  2. + ))} +
+); + +const TypeFilterList: FC<{ + typeFilters: { + identifier: string; + url: string; + name: string; + selected: boolean; + count: number; + }[]; +}> = ({ typeFilters }) => ( + +); + +export const SearchResultPageModule: FC = ({ searchPageData }) => { + const { query, results, typeFilters } = searchPageData; + const searchBarRef = useRef(null); + + useEffect(() => { + const timeout = setTimeout(() => { + const searchBarPlaceholder = document.getElementById('search-bar-search-result'); + if (searchBarPlaceholder && searchBarRef.current) { + searchBarRef.current.appendChild(searchBarPlaceholder); + searchBarPlaceholder.style.opacity = '1'; + } + }, 100); + + return () => clearTimeout(timeout); + }, []); + + if (!query) return null; + + return ( +
+
+
+ +
+
+
+ +

+ {results ? ( + <> + {results.length} results for "{query}" + + ) : ( +
+
+ No result for {query} +
+
+ )} +

+
+ {results ? ( +
    + {results.map((result) => ( +
  • +
    +
    +

    + {result.title} +

    + +
    +

    + {parseTextWithEmphasis(result.text)} +

    + + {formatDate(result.created_at)} + +
    +
    +
  • + ))} +
+ ) : ( + + )} +
+
+
+
+ ); +}; diff --git a/src/modules/search-result-page/index.ts b/src/modules/search-result-page/index.ts new file mode 100644 index 000000000..e222aeecd --- /dev/null +++ b/src/modules/search-result-page/index.ts @@ -0,0 +1 @@ +export { renderSearchResults } from './renderSearchResults'; diff --git a/src/modules/search-result-page/renderSearchResults.tsx b/src/modules/search-result-page/renderSearchResults.tsx new file mode 100644 index 000000000..e44c8b18f --- /dev/null +++ b/src/modules/search-result-page/renderSearchResults.tsx @@ -0,0 +1,18 @@ +import { render } from 'react-dom'; +import { SearchPageData } from '../../lib/types'; +import { Settings } from '../shared'; +import { createTheme, ThemeProviders } from '../shared'; +import { SearchResultPageModule } from './SearchResultPageModule'; + +export async function renderSearchResults( + settings: Settings, + searchData: SearchPageData, + container: HTMLElement +) { + render( + + + , + container + ); +} diff --git a/templates/document_head.hbs b/templates/document_head.hbs index 7489a80a0..9757767ec 100644 --- a/templates/document_head.hbs +++ b/templates/document_head.hbs @@ -20,6 +20,7 @@ "category-page": "{{asset 'category-page-bundle.js'}}", "section-page": "{{asset 'section-page-bundle.js'}}", "side-nav": "{{asset 'side-nav-bundle.js'}}", + "search-result-page": "{{asset 'search-result-page-bundle.js'}}", "new-request-form-translations": "{{asset 'new-request-form-translations-bundle.js'}}", "shared": "{{asset 'shared-bundle.js'}}", "wysiwyg": "{{asset 'wysiwyg-bundle.js'}}", diff --git a/templates/header.hbs b/templates/header.hbs index a88fafcfd..1c23c71e1 100644 --- a/templates/header.hbs +++ b/templates/header.hbs @@ -6,7 +6,8 @@ - {{search submit=false instant=settings.instant_search class='search search-full'}} + {{search submit=false instant=settings.instant_search class='search search-full peer'}} +
⌘ K
{{!-- for mobile nav search bar --}} diff --git a/templates/search_results.hbs b/templates/search_results.hbs index 6ea05b867..ab620375b 100644 --- a/templates/search_results.hbs +++ b/templates/search_results.hbs @@ -1,297 +1,33 @@ -
-
- -
-
- -

- {{#if results}} - {{#is current_filter.identifier 'unified'}} - {{#if content_tag_filters }} - {{#each (filter content_tag_filters on="selected" equals=true)}} - {{t 'results_content_tag' content_tag=name count=../results_count}} - {{/each}} - {{else}} - {{t 'results' query=query count=results_count}} - {{/if}} - {{else}} - {{#if content_tag_filters }} - {{#each (filter content_tag_filters on="selected" equals=true)}} - {{t 'results_content_tag' content_tag=name count=../results_count}} - {{/each}} - {{else}} - {{#unless current_subfilter.identifier}} - {{t 'results' query=query count=results_count}} - {{else}} - {{t 'results_with_scope' query=query count=results_count scope_name=current_subfilter.name}} - {{/unless}} - {{/if}} - {{/is}} - {{/if}} -

-
-
-

{{ t 'search' }}

- {{search submit=false}} -
-
- {{#if results}} -
    - {{#each results}} -
  • -
    -
    -
    -

    - - {{title}} - {{#if is_external}} - - - - - {{/if}} - -

    -
    - {{#if vote_sum}} - - - {{t 'votes_sum' count=vote_sum}} - - - - {{/if}} - {{#if comment_count}} - - - {{t 'comments_count' count=comment_count}} - - - - {{/if}} -
    -
    -
    - -
    -
    -

    {{text}}

    - -
    -
  • -
    - {{/each}} -
- {{else}} -
- -
- {{t 'no_results_unified_start_new_search'}} -
-
- {{t 'no_results_unified_enter_keywords'}} -
-
- {{#link 'help_center'}} - {{t 'go_to_help_center'}} - - - - {{/link}} -
-
- {{/if}} -
+ {{!-- need this if statement to deliver type filters to the view --}} + {{#if source_filters}} + {{/if}} +
+
+

{{ t 'search' }}

+ {{search submit=false}}
+
{{pagination}}
+ + \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index a051fa891..aa4646eeb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4686,6 +4686,11 @@ date-fns@^3.0.0: resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-3.6.0.tgz#f20ca4fe94f8b754951b24240676e8618c0206bf" integrity sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww== +date-fns@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-4.1.0.tgz#64b3d83fff5aa80438f5b1a633c2e83b8a1c2d14" + integrity sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg== + dateformat@^3.0.0: version "3.0.3" resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae"