@stackone/malachite 2.86.0 → 2.88.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/COMPONENTS.md +5 -4
- package/dist/components/Accordion.js +206 -179
- package/dist/components/Accordion.js.map +1 -1
- package/dist/components/Button.js +118 -81
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Card.js +128 -75
- package/dist/components/Card.js.map +1 -1
- package/dist/components/Chat/ChatModelPicker.js +70 -67
- package/dist/components/Chat/ChatModelPicker.js.map +1 -1
- package/dist/components/FilterSearch.js +237 -232
- package/dist/components/FilterSearch.js.map +1 -1
- package/dist/components/FrameHeader.js +36 -0
- package/dist/components/FrameHeader.js.map +1 -0
- package/dist/components/LoadingBar.js +5 -5
- package/dist/components/LoadingBar.js.map +1 -1
- package/dist/components/MultiSelect.js +438 -388
- package/dist/components/MultiSelect.js.map +1 -1
- package/dist/components/PinnedCornerCap.js +32 -19
- package/dist/components/PinnedCornerCap.js.map +1 -1
- package/dist/components/QueryInput.js +95 -92
- package/dist/components/QueryInput.js.map +1 -1
- package/dist/components/SplitButton.js +62 -61
- package/dist/components/SplitButton.js.map +1 -1
- package/dist/components/Surface.js +98 -94
- package/dist/components/Surface.js.map +1 -1
- package/dist/components/Table/Table.js +630 -606
- package/dist/components/Table/Table.js.map +1 -1
- package/dist/components/TimeBarChart/TimeBarChart.js +241 -0
- package/dist/components/TimeBarChart/TimeBarChart.js.map +1 -0
- package/dist/components/TimeBarChart/TimeBarChartAxes.js +49 -0
- package/dist/components/TimeBarChart/TimeBarChartAxes.js.map +1 -0
- package/dist/components/TimeBarChart/TimeBarChartBars.js +58 -0
- package/dist/components/TimeBarChart/TimeBarChartBars.js.map +1 -0
- package/dist/components/TimeBarChart/TimeBarChartLegend.js +29 -0
- package/dist/components/TimeBarChart/TimeBarChartLegend.js.map +1 -0
- package/dist/components/TimeBarChart/TimeBarChartTable.js +33 -0
- package/dist/components/TimeBarChart/TimeBarChartTable.js.map +1 -0
- package/dist/components/TimeBarChart/TimeBarChartTooltip.js +77 -0
- package/dist/components/TimeBarChart/TimeBarChartTooltip.js.map +1 -0
- package/dist/components/TimeBarChart/stackLayout.js +25 -0
- package/dist/components/TimeBarChart/stackLayout.js.map +1 -0
- package/dist/components/TimeBarChart/timeBuckets.js +133 -0
- package/dist/components/TimeBarChart/timeBuckets.js.map +1 -0
- package/dist/components/TimeBarChart/tones.js +10 -0
- package/dist/components/TimeBarChart/tones.js.map +1 -0
- package/dist/components/Tooltip.js +93 -90
- package/dist/components/Tooltip.js.map +1 -1
- package/dist/components/activeElement.js +5 -1
- package/dist/components/activeElement.js.map +1 -1
- package/dist/components/dateMath.js +1 -0
- package/dist/components/dateMath.js.map +1 -1
- package/dist/components/filterSearchModel.js +53 -45
- package/dist/components/filterSearchModel.js.map +1 -1
- package/dist/components/frameStyles.js +14 -0
- package/dist/components/frameStyles.js.map +1 -0
- package/dist/components/headerContent.js +10 -0
- package/dist/components/headerContent.js.map +1 -0
- package/dist/components/useFollowTrigger.js +28 -0
- package/dist/components/useFollowTrigger.js.map +1 -0
- package/dist/index.d.ts +131 -9
- package/dist/index.js +24 -22
- package/dist/index.js.map +1 -1
- package/dist/tailwind.css.js +1 -1
- package/dist/theme.js +340 -340
- package/dist/theme.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dateMath.js","sources":["../../src/components/dateMath.ts"],"sourcesContent":["export type DatePickerTimeZone = 'local' | 'utc';\n\nexport type DatePickerPrecision = 'day' | 'minute' | 'second';\n\nexport type WeekStart = 'monday' | 'sunday';\n\nexport interface DayKey {\n year: number;\n month: number;\n day: number;\n}\n\nexport interface MonthKey {\n year: number;\n month: number;\n}\n\nexport interface DateTimeParts extends DayKey {\n hours: number;\n minutes: number;\n seconds: number;\n}\n\nexport interface DateRange {\n start: Date;\n end: Date;\n}\n\nconst MONTHS_SHORT = [\n 'Jan',\n 'Feb',\n 'Mar',\n 'Apr',\n 'May',\n 'Jun',\n 'Jul',\n 'Aug',\n 'Sep',\n 'Oct',\n 'Nov',\n 'Dec',\n] as const;\n\nconst WEEKDAYS_SHORT = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'] as const;\nconst WEEKDAYS_LONG = [\n 'Sunday',\n 'Monday',\n 'Tuesday',\n 'Wednesday',\n 'Thursday',\n 'Friday',\n 'Saturday',\n] as const;\n\nexport const partsOf = (date: Date, zone: DatePickerTimeZone): DateTimeParts =>\n zone === 'utc'\n ? {\n year: date.getUTCFullYear(),\n month: date.getUTCMonth(),\n day: date.getUTCDate(),\n hours: date.getUTCHours(),\n minutes: date.getUTCMinutes(),\n seconds: date.getUTCSeconds(),\n }\n : {\n year: date.getFullYear(),\n month: date.getMonth(),\n day: date.getDate(),\n hours: date.getHours(),\n minutes: date.getMinutes(),\n seconds: date.getSeconds(),\n };\n\n// `Date` reads years 0-99 as 19xx; build 400 years on (same calendar) and move back.\nconst YEAR_SHIFT = 400;\n\nexport const fromParts = (\n { year, month, day, hours = 0, minutes = 0, seconds = 0 }: DayKey & Partial<DateTimeParts>,\n zone: DatePickerTimeZone,\n milliseconds = 0,\n): Date => {\n const shift = year >= 0 && year < 100 ? YEAR_SHIFT : 0;\n if (zone === 'utc') {\n const date = new Date(\n Date.UTC(year + shift, month, day, hours, minutes, seconds, milliseconds),\n );\n if (shift) {\n date.setUTCFullYear(date.getUTCFullYear() - shift);\n }\n return date;\n }\n const date = new Date(year + shift, month, day, hours, minutes, seconds, milliseconds);\n if (shift) {\n date.setFullYear(date.getFullYear() - shift);\n }\n return date;\n};\n\nexport const dayKeyOf = (date: Date, zone: DatePickerTimeZone): DayKey => {\n const { year, month, day } = partsOf(date, zone);\n return { year, month, day };\n};\n\nexport const compareDays = (a: DayKey, b: DayKey): number =>\n a.year - b.year || a.month - b.month || a.day - b.day;\n\nexport const sameDay = (a: DayKey | null | undefined, b: DayKey | null | undefined): boolean =>\n !!a && !!b && compareDays(a, b) === 0;\n\nexport const dayKeyString = ({ year, month, day }: DayKey): string =>\n `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`;\n\nexport const startOfDay = ({ year, month, day }: DayKey, zone: DatePickerTimeZone): Date =>\n fromParts({ year, month, day }, zone);\n\nexport const endOfDay = ({ year, month, day }: DayKey, zone: DatePickerTimeZone): Date =>\n fromParts({ year, month, day, hours: 23, minutes: 59, seconds: 59 }, zone, 999);\n\nexport const addDays = (day: DayKey, amount: number): DayKey =>\n dayKeyOf(fromParts({ year: day.year, month: day.month, day: day.day + amount }, 'utc'), 'utc');\n\nexport const daysInMonth = ({ year, month }: MonthKey): number =>\n dayKeyOf(fromParts({ year, month: month + 1, day: 0 }, 'utc'), 'utc').day;\n\nexport const addMonths = ({ year, month }: MonthKey, amount: number): MonthKey => {\n const total = year * 12 + month + amount;\n return { year: Math.floor(total / 12), month: ((total % 12) + 12) % 12 };\n};\n\nexport const addMonthsToDay = (day: DayKey, amount: number): DayKey => {\n const target = addMonths(day, amount);\n return { ...target, day: Math.min(day.day, daysInMonth(target)) };\n};\n\nexport const weekdayOf = (day: DayKey): number => fromParts(day, 'utc').getUTCDay();\n\nconst WEEK_START_INDEX: Record<WeekStart, number> = { sunday: 0, monday: 1 };\n\nexport const weekdayLabels = (weekStart: WeekStart): { short: string; long: string }[] =>\n Array.from({ length: 7 }, (_, index) => {\n const weekday = (index + WEEK_START_INDEX[weekStart]) % 7;\n return { short: WEEKDAYS_SHORT[weekday], long: WEEKDAYS_LONG[weekday] };\n });\n\nexport const monthWeeks = (view: MonthKey, weekStart: WeekStart): DayKey[][] => {\n const first: DayKey = { ...view, day: 1 };\n const lead = (weekdayOf(first) - WEEK_START_INDEX[weekStart] + 7) % 7;\n const start = addDays(first, -lead);\n const weeks: DayKey[][] = [];\n for (let index = 0; index < 42; index++) {\n if (index % 7 === 0) {\n weeks.push([]);\n }\n weeks[weeks.length - 1].push(addDays(start, index));\n }\n return weeks;\n};\n\nexport const startOfWeek = (day: DayKey, weekStart: WeekStart): DayKey =>\n addDays(day, -((weekdayOf(day) - WEEK_START_INDEX[weekStart] + 7) % 7));\n\nexport const monthLabel = ({ year, month }: MonthKey): string => `${MONTHS_SHORT[month]} ${year}`;\n\nconst pad = (value: number): string => String(value).padStart(2, '0');\n\nexport const formatTime = (\n parts: Pick<DateTimeParts, 'hours' | 'minutes' | 'seconds'>,\n precision: DatePickerPrecision,\n): string =>\n precision === 'second'\n ? `${pad(parts.hours)}:${pad(parts.minutes)}:${pad(parts.seconds)}`\n : `${pad(parts.hours)}:${pad(parts.minutes)}`;\n\nconst zoneSuffix = (zone: DatePickerTimeZone): string => (zone === 'utc' ? ' UTC' : '');\n\nexport const formatDate = (\n date: Date,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): string => {\n const parts = partsOf(date, zone);\n const day = `${MONTHS_SHORT[parts.month]} ${parts.day} ${parts.year}`;\n return precision === 'day' ? day : `${day}, ${formatTime(parts, precision)}${zoneSuffix(zone)}`;\n};\n\nexport const formatTimeReadout = (\n date: Date | null,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): string =>\n `${date ? formatTime(partsOf(date, zone), precision) : precision === 'second' ? '--:--:--' : '--:--'}${zoneSuffix(zone)}`;\n\n// Lazy, so importing the module has no side effects.\nlet spokenDayFormat: Intl.DateTimeFormat | undefined;\n\nexport const spokenDay = (day: DayKey): string => {\n spokenDayFormat ??= new Intl.DateTimeFormat('en-US', {\n weekday: 'long',\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n timeZone: 'UTC',\n });\n return spokenDayFormat.format(fromParts(day, 'utc'));\n};\n\nexport const clampDate = (date: Date, min?: Date, max?: Date): Date => {\n if (min && date.getTime() < min.getTime()) {\n return new Date(min.getTime());\n }\n if (max && date.getTime() > max.getTime()) {\n return new Date(max.getTime());\n }\n return date;\n};\n\nexport const overlapsBounds = (from: Date, to: Date, min?: Date, max?: Date): boolean =>\n (!min || to.getTime() >= min.getTime()) && (!max || from.getTime() <= max.getTime());\n\nconst isValidDate = (value: unknown): value is Date =>\n value instanceof Date && !Number.isNaN(value.getTime());\n\nconst ZONELESS = /^(\\d{4})-(\\d{2})-(\\d{2})(?:[T ](\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d{1,3}))?)?)?$/;\n\nexport const toDate = (\n value: Date | string | number | null | undefined,\n zone: DatePickerTimeZone,\n): Date | null => {\n if (value === null || value === undefined || value === '') {\n return null;\n }\n // Without an offset, a string names a wall-clock time in `zone`, not in the browser's.\n const zoneless = typeof value === 'string' ? ZONELESS.exec(value) : null;\n if (zoneless) {\n const [, year, month, day, hours = '0', minutes = '0', seconds = '0', ms = ''] = zoneless;\n const parts = {\n year: Number(year),\n month: Number(month) - 1,\n day: Number(day),\n hours: Number(hours),\n minutes: Number(minutes),\n seconds: Number(seconds),\n };\n if (parts.hours > 23 || parts.minutes > 59 || parts.seconds > 59) {\n return null;\n }\n const date = fromParts(parts, zone, Number(ms.padEnd(3, '0')));\n return sameDay(dayKeyOf(date, zone), parts) ? date : null;\n }\n const date = value instanceof Date ? value : new Date(value);\n return isValidDate(date) ? date : null;\n};\n\nexport const withTime = (\n day: DayKey,\n time: Pick<DateTimeParts, 'hours' | 'minutes' | 'seconds'>,\n zone: DatePickerTimeZone,\n): Date =>\n fromParts(\n {\n year: day.year,\n month: day.month,\n day: day.day,\n hours: time.hours,\n minutes: time.minutes,\n seconds: time.seconds,\n },\n zone,\n );\n\nconst UNIT_MS: Record<Exclude<DatePickerPrecision, 'day'>, number> = {\n minute: 60_000,\n second: 1_000,\n};\n\n// Arithmetic, not a rebuild from local fields, which moves the repeated hour when clocks go back.\nexport const truncateTo = (\n date: Date,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): Date => {\n if (precision === 'day') {\n return startOfDay(partsOf(date, zone), zone);\n }\n if (zone === 'local' && !Number.isInteger(date.getTimezoneOffset())) {\n const parts = partsOf(date, zone);\n return fromParts({ ...parts, seconds: precision === 'second' ? parts.seconds : 0 }, zone);\n }\n const unit = UNIT_MS[precision];\n return new Date(Math.floor(date.getTime() / unit) * unit);\n};\n\n/** The last millisecond of the unit `date` falls in, so a range end covers the whole of it. */\nexport const endOfUnit = (\n date: Date,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): Date =>\n precision === 'day'\n ? endOfDay(dayKeyOf(date, zone), zone)\n : new Date(truncateTo(date, zone, precision).getTime() + UNIT_MS[precision] - 1);\n\nexport const ceilTo = (\n date: Date,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): Date => {\n if (precision === 'day') {\n return date;\n }\n const floor = truncateTo(date, zone, precision);\n return floor.getTime() < date.getTime()\n ? new Date(floor.getTime() + UNIT_MS[precision])\n : floor;\n};\n"],"names":["MONTHS_SHORT","WEEKDAYS_SHORT","WEEKDAYS_LONG","partsOf","date","zone","fromParts","year","month","day","hours","minutes","seconds","milliseconds","shift","dayKeyOf","compareDays","a","b","sameDay","dayKeyString","startOfDay","endOfDay","addDays","amount","daysInMonth","addMonths","total","addMonthsToDay","target","weekdayOf","WEEK_START_INDEX","weekdayLabels","weekStart","_","index","weekday","monthWeeks","view","first","lead","start","weeks","startOfWeek","monthLabel","pad","value","formatTime","parts","precision","zoneSuffix","formatDate","formatTimeReadout","spokenDayFormat","spokenDay","clampDate","min","max","overlapsBounds","from","to","isValidDate","ZONELESS","toDate","zoneless","ms","withTime","time","UNIT_MS","truncateTo","unit","endOfUnit","ceilTo","floor"],"mappings":"AA4BA,MAAMA,IAAe;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ,GAEMC,IAAiB,CAAC,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,IAAI,GAC1DC,IAAgB;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;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ACO;AACP,MAAIA,MAAc;AACd,WAAO5B,EAAWlB,EAAQC,GAAMC,CAAI,GAAGA,CAAI;AAE/C,MAAIA,MAAS,WAAW,CAAC,OAAO,UAAUD,EAAK,kBAAA,CAAmB,GAAG;AACjE,UAAM4C,IAAQ7C,EAAQC,GAAMC,CAAI;AAChC,WAAOC,EAAU,EAAE,GAAG0C,GAAO,SAASC,MAAc,WAAWD,EAAM,UAAU,EAAA,GAAK3C,CAAI;AAAA,EAC5F;AACA,QAAMiE,IAAOF,EAAQnB,CAAS;AAC9B,SAAO,IAAI,KAAK,KAAK,MAAM7C,EAAK,QAAA,IAAYkE,CAAI,IAAIA,CAAI;AAC5D,GAGaC,IAAY,CACrBnE,GACAC,GACA4C,MAEAA,MAAc,QACR3B,EAASP,EAASX,GAAMC,CAAI,GAAGA,CAAI,IACnC,IAAI,KAAKgE,EAAWjE,GAAMC,GAAM4C,CAAS,EAAE,QAAA,IAAYmB,EAAQnB,CAAS,IAAI,CAAC,GAE1EuB,IAAS,CAClBpE,GACAC,GACA4C,MACO;AACP,MAAIA,MAAc;AACd,WAAO7C;AAEX,QAAMqE,IAAQJ,EAAWjE,GAAMC,GAAM4C,CAAS;AAC9C,SAAOwB,EAAM,QAAA,IAAYrE,EAAK,YACxB,IAAI,KAAKqE,EAAM,QAAA,IAAYL,EAAQnB,CAAS,CAAC,IAC7CwB;AACV;"}
|
|
1
|
+
{"version":3,"file":"dateMath.js","sources":["../../src/components/dateMath.ts"],"sourcesContent":["export type DatePickerTimeZone = 'local' | 'utc';\n\nexport type DatePickerPrecision = 'day' | 'minute' | 'second';\n\nexport type WeekStart = 'monday' | 'sunday';\n\nexport interface DayKey {\n year: number;\n month: number;\n day: number;\n}\n\nexport interface MonthKey {\n year: number;\n month: number;\n}\n\nexport interface DateTimeParts extends DayKey {\n hours: number;\n minutes: number;\n seconds: number;\n}\n\nexport interface DateRange {\n start: Date;\n end: Date;\n}\n\nexport const MONTHS_SHORT = [\n 'Jan',\n 'Feb',\n 'Mar',\n 'Apr',\n 'May',\n 'Jun',\n 'Jul',\n 'Aug',\n 'Sep',\n 'Oct',\n 'Nov',\n 'Dec',\n] as const;\n\nconst WEEKDAYS_SHORT = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'] as const;\nconst WEEKDAYS_LONG = [\n 'Sunday',\n 'Monday',\n 'Tuesday',\n 'Wednesday',\n 'Thursday',\n 'Friday',\n 'Saturday',\n] as const;\n\nexport const partsOf = (date: Date, zone: DatePickerTimeZone): DateTimeParts =>\n zone === 'utc'\n ? {\n year: date.getUTCFullYear(),\n month: date.getUTCMonth(),\n day: date.getUTCDate(),\n hours: date.getUTCHours(),\n minutes: date.getUTCMinutes(),\n seconds: date.getUTCSeconds(),\n }\n : {\n year: date.getFullYear(),\n month: date.getMonth(),\n day: date.getDate(),\n hours: date.getHours(),\n minutes: date.getMinutes(),\n seconds: date.getSeconds(),\n };\n\n// `Date` reads years 0-99 as 19xx; build 400 years on (same calendar) and move back.\nconst YEAR_SHIFT = 400;\n\nexport const fromParts = (\n { year, month, day, hours = 0, minutes = 0, seconds = 0 }: DayKey & Partial<DateTimeParts>,\n zone: DatePickerTimeZone,\n milliseconds = 0,\n): Date => {\n const shift = year >= 0 && year < 100 ? YEAR_SHIFT : 0;\n if (zone === 'utc') {\n const date = new Date(\n Date.UTC(year + shift, month, day, hours, minutes, seconds, milliseconds),\n );\n if (shift) {\n date.setUTCFullYear(date.getUTCFullYear() - shift);\n }\n return date;\n }\n const date = new Date(year + shift, month, day, hours, minutes, seconds, milliseconds);\n if (shift) {\n date.setFullYear(date.getFullYear() - shift);\n }\n return date;\n};\n\nexport const dayKeyOf = (date: Date, zone: DatePickerTimeZone): DayKey => {\n const { year, month, day } = partsOf(date, zone);\n return { year, month, day };\n};\n\nexport const compareDays = (a: DayKey, b: DayKey): number =>\n a.year - b.year || a.month - b.month || a.day - b.day;\n\nexport const sameDay = (a: DayKey | null | undefined, b: DayKey | null | undefined): boolean =>\n !!a && !!b && compareDays(a, b) === 0;\n\nexport const dayKeyString = ({ year, month, day }: DayKey): string =>\n `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`;\n\nexport const startOfDay = ({ year, month, day }: DayKey, zone: DatePickerTimeZone): Date =>\n fromParts({ year, month, day }, zone);\n\nexport const endOfDay = ({ year, month, day }: DayKey, zone: DatePickerTimeZone): Date =>\n fromParts({ year, month, day, hours: 23, minutes: 59, seconds: 59 }, zone, 999);\n\nexport const addDays = (day: DayKey, amount: number): DayKey =>\n dayKeyOf(fromParts({ year: day.year, month: day.month, day: day.day + amount }, 'utc'), 'utc');\n\nexport const daysInMonth = ({ year, month }: MonthKey): number =>\n dayKeyOf(fromParts({ year, month: month + 1, day: 0 }, 'utc'), 'utc').day;\n\nexport const addMonths = ({ year, month }: MonthKey, amount: number): MonthKey => {\n const total = year * 12 + month + amount;\n return { year: Math.floor(total / 12), month: ((total % 12) + 12) % 12 };\n};\n\nexport const addMonthsToDay = (day: DayKey, amount: number): DayKey => {\n const target = addMonths(day, amount);\n return { ...target, day: Math.min(day.day, daysInMonth(target)) };\n};\n\nexport const weekdayOf = (day: DayKey): number => fromParts(day, 'utc').getUTCDay();\n\nconst WEEK_START_INDEX: Record<WeekStart, number> = { sunday: 0, monday: 1 };\n\nexport const weekdayLabels = (weekStart: WeekStart): { short: string; long: string }[] =>\n Array.from({ length: 7 }, (_, index) => {\n const weekday = (index + WEEK_START_INDEX[weekStart]) % 7;\n return { short: WEEKDAYS_SHORT[weekday], long: WEEKDAYS_LONG[weekday] };\n });\n\nexport const monthWeeks = (view: MonthKey, weekStart: WeekStart): DayKey[][] => {\n const first: DayKey = { ...view, day: 1 };\n const lead = (weekdayOf(first) - WEEK_START_INDEX[weekStart] + 7) % 7;\n const start = addDays(first, -lead);\n const weeks: DayKey[][] = [];\n for (let index = 0; index < 42; index++) {\n if (index % 7 === 0) {\n weeks.push([]);\n }\n weeks[weeks.length - 1].push(addDays(start, index));\n }\n return weeks;\n};\n\nexport const startOfWeek = (day: DayKey, weekStart: WeekStart): DayKey =>\n addDays(day, -((weekdayOf(day) - WEEK_START_INDEX[weekStart] + 7) % 7));\n\nexport const monthLabel = ({ year, month }: MonthKey): string => `${MONTHS_SHORT[month]} ${year}`;\n\nconst pad = (value: number): string => String(value).padStart(2, '0');\n\nexport const formatTime = (\n parts: Pick<DateTimeParts, 'hours' | 'minutes' | 'seconds'>,\n precision: DatePickerPrecision,\n): string =>\n precision === 'second'\n ? `${pad(parts.hours)}:${pad(parts.minutes)}:${pad(parts.seconds)}`\n : `${pad(parts.hours)}:${pad(parts.minutes)}`;\n\nconst zoneSuffix = (zone: DatePickerTimeZone): string => (zone === 'utc' ? ' UTC' : '');\n\nexport const formatDate = (\n date: Date,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): string => {\n const parts = partsOf(date, zone);\n const day = `${MONTHS_SHORT[parts.month]} ${parts.day} ${parts.year}`;\n return precision === 'day' ? day : `${day}, ${formatTime(parts, precision)}${zoneSuffix(zone)}`;\n};\n\nexport const formatTimeReadout = (\n date: Date | null,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): string =>\n `${date ? formatTime(partsOf(date, zone), precision) : precision === 'second' ? '--:--:--' : '--:--'}${zoneSuffix(zone)}`;\n\n// Lazy, so importing the module has no side effects.\nlet spokenDayFormat: Intl.DateTimeFormat | undefined;\n\nexport const spokenDay = (day: DayKey): string => {\n spokenDayFormat ??= new Intl.DateTimeFormat('en-US', {\n weekday: 'long',\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n timeZone: 'UTC',\n });\n return spokenDayFormat.format(fromParts(day, 'utc'));\n};\n\nexport const clampDate = (date: Date, min?: Date, max?: Date): Date => {\n if (min && date.getTime() < min.getTime()) {\n return new Date(min.getTime());\n }\n if (max && date.getTime() > max.getTime()) {\n return new Date(max.getTime());\n }\n return date;\n};\n\nexport const overlapsBounds = (from: Date, to: Date, min?: Date, max?: Date): boolean =>\n (!min || to.getTime() >= min.getTime()) && (!max || from.getTime() <= max.getTime());\n\nconst isValidDate = (value: unknown): value is Date =>\n value instanceof Date && !Number.isNaN(value.getTime());\n\nconst ZONELESS = /^(\\d{4})-(\\d{2})-(\\d{2})(?:[T ](\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d{1,3}))?)?)?$/;\n\nexport const toDate = (\n value: Date | string | number | null | undefined,\n zone: DatePickerTimeZone,\n): Date | null => {\n if (value === null || value === undefined || value === '') {\n return null;\n }\n // Without an offset, a string names a wall-clock time in `zone`, not in the browser's.\n const zoneless = typeof value === 'string' ? ZONELESS.exec(value) : null;\n if (zoneless) {\n const [, year, month, day, hours = '0', minutes = '0', seconds = '0', ms = ''] = zoneless;\n const parts = {\n year: Number(year),\n month: Number(month) - 1,\n day: Number(day),\n hours: Number(hours),\n minutes: Number(minutes),\n seconds: Number(seconds),\n };\n if (parts.hours > 23 || parts.minutes > 59 || parts.seconds > 59) {\n return null;\n }\n const date = fromParts(parts, zone, Number(ms.padEnd(3, '0')));\n return sameDay(dayKeyOf(date, zone), parts) ? date : null;\n }\n const date = value instanceof Date ? value : new Date(value);\n return isValidDate(date) ? date : null;\n};\n\nexport const withTime = (\n day: DayKey,\n time: Pick<DateTimeParts, 'hours' | 'minutes' | 'seconds'>,\n zone: DatePickerTimeZone,\n): Date =>\n fromParts(\n {\n year: day.year,\n month: day.month,\n day: day.day,\n hours: time.hours,\n minutes: time.minutes,\n seconds: time.seconds,\n },\n zone,\n );\n\nconst UNIT_MS: Record<Exclude<DatePickerPrecision, 'day'>, number> = {\n minute: 60_000,\n second: 1_000,\n};\n\n// Arithmetic, not a rebuild from local fields, which moves the repeated hour when clocks go back.\nexport const truncateTo = (\n date: Date,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): Date => {\n if (precision === 'day') {\n return startOfDay(partsOf(date, zone), zone);\n }\n if (zone === 'local' && !Number.isInteger(date.getTimezoneOffset())) {\n const parts = partsOf(date, zone);\n return fromParts({ ...parts, seconds: precision === 'second' ? parts.seconds : 0 }, zone);\n }\n const unit = UNIT_MS[precision];\n return new Date(Math.floor(date.getTime() / unit) * unit);\n};\n\n/** The last millisecond of the unit `date` falls in, so a range end covers the whole of it. */\nexport const endOfUnit = (\n date: Date,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): Date =>\n precision === 'day'\n ? endOfDay(dayKeyOf(date, zone), zone)\n : new Date(truncateTo(date, zone, precision).getTime() + UNIT_MS[precision] - 1);\n\nexport const ceilTo = (\n date: Date,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): Date => {\n if (precision === 'day') {\n return date;\n }\n const floor = truncateTo(date, zone, precision);\n return floor.getTime() < date.getTime()\n ? new Date(floor.getTime() + UNIT_MS[precision])\n : floor;\n};\n"],"names":["MONTHS_SHORT","WEEKDAYS_SHORT","WEEKDAYS_LONG","partsOf","date","zone","fromParts","year","month","day","hours","minutes","seconds","milliseconds","shift","dayKeyOf","compareDays","a","b","sameDay","dayKeyString","startOfDay","endOfDay","addDays","amount","daysInMonth","addMonths","total","addMonthsToDay","target","weekdayOf","WEEK_START_INDEX","weekdayLabels","weekStart","_","index","weekday","monthWeeks","view","first","lead","start","weeks","startOfWeek","monthLabel","pad","value","formatTime","parts","precision","zoneSuffix","formatDate","formatTimeReadout","spokenDayFormat","spokenDay","clampDate","min","max","overlapsBounds","from","to","isValidDate","ZONELESS","toDate","zoneless","ms","withTime","time","UNIT_MS","truncateTo","unit","endOfUnit","ceilTo","floor"],"mappings":"AA4BO,MAAMA,IAAe;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ,GAEMC,IAAiB,CAAC,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,IAAI,GAC1DC,IAAgB;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,E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GACAC,GACA4C,MACO;AACP,MAAIA,MAAc;AACd,WAAO5B,EAAWlB,EAAQC,GAAMC,CAAI,GAAGA,CAAI;AAE/C,MAAIA,MAAS,WAAW,CAAC,OAAO,UAAUD,EAAK,kBAAA,CAAmB,GAAG;AACjE,UAAM4C,IAAQ7C,EAAQC,GAAMC,CAAI;AAChC,WAAOC,EAAU,EAAE,GAAG0C,GAAO,SAASC,MAAc,WAAWD,EAAM,UAAU,EAAA,GAAK3C,CAAI;AAAA,EAC5F;AACA,QAAMiE,IAAOF,EAAQnB,CAAS;AAC9B,SAAO,IAAI,KAAK,KAAK,MAAM7C,EAAK,QAAA,IAAYkE,CAAI,IAAIA,CAAI;AAC5D,GAGaC,IAAY,CACrBnE,GACAC,GACA4C,MAEAA,MAAc,QACR3B,EAASP,EAASX,GAAMC,CAAI,GAAGA,CAAI,IACnC,IAAI,KAAKgE,EAAWjE,GAAMC,GAAM4C,CAAS,EAAE,QAAA,IAAYmB,EAAQnB,CAAS,IAAI,CAAC,GAE1EuB,IAAS,CAClBpE,GACAC,GACA4C,MACO;AACP,MAAIA,MAAc;AACd,WAAO7C;AAEX,QAAMqE,IAAQJ,EAAWjE,GAAMC,GAAM4C,CAAS;AAC9C,SAAOwB,EAAM,QAAA,IAAYrE,EAAK,YACxB,IAAI,KAAKqE,EAAM,QAAA,IAAYL,EAAQnB,CAAS,CAAC,IAC7CwB;AACV;"}
|
|
@@ -1,76 +1,84 @@
|
|
|
1
|
-
const
|
|
1
|
+
const w = (e, t) => e !== null ? "items" : t.trim().length > 0 ? "search" : "filters", u = (e, t) => {
|
|
2
2
|
const s = t.trim().toLowerCase();
|
|
3
3
|
return e.label.toLowerCase().includes(s) || e.value.toLowerCase().includes(s);
|
|
4
4
|
}, c = (e, t) => {
|
|
5
5
|
var s;
|
|
6
6
|
return new Set(((s = e.find((l) => l.filter === t)) == null ? void 0 : s.items) ?? []);
|
|
7
|
-
},
|
|
7
|
+
}, p = (e, t) => e.flatMap((s) => {
|
|
8
8
|
const l = c(t, s.value);
|
|
9
9
|
return s.items.map((o) => ({ item: o, filter: s, selected: l.has(o.value) }));
|
|
10
|
-
}),
|
|
11
|
-
const s = e.filter((
|
|
12
|
-
if (!s.some((
|
|
13
|
-
const l = e.every((
|
|
10
|
+
}), g = (e, t) => {
|
|
11
|
+
const s = e.filter((n) => u(n.item, t));
|
|
12
|
+
if (!s.some((n) => !n.item.disabled)) return null;
|
|
13
|
+
const l = e.every((n) => n.item.disabled || n.selected), o = t.trim().length > 0 && s.filter((n) => !n.item.disabled).every((n) => n.selected);
|
|
14
14
|
return l || o ? "deselect" : "select";
|
|
15
|
-
},
|
|
16
|
-
toggle:
|
|
17
|
-
items: e.filter((s) =>
|
|
18
|
-
}),
|
|
15
|
+
}, v = (e, t) => ({
|
|
16
|
+
toggle: g(e, t),
|
|
17
|
+
items: e.filter((s) => u(s.item, t))
|
|
18
|
+
}), S = (e, t, s, l) => {
|
|
19
|
+
var f;
|
|
20
|
+
if (e === null) return;
|
|
21
|
+
const o = t.find((i) => i.value === e), n = s == null ? void 0 : s.find((i) => i.value === e);
|
|
22
|
+
if (!o || !n) return o ?? n;
|
|
23
|
+
const r = new Set((f = l.find((i) => i.filter === e)) == null ? void 0 : f.items), a = new Set(o.items.map((i) => i.value)), m = n.items.filter((i) => r.has(i.value) && !a.has(i.value));
|
|
24
|
+
return m.length ? { ...o, items: [...o.items, ...m] } : o;
|
|
25
|
+
}, y = (e, t, s) => e ? v(p([e], t), s) : { toggle: null, items: [] }, C = (e, t, s) => v(p(e, t), s), h = (e, t) => {
|
|
19
26
|
const s = new Set(t);
|
|
20
27
|
return e.length === s.size && e.every((l) => s.has(l));
|
|
21
|
-
},
|
|
28
|
+
}, d = (e, t) => {
|
|
22
29
|
const s = t.filter(
|
|
23
|
-
(
|
|
24
|
-
), l = new Map(s.map((
|
|
25
|
-
filter:
|
|
26
|
-
items: l.get(
|
|
27
|
-
})).filter((
|
|
28
|
-
(
|
|
30
|
+
(r) => !h(r.items, [...c(e, r.filter)])
|
|
31
|
+
), l = new Map(s.map((r) => [r.filter, r.items])), o = e.map((r) => ({
|
|
32
|
+
filter: r.filter,
|
|
33
|
+
items: l.get(r.filter) ?? r.items
|
|
34
|
+
})).filter((r) => r.items.length > 0), n = s.filter(
|
|
35
|
+
(r) => r.items.length > 0 && !e.some((a) => a.filter === r.filter)
|
|
29
36
|
);
|
|
30
|
-
return { next: [...o, ...
|
|
31
|
-
},
|
|
32
|
-
const l = [...c(e, t)], o = l.includes(s) ? l.filter((
|
|
33
|
-
return
|
|
34
|
-
},
|
|
37
|
+
return { next: [...o, ...n], changes: s };
|
|
38
|
+
}, M = (e, t, s) => {
|
|
39
|
+
const l = [...c(e, t)], o = l.includes(s) ? l.filter((n) => n !== s) : [...l, s];
|
|
40
|
+
return d(e, [{ filter: t, items: o }]);
|
|
41
|
+
}, $ = (e, t, s) => d(
|
|
35
42
|
t,
|
|
36
43
|
e.map((l) => {
|
|
37
|
-
const o = c(t, l.value),
|
|
38
|
-
(
|
|
39
|
-
).map((
|
|
40
|
-
return { filter: l.value, items: [...o, ...
|
|
44
|
+
const o = c(t, l.value), n = l.items.filter(
|
|
45
|
+
(r) => !o.has(r.value) && !r.disabled && u(r, s)
|
|
46
|
+
).map((r) => r.value);
|
|
47
|
+
return { filter: l.value, items: [...o, ...n] };
|
|
41
48
|
})
|
|
42
|
-
),
|
|
49
|
+
), b = (e, t, s) => d(
|
|
43
50
|
t,
|
|
44
51
|
e.map((l) => {
|
|
45
|
-
const o = c(t, l.value),
|
|
46
|
-
l.items.filter((
|
|
52
|
+
const o = c(t, l.value), n = new Set(
|
|
53
|
+
l.items.filter((r) => !r.disabled && u(r, s)).map((r) => r.value)
|
|
47
54
|
);
|
|
48
55
|
return {
|
|
49
56
|
filter: l.value,
|
|
50
|
-
items: [...o].filter((
|
|
57
|
+
items: [...o].filter((r) => !n.has(r))
|
|
51
58
|
};
|
|
52
59
|
})
|
|
53
|
-
),
|
|
60
|
+
), k = (e, t) => d(e, [{ filter: t, items: [] }]), x = (e) => d(
|
|
54
61
|
e,
|
|
55
62
|
e.map((t) => ({ filter: t.filter, items: [] }))
|
|
56
|
-
),
|
|
57
|
-
const l = new Set(e.map((
|
|
63
|
+
), A = (e, t) => t.length === 0 ? e : t.length === 1 ? `${e}: ${t[0]}` : `${e}: (${t.join(", ")})`, R = (e, t, s = null) => {
|
|
64
|
+
const l = new Set(e.map((n) => n.filter)), o = t.filter((n) => l.has(n) || n === s);
|
|
58
65
|
return [
|
|
59
66
|
...o,
|
|
60
|
-
...e.map((
|
|
67
|
+
...e.map((n) => n.filter).filter((n) => !o.includes(n))
|
|
61
68
|
];
|
|
62
69
|
};
|
|
63
70
|
export {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
A as chipText,
|
|
72
|
+
x as clearAll,
|
|
73
|
+
b as deselectAll,
|
|
74
|
+
y as filterRows,
|
|
75
|
+
u as matchesQuery,
|
|
76
|
+
S as openFilterOf,
|
|
77
|
+
R as orderSelections,
|
|
78
|
+
k as removeFilter,
|
|
79
|
+
w as resolveMode,
|
|
80
|
+
C as searchRows,
|
|
81
|
+
$ as selectAll,
|
|
82
|
+
M as toggleValue
|
|
75
83
|
};
|
|
76
84
|
//# sourceMappingURL=filterSearchModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterSearchModel.js","sources":["../../src/components/filterSearchModel.ts"],"sourcesContent":["export interface FilterSearchItem {\n value: string;\n label: string;\n disabled?: boolean;\n}\n\nexport interface FilterSearchFilter {\n value: string;\n label: string;\n /** Shown beside the filter's name in the menu, and beside its values in a cross-filter search. */\n info?: string;\n /** Right-aligned hint on the filter's row, e.g. `e.g. Attio, Ashby`. */\n example?: string;\n items: FilterSearchItem[];\n}\n\nexport interface FilterSearchSelection {\n filter: string;\n items: string[];\n}\n\n/** One filter's new values. An empty `items` means the filter was removed. */\nexport interface FilterSearchChange {\n filter: string;\n items: string[];\n}\n\nexport interface FilterSearchUpdate {\n next: FilterSearchSelection[];\n changes: FilterSearchChange[];\n}\n\nexport type FilterSearchMode = 'filters' | 'items' | 'search';\n\nexport type FilterSearchToggle = 'select' | 'deselect';\n\nexport interface FilterSearchItemRow {\n item: FilterSearchItem;\n filter: FilterSearchFilter;\n selected: boolean;\n}\n\nexport interface FilterSearchRows {\n /** The Select All / Deselect All row, absent when no enabled value matches. */\n toggle: FilterSearchToggle | null;\n items: FilterSearchItemRow[];\n}\n\nexport const resolveMode = (activeFilter: string | null, query: string): FilterSearchMode => {\n if (activeFilter !== null) return 'items';\n return query.trim().length > 0 ? 'search' : 'filters';\n};\n\nexport const matchesQuery = (item: FilterSearchItem, query: string): boolean => {\n const needle = query.trim().toLowerCase();\n return item.label.toLowerCase().includes(needle) || item.value.toLowerCase().includes(needle);\n};\n\nconst selectedValues = (selections: FilterSearchSelection[], filter: string): Set<string> =>\n new Set(selections.find((selection) => selection.filter === filter)?.items ?? []);\n\nconst toRows = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n): FilterSearchItemRow[] =>\n filters.flatMap((filter) => {\n const selected = selectedValues(selections, filter.value);\n return filter.items.map((item) => ({ item, filter, selected: selected.has(item.value) }));\n });\n\n/**\n * \"Deselect All\" replaces \"Select All\" once every enabled value is chosen, or once every value\n * the query matches is.\n */\nconst toggleFor = (all: FilterSearchItemRow[], query: string): FilterSearchToggle | null => {\n const matched = all.filter((row) => matchesQuery(row.item, query));\n if (!matched.some((row) => !row.item.disabled)) return null;\n\n const everyEnabledSelected = all.every((row) => row.item.disabled || row.selected);\n const everyMatchSelected =\n query.trim().length > 0 &&\n matched.filter((row) => !row.item.disabled).every((row) => row.selected);\n\n return everyEnabledSelected || everyMatchSelected ? 'deselect' : 'select';\n};\n\nconst rowsFor = (all: FilterSearchItemRow[], query: string): FilterSearchRows => ({\n toggle: toggleFor(all, query),\n items: all.filter((row) => matchesQuery(row.item, query)),\n});\n\n/** The values of one filter, as the menu lists them once that filter is picked. */\nexport const filterRows = (\n filter: FilterSearchFilter | undefined,\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchRows =>\n filter ? rowsFor(toRows([filter], selections), query) : { toggle: null, items: [] };\n\n/** The values of every filter that match a query typed before any filter was picked. */\nexport const searchRows = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchRows => rowsFor(toRows(filters, selections), query);\n\n// As sets: a Select All that adds nothing returns the values in item order, not the order chosen.\nconst sameItems = (a: string[], b: string[]) => {\n const set = new Set(b);\n return a.length === set.size && a.every((value) => set.has(value));\n};\n\n/** Applies per-filter changes, keeping each filter where it already was and dropping the emptied. */\nconst applyChanges = (\n selections: FilterSearchSelection[],\n proposed: FilterSearchChange[],\n): FilterSearchUpdate => {\n const changes = proposed.filter(\n (change) => !sameItems(change.items, [...selectedValues(selections, change.filter)]),\n );\n const byFilter = new Map(changes.map((change) => [change.filter, change.items]));\n const kept = selections\n .map((selection) => ({\n filter: selection.filter,\n items: byFilter.get(selection.filter) ?? selection.items,\n }))\n .filter((selection) => selection.items.length > 0);\n const added = changes.filter(\n (change) =>\n change.items.length > 0 &&\n !selections.some((selection) => selection.filter === change.filter),\n );\n\n return { next: [...kept, ...added], changes };\n};\n\nexport const toggleValue = (\n selections: FilterSearchSelection[],\n filter: string,\n value: string,\n): FilterSearchUpdate => {\n const current = [...selectedValues(selections, filter)];\n const items = current.includes(value)\n ? current.filter((item) => item !== value)\n : [...current, value];\n\n return applyChanges(selections, [{ filter, items }]);\n};\n\n/** Select All keeps what is already chosen and adds every enabled value the query matches. */\nexport const selectAll = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchUpdate =>\n applyChanges(\n selections,\n filters.map((filter) => {\n const selected = selectedValues(selections, filter.value);\n const added = filter.items\n .filter(\n (item) =>\n !selected.has(item.value) && !item.disabled && matchesQuery(item, query),\n )\n .map((item) => item.value);\n // Chosen values stay even when `items` no longer lists them (a stale or lazy list).\n return { filter: filter.value, items: [...selected, ...added] };\n }),\n );\n\n/** Deselect All drops every enabled value the query matches and keeps the rest. */\nexport const deselectAll = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchUpdate =>\n applyChanges(\n selections,\n filters.map((filter) => {\n const selected = selectedValues(selections, filter.value);\n const dropped = new Set(\n filter.items\n .filter((item) => !item.disabled && matchesQuery(item, query))\n .map((item) => item.value),\n );\n return {\n filter: filter.value,\n items: [...selected].filter((value) => !dropped.has(value)),\n };\n }),\n );\n\nexport const removeFilter = (\n selections: FilterSearchSelection[],\n filter: string,\n): FilterSearchUpdate => applyChanges(selections, [{ filter, items: [] }]);\n\nexport const clearAll = (selections: FilterSearchSelection[]): FilterSearchUpdate =>\n applyChanges(\n selections,\n selections.map((selection) => ({ filter: selection.filter, items: [] })),\n );\n\n/** `Connector: Notion`, or `Connector: (Notion, Attio)` once there is more than one value. */\nexport const chipText = (filterLabel: string, itemLabels: string[]): string => {\n if (itemLabels.length === 0) return filterLabel;\n if (itemLabels.length === 1) return `${filterLabel}: ${itemLabels[0]}`;\n return `${filterLabel}: (${itemLabels.join(', ')})`;\n};\n\n/**\n * The order chips show filters in: when each was first added. A consumer reading its selection back\n * from the URL gets it in a fixed key order, which would reshuffle the chips on every change.\n */\nexport const orderSelections = (\n selections: FilterSearchSelection[],\n order: string[],\n /** A filter to hold its place in `order` while it has no values, e.g. the one being edited. */\n keep: string | null = null,\n): string[] => {\n const present = new Set(selections.map((selection) => selection.filter));\n const kept = order.filter((filter) => present.has(filter) || filter === keep);\n return [\n ...kept,\n ...selections.map((selection) => selection.filter).filter((f) => !kept.includes(f)),\n ];\n};\n"],"names":["resolveMode","activeFilter","query","matchesQuery","item","needle","selectedValues","selections","filter","_a","selection","toRows","filters","selected","toggleFor","all","matched","row","everyEnabledSelected","everyMatchSelected","rowsFor","filterRows","searchRows","sameItems","a","b","set","value","applyChanges","proposed","changes","change","byFilter","kept","added","toggleValue","current","items","selectAll","deselectAll","dropped","removeFilter","clearAll","chipText","filterLabel","itemLabels","orderSelections","order","keep","present","f"],"mappings":"AAgDO,MAAMA,IAAc,CAACC,GAA6BC,MACjDD,MAAiB,OAAa,UAC3BC,EAAM,KAAA,EAAO,SAAS,IAAI,WAAW,WAGnCC,IAAe,CAACC,GAAwBF,MAA2B;AAC5E,QAAMG,IAASH,EAAM,KAAA,EAAO,YAAA;AAC5B,SAAOE,EAAK,MAAM,YAAA,EAAc,SAASC,CAAM,KAAKD,EAAK,MAAM,cAAc,SAASC,CAAM;AAChG,GAEMC,IAAiB,CAACC,GAAqCC,MAAA;AAVtD,MAAAC;AAWH,aAAI,MAAIA,IAAAF,EAAW,KAAK,CAACG,MAAcA,EAAU,WAAWF,CAAM,MAA1D,gBAAAC,EAA6D,UAAS,CAAA,CAAE;AAAA,GAE9EE,IAAS,CACXC,GACAL,MAEAK,EAAQ,QAAQ,CAACJ,MAAW;AACxB,QAAMK,IAAWP,EAAeC,GAAYC,EAAO,KAAK;AACxD,SAAOA,EAAO,MAAM,IAAI,CAACJ,OAAU,EAAE,MAAAA,GAAM,QAAAI,GAAQ,UAAUK,EAAS,IAAIT,EAAK,KAAK,IAAI;AAC5F,CAAC,GAMCU,IAAY,CAACC,GAA4Bb,MAA6C;AACxF,QAAMc,IAAUD,EAAI,OAAO,CAACE,MAAQd,EAAac,EAAI,MAAMf,CAAK,CAAC;AACjE,MAAI,CAACc,EAAQ,KAAK,CAACC,MAAQ,CAACA,EAAI,KAAK,QAAQ,EAAG,QAAO;AAEvD,QAAMC,IAAuBH,EAAI,MAAM,CAACE,MAAQA,EAAI,KAAK,YAAYA,EAAI,QAAQ,GAC3EE,IACFjB,EAAM,KAAA,EAAO,SAAS,KACtBc,EAAQ,OAAO,CAACC,MAAQ,CAACA,EAAI,KAAK,QAAQ,EAAE,MAAM,CAACA,MAA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C;AAAA,IAAA;AAAA,EAElE,CAAC;AACL,GAESc,IAAe,CACxBlC,GACAC,MACqBoB,EAAarB,GAAY,CAAC,EAAE,QAAAC,GAAQ,OAAO,CAAA,GAAI,CAAC,GAE5DkC,IAAW,CAACnC,MACrBqB;AAAA,EACIrB;AAAA,EACAA,EAAW,IAAI,CAACG,OAAe,EAAE,QAAQA,EAAU,QAAQ,OAAO,CAAA,IAAK;AAC3E,GAGSiC,IAAW,CAACC,GAAqBC,MACtCA,EAAW,WAAW,IAAUD,IAChCC,EAAW,WAAW,IAAU,GAAGD,CAAW,KAAKC,EAAW,CAAC,CAAC,KAC7D,GAAGD,CAAW,MAAMC,EAAW,KAAK,IAAI,CAAC,KAOvCC,IAAkB,CAC3BvC,GACAwC,GAEAC,IAAsB,SACX;AACX,QAAMC,IAAU,IAAI,IAAI1C,EAAW,IAAI,CAACG,MAAcA,EAAU,MAAM,CAAC,GACjEuB,IAAOc,EAAM,OAAO,CAACvC,MAAWyC,EAAQ,IAAIzC,CAAM,KAAKA,MAAWwC,CAAI;AAC5E,SAAO;AAAA,IACH,GAAGf;AAAA,IACH,GAAG1B,EAAW,IAAI,CAACG,MAAcA,EAAU,MAAM,EAAE,OAAO,CAACwC,MAAM,CAACjB,EAAK,SAASiB,CAAC,CAAC;AAAA,EAAA;AAE1F;"}
|
|
1
|
+
{"version":3,"file":"filterSearchModel.js","sources":["../../src/components/filterSearchModel.ts"],"sourcesContent":["export interface FilterSearchItem {\n value: string;\n label: string;\n disabled?: boolean;\n}\n\nexport interface FilterSearchFilter {\n value: string;\n label: string;\n /** Shown beside the filter's name in the menu, and beside its values in a cross-filter search. */\n info?: string;\n /** Right-aligned hint on the filter's row, e.g. `e.g. Attio, Ashby`. */\n example?: string;\n items: FilterSearchItem[];\n}\n\nexport interface FilterSearchSelection {\n filter: string;\n items: string[];\n}\n\n/** One filter's new values. An empty `items` means the filter was removed. */\nexport interface FilterSearchChange {\n filter: string;\n items: string[];\n}\n\nexport interface FilterSearchUpdate {\n next: FilterSearchSelection[];\n changes: FilterSearchChange[];\n}\n\nexport type FilterSearchMode = 'filters' | 'items' | 'search';\n\nexport type FilterSearchToggle = 'select' | 'deselect';\n\nexport interface FilterSearchItemRow {\n item: FilterSearchItem;\n filter: FilterSearchFilter;\n selected: boolean;\n}\n\nexport interface FilterSearchRows {\n /** The Select All / Deselect All row, absent when no enabled value matches. */\n toggle: FilterSearchToggle | null;\n items: FilterSearchItemRow[];\n}\n\nexport const resolveMode = (activeFilter: string | null, query: string): FilterSearchMode => {\n if (activeFilter !== null) return 'items';\n return query.trim().length > 0 ? 'search' : 'filters';\n};\n\nexport const matchesQuery = (item: FilterSearchItem, query: string): boolean => {\n const needle = query.trim().toLowerCase();\n return item.label.toLowerCase().includes(needle) || item.value.toLowerCase().includes(needle);\n};\n\nconst selectedValues = (selections: FilterSearchSelection[], filter: string): Set<string> =>\n new Set(selections.find((selection) => selection.filter === filter)?.items ?? []);\n\nconst toRows = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n): FilterSearchItemRow[] =>\n filters.flatMap((filter) => {\n const selected = selectedValues(selections, filter.value);\n return filter.items.map((item) => ({ item, filter, selected: selected.has(item.value) }));\n });\n\n/**\n * \"Deselect All\" replaces \"Select All\" once every enabled value is chosen, or once every value\n * the query matches is.\n */\nconst toggleFor = (all: FilterSearchItemRow[], query: string): FilterSearchToggle | null => {\n const matched = all.filter((row) => matchesQuery(row.item, query));\n if (!matched.some((row) => !row.item.disabled)) return null;\n\n const everyEnabledSelected = all.every((row) => row.item.disabled || row.selected);\n const everyMatchSelected =\n query.trim().length > 0 &&\n matched.filter((row) => !row.item.disabled).every((row) => row.selected);\n\n return everyEnabledSelected || everyMatchSelected ? 'deselect' : 'select';\n};\n\nconst rowsFor = (all: FilterSearchItemRow[], query: string): FilterSearchRows => ({\n toggle: toggleFor(all, query),\n items: all.filter((row) => matchesQuery(row.item, query)),\n});\n\n/** The values of one filter, as the menu lists them once that filter is picked. */\n/**\n * The open filter as its menu lists it: `filters`' entry, with any picked value only\n * `searchFilters` holds added back, so a value picked through search can be unticked from its\n * own chip. A filter only `searchFilters` holds is listed from there.\n */\nexport const openFilterOf = (\n active: string | null,\n filters: FilterSearchFilter[],\n searchFilters: FilterSearchFilter[] | undefined,\n selections: FilterSearchSelection[],\n): FilterSearchFilter | undefined => {\n if (active === null) return undefined;\n const narrowed = filters.find((filter) => filter.value === active);\n const wide = searchFilters?.find((filter) => filter.value === active);\n if (!narrowed || !wide) return narrowed ?? wide;\n const picked = new Set(selections.find((selection) => selection.filter === active)?.items);\n const listed = new Set(narrowed.items.map((item) => item.value));\n const missing = wide.items.filter((item) => picked.has(item.value) && !listed.has(item.value));\n return missing.length ? { ...narrowed, items: [...narrowed.items, ...missing] } : narrowed;\n};\n\nexport const filterRows = (\n filter: FilterSearchFilter | undefined,\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchRows =>\n filter ? rowsFor(toRows([filter], selections), query) : { toggle: null, items: [] };\n\n/** The values of every filter that match a query typed before any filter was picked. */\nexport const searchRows = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchRows => rowsFor(toRows(filters, selections), query);\n\n// As sets: a Select All that adds nothing returns the values in item order, not the order chosen.\nconst sameItems = (a: string[], b: string[]) => {\n const set = new Set(b);\n return a.length === set.size && a.every((value) => set.has(value));\n};\n\n/** Applies per-filter changes, keeping each filter where it already was and dropping the emptied. */\nconst applyChanges = (\n selections: FilterSearchSelection[],\n proposed: FilterSearchChange[],\n): FilterSearchUpdate => {\n const changes = proposed.filter(\n (change) => !sameItems(change.items, [...selectedValues(selections, change.filter)]),\n );\n const byFilter = new Map(changes.map((change) => [change.filter, change.items]));\n const kept = selections\n .map((selection) => ({\n filter: selection.filter,\n items: byFilter.get(selection.filter) ?? selection.items,\n }))\n .filter((selection) => selection.items.length > 0);\n const added = changes.filter(\n (change) =>\n change.items.length > 0 &&\n !selections.some((selection) => selection.filter === change.filter),\n );\n\n return { next: [...kept, ...added], changes };\n};\n\nexport const toggleValue = (\n selections: FilterSearchSelection[],\n filter: string,\n value: string,\n): FilterSearchUpdate => {\n const current = [...selectedValues(selections, filter)];\n const items = current.includes(value)\n ? current.filter((item) => item !== value)\n : [...current, value];\n\n return applyChanges(selections, [{ filter, items }]);\n};\n\n/** Select All keeps what is already chosen and adds every enabled value the query matches. */\nexport const selectAll = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchUpdate =>\n applyChanges(\n selections,\n filters.map((filter) => {\n const selected = selectedValues(selections, filter.value);\n const added = filter.items\n .filter(\n (item) =>\n !selected.has(item.value) && !item.disabled && matchesQuery(item, query),\n )\n .map((item) => item.value);\n // Chosen values stay even when `items` no longer lists them (a stale or lazy list).\n return { filter: filter.value, items: [...selected, ...added] };\n }),\n );\n\n/** Deselect All drops every enabled value the query matches and keeps the rest. */\nexport const deselectAll = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchUpdate =>\n applyChanges(\n selections,\n filters.map((filter) => {\n const selected = selectedValues(selections, filter.value);\n const dropped = new Set(\n filter.items\n .filter((item) => !item.disabled && matchesQuery(item, query))\n .map((item) => item.value),\n );\n return {\n filter: filter.value,\n items: [...selected].filter((value) => !dropped.has(value)),\n };\n }),\n );\n\nexport const removeFilter = (\n selections: FilterSearchSelection[],\n filter: string,\n): FilterSearchUpdate => applyChanges(selections, [{ filter, items: [] }]);\n\nexport const clearAll = (selections: FilterSearchSelection[]): FilterSearchUpdate =>\n applyChanges(\n selections,\n selections.map((selection) => ({ filter: selection.filter, items: [] })),\n );\n\n/** `Connector: Notion`, or `Connector: (Notion, Attio)` once there is more than one value. */\nexport const chipText = (filterLabel: string, itemLabels: string[]): string => {\n if (itemLabels.length === 0) return filterLabel;\n if (itemLabels.length === 1) return `${filterLabel}: ${itemLabels[0]}`;\n return `${filterLabel}: (${itemLabels.join(', ')})`;\n};\n\n/**\n * The order chips show filters in: when each was first added. A consumer reading its selection back\n * from the URL gets it in a fixed key order, which would reshuffle the chips on every change.\n */\nexport const orderSelections = (\n selections: FilterSearchSelection[],\n order: string[],\n /** A filter to hold its place in `order` while it has no values, e.g. the one being edited. */\n keep: string | null = null,\n): string[] => {\n const present = new Set(selections.map((selection) => selection.filter));\n const kept = order.filter((filter) => present.has(filter) || filter === keep);\n return [\n ...kept,\n ...selections.map((selection) => selection.filter).filter((f) => !kept.includes(f)),\n ];\n};\n"],"names":["resolveMode","activeFilter","query","matchesQuery","item","needle","selectedValues","selections","filter","_a","selection","toRows","filters","selected","toggleFor","all","matched","row","everyEnabledSelected","everyMatchSelected","rowsFor","openFilterOf","active","searchFilters","narrowed","wide","picked","listed","missing","filterRows","searchRows","sameItems","a","b","set","value","applyChanges","proposed","changes","change","byFilter","kept","added","toggleValue","current","items","selectAll","deselectAll","dropped","removeFilter","clearAll","chipText","filterLabel","itemLabels","orderSelections","order","keep","present","f"],"mappings":"AAgDO,MAAMA,IAAc,CAACC,GAA6BC,MACjDD,MAAiB,OAAa,UAC3BC,EAAM,KAAA,EAAO,SAAS,IAAI,WAAW,WAGnCC,IAAe,CAACC,GAAwBF,MAA2B;AAC5E,QAAMG,IAASH,EAAM,KAAA,EAAO,YAAA;AAC5B,SAAOE,EAAK,MAAM,YAAA,EAAc,SAASC,CAAM,KAAKD,EAAK,MAAM,cAAc,SAASC,CAAM;AAChG,GAEMC,IAAiB,CAACC,GAAqCC,MAAA;AAVtD,MAAAC;AAWH,aAAI,MAAIA,IAAAF,EAAW,KAAK,CAACG,MAAcA,EAAU,WAAWF,CAAM,MAA1D,gBAAAC,EAA6D,UAAS,CAAA,CAAE;AAAA,GAE9EE,IAAS,CACXC,GACAL,MAEAK,EAAQ,QAAQ,CAACJ,MAAW;AACxB,QAAMK,IAAWP,EAAeC,GAAYC,EAAO,KAAK;AACxD,SAAOA,EAAO,MAAM,IAAI,CAACJ,OAAU,EAAE,MAAAA,GAAM,QAAAI,GAAQ,UAAUK,E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,QAAAC,GAAQ,OAAO,CAAA,GAAI,CAAC,GAE5D0C,IAAW,CAAC3C,MACrB6B;AAAA,EACI7B;AAAA,EACAA,EAAW,IAAI,CAACG,OAAe,EAAE,QAAQA,EAAU,QAAQ,OAAO,CAAA,IAAK;AAC3E,GAGSyC,IAAW,CAACC,GAAqBC,MACtCA,EAAW,WAAW,IAAUD,IAChCC,EAAW,WAAW,IAAU,GAAGD,CAAW,KAAKC,EAAW,CAAC,CAAC,KAC7D,GAAGD,CAAW,MAAMC,EAAW,KAAK,IAAI,CAAC,KAOvCC,IAAkB,CAC3B/C,GACAgD,GAEAC,IAAsB,SACX;AACX,QAAMC,IAAU,IAAI,IAAIlD,EAAW,IAAI,CAACG,MAAcA,EAAU,MAAM,CAAC,GACjE+B,IAAOc,EAAM,OAAO,CAAC/C,MAAWiD,EAAQ,IAAIjD,CAAM,KAAKA,MAAWgD,CAAI;AAC5E,SAAO;AAAA,IACH,GAAGf;AAAA,IACH,GAAGlC,EAAW,IAAI,CAACG,MAAcA,EAAU,MAAM,EAAE,OAAO,CAACgD,MAAM,CAACjB,EAAK,SAASiB,CAAC,CAAC;AAAA,EAAA;AAE1F;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const r = "bg-[var(--malachite-table-background,#f7f7f7)] p-[4px] rounded-xl", o = 4, c = "var(--malachite-radius-xl, 12px)", e = 8, a = "1px solid var(--malachite-card-border, #e8e8e8)", t = {
|
|
2
|
+
background: "var(--malachite-table-row-background, #fff)",
|
|
3
|
+
border: a,
|
|
4
|
+
borderRadius: 8
|
|
5
|
+
};
|
|
6
|
+
export {
|
|
7
|
+
r as FRAME_CLASS,
|
|
8
|
+
o as FRAME_PADDING,
|
|
9
|
+
c as FRAME_RADIUS,
|
|
10
|
+
a as FRAME_SECTION_BORDER,
|
|
11
|
+
e as FRAME_SECTION_RADIUS,
|
|
12
|
+
t as FRAME_SECTION_STYLE
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=frameStyles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frameStyles.js","sources":["../../src/components/frameStyles.ts"],"sourcesContent":["import type React from 'react';\n\n/**\n * The grey frame the detached Table draws around its header and rows, shared with Card's\n * `framed` variant so a card and the table beside it read as one set in both themes.\n */\nexport const FRAME_CLASS = 'bg-[var(--malachite-table-background,#f7f7f7)] p-[4px] rounded-xl';\n/** The `p-[4px]` in `FRAME_CLASS`, for geometry that has to offset it. */\nexport const FRAME_PADDING = 4;\n/** The radius `rounded-xl` in `FRAME_CLASS` resolves to. Read from the same token, or overriding\n * `radius.xl` pinches the corners of anything drawn to match them. */\nexport const FRAME_RADIUS = 'var(--malachite-radius-xl, 12px)';\n\n/** The bordered section inside the frame is clipped to this radius. The detached Table's first\n * and last rows echo it, so a selected row's accent bar curves into the corner instead of\n * being cut off by the clip. */\nexport const FRAME_SECTION_RADIUS = 8;\nexport const FRAME_SECTION_BORDER = '1px solid var(--malachite-card-border, #e8e8e8)';\n\n/** The bordered section a framed Card's children sit in, as the detached Table's rows do. */\nexport const FRAME_SECTION_STYLE: React.CSSProperties = {\n background: 'var(--malachite-table-row-background, #fff)',\n border: FRAME_SECTION_BORDER,\n borderRadius: FRAME_SECTION_RADIUS,\n};\n"],"names":["FRAME_CLASS","FRAME_PADDING","FRAME_RADIUS","FRAME_SECTION_RADIUS","FRAME_SECTION_BORDER","FRAME_SECTION_STYLE"],"mappings":"AAMO,MAAMA,IAAc,qEAEdC,IAAgB,GAGhBC,IAAe,oCAKfC,IAAuB,GACvBC,IAAuB,mDAGvBC,IAA2C;AAAA,EACpD,YAAY;AAAA,EACZ,QAAQD;AAAA,EACR,cAAc;AAClB;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headerContent.js","sources":["../../src/components/headerContent.ts"],"sourcesContent":["import type React from 'react';\n\n/** Whether a header slot has something to draw: `0` does, `null`, `false` and `''` do not. */\nexport const isShown = (node: React.ReactNode): boolean =>\n node !== undefined && node !== null && node !== false && node !== '';\n\nexport const hasHeaderContent = ({\n title,\n subtitle,\n extra,\n}: {\n title?: React.ReactNode;\n subtitle?: React.ReactNode;\n extra?: React.ReactNode;\n}): boolean => isShown(title) || isShown(subtitle) || isShown(extra);\n"],"names":["isShown","node","hasHeaderContent","title","subtitle","extra"],"mappings":"AAGO,MAAMA,IAAU,CAACC,MACEA,KAAS,QAAQA,MAAS,MAASA,MAAS,IAEzDC,IAAmB,CAAC;AAAA,EAC7B,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,OAAAC;AACJ,MAIeL,EAAQG,CAAK,KAAKH,EAAQI,CAAQ,KAAKJ,EAAQK,CAAK;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useEffect as p } from "react";
|
|
2
|
+
import { rectSignature as F, isTriggerOffscreen as H } from "./floatingMenuGeometry.js";
|
|
3
|
+
import { useLatestRef as l } from "./useLatestRef.js";
|
|
4
|
+
const a = (e) => e.width === 0 && e.height === 0 && e.top === 0 && e.left === 0, h = (e) => `${F(e)}|${window.innerWidth}x${window.innerHeight}`, B = (e, t, g, m) => {
|
|
5
|
+
const o = l(g), i = l(m);
|
|
6
|
+
p(() => {
|
|
7
|
+
if (!e)
|
|
8
|
+
return;
|
|
9
|
+
let s = t.current ? h(t.current.getBoundingClientRect()) : "", c = 0, r = !1;
|
|
10
|
+
const u = () => {
|
|
11
|
+
r = !0, c = requestAnimationFrame(w), r = !1;
|
|
12
|
+
}, w = () => {
|
|
13
|
+
if (r)
|
|
14
|
+
return;
|
|
15
|
+
const f = t.current;
|
|
16
|
+
if (f) {
|
|
17
|
+
const n = f.getBoundingClientRect(), d = h(n);
|
|
18
|
+
d !== s && (s = d, (a(n) || H(n, window.innerWidth, window.innerHeight)) && i.current ? i.current() : a(n) || o.current(n));
|
|
19
|
+
}
|
|
20
|
+
u();
|
|
21
|
+
};
|
|
22
|
+
return u(), () => cancelAnimationFrame(c);
|
|
23
|
+
}, [e, t, o, i]);
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
B as useFollowTrigger
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=useFollowTrigger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFollowTrigger.js","sources":["../../src/components/useFollowTrigger.ts"],"sourcesContent":["import { type RefObject, useEffect } from 'react';\nimport { isTriggerOffscreen, rectSignature } from './floatingMenuGeometry';\nimport { useLatestRef } from './useLatestRef';\n\n// `display: none` reports an empty rect at the origin. A trigger that is merely empty (its\n// only children positioned out of flow) still sits somewhere, and is followed.\nconst isDetached = (rect: DOMRect) =>\n rect.width === 0 && rect.height === 0 && rect.top === 0 && rect.left === 0;\n\n// The viewport is part of it: a resize can leave a trigger offscreen without moving it.\nconst signatureOf = (rect: DOMRect) =>\n `${rectSignature(rect)}|${window.innerWidth}x${window.innerHeight}`;\n\n/**\n * `scroll` is not composed, so a window listener never hears a scroller inside a consumer's\n * shadow root: while `active`, the trigger's rect is polled once a frame instead.\n */\nexport const useFollowTrigger = (\n active: boolean,\n triggerRef: RefObject<Element | null>,\n onMove: (rect: DOMRect) => void,\n onHide?: () => void,\n): void => {\n const onMoveRef = useLatestRef(onMove);\n const onHideRef = useLatestRef(onHide);\n\n useEffect(() => {\n if (!active) {\n return;\n }\n // Measured now, not on the first frame: a move before that frame is still a move.\n let lastRect = triggerRef.current\n ? signatureOf(triggerRef.current.getBoundingClientRect())\n : '';\n let frame = 0;\n let scheduling = false;\n // A test double that runs the callback inside `requestAnimationFrame` itself would\n // recurse; such a frame stops the loop instead. A browser never calls back that way.\n const schedule = () => {\n scheduling = true;\n frame = requestAnimationFrame(follow);\n scheduling = false;\n };\n const follow = () => {\n if (scheduling) {\n return;\n }\n const trigger = triggerRef.current;\n if (trigger) {\n const rect = trigger.getBoundingClientRect();\n const signature = signatureOf(rect);\n if (signature !== lastRect) {\n lastRect = signature;\n const hidden =\n isDetached(rect) ||\n isTriggerOffscreen(rect, window.innerWidth, window.innerHeight);\n if (hidden && onHideRef.current) {\n onHideRef.current();\n } else if (!isDetached(rect)) {\n onMoveRef.current(rect);\n }\n }\n }\n schedule();\n };\n schedule();\n return () => cancelAnimationFrame(frame);\n }, [active, triggerRef, onMoveRef, onHideRef]);\n};\n"],"names":["isDetached","rect","signatureOf","rectSignature","useFollowTrigger","active","triggerRef","onMove","onHide","onMoveRef","useLatestRef","onHideRef","useEffect","lastRect","frame","scheduling","schedule","follow","trigger","signature","isTriggerOffscreen"],"mappings":";;;AAMA,MAAMA,IAAa,CAACC,MAChBA,EAAK,UAAU,KAAKA,EAAK,WAAW,KAAKA,EAAK,QAAQ,KAAKA,EAAK,SAAS,GAGvEC,IAAc,CAACD,MACjB,GAAGE,EAAcF,CAAI,CAAC,IAAI,OAAO,UAAU,IAAI,OAAO,WAAW,IAMxDG,IAAmB,CAC5BC,GACAC,GACAC,GACAC,MACO;AACP,QAAMC,IAAYC,EAAaH,CAAM,GAC/BI,IAAYD,EAAaF,CAAM;AAErC,EAAAI,EAAU,MAAM;AACZ,QAAI,CAACP;AACD;AAGJ,QAAIQ,IAAWP,EAAW,UACpBJ,EAAYI,EAAW,QAAQ,sBAAA,CAAuB,IACtD,IACFQ,IAAQ,GACRC,IAAa;AAGjB,UAAMC,IAAW,MAAM;AACnB,MAAAD,IAAa,IACbD,IAAQ,sBAAsBG,CAAM,GACpCF,IAAa;AAAA,IACjB,GACME,IAAS,MAAM;AACjB,UAAIF;AACA;AAEJ,YAAMG,IAAUZ,EAAW;AAC3B,UAAIY,GAAS;AACT,cAAMjB,IAAOiB,EAAQ,sBAAA,GACfC,IAAYjB,EAAYD,CAAI;AAClC,QAAIkB,MAAcN,MACdA,IAAWM,IAEPnB,EAAWC,CAAI,KACfmB,EAAmBnB,GAAM,OAAO,YAAY,OAAO,WAAW,MACpDU,EAAU,UACpBA,EAAU,QAAA,IACFX,EAAWC,CAAI,KACvBQ,EAAU,QAAQR,CAAI;AAAA,MAGlC;AACA,MAAAe,EAAA;AAAA,IACJ;AACA,WAAAA,EAAA,GACO,MAAM,qBAAqBF,CAAK;AAAA,EAC3C,GAAG,CAACT,GAAQC,GAAYG,GAAWE,CAAS,CAAC;AACjD;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare type AccessPillsSize = 'default' | 'dense';
|
|
|
32
32
|
/** `'mixed'` is partly on: some, not all, of the effect's actions are allowed. */
|
|
33
33
|
export declare type AccessPillState = boolean | 'mixed';
|
|
34
34
|
|
|
35
|
-
export declare const Accordion: default_2.
|
|
35
|
+
export declare const Accordion: default_2.ForwardRefExoticComponent<AccordionProps & default_2.RefAttributes<HTMLDivElement>>;
|
|
36
36
|
|
|
37
37
|
declare interface AccordionBaseProps {
|
|
38
38
|
className?: string;
|
|
@@ -66,11 +66,13 @@ declare interface AccordionBaseProps {
|
|
|
66
66
|
/** Offset (px) from the top of the scroll container when `stickyHeader` is set. */
|
|
67
67
|
stickyTopOffset?: number;
|
|
68
68
|
/**
|
|
69
|
-
* With `stickyHeader`, rounds the header into its card's top corners once it pins,
|
|
70
|
-
*
|
|
69
|
+
* With `stickyHeader`, rounds the header into its card's top corners once it pins,
|
|
70
|
+
* in a flat, default-tone `<Surface overflow="clip" shadow={false}>`. Set
|
|
71
71
|
* `--malachite-ctx-pinned-surround` on an ancestor when the card sits on another ground.
|
|
72
72
|
*/
|
|
73
73
|
pinnedCorners?: boolean;
|
|
74
|
+
/** Change it after mount to flash an outline around the section. */
|
|
75
|
+
flashKey?: default_2.Key;
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
/**
|
|
@@ -86,7 +88,7 @@ export declare type AccordionProps = AccordionBaseProps & AccordionToggleProps &
|
|
|
86
88
|
});
|
|
87
89
|
|
|
88
90
|
declare interface AccordionToggleProps {
|
|
89
|
-
/** `false` is a section that never closes; the toggle props are then ignored. */
|
|
91
|
+
/** `false` is a section that never closes; the toggle props except `animate` are then ignored. */
|
|
90
92
|
collapsible?: boolean;
|
|
91
93
|
/** `gutter` puts the arrow before `leading` as its own mouse toggle; the title stays the keyboard one. */
|
|
92
94
|
arrowPosition?: 'start' | 'end' | 'gutter';
|
|
@@ -531,7 +533,17 @@ export declare const Card: default_2.FC<CardProps>;
|
|
|
531
533
|
export declare const CardIcon: React.FC<IconProps_15>;
|
|
532
534
|
|
|
533
535
|
declare interface CardProps {
|
|
536
|
+
/**
|
|
537
|
+
* `framed` draws the detached Table's frame: the title row sits on a grey frame and the
|
|
538
|
+
* children in a bordered section inside it, so a card above a table reads as part of the
|
|
539
|
+
* same set. `dimmed`, `border`, `size`, `glassFooter` and `headerConfig` do not apply to it.
|
|
540
|
+
*/
|
|
541
|
+
variant?: CardVariant;
|
|
534
542
|
title?: string | default_2.ReactNode;
|
|
543
|
+
/** Dimmed text beside the title, such as a count or a unit. */
|
|
544
|
+
subtitle?: default_2.ReactNode;
|
|
545
|
+
/** Actions at the right of the title row. */
|
|
546
|
+
extra?: default_2.ReactNode;
|
|
535
547
|
padding?: string;
|
|
536
548
|
children?: default_2.ReactNode;
|
|
537
549
|
size?: 'default' | 'small';
|
|
@@ -607,6 +619,8 @@ export declare interface CardStripProps {
|
|
|
607
619
|
/** Palette for the strip's rule. Pass the tone of whatever card is selected. */
|
|
608
620
|
export declare type CardStripTone = 'profile' | 'library' | 'editing';
|
|
609
621
|
|
|
622
|
+
export declare type CardVariant = 'default' | 'framed';
|
|
623
|
+
|
|
610
624
|
export declare const CaretDoubleLeftIcon: React.FC<IconProps_16>;
|
|
611
625
|
|
|
612
626
|
export declare const CaretDoubleRightIcon: React.FC<IconProps_17>;
|
|
@@ -1907,6 +1921,12 @@ export declare interface FilterSearchItem {
|
|
|
1907
1921
|
|
|
1908
1922
|
export declare interface FilterSearchProps {
|
|
1909
1923
|
filters: FilterSearchFilter[];
|
|
1924
|
+
/**
|
|
1925
|
+
* What a query typed before a filter is picked searches, when it should differ from
|
|
1926
|
+
* `filters`: every value, say, while `filters` holds only those the applied filters leave.
|
|
1927
|
+
* Memoise it: a new array on each render rebuilds the chip labels over every value it holds.
|
|
1928
|
+
*/
|
|
1929
|
+
searchFilters?: FilterSearchFilter[];
|
|
1910
1930
|
/** Controlled: the bar always shows `value`, so a URL-backed selection needs no syncing. */
|
|
1911
1931
|
value: FilterSearchSelection[];
|
|
1912
1932
|
/** `changes` lists only the filters that moved; an empty `items` means that filter was removed. */
|
|
@@ -5208,7 +5228,7 @@ export declare interface SurfaceProps {
|
|
|
5208
5228
|
* Content overflow. Defaults to `hidden` so children are clipped to the rounded
|
|
5209
5229
|
* corners. Use `clip` to keep the rounded clipping WITHOUT creating a scroll
|
|
5210
5230
|
* container — so a `position: sticky` descendant still pins (unlike `hidden`,
|
|
5211
|
-
* which traps it). `visible` disables clipping entirely.
|
|
5231
|
+
* which traps it). `visible` disables clipping entirely. A flat, default-tone `clip` card clips at its border.
|
|
5212
5232
|
*/
|
|
5213
5233
|
overflow?: 'hidden' | 'visible' | 'clip';
|
|
5214
5234
|
/**
|
|
@@ -5295,7 +5315,7 @@ export declare interface SurfaceRowProps extends SurfaceRowChromeProps {
|
|
|
5295
5315
|
* which has no hover, always shows it.
|
|
5296
5316
|
*/
|
|
5297
5317
|
revealTrailing?: boolean;
|
|
5298
|
-
/** The row's indicator, before the children. */
|
|
5318
|
+
/** The row's indicator, before the children. With this or `dimmed`, pass one child. */
|
|
5299
5319
|
leading?: default_2.ReactNode;
|
|
5300
5320
|
/** Fades the children, not `leading` or `trailing`. */
|
|
5301
5321
|
dimmed?: boolean;
|
|
@@ -5332,7 +5352,7 @@ export declare interface TabItem {
|
|
|
5332
5352
|
disabled?: boolean;
|
|
5333
5353
|
}
|
|
5334
5354
|
|
|
5335
|
-
export declare const Table: <T = Record<string, unknown>>({ columns, data, loading, error, errorTitle, errorSubTitle, emptyTitle, emptySubTitle, bordered, showHeader, rowKey, scrollHeight, size, rowDensity, layout, headerVariant, rowClassName, rowVariant, onRow, onClickRow, selectedRowKey, scrollSelectedIntoView, rowSelection, pagination, className, style, stickyHeaderTop, scrollX, rowSection, renderSectionDivider, onVisibleOrderChange, virtual, virtualRowHeightEstimate, virtualScrollElement, }: TableProps<T>) => JSX_2.Element;
|
|
5355
|
+
export declare const Table: <T = Record<string, unknown>>({ columns, data, loading, error, errorTitle, errorSubTitle, emptyTitle, emptySubTitle, bordered, showHeader, rowKey, scrollHeight, size, rowDensity, layout, headerVariant, title, subtitle, extra, rowClassName, rowVariant, onRow, onClickRow, selectedRowKey, scrollSelectedIntoView, rowSelection, pagination, className, style, stickyHeaderTop, scrollX, rowSection, renderSectionDivider, onVisibleOrderChange, virtual, virtualRowHeightEstimate, virtualScrollElement, }: TableProps<T>) => JSX_2.Element;
|
|
5336
5356
|
|
|
5337
5357
|
export declare type TableColumnDefinition<T = Record<string, unknown>> = {
|
|
5338
5358
|
title: string | default_2.ReactNode;
|
|
@@ -5344,12 +5364,24 @@ export declare type TableColumnDefinition<T = Record<string, unknown>> = {
|
|
|
5344
5364
|
minWidth?: number;
|
|
5345
5365
|
ellipsis?: boolean;
|
|
5346
5366
|
render?: (value: unknown, record?: T, index?: number) => default_2.ReactNode;
|
|
5347
|
-
|
|
5367
|
+
/**
|
|
5368
|
+
* `true` sorts the rows by `dataIndex`, a function sorts them with it, and `'server'` leaves
|
|
5369
|
+
* them in the order given: the arrow still moves and `onHeaderCell` still runs, for a page
|
|
5370
|
+
* the server has already sorted.
|
|
5371
|
+
*/
|
|
5372
|
+
sorter?: boolean | 'server' | ((a: T, b: T) => number);
|
|
5348
5373
|
sortIcon?: (props: {
|
|
5349
5374
|
sortOrder: 'desc' | 'asc' | null;
|
|
5350
5375
|
}) => default_2.ReactNode;
|
|
5351
|
-
|
|
5376
|
+
/**
|
|
5377
|
+
* Its `onClick` runs when a sortable column's header is clicked, as the table moves its
|
|
5378
|
+
* arrow: the hook for a sort the server does, with `sorter: 'server'`. The arrow cycles
|
|
5379
|
+
* ascending, descending, none, and the handler runs on each click, the clearing one too.
|
|
5380
|
+
*/
|
|
5381
|
+
onHeaderCell?: (column: TableColumnDefinition<T>, index?: number) => TableHeaderCellHandlers;
|
|
5382
|
+
/** The arrow the column starts with, and for a `sorter` function the order it starts in. */
|
|
5352
5383
|
defaultSortOrder?: 'ascend' | 'descend';
|
|
5384
|
+
/** Not read: the header always cycles ascending, descending, none. */
|
|
5353
5385
|
sortDirections?: ('ascend' | 'descend')[];
|
|
5354
5386
|
fixed?: 'left' | 'right';
|
|
5355
5387
|
align?: 'left' | 'center' | 'right';
|
|
@@ -5357,6 +5389,11 @@ export declare type TableColumnDefinition<T = Record<string, unknown>> = {
|
|
|
5357
5389
|
|
|
5358
5390
|
export declare type TableColumns<T = Record<string, unknown>> = TableColumnDefinition<T>[];
|
|
5359
5391
|
|
|
5392
|
+
/** What the table reads from a column's `onHeaderCell`: `onClick`, run from the sort button. */
|
|
5393
|
+
export declare interface TableHeaderCellHandlers {
|
|
5394
|
+
onClick?: (event: default_2.MouseEvent<HTMLButtonElement>) => void;
|
|
5395
|
+
}
|
|
5396
|
+
|
|
5360
5397
|
declare type TableHeaderVariant = 'inline' | 'detached';
|
|
5361
5398
|
|
|
5362
5399
|
export declare type TablePaginationPosition = 'topLeft' | 'topCenter' | 'topRight' | 'bottomLeft' | 'bottomCenter' | 'bottomRight';
|
|
@@ -5382,6 +5419,15 @@ declare type TableProps<T = Record<string, unknown>> = {
|
|
|
5382
5419
|
rowDensity?: 'default' | 'compact';
|
|
5383
5420
|
layout?: 'fixed' | 'auto';
|
|
5384
5421
|
headerVariant?: TableHeaderVariant;
|
|
5422
|
+
/** A title row on the detached frame, above the column headers, as on Card's `framed`
|
|
5423
|
+
* variant. With `stickyHeaderTop` it docks with the column headers; with
|
|
5424
|
+
* `showHeader={false}` nothing docks and it scrolls with the rows. Detached only: the inline
|
|
5425
|
+
* header has no frame, and warns in development when given one. */
|
|
5426
|
+
title?: default_2.ReactNode;
|
|
5427
|
+
/** Dimmed text beside `title`, such as a count. */
|
|
5428
|
+
subtitle?: default_2.ReactNode;
|
|
5429
|
+
/** Actions at the right of the title row. */
|
|
5430
|
+
extra?: default_2.ReactNode;
|
|
5385
5431
|
rowClassName?: (record: T, index: number) => string;
|
|
5386
5432
|
rowVariant?: (record: T, index: number) => RowVariant | undefined;
|
|
5387
5433
|
onRow?: (record: T, index: number) => TableRowActions<T>;
|
|
@@ -5643,6 +5689,82 @@ export declare const ThumbsDownIcon: React.FC<IconProps_109>;
|
|
|
5643
5689
|
|
|
5644
5690
|
export declare const ThumbsUpIcon: React.FC<IconProps_110>;
|
|
5645
5691
|
|
|
5692
|
+
export declare const TimeBarChart: default_2.FC<TimeBarChartProps>;
|
|
5693
|
+
|
|
5694
|
+
export declare interface TimeBarChartBucket {
|
|
5695
|
+
/** The bucket's start. A string with no zone is read as UTC. */
|
|
5696
|
+
start: TimeInput;
|
|
5697
|
+
/** Each series' count in this bucket, by series key. A missing key counts as 0. */
|
|
5698
|
+
values: Record<string, number>;
|
|
5699
|
+
}
|
|
5700
|
+
|
|
5701
|
+
export declare interface TimeBarChartInterval {
|
|
5702
|
+
unit: TimeBarChartUnit;
|
|
5703
|
+
/** How many `unit`s one bucket spans, e.g. 3 with `hour` for 3-hour buckets. Default 1. */
|
|
5704
|
+
step?: number;
|
|
5705
|
+
}
|
|
5706
|
+
|
|
5707
|
+
export declare interface TimeBarChartProps {
|
|
5708
|
+
/** Stacked by tone, failures on top (`neutral`, `success`, `error`), and in the order given
|
|
5709
|
+
* within a tone. The legend, tooltip and table keep the order given. */
|
|
5710
|
+
series: TimeBarChartSeries[];
|
|
5711
|
+
/** Only the buckets that have values; empty buckets in `range` are laid out regardless. */
|
|
5712
|
+
buckets: TimeBarChartBucket[];
|
|
5713
|
+
interval: TimeBarChartInterval;
|
|
5714
|
+
/** The window the axis covers, `end` exclusive as `onRangeSelect` reports it, so a selection
|
|
5715
|
+
* fed back in shows exactly the buckets selected. Without it the axis spans the buckets
|
|
5716
|
+
* given. At most 2,000 buckets are laid out; past that the newest are kept, so a live window
|
|
5717
|
+
* still ends at now. */
|
|
5718
|
+
range?: {
|
|
5719
|
+
start: TimeInput;
|
|
5720
|
+
end: TimeInput;
|
|
5721
|
+
};
|
|
5722
|
+
/** The plot's height, axis labels included: 120, 160 or 240px. */
|
|
5723
|
+
size?: TimeBarChartSize;
|
|
5724
|
+
/** With buckets already drawn, they stay and dim while new ones load. */
|
|
5725
|
+
loading?: boolean;
|
|
5726
|
+
error?: boolean;
|
|
5727
|
+
errorTitle?: string;
|
|
5728
|
+
errorSubTitle?: string;
|
|
5729
|
+
/** What the stacked total counts, shown in the tooltip, e.g. "Requests". */
|
|
5730
|
+
valueLabel?: string;
|
|
5731
|
+
/** A legend naming each series. Leave it off only where the page labels the series itself. */
|
|
5732
|
+
legend?: boolean;
|
|
5733
|
+
/** A time whose bucket is shaded behind the bars, e.g. the row under the pointer in a list. */
|
|
5734
|
+
highlightTime?: TimeInput;
|
|
5735
|
+
/** Turns on click-and-drag selection of whole buckets. */
|
|
5736
|
+
onRangeSelect?: (selection: TimeBarChartRangeSelection) => void;
|
|
5737
|
+
/** Names the chart. Pass this or `aria-labelledby`; the hidden table takes it as its caption. */
|
|
5738
|
+
'aria-label'?: string;
|
|
5739
|
+
/** Names the chart from a visible heading instead, and the hidden table with it. */
|
|
5740
|
+
'aria-labelledby'?: string;
|
|
5741
|
+
className?: string;
|
|
5742
|
+
style?: default_2.CSSProperties;
|
|
5743
|
+
}
|
|
5744
|
+
|
|
5745
|
+
export declare interface TimeBarChartRangeSelection {
|
|
5746
|
+
/** UTC ISO start of the first selected bucket. */
|
|
5747
|
+
start: string;
|
|
5748
|
+
/** UTC ISO end of the last selected bucket, exclusive: the start of the bucket after it. */
|
|
5749
|
+
end: string;
|
|
5750
|
+
/** Whether the selection takes in the last bucket, i.e. "up to now" on a live window. */
|
|
5751
|
+
reachesEnd: boolean;
|
|
5752
|
+
}
|
|
5753
|
+
|
|
5754
|
+
export declare interface TimeBarChartSeries {
|
|
5755
|
+
key: string;
|
|
5756
|
+
label: string;
|
|
5757
|
+
tone: TimeBarChartTone;
|
|
5758
|
+
}
|
|
5759
|
+
|
|
5760
|
+
export declare type TimeBarChartSize = 'small' | 'medium' | 'large';
|
|
5761
|
+
|
|
5762
|
+
export declare type TimeBarChartTone = 'success' | 'error' | 'neutral';
|
|
5763
|
+
|
|
5764
|
+
export declare type TimeBarChartUnit = 'minute' | 'hour' | 'day' | 'week' | 'month';
|
|
5765
|
+
|
|
5766
|
+
declare type TimeInput = string | number | Date;
|
|
5767
|
+
|
|
5646
5768
|
export declare interface ToastApi {
|
|
5647
5769
|
show: (options: ToastOptions) => void;
|
|
5648
5770
|
}
|