@dxos/react-ui-attention 0.6.14-main.7bd9c89 → 0.6.14-staging.934c9de

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/lib/browser/chunk-GABVXGFU.mjs +259 -0
  2. package/dist/lib/browser/chunk-GABVXGFU.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +19 -164
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +15 -0
  7. package/dist/lib/browser/testing/index.mjs.map +7 -0
  8. package/dist/types/src/attention.d.ts +37 -0
  9. package/dist/types/src/attention.d.ts.map +1 -0
  10. package/dist/types/src/attention.test.d.ts +2 -0
  11. package/dist/types/src/attention.test.d.ts.map +1 -0
  12. package/dist/types/src/components/AttentionGlyph.stories.d.ts +3 -2
  13. package/dist/types/src/components/AttentionGlyph.stories.d.ts.map +1 -1
  14. package/dist/types/src/components/AttentionProvider.d.ts +4 -12
  15. package/dist/types/src/components/AttentionProvider.d.ts.map +1 -1
  16. package/dist/types/src/components/AttentionProvider.stories.d.ts +10 -0
  17. package/dist/types/src/components/AttentionProvider.stories.d.ts.map +1 -0
  18. package/dist/types/src/index.d.ts +1 -0
  19. package/dist/types/src/index.d.ts.map +1 -1
  20. package/dist/types/src/testing/decorators/index.d.ts +2 -0
  21. package/dist/types/src/testing/decorators/index.d.ts.map +1 -0
  22. package/dist/types/src/testing/decorators/withAttention.d.ts +3 -0
  23. package/dist/types/src/testing/decorators/withAttention.d.ts.map +1 -0
  24. package/dist/types/src/testing/index.d.ts +2 -0
  25. package/dist/types/src/testing/index.d.ts.map +1 -0
  26. package/package.json +23 -13
  27. package/src/attention.test.ts +58 -0
  28. package/src/attention.ts +132 -0
  29. package/src/components/AttentionGlyph.stories.tsx +7 -4
  30. package/src/components/AttentionProvider.stories.tsx +41 -0
  31. package/src/components/AttentionProvider.tsx +14 -58
  32. package/src/index.ts +1 -0
  33. package/src/testing/decorators/index.ts +5 -0
  34. package/src/testing/decorators/withAttention.ts +12 -0
  35. package/src/testing/index.ts +5 -0
@@ -0,0 +1,259 @@
1
+ // packages/ui/react-ui-attention/src/attention.ts
2
+ import { untracked } from "@preact/signals-core";
3
+ import { create, S } from "@dxos/echo-schema";
4
+ import { ComplexMap } from "@dxos/util";
5
+ var AttentionSchema = S.mutable(S.Struct({
6
+ hasAttention: S.Boolean,
7
+ isAncestor: S.Boolean,
8
+ isRelated: S.Boolean
9
+ }));
10
+ var stringKey = (key) => key.join(",");
11
+ var AttentionManager = class {
12
+ constructor(initial = []) {
13
+ // Each attention path is associated with an attention object.
14
+ // The lookup is not a reactive object to ensure that attention for each path is subscribable independently.
15
+ this._map = new ComplexMap(stringKey);
16
+ this._state = create({
17
+ current: []
18
+ });
19
+ if (initial.length > 0) {
20
+ this.update(initial);
21
+ }
22
+ }
23
+ /**
24
+ * Currently attended element.
25
+ */
26
+ get current() {
27
+ return this._state.current;
28
+ }
29
+ /**
30
+ * All attention paths.
31
+ */
32
+ keys() {
33
+ return Array.from(this._map.keys());
34
+ }
35
+ /**
36
+ * Get the attention state for a given path.
37
+ */
38
+ get(key) {
39
+ const object = this._map.get(key);
40
+ if (object) {
41
+ return object;
42
+ }
43
+ const newObject = create(AttentionSchema, {
44
+ hasAttention: false,
45
+ isAncestor: false,
46
+ isRelated: false
47
+ });
48
+ this._map.set(key, newObject);
49
+ return newObject;
50
+ }
51
+ /**
52
+ * Update the currently attended element.
53
+ */
54
+ update(nextKey) {
55
+ const currentKey = untracked(() => this.current);
56
+ const currentRelatedTo = currentKey[0];
57
+ const nextRelatedTo = nextKey[0];
58
+ this.get([
59
+ nextRelatedTo
60
+ ]);
61
+ const currentRelatedKeys = this.keys().filter((key) => key[0] === currentRelatedTo);
62
+ const nextRelatedKeys = this.keys().filter((key) => key[0] === nextRelatedTo && stringKey(key) !== stringKey(nextKey));
63
+ const prevRelatedKeys = currentRelatedKeys.filter((curr) => !nextRelatedKeys.find((next) => stringKey(curr) === stringKey(next)));
64
+ const currentAncestorKeys = currentKey.slice(1).map((_, i) => currentKey.slice(i + 1, currentKey.length));
65
+ const nextAncestorKeys = nextKey.slice(1).map((_, i) => nextKey.slice(i + 1, nextKey.length));
66
+ const prevAncestorKeys = currentAncestorKeys.filter((curr) => !nextAncestorKeys.find((next) => stringKey(curr) === stringKey(next)));
67
+ this._state.current = nextKey;
68
+ prevRelatedKeys.forEach((key) => this._set(key, {}));
69
+ prevAncestorKeys.forEach((key) => this._set(key, {}));
70
+ nextRelatedKeys.forEach((key) => this._set(key, {
71
+ isRelated: true
72
+ }));
73
+ nextAncestorKeys.forEach((key) => this._set(key, {
74
+ isAncestor: true
75
+ }));
76
+ this._set(nextKey, {
77
+ hasAttention: true
78
+ });
79
+ }
80
+ _set(key, attention) {
81
+ const object = this.get(key);
82
+ object.hasAttention = attention.hasAttention ?? false;
83
+ object.isAncestor = attention.isAncestor ?? false;
84
+ object.isRelated = attention.isRelated ?? false;
85
+ }
86
+ };
87
+ var getAttendables = (selector, cursor, acc = []) => {
88
+ const closestAttendable = cursor.closest(selector);
89
+ if (closestAttendable) {
90
+ const attendableId = closestAttendable.getAttribute("data-attendable-id");
91
+ if (!attendableId) {
92
+ const trigger = document.querySelector(`[aria-controls="${closestAttendable.getAttribute("id")}"]`);
93
+ if (!trigger) {
94
+ return acc;
95
+ } else {
96
+ return getAttendables(selector, trigger, acc);
97
+ }
98
+ } else {
99
+ acc.push(attendableId);
100
+ return !closestAttendable.parentElement ? acc : getAttendables(selector, closestAttendable.parentElement, acc);
101
+ }
102
+ }
103
+ return [
104
+ ...new Set(acc)
105
+ ];
106
+ };
107
+
108
+ // packages/ui/react-ui-attention/src/components/AttentionGlyph.tsx
109
+ import React, { forwardRef } from "react";
110
+ import { mx } from "@dxos/react-ui-theme";
111
+ 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";
112
+ 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";
113
+ var PresenceOne = () => {
114
+ return /* @__PURE__ */ React.createElement("svg", {
115
+ width: "12",
116
+ height: "12",
117
+ viewBox: "0 0 12 12",
118
+ className: presenceIconStyles,
119
+ fill: "none",
120
+ xmlns: "http://www.w3.org/2000/svg"
121
+ }, /* @__PURE__ */ React.createElement("circle", {
122
+ cx: "6",
123
+ cy: "6",
124
+ r: "2.5",
125
+ fill: "currentColor"
126
+ }));
127
+ };
128
+ var PresenceMany = () => {
129
+ return /* @__PURE__ */ React.createElement("svg", {
130
+ width: "12",
131
+ height: "12",
132
+ viewBox: "0 0 12 12",
133
+ className: presenceIconStyles,
134
+ fill: "none",
135
+ xmlns: "http://www.w3.org/2000/svg"
136
+ }, /* @__PURE__ */ React.createElement("path", {
137
+ 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",
138
+ fill: "currentColor"
139
+ }), /* @__PURE__ */ React.createElement("circle", {
140
+ cx: "4.25",
141
+ cy: "6",
142
+ r: "2.5",
143
+ fill: "currentColor"
144
+ }));
145
+ };
146
+ var AttentionGlyph = /* @__PURE__ */ forwardRef(({ presence, classNames, ...props }, forwardedRef) => {
147
+ return /* @__PURE__ */ React.createElement("span", {
148
+ role: "none",
149
+ ...props,
150
+ className: mx(attentionGlyphStyles, classNames),
151
+ ref: forwardedRef
152
+ }, presence === "many" && /* @__PURE__ */ React.createElement(PresenceMany, null), presence === "one" && /* @__PURE__ */ React.createElement(PresenceOne, null));
153
+ });
154
+
155
+ // packages/ui/react-ui-attention/src/components/AttentionProvider.tsx
156
+ import { createContext } from "@radix-ui/react-context";
157
+ import React2, { useMemo } from "react";
158
+ import { useDefaultValue } from "@dxos/react-ui";
159
+ var ATTENTION_NAME = "Attention";
160
+ var ATTENABLE_ATTRIBUTE = "data-attendable-id";
161
+ var ATTENTION_SOURCE_ATTRIBUTE = "data-is-attention-source";
162
+ var [AttentionContextProvider, useAttentionContext] = createContext(ATTENTION_NAME, {
163
+ attention: new AttentionManager(),
164
+ path: []
165
+ });
166
+ var UNKNOWN_ATTENDABLE = {
167
+ hasAttention: false,
168
+ isAncestor: false,
169
+ isRelated: false
170
+ };
171
+ var useAttention = (attendableId) => {
172
+ const { attention, path } = useAttentionContext(ATTENTION_NAME);
173
+ if (!attendableId) {
174
+ return UNKNOWN_ATTENDABLE;
175
+ }
176
+ const current = [
177
+ attendableId,
178
+ ...path
179
+ ];
180
+ return attention.get(current);
181
+ };
182
+ var useAttended = () => {
183
+ const { attention } = useAttentionContext(ATTENTION_NAME);
184
+ return attention.current;
185
+ };
186
+ var useAttendableAttributes = (attendableId) => {
187
+ const { hasAttention } = useAttention(attendableId);
188
+ return useMemo(() => {
189
+ const attributes = {
190
+ [ATTENABLE_ATTRIBUTE]: attendableId
191
+ };
192
+ if (hasAttention) {
193
+ attributes[ATTENTION_SOURCE_ATTRIBUTE] = "true";
194
+ }
195
+ return attributes;
196
+ }, [
197
+ attendableId,
198
+ hasAttention
199
+ ]);
200
+ };
201
+ var useAttentionPath = () => {
202
+ const { path } = useAttentionContext(ATTENTION_NAME);
203
+ return path;
204
+ };
205
+ var RootAttentionProvider = ({ children, attention: propsAttention, onChange }) => {
206
+ const attention = useDefaultValue(propsAttention, () => new AttentionManager());
207
+ const handleFocus = (event) => {
208
+ const selector = [
209
+ "[data-attendable-id]",
210
+ ...Array.from(document.querySelectorAll("[aria-controls]")).map((el) => `[id="${el.getAttribute("aria-controls")}"]`)
211
+ ].join(",");
212
+ const prev = attention.current;
213
+ const next = getAttendables(selector, event.target);
214
+ if (next.length > 0 && (prev.length !== next.length || !!prev.find((id, index) => next[index] !== id))) {
215
+ attention.update(next);
216
+ onChange?.(next);
217
+ }
218
+ };
219
+ return /* @__PURE__ */ React2.createElement(AttentionContextProvider, {
220
+ attention,
221
+ path: []
222
+ }, /* @__PURE__ */ React2.createElement("div", {
223
+ role: "none",
224
+ className: "contents",
225
+ onFocusCapture: handleFocus
226
+ }, children));
227
+ };
228
+ var AttentionProvider = ({ id, children }) => {
229
+ const { attention, path } = useAttentionContext(ATTENTION_NAME);
230
+ const nextPath = useMemo(() => [
231
+ id,
232
+ ...path
233
+ ], [
234
+ id,
235
+ path
236
+ ]);
237
+ return /* @__PURE__ */ React2.createElement(AttentionContextProvider, {
238
+ attention,
239
+ path: nextPath
240
+ }, children);
241
+ };
242
+
243
+ export {
244
+ AttentionSchema,
245
+ AttentionManager,
246
+ getAttendables,
247
+ AttentionGlyph,
248
+ ATTENTION_NAME,
249
+ ATTENABLE_ATTRIBUTE,
250
+ ATTENTION_SOURCE_ATTRIBUTE,
251
+ useAttentionContext,
252
+ useAttention,
253
+ useAttended,
254
+ useAttendableAttributes,
255
+ useAttentionPath,
256
+ RootAttentionProvider,
257
+ AttentionProvider
258
+ };
259
+ //# sourceMappingURL=chunk-GABVXGFU.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", "//\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,SAAS,CAAA;IAAG,CAAA;AAGpE,QAAIL,QA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AAMa,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
+ }
@@ -1,174 +1,29 @@
1
- // packages/ui/react-ui-attention/src/components/AttentionGlyph.tsx
2
- import React, { forwardRef } from "react";
3
- import { mx } from "@dxos/react-ui-theme";
4
- 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";
5
- 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";
6
- var PresenceOne = () => {
7
- return /* @__PURE__ */ React.createElement("svg", {
8
- width: "12",
9
- height: "12",
10
- viewBox: "0 0 12 12",
11
- className: presenceIconStyles,
12
- fill: "none",
13
- xmlns: "http://www.w3.org/2000/svg"
14
- }, /* @__PURE__ */ React.createElement("circle", {
15
- cx: "6",
16
- cy: "6",
17
- r: "2.5",
18
- fill: "currentColor"
19
- }));
20
- };
21
- var PresenceMany = () => {
22
- return /* @__PURE__ */ React.createElement("svg", {
23
- width: "12",
24
- height: "12",
25
- viewBox: "0 0 12 12",
26
- className: presenceIconStyles,
27
- fill: "none",
28
- xmlns: "http://www.w3.org/2000/svg"
29
- }, /* @__PURE__ */ React.createElement("path", {
30
- 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",
31
- fill: "currentColor"
32
- }), /* @__PURE__ */ React.createElement("circle", {
33
- cx: "4.25",
34
- cy: "6",
35
- r: "2.5",
36
- fill: "currentColor"
37
- }));
38
- };
39
- var AttentionGlyph = /* @__PURE__ */ forwardRef(({ presence, classNames, ...props }, forwardedRef) => {
40
- return /* @__PURE__ */ React.createElement("span", {
41
- role: "none",
42
- ...props,
43
- className: mx(attentionGlyphStyles, classNames),
44
- ref: forwardedRef
45
- }, presence === "many" && /* @__PURE__ */ React.createElement(PresenceMany, null), presence === "one" && /* @__PURE__ */ React.createElement(PresenceOne, null));
46
- });
47
-
48
- // packages/ui/react-ui-attention/src/components/AttentionProvider.tsx
49
- import { createContext } from "@radix-ui/react-context";
50
- import React2, { useMemo } from "react";
51
- import { create } from "@dxos/echo-schema";
52
- import { useDefaultValue } from "@dxos/react-ui";
53
- var ATTENTION_NAME = "Attention";
54
- var ATTENABLE_ATTRIBUTE = "data-attendable-id";
55
- var ATTENTION_SOURCE_ATTRIBUTE = "data-is-attention-source";
56
- var [AttentionContextProvider, useAttentionContext] = createContext(ATTENTION_NAME, {
57
- attention: {
58
- attended: []
59
- },
60
- path: []
61
- });
62
- var useAttention = (attendableId) => {
63
- const { attention, path } = useAttentionContext(ATTENTION_NAME);
64
- if (!attendableId) {
65
- return {
66
- hasAttention: false,
67
- isAncestor: false,
68
- isRelated: false
69
- };
70
- }
71
- const current = [
72
- attendableId,
73
- ...path
74
- ];
75
- const hasAttention = current.length === attention.attended.length && current.every((id, index) => attention.attended[index] === id);
76
- const isAncestor = current.length < attention.attended.length && attention.attended.slice(-current.length).every((id, index) => current[index] === id);
77
- const isRelated = attendableId === attention.attended[0];
78
- return {
79
- hasAttention,
80
- isAncestor,
81
- isRelated
82
- };
83
- };
84
- var useAttended = () => {
85
- const { attention } = useAttentionContext(ATTENTION_NAME);
86
- return attention.attended;
87
- };
88
- var useAttendableAttributes = (attendableId) => {
89
- const { hasAttention } = useAttention(attendableId);
90
- return useMemo(() => {
91
- const attributes = {
92
- [ATTENABLE_ATTRIBUTE]: attendableId
93
- };
94
- if (hasAttention) {
95
- attributes[ATTENTION_SOURCE_ATTRIBUTE] = "true";
96
- }
97
- return attributes;
98
- }, [
99
- attendableId,
100
- hasAttention
101
- ]);
102
- };
103
- var useAttentionPath = () => {
104
- const { path } = useAttentionContext(ATTENTION_NAME);
105
- return path;
106
- };
107
- var getAttendables = (selector, cursor, acc = []) => {
108
- const closestAttendable = cursor.closest(selector);
109
- if (!closestAttendable) {
110
- return acc;
111
- } else {
112
- const attendableId = closestAttendable.getAttribute("data-attendable-id");
113
- if (!attendableId) {
114
- const trigger = document.querySelector(`[aria-controls="${closestAttendable.getAttribute("id")}"]`);
115
- if (!trigger) {
116
- return acc;
117
- } else {
118
- return getAttendables(selector, trigger, acc);
119
- }
120
- } else {
121
- acc.push(attendableId);
122
- return !closestAttendable.parentElement ? acc : getAttendables(selector, closestAttendable.parentElement, acc);
123
- }
124
- }
125
- };
126
- var RootAttentionProvider = ({ children, attention: propsAttention, onChange }) => {
127
- const attention = useDefaultValue(propsAttention, () => create({
128
- attended: []
129
- }));
130
- const handleFocus = (event) => {
131
- const selector = [
132
- "[data-attendable-id]",
133
- ...Array.from(document.querySelectorAll("[aria-controls]")).map((el) => `[id="${el.getAttribute("aria-controls")}"]`)
134
- ].join(",");
135
- const prev = attention.attended;
136
- const next = Array.from(new Set(getAttendables(selector, event.target)));
137
- if (next.length > 0 && (prev.length !== next.length || !!prev.find((id, index) => next[index] !== id))) {
138
- attention.attended = next;
139
- onChange?.(next);
140
- }
141
- };
142
- return /* @__PURE__ */ React2.createElement(AttentionContextProvider, {
143
- attention,
144
- path: []
145
- }, /* @__PURE__ */ React2.createElement("div", {
146
- role: "none",
147
- className: "contents",
148
- onFocusCapture: handleFocus
149
- }, children));
150
- };
151
- var AttentionProvider = ({ id, children }) => {
152
- const { attention, path } = useAttentionContext(ATTENTION_NAME);
153
- const nextPath = useMemo(() => [
154
- id,
155
- ...path
156
- ], [
157
- id,
158
- path
159
- ]);
160
- return /* @__PURE__ */ React2.createElement(AttentionContextProvider, {
161
- attention,
162
- path: nextPath
163
- }, children);
164
- };
1
+ import {
2
+ ATTENABLE_ATTRIBUTE,
3
+ ATTENTION_NAME,
4
+ ATTENTION_SOURCE_ATTRIBUTE,
5
+ AttentionGlyph,
6
+ AttentionManager,
7
+ AttentionProvider,
8
+ AttentionSchema,
9
+ RootAttentionProvider,
10
+ getAttendables,
11
+ useAttendableAttributes,
12
+ useAttended,
13
+ useAttention,
14
+ useAttentionContext,
15
+ useAttentionPath
16
+ } from "./chunk-GABVXGFU.mjs";
165
17
  export {
166
18
  ATTENABLE_ATTRIBUTE,
167
19
  ATTENTION_NAME,
168
20
  ATTENTION_SOURCE_ATTRIBUTE,
169
21
  AttentionGlyph,
22
+ AttentionManager,
170
23
  AttentionProvider,
24
+ AttentionSchema,
171
25
  RootAttentionProvider,
26
+ getAttendables,
172
27
  useAttendableAttributes,
173
28
  useAttended,
174
29
  useAttention,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/components/AttentionGlyph.tsx", "../../../src/components/AttentionProvider.tsx"],
4
- "sourcesContent": ["//\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 { create } from '@dxos/echo-schema';\nimport { useDefaultValue } from '@dxos/react-ui';\n\nconst ATTENTION_NAME = 'Attention';\nconst ATTENABLE_ATTRIBUTE = 'data-attendable-id';\nconst ATTENTION_SOURCE_ATTRIBUTE = 'data-is-attention-source';\n\ntype Attention = {\n attended: string[];\n};\n\ntype AttentionContextValue = {\n attention: Attention;\n path: string[];\n};\n\nconst [AttentionContextProvider, useAttentionContext] = createContext<AttentionContextValue>(ATTENTION_NAME, {\n attention: { attended: [] },\n path: [],\n});\n\ntype UseAttention = {\n hasAttention: boolean;\n isAncestor: boolean;\n isRelated: boolean;\n};\n\nconst useAttention = (attendableId?: string): UseAttention => {\n const { attention, path } = useAttentionContext(ATTENTION_NAME);\n if (!attendableId) {\n return { hasAttention: false, isAncestor: false, isRelated: false };\n }\n\n const current = [attendableId, ...path];\n const hasAttention =\n current.length === attention.attended.length && current.every((id, index) => attention.attended[index] === id);\n\n const isAncestor =\n current.length < attention.attended.length &&\n attention.attended.slice(-current.length).every((id, index) => current[index] === id);\n\n const isRelated = attendableId === attention.attended[0];\n\n return { hasAttention, isAncestor, isRelated };\n};\n\nconst useAttended = () => {\n const { attention } = useAttentionContext(ATTENTION_NAME);\n return attention.attended;\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\n/**\n * Accumulates all attendable id’s between the element provided and the root, inclusive.\n */\nconst 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 return acc;\n } else {\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\nconst RootAttentionProvider = ({\n children,\n attention: propsAttention,\n onChange,\n}: PropsWithChildren<\n Partial<{\n attention: Attention;\n onChange: (nextAttended: string[]) => void;\n }>\n>) => {\n const attention = useDefaultValue(propsAttention, () => create<Attention>({ attended: [] }));\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.attended;\n const next = Array.from(new Set(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.attended = 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\nexport type { Attention, AttentionContextValue };\n"],
5
- "mappings": ";AAKA,OAAOA,SAAqCC,kBAAkB;AAG9D,SAASC,UAAU;AAEnB,IAAMC,uBACJ;AAEF,IAAMC,qBACJ;AAEF,IAAMC,cAAc,MAAA;AAClB,SACE,sBAAA,cAACC,OAAAA;IACCC,OAAM;IACNC,QAAO;IACPC,SAAQ;IACRC,WAAWN;IACXO,MAAK;IACLC,OAAM;KAEN,sBAAA,cAACC,UAAAA;IAAOC,IAAG;IAAIC,IAAG;IAAIC,GAAE;IAAML,MAAK;;AAGzC;AAEA,IAAMM,eAAe,MAAA;AACnB,SACE,sBAAA,cAACX,OAAAA;IACCC,OAAM;IACNC,QAAO;IACPC,SAAQ;IACRC,WAAWN;IACXO,MAAK;IACLC,OAAM;KAEN,sBAAA,cAACM,QAAAA;IACCC,GAAE;IACFR,MAAK;MAEP,sBAAA,cAACE,UAAAA;IAAOC,IAAG;IAAOC,IAAG;IAAIC,GAAE;IAAML,MAAK;;AAG5C;AAMO,IAAMS,iBAAiBC,2BAC5B,CAAC,EAAEC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AA,EAAoBC,IAC1D,CAACC,OAAO,QAAQA,GAAGlB,aAAa,eAAA,CAAA,IAAoB;MAEtDmB,KAAK,GAAA;AACP,UAAMC,OAAO7C,UAAUC;AACvB,UAAM6C,OAAOP,MAAMC,KAAK,IAAIO,IAAI5B,eAAeC,UAAUkB,MAAMU,MAAM,CAAA,CAAA;AAIrE,QAAIF,KAAKrC,SAAS,MAAMoC,KAAKpC,WAAWqC,KAAKrC,UAAU,CAAC,CAACoC,KAAKI,KAAK,CAACtC,IAAIC,UAAUkC,KAAKlC,KAAAA,MAAWD,EAAAA,IAAM;AACtGX,gBAAUC,WAAW6C;AACrBZ,iBAAWY,IAAAA;IACb;EACF;AACA,SACE,gBAAAI,OAAA,cAACrD,0BAAAA;IAAyBG;IAAsBE,MAAM,CAAA;KACpD,gBAAAgD,OAAA,cAACC,OAAAA;IAAIC,MAAK;IAAOC,WAAU;IAAWC,gBAAgBjB;KACnDL,QAAAA,CAAAA;AAIT;AAEA,IAAMuB,oBAAoB,CAAC,EAAE5C,IAAIqB,SAAQ,MAAqC;AAC5E,QAAM,EAAEhC,WAAWE,KAAI,IAAKJ,oBAAoBJ,cAAAA;AAChD,QAAM8D,WAAWxC,QAAQ,MAAM;IAACL;OAAOT;KAAO;IAACS;IAAIT;GAAK;AAExD,SACE,gBAAAgD,OAAA,cAACrD,0BAAAA;IAAyBG;IAAsBE,MAAMsD;KACnDxB,QAAAA;AAGP;",
6
- "names": ["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", "create", "useDefaultValue", "ATTENTION_NAME", "ATTENABLE_ATTRIBUTE", "ATTENTION_SOURCE_ATTRIBUTE", "AttentionContextProvider", "useAttentionContext", "createContext", "attention", "attended", "path", "useAttention", "attendableId", "hasAttention", "isAncestor", "isRelated", "current", "length", "every", "id", "index", "slice", "useAttended", "useAttendableAttributes", "useMemo", "attributes", "useAttentionPath", "getAttendables", "selector", "cursor", "acc", "closestAttendable", "closest", "getAttribute", "trigger", "document", "querySelector", "push", "parentElement", "RootAttentionProvider", "children", "propsAttention", "onChange", "useDefaultValue", "create", "handleFocus", "event", "Array", "from", "querySelectorAll", "map", "el", "join", "prev", "next", "Set", "target", "find", "React", "div", "role", "className", "onFocusCapture", "AttentionProvider", "nextPath"]
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"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":18359,"imports":[{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true}],"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":508,"imports":[{"path":"packages/ui/react-ui-attention/src/components/index.ts","kind":"import-statement","original":"./components"}],"format":"esm"}},"outputs":{"packages/ui/react-ui-attention/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":13033},"packages/ui/react-ui-attention/dist/lib/browser/index.mjs":{"imports":[{"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/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true}],"exports":["ATTENABLE_ATTRIBUTE","ATTENTION_NAME","ATTENTION_SOURCE_ATTRIBUTE","AttentionGlyph","AttentionProvider","RootAttentionProvider","useAttendableAttributes","useAttended","useAttention","useAttentionContext","useAttentionPath"],"entryPoint":"packages/ui/react-ui-attention/src/index.ts","inputs":{"packages/ui/react-ui-attention/src/components/AttentionGlyph.tsx":{"bytesInOutput":2349},"packages/ui/react-ui-attention/src/components/index.ts":{"bytesInOutput":0},"packages/ui/react-ui-attention/src/components/AttentionProvider.tsx":{"bytesInOutput":3703},"packages/ui/react-ui-attention/src/index.ts":{"bytesInOutput":0}},"bytes":6474}}}
1
+ {"inputs":{"packages/ui/react-ui-attention/src/attention.ts":{"bytes":15753,"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/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"packages/ui/react-ui-attention/dist/lib/browser/index.mjs":{"imports":[{"path":"packages/ui/react-ui-attention/dist/lib/browser/chunk-GABVXGFU.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":671},"packages/ui/react-ui-attention/dist/lib/browser/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":697},"packages/ui/react-ui-attention/dist/lib/browser/testing/index.mjs":{"imports":[{"path":"packages/ui/react-ui-attention/dist/lib/browser/chunk-GABVXGFU.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":367},"packages/ui/react-ui-attention/dist/lib/browser/chunk-GABVXGFU.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":18441},"packages/ui/react-ui-attention/dist/lib/browser/chunk-GABVXGFU.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":8981}}}
@@ -0,0 +1,15 @@
1
+ import {
2
+ RootAttentionProvider
3
+ } from "../chunk-GABVXGFU.mjs";
4
+
5
+ // packages/ui/react-ui-attention/src/testing/decorators/withAttention.ts
6
+ import { createElement } from "react";
7
+ var withAttention = (Story) => {
8
+ return createElement(RootAttentionProvider, {
9
+ children: createElement(Story)
10
+ });
11
+ };
12
+ export {
13
+ withAttention
14
+ };
15
+ //# 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
+ }
@@ -0,0 +1,37 @@
1
+ import { type ReactiveObject, S } from '@dxos/echo-schema';
2
+ export declare const AttentionSchema: S.mutable<S.Struct<{
3
+ hasAttention: typeof S.Boolean;
4
+ isAncestor: typeof S.Boolean;
5
+ isRelated: typeof S.Boolean;
6
+ }>>;
7
+ export type Attention = S.Schema.Type<typeof AttentionSchema>;
8
+ /**
9
+ * Manages attention state for an application.
10
+ */
11
+ export declare class AttentionManager {
12
+ private readonly _map;
13
+ private readonly _state;
14
+ constructor(initial?: string[]);
15
+ /**
16
+ * Currently attended element.
17
+ */
18
+ get current(): string[];
19
+ /**
20
+ * All attention paths.
21
+ */
22
+ keys(): string[][];
23
+ /**
24
+ * Get the attention state for a given path.
25
+ */
26
+ get(key: string[]): ReactiveObject<Attention>;
27
+ /**
28
+ * Update the currently attended element.
29
+ */
30
+ update(nextKey: string[]): void;
31
+ private _set;
32
+ }
33
+ /**
34
+ * Accumulates all attendable id’s between the element provided and the root, inclusive.
35
+ */
36
+ export declare const getAttendables: (selector: string, cursor: Element, acc?: string[]) => string[];
37
+ //# sourceMappingURL=attention.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attention.d.ts","sourceRoot":"","sources":["../../../src/attention.ts"],"names":[],"mappings":"AAMA,OAAO,EAAU,KAAK,cAAc,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAGnE,eAAO,MAAM,eAAe;;;;GAM3B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,eAAe,CAAC,CAAC;AAK9D;;GAEG;AAEH,qBAAa,gBAAgB;IAG3B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAkE;IACvF,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkD;gBAE7D,OAAO,GAAE,MAAM,EAAO;IAMlC;;OAEG;IACH,IAAI,OAAO,aAEV;IAED;;OAEG;IACH,IAAI;IAIJ;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC,SAAS,CAAC;IAW7C;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE;IA8BxB,OAAO,CAAC,IAAI;CAMb;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,aAAc,MAAM,UAAU,OAAO,QAAO,MAAM,EAAE,KAAQ,MAAM,EAqB5F,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=attention.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attention.test.d.ts","sourceRoot":"","sources":["../../../src/attention.test.ts"],"names":[],"mappings":""}