@abraca/nuxt 2.84.0 → 2.86.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.0.0"
6
6
  },
7
- "version": "2.84.0",
7
+ "version": "2.86.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -2,7 +2,7 @@
2
2
  import { computed, ref, useAttrs, watch } from "vue";
3
3
  import { useAAField } from "../../composables/useAAField";
4
4
  import { useAAUIState } from "../../composables/useAAUIState";
5
- import { useAAFollowPeer } from "../../composables/useAAFollowPeer";
5
+ import { useAAFollowShare } from "../../composables/useAAFollowShare";
6
6
  import AHoverItem from "./AHoverItem.vue";
7
7
  function itemId(item) {
8
8
  if (item == null) return "";
@@ -22,9 +22,13 @@ const props = defineProps({
22
22
  followOnly: { type: Boolean, required: false, default: false },
23
23
  total: { type: Boolean, required: false, default: false }
24
24
  });
25
- const { isFollowing } = useAAFollowPeer();
26
25
  const enableAwareness = computed(() => props.awareness || props.total);
27
- const enableLive = computed(() => props.live || props.total || props.followOnly && isFollowing.value);
26
+ const enableLive = computed(() => props.live || props.total);
27
+ const follow = useAAFollowShare(
28
+ () => `${props.fieldKey}:expanded`,
29
+ { enabled: () => props.followOnly }
30
+ );
31
+ const controlled = computed(() => enableLive.value || props.followOnly);
28
32
  const attrs = useAttrs();
29
33
  const { hoverers, focusers, hoverHandlers } = useAAField(() => props.fieldKey);
30
34
  const liveExpanded = useAAUIState(() => `${props.fieldKey}:expanded`, { defaultValue: "" });
@@ -37,8 +41,10 @@ watch(liveExpanded, (val) => {
37
41
  if (JSON.stringify(local.value) !== JSON.stringify(val)) local.value = val ?? "";
38
42
  });
39
43
  watch(local, (val) => {
40
- if (!enableLive.value) return;
41
- if (JSON.stringify(liveExpanded.value) !== JSON.stringify(val)) liveExpanded.value = val;
44
+ if (enableLive.value && JSON.stringify(liveExpanded.value) !== JSON.stringify(val)) {
45
+ liveExpanded.value = val;
46
+ }
47
+ follow.publish(val ?? "");
42
48
  });
43
49
  watch(enableLive, (now, prev) => {
44
50
  if (!now || prev) return;
@@ -47,6 +53,10 @@ watch(enableLive, (now, prev) => {
47
53
  local.value = incoming;
48
54
  }
49
55
  });
56
+ watch(() => follow.leaderValue.value, (val) => {
57
+ if (!follow.adopting.value || val === void 0) return;
58
+ if (JSON.stringify(local.value) !== JSON.stringify(val)) local.value = val;
59
+ }, { deep: true });
50
60
  const ringStyle = computed(() => {
51
61
  if (!enableAwareness.value) return void 0;
52
62
  const focusColor = focusers.value[0]?.user?.color;
@@ -71,7 +81,7 @@ const eventHandlers = computed(() => enableAwareness.value ? hoverHandlers : {})
71
81
  v-on="eventHandlers"
72
82
  >
73
83
  <UAccordion
74
- v-if="enableLive && !hasExternalModel"
84
+ v-if="controlled && !hasExternalModel"
75
85
  v-model="local"
76
86
  v-bind="attrs"
77
87
  >
@@ -1,7 +1,7 @@
1
1
  <script setup>
2
2
  import { computed, ref, useAttrs, watch } from "vue";
3
3
  import { useAAUIState } from "../../composables/useAAUIState";
4
- import { useAAFollowPeer } from "../../composables/useAAFollowPeer";
4
+ import { useAAFollowShare } from "../../composables/useAAFollowShare";
5
5
  defineOptions({ inheritAttrs: false });
6
6
  const props = defineProps({
7
7
  fieldKey: { type: String, required: true },
@@ -10,8 +10,12 @@ const props = defineProps({
10
10
  followOnly: { type: Boolean, required: false, default: false },
11
11
  total: { type: Boolean, required: false, default: false }
12
12
  });
13
- const { isFollowing } = useAAFollowPeer();
14
- const enableLive = computed(() => props.live || props.total || props.followOnly && isFollowing.value);
13
+ const enableLive = computed(() => props.live || props.total);
14
+ const follow = useAAFollowShare(
15
+ () => `${props.fieldKey}:open`,
16
+ { enabled: () => props.followOnly }
17
+ );
18
+ const controlled = computed(() => enableLive.value || props.followOnly);
15
19
  const attrs = useAttrs();
16
20
  const liveOpen = useAAUIState(() => `${props.fieldKey}:open`, { defaultValue: false });
17
21
  const hasExternalOpen = computed(() => "open" in attrs || "onUpdate:open" in attrs);
@@ -22,19 +26,23 @@ watch(liveOpen, (val) => {
22
26
  if (local.value !== next) local.value = next;
23
27
  });
24
28
  watch(local, (val) => {
25
- if (!enableLive.value) return;
26
- if (!!liveOpen.value !== val) liveOpen.value = val;
29
+ if (enableLive.value && !!liveOpen.value !== val) liveOpen.value = val;
30
+ follow.publish(val);
27
31
  });
28
32
  watch(enableLive, (now, prev) => {
29
33
  if (!now || prev) return;
30
34
  const incoming = !!liveOpen.value;
31
35
  if (local.value !== incoming) local.value = incoming;
32
36
  });
37
+ watch(() => follow.leaderValue.value, (val) => {
38
+ if (!follow.adopting.value || val === void 0) return;
39
+ if (local.value !== !!val) local.value = !!val;
40
+ });
33
41
  </script>
34
42
 
35
43
  <template>
36
44
  <UCollapsible
37
- v-if="enableLive && !hasExternalOpen"
45
+ v-if="controlled && !hasExternalOpen"
38
46
  v-model:open="local"
39
47
  v-bind="attrs"
40
48
  >
@@ -1,5 +1,5 @@
1
1
  <script setup>
2
- import { computed, watch } from "vue";
2
+ import { computed, ref, watch } from "vue";
3
3
  import { useRoute, useRouter } from "#imports";
4
4
  import { useAAFollowPeer } from "../../composables/useAAFollowPeer";
5
5
  import { useAwareness } from "../../composables/useAwareness";
@@ -12,7 +12,11 @@ const route = useRoute();
12
12
  const router = useRouter();
13
13
  const { setField, states } = useAwareness();
14
14
  const { peers } = useAwarenessPeers();
15
- const { follow, unfollow, followingClientId, followingUser } = useAAFollowPeer({ keyPrefix: props.keyPrefix });
15
+ const barEl = ref(null);
16
+ const { follow, unfollow, followingClientId, followingUser } = useAAFollowPeer({
17
+ keyPrefix: props.keyPrefix,
18
+ ignoreWithin: () => [barEl.value]
19
+ });
16
20
  watch(() => route.fullPath, (path) => {
17
21
  setField("route", path);
18
22
  }, { immediate: true });
@@ -38,7 +42,7 @@ const positionClass = computed(() => `aa-follow-bar--${props.position}`);
38
42
  </script>
39
43
 
40
44
  <template>
41
- <div v-if="visiblePeers.length" class="aa-follow-bar" :class="positionClass">
45
+ <div v-if="visiblePeers.length" ref="barEl" class="aa-follow-bar" :class="positionClass">
42
46
  <span class="aa-follow-bar__label">{{ followingUser ? `Following ${followingUser.name}` : "Follow" }}</span>
43
47
  <button
44
48
  v-for="p in visiblePeers"
@@ -1,7 +1,7 @@
1
1
  <script setup>
2
2
  import { computed, ref, useAttrs, watch } from "vue";
3
3
  import { useAAUIState, useAAUIStateAuthor } from "../../composables/useAAUIState";
4
- import { useAAFollowPeer } from "../../composables/useAAFollowPeer";
4
+ import { useAAFollowShare } from "../../composables/useAAFollowShare";
5
5
  import { useAwareness } from "../../composables/useAwareness";
6
6
  defineOptions({ inheritAttrs: false });
7
7
  const props = defineProps({
@@ -11,8 +11,12 @@ const props = defineProps({
11
11
  followOnly: { type: Boolean, required: false, default: false },
12
12
  total: { type: Boolean, required: false, default: false }
13
13
  });
14
- const { isFollowing } = useAAFollowPeer();
15
- const enableLive = computed(() => props.live || props.total || props.followOnly && isFollowing.value);
14
+ const enableLive = computed(() => props.live || props.total);
15
+ const follow = useAAFollowShare(
16
+ () => `${props.fieldKey}:open`,
17
+ { enabled: () => props.followOnly }
18
+ );
19
+ const controlled = computed(() => enableLive.value || props.followOnly);
16
20
  const attrs = useAttrs();
17
21
  const liveOpen = useAAUIState(() => `${props.fieldKey}:open`, { defaultValue: false });
18
22
  const author = useAAUIStateAuthor(() => `${props.fieldKey}:open`);
@@ -25,14 +29,18 @@ watch(liveOpen, (val) => {
25
29
  if (local.value !== next) local.value = next;
26
30
  });
27
31
  watch(local, (val) => {
28
- if (!enableLive.value) return;
29
- if (!!liveOpen.value !== val) liveOpen.value = val;
32
+ if (enableLive.value && !!liveOpen.value !== val) liveOpen.value = val;
33
+ follow.publish(val);
30
34
  });
31
35
  watch(enableLive, (now, prev) => {
32
36
  if (!now || prev) return;
33
37
  const incoming = !!liveOpen.value;
34
38
  if (local.value !== incoming) local.value = incoming;
35
39
  });
40
+ watch(() => follow.leaderValue.value, (val) => {
41
+ if (!follow.adopting.value || val === void 0) return;
42
+ if (local.value !== !!val) local.value = !!val;
43
+ });
36
44
  const openedByUser = computed(() => {
37
45
  if (!enableLive.value || !local.value || author.value == null) return null;
38
46
  const state = states.value.get(author.value);
@@ -42,7 +50,7 @@ const openedByUser = computed(() => {
42
50
 
43
51
  <template>
44
52
  <UModal
45
- v-if="enableLive && !hasExternalOpen"
53
+ v-if="controlled && !hasExternalOpen"
46
54
  v-model:open="local"
47
55
  v-bind="attrs"
48
56
  >
@@ -3,7 +3,7 @@ import { computed, onBeforeUnmount, onMounted, ref, useAttrs, watch } from "vue"
3
3
  import { useAAField } from "../../composables/useAAField";
4
4
  import { useAAUIState } from "../../composables/useAAUIState";
5
5
  import { useAAEphemeral } from "../../composables/useAAEphemeral";
6
- import { useAAFollowPeer } from "../../composables/useAAFollowPeer";
6
+ import { useAAFollowShare } from "../../composables/useAAFollowShare";
7
7
  import { awareRingStyle } from "../../utils/awareRingStyle";
8
8
  defineOptions({ inheritAttrs: false });
9
9
  const props = defineProps({
@@ -14,10 +14,13 @@ const props = defineProps({
14
14
  peers: { type: Boolean, required: false, default: false },
15
15
  total: { type: Boolean, required: false, default: false }
16
16
  });
17
- const { isFollowing } = useAAFollowPeer();
18
17
  const enableAwareness = computed(() => props.awareness || props.total);
19
- const enableLive = computed(() => props.live || props.total || props.followOnly && isFollowing.value);
18
+ const enableLive = computed(() => props.live || props.total);
20
19
  const enablePeers = computed(() => props.peers || props.total);
20
+ const follow = useAAFollowShare(
21
+ () => `${props.fieldKey}:scroll`,
22
+ { enabled: () => props.followOnly }
23
+ );
21
24
  const { hoverers, focusers, pressers, isPressed, hoverHandlers } = useAAField(() => props.fieldKey);
22
25
  const ringStyle = computed(
23
26
  () => enableAwareness.value ? awareRingStyle({
@@ -39,6 +42,7 @@ function flush() {
39
42
  const payload = { y: el.scrollTop, x: el.scrollLeft };
40
43
  if (enableLive.value && !suppress) liveScroll.value = payload;
41
44
  if (enablePeers.value) setPeerScroll(payload);
45
+ if (!suppress) follow.publish(payload);
42
46
  }
43
47
  function onScroll() {
44
48
  if (!raf) raf = requestAnimationFrame(flush);
@@ -61,6 +65,10 @@ watch(enableLive, (now, prev) => {
61
65
  if (!now || prev) return;
62
66
  applyLiveScroll(liveScroll.value);
63
67
  });
68
+ watch(() => follow.leaderValue.value, (val) => {
69
+ if (!follow.adopting.value) return;
70
+ applyLiveScroll(val);
71
+ }, { deep: true });
64
72
  onMounted(() => {
65
73
  elRef.value?.addEventListener("scroll", onScroll, { passive: true });
66
74
  });
@@ -1,7 +1,7 @@
1
1
  <script setup>
2
2
  import { computed, ref, useAttrs, watch } from "vue";
3
3
  import { useAAUIState, useAAUIStateAuthor } from "../../composables/useAAUIState";
4
- import { useAAFollowPeer } from "../../composables/useAAFollowPeer";
4
+ import { useAAFollowShare } from "../../composables/useAAFollowShare";
5
5
  import { useAwareness } from "../../composables/useAwareness";
6
6
  defineOptions({ inheritAttrs: false });
7
7
  const props = defineProps({
@@ -11,8 +11,12 @@ const props = defineProps({
11
11
  followOnly: { type: Boolean, required: false, default: false },
12
12
  total: { type: Boolean, required: false, default: false }
13
13
  });
14
- const { isFollowing } = useAAFollowPeer();
15
- const enableLive = computed(() => props.live || props.total || props.followOnly && isFollowing.value);
14
+ const enableLive = computed(() => props.live || props.total);
15
+ const follow = useAAFollowShare(
16
+ () => `${props.fieldKey}:open`,
17
+ { enabled: () => props.followOnly }
18
+ );
19
+ const controlled = computed(() => enableLive.value || props.followOnly);
16
20
  const attrs = useAttrs();
17
21
  const liveOpen = useAAUIState(() => `${props.fieldKey}:open`, { defaultValue: false });
18
22
  const author = useAAUIStateAuthor(() => `${props.fieldKey}:open`);
@@ -25,14 +29,18 @@ watch(liveOpen, (val) => {
25
29
  if (local.value !== next) local.value = next;
26
30
  });
27
31
  watch(local, (val) => {
28
- if (!enableLive.value) return;
29
- if (!!liveOpen.value !== val) liveOpen.value = val;
32
+ if (enableLive.value && !!liveOpen.value !== val) liveOpen.value = val;
33
+ follow.publish(val);
30
34
  });
31
35
  watch(enableLive, (now, prev) => {
32
36
  if (!now || prev) return;
33
37
  const incoming = !!liveOpen.value;
34
38
  if (local.value !== incoming) local.value = incoming;
35
39
  });
40
+ watch(() => follow.leaderValue.value, (val) => {
41
+ if (!follow.adopting.value || val === void 0) return;
42
+ if (local.value !== !!val) local.value = !!val;
43
+ });
36
44
  const openedByUser = computed(() => {
37
45
  if (!enableLive.value || !local.value || author.value == null) return null;
38
46
  const state = states.value.get(author.value);
@@ -42,7 +50,7 @@ const openedByUser = computed(() => {
42
50
 
43
51
  <template>
44
52
  <USlideover
45
- v-if="enableLive && !hasExternalOpen"
53
+ v-if="controlled && !hasExternalOpen"
46
54
  v-model:open="local"
47
55
  v-bind="attrs"
48
56
  >
@@ -3,7 +3,7 @@ import { computed, ref, useAttrs, watch } from "vue";
3
3
  import { useAAField } from "../../composables/useAAField";
4
4
  import { useAAUIState } from "../../composables/useAAUIState";
5
5
  import { useAAEphemeral } from "../../composables/useAAEphemeral";
6
- import { useAAFollowPeer } from "../../composables/useAAFollowPeer";
6
+ import { useAAFollowShare } from "../../composables/useAAFollowShare";
7
7
  import AHoverItem from "./AHoverItem.vue";
8
8
  function tabId(item) {
9
9
  if (item == null) return "";
@@ -24,10 +24,14 @@ const props = defineProps({
24
24
  peers: { type: Boolean, required: false, default: false },
25
25
  total: { type: Boolean, required: false, default: false }
26
26
  });
27
- const { isFollowing } = useAAFollowPeer();
28
27
  const enableAwareness = computed(() => props.awareness || props.total);
29
- const enableLive = computed(() => props.live || props.total || props.followOnly && isFollowing.value);
28
+ const enableLive = computed(() => props.live || props.total);
30
29
  const enablePeers = computed(() => props.peers || props.total);
30
+ const follow = useAAFollowShare(
31
+ () => `${props.fieldKey}:active`,
32
+ { enabled: () => props.followOnly }
33
+ );
34
+ const controlled = computed(() => enableLive.value || props.followOnly);
31
35
  const attrs = useAttrs();
32
36
  const { hoverers, focusers, hoverHandlers } = useAAField(() => props.fieldKey);
33
37
  const liveActive = useAAUIState(() => `${props.fieldKey}:active`, { defaultValue: "" });
@@ -44,12 +48,18 @@ watch(liveActive, (val) => {
44
48
  watch(local, (val) => {
45
49
  if (enableLive.value && (liveActive.value || "") !== val) liveActive.value = val;
46
50
  if (enablePeers.value) setLocal(val || null);
51
+ follow.publish(val || "");
47
52
  });
48
53
  watch(enableLive, (now, prev) => {
49
54
  if (!now || prev) return;
50
55
  const incoming = liveActive.value || "";
51
56
  if (incoming && local.value !== incoming) local.value = incoming;
52
57
  });
58
+ watch(() => follow.leaderValue.value, (val) => {
59
+ if (!follow.adopting.value) return;
60
+ const next = val || "";
61
+ if (next && local.value !== next) local.value = next;
62
+ });
53
63
  const ringStyle = computed(() => {
54
64
  if (!enableAwareness.value) return void 0;
55
65
  const focusColor = focusers.value[0]?.user?.color;
@@ -74,7 +84,7 @@ const eventHandlers = computed(() => enableAwareness.value ? hoverHandlers : {})
74
84
  v-on="eventHandlers"
75
85
  >
76
86
  <UTabs
77
- v-if="enableLive && !hasExternalModel"
87
+ v-if="controlled && !hasExternalModel"
78
88
  v-model="local"
79
89
  v-bind="attrs"
80
90
  >
@@ -1,5 +1,5 @@
1
1
  type __VLS_Props = {
2
- fieldType: 'text' | 'url' | 'date' | 'datetime' | 'daterange' | 'location' | 'select' | 'icon';
2
+ fieldType: 'text' | 'url' | 'date' | 'datetime' | 'daterange' | 'location' | 'select' | 'icon' | 'tags';
3
3
  /** Chip label — shown while the field is empty, and as the popover title. */
4
4
  label?: string;
5
5
  /** Lucide icon override (defaults per field type). */
@@ -8,6 +8,7 @@ import {
8
8
  } from "@internationalized/date";
9
9
  import ALocationPickerPopover from "./ALocationPickerPopover.vue";
10
10
  import AIconPickerPopover from "./AIconPickerPopover.vue";
11
+ import ATagsEditor from "../ATagsEditor.vue";
11
12
  const props = defineProps({
12
13
  fieldType: { type: String, required: true },
13
14
  label: { type: String, required: false, default: "" },
@@ -33,7 +34,8 @@ const DEFAULT_ICONS = {
33
34
  daterange: "i-lucide-calendar-range",
34
35
  location: "i-lucide-map-pin",
35
36
  select: "i-lucide-list",
36
- icon: "i-lucide-smile"
37
+ icon: "i-lucide-smile",
38
+ tags: "i-lucide-tags"
37
39
  };
38
40
  const chipIcon = computed(() => {
39
41
  if (props.fieldType === "icon") {
@@ -55,6 +57,9 @@ function patch(update) {
55
57
  if (props.readonly) return;
56
58
  emit("patch", update);
57
59
  }
60
+ function onTagsSave(next) {
61
+ patch({ [props.metaKey]: next.length ? next : void 0 });
62
+ }
58
63
  function isoToCalendarDate(s) {
59
64
  if (s.length < 10) return void 0;
60
65
  try {
@@ -87,6 +92,12 @@ function asSingleTime(raw) {
87
92
  }
88
93
  return null;
89
94
  }
95
+ const tagList = computed(() => {
96
+ const raw = props.meta?.[props.metaKey];
97
+ if (Array.isArray(raw)) return raw.map((t) => String(t).trim()).filter(Boolean);
98
+ if (typeof raw === "string") return raw.split(",").map((t) => t.trim()).filter(Boolean);
99
+ return [];
100
+ });
90
101
  const displayText = computed(() => {
91
102
  switch (props.fieldType) {
92
103
  case "text":
@@ -125,6 +136,8 @@ const displayText = computed(() => {
125
136
  return getStr(props.metaKey);
126
137
  case "icon":
127
138
  return getStr(props.metaKey);
139
+ case "tags":
140
+ return tagList.value.join(", ");
128
141
  default:
129
142
  return "";
130
143
  }
@@ -266,6 +279,32 @@ function onIconPick(name) {
266
279
  />
267
280
  </template>
268
281
 
282
+ <!-- tags delegates to the shared editor. It is a MODAL rather than a
283
+ popover, so the chip is an ordinary button that opens it — an
284
+ `<UInputTags>` inline in a popover loses its own focus to the popover's
285
+ focus trap on the first Enter. -->
286
+ <template v-else-if="fieldType === 'tags' && !readonly">
287
+ <UButton
288
+ size="sm"
289
+ color="neutral"
290
+ variant="ghost"
291
+ :icon="chipIcon"
292
+ :class="CHIP_CLASS"
293
+ @click="popoverOpen = true"
294
+ >
295
+ <span
296
+ class="max-w-44 truncate"
297
+ :class="isEmpty ? 'text-(--ui-text-muted)' : ''"
298
+ >{{ chipText }}</span>
299
+ </UButton>
300
+ <ATagsEditor
301
+ v-model:open="popoverOpen"
302
+ :tags="tagList"
303
+ :title="label ? `Edit ${label.toLowerCase()}` : 'Edit tags'"
304
+ @save="onTagsSave"
305
+ />
306
+ </template>
307
+
269
308
  <UPopover
270
309
  v-else-if="!readonly"
271
310
  :open="popoverOpen"
@@ -1,5 +1,5 @@
1
1
  type __VLS_Props = {
2
- fieldType: 'text' | 'url' | 'date' | 'datetime' | 'daterange' | 'location' | 'select' | 'icon';
2
+ fieldType: 'text' | 'url' | 'date' | 'datetime' | 'daterange' | 'location' | 'select' | 'icon' | 'tags';
3
3
  /** Chip label — shown while the field is empty, and as the popover title. */
4
4
  label?: string;
5
5
  /** Lucide icon override (defaults per field type). */
@@ -36,10 +36,10 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {},
36
36
  name: string;
37
37
  color: string;
38
38
  online: boolean | null;
39
+ isFollowing: boolean;
39
40
  currentDocId: string | null;
40
41
  isSelf: boolean;
41
42
  avatarStyle: string;
42
- isFollowing: boolean;
43
43
  showFollow: boolean;
44
44
  currentDocLabel: string | null;
45
45
  currentDocIcon: string;
@@ -36,10 +36,10 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {},
36
36
  name: string;
37
37
  color: string;
38
38
  online: boolean | null;
39
+ isFollowing: boolean;
39
40
  currentDocId: string | null;
40
41
  isSelf: boolean;
41
42
  avatarStyle: string;
42
- isFollowing: boolean;
43
43
  showFollow: boolean;
44
44
  currentDocLabel: string | null;
45
45
  currentDocIcon: string;
@@ -17,6 +17,28 @@ export interface UseAAFollowPeerOptions {
17
17
  keyPrefix?: string;
18
18
  /** Hook fired when the user breaks follow via local interaction. */
19
19
  onBreak?: () => void;
20
+ /**
21
+ * Which local interactions end the follow.
22
+ *
23
+ * The default (`'any'`) is right for an INCIDENTAL follow — you were dragged
24
+ * along by someone's scroll and the first thing you do should get you out.
25
+ * It is wrong for a DELIBERATE one: with `'any'`, the very next click ends
26
+ * it, including the click on the follow button used to check whether it
27
+ * worked, and including any click inside the UI that offers the follow.
28
+ *
29
+ * `'scroll-keys'` keeps the escape hatch that matters (scrolling or typing —
30
+ * the things you do to the CONTENT) and ignores clicks, so a follow survives
31
+ * using the interface around it.
32
+ *
33
+ * `'none'` never breaks automatically; the caller owns `unfollow()`.
34
+ */
35
+ breakOn?: 'any' | 'scroll-keys' | 'none';
36
+ /**
37
+ * A pointerdown inside one of these is not an escape. Pass the surface that
38
+ * owns the follow UI — its own controls should not cancel the thing they
39
+ * exist to control. Ignored unless `breakOn` is `'any'`.
40
+ */
41
+ ignoreWithin?: () => (HTMLElement | null | undefined)[];
20
42
  }
21
43
  export declare function useAAFollowPeer(options?: UseAAFollowPeerOptions): {
22
44
  follow: (clientIdOrPublicKey: number | string) => void;
@@ -34,7 +34,7 @@ export function useAAFollowPeer(options = {}) {
34
34
  return followingUserCache.value;
35
35
  });
36
36
  watch(followingUser, (user) => {
37
- if (user) followingUserCache.value = { ...user };
37
+ if (user && user !== followingUserCache.value) followingUserCache.value = { ...user };
38
38
  }, { flush: "post" });
39
39
  watch(isFollowing, (active) => {
40
40
  if (!active) followingUserCache.value = null;
@@ -46,14 +46,24 @@ export function useAAFollowPeer(options = {}) {
46
46
  function attachInteractionBreaker() {
47
47
  detachInteraction();
48
48
  if (typeof window === "undefined") return;
49
+ const mode = options.breakOn ?? "any";
50
+ if (mode === "none") return;
49
51
  const onBreak = () => unfollow();
52
+ const onPointerDown = (event) => {
53
+ const roots = options.ignoreWithin?.() ?? [];
54
+ const target = event.target;
55
+ for (const root of roots) {
56
+ if (root && target && root.contains(target)) return;
57
+ }
58
+ unfollow();
59
+ };
50
60
  window.addEventListener("keydown", onBreak);
51
- window.addEventListener("pointerdown", onBreak);
52
61
  window.addEventListener("wheel", onBreak, { passive: true });
62
+ if (mode === "any") window.addEventListener("pointerdown", onPointerDown);
53
63
  unsubInteraction = () => {
54
64
  window.removeEventListener("keydown", onBreak);
55
- window.removeEventListener("pointerdown", onBreak);
56
65
  window.removeEventListener("wheel", onBreak);
66
+ window.removeEventListener("pointerdown", onPointerDown);
57
67
  };
58
68
  }
59
69
  function follow(clientIdOrPublicKey) {
@@ -0,0 +1,64 @@
1
+ import type { MaybeRefOrGetter } from 'vue';
2
+ /**
3
+ * The channel `followOnly` runs on.
4
+ *
5
+ * ## The bug this exists to fix
6
+ *
7
+ * `followOnly` had never worked, in any of the six aware components that offer
8
+ * it, since the day it was added. Every one of them gated the WRITE and the
9
+ * READ on a single computed:
10
+ *
11
+ * ```ts
12
+ * const enableLive = computed(() =>
13
+ * props.live || props.total || (props.followOnly && isFollowing.value))
14
+ * ```
15
+ *
16
+ * `isFollowing` is false for anyone who is not currently following someone —
17
+ * **including the leader**. So the leader never published, the follower had
18
+ * nothing to adopt, and the mode was inert in both directions. It is not a
19
+ * corner case: the module's own docs recommend `followOnly` as the DEFAULT for
20
+ * scroll, tabs, collapsibles and modal-open, and describe the intent the code
21
+ * did not implement — *"live semantics, but only adopted while actively
22
+ * following someone."* Adoption was gated correctly; publication was gated by
23
+ * mistake.
24
+ *
25
+ * ## Why "just publish always" is the wrong fix
26
+ *
27
+ * That was the obvious repair and it makes `followOnly` identical to `live`.
28
+ * `useAAUIState` stores **one entry per fieldKey** on a shared `aware-ui`
29
+ * Y.Map (`{value, by, ts}`, last-write-wins, not per client), so unconditional
30
+ * publishing means every visitor's scroll position overwrites the same slot and
31
+ * drags everybody else with it. The shared slot is what `live` NEEDS; it is
32
+ * exactly wrong here.
33
+ *
34
+ * ## The shape that works
35
+ *
36
+ * A per-peer ephemeral channel. `useAAEphemeral` keys on the awareness
37
+ * clientId, so N peers write N slots and never collide, and none of it touches
38
+ * the CRDT. Publish unconditionally into that; while following, read back the
39
+ * one entry whose `clientId` is the leader's. `aware-ui` is left alone as the
40
+ * shared-slot channel `live` and `total` need.
41
+ *
42
+ * There is a working reference for this shape already: `useAAFocus` publishes
43
+ * selection to `useAAEphemeral('aa:focus')` and `<AGlobalFocusLayer follow-only>`
44
+ * filters on `followingClientId`. This is the same two lines, generalised so
45
+ * the six components share one implementation instead of six near-copies.
46
+ *
47
+ * ## Publishing is skipped when nobody could be listening
48
+ *
49
+ * A visitor alone on a page has no follower, so every awareness frame this
50
+ * would send is waste — and on a personal site "alone" is the common case, not
51
+ * the edge one. The guard costs one comparison and removes the whole cost.
52
+ */
53
+ export interface UseAAFollowShareOptions {
54
+ /**
55
+ * Whether this component is in `followOnly` mode at all. When false nothing
56
+ * is published and nothing is adopted — the component is solo.
57
+ */
58
+ enabled: MaybeRefOrGetter<boolean>;
59
+ }
60
+ export declare function useAAFollowShare<T>(fieldKey: MaybeRefOrGetter<string>, options: UseAAFollowShareOptions): {
61
+ publish: (value: T) => void;
62
+ leaderValue: import("vue").ComputedRef<T | undefined>;
63
+ adopting: import("vue").ComputedRef<boolean>;
64
+ };
@@ -0,0 +1,30 @@
1
+ import { computed, onScopeDispose, toValue, watch } from "vue";
2
+ import { useAAEphemeral } from "./useAAEphemeral.js";
3
+ import { useAAFollowPeer } from "./useAAFollowPeer.js";
4
+ import { useAwareness } from "./useAwareness.js";
5
+ function resolveKey(fieldKey) {
6
+ return toValue(fieldKey);
7
+ }
8
+ export function useAAFollowShare(fieldKey, options) {
9
+ const { peers, setLocal } = useAAEphemeral(() => `${resolveKey(fieldKey)}:follow`);
10
+ const { followingClientId, isFollowing } = useAAFollowPeer();
11
+ const { states } = useAwareness();
12
+ const enabled = computed(() => !!toValue(options.enabled));
13
+ const observed = computed(() => states.value.size > 1);
14
+ const leaderValue = computed(() => {
15
+ if (!enabled.value) return void 0;
16
+ const cid = followingClientId.value;
17
+ if (cid == null) return void 0;
18
+ return peers.value.find((p) => p.clientId === cid)?.value;
19
+ });
20
+ const adopting = computed(() => enabled.value && isFollowing.value);
21
+ function publish(value) {
22
+ if (!enabled.value || !observed.value) return;
23
+ setLocal(value);
24
+ }
25
+ watch(enabled, (on) => {
26
+ if (!on) setLocal(null);
27
+ });
28
+ onScopeDispose(() => setLocal(null));
29
+ return { publish, leaderValue, adopting };
30
+ }