@knitify/vue 1.0.0 → 2.0.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.
Files changed (39) hide show
  1. package/README.md +111 -86
  2. package/dist/index.es.js +3384 -1526
  3. package/dist/index.umd.js +1 -1
  4. package/dist/types/components/Avatar/KAvatar.vue.d.ts +5 -1
  5. package/dist/types/components/Avatar/types.d.ts +91 -3
  6. package/dist/types/components/Badge/types.d.ts +2 -0
  7. package/dist/types/components/Chat/KChatDivider.vue.d.ts +11 -0
  8. package/dist/types/components/Chat/KChatMessageActions.vue.d.ts +18 -0
  9. package/dist/types/components/Chat/KChatNotice.vue.d.ts +11 -0
  10. package/dist/types/components/Chat/KChatPrompt.vue.d.ts +1 -1
  11. package/dist/types/components/Chat/types.d.ts +90 -0
  12. package/dist/types/components/ChatDock/KChatDock.vue.d.ts +45 -0
  13. package/dist/types/components/ChatDock/KChatDockItem.vue.d.ts +11 -0
  14. package/dist/types/components/ChatDock/KChatDockPanel.vue.d.ts +11 -0
  15. package/dist/types/components/ChatDock/KChatWindow.vue.d.ts +27 -0
  16. package/dist/types/components/ChatDock/KMessenger.vue.d.ts +23 -0
  17. package/dist/types/components/ChatDock/keys.d.ts +98 -0
  18. package/dist/types/components/ChatDock/messenger-types.d.ts +280 -0
  19. package/dist/types/components/ChatDock/store-keys.d.ts +7 -0
  20. package/dist/types/components/ChatDock/types.d.ts +134 -0
  21. package/dist/types/components/ChatDock/useChatDock.d.ts +11 -0
  22. package/dist/types/components/Collapse/KCollapse.vue.d.ts +2 -2
  23. package/dist/types/components/Collapse/useCollapseSync.d.ts +7 -5
  24. package/dist/types/components/Drawer/KDrawer.vue.d.ts +3 -3
  25. package/dist/types/components/Dropdown/KDropdown.vue.d.ts +2 -2
  26. package/dist/types/components/Input/types.d.ts +1 -1
  27. package/dist/types/components/Modal/KModal.vue.d.ts +3 -3
  28. package/dist/types/components/Popover/KPopover.vue.d.ts +2 -2
  29. package/dist/types/components/Popover/useOverlaySync.d.ts +15 -1
  30. package/dist/types/components/Spinner/KSpinner.vue.d.ts +6 -0
  31. package/dist/types/components/Spinner/types.d.ts +13 -0
  32. package/dist/types/components/index.d.ts +12 -0
  33. package/dist/types/components/types.d.ts +4 -0
  34. package/dist/types/index.d.ts +1 -0
  35. package/dist/types/utils/useDocumentEvent.d.ts +19 -0
  36. package/dist/types/utils/useExclusive.d.ts +13 -0
  37. package/dist/types/utils/useTopmost.d.ts +17 -0
  38. package/dist/web-types.json +5107 -0
  39. package/package.json +17 -5
@@ -1,5 +1,7 @@
1
1
  import { Size, Variant } from '../../types';
2
2
  export type KBadgeProps = {
3
+ /** Tighter padding for a badge sitting on an avatar or in a dense list. */
4
+ compact?: boolean;
3
5
  pill?: boolean;
4
6
  size?: Size;
5
7
  subtle?: boolean;
@@ -0,0 +1,11 @@
1
+ import type { KChatDividerProps, KChatDividerSlots } from './types';
2
+ type __VLS_Slots = KChatDividerSlots;
3
+ declare const __VLS_base: import("vue").DefineComponent<KChatDividerProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<KChatDividerProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
4
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
5
+ declare const _default: typeof __VLS_export;
6
+ export default _default;
7
+ type __VLS_WithSlots<T, S> = T & {
8
+ new (): {
9
+ $slots: S;
10
+ };
11
+ };
@@ -0,0 +1,18 @@
1
+ import type { KChatMessageActionsProps, KChatMessageActionsSlots } from './types';
2
+ type __VLS_Slots = KChatMessageActionsSlots;
3
+ declare const __VLS_base: import("vue").DefineComponent<KChatMessageActionsProps, {
4
+ hold: () => void;
5
+ release: () => void;
6
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
7
+ action: (key: string, item?: string | undefined) => any;
8
+ }, string, import("vue").PublicProps, Readonly<KChatMessageActionsProps> & Readonly<{
9
+ onAction?: ((key: string, item?: string | undefined) => any) | undefined;
10
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
12
+ declare const _default: typeof __VLS_export;
13
+ export default _default;
14
+ type __VLS_WithSlots<T, S> = T & {
15
+ new (): {
16
+ $slots: S;
17
+ };
18
+ };
@@ -0,0 +1,11 @@
1
+ import type { KChatNoticeProps, KChatNoticeSlots } from './types';
2
+ type __VLS_Slots = KChatNoticeSlots;
3
+ declare const __VLS_base: import("vue").DefineComponent<KChatNoticeProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<KChatNoticeProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
4
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
5
+ declare const _default: typeof __VLS_export;
6
+ export default _default;
7
+ type __VLS_WithSlots<T, S> = T & {
8
+ new (): {
9
+ $slots: S;
10
+ };
11
+ };
@@ -16,8 +16,8 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {}, {
16
16
  }>, {
17
17
  disabled: boolean;
18
18
  busy: boolean;
19
- maxRows: number;
20
19
  placeholder: string;
20
+ maxRows: number;
21
21
  newlineOnEnter: boolean;
22
22
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
23
23
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
@@ -1,4 +1,7 @@
1
+ import type { Intent } from '../../types';
1
2
  export type KChatProps = {
3
+ /** Stacks every message's actions under its bubble instead of beside it. */
4
+ actionsBottom?: boolean;
2
5
  ai?: boolean;
3
6
  autoscroll?: boolean;
4
7
  busy?: boolean;
@@ -18,6 +21,93 @@ export type KChatMessageProps = {
18
21
  export type KChatMessageSlots = {
19
22
  default?(): any;
20
23
  time?(): any;
24
+ /** The hover row beside or below the bubble. Put a `KChatMessageActions` here. */
25
+ actions?(): any;
26
+ };
27
+ /**
28
+ * One entry in a `KChatMessageActions` set. A consuming project computes these
29
+ * per message, which is where sender, status and permission logic belongs —
30
+ * the component only renders what it is handed.
31
+ */
32
+ export type KChatAction = {
33
+ /** Identifies the action in the `action` event. Unique within its level. */
34
+ key: string;
35
+ /** Sprite id, e.g. `reply`. Omitted for a text-only dropdown row. */
36
+ icon?: string;
37
+ /** Tooltip and accessible name. */
38
+ label: string;
39
+ disabled?: boolean;
40
+ /**
41
+ * Semantic color, for destructive rows. Applies to top-level actions only
42
+ * — a row nested under `items` renders as a plain `KDropdownItem`, which
43
+ * has no intent prop, so `intent` is silently ignored there.
44
+ */
45
+ intent?: Intent;
46
+ /** Defaults to `true`. A hidden action renders nothing at all. */
47
+ visible?: boolean;
48
+ /** Presence turns the action into a dropdown of these rows. */
49
+ items?: KChatAction[];
50
+ /** A rule between rows. Only meaningful inside `items`. */
51
+ divider?: boolean;
52
+ };
53
+ export type KChatMessageActionsProps = {
54
+ /**
55
+ * The action set. Defaults to react, reply and more; passing an array
56
+ * replaces it outright rather than adding to it.
57
+ */
58
+ actions?: KChatAction[];
59
+ };
60
+ export type KChatMessageActionsEmits = {
61
+ /**
62
+ * A top-level action's key, plus the nested key when the choice came from a
63
+ * dropdown row. Switch on `key` rather than binding a handler per button.
64
+ */
65
+ action: [key: string, item?: string];
66
+ };
67
+ export type KChatMessageActionsSlots = {
68
+ /**
69
+ * Replaces the whole row, keeping the reveal behaviour and the latch. `hold`
70
+ * and `release` are the same pair the built-in dropdown binds, so a custom
71
+ * overlay can keep the row up while it is open.
72
+ */
73
+ default?(props: {
74
+ hold: () => void;
75
+ release: () => void;
76
+ }): any;
77
+ /**
78
+ * Fills the `react` action, which exists precisely because a panel-shaped
79
+ * overlay — an emoji picker — cannot be described by a `KChatAction`.
80
+ */
81
+ react?(props: {
82
+ hold: () => void;
83
+ release: () => void;
84
+ }): any;
85
+ /**
86
+ * Dropdown rows for the `more` action, replacing its `items`. Rows you
87
+ * supply here are your own markup — only the rows generated from `items`
88
+ * emit the `action` event, so a row rendered through this slot must wire
89
+ * up its own click handling.
90
+ */
91
+ more?(): any;
92
+ };
93
+ export type KChatDividerProps = {
94
+ /** Centred label. Omit for an unbroken rule. */
95
+ label?: string;
96
+ };
97
+ /**
98
+ * An event in the conversation — "Call ended at 01:48 PM", "You ended the
99
+ * meeting". Distinct from `KChatDivider`, which marks a boundary between
100
+ * messages rather than being content itself.
101
+ */
102
+ export type KChatNoticeProps = {
103
+ /** The notice text. The default slot overrides it, for markup or a link. */
104
+ label?: string;
105
+ };
106
+ export type KChatNoticeSlots = {
107
+ default?(): any;
108
+ };
109
+ export type KChatDividerSlots = {
110
+ default?(): any;
21
111
  };
22
112
  export type KChatPromptProps = {
23
113
  busy?: boolean;
@@ -0,0 +1,45 @@
1
+ import type { KChatDockProps, KChatDockSlots } from './types';
2
+ type __VLS_Slots = KChatDockSlots;
3
+ declare function openPanel(): void;
4
+ declare function closePanel(): void;
5
+ declare function togglePanel(): void;
6
+ /**
7
+ * Re-runs core's filter against whatever the search field currently holds.
8
+ *
9
+ * `filter()` is one-shot: it stamps `is-hidden` on the items present when it
10
+ * runs and recomputes the empty element only then. Rows a framework renders
11
+ * later — an async list resolving, a refresh adding rows while a query is
12
+ * active — are therefore unfiltered, and the empty element keeps whatever the
13
+ * last call decided (`closePanel()` filters on an empty list, so it un-hides
14
+ * it). A caller that renders the panel's items itself calls this after the
15
+ * rows change.
16
+ */
17
+ declare function refilter(): void;
18
+ declare const __VLS_base: import("vue").DefineComponent<KChatDockProps, {
19
+ openPanel: typeof openPanel;
20
+ closePanel: typeof closePanel;
21
+ togglePanel: typeof togglePanel;
22
+ refilter: typeof refilter;
23
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
24
+ select: (id: string, opened: boolean) => any;
25
+ search: (query: string) => any;
26
+ reflow: () => any;
27
+ launcher: () => any;
28
+ panel: (open: boolean) => any;
29
+ activate: (id: string) => any;
30
+ }, string, import("vue").PublicProps, Readonly<KChatDockProps> & Readonly<{
31
+ onSelect?: ((id: string, opened: boolean) => any) | undefined;
32
+ onSearch?: ((query: string) => any) | undefined;
33
+ onReflow?: (() => any) | undefined;
34
+ onLauncher?: (() => any) | undefined;
35
+ onPanel?: ((open: boolean) => any) | undefined;
36
+ onActivate?: ((id: string) => any) | undefined;
37
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
38
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
39
+ declare const _default: typeof __VLS_export;
40
+ export default _default;
41
+ type __VLS_WithSlots<T, S> = T & {
42
+ new (): {
43
+ $slots: S;
44
+ };
45
+ };
@@ -0,0 +1,11 @@
1
+ import type { KChatDockItemProps, KChatDockItemSlots } from './types';
2
+ type __VLS_Slots = KChatDockItemSlots;
3
+ declare const __VLS_base: import("vue").DefineComponent<KChatDockItemProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<KChatDockItemProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
4
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
5
+ declare const _default: typeof __VLS_export;
6
+ export default _default;
7
+ type __VLS_WithSlots<T, S> = T & {
8
+ new (): {
9
+ $slots: S;
10
+ };
11
+ };
@@ -0,0 +1,11 @@
1
+ import type { KChatDockPanelProps, KChatDockPanelSlots } from './types';
2
+ type __VLS_Slots = KChatDockPanelSlots;
3
+ declare const __VLS_base: import("vue").DefineComponent<KChatDockPanelProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<KChatDockPanelProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
4
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
5
+ declare const _default: typeof __VLS_export;
6
+ export default _default;
7
+ type __VLS_WithSlots<T, S> = T & {
8
+ new (): {
9
+ $slots: S;
10
+ };
11
+ };
@@ -0,0 +1,27 @@
1
+ import type { KChatWindowProps, KChatWindowSlots, KChatWindowState } from './types';
2
+ type __VLS_Props = KChatWindowProps;
3
+ type __VLS_Slots = KChatWindowSlots;
4
+ declare function expand(): void;
5
+ declare function rail(): void;
6
+ type __VLS_ModelProps = {
7
+ 'state'?: KChatWindowState;
8
+ };
9
+ type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
10
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
11
+ expand: typeof expand;
12
+ rail: typeof rail;
13
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
14
+ close: () => any;
15
+ "update:state": (value: KChatWindowState) => any;
16
+ }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
17
+ onClose?: (() => any) | undefined;
18
+ "onUpdate:state"?: ((value: KChatWindowState) => any) | undefined;
19
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
20
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
21
+ declare const _default: typeof __VLS_export;
22
+ export default _default;
23
+ type __VLS_WithSlots<T, S> = T & {
24
+ new (): {
25
+ $slots: S;
26
+ };
27
+ };
@@ -0,0 +1,23 @@
1
+ import type { ChatDockStore, KMessengerProps, KMessengerSlots } from './messenger-types';
2
+ type __VLS_Slots = KMessengerSlots;
3
+ declare const __VLS_base: import("vue").DefineComponent<KMessengerProps, ChatDockStore, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
4
+ error: (kind: import("./messenger-types").ChatDockErrorKind, id: string | undefined, error: unknown) => any;
5
+ send: (message: import("./messenger-types").ChatMessage) => any;
6
+ open: (id: string) => any;
7
+ close: (id: string) => any;
8
+ receive: (message: import("./messenger-types").ChatMessage) => any;
9
+ }, string, import("vue").PublicProps, Readonly<KMessengerProps> & Readonly<{
10
+ onError?: ((kind: import("./messenger-types").ChatDockErrorKind, id: string | undefined, error: unknown) => any) | undefined;
11
+ onSend?: ((message: import("./messenger-types").ChatMessage) => any) | undefined;
12
+ onOpen?: ((id: string) => any) | undefined;
13
+ onClose?: ((id: string) => any) | undefined;
14
+ onReceive?: ((message: import("./messenger-types").ChatMessage) => any) | undefined;
15
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
16
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
17
+ declare const _default: typeof __VLS_export;
18
+ export default _default;
19
+ type __VLS_WithSlots<T, S> = T & {
20
+ new (): {
21
+ $slots: S;
22
+ };
23
+ };
@@ -0,0 +1,98 @@
1
+ import type { InjectionKey, ShallowRef } from 'vue';
2
+ import type Knitify from '@knitify/core';
3
+ export type ChatDockInstance = InstanceType<typeof Knitify.modules.ChatDock>;
4
+ /**
5
+ * What `withModule` did, so a caller can react to each outcome distinctly:
6
+ *
7
+ * - `'called'` — the callback ran against a live module. Anything the caller
8
+ * wanted to tell core has been told.
9
+ * - `'deferred'` — a dock is present but its first `init()` has not run yet,
10
+ * so nothing may reach core (see `withModule`). The callback did **not**
11
+ * run; the caller must record its intent through `declare` instead, and the
12
+ * dock replays it the moment calling core becomes safe.
13
+ * - `'unavailable'` — there is no module to call at all: no `KChatDock`
14
+ * ancestor, or the dock's own root is gone. The callback did **not** run and
15
+ * nothing was or will be recorded, so a caller must not update bookkeeping
16
+ * that claims core was told something.
17
+ */
18
+ export type ChatDockCallResult = 'called' | 'deferred' | 'unavailable';
19
+ export type ChatDockContext = {
20
+ /**
21
+ * **The only way to reach core from anywhere in this component pair.** The
22
+ * module instance is deliberately not exposed: a call site that cannot get
23
+ * hold of it cannot skip the gate below by accident, which is what four
24
+ * successive rounds of path-specific patching kept failing to prevent.
25
+ *
26
+ * The gate: no core call may happen before the dock's own first deferred
27
+ * `init()` has run. Every core method reflows synchronously before it
28
+ * returns, and a reflow dispatches `kt.chatdock.rail`/`.unrail` to whichever
29
+ * windows changed — but a child window attaches those listeners from a
30
+ * template-ref watcher, which lands a flush *after* its parent's
31
+ * `onMounted`, and Vue orders pre-flush jobs by component creation order, so
32
+ * the dock's own watchers and an earlier sibling's watchers all run while a
33
+ * later sibling is still deaf. An event dropped that way is lost for good:
34
+ * Vue never re-patches a `class` binding whose rendered string is unchanged,
35
+ * so core's directly-set `is-railed` survives on the element while
36
+ * `v-model:state` (and `aria-expanded`) stay wrong forever, and every later
37
+ * reflow is a no-op diff that never repairs it.
38
+ *
39
+ * Skipping a pre-init call costs nothing, which is what makes the gate safe
40
+ * rather than merely cautious: the deferred `init()` applies every pending
41
+ * declaration and reflows anyway, so it subsumes whatever was skipped.
42
+ *
43
+ * Also flushes any pending declarations through core immediately before
44
+ * running the callback, so a `reflow()` never computes capacity against a
45
+ * window core has not yet been told is railed.
46
+ */
47
+ withModule: (run: (module: ChatDockInstance) => void) => ChatDockCallResult;
48
+ /**
49
+ * Records whether a window should be railed once the dock next applies its
50
+ * declarations — no class, no attribute, no method call yet. `KChatDock`
51
+ * plays every recorded declaration through core itself, from its deferred
52
+ * first `init()` and again before every later core call (see `withModule`),
53
+ * which are the only points every window is guaranteed to have already
54
+ * attached its own `kt.chatdock.*` listeners.
55
+ *
56
+ * This is where state intent goes whenever `withModule` reports
57
+ * `'deferred'`, and where a window's own initial non-expanded state goes at
58
+ * mount.
59
+ *
60
+ * With only two states left, this only ever records `railed` — an
61
+ * `'expanded'` window needs nothing (that's what a freshly-seeded window
62
+ * already is), and `railed` needs a core call because only core's `rail()`
63
+ * sets the `data-kt-chat-window-minimized` marker `reflow()` reads to tell
64
+ * an explicit minimize apart from a window merely ranked below capacity.
65
+ *
66
+ * Idempotent both ways: declaring the same element `railed` repeatedly, or
67
+ * un-declaring it (passing `false`) before it's ever applied, just leaves
68
+ * one net entry (or none) — whichever a window's most recent write before
69
+ * the dock's next apply says is true.
70
+ */
71
+ declare: (element: HTMLElement, railed: boolean) => void;
72
+ /**
73
+ * The rail element, as a ref, so a window can teleport its head into it.
74
+ *
75
+ * A ref rather than the element itself because the rail is rendered by the
76
+ * dock and a window may set up before it resolves; `<Teleport defer>`
77
+ * handles a target that appears later in the same tree, and the ref is what
78
+ * lets the window react when it does.
79
+ *
80
+ * This is not a way around the gate: teleporting renders markup, it does
81
+ * not call core. Every core call still goes through `withModule`.
82
+ */
83
+ rail: Readonly<ShallowRef<HTMLElement | null>>;
84
+ /**
85
+ * The popover list element, as a ref, so a window can teleport its row into
86
+ * it. Same shape and reasoning as `rail`: the dock renders it, a window may
87
+ * set up before it resolves, and `<Teleport defer>` handles a target that
88
+ * appears later in the same tree.
89
+ */
90
+ list: Readonly<ShallowRef<HTMLElement | null>>;
91
+ /**
92
+ * The row zone element, as a ref, so `KChatDockPanel` can teleport into it.
93
+ * Same shape and reasoning as `rail` and `list`. The panel's `order: -1`
94
+ * places it beside the rail regardless of where the teleport appends it.
95
+ */
96
+ panel: Readonly<ShallowRef<HTMLElement | null>>;
97
+ };
98
+ export declare const chatDockKey: InjectionKey<ChatDockContext>;
@@ -0,0 +1,280 @@
1
+ import type { ComputedRef, Ref } from 'vue';
2
+ export type ChatConversation = {
3
+ id: string;
4
+ name: string;
5
+ /** Image URL; the avatar falls back to initials from `name`. */
6
+ avatar?: string;
7
+ /** Last message line, shown in the panel row. */
8
+ preview?: string;
9
+ unread?: number;
10
+ /** ISO timestamp; when present the panel sorts newest first. */
11
+ updatedAt?: string;
12
+ /**
13
+ * Untouched by the store — carry app-specific payload through to the slots.
14
+ * Replaced, not merged, when `refreshConversations` returns a conversation
15
+ * that carries one: the merge is a shallow spread.
16
+ */
17
+ meta?: unknown;
18
+ };
19
+ export type ChatMessage = {
20
+ id: string;
21
+ conversationId: string;
22
+ text: string;
23
+ /** `true` for the current user; drives `KChatMessage`'s `sender`. */
24
+ sender: boolean;
25
+ /** Display string, e.g. "10:42 AM". */
26
+ time?: string;
27
+ /** ISO timestamp, for ordering by the server. */
28
+ sentAt?: string;
29
+ /** Optimistic send in flight; cleared when `sendMessage` resolves. */
30
+ pending?: boolean;
31
+ /** `sendMessage` rejected; the message shows a retry control. */
32
+ failed?: boolean;
33
+ /**
34
+ * Untouched by the store — carry app-specific payload through to the slots.
35
+ * An optimistic message created by `send()` has none; the message returned
36
+ * by `sendMessage` replaces it wholesale, so `meta` appears when the server
37
+ * response does.
38
+ */
39
+ meta?: unknown;
40
+ };
41
+ export type ChatMessagesPage = {
42
+ messages: ChatMessage[];
43
+ /** `null` or `undefined` means there is nothing older. */
44
+ nextCursor?: string | null;
45
+ };
46
+ export type ChatDockLoaders = {
47
+ loadConversations: () => Promise<ChatConversation[]>;
48
+ /** Chronological within the page (oldest first). `cursor` asks for older. */
49
+ loadMessages: (id: string, cursor?: string) => Promise<ChatMessagesPage>;
50
+ /** Optional; without it the composer is hidden. */
51
+ sendMessage?: (id: string, text: string) => Promise<ChatMessage>;
52
+ /** Optional; called when a window expands. Unread is zeroed locally either way. */
53
+ markRead?: (id: string) => Promise<void>;
54
+ };
55
+ export type ChatDockOptions = {
56
+ /** Drop messages, cursor and draft when a window closes. Default `false`. */
57
+ evictOnClose?: boolean;
58
+ };
59
+ export type ChatWindowState = 'closed' | 'expanded' | 'railed';
60
+ export type LoadState = 'idle' | 'loading' | 'loaded' | 'error';
61
+ export type ChatEntry = {
62
+ conversation: ChatConversation;
63
+ window: ChatWindowState;
64
+ messages: ChatMessage[];
65
+ /** `undefined` until the first page loads; `null` when nothing older exists. */
66
+ cursor: string | null | undefined;
67
+ loading: LoadState;
68
+ loadingOlder: boolean;
69
+ error?: unknown;
70
+ draft: string;
71
+ };
72
+ export type ChatDockErrorKind = 'conversations' | 'messages' | 'send';
73
+ export type ChatDockStore = {
74
+ /** Sorted newest first when `updatedAt` is present on every entry. */
75
+ conversations: ComputedRef<ChatConversation[]>;
76
+ entries: Record<string, ChatEntry>;
77
+ /** Ids whose window is not `'closed'`, most recently opened first. */
78
+ openIds: ComputedRef<string[]>;
79
+ listLoading: Ref<LoadState>;
80
+ listError: Ref<unknown>;
81
+ query: Ref<string>;
82
+ /** Whether a composer can be rendered at all. */
83
+ canSend: boolean;
84
+ refreshConversations: () => Promise<void>;
85
+ open: (id: string) => Promise<void>;
86
+ /**
87
+ * Shows a window again without treating it as a user-initiated open: no
88
+ * rank change, no unread reset, no `markRead`, no `'open'` event. For a
89
+ * reflow un-railing a window; use `open` for a real choice.
90
+ */
91
+ expand: (id: string) => Promise<void>;
92
+ minimize: (id: string) => void;
93
+ close: (id: string) => void;
94
+ loadOlder: (id: string) => Promise<void>;
95
+ send: (id: string, text: string) => Promise<void>;
96
+ retry: (id: string, messageId: string) => Promise<void>;
97
+ retryLoad: (id: string) => Promise<void>;
98
+ receive: (message: ChatMessage) => void;
99
+ setDraft: (id: string, text: string) => void;
100
+ setQuery: (text: string) => void;
101
+ /**
102
+ * Fires after an action outcome, so a component can mirror it as an emit.
103
+ * Returns an unsubscribe function.
104
+ */
105
+ onEvent: (listener: (event: ChatDockEvent) => void) => () => void;
106
+ };
107
+ export type ChatDockEvent = {
108
+ type: 'open';
109
+ id: string;
110
+ } | {
111
+ type: 'close';
112
+ id: string;
113
+ } | {
114
+ type: 'send';
115
+ message: ChatMessage;
116
+ } | {
117
+ type: 'receive';
118
+ message: ChatMessage;
119
+ } | {
120
+ type: 'error';
121
+ kind: ChatDockErrorKind;
122
+ id?: string;
123
+ error: unknown;
124
+ };
125
+ export type KMessengerProps = {
126
+ /** The component creates its own store. Exactly one of `loaders` or `store`. */
127
+ loaders?: ChatDockLoaders;
128
+ /** A store created with `useChatDock` elsewhere and shared. */
129
+ store?: ChatDockStore;
130
+ minWindows?: number;
131
+ title?: string;
132
+ placeholder?: string;
133
+ /** Passed to `useChatDock` when the component creates the store. */
134
+ evictOnClose?: boolean;
135
+ /**
136
+ * Passed to every window's `KChat`: stacks message actions under the bubble.
137
+ * Defaults to `true` — a dock window is too narrow to spare the width beside
138
+ * each bubble. Pass `false` to put them back at the side.
139
+ */
140
+ actionsBottom?: boolean;
141
+ /**
142
+ * Called for each message with the one before it. Return a label to render
143
+ * a divider above that message, or `undefined` for none. `previous` is
144
+ * `undefined` for the first message in the list.
145
+ *
146
+ * A boundary hook, not a date hook: an app tracking its own unread boundary
147
+ * returns "Unread messages" there and a day label elsewhere.
148
+ *
149
+ * Called for every message on every render, so compare pre-computed day
150
+ * keys here rather than parsing and formatting inside the callback.
151
+ */
152
+ dateLabel?: (message: ChatMessage, previous?: ChatMessage) => string | undefined;
153
+ /**
154
+ * Return a label to render this message as a `KChatNotice` instead of a
155
+ * `KChatMessage`. `undefined` renders it as a normal bubble.
156
+ *
157
+ * For an event that arrives in the same message stream as ordinary
158
+ * messages and is distinguished per message — "You left the meeting room",
159
+ * "Call ended at 01:48 PM".
160
+ *
161
+ * A notice renders no bubble, no sender side, no time and no actions row,
162
+ * and so no retry control either: a message carrying both `failed` and a
163
+ * notice label loses the way to retry it. Return `undefined` for a message
164
+ * still in flight. `dateLabel` still applies above a notice, so a day
165
+ * divider can precede one.
166
+ *
167
+ * Called for every message on every render, like `dateLabel` — read a
168
+ * pre-computed field here rather than deriving one inside the callback.
169
+ */
170
+ noticeLabel?: (message: ChatMessage) => string | undefined;
171
+ };
172
+ export type KMessengerEmits = {
173
+ open: [id: string];
174
+ close: [id: string];
175
+ send: [message: ChatMessage];
176
+ receive: [message: ChatMessage];
177
+ error: [kind: ChatDockErrorKind, id: string | undefined, error: unknown];
178
+ };
179
+ export type KMessengerSlots = {
180
+ /** Inside the avatar circle of a head and a panel row. */
181
+ avatar?(props: {
182
+ conversation: ChatConversation;
183
+ }): any;
184
+ /**
185
+ * The window header's action area, before the minimize and close controls.
186
+ * `window-` prefixed because an unprefixed `title` would read as the dock's
187
+ * own title, which is already a prop, and `actions` would collide with the
188
+ * panel's.
189
+ */
190
+ 'window-actions'?(props: {
191
+ conversation: ChatConversation;
192
+ entry: ChatEntry;
193
+ }): any;
194
+ /** The window header's title text. */
195
+ 'window-title'?(props: {
196
+ conversation: ChatConversation;
197
+ entry: ChatEntry;
198
+ }): any;
199
+ /** Inside a railed head's avatar circle. Falls back to `avatar`. */
200
+ head?(props: {
201
+ conversation: ChatConversation;
202
+ entry: ChatEntry;
203
+ }): any;
204
+ /** Inside a `+N` popover row's avatar. Falls back to `avatar`. */
205
+ row?(props: {
206
+ conversation: ChatConversation;
207
+ entry: ChatEntry;
208
+ }): any;
209
+ /** The panel header's action area, between the title and close. */
210
+ 'panel-actions'?(): any;
211
+ /** The whole panel row. */
212
+ item?(props: {
213
+ conversation: ChatConversation;
214
+ entry: ChatEntry;
215
+ }): any;
216
+ /** One message bubble's content. */
217
+ message?(props: {
218
+ message: ChatMessage;
219
+ conversation: ChatConversation;
220
+ }): any;
221
+ /**
222
+ * The hover row beside a message's bubble — put a `KChatMessageActions`
223
+ * here. `message-` prefixed to match `window-actions` and `panel-actions`,
224
+ * which are the two headers rather than a message.
225
+ *
226
+ * Forwarded only when you pass it, so `KChatMessage`'s own empty actions
227
+ * rendering is unchanged otherwise. Not rendered for a message that
228
+ * `noticeLabel` turned into a notice.
229
+ */
230
+ 'message-actions'?(props: {
231
+ message: ChatMessage;
232
+ conversation: ChatConversation;
233
+ }): any;
234
+ /** The window footer. */
235
+ composer?(props: {
236
+ conversation: ChatConversation;
237
+ draft: string;
238
+ send: (text: string) => void;
239
+ setDraft: (text: string) => void;
240
+ }): any;
241
+ /** Window body while the first page loads. */
242
+ loading?(props: {
243
+ conversation: ChatConversation;
244
+ }): any;
245
+ /**
246
+ * The list row shown while an older page loads. Rendered inside the
247
+ * message `<ul>`, so its root must be an `<li>`.
248
+ */
249
+ 'loading-older'?(props: {
250
+ conversation: ChatConversation;
251
+ }): any;
252
+ /** Window body when the first page failed. */
253
+ error?(props: {
254
+ conversation: ChatConversation;
255
+ error: unknown;
256
+ retry: () => void;
257
+ }): any;
258
+ /** Panel text when the filter matches nothing. */
259
+ empty?(): any;
260
+ launcher?(): any;
261
+ /**
262
+ * Replaces the rendered divider while keeping `dateLabel`'s positioning.
263
+ * Whatever you render must be an `<li>`: it is a direct child of the
264
+ * message list's `<ul>`.
265
+ */
266
+ divider?(props: {
267
+ label: string;
268
+ message: ChatMessage;
269
+ previous?: ChatMessage;
270
+ }): any;
271
+ /**
272
+ * Replaces the rendered notice while keeping `noticeLabel`'s decision.
273
+ * Whatever you render must be an `<li>`: it is a direct child of the
274
+ * message list's `<ul>`.
275
+ */
276
+ notice?(props: {
277
+ label: string;
278
+ message: ChatMessage;
279
+ }): any;
280
+ };