@dxos/react-ui-attention 0.7.1-staging.8709ba7 → 0.7.2-main.f1adc9f

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.
@@ -0,0 +1,298 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var chunk_3BUNDA53_exports = {};
30
+ __export(chunk_3BUNDA53_exports, {
31
+ ATTENABLE_ATTRIBUTE: () => ATTENABLE_ATTRIBUTE,
32
+ ATTENTION_NAME: () => ATTENTION_NAME,
33
+ ATTENTION_SOURCE_ATTRIBUTE: () => ATTENTION_SOURCE_ATTRIBUTE,
34
+ AttentionGlyph: () => AttentionGlyph,
35
+ AttentionManager: () => AttentionManager,
36
+ AttentionProvider: () => AttentionProvider,
37
+ AttentionSchema: () => AttentionSchema,
38
+ RootAttentionProvider: () => RootAttentionProvider,
39
+ getAttendables: () => getAttendables,
40
+ useAttendableAttributes: () => useAttendableAttributes,
41
+ useAttended: () => useAttended,
42
+ useAttention: () => useAttention,
43
+ useAttentionContext: () => useAttentionContext,
44
+ useAttentionPath: () => useAttentionPath
45
+ });
46
+ module.exports = __toCommonJS(chunk_3BUNDA53_exports);
47
+ var import_signals_core = require("@preact/signals-core");
48
+ var import_echo_schema = require("@dxos/echo-schema");
49
+ var import_util = require("@dxos/util");
50
+ var import_react = __toESM(require("react"));
51
+ var import_react_ui_theme = require("@dxos/react-ui-theme");
52
+ var import_react_context = require("@radix-ui/react-context");
53
+ var import_react2 = __toESM(require("react"));
54
+ var import_react_ui = require("@dxos/react-ui");
55
+ var AttentionSchema = import_echo_schema.S.mutable(import_echo_schema.S.Struct({
56
+ hasAttention: import_echo_schema.S.Boolean,
57
+ isAncestor: import_echo_schema.S.Boolean,
58
+ isRelated: import_echo_schema.S.Boolean
59
+ }));
60
+ var stringKey = (key) => key.join(",");
61
+ var AttentionManager = class {
62
+ constructor(initial = []) {
63
+ this._map = new import_util.ComplexMap(stringKey);
64
+ this._state = (0, import_echo_schema.create)({
65
+ current: []
66
+ });
67
+ if (initial.length > 0) {
68
+ this.update(initial);
69
+ }
70
+ }
71
+ /**
72
+ * Currently attended element.
73
+ */
74
+ get current() {
75
+ return this._state.current;
76
+ }
77
+ /**
78
+ * All attention paths.
79
+ */
80
+ keys() {
81
+ return Array.from(this._map.keys());
82
+ }
83
+ /**
84
+ * Get the attention state for a given path.
85
+ */
86
+ get(key) {
87
+ const object = this._map.get(key);
88
+ if (object) {
89
+ return object;
90
+ }
91
+ const newObject = (0, import_echo_schema.create)(AttentionSchema, {
92
+ hasAttention: false,
93
+ isAncestor: false,
94
+ isRelated: false
95
+ });
96
+ this._map.set(key, newObject);
97
+ return newObject;
98
+ }
99
+ /**
100
+ * Update the currently attended element.
101
+ */
102
+ update(nextKey) {
103
+ const currentKey = (0, import_signals_core.untracked)(() => this.current);
104
+ const currentRelatedTo = currentKey[0];
105
+ const nextRelatedTo = nextKey[0];
106
+ this.get([
107
+ nextRelatedTo
108
+ ]);
109
+ const currentRelatedKeys = this.keys().filter((key) => key[0] === currentRelatedTo);
110
+ const nextRelatedKeys = this.keys().filter((key) => key[0] === nextRelatedTo && stringKey(key) !== stringKey(nextKey));
111
+ const prevRelatedKeys = currentRelatedKeys.filter((curr) => !nextRelatedKeys.find((next) => stringKey(curr) === stringKey(next)));
112
+ const currentAncestorKeys = currentKey.slice(1).map((_, i) => currentKey.slice(i + 1, currentKey.length));
113
+ const nextAncestorKeys = nextKey.slice(1).map((_, i) => nextKey.slice(i + 1, nextKey.length));
114
+ const prevAncestorKeys = currentAncestorKeys.filter((curr) => !nextAncestorKeys.find((next) => stringKey(curr) === stringKey(next)));
115
+ this._state.current = nextKey;
116
+ prevRelatedKeys.forEach((key) => this._set(key, {}));
117
+ prevAncestorKeys.forEach((key) => this._set(key, {}));
118
+ nextRelatedKeys.forEach((key) => this._set(key, {
119
+ isRelated: true
120
+ }));
121
+ nextAncestorKeys.forEach((key) => this._set(key, {
122
+ isAncestor: true
123
+ }));
124
+ this._set(nextKey, {
125
+ hasAttention: true
126
+ });
127
+ }
128
+ _set(key, attention) {
129
+ const object = this.get(key);
130
+ object.hasAttention = attention.hasAttention ?? false;
131
+ object.isAncestor = attention.isAncestor ?? false;
132
+ object.isRelated = attention.isRelated ?? false;
133
+ }
134
+ };
135
+ var getAttendables = (selector, cursor, acc = []) => {
136
+ const closestAttendable = cursor.closest(selector);
137
+ if (closestAttendable) {
138
+ const attendableId = closestAttendable.getAttribute("data-attendable-id");
139
+ if (!attendableId) {
140
+ const trigger = document.querySelector(`[aria-controls="${closestAttendable.getAttribute("id")}"]`);
141
+ if (!trigger) {
142
+ return acc;
143
+ } else {
144
+ return getAttendables(selector, trigger, acc);
145
+ }
146
+ } else {
147
+ acc.push(attendableId);
148
+ return !closestAttendable.parentElement ? acc : getAttendables(selector, closestAttendable.parentElement, acc);
149
+ }
150
+ }
151
+ return [
152
+ ...new Set(acc)
153
+ ];
154
+ };
155
+ var attentionGlyphStyles = "inline-block rounded-sm is-3 bs-3 bg-transparent text-accentText transition-colors [[data-attention=true]_&]:bg-accentSurface [[data-attention=true]_&]:text-inverse [[aria-current][data-attention=true]_&]:bg-accentSurface [[aria-current][data-attention=true]_&]:text-inverse";
156
+ var presenceIconStyles = "is-3 bs-3 group-[[aria-current]_&:hover]/attentionGlyphButton:hidden group-[[aria-current]_&:focus]/attentionGlyphButton:hidden group-[[data-attention=true]_&:hover]/attentionGlyphButton:hidden group-[[data-attention=true]_&:focus]/attentionGlyphButton:hidden group-[[aria-current][data-attention=true]_&:hover]/attentionGlyphButton:hidden group-[[aria-current][data-attention=true]_&:focus]/attentionGlyphButton:hidden";
157
+ var PresenceOne = () => {
158
+ return /* @__PURE__ */ import_react.default.createElement("svg", {
159
+ width: "12",
160
+ height: "12",
161
+ viewBox: "0 0 12 12",
162
+ className: presenceIconStyles,
163
+ fill: "none",
164
+ xmlns: "http://www.w3.org/2000/svg"
165
+ }, /* @__PURE__ */ import_react.default.createElement("circle", {
166
+ cx: "6",
167
+ cy: "6",
168
+ r: "2.5",
169
+ fill: "currentColor"
170
+ }));
171
+ };
172
+ var PresenceMany = () => {
173
+ return /* @__PURE__ */ import_react.default.createElement("svg", {
174
+ width: "12",
175
+ height: "12",
176
+ viewBox: "0 0 12 12",
177
+ className: presenceIconStyles,
178
+ fill: "none",
179
+ xmlns: "http://www.w3.org/2000/svg"
180
+ }, /* @__PURE__ */ import_react.default.createElement("path", {
181
+ 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",
182
+ fill: "currentColor"
183
+ }), /* @__PURE__ */ import_react.default.createElement("circle", {
184
+ cx: "4.25",
185
+ cy: "6",
186
+ r: "2.5",
187
+ fill: "currentColor"
188
+ }));
189
+ };
190
+ var AttentionGlyph = /* @__PURE__ */ (0, import_react.forwardRef)(({ presence, classNames, ...props }, forwardedRef) => {
191
+ return /* @__PURE__ */ import_react.default.createElement("span", {
192
+ role: "none",
193
+ ...props,
194
+ className: (0, import_react_ui_theme.mx)(attentionGlyphStyles, classNames),
195
+ ref: forwardedRef
196
+ }, presence === "many" && /* @__PURE__ */ import_react.default.createElement(PresenceMany, null), presence === "one" && /* @__PURE__ */ import_react.default.createElement(PresenceOne, null));
197
+ });
198
+ var ATTENTION_NAME = "Attention";
199
+ var ATTENABLE_ATTRIBUTE = "data-attendable-id";
200
+ var ATTENTION_SOURCE_ATTRIBUTE = "data-is-attention-source";
201
+ var [AttentionContextProvider, useAttentionContext] = (0, import_react_context.createContext)(ATTENTION_NAME, {
202
+ attention: new AttentionManager(),
203
+ path: []
204
+ });
205
+ var UNKNOWN_ATTENDABLE = {
206
+ hasAttention: false,
207
+ isAncestor: false,
208
+ isRelated: false
209
+ };
210
+ var useAttention = (attendableId) => {
211
+ const { attention, path } = useAttentionContext(ATTENTION_NAME);
212
+ if (!attendableId) {
213
+ return UNKNOWN_ATTENDABLE;
214
+ }
215
+ const current = [
216
+ attendableId,
217
+ ...path
218
+ ];
219
+ return attention.get(current);
220
+ };
221
+ var useAttended = () => {
222
+ const { attention } = useAttentionContext(ATTENTION_NAME);
223
+ return attention.current;
224
+ };
225
+ var useAttendableAttributes = (attendableId) => {
226
+ const { hasAttention } = useAttention(attendableId);
227
+ return (0, import_react2.useMemo)(() => {
228
+ const attributes = {
229
+ [ATTENABLE_ATTRIBUTE]: attendableId
230
+ };
231
+ if (hasAttention) {
232
+ attributes[ATTENTION_SOURCE_ATTRIBUTE] = "true";
233
+ }
234
+ return attributes;
235
+ }, [
236
+ attendableId,
237
+ hasAttention
238
+ ]);
239
+ };
240
+ var useAttentionPath = () => {
241
+ const { path } = useAttentionContext(ATTENTION_NAME);
242
+ return path;
243
+ };
244
+ var RootAttentionProvider = ({ children, attention: propsAttention, onChange }) => {
245
+ const attention = (0, import_react_ui.useDefaultValue)(propsAttention, () => new AttentionManager());
246
+ const handleFocus = (event) => {
247
+ const selector = [
248
+ "[data-attendable-id]",
249
+ ...Array.from(document.querySelectorAll("[aria-controls]")).map((el) => `[id="${el.getAttribute("aria-controls")}"]`)
250
+ ].join(",");
251
+ const prev = attention.current;
252
+ const next = getAttendables(selector, event.target);
253
+ if (next.length > 0 && (prev.length !== next.length || !!prev.find((id, index) => next[index] !== id))) {
254
+ attention.update(next);
255
+ onChange?.(next);
256
+ }
257
+ };
258
+ return /* @__PURE__ */ import_react2.default.createElement(AttentionContextProvider, {
259
+ attention,
260
+ path: []
261
+ }, /* @__PURE__ */ import_react2.default.createElement("div", {
262
+ role: "none",
263
+ className: "contents",
264
+ onFocusCapture: handleFocus
265
+ }, children));
266
+ };
267
+ var AttentionProvider = ({ id, children }) => {
268
+ const { attention, path } = useAttentionContext(ATTENTION_NAME);
269
+ const nextPath = (0, import_react2.useMemo)(() => [
270
+ id,
271
+ ...path
272
+ ], [
273
+ id,
274
+ path
275
+ ]);
276
+ return /* @__PURE__ */ import_react2.default.createElement(AttentionContextProvider, {
277
+ attention,
278
+ path: nextPath
279
+ }, children);
280
+ };
281
+ // Annotate the CommonJS export names for ESM import in node:
282
+ 0 && (module.exports = {
283
+ ATTENABLE_ATTRIBUTE,
284
+ ATTENTION_NAME,
285
+ ATTENTION_SOURCE_ATTRIBUTE,
286
+ AttentionGlyph,
287
+ AttentionManager,
288
+ AttentionProvider,
289
+ AttentionSchema,
290
+ RootAttentionProvider,
291
+ getAttendables,
292
+ useAttendableAttributes,
293
+ useAttended,
294
+ useAttention,
295
+ useAttentionContext,
296
+ useAttentionPath
297
+ });
298
+ //# sourceMappingURL=chunk-3BUNDA53.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/attention.ts", "../../../src/components/AttentionGlyph.tsx", "../../../src/components/AttentionProvider.tsx"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { untracked } from '@preact/signals-core';\n\nimport { create, type ReactiveObject, S } from '@dxos/echo-schema';\nimport { ComplexMap } from '@dxos/util';\n\nexport const AttentionSchema = S.mutable(\n S.Struct({\n hasAttention: S.Boolean,\n isAncestor: S.Boolean,\n isRelated: S.Boolean,\n }),\n);\n\nexport type Attention = S.Schema.Type<typeof AttentionSchema>;\n\n// TODO(wittjosiah): Use mosaic path utility?\nconst stringKey = (key: string[]) => key.join(',');\n\n/**\n * Manages attention state for an application.\n */\n// TODO(wittjosiah): Write unit tests.\nexport class AttentionManager {\n // Each attention path is associated with an attention object.\n // The lookup is not a reactive object to ensure that attention for each path is subscribable independently.\n private readonly _map = new ComplexMap<string[], ReactiveObject<Attention>>(stringKey);\n private readonly _state = create<{ current: string[] }>({ current: [] });\n\n constructor(initial: string[] = []) {\n if (initial.length > 0) {\n this.update(initial);\n }\n }\n\n /**\n * Currently attended element.\n */\n get current() {\n return this._state.current;\n }\n\n /**\n * All attention paths.\n */\n keys() {\n return Array.from(this._map.keys());\n }\n\n /**\n * Get the attention state for a given path.\n */\n get(key: string[]): ReactiveObject<Attention> {\n const object = this._map.get(key);\n if (object) {\n return object;\n }\n\n const newObject = create(AttentionSchema, { hasAttention: false, isAncestor: false, isRelated: false });\n this._map.set(key, newObject);\n return newObject;\n }\n\n /**\n * Update the currently attended element.\n */\n update(nextKey: string[]) {\n const currentKey = untracked(() => this.current);\n const currentRelatedTo = currentKey[0];\n const nextRelatedTo = nextKey[0];\n\n // Ensure related attention object is initialized.\n this.get([nextRelatedTo]);\n\n const currentRelatedKeys = this.keys().filter((key) => key[0] === currentRelatedTo);\n const nextRelatedKeys = this.keys().filter(\n (key) => key[0] === nextRelatedTo && stringKey(key) !== stringKey(nextKey),\n );\n const prevRelatedKeys = currentRelatedKeys.filter(\n (curr) => !nextRelatedKeys.find((next) => stringKey(curr) === stringKey(next)),\n );\n\n const currentAncestorKeys = currentKey.slice(1).map((_, i) => currentKey.slice(i + 1, currentKey.length));\n const nextAncestorKeys = nextKey.slice(1).map((_, i) => nextKey.slice(i + 1, nextKey.length));\n const prevAncestorKeys = currentAncestorKeys.filter(\n (curr) => !nextAncestorKeys.find((next) => stringKey(curr) === stringKey(next)),\n );\n\n this._state.current = nextKey;\n prevRelatedKeys.forEach((key) => this._set(key, {}));\n prevAncestorKeys.forEach((key) => this._set(key, {}));\n nextRelatedKeys.forEach((key) => this._set(key, { isRelated: true }));\n nextAncestorKeys.forEach((key) => this._set(key, { isAncestor: true }));\n this._set(nextKey, { hasAttention: true });\n }\n\n private _set(key: string[], attention: Partial<Attention>) {\n const object = this.get(key);\n object.hasAttention = attention.hasAttention ?? false;\n object.isAncestor = attention.isAncestor ?? false;\n object.isRelated = attention.isRelated ?? false;\n }\n}\n\n/**\n * Accumulates all attendable id’s between the element provided and the root, inclusive.\n */\nexport const getAttendables = (selector: string, cursor: Element, acc: string[] = []): string[] => {\n // Find the closest element with `data-attendable-id`, if any; start from cursor and move up the DOM tree.\n const closestAttendable = cursor.closest(selector);\n if (closestAttendable) {\n const attendableId = closestAttendable.getAttribute('data-attendable-id');\n if (!attendableId) {\n // this has an id of an aria-controls elsewhere on the page, move cursor to that trigger\n const trigger = document.querySelector(`[aria-controls=\"${closestAttendable.getAttribute('id')}\"]`);\n if (!trigger) {\n return acc;\n } else {\n return getAttendables(selector, trigger, acc);\n }\n } else {\n acc.push(attendableId);\n // (attempt tail recursion)\n return !closestAttendable.parentElement ? acc : getAttendables(selector, closestAttendable.parentElement, acc);\n }\n }\n\n return [...new Set(acc)];\n};\n\nexport type AttendableId = { attendableId?: string };\n\nexport type Related = { related?: boolean };\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Primitive } from '@radix-ui/react-primitive';\nimport React, { type ComponentPropsWithRef, forwardRef } from 'react';\n\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\nconst attentionGlyphStyles =\n 'inline-block rounded-sm is-3 bs-3 bg-transparent text-accentText transition-colors [[data-attention=true]_&]:bg-accentSurface [[data-attention=true]_&]:text-inverse [[aria-current][data-attention=true]_&]:bg-accentSurface [[aria-current][data-attention=true]_&]:text-inverse';\n\nconst presenceIconStyles =\n 'is-3 bs-3 group-[[aria-current]_&:hover]/attentionGlyphButton:hidden group-[[aria-current]_&:focus]/attentionGlyphButton:hidden group-[[data-attention=true]_&:hover]/attentionGlyphButton:hidden group-[[data-attention=true]_&:focus]/attentionGlyphButton:hidden group-[[aria-current][data-attention=true]_&:hover]/attentionGlyphButton:hidden group-[[aria-current][data-attention=true]_&:focus]/attentionGlyphButton:hidden';\n\nconst PresenceOne = () => {\n return (\n <svg\n width='12'\n height='12'\n viewBox='0 0 12 12'\n className={presenceIconStyles}\n fill='none'\n xmlns='http://www.w3.org/2000/svg'\n >\n <circle cx='6' cy='6' r='2.5' fill='currentColor' />\n </svg>\n );\n};\n\nconst PresenceMany = () => {\n return (\n <svg\n width='12'\n height='12'\n viewBox='0 0 12 12'\n className={presenceIconStyles}\n fill='none'\n xmlns='http://www.w3.org/2000/svg'\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\nexport type AttentionGlyphProps = {\n presence?: 'none' | 'one' | 'many';\n} & ThemedClassName<Omit<ComponentPropsWithRef<typeof Primitive.span>, 'children'>>;\n\nexport const AttentionGlyph = forwardRef<HTMLSpanElement, AttentionGlyphProps>(\n ({ presence, classNames, ...props }, forwardedRef) => {\n return (\n <span role='none' {...props} className={mx(attentionGlyphStyles, classNames)} ref={forwardedRef}>\n {presence === 'many' && <PresenceMany />}\n {presence === 'one' && <PresenceOne />}\n </span>\n );\n },\n);\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// NOTE(thure): The following unused imports quell TS2742 (“likely not portable”).\n\n// eslint-disable-next-line unused-imports/no-unused-imports\nimport { createContext, type Scope, type CreateScope } from '@radix-ui/react-context';\nimport React, { useMemo, type FocusEvent, type PropsWithChildren } from 'react';\n\nimport { useDefaultValue } from '@dxos/react-ui';\n\nimport { type Attention, AttentionManager, getAttendables } from '../attention';\n\nconst ATTENTION_NAME = 'Attention';\nconst ATTENABLE_ATTRIBUTE = 'data-attendable-id';\nconst ATTENTION_SOURCE_ATTRIBUTE = 'data-is-attention-source';\n\ntype AttentionContextValue = {\n attention: AttentionManager;\n path: string[];\n};\n\nconst [AttentionContextProvider, useAttentionContext] = createContext<AttentionContextValue>(ATTENTION_NAME, {\n attention: new AttentionManager(),\n path: [],\n});\n\nconst UNKNOWN_ATTENDABLE = { hasAttention: false, isAncestor: false, isRelated: false };\n\nconst useAttention = (attendableId?: string): Attention => {\n const { attention, path } = useAttentionContext(ATTENTION_NAME);\n if (!attendableId) {\n return UNKNOWN_ATTENDABLE;\n }\n\n const current = [attendableId, ...path];\n return attention.get(current);\n};\n\nconst useAttended = () => {\n const { attention } = useAttentionContext(ATTENTION_NAME);\n return attention.current;\n};\n\n/**\n * Computes HTML element attributes to apply so the attention system can detect changes\n * @param attendableId\n */\nconst useAttendableAttributes = (attendableId?: string) => {\n const { hasAttention } = useAttention(attendableId);\n return useMemo(() => {\n const attributes: Record<string, string | undefined> = { [ATTENABLE_ATTRIBUTE]: attendableId };\n if (hasAttention) {\n attributes[ATTENTION_SOURCE_ATTRIBUTE] = 'true';\n }\n\n return attributes;\n }, [attendableId, hasAttention]);\n};\n\nconst useAttentionPath = () => {\n const { path } = useAttentionContext(ATTENTION_NAME);\n return path;\n};\n\nconst RootAttentionProvider = ({\n children,\n attention: propsAttention,\n onChange,\n}: PropsWithChildren<\n Partial<{\n attention: AttentionManager;\n onChange: (nextAttended: string[]) => void;\n }>\n>) => {\n const attention = useDefaultValue(propsAttention, () => new AttentionManager());\n const handleFocus = (event: FocusEvent) => {\n const selector = [\n '[data-attendable-id]',\n ...Array.from(document.querySelectorAll('[aria-controls]')).map(\n (el) => `[id=\"${el.getAttribute('aria-controls')}\"]`,\n ),\n ].join(',');\n const prev = attention.current;\n const next = getAttendables(selector, event.target);\n // TODO(wittjosiah): Not allowing empty state means that the attended item is not strictly guaranteed to be in the DOM.\n // Currently this depends on the deck in order to ensure that when the attended item is removed something else is attended.\n // Only update state if the result is different and not empty.\n if (next.length > 0 && (prev.length !== next.length || !!prev.find((id, index) => next[index] !== id))) {\n attention.update(next);\n onChange?.(next);\n }\n };\n return (\n <AttentionContextProvider attention={attention} path={[]}>\n <div role='none' className='contents' onFocusCapture={handleFocus}>\n {children}\n </div>\n </AttentionContextProvider>\n );\n};\n\nconst AttentionProvider = ({ id, children }: PropsWithChildren<{ id: string }>) => {\n const { attention, path } = useAttentionContext(ATTENTION_NAME);\n const nextPath = useMemo(() => [id, ...path], [id, path]);\n\n return (\n <AttentionContextProvider attention={attention} path={nextPath}>\n {children}\n </AttentionContextProvider>\n );\n};\n\nexport {\n RootAttentionProvider,\n AttentionProvider,\n useAttentionContext,\n useAttention,\n useAttended,\n useAttendableAttributes,\n useAttentionPath,\n ATTENTION_NAME,\n ATTENABLE_ATTRIBUTE,\n ATTENTION_SOURCE_ATTRIBUTE,\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,0BAA0B;AAE1B,yBAA+C;AAC/C,kBAA2B;ACF3B,mBAA8D;AAG9D,4BAAmB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EA,IAAMyB,wBAAwB,CAAC,EAC7BC,UACAzD,WAAW0D,gBACXC,SAAQ,MAMT;AACC,QAAM3D,gBAAY4D,iCAAgBF,gBAAgB,MAAM,IAAIhG,iBAAAA,CAAAA;AAC5D,QAAMmG,cAAc,CAACC,UAAAA;AACnB,UAAM5D,WAAW;MACf;SACG9B,MAAMC,KAAKqC,SAASqD,iBAAiB,iBAAA,CAAA,EAAoBtE,IAC1D,CAACuE,OAAO,QAAQA,GAAGxD,aAAa,eAAA,CAAA,IAAoB;MAEtD/C,KAAK,GAAA;AACP,UAAMwG,OAAOjE,UAAUhC;AACvB,UAAMsB,OAAOW,eAAeC,UAAU4D,MAAMI,MAAM;AAIlD,QAAI5E,KAAKrB,SAAS,MAAMgG,KAAKhG,WAAWqB,KAAKrB,UAAU,CAAC,CAACgG,KAAK5E,KAAK,CAAC8E,IAAIC,UAAU9E,KAAK8E,KAAAA,MAAWD,EAAAA,IAAM;AACtGnE,gBAAU9B,OAAOoB,IAAAA;AACjBqE,iBAAWrE,IAAAA;IACb;EACF;AACA,SACE4B,8BAAAA,QAAA,cAAC4B,0BAAAA;IAAyB9C;IAAsB+B,MAAM,CAAA;KACpDb,8BAAAA,QAAA,cAACmD,OAAAA;IAAI7B,MAAK;IAAOjB,WAAU;IAAW+C,gBAAgBT;KACnDJ,QAAAA,CAAAA;AAIT;AAEA,IAAMc,oBAAoB,CAAC,EAAEJ,IAAIV,SAAQ,MAAqC;AAC5E,QAAM,EAAEzD,WAAW+B,KAAI,IAAKgB,oBAAoBJ,cAAAA;AAChD,QAAM6B,eAAWnB,uBAAQ,MAAM;IAACc;OAAOpC;KAAO;IAACoC;IAAIpC;GAAK;AAExD,SACEb,8BAAAA,QAAA,cAAC4B,0BAAAA;IAAyB9C;IAAsB+B,MAAMyC;KACnDf,QAAAA;AAGP;",
6
+ "names": ["import_react", "AttentionSchema", "S", "mutable", "Struct", "hasAttention", "Boolean", "isAncestor", "isRelated", "stringKey", "key", "join", "AttentionManager", "constructor", "initial", "ComplexMap", "_state", "create", "current", "length", "update", "keys", "Array", "from", "_map", "get", "object", "newObject", "set", "nextKey", "currentKey", "untracked", "currentRelatedTo", "nextRelatedTo", "currentRelatedKeys", "filter", "nextRelatedKeys", "prevRelatedKeys", "curr", "find", "next", "currentAncestorKeys", "slice", "map", "_", "i", "nextAncestorKeys", "prevAncestorKeys", "forEach", "_set", "attention", "getAttendables", "selector", "cursor", "acc", "closestAttendable", "closest", "attendableId", "getAttribute", "trigger", "document", "querySelector", "push", "parentElement", "Set", "attentionGlyphStyles", "presenceIconStyles", "PresenceOne", "React", "svg", "width", "height", "viewBox", "className", "fill", "xmlns", "circle", "cx", "cy", "r", "PresenceMany", "path", "d", "AttentionGlyph", "forwardRef", "presence", "classNames", "props", "forwardedRef", "span", "role", "mx", "ref", "ATTENTION_NAME", "ATTENABLE_ATTRIBUTE", "ATTENTION_SOURCE_ATTRIBUTE", "AttentionContextProvider", "useAttentionContext", "createContext", "UNKNOWN_ATTENDABLE", "useAttention", "useAttended", "useAttendableAttributes", "useMemo", "attributes", "useAttentionPath", "RootAttentionProvider", "children", "propsAttention", "onChange", "useDefaultValue", "handleFocus", "event", "querySelectorAll", "el", "prev", "target", "id", "index", "div", "onFocusCapture", "AttentionProvider", "nextPath"]
7
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var node_exports = {};
20
+ __export(node_exports, {
21
+ ATTENABLE_ATTRIBUTE: () => import_chunk_3BUNDA53.ATTENABLE_ATTRIBUTE,
22
+ ATTENTION_NAME: () => import_chunk_3BUNDA53.ATTENTION_NAME,
23
+ ATTENTION_SOURCE_ATTRIBUTE: () => import_chunk_3BUNDA53.ATTENTION_SOURCE_ATTRIBUTE,
24
+ AttentionGlyph: () => import_chunk_3BUNDA53.AttentionGlyph,
25
+ AttentionManager: () => import_chunk_3BUNDA53.AttentionManager,
26
+ AttentionProvider: () => import_chunk_3BUNDA53.AttentionProvider,
27
+ AttentionSchema: () => import_chunk_3BUNDA53.AttentionSchema,
28
+ RootAttentionProvider: () => import_chunk_3BUNDA53.RootAttentionProvider,
29
+ getAttendables: () => import_chunk_3BUNDA53.getAttendables,
30
+ useAttendableAttributes: () => import_chunk_3BUNDA53.useAttendableAttributes,
31
+ useAttended: () => import_chunk_3BUNDA53.useAttended,
32
+ useAttention: () => import_chunk_3BUNDA53.useAttention,
33
+ useAttentionContext: () => import_chunk_3BUNDA53.useAttentionContext,
34
+ useAttentionPath: () => import_chunk_3BUNDA53.useAttentionPath
35
+ });
36
+ module.exports = __toCommonJS(node_exports);
37
+ var import_chunk_3BUNDA53 = require("./chunk-3BUNDA53.cjs");
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ ATTENABLE_ATTRIBUTE,
41
+ ATTENTION_NAME,
42
+ ATTENTION_SOURCE_ATTRIBUTE,
43
+ AttentionGlyph,
44
+ AttentionManager,
45
+ AttentionProvider,
46
+ AttentionSchema,
47
+ RootAttentionProvider,
48
+ getAttendables,
49
+ useAttendableAttributes,
50
+ useAttended,
51
+ useAttention,
52
+ useAttentionContext,
53
+ useAttentionPath
54
+ });
55
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["index.cjs"],
4
+ "sourcesContent": ["import {\n ATTENABLE_ATTRIBUTE,\n ATTENTION_NAME,\n ATTENTION_SOURCE_ATTRIBUTE,\n AttentionGlyph,\n AttentionManager,\n AttentionProvider,\n AttentionSchema,\n RootAttentionProvider,\n getAttendables,\n useAttendableAttributes,\n useAttended,\n useAttention,\n useAttentionContext,\n useAttentionPath\n} from \"./chunk-3BUNDA53.cjs\";\nexport {\n ATTENABLE_ATTRIBUTE,\n ATTENTION_NAME,\n ATTENTION_SOURCE_ATTRIBUTE,\n AttentionGlyph,\n AttentionManager,\n AttentionProvider,\n AttentionSchema,\n RootAttentionProvider,\n getAttendables,\n useAttendableAttributes,\n useAttended,\n useAttention,\n useAttentionContext,\n useAttentionPath\n};\n//# sourceMappingURL=index.cjs.map\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAeO;",
6
+ "names": []
7
+ }
@@ -0,0 +1 @@
1
+ {"inputs":{"packages/ui/react-ui-attention/src/attention.ts":{"bytes":15893,"imports":[{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/ui/react-ui-attention/src/components/AttentionGlyph.tsx":{"bytes":7599,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"format":"esm"},"packages/ui/react-ui-attention/src/components/AttentionProvider.tsx":{"bytes":13329,"imports":[{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"packages/ui/react-ui-attention/src/attention.ts","kind":"import-statement","original":"../attention"}],"format":"esm"},"packages/ui/react-ui-attention/src/components/index.ts":{"bytes":644,"imports":[{"path":"packages/ui/react-ui-attention/src/components/AttentionGlyph.tsx","kind":"import-statement","original":"./AttentionGlyph"},{"path":"packages/ui/react-ui-attention/src/components/AttentionProvider.tsx","kind":"import-statement","original":"./AttentionProvider"}],"format":"esm"},"packages/ui/react-ui-attention/src/index.ts":{"bytes":597,"imports":[{"path":"packages/ui/react-ui-attention/src/attention.ts","kind":"import-statement","original":"./attention"},{"path":"packages/ui/react-ui-attention/src/components/index.ts","kind":"import-statement","original":"./components"}],"format":"esm"},"packages/ui/react-ui-attention/src/testing/decorators/withAttention.ts":{"bytes":1386,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"packages/ui/react-ui-attention/src/components/index.ts","kind":"import-statement","original":"../../components"}],"format":"esm"},"packages/ui/react-ui-attention/src/testing/decorators/index.ts":{"bytes":534,"imports":[{"path":"packages/ui/react-ui-attention/src/testing/decorators/withAttention.ts","kind":"import-statement","original":"./withAttention"}],"format":"esm"},"packages/ui/react-ui-attention/src/testing/index.ts":{"bytes":516,"imports":[{"path":"packages/ui/react-ui-attention/src/testing/decorators/index.ts","kind":"import-statement","original":"./decorators"}],"format":"esm"}},"outputs":{"packages/ui/react-ui-attention/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"packages/ui/react-ui-attention/dist/lib/node/index.cjs":{"imports":[{"path":"packages/ui/react-ui-attention/dist/lib/node/chunk-3BUNDA53.cjs","kind":"import-statement"}],"exports":["ATTENABLE_ATTRIBUTE","ATTENTION_NAME","ATTENTION_SOURCE_ATTRIBUTE","AttentionGlyph","AttentionManager","AttentionProvider","AttentionSchema","RootAttentionProvider","getAttendables","useAttendableAttributes","useAttended","useAttention","useAttentionContext","useAttentionPath"],"entryPoint":"packages/ui/react-ui-attention/src/index.ts","inputs":{"packages/ui/react-ui-attention/src/index.ts":{"bytesInOutput":0}},"bytes":671},"packages/ui/react-ui-attention/dist/lib/node/testing/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":697},"packages/ui/react-ui-attention/dist/lib/node/testing/index.cjs":{"imports":[{"path":"packages/ui/react-ui-attention/dist/lib/node/chunk-3BUNDA53.cjs","kind":"import-statement"},{"path":"react","kind":"import-statement","external":true}],"exports":["withAttention"],"entryPoint":"packages/ui/react-ui-attention/src/testing/index.ts","inputs":{"packages/ui/react-ui-attention/src/testing/decorators/withAttention.ts":{"bytesInOutput":164},"packages/ui/react-ui-attention/src/testing/decorators/index.ts":{"bytesInOutput":0},"packages/ui/react-ui-attention/src/testing/index.ts":{"bytesInOutput":0}},"bytes":367},"packages/ui/react-ui-attention/dist/lib/node/chunk-3BUNDA53.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":18546},"packages/ui/react-ui-attention/dist/lib/node/chunk-3BUNDA53.cjs":{"imports":[{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true}],"exports":["ATTENABLE_ATTRIBUTE","ATTENTION_NAME","ATTENTION_SOURCE_ATTRIBUTE","AttentionGlyph","AttentionManager","AttentionProvider","AttentionSchema","RootAttentionProvider","getAttendables","useAttendableAttributes","useAttended","useAttention","useAttentionContext","useAttentionPath"],"inputs":{"packages/ui/react-ui-attention/src/attention.ts":{"bytesInOutput":3486},"packages/ui/react-ui-attention/src/components/AttentionGlyph.tsx":{"bytesInOutput":2349},"packages/ui/react-ui-attention/src/components/AttentionProvider.tsx":{"bytesInOutput":2605},"packages/ui/react-ui-attention/src/components/index.ts":{"bytesInOutput":0}},"bytes":8981}}}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var testing_exports = {};
20
+ __export(testing_exports, {
21
+ withAttention: () => withAttention
22
+ });
23
+ module.exports = __toCommonJS(testing_exports);
24
+ var import_chunk_3BUNDA53 = require("../chunk-3BUNDA53.cjs");
25
+ var import_react = require("react");
26
+ var withAttention = (Story) => {
27
+ return (0, import_react.createElement)(import_chunk_3BUNDA53.RootAttentionProvider, {
28
+ children: (0, import_react.createElement)(Story)
29
+ });
30
+ };
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ withAttention
34
+ });
35
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/testing/decorators/withAttention.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Decorator } from '@storybook/react';\nimport { createElement } from 'react';\n\nimport { RootAttentionProvider } from '../../components';\n\nexport const withAttention: Decorator = (Story) => {\n return createElement(RootAttentionProvider, { children: createElement(Story) });\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAKA,mBAA8B;AAIvB,IAAMA,gBAA2B,CAACC,UAAAA;AACvC,aAAOC,4BAAcC,6CAAuB;IAAEC,cAAUF,4BAAcD,KAAAA;EAAO,CAAA;AAC/E;",
6
+ "names": ["withAttention", "Story", "createElement", "RootAttentionProvider", "children"]
7
+ }
@@ -0,0 +1,261 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+
3
+ // packages/ui/react-ui-attention/src/attention.ts
4
+ import { untracked } from "@preact/signals-core";
5
+ import { create, S } from "@dxos/echo-schema";
6
+ import { ComplexMap } from "@dxos/util";
7
+ var AttentionSchema = S.mutable(S.Struct({
8
+ hasAttention: S.Boolean,
9
+ isAncestor: S.Boolean,
10
+ isRelated: S.Boolean
11
+ }));
12
+ var stringKey = (key) => key.join(",");
13
+ var AttentionManager = class {
14
+ constructor(initial = []) {
15
+ // Each attention path is associated with an attention object.
16
+ // The lookup is not a reactive object to ensure that attention for each path is subscribable independently.
17
+ this._map = new ComplexMap(stringKey);
18
+ this._state = create({
19
+ current: []
20
+ });
21
+ if (initial.length > 0) {
22
+ this.update(initial);
23
+ }
24
+ }
25
+ /**
26
+ * Currently attended element.
27
+ */
28
+ get current() {
29
+ return this._state.current;
30
+ }
31
+ /**
32
+ * All attention paths.
33
+ */
34
+ keys() {
35
+ return Array.from(this._map.keys());
36
+ }
37
+ /**
38
+ * Get the attention state for a given path.
39
+ */
40
+ get(key) {
41
+ const object = this._map.get(key);
42
+ if (object) {
43
+ return object;
44
+ }
45
+ const newObject = create(AttentionSchema, {
46
+ hasAttention: false,
47
+ isAncestor: false,
48
+ isRelated: false
49
+ });
50
+ this._map.set(key, newObject);
51
+ return newObject;
52
+ }
53
+ /**
54
+ * Update the currently attended element.
55
+ */
56
+ update(nextKey) {
57
+ const currentKey = untracked(() => this.current);
58
+ const currentRelatedTo = currentKey[0];
59
+ const nextRelatedTo = nextKey[0];
60
+ this.get([
61
+ nextRelatedTo
62
+ ]);
63
+ const currentRelatedKeys = this.keys().filter((key) => key[0] === currentRelatedTo);
64
+ const nextRelatedKeys = this.keys().filter((key) => key[0] === nextRelatedTo && stringKey(key) !== stringKey(nextKey));
65
+ const prevRelatedKeys = currentRelatedKeys.filter((curr) => !nextRelatedKeys.find((next) => stringKey(curr) === stringKey(next)));
66
+ const currentAncestorKeys = currentKey.slice(1).map((_, i) => currentKey.slice(i + 1, currentKey.length));
67
+ const nextAncestorKeys = nextKey.slice(1).map((_, i) => nextKey.slice(i + 1, nextKey.length));
68
+ const prevAncestorKeys = currentAncestorKeys.filter((curr) => !nextAncestorKeys.find((next) => stringKey(curr) === stringKey(next)));
69
+ this._state.current = nextKey;
70
+ prevRelatedKeys.forEach((key) => this._set(key, {}));
71
+ prevAncestorKeys.forEach((key) => this._set(key, {}));
72
+ nextRelatedKeys.forEach((key) => this._set(key, {
73
+ isRelated: true
74
+ }));
75
+ nextAncestorKeys.forEach((key) => this._set(key, {
76
+ isAncestor: true
77
+ }));
78
+ this._set(nextKey, {
79
+ hasAttention: true
80
+ });
81
+ }
82
+ _set(key, attention) {
83
+ const object = this.get(key);
84
+ object.hasAttention = attention.hasAttention ?? false;
85
+ object.isAncestor = attention.isAncestor ?? false;
86
+ object.isRelated = attention.isRelated ?? false;
87
+ }
88
+ };
89
+ var getAttendables = (selector, cursor, acc = []) => {
90
+ const closestAttendable = cursor.closest(selector);
91
+ if (closestAttendable) {
92
+ const attendableId = closestAttendable.getAttribute("data-attendable-id");
93
+ if (!attendableId) {
94
+ const trigger = document.querySelector(`[aria-controls="${closestAttendable.getAttribute("id")}"]`);
95
+ if (!trigger) {
96
+ return acc;
97
+ } else {
98
+ return getAttendables(selector, trigger, acc);
99
+ }
100
+ } else {
101
+ acc.push(attendableId);
102
+ return !closestAttendable.parentElement ? acc : getAttendables(selector, closestAttendable.parentElement, acc);
103
+ }
104
+ }
105
+ return [
106
+ ...new Set(acc)
107
+ ];
108
+ };
109
+
110
+ // packages/ui/react-ui-attention/src/components/AttentionGlyph.tsx
111
+ import React, { forwardRef } from "react";
112
+ import { mx } from "@dxos/react-ui-theme";
113
+ var attentionGlyphStyles = "inline-block rounded-sm is-3 bs-3 bg-transparent text-accentText transition-colors [[data-attention=true]_&]:bg-accentSurface [[data-attention=true]_&]:text-inverse [[aria-current][data-attention=true]_&]:bg-accentSurface [[aria-current][data-attention=true]_&]:text-inverse";
114
+ var presenceIconStyles = "is-3 bs-3 group-[[aria-current]_&:hover]/attentionGlyphButton:hidden group-[[aria-current]_&:focus]/attentionGlyphButton:hidden group-[[data-attention=true]_&:hover]/attentionGlyphButton:hidden group-[[data-attention=true]_&:focus]/attentionGlyphButton:hidden group-[[aria-current][data-attention=true]_&:hover]/attentionGlyphButton:hidden group-[[aria-current][data-attention=true]_&:focus]/attentionGlyphButton:hidden";
115
+ var PresenceOne = () => {
116
+ return /* @__PURE__ */ React.createElement("svg", {
117
+ width: "12",
118
+ height: "12",
119
+ viewBox: "0 0 12 12",
120
+ className: presenceIconStyles,
121
+ fill: "none",
122
+ xmlns: "http://www.w3.org/2000/svg"
123
+ }, /* @__PURE__ */ React.createElement("circle", {
124
+ cx: "6",
125
+ cy: "6",
126
+ r: "2.5",
127
+ fill: "currentColor"
128
+ }));
129
+ };
130
+ var PresenceMany = () => {
131
+ return /* @__PURE__ */ React.createElement("svg", {
132
+ width: "12",
133
+ height: "12",
134
+ viewBox: "0 0 12 12",
135
+ className: presenceIconStyles,
136
+ fill: "none",
137
+ xmlns: "http://www.w3.org/2000/svg"
138
+ }, /* @__PURE__ */ React.createElement("path", {
139
+ 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",
140
+ fill: "currentColor"
141
+ }), /* @__PURE__ */ React.createElement("circle", {
142
+ cx: "4.25",
143
+ cy: "6",
144
+ r: "2.5",
145
+ fill: "currentColor"
146
+ }));
147
+ };
148
+ var AttentionGlyph = /* @__PURE__ */ forwardRef(({ presence, classNames, ...props }, forwardedRef) => {
149
+ return /* @__PURE__ */ React.createElement("span", {
150
+ role: "none",
151
+ ...props,
152
+ className: mx(attentionGlyphStyles, classNames),
153
+ ref: forwardedRef
154
+ }, presence === "many" && /* @__PURE__ */ React.createElement(PresenceMany, null), presence === "one" && /* @__PURE__ */ React.createElement(PresenceOne, null));
155
+ });
156
+
157
+ // packages/ui/react-ui-attention/src/components/AttentionProvider.tsx
158
+ import { createContext } from "@radix-ui/react-context";
159
+ import React2, { useMemo } from "react";
160
+ import { useDefaultValue } from "@dxos/react-ui";
161
+ var ATTENTION_NAME = "Attention";
162
+ var ATTENABLE_ATTRIBUTE = "data-attendable-id";
163
+ var ATTENTION_SOURCE_ATTRIBUTE = "data-is-attention-source";
164
+ var [AttentionContextProvider, useAttentionContext] = createContext(ATTENTION_NAME, {
165
+ attention: new AttentionManager(),
166
+ path: []
167
+ });
168
+ var UNKNOWN_ATTENDABLE = {
169
+ hasAttention: false,
170
+ isAncestor: false,
171
+ isRelated: false
172
+ };
173
+ var useAttention = (attendableId) => {
174
+ const { attention, path } = useAttentionContext(ATTENTION_NAME);
175
+ if (!attendableId) {
176
+ return UNKNOWN_ATTENDABLE;
177
+ }
178
+ const current = [
179
+ attendableId,
180
+ ...path
181
+ ];
182
+ return attention.get(current);
183
+ };
184
+ var useAttended = () => {
185
+ const { attention } = useAttentionContext(ATTENTION_NAME);
186
+ return attention.current;
187
+ };
188
+ var useAttendableAttributes = (attendableId) => {
189
+ const { hasAttention } = useAttention(attendableId);
190
+ return useMemo(() => {
191
+ const attributes = {
192
+ [ATTENABLE_ATTRIBUTE]: attendableId
193
+ };
194
+ if (hasAttention) {
195
+ attributes[ATTENTION_SOURCE_ATTRIBUTE] = "true";
196
+ }
197
+ return attributes;
198
+ }, [
199
+ attendableId,
200
+ hasAttention
201
+ ]);
202
+ };
203
+ var useAttentionPath = () => {
204
+ const { path } = useAttentionContext(ATTENTION_NAME);
205
+ return path;
206
+ };
207
+ var RootAttentionProvider = ({ children, attention: propsAttention, onChange }) => {
208
+ const attention = useDefaultValue(propsAttention, () => new AttentionManager());
209
+ const handleFocus = (event) => {
210
+ const selector = [
211
+ "[data-attendable-id]",
212
+ ...Array.from(document.querySelectorAll("[aria-controls]")).map((el) => `[id="${el.getAttribute("aria-controls")}"]`)
213
+ ].join(",");
214
+ const prev = attention.current;
215
+ const next = getAttendables(selector, event.target);
216
+ if (next.length > 0 && (prev.length !== next.length || !!prev.find((id, index) => next[index] !== id))) {
217
+ attention.update(next);
218
+ onChange?.(next);
219
+ }
220
+ };
221
+ return /* @__PURE__ */ React2.createElement(AttentionContextProvider, {
222
+ attention,
223
+ path: []
224
+ }, /* @__PURE__ */ React2.createElement("div", {
225
+ role: "none",
226
+ className: "contents",
227
+ onFocusCapture: handleFocus
228
+ }, children));
229
+ };
230
+ var AttentionProvider = ({ id, children }) => {
231
+ const { attention, path } = useAttentionContext(ATTENTION_NAME);
232
+ const nextPath = useMemo(() => [
233
+ id,
234
+ ...path
235
+ ], [
236
+ id,
237
+ path
238
+ ]);
239
+ return /* @__PURE__ */ React2.createElement(AttentionContextProvider, {
240
+ attention,
241
+ path: nextPath
242
+ }, children);
243
+ };
244
+
245
+ export {
246
+ AttentionSchema,
247
+ AttentionManager,
248
+ getAttendables,
249
+ AttentionGlyph,
250
+ ATTENTION_NAME,
251
+ ATTENABLE_ATTRIBUTE,
252
+ ATTENTION_SOURCE_ATTRIBUTE,
253
+ useAttentionContext,
254
+ useAttention,
255
+ useAttended,
256
+ useAttendableAttributes,
257
+ useAttentionPath,
258
+ RootAttentionProvider,
259
+ AttentionProvider
260
+ };
261
+ //# sourceMappingURL=chunk-XVOVHRJM.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/attention.ts", "../../../src/components/AttentionGlyph.tsx", "../../../src/components/AttentionProvider.tsx"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { untracked } from '@preact/signals-core';\n\nimport { create, type ReactiveObject, S } from '@dxos/echo-schema';\nimport { ComplexMap } from '@dxos/util';\n\nexport const AttentionSchema = S.mutable(\n S.Struct({\n hasAttention: S.Boolean,\n isAncestor: S.Boolean,\n isRelated: S.Boolean,\n }),\n);\n\nexport type Attention = S.Schema.Type<typeof AttentionSchema>;\n\n// TODO(wittjosiah): Use mosaic path utility?\nconst stringKey = (key: string[]) => key.join(',');\n\n/**\n * Manages attention state for an application.\n */\n// TODO(wittjosiah): Write unit tests.\nexport class AttentionManager {\n // Each attention path is associated with an attention object.\n // The lookup is not a reactive object to ensure that attention for each path is subscribable independently.\n private readonly _map = new ComplexMap<string[], ReactiveObject<Attention>>(stringKey);\n private readonly _state = create<{ current: string[] }>({ current: [] });\n\n constructor(initial: string[] = []) {\n if (initial.length > 0) {\n this.update(initial);\n }\n }\n\n /**\n * Currently attended element.\n */\n get current() {\n return this._state.current;\n }\n\n /**\n * All attention paths.\n */\n keys() {\n return Array.from(this._map.keys());\n }\n\n /**\n * Get the attention state for a given path.\n */\n get(key: string[]): ReactiveObject<Attention> {\n const object = this._map.get(key);\n if (object) {\n return object;\n }\n\n const newObject = create(AttentionSchema, { hasAttention: false, isAncestor: false, isRelated: false });\n this._map.set(key, newObject);\n return newObject;\n }\n\n /**\n * Update the currently attended element.\n */\n update(nextKey: string[]) {\n const currentKey = untracked(() => this.current);\n const currentRelatedTo = currentKey[0];\n const nextRelatedTo = nextKey[0];\n\n // Ensure related attention object is initialized.\n this.get([nextRelatedTo]);\n\n const currentRelatedKeys = this.keys().filter((key) => key[0] === currentRelatedTo);\n const nextRelatedKeys = this.keys().filter(\n (key) => key[0] === nextRelatedTo && stringKey(key) !== stringKey(nextKey),\n );\n const prevRelatedKeys = currentRelatedKeys.filter(\n (curr) => !nextRelatedKeys.find((next) => stringKey(curr) === stringKey(next)),\n );\n\n const currentAncestorKeys = currentKey.slice(1).map((_, i) => currentKey.slice(i + 1, currentKey.length));\n const nextAncestorKeys = nextKey.slice(1).map((_, i) => nextKey.slice(i + 1, nextKey.length));\n const prevAncestorKeys = currentAncestorKeys.filter(\n (curr) => !nextAncestorKeys.find((next) => stringKey(curr) === stringKey(next)),\n );\n\n this._state.current = nextKey;\n prevRelatedKeys.forEach((key) => this._set(key, {}));\n prevAncestorKeys.forEach((key) => this._set(key, {}));\n nextRelatedKeys.forEach((key) => this._set(key, { isRelated: true }));\n nextAncestorKeys.forEach((key) => this._set(key, { isAncestor: true }));\n this._set(nextKey, { hasAttention: true });\n }\n\n private _set(key: string[], attention: Partial<Attention>) {\n const object = this.get(key);\n object.hasAttention = attention.hasAttention ?? false;\n object.isAncestor = attention.isAncestor ?? false;\n object.isRelated = attention.isRelated ?? false;\n }\n}\n\n/**\n * Accumulates all attendable id’s between the element provided and the root, inclusive.\n */\nexport const getAttendables = (selector: string, cursor: Element, acc: string[] = []): string[] => {\n // Find the closest element with `data-attendable-id`, if any; start from cursor and move up the DOM tree.\n const closestAttendable = cursor.closest(selector);\n if (closestAttendable) {\n const attendableId = closestAttendable.getAttribute('data-attendable-id');\n if (!attendableId) {\n // this has an id of an aria-controls elsewhere on the page, move cursor to that trigger\n const trigger = document.querySelector(`[aria-controls=\"${closestAttendable.getAttribute('id')}\"]`);\n if (!trigger) {\n return acc;\n } else {\n return getAttendables(selector, trigger, acc);\n }\n } else {\n acc.push(attendableId);\n // (attempt tail recursion)\n return !closestAttendable.parentElement ? acc : getAttendables(selector, closestAttendable.parentElement, acc);\n }\n }\n\n return [...new Set(acc)];\n};\n\nexport type AttendableId = { attendableId?: string };\n\nexport type Related = { related?: boolean };\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Primitive } from '@radix-ui/react-primitive';\nimport React, { type ComponentPropsWithRef, forwardRef } from 'react';\n\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\nconst attentionGlyphStyles =\n 'inline-block rounded-sm is-3 bs-3 bg-transparent text-accentText transition-colors [[data-attention=true]_&]:bg-accentSurface [[data-attention=true]_&]:text-inverse [[aria-current][data-attention=true]_&]:bg-accentSurface [[aria-current][data-attention=true]_&]:text-inverse';\n\nconst presenceIconStyles =\n 'is-3 bs-3 group-[[aria-current]_&:hover]/attentionGlyphButton:hidden group-[[aria-current]_&:focus]/attentionGlyphButton:hidden group-[[data-attention=true]_&:hover]/attentionGlyphButton:hidden group-[[data-attention=true]_&:focus]/attentionGlyphButton:hidden group-[[aria-current][data-attention=true]_&:hover]/attentionGlyphButton:hidden group-[[aria-current][data-attention=true]_&:focus]/attentionGlyphButton:hidden';\n\nconst PresenceOne = () => {\n return (\n <svg\n width='12'\n height='12'\n viewBox='0 0 12 12'\n className={presenceIconStyles}\n fill='none'\n xmlns='http://www.w3.org/2000/svg'\n >\n <circle cx='6' cy='6' r='2.5' fill='currentColor' />\n </svg>\n );\n};\n\nconst PresenceMany = () => {\n return (\n <svg\n width='12'\n height='12'\n viewBox='0 0 12 12'\n className={presenceIconStyles}\n fill='none'\n xmlns='http://www.w3.org/2000/svg'\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\nexport type AttentionGlyphProps = {\n presence?: 'none' | 'one' | 'many';\n} & ThemedClassName<Omit<ComponentPropsWithRef<typeof Primitive.span>, 'children'>>;\n\nexport const AttentionGlyph = forwardRef<HTMLSpanElement, AttentionGlyphProps>(\n ({ presence, classNames, ...props }, forwardedRef) => {\n return (\n <span role='none' {...props} className={mx(attentionGlyphStyles, classNames)} ref={forwardedRef}>\n {presence === 'many' && <PresenceMany />}\n {presence === 'one' && <PresenceOne />}\n </span>\n );\n },\n);\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// NOTE(thure): The following unused imports quell TS2742 (“likely not portable”).\n\n// eslint-disable-next-line unused-imports/no-unused-imports\nimport { createContext, type Scope, type CreateScope } from '@radix-ui/react-context';\nimport React, { useMemo, type FocusEvent, type PropsWithChildren } from 'react';\n\nimport { useDefaultValue } from '@dxos/react-ui';\n\nimport { type Attention, AttentionManager, getAttendables } from '../attention';\n\nconst ATTENTION_NAME = 'Attention';\nconst ATTENABLE_ATTRIBUTE = 'data-attendable-id';\nconst ATTENTION_SOURCE_ATTRIBUTE = 'data-is-attention-source';\n\ntype AttentionContextValue = {\n attention: AttentionManager;\n path: string[];\n};\n\nconst [AttentionContextProvider, useAttentionContext] = createContext<AttentionContextValue>(ATTENTION_NAME, {\n attention: new AttentionManager(),\n path: [],\n});\n\nconst UNKNOWN_ATTENDABLE = { hasAttention: false, isAncestor: false, isRelated: false };\n\nconst useAttention = (attendableId?: string): Attention => {\n const { attention, path } = useAttentionContext(ATTENTION_NAME);\n if (!attendableId) {\n return UNKNOWN_ATTENDABLE;\n }\n\n const current = [attendableId, ...path];\n return attention.get(current);\n};\n\nconst useAttended = () => {\n const { attention } = useAttentionContext(ATTENTION_NAME);\n return attention.current;\n};\n\n/**\n * Computes HTML element attributes to apply so the attention system can detect changes\n * @param attendableId\n */\nconst useAttendableAttributes = (attendableId?: string) => {\n const { hasAttention } = useAttention(attendableId);\n return useMemo(() => {\n const attributes: Record<string, string | undefined> = { [ATTENABLE_ATTRIBUTE]: attendableId };\n if (hasAttention) {\n attributes[ATTENTION_SOURCE_ATTRIBUTE] = 'true';\n }\n\n return attributes;\n }, [attendableId, hasAttention]);\n};\n\nconst useAttentionPath = () => {\n const { path } = useAttentionContext(ATTENTION_NAME);\n return path;\n};\n\nconst RootAttentionProvider = ({\n children,\n attention: propsAttention,\n onChange,\n}: PropsWithChildren<\n Partial<{\n attention: AttentionManager;\n onChange: (nextAttended: string[]) => void;\n }>\n>) => {\n const attention = useDefaultValue(propsAttention, () => new AttentionManager());\n const handleFocus = (event: FocusEvent) => {\n const selector = [\n '[data-attendable-id]',\n ...Array.from(document.querySelectorAll('[aria-controls]')).map(\n (el) => `[id=\"${el.getAttribute('aria-controls')}\"]`,\n ),\n ].join(',');\n const prev = attention.current;\n const next = getAttendables(selector, event.target);\n // TODO(wittjosiah): Not allowing empty state means that the attended item is not strictly guaranteed to be in the DOM.\n // Currently this depends on the deck in order to ensure that when the attended item is removed something else is attended.\n // Only update state if the result is different and not empty.\n if (next.length > 0 && (prev.length !== next.length || !!prev.find((id, index) => next[index] !== id))) {\n attention.update(next);\n onChange?.(next);\n }\n };\n return (\n <AttentionContextProvider attention={attention} path={[]}>\n <div role='none' className='contents' onFocusCapture={handleFocus}>\n {children}\n </div>\n </AttentionContextProvider>\n );\n};\n\nconst AttentionProvider = ({ id, children }: PropsWithChildren<{ id: string }>) => {\n const { attention, path } = useAttentionContext(ATTENTION_NAME);\n const nextPath = useMemo(() => [id, ...path], [id, path]);\n\n return (\n <AttentionContextProvider attention={attention} path={nextPath}>\n {children}\n </AttentionContextProvider>\n );\n};\n\nexport {\n RootAttentionProvider,\n AttentionProvider,\n useAttentionContext,\n useAttention,\n useAttended,\n useAttendableAttributes,\n useAttentionPath,\n ATTENTION_NAME,\n ATTENABLE_ATTRIBUTE,\n ATTENTION_SOURCE_ATTRIBUTE,\n};\n"],
5
+ "mappings": ";;;AAIA,SAASA,iBAAiB;AAE1B,SAASC,QAA6BC,SAAS;AAC/C,SAASC,kBAAkB;AAEpB,IAAMC,kBAAkBC,EAAEC,QAC/BD,EAAEE,OAAO;EACPC,cAAcH,EAAEI;EAChBC,YAAYL,EAAEI;EACdE,WAAWN,EAAEI;AACf,CAAA,CAAA;AAMF,IAAMG,YAAY,CAACC,QAAkBA,IAAIC,KAAK,GAAA;AAMvC,IAAMC,mBAAN,MAAMA;EAMXC,YAAYC,UAAoB,CAAA,GAAI;AAHnBC;;gBAAO,IAAIC,WAAgDP,SAAAA;AAC3DQ,kBAASC,OAA8B;MAAEC,S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S;AACvB,UAAMwB,OAAOC,eAAeX,UAAUD,MAAMa,MAAM;AAIlD,QAAIF,KAAKG,SAAS,MAAMJ,KAAKI,WAAWH,KAAKG,UAAU,CAAC,CAACJ,KAAKK,KAAK,CAACC,IAAIC,UAAUN,KAAKM,KAAAA,MAAWD,EAAAA,IAAM;AACtGtC,gBAAUwC,OAAOP,IAAAA;AACjBd,iBAAWc,IAAAA;IACb;EACF;AACA,SACE,gBAAAQ,OAAA,cAAC5C,0BAAAA;IAAyBG;IAAsBE,MAAM,CAAA;KACpD,gBAAAuC,OAAA,cAACC,OAAAA;IAAIC,MAAK;IAAOC,WAAU;IAAWC,gBAAgBxB;KACnDJ,QAAAA,CAAAA;AAIT;AAEA,IAAM6B,oBAAoB,CAAC,EAAER,IAAIrB,SAAQ,MAAqC;AAC5E,QAAM,EAAEjB,WAAWE,KAAI,IAAKJ,oBAAoBJ,cAAAA;AAChD,QAAMqD,WAAWlC,QAAQ,MAAM;IAACyB;OAAOpC;KAAO;IAACoC;IAAIpC;GAAK;AAExD,SACE,gBAAAuC,OAAA,cAAC5C,0BAAAA;IAAyBG;IAAsBE,MAAM6C;KACnD9B,QAAAA;AAGP;",
6
+ "names": ["untracked", "create", "S", "ComplexMap", "AttentionSchema", "S", "mutable", "Struct", "hasAttention", "Boolean", "isAncestor", "isRelated", "stringKey", "key", "join", "AttentionManager", "constructor", "initial", "_map", "ComplexMap", "_state", "create", "current", "length", "update", "keys", "Array", "from", "get", "object", "newObject", "set", "nextKey", "currentKey", "untracked", "currentRelatedTo", "nextRelatedTo", "currentRelatedKeys", "filter", "nextRelatedKeys", "prevRelatedKeys", "curr", "find", "next", "currentAncestorKeys", "slice", "map", "_", "i", "nextAncestorKeys", "prevAncestorKeys", "forEach", "_set", "attention", "getAttendables", "selector", "cursor", "acc", "closestAttendable", "closest", "attendableId", "getAttribute", "trigger", "document", "querySelector", "push", "parentElement", "Set", "React", "forwardRef", "mx", "attentionGlyphStyles", "presenceIconStyles", "PresenceOne", "svg", "width", "height", "viewBox", "className", "fill", "xmlns", "circle", "cx", "cy", "r", "PresenceMany", "path", "d", "AttentionGlyph", "forwardRef", "presence", "classNames", "props", "forwardedRef", "span", "role", "mx", "ref", "createContext", "React", "useMemo", "useDefaultValue", "ATTENTION_NAME", "ATTENABLE_ATTRIBUTE", "ATTENTION_SOURCE_ATTRIBUTE", "AttentionContextProvider", "useAttentionContext", "createContext", "attention", "AttentionManager", "path", "UNKNOWN_ATTENDABLE", "hasAttention", "isAncestor", "isRelated", "useAttention", "attendableId", "current", "get", "useAttended", "useAttendableAttributes", "useMemo", "attributes", "useAttentionPath", "RootAttentionProvider", "children", "propsAttention", "onChange", "useDefaultValue", "handleFocus", "event", "selector", "Array", "from", "document", "querySelectorAll", "map", "el", "getAttribute", "join", "prev", "next", "getAttendables", "target", "length", "find", "id", "index", "update", "React", "div", "role", "className", "onFocusCapture", "AttentionProvider", "nextPath"]
7
+ }
@@ -0,0 +1,34 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ ATTENABLE_ATTRIBUTE,
4
+ ATTENTION_NAME,
5
+ ATTENTION_SOURCE_ATTRIBUTE,
6
+ AttentionGlyph,
7
+ AttentionManager,
8
+ AttentionProvider,
9
+ AttentionSchema,
10
+ RootAttentionProvider,
11
+ getAttendables,
12
+ useAttendableAttributes,
13
+ useAttended,
14
+ useAttention,
15
+ useAttentionContext,
16
+ useAttentionPath
17
+ } from "./chunk-XVOVHRJM.mjs";
18
+ export {
19
+ ATTENABLE_ATTRIBUTE,
20
+ ATTENTION_NAME,
21
+ ATTENTION_SOURCE_ATTRIBUTE,
22
+ AttentionGlyph,
23
+ AttentionManager,
24
+ AttentionProvider,
25
+ AttentionSchema,
26
+ RootAttentionProvider,
27
+ getAttendables,
28
+ useAttendableAttributes,
29
+ useAttended,
30
+ useAttention,
31
+ useAttentionContext,
32
+ useAttentionPath
33
+ };
34
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1 @@
1
+ {"inputs":{"packages/ui/react-ui-attention/src/attention.ts":{"bytes":15893,"imports":[{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/ui/react-ui-attention/src/components/AttentionGlyph.tsx":{"bytes":7599,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"format":"esm"},"packages/ui/react-ui-attention/src/components/AttentionProvider.tsx":{"bytes":13329,"imports":[{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"packages/ui/react-ui-attention/src/attention.ts","kind":"import-statement","original":"../attention"}],"format":"esm"},"packages/ui/react-ui-attention/src/components/index.ts":{"bytes":644,"imports":[{"path":"packages/ui/react-ui-attention/src/components/AttentionGlyph.tsx","kind":"import-statement","original":"./AttentionGlyph"},{"path":"packages/ui/react-ui-attention/src/components/AttentionProvider.tsx","kind":"import-statement","original":"./AttentionProvider"}],"format":"esm"},"packages/ui/react-ui-attention/src/index.ts":{"bytes":597,"imports":[{"path":"packages/ui/react-ui-attention/src/attention.ts","kind":"import-statement","original":"./attention"},{"path":"packages/ui/react-ui-attention/src/components/index.ts","kind":"import-statement","original":"./components"}],"format":"esm"},"packages/ui/react-ui-attention/src/testing/decorators/withAttention.ts":{"bytes":1386,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"packages/ui/react-ui-attention/src/components/index.ts","kind":"import-statement","original":"../../components"}],"format":"esm"},"packages/ui/react-ui-attention/src/testing/decorators/index.ts":{"bytes":534,"imports":[{"path":"packages/ui/react-ui-attention/src/testing/decorators/withAttention.ts","kind":"import-statement","original":"./withAttention"}],"format":"esm"},"packages/ui/react-ui-attention/src/testing/index.ts":{"bytes":516,"imports":[{"path":"packages/ui/react-ui-attention/src/testing/decorators/index.ts","kind":"import-statement","original":"./decorators"}],"format":"esm"}},"outputs":{"packages/ui/react-ui-attention/dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"packages/ui/react-ui-attention/dist/lib/node-esm/index.mjs":{"imports":[{"path":"packages/ui/react-ui-attention/dist/lib/node-esm/chunk-XVOVHRJM.mjs","kind":"import-statement"}],"exports":["ATTENABLE_ATTRIBUTE","ATTENTION_NAME","ATTENTION_SOURCE_ATTRIBUTE","AttentionGlyph","AttentionManager","AttentionProvider","AttentionSchema","RootAttentionProvider","getAttendables","useAttendableAttributes","useAttended","useAttention","useAttentionContext","useAttentionPath"],"entryPoint":"packages/ui/react-ui-attention/src/index.ts","inputs":{"packages/ui/react-ui-attention/src/index.ts":{"bytesInOutput":0}},"bytes":763},"packages/ui/react-ui-attention/dist/lib/node-esm/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":698},"packages/ui/react-ui-attention/dist/lib/node-esm/testing/index.mjs":{"imports":[{"path":"packages/ui/react-ui-attention/dist/lib/node-esm/chunk-XVOVHRJM.mjs","kind":"import-statement"},{"path":"react","kind":"import-statement","external":true}],"exports":["withAttention"],"entryPoint":"packages/ui/react-ui-attention/src/testing/index.ts","inputs":{"packages/ui/react-ui-attention/src/testing/decorators/withAttention.ts":{"bytesInOutput":164},"packages/ui/react-ui-attention/src/testing/decorators/index.ts":{"bytesInOutput":0},"packages/ui/react-ui-attention/src/testing/index.ts":{"bytesInOutput":0}},"bytes":459},"packages/ui/react-ui-attention/dist/lib/node-esm/chunk-XVOVHRJM.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":18548},"packages/ui/react-ui-attention/dist/lib/node-esm/chunk-XVOVHRJM.mjs":{"imports":[{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true}],"exports":["ATTENABLE_ATTRIBUTE","ATTENTION_NAME","ATTENTION_SOURCE_ATTRIBUTE","AttentionGlyph","AttentionManager","AttentionProvider","AttentionSchema","RootAttentionProvider","getAttendables","useAttendableAttributes","useAttended","useAttention","useAttentionContext","useAttentionPath"],"inputs":{"packages/ui/react-ui-attention/src/attention.ts":{"bytesInOutput":3486},"packages/ui/react-ui-attention/src/components/AttentionGlyph.tsx":{"bytesInOutput":2349},"packages/ui/react-ui-attention/src/components/AttentionProvider.tsx":{"bytesInOutput":2605},"packages/ui/react-ui-attention/src/components/index.ts":{"bytesInOutput":0}},"bytes":9074}}}
@@ -0,0 +1,16 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ RootAttentionProvider
4
+ } from "../chunk-XVOVHRJM.mjs";
5
+
6
+ // packages/ui/react-ui-attention/src/testing/decorators/withAttention.ts
7
+ import { createElement } from "react";
8
+ var withAttention = (Story) => {
9
+ return createElement(RootAttentionProvider, {
10
+ children: createElement(Story)
11
+ });
12
+ };
13
+ export {
14
+ withAttention
15
+ };
16
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/testing/decorators/withAttention.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Decorator } from '@storybook/react';\nimport { createElement } from 'react';\n\nimport { RootAttentionProvider } from '../../components';\n\nexport const withAttention: Decorator = (Story) => {\n return createElement(RootAttentionProvider, { children: createElement(Story) });\n};\n"],
5
+ "mappings": ";;;;;;AAKA,SAASA,qBAAqB;AAIvB,IAAMC,gBAA2B,CAACC,UAAAA;AACvC,SAAOC,cAAcC,uBAAuB;IAAEC,UAAUF,cAAcD,KAAAA;EAAO,CAAA;AAC/E;",
6
+ "names": ["createElement", "withAttention", "Story", "createElement", "RootAttentionProvider", "children"]
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-attention",
3
- "version": "0.7.1-staging.8709ba7",
3
+ "version": "0.7.2-main.f1adc9f",
4
4
  "description": "Signifier components and providers for attention system.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -10,11 +10,13 @@
10
10
  "exports": {
11
11
  ".": {
12
12
  "types": "./dist/types/src/index.d.ts",
13
- "browser": "./dist/lib/browser/index.mjs"
13
+ "browser": "./dist/lib/browser/index.mjs",
14
+ "node": "./dist/lib/node-esm/index.mjs"
14
15
  },
15
16
  "./testing": {
16
17
  "types": "./dist/types/src/testing/index.d.ts",
17
- "browser": "./dist/lib/browser/testing/index.mjs"
18
+ "browser": "./dist/lib/browser/testing/index.mjs",
19
+ "node": "./dist/lib/node-esm/testing/index.mjs"
18
20
  }
19
21
  },
20
22
  "types": "dist/types/src/index.d.ts",
@@ -38,8 +40,8 @@
38
40
  "@radix-ui/react-primitive": "^1.0.2",
39
41
  "@radix-ui/react-slot": "^1.0.1",
40
42
  "@radix-ui/react-use-controllable-state": "^1.0.0",
41
- "@dxos/echo-schema": "0.7.1-staging.8709ba7",
42
- "@dxos/util": "0.7.1-staging.8709ba7"
43
+ "@dxos/echo-schema": "0.7.2-main.f1adc9f",
44
+ "@dxos/util": "0.7.2-main.f1adc9f"
43
45
  },
44
46
  "devDependencies": {
45
47
  "@phosphor-icons/react": "^2.1.5",
@@ -48,18 +50,18 @@
48
50
  "react": "~18.2.0",
49
51
  "react-dom": "~18.2.0",
50
52
  "vite": "5.4.7",
51
- "@dxos/app-graph": "0.7.1-staging.8709ba7",
52
- "@dxos/random": "0.7.1-staging.8709ba7",
53
- "@dxos/react-ui": "0.7.1-staging.8709ba7",
54
- "@dxos/react-ui-theme": "0.7.1-staging.8709ba7",
55
- "@dxos/storybook-utils": "0.7.1-staging.8709ba7"
53
+ "@dxos/random": "0.7.2-main.f1adc9f",
54
+ "@dxos/react-ui": "0.7.2-main.f1adc9f",
55
+ "@dxos/app-graph": "0.7.2-main.f1adc9f",
56
+ "@dxos/react-ui-theme": "0.7.2-main.f1adc9f",
57
+ "@dxos/storybook-utils": "0.7.2-main.f1adc9f"
56
58
  },
57
59
  "peerDependencies": {
58
60
  "@phosphor-icons/react": "^2.1.5",
59
61
  "react": "~18.2.0",
60
62
  "react-dom": "~18.2.0",
61
- "@dxos/react-ui-theme": "0.7.1-staging.8709ba7",
62
- "@dxos/react-ui": "0.7.1-staging.8709ba7"
63
+ "@dxos/react-ui": "0.7.2-main.f1adc9f",
64
+ "@dxos/react-ui-theme": "0.7.2-main.f1adc9f"
63
65
  },
64
66
  "publishConfig": {
65
67
  "access": "public"