@bagelink/vue 1.21.3 → 1.21.7

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/vue",
3
3
  "type": "module",
4
- "version": "1.21.3",
4
+ "version": "1.21.7",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
@@ -63,7 +63,7 @@
63
63
  "@types/signature_pad": "^4.0.0",
64
64
  "vue": "^3.5.43",
65
65
  "vue-component-type-helpers": "^2.2.12",
66
- "@bagelink/sdk": "1.21.3"
66
+ "@bagelink/sdk": "1.21.7"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "@bagelink/sdk": "*",
@@ -49,6 +49,12 @@ const emit = defineEmits<{
49
49
  const { t } = useI18n()
50
50
 
51
51
  const currentDate = ref(new Date(props.startDate))
52
+ /**
53
+ * Month shown in the agenda title. This follows the day at the top of the
54
+ * scroll, and is kept separate from `currentDate` so scrolling does not move
55
+ * the loaded range or snap the list.
56
+ */
57
+ const agendaDate = ref<Date | null>(props.focusDate ? new Date(props.focusDate) : null)
52
58
  const currentView = ref(props.view)
53
59
  const activeEvent = ref<CalendarEvent>()
54
60
  const showPopover = ref(false)
@@ -96,6 +102,10 @@ const visibleDateRange = computed(() => {
96
102
  return { start, end }
97
103
  })
98
104
 
105
+ const headerDate = computed(() =>
106
+ currentView.value === 'Agenda' && agendaDate.value ? agendaDate.value : currentDate.value,
107
+ )
108
+
99
109
  const state = computed<CalendarViewState>(() => ({
100
110
  visibleDateRange: visibleDateRange.value,
101
111
  currentDate: currentDate.value,
@@ -117,13 +127,32 @@ function handleDateChange(date: Date) {
117
127
  watch(() => props.startDate?.getTime(), (next, prev) => {
118
128
  if (!next || next === prev) { return }
119
129
  currentDate.value = new Date(next)
130
+ agendaDate.value = new Date(next)
120
131
  emit('dateChange', state.value)
121
132
  })
122
133
 
123
- // Agenda view emits dateChange on scroll for header display,
124
- // but we must NOT feed it back into currentDate or it causes a scroll loop.
134
+ watch(() => props.focusDate?.getTime(), (next, prev) => {
135
+ if (!next || next === prev) { return }
136
+ agendaDate.value = new Date(next)
137
+ })
138
+
139
+ /**
140
+ * Agenda scroll reports the day nearest the top so the title can follow it.
141
+ * That day must not be written back into `currentDate`: the agenda receives
142
+ * `currentDate` as its start, and updating it restamps the range and snaps
143
+ * the list.
144
+ */
125
145
  function handleAgendaDateChange(date: Date) {
126
- emit('dateChange', { visibleDateRange: visibleDateRange.value, currentDate: date, currentView: currentView.value })
146
+ const next = new Date(date)
147
+ const shown = agendaDate.value
148
+ if (
149
+ shown
150
+ && shown.getFullYear() === next.getFullYear()
151
+ && shown.getMonth() === next.getMonth()
152
+ && shown.getDate() === next.getDate()
153
+ ) { return }
154
+ agendaDate.value = next
155
+ emit('dateChange', { visibleDateRange: visibleDateRange.value, currentDate: next, currentView: currentView.value })
127
156
  }
128
157
 
129
158
  function handleViewChange(view: CalendarView) {
@@ -175,11 +204,11 @@ onMounted(() => {
175
204
  </script>
176
205
 
177
206
  <template>
178
- <div class="calendar_month">
207
+ <div class="calendar_month h-100p min-h-0 overflow-hidden grid grid-rows-auto-1fr">
179
208
  <div class="flex m_block p-1">
180
209
  <h3 class="txt-light my-0 m_pb-05">
181
- <b>{{ formatDate(currentDate, 'MMMM') }}</b>
182
- {{ formatDate(currentDate, 'YYYY') }}
210
+ <b>{{ formatDate(headerDate, 'MMMM') }}</b>
211
+ {{ formatDate(headerDate, 'YYYY') }}
183
212
  </h3>
184
213
  <div class="ms-auto flex gap-025 m_flex-wrap m_me-auto m_w-100p" >
185
214
  <TabsNav size="sm" v-if="viewSwitcher === 'tabs'" :model-value="currentView" :tabs="viewTabs" group="calendar-view" @update:model-value="handleViewChange($event as CalendarView)"
@@ -203,6 +232,7 @@ onMounted(() => {
203
232
  </div>
204
233
  </div>
205
234
  <component
235
+ class="min-h-0 h-100p overflow-hidden"
206
236
  :is="views[currentView]" :events="events" :start-date="currentDate" :week-start="weekStart"
207
237
  :availability-mode="props.availabilityMode" :availability-editable="props.availabilityEditable" :availability-slots="props.availabilitySlots"
208
238
  :focus-date="props.focusDate"
@@ -227,14 +257,3 @@ onMounted(() => {
227
257
  </CalendarPopover>
228
258
  </div>
229
259
  </template>
230
-
231
- <style scoped>
232
-
233
- .calendar {
234
- display: flex;
235
- flex-direction: column;
236
- height: 100%;
237
- width: 100%;
238
- }
239
-
240
- </style>
@@ -0,0 +1,53 @@
1
+ /** Scroll offset that counts as "pinned to the earliest loaded day". */
2
+ export const HISTORY_EDGE_PX = 48
3
+
4
+ export interface HistoryLoadGate {
5
+ /** A history request is in flight. Further edge hits must not emit. */
6
+ loading: boolean
7
+ /**
8
+ * The edge was left since the last request. Staying pinned to the top,
9
+ * including repeated bounces while a load is stuck there, stays disarmed.
10
+ */
11
+ armed: boolean
12
+ /** Earliest day already requested. The same day is not requested again. */
13
+ requestedKey: string | null
14
+ }
15
+
16
+ export function createHistoryLoadGate(): HistoryLoadGate {
17
+ return { loading: false, armed: true, requestedKey: null }
18
+ }
19
+
20
+ /**
21
+ * Decide whether a scroll position should ask for older history.
22
+ *
23
+ * One request per visit to the top. Repeating the gesture while the request
24
+ * is in flight, or while the scroller is still sitting on that same edge,
25
+ * does not emit again. A new request requires the user to leave the edge
26
+ * and come back, and only for an earliest day that has not been asked for.
27
+ */
28
+ export function nextHistoryLoad(
29
+ gate: HistoryLoadGate,
30
+ input: { scrollTop: number; firstKey: string; now: number; ignoreUntil: number },
31
+ ): { gate: HistoryLoadGate; emit: boolean } {
32
+ const atTop = input.scrollTop <= HISTORY_EDGE_PX
33
+ const armed = gate.loading || atTop ? gate.armed : true
34
+ const next: HistoryLoadGate = { ...gate, armed }
35
+ if (
36
+ !atTop
37
+ || input.now <= input.ignoreUntil
38
+ || next.loading
39
+ || !next.armed
40
+ || next.requestedKey === input.firstKey
41
+ ) {
42
+ return { gate: next, emit: false }
43
+ }
44
+ return {
45
+ emit: true,
46
+ gate: { loading: true, armed: false, requestedKey: input.firstKey },
47
+ }
48
+ }
49
+
50
+ /** The in-flight request finished. The edge stays disarmed until the user leaves it. */
51
+ export function settleHistoryLoad(gate: HistoryLoadGate): HistoryLoadGate {
52
+ return { ...gate, loading: false, armed: false }
53
+ }
@@ -1,6 +1,8 @@
1
1
  <script setup lang="ts">
2
2
  import type { SetupContext } from 'vue'
3
3
  import type { CalendarEvent } from '../CalendarTypes'
4
+ import type { HistoryLoadGate } from '../previousHistory'
5
+ import { createHistoryLoadGate, nextHistoryLoad, settleHistoryLoad } from '../previousHistory'
4
6
  import { formatDate, getI18n, useI18n, Icon, Card } from '../../../index'
5
7
  import { ref, computed, watch, watchEffect, nextTick, onMounted, onUnmounted, useSlots } from 'vue'
6
8
 
@@ -93,12 +95,8 @@ const loadingPrevious = ref(false)
93
95
  let previousScrollHeight = 0
94
96
  let previousScrollTop = 0
95
97
  let loadPreviousTimer: ReturnType<typeof setTimeout> | undefined
96
- /**
97
- * Day key that was earliest when we last asked the parent for more history.
98
- * Re-requesting only when this key changes is what stops a single upward
99
- * scroll gesture from firing dozens of identical range requests.
100
- */
101
- let lastRequestedFirstKey: string | null = null
98
+ /** One history request per visit to the top. See `previousHistory.ts`. */
99
+ let historyGate: HistoryLoadGate = createHistoryLoadGate()
102
100
  let dateChangeFrame: number | undefined
103
101
  /**
104
102
  * Ignore "reached the top" detections briefly after a programmatic scroll.
@@ -123,21 +121,24 @@ function handleScroll() {
123
121
  const container = containerRef.value
124
122
  if (!container || !dayGroups.value.length) { return }
125
123
 
126
- // Request older history at most once per distinct earliest-day.
127
- if (container.scrollTop <= 48 && Date.now() > ignoreLoadPreviousUntil) {
128
- const firstKey = dayGroups.value[0].dateKey
129
- if (!loadingPrevious.value && lastRequestedFirstKey !== firstKey) {
130
- lastRequestedFirstKey = firstKey
131
- loadingPrevious.value = true
132
- previousScrollHeight = container.scrollHeight
133
- previousScrollTop = container.scrollTop
134
- emit('loadPrevious', dayGroups.value[0].date)
135
- // Safety valve: if the parent can't supply anything older, release the
136
- // guard so a later gesture is still possible. `lastRequestedFirstKey`
137
- // keeps the identical query from repeating until the first day moves.
138
- clearTimeout(loadPreviousTimer)
139
- loadPreviousTimer = setTimeout(() => { loadingPrevious.value = false }, 4000)
140
- }
124
+ // One request per visit to the top. Extra hits while that request is in
125
+ // flight, or while the scroller is still pinned to the same edge, are ignored.
126
+ const decision = nextHistoryLoad(historyGate, {
127
+ scrollTop: container.scrollTop,
128
+ firstKey: dayGroups.value[0].dateKey,
129
+ now: Date.now(),
130
+ ignoreUntil: ignoreLoadPreviousUntil,
131
+ })
132
+ historyGate = decision.gate
133
+ if (decision.emit) {
134
+ loadingPrevious.value = true
135
+ previousScrollHeight = container.scrollHeight
136
+ previousScrollTop = container.scrollTop
137
+ emit('loadPrevious', dayGroups.value[0].date)
138
+ // If the parent has nothing older, the event list never changes and the
139
+ // bar would otherwise stay up. The same day is not requested again.
140
+ clearTimeout(loadPreviousTimer)
141
+ loadPreviousTimer = setTimeout(finishHistoryLoad, 8000)
141
142
  }
142
143
 
143
144
  // Nearest-day reporting is coalesced to one emit per animation frame.
@@ -147,14 +148,21 @@ function handleScroll() {
147
148
  const el = containerRef.value
148
149
  if (!el) { return }
149
150
  const containerTop = el.getBoundingClientRect().top
151
+ let pinned: HTMLElement | null = null
150
152
  let closest: HTMLElement | null = null
151
153
  let minDist = Infinity
152
- el.querySelectorAll<HTMLElement>('.agenda-day-group').forEach((dayEl) => {
153
- const dist = Math.abs(dayEl.getBoundingClientRect().top - containerTop)
154
+ // A plain loop, not forEach: assignments inside a callback are invisible
155
+ // to control-flow analysis, which then types the chosen element as never.
156
+ for (const dayEl of el.querySelectorAll<HTMLElement>('.agenda-day-group')) {
157
+ const rect = dayEl.getBoundingClientRect()
158
+ const dist = Math.abs(rect.top - containerTop)
154
159
  if (dist < minDist) { minDist = dist; closest = dayEl }
155
- })
156
- if (closest) {
157
- const dateStr = (closest as HTMLElement).dataset.date
160
+ // The day that occupies the top edge is the one the title should name.
161
+ if (rect.top <= containerTop + 1 && rect.bottom > containerTop + 1) pinned = dayEl
162
+ }
163
+ const chosen = pinned ?? closest
164
+ if (chosen) {
165
+ const dateStr = chosen.dataset.date
158
166
  if (dateStr) { emit('dateChange', new Date(dateStr)) }
159
167
  }
160
168
  })
@@ -163,22 +171,26 @@ function handleScroll() {
163
171
  /**
164
172
  * Restore the reading position after older days are prepended.
165
173
  *
166
- * Watches the rendered group count rather than `events.length`: history can
167
- * arrive with the same number of events (or none at all), and the old
168
- * length-based check silently skipped the adjustment, which is what made
169
- * scrolling back feel like it jumped to an arbitrary place.
174
+ * Watches the events themselves: history can arrive without changing the
175
+ * number of days, and a length-only check then skipped the adjustment, which
176
+ * is what made scrolling back feel like it jumped to an arbitrary place.
170
177
  */
171
- watch(() => dayGroups.value.length, (count, oldCount) => {
178
+ function finishHistoryLoad() {
179
+ clearTimeout(loadPreviousTimer)
180
+ historyGate = settleHistoryLoad(historyGate)
181
+ loadingPrevious.value = false
182
+ }
183
+
184
+ watch(() => [props.events.length, dayGroups.value[0]?.dateKey] as const, () => {
172
185
  if (!loadingPrevious.value || !containerRef.value) { return }
173
186
  nextTick(() => {
174
187
  const container = containerRef.value
175
- if (!container) { return }
176
- const grew = count > (oldCount ?? 0)
188
+ if (!container || !loadingPrevious.value) { return }
189
+ const grew = container.scrollHeight > previousScrollHeight
177
190
  if (grew) {
178
191
  container.scrollTop = previousScrollTop + (container.scrollHeight - previousScrollHeight)
179
192
  }
180
- loadingPrevious.value = false
181
- clearTimeout(loadPreviousTimer)
193
+ finishHistoryLoad()
182
194
  })
183
195
  })
184
196
 
@@ -358,6 +370,14 @@ onUnmounted(() => {
358
370
  </script>
359
371
 
360
372
  <template>
373
+ <div class="relative h-100p">
374
+ <div
375
+ class="agenda-history-loading"
376
+ :class="{ 'is-active': loadingPrevious }"
377
+ role="progressbar"
378
+ :aria-hidden="!loadingPrevious"
379
+ :aria-label="t('calendar.agenda.loadingEarlier')"
380
+ />
361
381
  <div ref="containerRef" class="display-flex column h-100p overflow gap-0">
362
382
  <template v-if="dayGroups.length === 0">
363
383
  <div class="flex h-100p justify-content-center column gap-1 opacity-3">
@@ -396,10 +416,42 @@ onUnmounted(() => {
396
416
  </article>
397
417
  </section>
398
418
  </div>
419
+ </div>
399
420
  </template>
400
421
 
401
422
  <style scoped>
402
423
 
424
+ /* Overlay only. Kept mounted so showing it never changes the list height. */
425
+ .agenda-history-loading {
426
+ position: absolute;
427
+ z-index: 3;
428
+ top: 0;
429
+ inset-inline: 0;
430
+ height: 2px;
431
+ pointer-events: none;
432
+ opacity: 0;
433
+ overflow: hidden;
434
+ background: color-mix(in srgb, var(--bgl-primary, #2563eb) 18%, transparent);
435
+ }
436
+
437
+ .agenda-history-loading.is-active {
438
+ opacity: 1;
439
+ }
440
+
441
+ .agenda-history-loading::after {
442
+ content: '';
443
+ position: absolute;
444
+ inset-block: 0;
445
+ width: 35%;
446
+ background: var(--bgl-primary, #2563eb);
447
+ animation: agenda-history-loading 1.1s ease-in-out infinite;
448
+ }
449
+
450
+ @keyframes agenda-history-loading {
451
+ from { transform: translateX(-120%); }
452
+ to { transform: translateX(320%); }
453
+ }
454
+
403
455
  .agenda-event-row {
404
456
  grid-template-columns: 72px 1fr;
405
457
  align-items: stretch;
@@ -178,12 +178,26 @@ function onUpdate(value: T, i: number) {
178
178
  updateModel()
179
179
  }
180
180
 
181
+ function isNestedFormFlow(vnode: VNode): boolean {
182
+ const type = vnode.type as { name?: string, __name?: string, __file?: string } | string | symbol
183
+ if (!type || typeof type === 'string' || typeof type === 'symbol') return false
184
+ return type.__name === 'FormFlow'
185
+ || type.name === 'FormFlow'
186
+ || Boolean(type.__file?.includes('FormFlow.vue'))
187
+ }
188
+
181
189
  const isSimple = computed(() => {
182
- if (props.simple) return true
190
+ // Explicit opt-in/out wins. Nested multi-field schemas must be able to force
191
+ // `simple: false` so field labels inside each row stay visible.
192
+ if (props.simple != null) return !!props.simple
183
193
  if (!slots.default) return false
184
194
  const dummyItem = computed({ get: () => undefined as T, set: () => { } })
185
195
  const vnodes = slots.default({ item: dummyItem, index: 0 }) as VNode[]
186
- return vnodes.filter(vn => typeof vn.type !== 'symbol').length === 1
196
+ const content = vnodes.filter(vn => typeof vn.type !== 'symbol')
197
+ // A single nested FormFlow is one vnode but contains many labeled fields —
198
+ // never treat that as "simple" (which hides `.label-text`).
199
+ if (content.length === 1 && isNestedFormFlow(content[0]!)) return false
200
+ return content.length === 1
187
201
  })
188
202
 
189
203
  // Create a writable computed ref for each item
@@ -651,7 +651,8 @@ defineExpose({
651
651
  >
652
652
  <!-- Array field with nested schema -->
653
653
  <template v-if="field._type === 'array' && field._config.schema?._isSchema">
654
- <ArrayInput v-bind="getFieldProps(field, key)" :create-item="() => createArrayItem(field)">
654
+ <!-- Force simple=false: nested FormFlow is one vnode but needs field labels. -->
655
+ <ArrayInput v-bind="getFieldProps(field, key)" :simple="false" :create-item="() => createArrayItem(field)">
655
656
  <template #default="{ item }">
656
657
  <!-- @vue-ignore -->
657
658
  <FormFlow
@@ -504,7 +504,8 @@
504
504
  "time": "Time",
505
505
  "event": "Event",
506
506
  "eventsCount": "{n} event | {n} events",
507
- "noEvents": "No events"
507
+ "noEvents": "No events",
508
+ "loadingEarlier": "Loading earlier events"
508
509
  }
509
510
  },
510
511
  "addToCalendar": {
@@ -288,7 +288,8 @@
288
288
  "time": "Hora",
289
289
  "event": "Evento",
290
290
  "eventsCount": "{n} evento | {n} eventos",
291
- "noEvents": "Sin eventos"
291
+ "noEvents": "Sin eventos",
292
+ "loadingEarlier": "Cargando eventos anteriores"
292
293
  }
293
294
  },
294
295
  "addToCalendar": {
@@ -288,7 +288,8 @@
288
288
  "time": "Heure",
289
289
  "event": "Événement",
290
290
  "eventsCount": "{n} événement | {n} événements",
291
- "noEvents": "Aucun événement"
291
+ "noEvents": "Aucun événement",
292
+ "loadingEarlier": "Chargement des événements précédents"
292
293
  }
293
294
  },
294
295
  "addToCalendar": {
@@ -525,7 +525,8 @@
525
525
  "time": "שעה",
526
526
  "event": "אירוע",
527
527
  "eventsCount": "אירוע אחד | {n} אירועים",
528
- "noEvents": "אין אירועים"
528
+ "noEvents": "אין אירועים",
529
+ "loadingEarlier": "טוען אירועים קודמים"
529
530
  }
530
531
  },
531
532
  "addToCalendar": {
@@ -288,7 +288,8 @@
288
288
  "time": "Ora",
289
289
  "event": "Evento",
290
290
  "eventsCount": "{n} evento | {n} eventi",
291
- "noEvents": "Nessun evento"
291
+ "noEvents": "Nessun evento",
292
+ "loadingEarlier": "Caricamento eventi precedenti"
292
293
  }
293
294
  },
294
295
  "addToCalendar": {
@@ -288,7 +288,8 @@
288
288
  "time": "Время",
289
289
  "event": "Событие",
290
290
  "eventsCount": "{n} событие | {n} события | {n} событий",
291
- "noEvents": "Нет событий"
291
+ "noEvents": "Нет событий",
292
+ "loadingEarlier": "Загрузка более ранних событий"
292
293
  }
293
294
  },
294
295
  "addToCalendar": {