@dxos/react-ui-attention 0.16.0 → 0.17.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/lib/chunk-ViewStateProvider.mjs +1 -1
- package/dist/lib/chunk-types.mjs +240 -9
- package/dist/lib/chunk-types.mjs.map +1 -1
- package/dist/lib/index.mjs +242 -56
- package/dist/lib/index.mjs.map +1 -1
- package/dist/lib/testing.mjs +1 -1
- package/dist/lib/types.mjs +1 -1
- package/dist/types/src/components/AttentionGlyph/AttentionGlyph.d.ts +6 -11
- package/dist/types/src/components/AttentionGlyph/AttentionGlyph.d.ts.map +1 -1
- package/dist/types/src/components/AttentionGlyph/AttentionGlyph.stories.d.ts +13 -6
- package/dist/types/src/components/AttentionGlyph/AttentionGlyph.stories.d.ts.map +1 -1
- package/dist/types/src/components/RemoteCursor/RemoteCursor.d.ts +18 -0
- package/dist/types/src/components/RemoteCursor/RemoteCursor.d.ts.map +1 -0
- package/dist/types/src/components/RemoteCursor/RemoteCursorLayer.d.ts +32 -0
- package/dist/types/src/components/RemoteCursor/RemoteCursorLayer.d.ts.map +1 -0
- package/dist/types/src/components/RemoteCursor/RemoteCursorLayer.test.d.ts +2 -0
- package/dist/types/src/components/RemoteCursor/RemoteCursorLayer.test.d.ts.map +1 -0
- package/dist/types/src/components/RemoteCursor/index.d.ts +3 -0
- package/dist/types/src/components/RemoteCursor/index.d.ts.map +1 -0
- package/dist/types/src/components/ScrollScope/ScrollScope.d.ts +11 -0
- package/dist/types/src/components/ScrollScope/ScrollScope.d.ts.map +1 -0
- package/dist/types/src/components/ScrollScope/ScrollScope.stories.d.ts +15 -0
- package/dist/types/src/components/ScrollScope/ScrollScope.stories.d.ts.map +1 -0
- package/dist/types/src/components/ScrollScope/index.d.ts +2 -0
- package/dist/types/src/components/ScrollScope/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +2 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/types/Activity.d.ts +71 -0
- package/dist/types/src/types/Activity.d.ts.map +1 -0
- package/dist/types/src/types/Activity.test.d.ts +2 -0
- package/dist/types/src/types/Activity.test.d.ts.map +1 -0
- package/dist/types/src/types/ScrollPosition.d.ts +24 -0
- package/dist/types/src/types/ScrollPosition.d.ts.map +1 -0
- package/dist/types/src/types/ViewLocation.d.ts +16 -0
- package/dist/types/src/types/ViewLocation.d.ts.map +1 -0
- package/dist/types/src/types/ViewState.d.ts +44 -2
- package/dist/types/src/types/ViewState.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +3 -0
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -16
- package/src/components/AttentionGlyph/AttentionGlyph.stories.tsx +424 -31
- package/src/components/AttentionGlyph/AttentionGlyph.tsx +80 -56
- package/src/components/RemoteCursor/RemoteCursor.tsx +55 -0
- package/src/components/RemoteCursor/RemoteCursorLayer.test.tsx +98 -0
- package/src/components/RemoteCursor/RemoteCursorLayer.tsx +97 -0
- package/src/components/RemoteCursor/index.ts +6 -0
- package/src/components/ScrollScope/ScrollScope.stories.tsx +97 -0
- package/src/components/ScrollScope/ScrollScope.tsx +59 -0
- package/src/components/ScrollScope/index.ts +5 -0
- package/src/components/index.ts +2 -0
- package/src/types/Activity.test.ts +53 -0
- package/src/types/Activity.ts +110 -0
- package/src/types/ScrollPosition.ts +34 -0
- package/src/types/ViewLocation.ts +28 -0
- package/src/types/ViewState.test.ts +74 -1
- package/src/types/ViewState.ts +217 -4
- package/src/types/index.ts +3 -0
package/dist/lib/index.mjs
CHANGED
|
@@ -1,69 +1,255 @@
|
|
|
1
|
-
import { f as Attention_exports, i as
|
|
1
|
+
import { _ as Activity_exports, a as Selection_exports, f as ViewState_exports, h as Attention_exports, i as ViewLocation_exports, l as ScrollPosition_exports, n as MemoryBackend, r as createDefaultBackends, t as LocalBackend, u as aspect, v as resolve } from "./chunk-types.mjs";
|
|
2
2
|
import { a as useSelectionActions, c as AttendableContainer, d as useAttention, f as useAttentionAttributes, i as useSelection, l as RootAttentionProvider, n as useManager, o as useViewState, p as useAttentionContext, r as useManagerOptional, s as useViewStateActions, t as ViewStateProvider, u as useAttended } from "./chunk-ViewStateProvider.mjs";
|
|
3
|
-
import { forwardRef, useMemo } from "react";
|
|
4
|
-
import
|
|
3
|
+
import { forwardRef, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { useIconHref } from "@dxos/react-ui/Icon";
|
|
5
5
|
import { mx } from "@dxos/ui-theme";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import * as ScrollArea from "@dxos/react-ui/ScrollArea";
|
|
7
8
|
import { useHotkeys } from "@dxos/react-focus";
|
|
8
9
|
//#region src/components/AttentionGlyph/AttentionGlyph.tsx
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var PresenceMany = () => /* @__PURE__ */ jsxs("svg", {
|
|
24
|
-
viewBox: "0 0 12 12",
|
|
25
|
-
fill: "none",
|
|
26
|
-
"aria-hidden": true,
|
|
27
|
-
"data-scope": "attention-glyph",
|
|
28
|
-
"data-part": "mark",
|
|
29
|
-
className: "dx-attention-glyph-mark",
|
|
30
|
-
children: [/* @__PURE__ */ jsx("path", {
|
|
31
|
-
d: "M6.75 8.27311C7.38815 7.72296 7.79212 6.90866 7.79212 6C7.79212 5.09134 7.38815 4.27704 6.75 3.72689C7.06722 3.58122 7.42019 3.5 7.79212 3.5C9.17283 3.5 10.2921 4.61929 10.2921 6C10.2921 7.38071 9.17283 8.5 7.79212 8.5C7.42019 8.5 7.06723 8.41878 6.75 8.27311Z",
|
|
32
|
-
fill: "currentColor"
|
|
33
|
-
}), /* @__PURE__ */ jsx("circle", {
|
|
34
|
-
cx: "4.25",
|
|
35
|
-
cy: "6",
|
|
36
|
-
r: "2.5",
|
|
37
|
-
fill: "currentColor"
|
|
38
|
-
})]
|
|
39
|
-
});
|
|
40
|
-
/** Every spinner on the page shares one phase, so a list of syncing items turns together rather than flickering. */
|
|
41
|
-
var Syncing = () => {
|
|
42
|
-
const style = useMemo(() => ({ animationDelay: `-${Date.now() % 2e3}ms` }), []);
|
|
43
|
-
return /* @__PURE__ */ jsx(Icon.Icon, {
|
|
44
|
-
icon: "ph--circle-notch--bold",
|
|
45
|
-
"data-spin": "",
|
|
46
|
-
style
|
|
10
|
+
var VIEWERS_PATH = "M6.75 8.27311C7.38815 7.72296 7.79212 6.90866 7.79212 6C7.79212 5.09134 7.38815 4.27704 6.75 3.72689C7.06722 3.58122 7.42019 3.5 7.79212 3.5C9.17283 3.5 10.2921 4.61929 10.2921 6C10.2921 7.38071 9.17283 8.5 7.79212 8.5C7.42019 8.5 7.06723 8.41878 6.75 8.27311Z";
|
|
11
|
+
var STAR_PATH = "M6 2.2l1 2.8 2.8 1-2.8 1-1 2.8-1-2.8-2.8-1 2.8-1z";
|
|
12
|
+
var DEFAULT_FILL_OPACITY = .25;
|
|
13
|
+
/** A hue's saturated fill shade, which reads on both themes at the glyph's size. */
|
|
14
|
+
var solid = (hue) => `var(--color-${hue}-bg)`;
|
|
15
|
+
var IconMark = ({ icon }) => {
|
|
16
|
+
const href = useIconHref(icon);
|
|
17
|
+
return /* @__PURE__ */ jsx("use", {
|
|
18
|
+
"data-part": "mark",
|
|
19
|
+
href,
|
|
20
|
+
x: "2",
|
|
21
|
+
y: "2",
|
|
22
|
+
width: "8",
|
|
23
|
+
height: "8"
|
|
47
24
|
});
|
|
48
25
|
};
|
|
26
|
+
var Mark = ({ icon }) => {
|
|
27
|
+
switch (icon) {
|
|
28
|
+
case "dot": return /* @__PURE__ */ jsx("circle", {
|
|
29
|
+
"data-part": "mark",
|
|
30
|
+
cx: "6",
|
|
31
|
+
cy: "6",
|
|
32
|
+
r: "2.5"
|
|
33
|
+
});
|
|
34
|
+
case "dots": return /* @__PURE__ */ jsxs("g", {
|
|
35
|
+
"data-part": "mark",
|
|
36
|
+
children: [/* @__PURE__ */ jsx("path", { d: VIEWERS_PATH }), /* @__PURE__ */ jsx("circle", {
|
|
37
|
+
cx: "4.25",
|
|
38
|
+
cy: "6",
|
|
39
|
+
r: "2.5"
|
|
40
|
+
})]
|
|
41
|
+
});
|
|
42
|
+
case "star": return /* @__PURE__ */ jsx("path", {
|
|
43
|
+
"data-part": "mark",
|
|
44
|
+
d: STAR_PATH
|
|
45
|
+
});
|
|
46
|
+
default: return /* @__PURE__ */ jsx(IconMark, { icon });
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
49
|
/**
|
|
50
|
-
* A small square marking an item's attention state
|
|
51
|
-
* else is viewing it or whether it is syncing. The state is the glyph's own attributes, so it needs no host markup.
|
|
50
|
+
* A small square marking an item's attention state and the activity on it, one treatment per slot (see `Activity.Slot`).
|
|
52
51
|
*/
|
|
53
|
-
var AttentionGlyph = forwardRef(({ classNames, attended, containsAttended,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
var AttentionGlyph = forwardRef(({ classNames, style, attended, containsAttended, treatments, ...props }, forwardedRef) => {
|
|
53
|
+
const { fill, mark, edge, corner, moving } = useMemo(() => resolve(treatments ?? [], { attention: attended || containsAttended }), [
|
|
54
|
+
attended,
|
|
55
|
+
containsAttended,
|
|
56
|
+
treatments
|
|
57
|
+
]);
|
|
58
|
+
const colors = useMemo(() => ({
|
|
59
|
+
...fill && {
|
|
60
|
+
"--dx-attention-glyph-fill-hue": solid(fill.hue),
|
|
61
|
+
"--dx-attention-glyph-fill-opacity": `${(fill.opacity ?? DEFAULT_FILL_OPACITY) * 100}%`
|
|
62
|
+
},
|
|
63
|
+
...mark && { "--dx-attention-glyph-mark": mark.hue ? solid(mark.hue) : "var(--color-fg)" },
|
|
64
|
+
...edge && { "--dx-attention-glyph-edge": solid(edge.hue) },
|
|
65
|
+
...corner && { "--dx-attention-glyph-corner": solid(corner.hue) }
|
|
66
|
+
}), [
|
|
67
|
+
fill,
|
|
68
|
+
mark,
|
|
69
|
+
edge,
|
|
70
|
+
corner
|
|
71
|
+
]);
|
|
72
|
+
return /* @__PURE__ */ jsx("span", {
|
|
73
|
+
...props,
|
|
74
|
+
style: {
|
|
75
|
+
...colors,
|
|
76
|
+
...style
|
|
77
|
+
},
|
|
78
|
+
"data-scope": "attention-glyph",
|
|
79
|
+
"data-part": "root",
|
|
80
|
+
"data-fill": attended ? "attended" : containsAttended ? "contains-attended" : fill && "hue",
|
|
81
|
+
"data-fill-hue": fill?.hue,
|
|
82
|
+
"data-mark": mark?.icon,
|
|
83
|
+
"data-mark-hue": mark?.hue,
|
|
84
|
+
"data-edge": edge && (edge.dashed ? "dashed" : "solid"),
|
|
85
|
+
"data-edge-hue": edge?.hue,
|
|
86
|
+
"data-corner": corner && (corner.shape ?? "dot"),
|
|
87
|
+
"data-corner-hue": corner?.hue,
|
|
88
|
+
"data-moving": moving,
|
|
89
|
+
className: mx("dx-attention-glyph", classNames),
|
|
90
|
+
ref: forwardedRef,
|
|
91
|
+
children: (mark || edge || corner) && /* @__PURE__ */ jsxs("svg", {
|
|
92
|
+
viewBox: "0 0 12 12",
|
|
93
|
+
fill: "none",
|
|
94
|
+
"aria-hidden": true,
|
|
95
|
+
"data-scope": "attention-glyph",
|
|
96
|
+
"data-part": "overlay",
|
|
97
|
+
children: [
|
|
98
|
+
edge && /* @__PURE__ */ jsx("rect", {
|
|
99
|
+
"data-part": "edge",
|
|
100
|
+
x: "0.5",
|
|
101
|
+
y: "0.5",
|
|
102
|
+
width: "11",
|
|
103
|
+
height: "11",
|
|
104
|
+
rx: "1.75",
|
|
105
|
+
pathLength: "48"
|
|
106
|
+
}),
|
|
107
|
+
mark && /* @__PURE__ */ jsx(Mark, { icon: mark.icon }),
|
|
108
|
+
corner && /* @__PURE__ */ jsx("circle", {
|
|
109
|
+
"data-part": "corner",
|
|
110
|
+
cx: "12.25",
|
|
111
|
+
cy: "-0.25",
|
|
112
|
+
r: corner.shape === "ring" ? 2 : 2.5
|
|
113
|
+
})
|
|
114
|
+
]
|
|
115
|
+
})
|
|
116
|
+
});
|
|
117
|
+
});
|
|
65
118
|
AttentionGlyph.displayName = "AttentionGlyph";
|
|
66
119
|
//#endregion
|
|
120
|
+
//#region src/components/RemoteCursor/RemoteCursor.tsx
|
|
121
|
+
var safeHue = (hue) => /^[a-z]+$/.test(hue) ? hue : "neutral";
|
|
122
|
+
/**
|
|
123
|
+
* Another collaborator's pointer: an arrow and a name tag in their member hue.
|
|
124
|
+
*/
|
|
125
|
+
var RemoteCursor = ({ classNames, name, hue, x, y, zoom = 1 }) => {
|
|
126
|
+
const color = safeHue(hue);
|
|
127
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
128
|
+
role: "none",
|
|
129
|
+
className: mx("absolute top-0 left-0 pointer-events-none origin-top-left", classNames),
|
|
130
|
+
style: { transform: `translate(${x}px, ${y}px) scale(${1 / zoom})` },
|
|
131
|
+
"data-testid": "remote-cursor",
|
|
132
|
+
"data-hue": color,
|
|
133
|
+
children: [/* @__PURE__ */ jsx("svg", {
|
|
134
|
+
width: "16",
|
|
135
|
+
height: "16",
|
|
136
|
+
viewBox: "0 0 16 16",
|
|
137
|
+
"aria-hidden": true,
|
|
138
|
+
className: "block drop-shadow-sm",
|
|
139
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
140
|
+
d: "M1 1 L1 13 L4.5 9.75 L7 15 L9 14 L6.75 8.75 L11.5 8.5 Z",
|
|
141
|
+
style: { fill: `var(--color-${color}-bg)` },
|
|
142
|
+
stroke: "white",
|
|
143
|
+
strokeWidth: "1",
|
|
144
|
+
strokeLinejoin: "round"
|
|
145
|
+
})
|
|
146
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
147
|
+
className: "absolute top-[14px] left-[10px] px-1.5 py-0.5 rounded-sm text-xs leading-none whitespace-nowrap shadow-sm",
|
|
148
|
+
style: {
|
|
149
|
+
backgroundColor: `var(--color-${color}-surface)`,
|
|
150
|
+
color: `var(--color-${color}-fg)`
|
|
151
|
+
},
|
|
152
|
+
children: name
|
|
153
|
+
})]
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/components/RemoteCursor/RemoteCursorLayer.tsx
|
|
158
|
+
/**
|
|
159
|
+
* Collaborators' pointers over any surface, and the local one reported back. Renders as a cover over its parent,
|
|
160
|
+
* which must be positioned and contain the surface; the parent's pointer events are what it tracks.
|
|
161
|
+
*/
|
|
162
|
+
var RemoteCursorLayer = ({ cursors, projection, onPointerChange }) => {
|
|
163
|
+
const [layer, setLayer] = useState(null);
|
|
164
|
+
const latest = useRef({
|
|
165
|
+
projection,
|
|
166
|
+
onPointerChange
|
|
167
|
+
});
|
|
168
|
+
latest.current = {
|
|
169
|
+
projection,
|
|
170
|
+
onPointerChange
|
|
171
|
+
};
|
|
172
|
+
const pointer = useRef(void 0);
|
|
173
|
+
const [, setLayout] = useState(0);
|
|
174
|
+
useLayoutEffect(() => setLayout((layout) => layout + 1), [projection]);
|
|
175
|
+
useEffect(() => {
|
|
176
|
+
const point = layer && pointer.current && projection.fromLayer(pointer.current, layer);
|
|
177
|
+
if (point) latest.current.onPointerChange?.(point);
|
|
178
|
+
}, [layer, projection]);
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
const root = layer?.parentElement;
|
|
181
|
+
if (!layer || !root) return;
|
|
182
|
+
const handleMove = (event) => {
|
|
183
|
+
const rect = layer.getBoundingClientRect();
|
|
184
|
+
pointer.current = {
|
|
185
|
+
x: event.clientX - rect.left,
|
|
186
|
+
y: event.clientY - rect.top
|
|
187
|
+
};
|
|
188
|
+
const point = latest.current.projection.fromLayer(pointer.current, layer);
|
|
189
|
+
if (point) latest.current.onPointerChange?.(point);
|
|
190
|
+
};
|
|
191
|
+
const handleLeave = () => {
|
|
192
|
+
pointer.current = void 0;
|
|
193
|
+
latest.current.onPointerChange?.(void 0);
|
|
194
|
+
};
|
|
195
|
+
const observer = new ResizeObserver(() => setLayout((layout) => layout + 1));
|
|
196
|
+
root.addEventListener("pointermove", handleMove, { passive: true });
|
|
197
|
+
root.addEventListener("pointerleave", handleLeave);
|
|
198
|
+
observer.observe(root);
|
|
199
|
+
return () => {
|
|
200
|
+
root.removeEventListener("pointermove", handleMove);
|
|
201
|
+
root.removeEventListener("pointerleave", handleLeave);
|
|
202
|
+
observer.disconnect();
|
|
203
|
+
handleLeave();
|
|
204
|
+
};
|
|
205
|
+
}, [layer]);
|
|
206
|
+
return /* @__PURE__ */ jsx("div", {
|
|
207
|
+
ref: setLayer,
|
|
208
|
+
role: "none",
|
|
209
|
+
className: "dx-cover overflow-hidden pointer-events-none",
|
|
210
|
+
children: layer && cursors.map((cursor) => {
|
|
211
|
+
const point = projection.toLayer(cursor, layer);
|
|
212
|
+
return point ? /* @__PURE__ */ jsx(RemoteCursor, {
|
|
213
|
+
name: cursor.name,
|
|
214
|
+
hue: cursor.hue,
|
|
215
|
+
x: point.x,
|
|
216
|
+
y: point.y
|
|
217
|
+
}, cursor.id) : null;
|
|
218
|
+
})
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/components/ScrollScope/ScrollScope.tsx
|
|
223
|
+
/**
|
|
224
|
+
* Keeps the scroll of an object's view as its `ScrollPosition` view state: the outermost `ScrollArea` inside reports
|
|
225
|
+
* where it is, and it is restored when it mounts and when a follow writes the leader's position.
|
|
226
|
+
*/
|
|
227
|
+
var ScrollScope = ({ contextId, children }) => {
|
|
228
|
+
const manager = useManagerOptional();
|
|
229
|
+
const tracking = useRef(null);
|
|
230
|
+
useEffect(() => {
|
|
231
|
+
if (!manager || !contextId) return;
|
|
232
|
+
let previous = manager.get(aspect, contextId);
|
|
233
|
+
return manager.subscribe(aspect, contextId, (state, origin) => {
|
|
234
|
+
const changed = Object.entries(state).filter(([name, position]) => JSON.stringify(position) !== JSON.stringify(previous[name]));
|
|
235
|
+
previous = state;
|
|
236
|
+
if (origin === "follow") changed.forEach(([name, position]) => tracking.current?.restore(name, position));
|
|
237
|
+
});
|
|
238
|
+
}, [manager, contextId]);
|
|
239
|
+
const options = useMemo(() => manager && contextId ? {
|
|
240
|
+
initial: (name) => manager.get(aspect, contextId)[name],
|
|
241
|
+
onScroll: (name, position) => manager.update(aspect, contextId, (state) => ({
|
|
242
|
+
...state,
|
|
243
|
+
[name]: position
|
|
244
|
+
}))
|
|
245
|
+
} : {}, [manager, contextId]);
|
|
246
|
+
return /* @__PURE__ */ jsx(ScrollArea.Tracking, {
|
|
247
|
+
ref: tracking,
|
|
248
|
+
...options,
|
|
249
|
+
children
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
//#endregion
|
|
67
253
|
//#region src/hooks/useArticleKeyboardNavigation.ts
|
|
68
254
|
/**
|
|
69
255
|
* Compute the id to select after pressing 'j' (delta = 1) or 'k' (delta = -1).
|
|
@@ -115,6 +301,6 @@ var useArticleKeyboardNavigation = ({ articleId, items, currentId, getId, onSele
|
|
|
115
301
|
});
|
|
116
302
|
};
|
|
117
303
|
//#endregion
|
|
118
|
-
export { AttendableContainer, Attention_exports as Attention, AttentionGlyph, LocalBackend, MemoryBackend, RootAttentionProvider, Selection_exports as Selection, ViewState_exports as ViewState, ViewStateProvider, advance, createDefaultBackends, useArticleKeyboardNavigation, useAttended, useAttention, useAttentionAttributes, useAttentionContext, useManager, useManagerOptional, useSelection, useSelectionActions, useViewState, useViewStateActions };
|
|
304
|
+
export { Activity_exports as Activity, AttendableContainer, Attention_exports as Attention, AttentionGlyph, LocalBackend, MemoryBackend, RemoteCursor, RemoteCursorLayer, RootAttentionProvider, ScrollPosition_exports as ScrollPosition, ScrollScope, Selection_exports as Selection, ViewLocation_exports as ViewLocation, ViewState_exports as ViewState, ViewStateProvider, advance, createDefaultBackends, useArticleKeyboardNavigation, useAttended, useAttention, useAttentionAttributes, useAttentionContext, useManager, useManagerOptional, useSelection, useSelectionActions, useViewState, useViewStateActions };
|
|
119
305
|
|
|
120
306
|
//# sourceMappingURL=index.mjs.map
|
package/dist/lib/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/components/AttentionGlyph/AttentionGlyph.tsx","../../src/hooks/useArticleKeyboardNavigation.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport React, { type ComponentPropsWithoutRef, type CSSProperties, forwardRef, useMemo } from 'react';\n\nimport * as Icon from '@dxos/react-ui/Icon';\nimport { mx } from '@dxos/ui-theme';\nimport { type ThemedClassName } from '@dxos/ui-types';\n\nexport type AttentionGlyphPresence = 'none' | 'one' | 'many';\n\nexport type AttentionGlyphProps = ThemedClassName<Omit<ComponentPropsWithoutRef<'span'>, 'children'>> & {\n /** The item is the attended one: the glyph fills with the accent. */\n attended?: boolean;\n /** The attended item is inside this one: the glyph takes the softer contains tint. */\n containsAttended?: boolean;\n /** Shows a spinner in place of the presence mark. */\n syncing?: boolean;\n /** How many others are viewing the item. */\n presence?: AttentionGlyphPresence;\n};\n\nconst PresenceOne = () => (\n <svg\n viewBox='0 0 12 12'\n fill='none'\n aria-hidden\n data-scope='attention-glyph'\n data-part='mark'\n className={'dx-attention-glyph-mark'}\n >\n <circle cx='6' cy='6' r='2.5' fill='currentColor' />\n </svg>\n);\n\nconst PresenceMany = () => (\n <svg\n viewBox='0 0 12 12'\n fill='none'\n aria-hidden\n data-scope='attention-glyph'\n data-part='mark'\n className={'dx-attention-glyph-mark'}\n >\n <path\n d='M6.75 8.27311C7.38815 7.72296 7.79212 6.90866 7.79212 6C7.79212 5.09134 7.38815 4.27704 6.75 3.72689C7.06722 3.58122 7.42019 3.5 7.79212 3.5C9.17283 3.5 10.2921 4.61929 10.2921 6C10.2921 7.38071 9.17283 8.5 7.79212 8.5C7.42019 8.5 7.06723 8.41878 6.75 8.27311Z'\n fill='currentColor'\n />\n <circle cx='4.25' cy='6' r='2.5' fill='currentColor' />\n </svg>\n);\n\n/** Every spinner on the page shares one phase, so a list of syncing items turns together rather than flickering. */\nconst Syncing = () => {\n const style = useMemo<CSSProperties>(() => ({ animationDelay: `-${Date.now() % 2_000}ms` }), []);\n return <Icon.Icon icon='ph--circle-notch--bold' data-spin='' style={style} />;\n};\n\n/**\n * A small square marking an item's attention state (attended, or containing the attended item) and, inside it, who\n * else is viewing it or whether it is syncing. The state is the glyph's own attributes, so it needs no host markup.\n */\nexport const AttentionGlyph = forwardRef<HTMLSpanElement, AttentionGlyphProps>(\n ({ classNames, attended, containsAttended, syncing, presence = 'none', ...props }, forwardedRef) => (\n <span\n {...props}\n data-scope='attention-glyph'\n data-part='root'\n data-attended={attended ? '' : undefined}\n data-contains-attended={containsAttended ? '' : undefined}\n data-syncing={syncing ? '' : undefined}\n data-presence={presence}\n className={mx('dx-attention-glyph', classNames)}\n ref={forwardedRef}\n >\n {syncing ? <Syncing /> : presence === 'many' ? <PresenceMany /> : presence === 'one' ? <PresenceOne /> : null}\n </span>\n ),\n);\n\nAttentionGlyph.displayName = 'AttentionGlyph';\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { useHotkeys } from '@dxos/react-focus';\n\nimport { useAttention } from '../components/index.ts';\n\n/**\n * Compute the id to select after pressing 'j' (delta = 1) or 'k' (delta = -1).\n * Clamps at the list ends — pressing 'j' on the last item keeps the last item\n * selected (vim-style), and 'k' on the first item keeps the first.\n *\n * When no current selection exists, returns the first id (for delta = 1) or the\n * last id (for delta = -1) so the user can enter the list with either key.\n */\nexport const advance = ({\n ids,\n currentId,\n delta,\n}: {\n ids: readonly string[];\n currentId: string | undefined;\n delta: 1 | -1;\n}): string | undefined => {\n if (ids.length === 0) {\n return undefined;\n }\n\n const idx = currentId ? ids.indexOf(currentId) : -1;\n if (idx === -1) {\n return delta === 1 ? ids[0] : ids[ids.length - 1];\n }\n\n const next = Math.max(0, Math.min(ids.length - 1, idx + delta));\n return ids[next];\n};\n\nexport type UseArticleKeyboardNavigationOptions<T> = {\n /** Stable id for the article; also the hotkey command id. */\n articleId: string;\n /** Ordered list of selectable items as they appear in the article. */\n items: readonly T[];\n /** Currently-selected id, if any. */\n currentId: string | undefined;\n /** Extracts the id from an item. Defaults to `item.id`. */\n getId?: (item: T) => string;\n /** Called with the id to select when the user presses 'j' or 'k'. */\n onSelect: (id: string) => void;\n};\n\n/**\n * Wire 'j' (next) and 'k' (previous) for an article that navigates a list of items (e.g. messages,\n * events). This moves the *selection*, never focus, and it is gated on the article having\n * attention — so it is a hotkey rather than a focus group, and the gate is `enabled` rather than a\n * scope, since attention is already React state here.\n *\n * Pass the items directly; ids are derived via `getId` (defaults to `item.id`).\n * Clamps at list boundaries.\n */\nexport const useArticleKeyboardNavigation: {\n <T extends { id: string }>(options: UseArticleKeyboardNavigationOptions<T>): void;\n <T>(options: UseArticleKeyboardNavigationOptions<T> & { getId: (item: T) => string }): void;\n} = <T>({ articleId, items, currentId, getId, onSelect }: UseArticleKeyboardNavigationOptions<T>): void => {\n const { hasAttention } = useAttention(articleId);\n\n // `getId` is optional only when `T extends { id: string }` (enforced by the overloads above),\n // so the fallback is sound; the cast bridges the generic erased by the implementation signature.\n const ids = useMemo(() => items.map((item) => (getId ? getId(item) : (item as { id: string }).id)), [items, getId]);\n\n const move = (delta: 1 | -1) => {\n const target = advance({ ids, currentId, delta });\n if (target !== undefined) {\n onSelect(target);\n }\n };\n\n useHotkeys({\n id: articleId,\n commands: [\n { hotkey: 'j', label: 'Next item', enabled: () => hasAttention, action: () => move(1) },\n { hotkey: 'k', label: 'Previous item', enabled: () => hasAttention, action: () => move(-1) },\n ],\n });\n};\n"],"mappings":";;;;;;;;AAuBA,IAAM,oBACJ,oBAAC,OAAD;CACE,SAAQ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,IACV,OAAO,UAAU,IAAI,IAAI,KAAK,IAAI,IAAI,SAAS;CAIjD,OAAO,IADM,KAAK,IAAI,GAAG,KAAK,IAAI,IAAI,SAAS,GAAG,MAAM,KAAK,CAClD;AACb;;;;;;;;;;AAwBA,IAAa,gCAGL,EAAE,WAAW,OAAO,WAAW,OAAO,eAA6D;CACzG,MAAM,EAAE,iBAAiB,aAAa,SAAS;CAI/C,MAAM,MAAM,cAAc,MAAM,KAAK,SAAU,QAAQ,MAAM,IAAI,IAAK,KAAwB,EAAG,GAAG,CAAC,OAAO,KAAK,CAAC;CAElH,MAAM,QAAQ,UAAkB;EAC9B,MAAM,SAAS,QAAQ;GAAE;GAAK;GAAW;EAAM,CAAC;EAChD,IAAI,WAAW,KAAA,GACb,SAAS,MAAM;CAEnB;CAEA,WAAW;EACT,IAAI;EACJ,UAAU,CACR;GAAE,QAAQ;GAAK,OAAO;GAAa,eAAe;GAAc,cAAc,KAAK,CAAC;EAAE,GACtF;GAAE,QAAQ;GAAK,OAAO;GAAiB,eAAe;GAAc,cAAc,KAAK,EAAE;EAAE,CAC7F;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["Activity.resolve","ScrollPosition.aspect"],"sources":["../../src/components/AttentionGlyph/AttentionGlyph.tsx","../../src/components/RemoteCursor/RemoteCursor.tsx","../../src/components/RemoteCursor/RemoteCursorLayer.tsx","../../src/components/ScrollScope/ScrollScope.tsx","../../src/hooks/useArticleKeyboardNavigation.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport React, { type ComponentPropsWithoutRef, type CSSProperties, forwardRef, useMemo } from 'react';\n\nimport { useIconHref } from '@dxos/react-ui/Icon';\nimport { mx } from '@dxos/ui-theme';\nimport { type Hue, type ThemedClassName } from '@dxos/ui-types';\n\nimport * as Activity from '../../types/Activity.ts';\n\nexport type AttentionGlyphProps = ThemedClassName<Omit<ComponentPropsWithoutRef<'span'>, 'children'>> & {\n /** The item is the attended one: the glyph fills with the accent. */\n attended?: boolean;\n /** The attended item is inside this one: the glyph takes the softer contains tint. */\n containsAttended?: boolean;\n /** Activity on the item; the glyph draws one treatment per slot and animates at most one (see `Activity.resolve`). */\n treatments?: readonly Activity.Treatment[];\n};\n\nconst VIEWERS_PATH =\n 'M6.75 8.27311C7.38815 7.72296 7.79212 6.90866 7.79212 6C7.79212 5.09134 7.38815 4.27704 6.75 3.72689C7.06722 3.58122 7.42019 3.5 7.79212 3.5C9.17283 3.5 10.2921 4.61929 10.2921 6C10.2921 7.38071 9.17283 8.5 7.79212 8.5C7.42019 8.5 7.06723 8.41878 6.75 8.27311Z';\nconst STAR_PATH = 'M6 2.2l1 2.8 2.8 1-2.8 1-1 2.8-1-2.8-2.8-1 2.8-1z';\n\nconst DEFAULT_FILL_OPACITY = 0.25;\n\n/** A hue's saturated fill shade, which reads on both themes at the glyph's size. */\nconst solid = (hue: Hue) => `var(--color-${hue}-bg)`;\n\nconst IconMark = ({ icon }: { icon: string }) => {\n const href = useIconHref(icon);\n return <use data-part='mark' href={href} x='2' y='2' width='8' height='8' />;\n};\n\nconst Mark = ({ icon }: { icon: string }) => {\n switch (icon) {\n case 'dot':\n return <circle data-part='mark' cx='6' cy='6' r='2.5' />;\n case 'dots':\n return (\n <g data-part='mark'>\n <path d={VIEWERS_PATH} />\n <circle cx='4.25' cy='6' r='2.5' />\n </g>\n );\n case 'star':\n return <path data-part='mark' d={STAR_PATH} />;\n default:\n return <IconMark icon={icon} />;\n }\n};\n\n/**\n * A small square marking an item's attention state and the activity on it, one treatment per slot (see `Activity.Slot`).\n */\nexport const AttentionGlyph = forwardRef<HTMLSpanElement, AttentionGlyphProps>(\n ({ classNames, style, attended, containsAttended, treatments, ...props }, forwardedRef) => {\n const { fill, mark, edge, corner, moving } = useMemo(\n () => Activity.resolve(treatments ?? [], { attention: attended || containsAttended }),\n [attended, containsAttended, treatments],\n );\n const colors = useMemo(\n (): CSSProperties & Record<`--${string}`, string> => ({\n ...(fill && {\n '--dx-attention-glyph-fill-hue': solid(fill.hue),\n '--dx-attention-glyph-fill-opacity': `${(fill.opacity ?? DEFAULT_FILL_OPACITY) * 100}%`,\n }),\n ...(mark && { '--dx-attention-glyph-mark': mark.hue ? solid(mark.hue) : 'var(--color-fg)' }),\n ...(edge && { '--dx-attention-glyph-edge': solid(edge.hue) }),\n ...(corner && { '--dx-attention-glyph-corner': solid(corner.hue) }),\n }),\n [fill, mark, edge, corner],\n );\n\n return (\n <span\n {...props}\n style={{ ...colors, ...style }}\n data-scope='attention-glyph'\n data-part='root'\n data-fill={attended ? 'attended' : containsAttended ? 'contains-attended' : fill && 'hue'}\n data-fill-hue={fill?.hue}\n data-mark={mark?.icon}\n data-mark-hue={mark?.hue}\n data-edge={edge && (edge.dashed ? 'dashed' : 'solid')}\n data-edge-hue={edge?.hue}\n data-corner={corner && (corner.shape ?? 'dot')}\n data-corner-hue={corner?.hue}\n data-moving={moving}\n className={mx('dx-attention-glyph', classNames)}\n ref={forwardedRef}\n >\n {(mark || edge || corner) && (\n <svg viewBox='0 0 12 12' fill='none' aria-hidden data-scope='attention-glyph' data-part='overlay'>\n {edge && <rect data-part='edge' x='0.5' y='0.5' width='11' height='11' rx='1.75' pathLength='48' />}\n {mark && <Mark icon={mark.icon} />}\n {corner && <circle data-part='corner' cx='12.25' cy='-0.25' r={corner.shape === 'ring' ? 2 : 2.5} />}\n </svg>\n )}\n </span>\n );\n },\n);\n\nAttentionGlyph.displayName = 'AttentionGlyph';\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport React from 'react';\n\nimport { mx } from '@dxos/ui-theme';\nimport { type ThemedClassName } from '@dxos/ui-types';\n\nexport type RemoteCursorProps = ThemedClassName<{\n /** Collaborator's display name, shown in the tag. */\n name: string;\n /** Member hue (a palette name such as `red`), matching their presence avatar. */\n hue: string;\n /** Tip position in the positioned parent's pixels. */\n x: number;\n y: number;\n /** Divides the cursor's size, for a parent drawn under a zoom that the cursor should not follow. */\n zoom?: number;\n}>;\n\n// The hue lands in a CSS variable name, and it arrives from other peers.\nconst safeHue = (hue: string) => (/^[a-z]+$/.test(hue) ? hue : 'neutral');\n\n/**\n * Another collaborator's pointer: an arrow and a name tag in their member hue.\n */\nexport const RemoteCursor = ({ classNames, name, hue, x, y, zoom = 1 }: RemoteCursorProps) => {\n const color = safeHue(hue);\n return (\n <div\n role='none'\n className={mx('absolute top-0 left-0 pointer-events-none origin-top-left', classNames)}\n style={{ transform: `translate(${x}px, ${y}px) scale(${1 / zoom})` }}\n data-testid='remote-cursor'\n data-hue={color}\n >\n <svg width='16' height='16' viewBox='0 0 16 16' aria-hidden className='block drop-shadow-sm'>\n <path\n d='M1 1 L1 13 L4.5 9.75 L7 15 L9 14 L6.75 8.75 L11.5 8.5 Z'\n style={{ fill: `var(--color-${color}-bg)` }}\n stroke='white'\n strokeWidth='1'\n strokeLinejoin='round'\n />\n </svg>\n <span\n className='absolute top-[14px] left-[10px] px-1.5 py-0.5 rounded-sm text-xs leading-none whitespace-nowrap shadow-sm'\n style={{ backgroundColor: `var(--color-${color}-surface)`, color: `var(--color-${color}-fg)` }}\n >\n {name}\n </span>\n </div>\n );\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport React, { useEffect, useLayoutEffect, useRef, useState } from 'react';\n\nimport { RemoteCursor } from './RemoteCursor.tsx';\n\nexport type CursorPoint = { x: number; y: number };\n\n/**\n * Maps between the layer's pixels and the surface's own coordinates (a scene's world, an svg's viewBox, a map's\n * lat/lng), which peers share. Either returns `undefined` while the surface is not laid out.\n */\nexport type CursorProjection = {\n fromLayer: (point: CursorPoint, layer: HTMLElement) => CursorPoint | undefined;\n toLayer: (point: CursorPoint, layer: HTMLElement) => CursorPoint | undefined;\n};\n\nexport type LayerCursor = CursorPoint & { id: string; name: string; hue: string };\n\nexport type RemoteCursorLayerProps = {\n /** Other collaborators' pointers, in surface coordinates. */\n cursors: readonly LayerCursor[];\n /** Pass a new projection when the surface's transform changes, so the cursors are placed again. */\n projection: CursorProjection;\n /** The local pointer moved over the surface (in surface coordinates), or left it (`undefined`). */\n onPointerChange?: (point: CursorPoint | undefined) => void;\n};\n\n/**\n * Collaborators' pointers over any surface, and the local one reported back. Renders as a cover over its parent,\n * which must be positioned and contain the surface; the parent's pointer events are what it tracks.\n */\nexport const RemoteCursorLayer = ({ cursors, projection, onPointerChange }: RemoteCursorLayerProps) => {\n const [layer, setLayer] = useState<HTMLDivElement | null>(null);\n const latest = useRef({ projection, onPointerChange });\n latest.current = { projection, onPointerChange };\n // Where the local pointer rests in the layer, while it is over the surface.\n const pointer = useRef<CursorPoint | undefined>(undefined);\n // A resize moves the surface under the layer without a new projection.\n const [, setLayout] = useState(0);\n\n // A new projection renders before its surface reaches the DOM, so place the cursors again once it has.\n useLayoutEffect(() => setLayout((layout) => layout + 1), [projection]);\n\n // A pan or zoom moves the surface under a pointer that stays still, so report the point it now rests on.\n useEffect(() => {\n const point = layer && pointer.current && projection.fromLayer(pointer.current, layer);\n if (point) {\n latest.current.onPointerChange?.(point);\n }\n }, [layer, projection]);\n\n useEffect(() => {\n const root = layer?.parentElement;\n if (!layer || !root) {\n return;\n }\n\n const handleMove = (event: PointerEvent) => {\n const rect = layer.getBoundingClientRect();\n pointer.current = { x: event.clientX - rect.left, y: event.clientY - rect.top };\n const point = latest.current.projection.fromLayer(pointer.current, layer);\n if (point) {\n latest.current.onPointerChange?.(point);\n }\n };\n const handleLeave = () => {\n pointer.current = undefined;\n latest.current.onPointerChange?.(undefined);\n };\n const observer = new ResizeObserver(() => setLayout((layout) => layout + 1));\n\n root.addEventListener('pointermove', handleMove, { passive: true });\n root.addEventListener('pointerleave', handleLeave);\n observer.observe(root);\n return () => {\n root.removeEventListener('pointermove', handleMove);\n root.removeEventListener('pointerleave', handleLeave);\n observer.disconnect();\n handleLeave();\n };\n }, [layer]);\n\n return (\n <div ref={setLayer} role='none' className='dx-cover overflow-hidden pointer-events-none'>\n {layer &&\n cursors.map((cursor) => {\n const point = projection.toLayer(cursor, layer);\n return point ? (\n <RemoteCursor key={cursor.id} name={cursor.name} hue={cursor.hue} x={point.x} y={point.y} />\n ) : null;\n })}\n </div>\n );\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport React, { type PropsWithChildren, useEffect, useMemo, useRef } from 'react';\n\nimport * as ScrollArea from '@dxos/react-ui/ScrollArea';\n\nimport { ScrollPosition } from '../../types/index.ts';\nimport { useManagerOptional } from '../ViewStateProvider/view-state-hooks.ts';\n\nexport type ScrollScopeProps = PropsWithChildren<{\n /** The EID of the object whose view this is; no scroll is kept without one. */\n contextId?: string;\n}>;\n\n/**\n * Keeps the scroll of an object's view as its `ScrollPosition` view state: the outermost `ScrollArea` inside reports\n * where it is, and it is restored when it mounts and when a follow writes the leader's position.\n */\nexport const ScrollScope = ({ contextId, children }: ScrollScopeProps) => {\n const manager = useManagerOptional();\n const tracking = useRef<ScrollArea.TrackingHandle>(null);\n\n // Only the areas whose position the follow changed move; the session's own writes are where it already is.\n useEffect(() => {\n if (!manager || !contextId) {\n return;\n }\n let previous = manager.get(ScrollPosition.aspect, contextId);\n return manager.subscribe(ScrollPosition.aspect, contextId, (state, origin) => {\n const changed = Object.entries(state).filter(\n ([name, position]) => JSON.stringify(position) !== JSON.stringify(previous[name]),\n );\n previous = state;\n if (origin === 'follow') {\n changed.forEach(([name, position]) => tracking.current?.restore(name, position));\n }\n });\n }, [manager, contextId]);\n\n const options = useMemo<ScrollArea.TrackingProps>(\n () =>\n manager && contextId\n ? {\n initial: (name) => manager.get(ScrollPosition.aspect, contextId)[name],\n onScroll: (name, position) =>\n manager.update(ScrollPosition.aspect, contextId, (state) => ({ ...state, [name]: position })),\n }\n : {},\n [manager, contextId],\n );\n\n return (\n <ScrollArea.Tracking ref={tracking} {...options}>\n {children}\n </ScrollArea.Tracking>\n );\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { useHotkeys } from '@dxos/react-focus';\n\nimport { useAttention } from '../components/index.ts';\n\n/**\n * Compute the id to select after pressing 'j' (delta = 1) or 'k' (delta = -1).\n * Clamps at the list ends — pressing 'j' on the last item keeps the last item\n * selected (vim-style), and 'k' on the first item keeps the first.\n *\n * When no current selection exists, returns the first id (for delta = 1) or the\n * last id (for delta = -1) so the user can enter the list with either key.\n */\nexport const advance = ({\n ids,\n currentId,\n delta,\n}: {\n ids: readonly string[];\n currentId: string | undefined;\n delta: 1 | -1;\n}): string | undefined => {\n if (ids.length === 0) {\n return undefined;\n }\n\n const idx = currentId ? ids.indexOf(currentId) : -1;\n if (idx === -1) {\n return delta === 1 ? ids[0] : ids[ids.length - 1];\n }\n\n const next = Math.max(0, Math.min(ids.length - 1, idx + delta));\n return ids[next];\n};\n\nexport type UseArticleKeyboardNavigationOptions<T> = {\n /** Stable id for the article; also the hotkey command id. */\n articleId: string;\n /** Ordered list of selectable items as they appear in the article. */\n items: readonly T[];\n /** Currently-selected id, if any. */\n currentId: string | undefined;\n /** Extracts the id from an item. Defaults to `item.id`. */\n getId?: (item: T) => string;\n /** Called with the id to select when the user presses 'j' or 'k'. */\n onSelect: (id: string) => void;\n};\n\n/**\n * Wire 'j' (next) and 'k' (previous) for an article that navigates a list of items (e.g. messages,\n * events). This moves the *selection*, never focus, and it is gated on the article having\n * attention — so it is a hotkey rather than a focus group, and the gate is `enabled` rather than a\n * scope, since attention is already React state here.\n *\n * Pass the items directly; ids are derived via `getId` (defaults to `item.id`).\n * Clamps at list boundaries.\n */\nexport const useArticleKeyboardNavigation: {\n <T extends { id: string }>(options: UseArticleKeyboardNavigationOptions<T>): void;\n <T>(options: UseArticleKeyboardNavigationOptions<T> & { getId: (item: T) => string }): void;\n} = <T>({ articleId, items, currentId, getId, onSelect }: UseArticleKeyboardNavigationOptions<T>): void => {\n const { hasAttention } = useAttention(articleId);\n\n // `getId` is optional only when `T extends { id: string }` (enforced by the overloads above),\n // so the fallback is sound; the cast bridges the generic erased by the implementation signature.\n const ids = useMemo(() => items.map((item) => (getId ? getId(item) : (item as { id: string }).id)), [items, getId]);\n\n const move = (delta: 1 | -1) => {\n const target = advance({ ids, currentId, delta });\n if (target !== undefined) {\n onSelect(target);\n }\n };\n\n useHotkeys({\n id: articleId,\n commands: [\n { hotkey: 'j', label: 'Next item', enabled: () => hasAttention, action: () => move(1) },\n { hotkey: 'k', label: 'Previous item', enabled: () => hasAttention, action: () => move(-1) },\n ],\n });\n};\n"],"mappings":";;;;;;;;;AAqBA,IAAM,eACJ;AACF,IAAM,YAAY;AAElB,IAAM,uBAAuB;;AAG7B,IAAM,SAAS,QAAa,eAAe,IAAI;AAE/C,IAAM,YAAY,EAAE,WAA6B;CAC/C,MAAM,OAAO,YAAY,IAAI;CAC7B,OAAO,oBAAC,OAAD;EAAK,aAAU;EAAa;EAAM,GAAE;EAAI,GAAE;EAAI,OAAM;EAAI,QAAO;CAAK,CAAA;AAC7E;AAEA,IAAM,QAAQ,EAAE,WAA6B;CAC3C,QAAQ,MAAR;EACE,KAAK,OACH,OAAO,oBAAC,UAAD;GAAQ,aAAU;GAAO,IAAG;GAAI,IAAG;GAAI,GAAE;EAAO,CAAA;EACzD,KAAK,QACH,OACE,qBAAC,KAAD;GAAG,aAAU;GAAb,UAAA,CACE,oBAAC,QAAD,EAAM,GAAG,aAAe,CAAA,GACxB,oBAAC,UAAD;IAAQ,IAAG;IAAO,IAAG;IAAI,GAAE;GAAO,CAAA,CACjC;;EAEP,KAAK,QACH,OAAO,oBAAC,QAAD;GAAM,aAAU;GAAO,GAAG;EAAY,CAAA;EAC/C,SACE,OAAO,oBAAC,UAAD,EAAgB,KAAO,CAAA;CAClC;AACF;;;;AAKA,IAAa,iBAAiB,YAC3B,EAAE,YAAY,OAAO,UAAU,kBAAkB,YAAY,GAAG,SAAS,iBAAiB;CACzF,MAAM,EAAE,MAAM,MAAM,MAAM,QAAQ,WAAW,cACrCA,QAAiB,cAAc,CAAC,GAAG,EAAE,WAAW,YAAY,iBAAiB,CAAC,GACpF;EAAC;EAAU;EAAkB;CAAU,CACzC;CACA,MAA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AAW;EACT,IAAI;EACJ,UAAU,CACR;GAAE,QAAQ;GAAK,OAAO;GAAa,eAAe;GAAc,cAAc,KAAK,CAAC;EAAE,GACtF;GAAE,QAAQ;GAAK,OAAO;GAAiB,eAAe;GAAc,cAAc,KAAK,EAAE;EAAE,CAC7F;CACF,CAAC;AACH"}
|
package/dist/lib/testing.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { m as AttentionManager } from "./chunk-types.mjs";
|
|
2
2
|
import { l as RootAttentionProvider, t as ViewStateProvider } from "./chunk-ViewStateProvider.mjs";
|
|
3
3
|
import { createElement, useMemo } from "react";
|
|
4
4
|
import { RegistryContext } from "@effect/atom-react/RegistryContext";
|
package/dist/lib/types.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { _ as Activity, h as Attention, t as LocalBackend, n as MemoryBackend, l as ScrollPosition, a as Selection, i as ViewLocation, f as ViewState, r as createDefaultBackends } from "./chunk-types.mjs";
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import React, { type ComponentPropsWithoutRef } from 'react';
|
|
2
2
|
import { type ThemedClassName } from '@dxos/ui-types';
|
|
3
|
-
|
|
3
|
+
import * as Activity from '../../types/Activity.ts';
|
|
4
4
|
export type AttentionGlyphProps = ThemedClassName<Omit<ComponentPropsWithoutRef<'span'>, 'children'>> & {
|
|
5
5
|
/** The item is the attended one: the glyph fills with the accent. */
|
|
6
6
|
attended?: boolean;
|
|
7
7
|
/** The attended item is inside this one: the glyph takes the softer contains tint. */
|
|
8
8
|
containsAttended?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
/** How many others are viewing the item. */
|
|
12
|
-
presence?: AttentionGlyphPresence;
|
|
9
|
+
/** Activity on the item; the glyph draws one treatment per slot and animates at most one (see `Activity.resolve`). */
|
|
10
|
+
treatments?: readonly Activity.Treatment[];
|
|
13
11
|
};
|
|
14
12
|
/**
|
|
15
|
-
* A small square marking an item's attention state
|
|
16
|
-
* else is viewing it or whether it is syncing. The state is the glyph's own attributes, so it needs no host markup.
|
|
13
|
+
* A small square marking an item's attention state and the activity on it, one treatment per slot (see `Activity.Slot`).
|
|
17
14
|
*/
|
|
18
15
|
export declare const AttentionGlyph: React.ForwardRefExoticComponent<Omit<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref">, "children">, "className"> & {
|
|
19
16
|
classNames?: import("@dxos/ui-types").ClassNameValue;
|
|
@@ -22,9 +19,7 @@ export declare const AttentionGlyph: React.ForwardRefExoticComponent<Omit<Omit<O
|
|
|
22
19
|
attended?: boolean;
|
|
23
20
|
/** The attended item is inside this one: the glyph takes the softer contains tint. */
|
|
24
21
|
containsAttended?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
/** How many others are viewing the item. */
|
|
28
|
-
presence?: AttentionGlyphPresence;
|
|
22
|
+
/** Activity on the item; the glyph draws one treatment per slot and animates at most one (see `Activity.resolve`). */
|
|
23
|
+
treatments?: readonly Activity.Treatment[];
|
|
29
24
|
} & React.RefAttributes<HTMLSpanElement>>;
|
|
30
25
|
//# sourceMappingURL=AttentionGlyph.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttentionGlyph.d.ts","sourceRoot":"","sources":["../../../../../src/components/AttentionGlyph/AttentionGlyph.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAE,KAAK,wBAAwB,EAA2C,MAAM,OAAO,CAAC;AAItG,OAAO,
|
|
1
|
+
{"version":3,"file":"AttentionGlyph.d.ts","sourceRoot":"","sources":["../../../../../src/components/AttentionGlyph/AttentionGlyph.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAE,KAAK,wBAAwB,EAA2C,MAAM,OAAO,CAAC;AAItG,OAAO,EAAY,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AAEpD,MAAM,MAAM,mBAAmB,GAAG,eAAe,CAAC,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC,GAAG;IACtG,qEAAqE;IACrE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sFAAsF;IACtF,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,sHAAsH;IACtH,UAAU,CAAC,EAAE,SAAS,QAAQ,CAAC,SAAS,EAAE,CAAC;CAC5C,CAAC;AAkCF;;GAEG;AACH,eAAO,MAAM,cAAc;;;IA3CzB,qEAAqE;eAC1D,OAAO;IAClB,sFAAsF;uBACnE,OAAO;IAC1B,sHAAsH;iBACzG,SAAS,QAAQ,CAAC,SAAS,EAAE;yCAqF3C,CAAC"}
|
|
@@ -2,11 +2,18 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
2
2
|
import '@dxos/react-ui/theme.css';
|
|
3
3
|
import { type SizeArgs } from '@dxos/react-ui/testing';
|
|
4
4
|
import { type AttentionGlyphProps } from './AttentionGlyph.tsx';
|
|
5
|
-
type
|
|
6
|
-
declare const meta: Meta
|
|
5
|
+
type SizeStoryArgs = SizeArgs & Pick<AttentionGlyphProps, 'attended' | 'containsAttended'>;
|
|
6
|
+
declare const meta: Meta;
|
|
7
7
|
export default meta;
|
|
8
|
-
type Story = StoryObj
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export declare const
|
|
8
|
+
type Story = StoryObj;
|
|
9
|
+
/** Everything the glyph can draw: the vocabulary, how slots resolve, combinations and the motion rule. */
|
|
10
|
+
export declare const Default: StoryObj<SizeArgs>;
|
|
11
|
+
export declare const Examples: Story;
|
|
12
|
+
export declare const Resolution: Story;
|
|
13
|
+
export declare const Combinations: Story;
|
|
14
|
+
export declare const AgentStar: StoryObj<SizeArgs>;
|
|
15
|
+
export declare const Motion: Story;
|
|
16
|
+
export declare const Sizes: StoryObj<SizeStoryArgs>;
|
|
17
|
+
/** The glyph is 3/4 of the icon size; attention colours its fill, and activity draws one treatment per slot. */
|
|
18
|
+
export declare const Test: StoryObj<SizeStoryArgs>;
|
|
12
19
|
//# sourceMappingURL=AttentionGlyph.stories.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttentionGlyph.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/AttentionGlyph/AttentionGlyph.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAIjE,OAAO,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"AttentionGlyph.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/AttentionGlyph/AttentionGlyph.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAIjE,OAAO,0BAA0B,CAAC;AAElC,OAAO,EAAkB,KAAK,QAAQ,EAAoC,MAAM,wBAAwB,CAAC;AAGzG,OAAO,EAAkB,KAAK,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AA2VhF,KAAK,aAAa,GAAG,QAAQ,GAAG,IAAI,CAAC,mBAAmB,EAAE,UAAU,GAAG,kBAAkB,CAAC,CAAC;AAa3F,QAAA,MAAM,IAAI,EAAE,IAIX,CAAC;eAEa,IAAI;AAEnB,KAAK,KAAK,GAAG,QAAQ,CAAC;AAEtB,0GAA0G;AAC1G,eAAO,MAAM,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAMtC,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,KAMtB,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,KAMxB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,KAM1B,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,QAAQ,CAUxC,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,KAMpB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,QAAQ,CAAC,aAAa,CAKzC,CAAC;AAEF,gHAAgH;AAChH,eAAO,MAAM,IAAI,EAAE,QAAQ,CAAC,aAAa,CAkCxC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type ThemedClassName } from '@dxos/ui-types';
|
|
3
|
+
export type RemoteCursorProps = ThemedClassName<{
|
|
4
|
+
/** Collaborator's display name, shown in the tag. */
|
|
5
|
+
name: string;
|
|
6
|
+
/** Member hue (a palette name such as `red`), matching their presence avatar. */
|
|
7
|
+
hue: string;
|
|
8
|
+
/** Tip position in the positioned parent's pixels. */
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
/** Divides the cursor's size, for a parent drawn under a zoom that the cursor should not follow. */
|
|
12
|
+
zoom?: number;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Another collaborator's pointer: an arrow and a name tag in their member hue.
|
|
16
|
+
*/
|
|
17
|
+
export declare const RemoteCursor: ({ classNames, name, hue, x, y, zoom }: RemoteCursorProps) => React.JSX.Element;
|
|
18
|
+
//# sourceMappingURL=RemoteCursor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteCursor.d.ts","sourceRoot":"","sources":["../../../../../src/components/RemoteCursor/RemoteCursor.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,MAAM,MAAM,iBAAiB,GAAG,eAAe,CAAC;IAC9C,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,iFAAiF;IACjF,GAAG,EAAE,MAAM,CAAC;IACZ,sDAAsD;IACtD,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,oGAAoG;IACpG,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC,CAAC;AAKH;;GAEG;AACH,eAAO,MAAM,YAAY,0CAA+C,iBAAiB,sBA2BxF,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type CursorPoint = {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Maps between the layer's pixels and the surface's own coordinates (a scene's world, an svg's viewBox, a map's
|
|
8
|
+
* lat/lng), which peers share. Either returns `undefined` while the surface is not laid out.
|
|
9
|
+
*/
|
|
10
|
+
export type CursorProjection = {
|
|
11
|
+
fromLayer: (point: CursorPoint, layer: HTMLElement) => CursorPoint | undefined;
|
|
12
|
+
toLayer: (point: CursorPoint, layer: HTMLElement) => CursorPoint | undefined;
|
|
13
|
+
};
|
|
14
|
+
export type LayerCursor = CursorPoint & {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
hue: string;
|
|
18
|
+
};
|
|
19
|
+
export type RemoteCursorLayerProps = {
|
|
20
|
+
/** Other collaborators' pointers, in surface coordinates. */
|
|
21
|
+
cursors: readonly LayerCursor[];
|
|
22
|
+
/** Pass a new projection when the surface's transform changes, so the cursors are placed again. */
|
|
23
|
+
projection: CursorProjection;
|
|
24
|
+
/** The local pointer moved over the surface (in surface coordinates), or left it (`undefined`). */
|
|
25
|
+
onPointerChange?: (point: CursorPoint | undefined) => void;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Collaborators' pointers over any surface, and the local one reported back. Renders as a cover over its parent,
|
|
29
|
+
* which must be positioned and contain the surface; the parent's pointer events are what it tracks.
|
|
30
|
+
*/
|
|
31
|
+
export declare const RemoteCursorLayer: ({ cursors, projection, onPointerChange }: RemoteCursorLayerProps) => React.JSX.Element;
|
|
32
|
+
//# sourceMappingURL=RemoteCursorLayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteCursorLayer.d.ts","sourceRoot":"","sources":["../../../../../src/components/RemoteCursor/RemoteCursorLayer.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAuD,MAAM,OAAO,CAAC;AAI5E,MAAM,MAAM,WAAW,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,KAAK,WAAW,GAAG,SAAS,CAAC;IAC/E,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,KAAK,WAAW,GAAG,SAAS,CAAC;CAC9E,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAElF,MAAM,MAAM,sBAAsB,GAAG;IACnC,6DAA6D;IAC7D,OAAO,EAAE,SAAS,WAAW,EAAE,CAAC;IAChC,mGAAmG;IACnG,UAAU,EAAE,gBAAgB,CAAC;IAC7B,mGAAmG;IACnG,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,GAAG,SAAS,KAAK,IAAI,CAAC;CAC5D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,6CAA8C,sBAAsB,sBA8DjG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteCursorLayer.test.d.ts","sourceRoot":"","sources":["../../../../../src/components/RemoteCursor/RemoteCursorLayer.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/RemoteCursor/index.ts"],"names":[],"mappings":"AAIA,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React, { type PropsWithChildren } from 'react';
|
|
2
|
+
export type ScrollScopeProps = PropsWithChildren<{
|
|
3
|
+
/** The EID of the object whose view this is; no scroll is kept without one. */
|
|
4
|
+
contextId?: string;
|
|
5
|
+
}>;
|
|
6
|
+
/**
|
|
7
|
+
* Keeps the scroll of an object's view as its `ScrollPosition` view state: the outermost `ScrollArea` inside reports
|
|
8
|
+
* where it is, and it is restored when it mounts and when a follow writes the leader's position.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ScrollScope: ({ contextId, children }: ScrollScopeProps) => React.JSX.Element;
|
|
11
|
+
//# sourceMappingURL=ScrollScope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScrollScope.d.ts","sourceRoot":"","sources":["../../../../../src/components/ScrollScope/ScrollScope.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAA8B,MAAM,OAAO,CAAC;AAOlF,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;IAC/C,+EAA+E;IAC/E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,WAAW,4BAA6B,gBAAgB,sBAsCpE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import '@dxos/react-ui/theme.css';
|
|
4
|
+
/** Two sessions' views of one object; the follower takes each value the leader sends, as the follow does. */
|
|
5
|
+
declare const FollowStory: () => React.JSX.Element;
|
|
6
|
+
declare const meta: {
|
|
7
|
+
title: string;
|
|
8
|
+
render: typeof FollowStory;
|
|
9
|
+
decorators: import("@storybook/react").Decorator[];
|
|
10
|
+
};
|
|
11
|
+
export default meta;
|
|
12
|
+
type Story = StoryObj<typeof meta>;
|
|
13
|
+
/** The follower's view lands on the row at the top of the leader's. */
|
|
14
|
+
export declare const Follow: Story;
|
|
15
|
+
//# sourceMappingURL=ScrollScope.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScrollScope.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/ScrollScope/ScrollScope.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjE,OAAO,KAA6B,MAAM,OAAO,CAAC;AAGlD,OAAO,0BAA0B,CAAC;AAiClC,6GAA6G;AAC7G,QAAA,MAAM,WAAW,yBA2BhB,CAAC;AAEF,QAAA,MAAM,IAAI;;;;CAIM,CAAC;eAEF,IAAI;AAEnB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,uEAAuE;AACvE,eAAO,MAAM,MAAM,EAAE,KAapB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/ScrollScope/index.ts"],"names":[],"mappings":"AAIA,cAAc,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/index.ts"],"names":[],"mappings":"AAIA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/index.ts"],"names":[],"mappings":"AAIA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC"}
|