@40rty/ams-ui 0.3.0 → 0.3.2

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/agent.js CHANGED
@@ -27,8 +27,6 @@ import {
27
27
  FoldedRead,
28
28
  InlinePresenceRead,
29
29
  LayoutMorphSkeleton,
30
- PRESENCE_DURABLE_SLOTS,
31
- PRESENCE_FACT_LIMIT,
32
30
  PolicySourceCard,
33
31
  PresenceBriefBody,
34
32
  PresenceBriefDrawer,
@@ -57,8 +55,6 @@ import {
57
55
  policySourceForm,
58
56
  presenceClass,
59
57
  productSourceForm,
60
- readFacts,
61
- readLabel,
62
58
  registerBaselineFactForms,
63
59
  registerDefaultPresenceForms,
64
60
  registerDefaultPresenceSourceForms,
@@ -68,11 +64,17 @@ import {
68
64
  sourceCardBox,
69
65
  sourceCardClass,
70
66
  sourceCardState,
67
+ useMeasuredHeight
68
+ } from "./chunk-OKP7MC72.js";
69
+ import {
70
+ PRESENCE_DURABLE_SLOTS,
71
+ PRESENCE_FACT_LIMIT,
72
+ readFacts,
73
+ readLabel,
71
74
  useForgetFact,
72
- useMeasuredHeight,
73
75
  useVisibleFactList,
74
76
  useVisibleFacts
75
- } from "./chunk-54QPRWEG.js";
77
+ } from "./chunk-TEPH476O.js";
76
78
  import "./chunk-432XYPDT.js";
77
79
  export {
78
80
  AgentPresenceWidget,
@@ -0,0 +1,163 @@
1
+ 'use client';
2
+
3
+ // src/shell/SideDock.tsx
4
+ import * as React from "react";
5
+ import { useReducedMotion } from "framer-motion";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ var SIDE_DOCK_REVEAL_MS = 400;
8
+ var SIDE_DOCK_EASE = "cubic-bezier(0.22, 1, 0.36, 1)";
9
+ var OFFSCREEN_OVERSHOOT_PX = 40;
10
+ function SideDock({
11
+ open,
12
+ width,
13
+ top,
14
+ zIndex = 40,
15
+ onWidthChange,
16
+ onResizeStart,
17
+ onResizeEnd,
18
+ minWidth = 320,
19
+ maxWidth = 680,
20
+ children
21
+ }) {
22
+ const reduceMotion = useReducedMotion();
23
+ const dragStart = React.useRef(null);
24
+ const onHandleDown = (e) => {
25
+ if (onWidthChange === void 0 || typeof width !== "number") return;
26
+ e.preventDefault();
27
+ e.currentTarget.setPointerCapture(e.pointerId);
28
+ dragStart.current = { x: e.clientX, w: width };
29
+ if (onResizeStart !== void 0) onResizeStart();
30
+ };
31
+ const onHandleMove = (e) => {
32
+ if (dragStart.current === null || onWidthChange === void 0) return;
33
+ const delta = dragStart.current.x - e.clientX;
34
+ const next = Math.min(maxWidth, Math.max(minWidth, dragStart.current.w + delta));
35
+ onWidthChange(next);
36
+ };
37
+ const onHandleUp = (e) => {
38
+ if (dragStart.current === null) return;
39
+ e.currentTarget.releasePointerCapture(e.pointerId);
40
+ dragStart.current = null;
41
+ if (onResizeEnd !== void 0) onResizeEnd();
42
+ };
43
+ const transition = reduceMotion === true ? void 0 : `transform ${SIDE_DOCK_REVEAL_MS}ms ${SIDE_DOCK_EASE}, visibility 0s linear ${open ? "0s" : `${SIDE_DOCK_REVEAL_MS}ms`}`;
44
+ return (
45
+ // Outer frame — static, never moves, clips the sliding panel. The clip
46
+ // guarantees the closed (off-screen) panel can never create horizontal
47
+ // page overflow or become a scrollIntoView target that drags the
48
+ // document sideways — regardless of the host shell's CSS.
49
+ /* @__PURE__ */ jsx(
50
+ "div",
51
+ {
52
+ "data-fourty-shell-part": "sideDock",
53
+ style: {
54
+ position: "absolute",
55
+ top,
56
+ right: 0,
57
+ bottom: 0,
58
+ width,
59
+ zIndex,
60
+ overflow: "clip",
61
+ pointerEvents: open ? "auto" : "none"
62
+ },
63
+ children: /* @__PURE__ */ jsxs(
64
+ "div",
65
+ {
66
+ "aria-hidden": !open,
67
+ inert: !open,
68
+ style: {
69
+ position: "absolute",
70
+ inset: 0,
71
+ transform: open ? "translateX(0)" : `translateX(calc(100% + ${OFFSCREEN_OVERSHOOT_PX}px))`,
72
+ visibility: open ? "visible" : "hidden",
73
+ transition
74
+ },
75
+ children: [
76
+ onWidthChange !== void 0 && // Drag handle — a slim hit-strip pinned to the panel's inner-left
77
+ // edge. `touchAction: none` keeps a touch drag from scrolling.
78
+ /* @__PURE__ */ jsx(
79
+ "div",
80
+ {
81
+ role: "separator",
82
+ "aria-orientation": "vertical",
83
+ "aria-label": "Resize panel",
84
+ onPointerDown: onHandleDown,
85
+ onPointerMove: onHandleMove,
86
+ onPointerUp: onHandleUp,
87
+ onPointerCancel: onHandleUp,
88
+ style: {
89
+ position: "absolute",
90
+ top: 0,
91
+ bottom: 0,
92
+ left: 0,
93
+ width: 10,
94
+ transform: "translateX(-50%)",
95
+ cursor: "col-resize",
96
+ touchAction: "none",
97
+ zIndex: 2
98
+ }
99
+ }
100
+ ),
101
+ children
102
+ ]
103
+ }
104
+ )
105
+ }
106
+ )
107
+ );
108
+ }
109
+ function useSideDockSpacing(open, width, animate = true) {
110
+ const reduceMotion = useReducedMotion();
111
+ return {
112
+ paddingRight: open ? width : 0,
113
+ // During an active resize drag the host passes `animate: false` so the
114
+ // canvas edge tracks the panel 1:1 instead of easing behind the pointer.
115
+ transition: reduceMotion === true || !animate ? void 0 : `padding-right ${SIDE_DOCK_REVEAL_MS}ms ${SIDE_DOCK_EASE}`
116
+ };
117
+ }
118
+
119
+ // src/shell/use-dock-state.ts
120
+ import React2 from "react";
121
+ import { useAgentDriven, useDockPersistence, useHasLeftSeedHome, useHydrated, useOverridableToggle, useSessionId, useSessionMessages } from "@40rty/ams-sdk";
122
+ function useDockState(reopenOnMessage, autoOpen) {
123
+ const { initialOpen, onOpenChange } = useDockPersistence();
124
+ const messages = useSessionMessages();
125
+ const sessionId = useSessionId();
126
+ const hasLeftHome = useHasLeftSeedHome();
127
+ const agentDriven = useAgentDriven();
128
+ const settled = sessionId !== null;
129
+ const settledRef = React2.useRef(false);
130
+ const engagedWhenSettledRef = React2.useRef(false);
131
+ const hasEngagedRef = React2.useRef(initialOpen === true);
132
+ const historyIsAccountedFor = initialOpen !== null;
133
+ const engagementIsNew = historyIsAccountedFor ? settledRef.current && !engagedWhenSettledRef.current : true;
134
+ if (hasLeftHome && engagementIsNew && !agentDriven) hasEngagedRef.current = true;
135
+ const hydrated = useHydrated();
136
+ const openDefault = agentDriven || !autoOpen ? false : hydrated ? hasEngagedRef.current : initialOpen === true;
137
+ const toggle = useOverridableToggle(openDefault);
138
+ const userTurns = messages.reduce((n, m) => m.role === "user" ? n + 1 : n, 0);
139
+ const prevUserTurns = React2.useRef(userTurns);
140
+ React2.useEffect(() => {
141
+ if (!settledRef.current) {
142
+ if (!settled) return;
143
+ settledRef.current = true;
144
+ engagedWhenSettledRef.current = hasLeftHome;
145
+ prevUserTurns.current = userTurns;
146
+ return;
147
+ }
148
+ if (reopenOnMessage && autoOpen && !agentDriven && userTurns > prevUserTurns.current) toggle.set(true);
149
+ prevUserTurns.current = userTurns;
150
+ }, [userTurns, settled, hasLeftHome, reopenOnMessage, autoOpen, agentDriven, toggle.set]);
151
+ React2.useEffect(() => {
152
+ onOpenChange(toggle.value);
153
+ }, [toggle.value, onOpenChange]);
154
+ return { open: toggle.value, toggle: toggle.toggle };
155
+ }
156
+
157
+ export {
158
+ SIDE_DOCK_REVEAL_MS,
159
+ SIDE_DOCK_EASE,
160
+ SideDock,
161
+ useSideDockSpacing,
162
+ useDockState
163
+ };