@bikdotai/bik-component-library 0.0.867 → 0.0.868-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/chip-selector/ChipSelector.js +2 -0
- package/dist/cjs/components/chip-selector/ChipSelector.js.map +1 -0
- package/dist/cjs/components/chip-selector/ChipSelector.styled.js +36 -0
- package/dist/cjs/components/chip-selector/ChipSelector.styled.js.map +1 -0
- package/dist/cjs/components/chip-selector/ChipSelectorGroup.js +2 -0
- package/dist/cjs/components/chip-selector/ChipSelectorGroup.js.map +1 -0
- package/dist/cjs/components/combo-box/ComboBox.js +2 -0
- package/dist/cjs/components/combo-box/ComboBox.js.map +1 -0
- package/dist/cjs/components/combo-box/ComboBox.styled.js +33 -0
- package/dist/cjs/components/combo-box/ComboBox.styled.js.map +1 -0
- package/dist/cjs/components/datePicker/DatePickerWrapper.js +1 -1
- package/dist/cjs/components/datePicker/DatePickerWrapper.js.map +1 -1
- package/dist/cjs/components/schedule-builder/RefreshSegmentToggle.js +2 -0
- package/dist/cjs/components/schedule-builder/RefreshSegmentToggle.js.map +1 -0
- package/dist/cjs/components/schedule-builder/ScheduleBuilder.js +2 -0
- package/dist/cjs/components/schedule-builder/ScheduleBuilder.js.map +1 -0
- package/dist/cjs/components/schedule-builder/ScheduleBuilder.styled.js +138 -0
- package/dist/cjs/components/schedule-builder/ScheduleBuilder.styled.js.map +1 -0
- package/dist/cjs/components/schedule-builder/ScheduleEndPicker.js +2 -0
- package/dist/cjs/components/schedule-builder/ScheduleEndPicker.js.map +1 -0
- package/dist/cjs/components/schedule-builder/ScheduleFrequencyPicker.js +2 -0
- package/dist/cjs/components/schedule-builder/ScheduleFrequencyPicker.js.map +1 -0
- package/dist/cjs/components/schedule-builder/ScheduleHelper.js +2 -0
- package/dist/cjs/components/schedule-builder/ScheduleHelper.js.map +1 -0
- package/dist/cjs/components/schedule-builder/SendModeSelector.js +2 -0
- package/dist/cjs/components/schedule-builder/SendModeSelector.js.map +1 -0
- package/dist/cjs/components/schedule-builder/StartDateTimePicker.js +2 -0
- package/dist/cjs/components/schedule-builder/StartDateTimePicker.js.map +1 -0
- package/dist/cjs/components/schedule-builder/UpcomingRunsPreview.js +2 -0
- package/dist/cjs/components/schedule-builder/UpcomingRunsPreview.js.map +1 -0
- package/dist/cjs/components/schedule-builder/model.js +2 -0
- package/dist/cjs/components/schedule-builder/model.js.map +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/esm/components/chip-selector/ChipSelector.d.ts +9 -0
- package/dist/esm/components/chip-selector/ChipSelector.js +27 -0
- package/dist/esm/components/chip-selector/ChipSelector.js.map +1 -0
- package/dist/esm/components/chip-selector/ChipSelector.styled.d.ts +10 -0
- package/dist/esm/components/chip-selector/ChipSelector.styled.js +48 -0
- package/dist/esm/components/chip-selector/ChipSelector.styled.js.map +1 -0
- package/dist/esm/components/chip-selector/ChipSelectorGroup.d.ts +10 -0
- package/dist/esm/components/chip-selector/ChipSelectorGroup.js +48 -0
- package/dist/esm/components/chip-selector/ChipSelectorGroup.js.map +1 -0
- package/dist/esm/components/chip-selector/index.d.ts +4 -0
- package/dist/esm/components/chip-selector/model.d.ts +106 -0
- package/dist/esm/components/combo-box/ComboBox.d.ts +15 -0
- package/dist/esm/components/combo-box/ComboBox.js +118 -0
- package/dist/esm/components/combo-box/ComboBox.js.map +1 -0
- package/dist/esm/components/combo-box/ComboBox.styled.d.ts +12 -0
- package/dist/esm/components/combo-box/ComboBox.styled.js +40 -0
- package/dist/esm/components/combo-box/ComboBox.styled.js.map +1 -0
- package/dist/esm/components/combo-box/index.d.ts +3 -0
- package/dist/esm/components/combo-box/model.d.ts +55 -0
- package/dist/esm/components/datePicker/DatePickerWrapper.d.ts +7 -0
- package/dist/esm/components/datePicker/DatePickerWrapper.js +66 -64
- package/dist/esm/components/datePicker/DatePickerWrapper.js.map +1 -1
- package/dist/esm/components/datePicker/index.d.ts +1 -0
- package/dist/esm/components/schedule-builder/RefreshSegmentToggle.d.ts +22 -0
- package/dist/esm/components/schedule-builder/RefreshSegmentToggle.js +31 -0
- package/dist/esm/components/schedule-builder/RefreshSegmentToggle.js.map +1 -0
- package/dist/esm/components/schedule-builder/ScheduleBuilder.d.ts +88 -0
- package/dist/esm/components/schedule-builder/ScheduleBuilder.js +105 -0
- package/dist/esm/components/schedule-builder/ScheduleBuilder.js.map +1 -0
- package/dist/esm/components/schedule-builder/ScheduleBuilder.styled.d.ts +81 -0
- package/dist/esm/components/schedule-builder/ScheduleBuilder.styled.js +168 -0
- package/dist/esm/components/schedule-builder/ScheduleBuilder.styled.js.map +1 -0
- package/dist/esm/components/schedule-builder/ScheduleEndPicker.d.ts +17 -0
- package/dist/esm/components/schedule-builder/ScheduleEndPicker.js +105 -0
- package/dist/esm/components/schedule-builder/ScheduleEndPicker.js.map +1 -0
- package/dist/esm/components/schedule-builder/ScheduleFrequencyPicker.d.ts +21 -0
- package/dist/esm/components/schedule-builder/ScheduleFrequencyPicker.js +136 -0
- package/dist/esm/components/schedule-builder/ScheduleFrequencyPicker.js.map +1 -0
- package/dist/esm/components/schedule-builder/ScheduleHelper.d.ts +110 -0
- package/dist/esm/components/schedule-builder/ScheduleHelper.js +196 -0
- package/dist/esm/components/schedule-builder/ScheduleHelper.js.map +1 -0
- package/dist/esm/components/schedule-builder/SendModeSelector.d.ts +29 -0
- package/dist/esm/components/schedule-builder/SendModeSelector.js +41 -0
- package/dist/esm/components/schedule-builder/SendModeSelector.js.map +1 -0
- package/dist/esm/components/schedule-builder/StartDateTimePicker.d.ts +44 -0
- package/dist/esm/components/schedule-builder/StartDateTimePicker.js +119 -0
- package/dist/esm/components/schedule-builder/StartDateTimePicker.js.map +1 -0
- package/dist/esm/components/schedule-builder/UpcomingRunsPreview.d.ts +19 -0
- package/dist/esm/components/schedule-builder/UpcomingRunsPreview.js +44 -0
- package/dist/esm/components/schedule-builder/UpcomingRunsPreview.js.map +1 -0
- package/dist/esm/components/schedule-builder/index.d.ts +17 -0
- package/dist/esm/components/schedule-builder/model.d.ts +69 -0
- package/dist/esm/components/schedule-builder/model.js +8 -0
- package/dist/esm/components/schedule-builder/model.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +716 -675
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScheduleHelper.js","sources":["../../../../src/components/schedule-builder/ScheduleHelper.ts"],"sourcesContent":["import { format as formatDate } from 'date-fns';\nimport { ChipOption } from '../chip-selector';\nimport {\n\tMONTHLY_REPEAT_OPTION,\n\tRECURRENCE_END_MODE,\n\tRECURRENCE_FREQUENCY,\n\tRecurrenceSummary,\n\tRecurrenceValue,\n} from './model';\n\n/** How many upcoming runs the preview shows by default. */\nexport const UPCOMING_RUNS_PREVIEW_COUNT = 3;\n\n/** Upper bound on `endAfterRuns`, matching the 3-digit input in the design. */\nexport const MAX_RECURRENCE_RUNS = 999;\n\n/**\n * Width of a single chip in the \"Repeat on\" pickers.\n *\n * Shared by the weekly day chips and the monthly date chips: both grids are\n * drawn to the same 44px square in the design, and the monthly grid's 337px\n * width assumes it, so the two cannot be sized independently.\n */\nexport const CHIP_WIDTH = 44;\n\n/** Highest date the monthly grid offers. */\nexport const MAX_DATE_OF_MONTH = 31;\n\n/** Sentinel chip value for \"Last day of the month\", which is not a date. */\nexport const LAST_DAY_CHIP_VALUE = 'LAST_DAY';\n\n/**\n * Safety bound for the day-by-day walk.\n *\n * Sized for the worst realistic case rather than the common one: three runs on\n * the 29th starting just after February in a non-leap year waits out three\n * Februaries, so roughly four years of scanning. Weekly needs at most 7 days\n * per run.\n */\nconst MAX_DAYS_SCANNED = 1600;\n\n/** Short day labels, indexed by JS day number (0 = Sunday). */\nexport const DAY_LABELS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\n\n/** Selecting all seven days is stored as DAILY rather than a full weekly set. */\nexport const DAYS_IN_WEEK = 7;\n\n/**\n * Chips for the weekly \"Repeat on\" picker. Only the first letter is shown, so\n * each chip carries the full day name for screen readers — S, T and S repeat.\n */\nexport const DAY_CHIP_OPTIONS: ChipOption[] = DAY_LABELS.map(\n\t(label, dayIndex) => ({\n\t\tvalue: dayIndex,\n\t\tlabel: label.charAt(0),\n\t\tariaLabel: label,\n\t}),\n);\n\n/**\n * Chips for the monthly \"Repeat on\" grid — 1 to 31, then \"Last day of the\n * month\" as an independent option rather than an alias for the 31st.\n */\nexport const DATE_CHIP_OPTIONS: ChipOption[] = [\n\t...Array.from({ length: MAX_DATE_OF_MONTH }, (_, index) => ({\n\t\tvalue: index + 1,\n\t\tlabel: String(index + 1),\n\t})),\n\t{\n\t\tvalue: LAST_DAY_CHIP_VALUE,\n\t\tlabel: 'Last day of the month',\n\t\tfitContent: true,\n\t},\n];\n\n/** Mon–Fri, used to collapse a full working week into \"every weekday\". */\nconst WEEKDAY_INDICES = [1, 2, 3, 4, 5];\n\n/** Sat–Sun, collapsed into \"every weekend\". */\nconst WEEKEND_INDICES = [0, 6];\n\n/**\n * Weekly day order for the summary. Monday-first by design, which is not the\n * JS `getDay()` order the chips are indexed by (Sunday-first).\n */\nconst SUMMARY_DAY_ORDER = [1, 2, 3, 4, 5, 6, 0];\n\n/** Dates that do not exist in every month, with the months that skip them. */\nconst SKIPPED_MONTH_CAPTIONS: Record<number, string> = {\n\t29: 'Skipped most Februaries.',\n\t30: 'Skipped in February.',\n\t31: 'Skipped in months without a 31st (Apr, Jun, Sep, Nov).',\n};\n\n/**\n * \"1st\", \"22nd\", \"13th\" — the 11/12/13 exception is why this is not a plain\n * lookup on the last digit.\n */\nexport const ordinal = (value: number): string => {\n\tif ([11, 12, 13].includes(value % 100)) return `${value}th`;\n\n\tswitch (value % 10) {\n\t\tcase 1:\n\t\t\treturn `${value}st`;\n\t\tcase 2:\n\t\t\treturn `${value}nd`;\n\t\tcase 3:\n\t\t\treturn `${value}rd`;\n\t\tdefault:\n\t\t\treturn `${value}th`;\n\t}\n};\n\n/**\n * \"Mon\", \"Mon and Tue\", \"Mon, Tue and Thu\" — no Oxford comma, and always \"and\"\n * rather than \"&\". Shared by the weekly day names and the monthly ordinals.\n */\nexport const joinList = (items: string[]): string => {\n\tif (items.length <= 1) return items[0] ?? '';\n\tif (items.length === 2) return `${items[0]} and ${items[1]}`;\n\treturn `${items.slice(0, -1).join(', ')} and ${items[items.length - 1]}`;\n};\n\n/** Caption warning that a chosen date does not exist in every month. */\nexport const getSkippedMonthCaption = (\n\tdatesOfMonth: number[] | undefined,\n): string | null => {\n\tconst captions = (datesOfMonth ?? [])\n\t\t.map((date) => SKIPPED_MONTH_CAPTIONS[date])\n\t\t.filter(Boolean);\n\treturn captions.length ? captions.join(' ') : null;\n};\n\n/**\n * Works out when a recurring campaign actually runs.\n *\n * Kept free of React so the schedule preview and the eventual publish payload\n * can both read run dates from one place.\n */\nexport class ScheduleHelper {\n\tprivate readonly recurrence: RecurrenceValue;\n\n\tconstructor(recurrence: RecurrenceValue | undefined) {\n\t\tthis.recurrence = recurrence ?? {};\n\t}\n\n\tget frequency(): RECURRENCE_FREQUENCY {\n\t\treturn this.recurrence.frequency ?? RECURRENCE_FREQUENCY.DAILY;\n\t}\n\n\tget endMode(): RECURRENCE_END_MODE {\n\t\treturn this.recurrence.endMode ?? RECURRENCE_END_MODE.NEVER;\n\t}\n\n\t/** Days a weekly recurrence repeats on, as JS day indices. */\n\tget daysOfWeek(): number[] {\n\t\treturn this.recurrence.daysOfWeek ?? [];\n\t}\n\n\t/** Dates a monthly recurrence repeats on (1–31). */\n\tget datesOfMonth(): number[] {\n\t\treturn this.recurrence.datesOfMonth ?? [];\n\t}\n\n\t/** Whether a monthly recurrence also runs on the last day of every month. */\n\tget lastDaySelected(): boolean {\n\t\treturn !!this.recurrence.lastDaySelected;\n\t}\n\n\t/** A weekly recurrence cannot run until at least one day is picked. */\n\tget isMissingWeeklyDays(): boolean {\n\t\treturn (\n\t\t\tthis.frequency === RECURRENCE_FREQUENCY.WEEKLY && !this.daysOfWeek.length\n\t\t);\n\t}\n\n\t/** A monthly recurrence needs at least one date, or the last-day option. */\n\tget isMissingMonthlyDates(): boolean {\n\t\treturn (\n\t\t\tthis.frequency === RECURRENCE_FREQUENCY.MONTHLY &&\n\t\t\t!this.datesOfMonth.length &&\n\t\t\t!this.lastDaySelected\n\t\t);\n\t}\n\n\t/** True when the current selection cannot produce any run dates. */\n\tget isMissingRunDays(): boolean {\n\t\treturn this.isMissingWeeklyDays || this.isMissingMonthlyDates;\n\t}\n\n\t/**\n\t * Advances a date by one day.\n\t *\n\t * Every frequency walks day by day so `isRunDay` decides what counts. Monthly\n\t * cannot use `setMonth`: it rolls a 31st into the following month for shorter\n\t * months (31 Jan -> 3 Mar), whereas a missing date must skip that month\n\t * outright.\n\t */\n\tprivate addInterval(date: Date): Date {\n\t\tconst next = new Date(date);\n\t\tnext.setDate(next.getDate() + 1);\n\t\treturn next;\n\t}\n\n\t/** Last calendar date of the month the given date falls in. */\n\tprivate static lastDateOfMonth(date: Date): number {\n\t\treturn new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();\n\t}\n\n\t/** Whether a candidate date is one the campaign actually runs on. */\n\tprivate isRunDay(date: Date): boolean {\n\t\tif (this.frequency === RECURRENCE_FREQUENCY.WEEKLY) {\n\t\t\treturn this.daysOfWeek.includes(date.getDay());\n\t\t}\n\n\t\tif (this.frequency === RECURRENCE_FREQUENCY.MONTHLY) {\n\t\t\tconst dayOfMonth = date.getDate();\n\t\t\tif (this.datesOfMonth.includes(dayOfMonth)) return true;\n\t\t\treturn (\n\t\t\t\tthis.lastDaySelected &&\n\t\t\t\tdayOfMonth === ScheduleHelper.lastDateOfMonth(date)\n\t\t\t);\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Next `limit` run dates from `startDate`, respecting the end rule.\n\t *\n\t * Returns fewer than `limit` when the recurrence ends first, which is what\n\t * lets the preview stop honestly instead of inventing runs.\n\t */\n\tcomputeUpcomingRuns(\n\t\tstartDate: Date | null | undefined,\n\t\tlimit: number = UPCOMING_RUNS_PREVIEW_COUNT,\n\t): Date[] {\n\t\tif (!startDate || Number.isNaN(startDate.getTime())) return [];\n\t\t// Weekly with no day picked, or monthly with no date, has no run dates yet.\n\t\tif (this.isMissingRunDays) return [];\n\n\t\tconst runs: Date[] = [];\n\n\t\t// AFTER_RUNS counts the start date as run 1, so the cap includes it.\n\t\tconst { endAfterRuns } = this.recurrence;\n\t\tconst maxRuns =\n\t\t\tthis.endMode === RECURRENCE_END_MODE.AFTER_RUNS &&\n\t\t\ttypeof endAfterRuns === 'number' &&\n\t\t\tendAfterRuns > 0\n\t\t\t\t? Math.min(endAfterRuns, limit)\n\t\t\t\t: limit;\n\n\t\tconst endDateMs =\n\t\t\tthis.endMode === RECURRENCE_END_MODE.ON_DATE && this.recurrence.endOnDate\n\t\t\t\t? this.recurrence.endOnDate * 1000\n\t\t\t\t: null;\n\n\t\tlet cursor = new Date(startDate);\n\t\t// Weekly walks a day at a time and skips days that are not selected, so\n\t\t// bound the walk rather than trusting it to land on `maxRuns` matches.\n\t\tlet daysScanned = 0;\n\n\t\twhile (runs.length < maxRuns && daysScanned <= MAX_DAYS_SCANNED) {\n\t\t\tif (endDateMs !== null && cursor.getTime() > endDateMs) break;\n\t\t\tif (this.isRunDay(cursor)) runs.push(new Date(cursor));\n\t\t\tcursor = this.addInterval(cursor);\n\t\t\tdaysScanned += 1;\n\t\t}\n\n\t\treturn runs;\n\t}\n\n\t/**\n\t * The days a weekly recurrence runs on, in Monday-first display order rather\n\t * than the Sunday-first order the chip values are indexed by.\n\t *\n\t * Mon–Fri exactly collapses to \"weekday\", Sat+Sun to \"weekend\". All seven is\n\t * not handled here — that is normalised to DAILY when the day is selected.\n\t */\n\tprivate get weeklyDayPhrase(): string {\n\t\tconst days = this.daysOfWeek;\n\t\tif (!days.length) return '';\n\n\t\tconst matchesExactly = (indices: number[]) =>\n\t\t\tdays.length === indices.length &&\n\t\t\tindices.every((day) => days.includes(day));\n\n\t\tif (matchesExactly(WEEKDAY_INDICES)) return 'weekday';\n\t\tif (matchesExactly(WEEKEND_INDICES)) return 'weekend';\n\n\t\tconst labels = SUMMARY_DAY_ORDER.filter((day) => days.includes(day)).map(\n\t\t\t(day) => DAY_LABELS[day],\n\t\t);\n\t\treturn joinList(labels);\n\t}\n\n\tprivate get monthlyDatePhrase(): string {\n\t\tif (this.recurrence?.monthlyRepeatOption === MONTHLY_REPEAT_OPTION.FIRST) {\n\t\t\treturn 'on the first day';\n\t\t}\n\n\t\tconst ordinals = [...this.datesOfMonth]\n\t\t\t.sort((left, right) => left - right)\n\t\t\t.map(ordinal);\n\n\t\tif (!this.lastDaySelected) {\n\t\t\treturn ordinals.length ? `on the ${joinList(ordinals)}` : '';\n\t\t}\n\n\t\tif (!ordinals.length) return 'on the last day';\n\t\treturn `on the ${joinList([...ordinals, 'the last day'])}`;\n\t}\n\n\t/**\n\t * The semibold phrase after \"Repeats\". Weekly and monthly name the days they\n\t * run on; daily is a plain adverb.\n\t */\n\tprivate get frequencyLabel(): string {\n\t\tswitch (this.frequency) {\n\t\t\tcase RECURRENCE_FREQUENCY.WEEKLY: {\n\t\t\t\tconst phrase = this.weeklyDayPhrase;\n\t\t\t\treturn phrase ? `every ${phrase}` : 'weekly';\n\t\t\t}\n\t\t\tcase RECURRENCE_FREQUENCY.MONTHLY: {\n\t\t\t\tconst phrase = this.monthlyDatePhrase;\n\t\t\t\treturn phrase ? `${phrase} of every month` : 'monthly';\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn 'daily';\n\t\t}\n\t}\n\n\t/** The text following the time, which differs per end mode. */\n\tprivate get endClause(): string {\n\t\tif (this.endMode === RECURRENCE_END_MODE.AFTER_RUNS) {\n\t\t\tconst totalRuns = this.recurrence.endAfterRuns;\n\t\t\tif (!totalRuns) return '.';\n\t\t\treturn ` and ends after ${totalRuns} ${\n\t\t\t\ttotalRuns === 1 ? 'run' : 'runs'\n\t\t\t}.`;\n\t\t}\n\n\t\tif (this.endMode === RECURRENCE_END_MODE.ON_DATE) {\n\t\t\tif (!this.recurrence.endOnDate) return '.';\n\t\t\tconst endLabel = formatDate(\n\t\t\t\tnew Date(this.recurrence.endOnDate * 1000),\n\t\t\t\t'd MMM yyyy',\n\t\t\t);\n\t\t\treturn ` and ends on ${endLabel}.`;\n\t\t}\n\n\t\treturn ' with no end date, you can cancel anytime.';\n\t}\n\n\t/**\n\t * Summary shown under the upcoming runs, split so the frequency and time can\n\t * be rendered in semibold as the design shows:\n\t * \"Repeats **daily** at **10:00 AM** with no end date, you can cancel anytime.\"\n\t */\n\tbuildSummary(runs: Date[]): RecurrenceSummary | null {\n\t\tif (!runs.length) return null;\n\n\t\treturn {\n\t\t\tfrequencyLabel: this.frequencyLabel,\n\t\t\ttimeLabel: formatDate(runs[0], 'h:mm a'),\n\t\t\ttail: this.endClause,\n\t\t};\n\t}\n}\n"],"names":["UPCOMING_RUNS_PREVIEW_COUNT","MAX_RECURRENCE_RUNS","CHIP_WIDTH","MAX_DATE_OF_MONTH","LAST_DAY_CHIP_VALUE","MAX_DAYS_SCANNED","DAY_LABELS","DAYS_IN_WEEK","DAY_CHIP_OPTIONS","label","dayIndex","DATE_CHIP_OPTIONS","_","index","WEEKDAY_INDICES","WEEKEND_INDICES","SUMMARY_DAY_ORDER","SKIPPED_MONTH_CAPTIONS","ordinal","value","joinList","items","getSkippedMonthCaption","datesOfMonth","captions","date","ScheduleHelper","recurrence","RECURRENCE_FREQUENCY","RECURRENCE_END_MODE","next","dayOfMonth","startDate","limit","runs","endAfterRuns","maxRuns","endDateMs","cursor","daysScanned","days","matchesExactly","indices","day","labels","MONTHLY_REPEAT_OPTION","ordinals","left","right","phrase","totalRuns","formatDate"],"mappings":";;AAWO,MAAMA,IAA8B,GAG9BC,IAAsB,KAStBC,IAAa,IAGbC,IAAoB,IAGpBC,IAAsB,YAU7BC,IAAmB,MAGZC,IAAa,CAAC,OAAO,OAAO,OAAO,OAAO,OAAO,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AAEA,WAAI,KAAK,YAAYrB,EAAoB,UACnC,KAAK,WAAW,YAKd,gBAJUsB;AAAAA,MAChB,IAAI,KAAK,KAAK,WAAW,YAAY,GAAI;AAAA,MACzC;AAAA,IAAA,CAE8B,MALQ,MAQjC;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAajB,GAAwC;AACpD,WAAKA,EAAK,SAEH;AAAA,MACN,gBAAgB,KAAK;AAAA,MACrB,WAAWiB,EAAWjB,EAAK,CAAC,GAAG,QAAQ;AAAA,MACvC,MAAM,KAAK;AAAA,IAAA,IALa;AAAA,EAO1B;AACD;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface SendModeItem<T extends string = string> {
|
|
2
|
+
value: T;
|
|
3
|
+
label: string;
|
|
4
|
+
/**
|
|
5
|
+
* Greys out this mode while leaving the others usable.
|
|
6
|
+
*
|
|
7
|
+
* Disabled rather than removed so the mode still reads as something the
|
|
8
|
+
* product offers — a merchant who cannot use it here should see that it
|
|
9
|
+
* exists, not wonder where it went.
|
|
10
|
+
*/
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface SendModeSelectorProps<T extends string = string> {
|
|
14
|
+
options: SendModeItem<T>[];
|
|
15
|
+
value?: T;
|
|
16
|
+
onChange: (value: T) => void;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
'data-test'?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The row of "Send now / Schedule / Set as recurring" cards.
|
|
22
|
+
*
|
|
23
|
+
* The whole card is the hit target, not just the radio — the radio's own
|
|
24
|
+
* `onValueChange` fires too, so both routes land on the same handler.
|
|
25
|
+
*
|
|
26
|
+
* Options are passed in rather than hardcoded: the modes a screen offers are its
|
|
27
|
+
* own business, and a caller with only two of them should not get a dead third.
|
|
28
|
+
*/
|
|
29
|
+
export declare const SendModeSelector: <T extends string = string>({ options, value, onChange, disabled, "data-test": dataTest, }: SendModeSelectorProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import { COLORS as u } from "../../constants/Theme.js";
|
|
3
|
+
import { SendModeRow as i, SendModeOption as c } from "./ScheduleBuilder.styled.js";
|
|
4
|
+
import { RadioButton as v } from "../radioButton/RadioButton.js";
|
|
5
|
+
const m = u.background.inverseLight, n = ({
|
|
6
|
+
options: t,
|
|
7
|
+
value: d,
|
|
8
|
+
onChange: r,
|
|
9
|
+
disabled: a = !1,
|
|
10
|
+
"data-test": s
|
|
11
|
+
}) => /* @__PURE__ */ l(i, { "data-test": s, children: t.map((e) => /* @__PURE__ */ l(
|
|
12
|
+
c,
|
|
13
|
+
{
|
|
14
|
+
active: d === e.value,
|
|
15
|
+
disabled: a || !!e.disabled,
|
|
16
|
+
"data-test": `send-mode-${e.value}`,
|
|
17
|
+
onClick: () => {
|
|
18
|
+
a || e.disabled || r(e.value);
|
|
19
|
+
},
|
|
20
|
+
children: /* @__PURE__ */ l(
|
|
21
|
+
v,
|
|
22
|
+
{
|
|
23
|
+
isActive: d === e.value,
|
|
24
|
+
isDisabled: a || !!e.disabled,
|
|
25
|
+
label: e.label,
|
|
26
|
+
value: e.value,
|
|
27
|
+
onValueChange: () => {
|
|
28
|
+
a || e.disabled || r(e.value);
|
|
29
|
+
},
|
|
30
|
+
alwaysBold: !0,
|
|
31
|
+
activeColor: m,
|
|
32
|
+
skipSelectingOff: !0
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
},
|
|
36
|
+
e.value
|
|
37
|
+
)) });
|
|
38
|
+
export {
|
|
39
|
+
n as SendModeSelector
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=SendModeSelector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SendModeSelector.js","sources":["../../../../src/components/schedule-builder/SendModeSelector.tsx"],"sourcesContent":["import { COLORS } from '../../constants/Theme';\nimport { RadioButton } from '../radioButton';\nimport { SendModeOption, SendModeRow } from './ScheduleBuilder.styled';\n\n/** The purple of the selected radio, which is not the default brand colour. */\nconst RADIO_ACTIVE_COLOR = COLORS.background.inverseLight;\n\nexport interface SendModeItem<T extends string = string> {\n\tvalue: T;\n\tlabel: string;\n\t/**\n\t * Greys out this mode while leaving the others usable.\n\t *\n\t * Disabled rather than removed so the mode still reads as something the\n\t * product offers — a merchant who cannot use it here should see that it\n\t * exists, not wonder where it went.\n\t */\n\tdisabled?: boolean;\n}\n\nexport interface SendModeSelectorProps<T extends string = string> {\n\toptions: SendModeItem<T>[];\n\tvalue?: T;\n\tonChange: (value: T) => void;\n\tdisabled?: boolean;\n\t'data-test'?: string;\n}\n\n/**\n * The row of \"Send now / Schedule / Set as recurring\" cards.\n *\n * The whole card is the hit target, not just the radio — the radio's own\n * `onValueChange` fires too, so both routes land on the same handler.\n *\n * Options are passed in rather than hardcoded: the modes a screen offers are its\n * own business, and a caller with only two of them should not get a dead third.\n */\nexport const SendModeSelector = <T extends string = string>({\n\toptions,\n\tvalue,\n\tonChange,\n\tdisabled = false,\n\t'data-test': dataTest,\n}: SendModeSelectorProps<T>) => (\n\t<SendModeRow data-test={dataTest}>\n\t\t{options.map((option) => (\n\t\t\t<SendModeOption\n\t\t\t\tkey={option.value}\n\t\t\t\tactive={value === option.value}\n\t\t\t\tdisabled={disabled || !!option.disabled}\n\t\t\t\tdata-test={`send-mode-${option.value}`}\n\t\t\t\tonClick={() => {\n\t\t\t\t\tif (disabled || option.disabled) return;\n\t\t\t\t\tonChange(option.value);\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t<RadioButton\n\t\t\t\t\tisActive={value === option.value}\n\t\t\t\t\tisDisabled={disabled || !!option.disabled}\n\t\t\t\t\tlabel={option.label}\n\t\t\t\t\tvalue={option.value}\n\t\t\t\t\tonValueChange={() => {\n\t\t\t\t\t\tif (disabled || option.disabled) return;\n\t\t\t\t\t\tonChange(option.value);\n\t\t\t\t\t}}\n\t\t\t\t\talwaysBold\n\t\t\t\t\tactiveColor={RADIO_ACTIVE_COLOR}\n\t\t\t\t\tskipSelectingOff\n\t\t\t\t/>\n\t\t\t</SendModeOption>\n\t\t))}\n\t</SendModeRow>\n);\n"],"names":["RADIO_ACTIVE_COLOR","COLORS","SendModeSelector","options","value","onChange","disabled","dataTest","SendModeRow","option","jsx","SendModeOption","RadioButton"],"mappings":";;;;AAKA,MAAMA,IAAqBC,EAAO,WAAW,cAgChCC,IAAmB,CAA4B;AAAA,EAC3D,SAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,aAAaC;AACd,wBACEC,GAAA,EAAY,aAAWD,GACtB,UAAAJ,EAAQ,IAAI,CAACM,MACb,gBAAAC;AAAA,EAACC;AAAA,EAAA;AAAA,IAEA,QAAQP,MAAUK,EAAO;AAAA,IACzB,UAAUH,KAAY,CAAC,CAACG,EAAO;AAAA,IAC/B,aAAW,aAAaA,EAAO,KAAK;AAAA,IACpC,SAAS,MAAM;AACd,MAAIH,KAAYG,EAAO,YACvBJ,EAASI,EAAO,KAAK;AAAA,IACtB;AAAA,IAEA,UAAA,gBAAAC;AAAA,MAACE;AAAA,MAAA;AAAA,QACA,UAAUR,MAAUK,EAAO;AAAA,QAC3B,YAAYH,KAAY,CAAC,CAACG,EAAO;AAAA,QACjC,OAAOA,EAAO;AAAA,QACd,OAAOA,EAAO;AAAA,QACd,eAAe,MAAM;AACpB,UAAIH,KAAYG,EAAO,YACvBJ,EAASI,EAAO,KAAK;AAAA,QACtB;AAAA,QACA,YAAU;AAAA,QACV,aAAaT;AAAA,QACb,kBAAgB;AAAA,MAAA;AAAA,IAAA;AAAA,EACjB;AAAA,EArBKS,EAAO;AAsBb,CACA,EAAA,CACF;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Reads a typed 12-hour time.
|
|
4
|
+
*
|
|
5
|
+
* Accepts "9", "9:5" and "09:05" so the merchant can type naturally; am/pm sits
|
|
6
|
+
* on its own dropdown, so only 1-12 is valid here. Returns null while the text is
|
|
7
|
+
* incomplete, which is what keeps the field editable mid-entry.
|
|
8
|
+
*/
|
|
9
|
+
export declare const parseTimeText: (text: string) => {
|
|
10
|
+
hours: string;
|
|
11
|
+
minutes: string;
|
|
12
|
+
} | null;
|
|
13
|
+
export interface StartDateTimePickerProps {
|
|
14
|
+
/** The chosen date. Time-of-day is carried separately by hours/minutes/isAm. */
|
|
15
|
+
date?: Date;
|
|
16
|
+
onDateChange: (date: Date) => void;
|
|
17
|
+
/** 12-hour clock, "1"–"12". Empty string while nothing is chosen. */
|
|
18
|
+
hours: string;
|
|
19
|
+
/** "0"–"59". Empty string while nothing is chosen. */
|
|
20
|
+
minutes: string;
|
|
21
|
+
isAm: boolean;
|
|
22
|
+
/** Fires only for a parseable time, so partial typing does not clear state. */
|
|
23
|
+
onTimeChange: (time: {
|
|
24
|
+
hours: string;
|
|
25
|
+
minutes: string;
|
|
26
|
+
}) => void;
|
|
27
|
+
onMeridiemChange: (isAm: boolean) => void;
|
|
28
|
+
/** Called when focus leaves an unparseable time, for the caller to validate. */
|
|
29
|
+
onTimeInvalidBlur?: () => void;
|
|
30
|
+
/** Shown under the time field. The caller owns validation. */
|
|
31
|
+
timeErrorMessage?: string;
|
|
32
|
+
/** "Start date" when a recurrence follows, plain "Date" otherwise. */
|
|
33
|
+
dateLabel?: string;
|
|
34
|
+
minDate?: Date;
|
|
35
|
+
'data-test'?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The start date and time-of-day row.
|
|
39
|
+
*
|
|
40
|
+
* Date and time are separate props rather than one Date because the time is
|
|
41
|
+
* edited as text and can be mid-entry ("9:" is not a time yet) — folding it into
|
|
42
|
+
* a Date would force a guess about what an incomplete entry means.
|
|
43
|
+
*/
|
|
44
|
+
export declare const StartDateTimePicker: React.FC<StartDateTimePickerProps>;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { jsxs as l, jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo as P } from "react";
|
|
3
|
+
import { COLORS as p } from "../../constants/Theme.js";
|
|
4
|
+
import { ComboBox as $ } from "../combo-box/ComboBox.js";
|
|
5
|
+
import { BodySecondary as u } from "../TypographyStyle.js";
|
|
6
|
+
import { FieldsRow as A, DateFieldColumn as C, FieldLabel as h, RequiredMark as f, DatePickerSlot as k, TimeFieldColumn as B, TimeInputRow as F, TimeDropdownSlot as I, MeridiemDropdownSlot as R } from "./ScheduleBuilder.styled.js";
|
|
7
|
+
import { DatePickerWrapper as z } from "../datePicker/DatePickerWrapper.js";
|
|
8
|
+
import { DateButtonType as E } from "../datePicker/model.js";
|
|
9
|
+
import { Dropdown as L } from "../dropdown/Dropdown.js";
|
|
10
|
+
const O = 30, s = (c) => {
|
|
11
|
+
const d = c.trim();
|
|
12
|
+
if (!d) return null;
|
|
13
|
+
const i = d.match(/^(\d{1,2})(?::(\d{1,2}))?$/);
|
|
14
|
+
if (!i) return null;
|
|
15
|
+
const n = Number(i[1]), a = i[2] === void 0 ? 0 : Number(i[2]);
|
|
16
|
+
return n < 1 || n > 12 || a > 59 ? null : { hours: String(n), minutes: String(a) };
|
|
17
|
+
}, J = ({
|
|
18
|
+
date: c,
|
|
19
|
+
onDateChange: d,
|
|
20
|
+
hours: i,
|
|
21
|
+
minutes: n,
|
|
22
|
+
isAm: a,
|
|
23
|
+
onTimeChange: S,
|
|
24
|
+
onMeridiemChange: y,
|
|
25
|
+
onTimeInvalidBlur: M,
|
|
26
|
+
timeErrorMessage: T,
|
|
27
|
+
dateLabel: v = "Start date",
|
|
28
|
+
minDate: b,
|
|
29
|
+
"data-test": g
|
|
30
|
+
}) => {
|
|
31
|
+
const D = P(() => {
|
|
32
|
+
const e = [];
|
|
33
|
+
for (let o = 1; o <= 12; o += 1)
|
|
34
|
+
for (let m = 0; m < 60; m += O)
|
|
35
|
+
e.push(`${o}:${String(m).padStart(2, "0")}`);
|
|
36
|
+
const r = e.filter((o) => o.startsWith("12:"));
|
|
37
|
+
return [
|
|
38
|
+
...r,
|
|
39
|
+
...e.filter((o) => !r.includes(o))
|
|
40
|
+
].map((o) => ({ value: o }));
|
|
41
|
+
}, []), w = i !== "" && n !== "" ? `${i}:${String(n).padStart(2, "0")}` : void 0, x = [
|
|
42
|
+
{ label: "AM", value: "am", selected: a },
|
|
43
|
+
{ label: "PM", value: "pm", selected: !a }
|
|
44
|
+
];
|
|
45
|
+
return /* @__PURE__ */ l(A, { "data-test": g, children: [
|
|
46
|
+
/* @__PURE__ */ l(C, { children: [
|
|
47
|
+
/* @__PURE__ */ t(h, { children: /* @__PURE__ */ l(u, { color: p.content.primary, children: [
|
|
48
|
+
v,
|
|
49
|
+
/* @__PURE__ */ t(f, { children: " *" })
|
|
50
|
+
] }) }),
|
|
51
|
+
/* @__PURE__ */ t(k, { children: /* @__PURE__ */ t(
|
|
52
|
+
z,
|
|
53
|
+
{
|
|
54
|
+
val: c,
|
|
55
|
+
onChange: (e) => {
|
|
56
|
+
const r = Array.isArray(e) ? e[0] : e;
|
|
57
|
+
r && d(r);
|
|
58
|
+
},
|
|
59
|
+
displayFormat: "dd MMM yyyy",
|
|
60
|
+
dateButtonType: E.LARGE,
|
|
61
|
+
calendarProps: { minDate: b },
|
|
62
|
+
pickerStyles: { top: 8, zIndex: 4 }
|
|
63
|
+
}
|
|
64
|
+
) })
|
|
65
|
+
] }),
|
|
66
|
+
/* @__PURE__ */ l(B, { children: [
|
|
67
|
+
/* @__PURE__ */ t(h, { children: /* @__PURE__ */ l(u, { color: p.content.primary, children: [
|
|
68
|
+
"Time",
|
|
69
|
+
/* @__PURE__ */ t(f, { children: " *" })
|
|
70
|
+
] }) }),
|
|
71
|
+
/* @__PURE__ */ l(F, { children: [
|
|
72
|
+
/* @__PURE__ */ t(I, { children: /* @__PURE__ */ t(
|
|
73
|
+
$,
|
|
74
|
+
{
|
|
75
|
+
"data-test": "recurrence-time",
|
|
76
|
+
value: w ?? "",
|
|
77
|
+
options: D,
|
|
78
|
+
placeholder: "hh:mm",
|
|
79
|
+
errorMessage: T || void 0,
|
|
80
|
+
validate: (e) => !!s(e),
|
|
81
|
+
sanitize: (e) => e.replace(/[^\d:]/g, "").slice(0, 5),
|
|
82
|
+
format: (e) => {
|
|
83
|
+
const r = s(e);
|
|
84
|
+
return r ? `${r.hours}:${r.minutes.padStart(2, "0")}` : e;
|
|
85
|
+
},
|
|
86
|
+
onChange: (e) => {
|
|
87
|
+
const r = s(e);
|
|
88
|
+
r && S(r);
|
|
89
|
+
},
|
|
90
|
+
onInvalidBlur: M
|
|
91
|
+
}
|
|
92
|
+
) }),
|
|
93
|
+
/* @__PURE__ */ t(R, { "data-test": "recurrence-meridiem", children: /* @__PURE__ */ t(
|
|
94
|
+
L,
|
|
95
|
+
{
|
|
96
|
+
size: "default",
|
|
97
|
+
isSearchable: !1,
|
|
98
|
+
isMultiSelect: !1,
|
|
99
|
+
options: x,
|
|
100
|
+
value: a ? "AM" : "PM",
|
|
101
|
+
buttonWidth: "100%",
|
|
102
|
+
width: "84px",
|
|
103
|
+
placeHolderHeight: "48px",
|
|
104
|
+
placeHolder: "AM",
|
|
105
|
+
onSelect: (e) => {
|
|
106
|
+
const r = Array.isArray(e) ? e[0] : e;
|
|
107
|
+
y(r?.value !== "pm");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
) })
|
|
111
|
+
] })
|
|
112
|
+
] })
|
|
113
|
+
] });
|
|
114
|
+
};
|
|
115
|
+
export {
|
|
116
|
+
J as StartDateTimePicker,
|
|
117
|
+
s as parseTimeText
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=StartDateTimePicker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StartDateTimePicker.js","sources":["../../../../src/components/schedule-builder/StartDateTimePicker.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport { COLORS } from '../../constants/Theme';\nimport { ComboBox } from '../combo-box';\nimport { DateButtonType, DatePickerWrapper } from '../datePicker';\nimport { Dropdown, DropdownOption, SingleOption } from '../dropdown';\nimport { BodySecondary } from '../TypographyStyle';\nimport {\n\tDateFieldColumn,\n\tDatePickerSlot,\n\tFieldLabel,\n\tFieldsRow,\n\tMeridiemDropdownSlot,\n\tRequiredMark,\n\tTimeDropdownSlot,\n\tTimeFieldColumn,\n\tTimeInputRow,\n} from './ScheduleBuilder.styled';\n\n/** Step between offered times, in minutes. */\nconst TIME_STEP_MINUTES = 30;\n\n/**\n * Reads a typed 12-hour time.\n *\n * Accepts \"9\", \"9:5\" and \"09:05\" so the merchant can type naturally; am/pm sits\n * on its own dropdown, so only 1-12 is valid here. Returns null while the text is\n * incomplete, which is what keeps the field editable mid-entry.\n */\nexport const parseTimeText = (\n\ttext: string,\n): { hours: string; minutes: string } | null => {\n\tconst trimmed = text.trim();\n\tif (!trimmed) return null;\n\n\tconst match = trimmed.match(/^(\\d{1,2})(?::(\\d{1,2}))?$/);\n\tif (!match) return null;\n\n\tconst hours = Number(match[1]);\n\t// Minutes are optional: \"9\" means 9:00.\n\tconst minutes = match[2] === undefined ? 0 : Number(match[2]);\n\n\tif (hours < 1 || hours > 12) return null;\n\tif (minutes > 59) return null;\n\n\treturn { hours: String(hours), minutes: String(minutes) };\n};\n\nexport interface StartDateTimePickerProps {\n\t/** The chosen date. Time-of-day is carried separately by hours/minutes/isAm. */\n\tdate?: Date;\n\tonDateChange: (date: Date) => void;\n\t/** 12-hour clock, \"1\"–\"12\". Empty string while nothing is chosen. */\n\thours: string;\n\t/** \"0\"–\"59\". Empty string while nothing is chosen. */\n\tminutes: string;\n\tisAm: boolean;\n\t/** Fires only for a parseable time, so partial typing does not clear state. */\n\tonTimeChange: (time: { hours: string; minutes: string }) => void;\n\tonMeridiemChange: (isAm: boolean) => void;\n\t/** Called when focus leaves an unparseable time, for the caller to validate. */\n\tonTimeInvalidBlur?: () => void;\n\t/** Shown under the time field. The caller owns validation. */\n\ttimeErrorMessage?: string;\n\t/** \"Start date\" when a recurrence follows, plain \"Date\" otherwise. */\n\tdateLabel?: string;\n\tminDate?: Date;\n\t'data-test'?: string;\n}\n\n/**\n * The start date and time-of-day row.\n *\n * Date and time are separate props rather than one Date because the time is\n * edited as text and can be mid-entry (\"9:\" is not a time yet) — folding it into\n * a Date would force a guess about what an incomplete entry means.\n */\nexport const StartDateTimePicker: React.FC<StartDateTimePickerProps> = ({\n\tdate,\n\tonDateChange,\n\thours,\n\tminutes,\n\tisAm,\n\tonTimeChange,\n\tonMeridiemChange,\n\tonTimeInvalidBlur,\n\ttimeErrorMessage,\n\tdateLabel = 'Start date',\n\tminDate,\n\t'data-test': dataTest,\n}) => {\n\t/**\n\t * Times offered in the picker, at TIME_STEP_MINUTES steps. 12 leads the day in\n\t * 12-hour time, so it sorts to the front rather than after 11.\n\t */\n\tconst timeOptions = useMemo(() => {\n\t\tconst values: string[] = [];\n\t\tfor (let hour = 1; hour <= 12; hour += 1) {\n\t\t\tfor (let minute = 0; minute < 60; minute += TIME_STEP_MINUTES) {\n\t\t\t\tvalues.push(`${hour}:${String(minute).padStart(2, '0')}`);\n\t\t\t}\n\t\t}\n\t\tconst twelves = values.filter((value) => value.startsWith('12:'));\n\t\treturn [\n\t\t\t...twelves,\n\t\t\t...values.filter((value) => !twelves.includes(value)),\n\t\t].map((value) => ({ value }));\n\t}, []);\n\n\tconst selectedTimeLabel =\n\t\thours !== '' && minutes !== ''\n\t\t\t? `${hours}:${String(minutes).padStart(2, '0')}`\n\t\t\t: undefined;\n\n\tconst meridiemDropdownOptions: SingleOption[] = [\n\t\t{ label: 'AM', value: 'am', selected: isAm },\n\t\t{ label: 'PM', value: 'pm', selected: !isAm },\n\t];\n\n\treturn (\n\t\t<FieldsRow data-test={dataTest}>\n\t\t\t<DateFieldColumn>\n\t\t\t\t<FieldLabel>\n\t\t\t\t\t<BodySecondary color={COLORS.content.primary}>\n\t\t\t\t\t\t{dateLabel}\n\t\t\t\t\t\t<RequiredMark> *</RequiredMark>\n\t\t\t\t\t</BodySecondary>\n\t\t\t\t</FieldLabel>\n\t\t\t\t<DatePickerSlot>\n\t\t\t\t\t<DatePickerWrapper\n\t\t\t\t\t\tval={date}\n\t\t\t\t\t\tonChange={(value: Date | Date[]) => {\n\t\t\t\t\t\t\tconst dateValue = Array.isArray(value) ? value[0] : value;\n\t\t\t\t\t\t\tif (dateValue) onDateChange(dateValue);\n\t\t\t\t\t\t}}\n\t\t\t\t\t\tdisplayFormat=\"dd MMM yyyy\"\n\t\t\t\t\t\tdateButtonType={DateButtonType.LARGE}\n\t\t\t\t\t\tcalendarProps={{ minDate }}\n\t\t\t\t\t\tpickerStyles={{ top: 8, zIndex: 4 }}\n\t\t\t\t\t/>\n\t\t\t\t</DatePickerSlot>\n\t\t\t</DateFieldColumn>\n\t\t\t<TimeFieldColumn>\n\t\t\t\t<FieldLabel>\n\t\t\t\t\t<BodySecondary color={COLORS.content.primary}>\n\t\t\t\t\t\tTime\n\t\t\t\t\t\t<RequiredMark> *</RequiredMark>\n\t\t\t\t\t</BodySecondary>\n\t\t\t\t</FieldLabel>\n\t\t\t\t{/*\n Top-aligned: the time field's error message sits inside its own slot,\n so centring would drop AM/PM as the message appears.\n */}\n\t\t\t\t<TimeInputRow>\n\t\t\t\t\t<TimeDropdownSlot>\n\t\t\t\t\t\t<ComboBox\n\t\t\t\t\t\t\tdata-test=\"recurrence-time\"\n\t\t\t\t\t\t\tvalue={selectedTimeLabel ?? ''}\n\t\t\t\t\t\t\toptions={timeOptions}\n\t\t\t\t\t\t\tplaceholder=\"hh:mm\"\n\t\t\t\t\t\t\terrorMessage={timeErrorMessage || undefined}\n\t\t\t\t\t\t\tvalidate={(text) => !!parseTimeText(text)}\n\t\t\t\t\t\t\tsanitize={(text) => text.replace(/[^\\d:]/g, '').slice(0, 5)}\n\t\t\t\t\t\t\tformat={(text) => {\n\t\t\t\t\t\t\t\tconst parsed = parseTimeText(text);\n\t\t\t\t\t\t\t\tif (!parsed) return text;\n\t\t\t\t\t\t\t\treturn `${parsed.hours}:${parsed.minutes.padStart(2, '0')}`;\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\tonChange={(text) => {\n\t\t\t\t\t\t\t\tconst parsed = parseTimeText(text);\n\t\t\t\t\t\t\t\tif (!parsed) return;\n\t\t\t\t\t\t\t\tonTimeChange(parsed);\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\tonInvalidBlur={onTimeInvalidBlur}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</TimeDropdownSlot>\n\t\t\t\t\t<MeridiemDropdownSlot data-test=\"recurrence-meridiem\">\n\t\t\t\t\t\t<Dropdown\n\t\t\t\t\t\t\tsize=\"default\"\n\t\t\t\t\t\t\tisSearchable={false}\n\t\t\t\t\t\t\tisMultiSelect={false}\n\t\t\t\t\t\t\toptions={meridiemDropdownOptions}\n\t\t\t\t\t\t\tvalue={isAm ? 'AM' : 'PM'}\n\t\t\t\t\t\t\tbuttonWidth=\"100%\"\n\t\t\t\t\t\t\twidth=\"84px\"\n\t\t\t\t\t\t\tplaceHolderHeight=\"48px\"\n\t\t\t\t\t\t\tplaceHolder=\"AM\"\n\t\t\t\t\t\t\tonSelect={(\n\t\t\t\t\t\t\t\tselected: DropdownOption | DropdownOption[] | null,\n\t\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\t\tconst normalized = (\n\t\t\t\t\t\t\t\t\tArray.isArray(selected) ? selected[0] : selected\n\t\t\t\t\t\t\t\t) as SingleOption | null;\n\t\t\t\t\t\t\t\tonMeridiemChange(normalized?.value !== 'pm');\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</MeridiemDropdownSlot>\n\t\t\t\t</TimeInputRow>\n\t\t\t</TimeFieldColumn>\n\t\t</FieldsRow>\n\t);\n};\n"],"names":["TIME_STEP_MINUTES","parseTimeText","text","trimmed","match","hours","minutes","StartDateTimePicker","date","onDateChange","isAm","onTimeChange","onMeridiemChange","onTimeInvalidBlur","timeErrorMessage","dateLabel","minDate","dataTest","timeOptions","useMemo","values","hour","minute","twelves","value","selectedTimeLabel","meridiemDropdownOptions","jsxs","FieldsRow","DateFieldColumn","jsx","FieldLabel","BodySecondary","COLORS","RequiredMark","DatePickerSlot","DatePickerWrapper","dateValue","DateButtonType","TimeFieldColumn","TimeInputRow","TimeDropdownSlot","ComboBox","parsed","MeridiemDropdownSlot","Dropdown","selected","normalized"],"mappings":";;;;;;;;;AAmBA,MAAMA,IAAoB,IASbC,IAAgB,CAC5BC,MAC+C;AAC/C,QAAMC,IAAUD,EAAK,KAAA;AACrB,MAAI,CAACC,EAAS,QAAO;AAErB,QAAMC,IAAQD,EAAQ,MAAM,4BAA4B;AACxD,MAAI,CAACC,EAAO,QAAO;AAEnB,QAAMC,IAAQ,OAAOD,EAAM,CAAC,CAAC,GAEvBE,IAAUF,EAAM,CAAC,MAAM,SAAY,IAAI,OAAOA,EAAM,CAAC,CAAC;AAG5D,SADIC,IAAQ,KAAKA,IAAQ,MACrBC,IAAU,KAAW,OAElB,EAAE,OAAO,OAAOD,CAAK,GAAG,SAAS,OAAOC,CAAO,EAAA;AACvD,GA+BaC,IAA0D,CAAC;AAAA,EACvE,MAAAC;AAAA,EACA,cAAAC;AAAA,EACA,OAAAJ;AAAA,EACA,SAAAC;AAAA,EACA,MAAAI;AAAA,EACA,cAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,SAAAC;AAAA,EACA,aAAaC;AACd,MAAM;AAKL,QAAMC,IAAcC,EAAQ,MAAM;AACjC,UAAMC,IAAmB,CAAA;AACzB,aAASC,IAAO,GAAGA,KAAQ,IAAIA,KAAQ;AACtC,eAASC,IAAS,GAAGA,IAAS,IAAIA,KAAUtB;AAC3C,QAAAoB,EAAO,KAAK,GAAGC,CAAI,IAAI,OAAOC,CAAM,EAAE,SA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AAMC,IACL,MAAM,QAAQD,CAAQ,IAAIA,EAAS,CAAC,IAAIA;AAEzC,cAAAlC,EAAiBmC,GAAY,UAAU,IAAI;AAAA,YAC5C;AAAA,UAAA;AAAA,QAAA,EACD,CACD;AAAA,MAAA,EAAA,CACD;AAAA,IAAA,EAAA,CACD;AAAA,EAAA,GACD;AAEF;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { RecurrenceSummary } from './model';
|
|
3
|
+
export interface UpcomingRunsPreviewProps {
|
|
4
|
+
/** Run dates to list. Renders nothing when empty. */
|
|
5
|
+
runs: Date[];
|
|
6
|
+
/** Summary line under the list. Omit to show the list alone. */
|
|
7
|
+
summary?: RecurrenceSummary | null;
|
|
8
|
+
/** date-fns pattern for each run. */
|
|
9
|
+
dateFormat?: string;
|
|
10
|
+
'data-test'?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The dated list of the next few runs, with the plain-English summary beneath.
|
|
14
|
+
*
|
|
15
|
+
* Read-only: it renders whatever run dates it is given rather than deriving them,
|
|
16
|
+
* so a caller can preview a schedule it has not committed to. Pair it with
|
|
17
|
+
* `ScheduleHelper.computeUpcomingRuns` to produce the dates.
|
|
18
|
+
*/
|
|
19
|
+
export declare const UpcomingRunsPreview: React.FC<UpcomingRunsPreviewProps>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsxs as r, jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import { format as h } from "date-fns";
|
|
3
|
+
import { COLORS as o } from "../../constants/Theme.js";
|
|
4
|
+
import { TitleSmall as g, BodyCaption as l } from "../TypographyStyle.js";
|
|
5
|
+
import { Column as i, UpcomingRunItem as s, UpcomingRunDot as f, SummaryHighlight as a } from "./ScheduleBuilder.styled.js";
|
|
6
|
+
const x = ({
|
|
7
|
+
runs: n,
|
|
8
|
+
summary: e,
|
|
9
|
+
dateFormat: m = "EEE d MMM, yyyy",
|
|
10
|
+
"data-test": p
|
|
11
|
+
}) => n.length ? /* @__PURE__ */ r(i, { gap: 12, "data-test": p, children: [
|
|
12
|
+
/* @__PURE__ */ r(i, { gap: 8, children: [
|
|
13
|
+
/* @__PURE__ */ t(g, { color: o.content.primary, children: "Upcoming runs" }),
|
|
14
|
+
/* @__PURE__ */ t(i, { gap: 16, children: n.map((c, d) => /* @__PURE__ */ r(
|
|
15
|
+
s,
|
|
16
|
+
{
|
|
17
|
+
isLast: d === n.length - 1,
|
|
18
|
+
children: [
|
|
19
|
+
/* @__PURE__ */ t(f, {}),
|
|
20
|
+
/* @__PURE__ */ t(l, { color: o.content.primary, children: h(c, m) })
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
c.getTime()
|
|
24
|
+
)) })
|
|
25
|
+
] }),
|
|
26
|
+
!!e && /* @__PURE__ */ r(
|
|
27
|
+
l,
|
|
28
|
+
{
|
|
29
|
+
color: o.content.secondary,
|
|
30
|
+
"data-test": "recurrence-summary",
|
|
31
|
+
children: [
|
|
32
|
+
"Repeats ",
|
|
33
|
+
/* @__PURE__ */ t(a, { children: e.frequencyLabel }),
|
|
34
|
+
" at ",
|
|
35
|
+
/* @__PURE__ */ t(a, { children: e.timeLabel }),
|
|
36
|
+
e.tail
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
] }) : null;
|
|
41
|
+
export {
|
|
42
|
+
x as UpcomingRunsPreview
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=UpcomingRunsPreview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UpcomingRunsPreview.js","sources":["../../../../src/components/schedule-builder/UpcomingRunsPreview.tsx"],"sourcesContent":["import { format as formatDate } from 'date-fns';\nimport React from 'react';\nimport { COLORS } from '../../constants/Theme';\nimport { BodyCaption, TitleSmall } from '../TypographyStyle';\nimport { RecurrenceSummary } from './model';\nimport {\n\tColumn,\n\tSummaryHighlight,\n\tUpcomingRunDot,\n\tUpcomingRunItem,\n} from './ScheduleBuilder.styled';\n\nexport interface UpcomingRunsPreviewProps {\n\t/** Run dates to list. Renders nothing when empty. */\n\truns: Date[];\n\t/** Summary line under the list. Omit to show the list alone. */\n\tsummary?: RecurrenceSummary | null;\n\t/** date-fns pattern for each run. */\n\tdateFormat?: string;\n\t'data-test'?: string;\n}\n\n/**\n * The dated list of the next few runs, with the plain-English summary beneath.\n *\n * Read-only: it renders whatever run dates it is given rather than deriving them,\n * so a caller can preview a schedule it has not committed to. Pair it with\n * `ScheduleHelper.computeUpcomingRuns` to produce the dates.\n */\nexport const UpcomingRunsPreview: React.FC<UpcomingRunsPreviewProps> = ({\n\truns,\n\tsummary,\n\tdateFormat = 'EEE d MMM, yyyy',\n\t'data-test': dataTest,\n}) => {\n\tif (!runs.length) return null;\n\n\treturn (\n\t\t<Column gap={12} data-test={dataTest}>\n\t\t\t<Column gap={8}>\n\t\t\t\t<TitleSmall color={COLORS.content.primary}>Upcoming runs</TitleSmall>\n\t\t\t\t<Column gap={16}>\n\t\t\t\t\t{runs.map((run, index) => (\n\t\t\t\t\t\t<UpcomingRunItem\n\t\t\t\t\t\t\tkey={run.getTime()}\n\t\t\t\t\t\t\tisLast={index === runs.length - 1}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<UpcomingRunDot />\n\t\t\t\t\t\t\t<BodyCaption color={COLORS.content.primary}>\n\t\t\t\t\t\t\t\t{formatDate(run, dateFormat)}\n\t\t\t\t\t\t\t</BodyCaption>\n\t\t\t\t\t\t</UpcomingRunItem>\n\t\t\t\t\t))}\n\t\t\t\t</Column>\n\t\t\t</Column>\n\t\t\t{!!summary && (\n\t\t\t\t<BodyCaption\n\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\tdata-test=\"recurrence-summary\"\n\t\t\t\t>\n\t\t\t\t\t{'Repeats '}\n\t\t\t\t\t<SummaryHighlight>{summary.frequencyLabel}</SummaryHighlight>\n\t\t\t\t\t{' at '}\n\t\t\t\t\t<SummaryHighlight>{summary.timeLabel}</SummaryHighlight>\n\t\t\t\t\t{summary.tail}\n\t\t\t\t</BodyCaption>\n\t\t\t)}\n\t\t</Column>\n\t);\n};\n"],"names":["UpcomingRunsPreview","runs","summary","dateFormat","dataTest","jsxs","Column","jsx","TitleSmall","COLORS","run","index","UpcomingRunItem","UpcomingRunDot","BodyCaption","formatDate","SummaryHighlight"],"mappings":";;;;;AA6BO,MAAMA,IAA0D,CAAC;AAAA,EACvE,MAAAC;AAAA,EACA,SAAAC;AAAA,EACA,YAAAC,IAAa;AAAA,EACb,aAAaC;AACd,MACMH,EAAK,SAGT,gBAAAI,EAACC,GAAA,EAAO,KAAK,IAAI,aAAWF,GAC3B,UAAA;AAAA,EAAA,gBAAAC,EAACC,GAAA,EAAO,KAAK,GACZ,UAAA;AAAA,IAAA,gBAAAC,EAACC,GAAA,EAAW,OAAOC,EAAO,QAAQ,SAAS,UAAA,iBAAa;AAAA,IACxD,gBAAAF,EAACD,KAAO,KAAK,IACX,YAAK,IAAI,CAACI,GAAKC,MACf,gBAAAN;AAAA,MAACO;AAAA,MAAA;AAAA,QAEA,QAAQD,MAAUV,EAAK,SAAS;AAAA,QAEhC,UAAA;AAAA,UAAA,gBAAAM,EAACM,GAAA,EAAe;AAAA,UAChB,gBAAAN,EAACO,KAAY,OAAOL,EAAO,QAAQ,SACjC,UAAAM,EAAWL,GAAKP,CAAU,EAAA,CAC5B;AAAA,QAAA;AAAA,MAAA;AAAA,MANKO,EAAI,QAAA;AAAA,IAAQ,CAQlB,EAAA,CACF;AAAA,EAAA,GACD;AAAA,EACC,CAAC,CAACR,KACF,gBAAAG;AAAA,IAACS;AAAA,IAAA;AAAA,MACA,OAAOL,EAAO,QAAQ;AAAA,MACtB,aAAU;AAAA,MAET,UAAA;AAAA,QAAA;AAAA,QACD,gBAAAF,EAACS,GAAA,EAAkB,UAAAd,EAAQ,eAAA,CAAe;AAAA,QACzC;AAAA,QACD,gBAAAK,EAACS,GAAA,EAAkB,UAAAd,EAAQ,UAAA,CAAU;AAAA,QACpCA,EAAQ;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AACV,GAEF,IAhCwB;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RefreshSegmentToggle } from './RefreshSegmentToggle';
|
|
2
|
+
import { ScheduleBuilder } from './ScheduleBuilder';
|
|
3
|
+
import { ScheduleEndPicker } from './ScheduleEndPicker';
|
|
4
|
+
import { ScheduleFrequencyPicker } from './ScheduleFrequencyPicker';
|
|
5
|
+
import { SendModeSelector } from './SendModeSelector';
|
|
6
|
+
import { StartDateTimePicker } from './StartDateTimePicker';
|
|
7
|
+
import { UpcomingRunsPreview } from './UpcomingRunsPreview';
|
|
8
|
+
export { ScheduleBuilder, SendModeSelector, StartDateTimePicker, ScheduleFrequencyPicker, ScheduleEndPicker, UpcomingRunsPreview, RefreshSegmentToggle, };
|
|
9
|
+
export * from './model';
|
|
10
|
+
export * from './ScheduleHelper';
|
|
11
|
+
export type { ScheduleBuilderProps } from './ScheduleBuilder';
|
|
12
|
+
export type { SendModeSelectorProps, SendModeItem } from './SendModeSelector';
|
|
13
|
+
export type { StartDateTimePickerProps } from './StartDateTimePicker';
|
|
14
|
+
export type { ScheduleFrequencyPickerProps } from './ScheduleFrequencyPicker';
|
|
15
|
+
export type { ScheduleEndPickerProps } from './ScheduleEndPicker';
|
|
16
|
+
export type { UpcomingRunsPreviewProps } from './UpcomingRunsPreview';
|
|
17
|
+
export type { RefreshSegmentToggleProps } from './RefreshSegmentToggle';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the recurrence pickers.
|
|
3
|
+
*
|
|
4
|
+
* These enums are duplicated from the consuming app's campaign types on purpose:
|
|
5
|
+
* a library component cannot import from an app, and the string values are what
|
|
6
|
+
* both ends already send over the wire, so the two stay compatible without a
|
|
7
|
+
* shared package. Cast at the boundary if your app has its own copy.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* When something sends. SEND_NOW hides the date and time; SCHEDULE shows them;
|
|
11
|
+
* RECURRING adds the frequency, end rule and run preview beneath.
|
|
12
|
+
*/
|
|
13
|
+
export declare enum SEND_MODE {
|
|
14
|
+
SEND_NOW = "SEND_NOW",
|
|
15
|
+
SCHEDULE = "SCHEDULE",
|
|
16
|
+
RECURRING = "RECURRING"
|
|
17
|
+
}
|
|
18
|
+
/** How often the series repeats. */
|
|
19
|
+
export declare enum RECURRENCE_FREQUENCY {
|
|
20
|
+
DAILY = "DAILY",
|
|
21
|
+
WEEKLY = "WEEKLY",
|
|
22
|
+
MONTHLY = "MONTHLY"
|
|
23
|
+
}
|
|
24
|
+
/** What stops a series from running forever. */
|
|
25
|
+
export declare enum RECURRENCE_END_MODE {
|
|
26
|
+
NEVER = "NEVER",
|
|
27
|
+
AFTER_RUNS = "AFTER_RUNS",
|
|
28
|
+
ON_DATE = "ON_DATE"
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The "Repeat every" choice shown for a monthly recurrence. FIRST and LAST are
|
|
32
|
+
* presets over the same dates the CUSTOM grid picks, so all three resolve to one
|
|
33
|
+
* set of dates plus a last-day flag rather than three separate code paths.
|
|
34
|
+
*/
|
|
35
|
+
export declare enum MONTHLY_REPEAT_OPTION {
|
|
36
|
+
FIRST = "FIRST",
|
|
37
|
+
LAST = "LAST",
|
|
38
|
+
CUSTOM = "CUSTOM"
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Everything the pickers below the start date own.
|
|
42
|
+
*
|
|
43
|
+
* The start date and time are deliberately not here — they belong to the
|
|
44
|
+
* schedule the recurrence repeats from, which every send mode shares.
|
|
45
|
+
* `ScheduleBuilder` holds those as its own `date`/`hours`/`minutes` props so
|
|
46
|
+
* switching mode does not have to move them between two shapes.
|
|
47
|
+
*/
|
|
48
|
+
export interface RecurrenceValue {
|
|
49
|
+
frequency?: RECURRENCE_FREQUENCY;
|
|
50
|
+
endMode?: RECURRENCE_END_MODE;
|
|
51
|
+
/** Weekly only. JS day indices — 0 = Sunday, matching `Date.getDay()`. */
|
|
52
|
+
daysOfWeek?: number[];
|
|
53
|
+
/** Monthly only. Calendar dates, 1–31. */
|
|
54
|
+
datesOfMonth?: number[];
|
|
55
|
+
/** Monthly only. Runs on the last day of every month, whatever date that is. */
|
|
56
|
+
lastDaySelected?: boolean;
|
|
57
|
+
monthlyRepeatOption?: MONTHLY_REPEAT_OPTION;
|
|
58
|
+
/** AFTER_RUNS only. Counts the first run, so 1 means "just the start date". */
|
|
59
|
+
endAfterRuns?: number;
|
|
60
|
+
/** ON_DATE only. Epoch seconds at the end of the chosen day. */
|
|
61
|
+
endOnDate?: number;
|
|
62
|
+
refreshSegmentBeforeEachRun?: boolean;
|
|
63
|
+
}
|
|
64
|
+
/** Summary line split into its semibold parts and the plain text between them. */
|
|
65
|
+
export interface RecurrenceSummary {
|
|
66
|
+
frequencyLabel: string;
|
|
67
|
+
timeLabel: string;
|
|
68
|
+
tail: string;
|
|
69
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var S = /* @__PURE__ */ ((r) => (r.SEND_NOW = "SEND_NOW", r.SCHEDULE = "SCHEDULE", r.RECURRING = "RECURRING", r))(S || {}), L = /* @__PURE__ */ ((r) => (r.DAILY = "DAILY", r.WEEKLY = "WEEKLY", r.MONTHLY = "MONTHLY", r))(L || {}), A = /* @__PURE__ */ ((r) => (r.NEVER = "NEVER", r.AFTER_RUNS = "AFTER_RUNS", r.ON_DATE = "ON_DATE", r))(A || {}), T = /* @__PURE__ */ ((r) => (r.FIRST = "FIRST", r.LAST = "LAST", r.CUSTOM = "CUSTOM", r))(T || {});
|
|
2
|
+
export {
|
|
3
|
+
T as MONTHLY_REPEAT_OPTION,
|
|
4
|
+
A as RECURRENCE_END_MODE,
|
|
5
|
+
L as RECURRENCE_FREQUENCY,
|
|
6
|
+
S as SEND_MODE
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sources":["../../../../src/components/schedule-builder/model.ts"],"sourcesContent":["/**\n * Types for the recurrence pickers.\n *\n * These enums are duplicated from the consuming app's campaign types on purpose:\n * a library component cannot import from an app, and the string values are what\n * both ends already send over the wire, so the two stay compatible without a\n * shared package. Cast at the boundary if your app has its own copy.\n */\n\n/**\n * When something sends. SEND_NOW hides the date and time; SCHEDULE shows them;\n * RECURRING adds the frequency, end rule and run preview beneath.\n */\nexport enum SEND_MODE {\n\tSEND_NOW = 'SEND_NOW',\n\tSCHEDULE = 'SCHEDULE',\n\tRECURRING = 'RECURRING',\n}\n\n/** How often the series repeats. */\nexport enum RECURRENCE_FREQUENCY {\n\tDAILY = 'DAILY',\n\tWEEKLY = 'WEEKLY',\n\tMONTHLY = 'MONTHLY',\n}\n\n/** What stops a series from running forever. */\nexport enum RECURRENCE_END_MODE {\n\tNEVER = 'NEVER',\n\tAFTER_RUNS = 'AFTER_RUNS',\n\tON_DATE = 'ON_DATE',\n}\n\n/**\n * The \"Repeat every\" choice shown for a monthly recurrence. FIRST and LAST are\n * presets over the same dates the CUSTOM grid picks, so all three resolve to one\n * set of dates plus a last-day flag rather than three separate code paths.\n */\nexport enum MONTHLY_REPEAT_OPTION {\n\tFIRST = 'FIRST',\n\tLAST = 'LAST',\n\tCUSTOM = 'CUSTOM',\n}\n\n/**\n * Everything the pickers below the start date own.\n *\n * The start date and time are deliberately not here — they belong to the\n * schedule the recurrence repeats from, which every send mode shares.\n * `ScheduleBuilder` holds those as its own `date`/`hours`/`minutes` props so\n * switching mode does not have to move them between two shapes.\n */\nexport interface RecurrenceValue {\n\tfrequency?: RECURRENCE_FREQUENCY;\n\tendMode?: RECURRENCE_END_MODE;\n\t/** Weekly only. JS day indices — 0 = Sunday, matching `Date.getDay()`. */\n\tdaysOfWeek?: number[];\n\t/** Monthly only. Calendar dates, 1–31. */\n\tdatesOfMonth?: number[];\n\t/** Monthly only. Runs on the last day of every month, whatever date that is. */\n\tlastDaySelected?: boolean;\n\tmonthlyRepeatOption?: MONTHLY_REPEAT_OPTION;\n\t/** AFTER_RUNS only. Counts the first run, so 1 means \"just the start date\". */\n\tendAfterRuns?: number;\n\t/** ON_DATE only. Epoch seconds at the end of the chosen day. */\n\tendOnDate?: number;\n\trefreshSegmentBeforeEachRun?: boolean;\n}\n\n/** Summary line split into its semibold parts and the plain text between them. */\nexport interface RecurrenceSummary {\n\tfrequencyLabel: string;\n\ttimeLabel: string;\n\ttail: string;\n}\n"],"names":["SEND_MODE","RECURRENCE_FREQUENCY","RECURRENCE_END_MODE","MONTHLY_REPEAT_OPTION"],"mappings":"AAaO,IAAKA,sBAAAA,OACXA,EAAA,WAAW,YACXA,EAAA,WAAW,YACXA,EAAA,YAAY,aAHDA,IAAAA,KAAA,CAAA,CAAA,GAOAC,sBAAAA,OACXA,EAAA,QAAQ,SACRA,EAAA,SAAS,UACTA,EAAA,UAAU,WAHCA,IAAAA,KAAA,CAAA,CAAA,GAOAC,sBAAAA,OACXA,EAAA,QAAQ,SACRA,EAAA,aAAa,cACbA,EAAA,UAAU,WAHCA,IAAAA,KAAA,CAAA,CAAA,GAWAC,sBAAAA,OACXA,EAAA,QAAQ,SACRA,EAAA,OAAO,QACPA,EAAA,SAAS,UAHEA,IAAAA,KAAA,CAAA,CAAA;"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -88,6 +88,9 @@ export * from './utils/validator';
|
|
|
88
88
|
export * from './components/carousel-preview';
|
|
89
89
|
export * from './components/floater';
|
|
90
90
|
export * from './components/card-selector';
|
|
91
|
+
export * from './components/chip-selector';
|
|
92
|
+
export * from './components/combo-box';
|
|
93
|
+
export * from './components/schedule-builder';
|
|
91
94
|
export * from './components/variable-picker-v3';
|
|
92
95
|
export * from './components/action-button';
|
|
93
96
|
export * from './components/ai-modals';
|