@dxos/react-ui-attention 0.9.1-staging.ee54ba693a → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/lib/chunk-ViewStateProvider.mjs +308 -0
  2. package/dist/lib/chunk-ViewStateProvider.mjs.map +1 -0
  3. package/dist/lib/chunk-types.mjs +351 -0
  4. package/dist/lib/chunk-types.mjs.map +1 -0
  5. package/dist/lib/index.mjs +149 -0
  6. package/dist/lib/index.mjs.map +1 -0
  7. package/dist/lib/testing.mjs +20 -0
  8. package/dist/lib/testing.mjs.map +1 -0
  9. package/dist/lib/types.mjs +2 -0
  10. package/dist/types/src/components/AttentionProvider/AttentionProvider.d.ts +2 -15
  11. package/dist/types/src/components/AttentionProvider/AttentionProvider.d.ts.map +1 -1
  12. package/dist/types/src/components/AttentionProvider/attention-context.d.ts +20 -0
  13. package/dist/types/src/components/AttentionProvider/attention-context.d.ts.map +1 -0
  14. package/dist/types/src/components/AttentionProvider/index.d.ts +1 -0
  15. package/dist/types/src/components/AttentionProvider/index.d.ts.map +1 -1
  16. package/dist/types/src/components/ViewStateProvider/ViewStateProvider.d.ts +2 -26
  17. package/dist/types/src/components/ViewStateProvider/ViewStateProvider.d.ts.map +1 -1
  18. package/dist/types/src/components/ViewStateProvider/index.d.ts +1 -0
  19. package/dist/types/src/components/ViewStateProvider/index.d.ts.map +1 -1
  20. package/dist/types/src/components/ViewStateProvider/view-state-hooks.d.ts +32 -0
  21. package/dist/types/src/components/ViewStateProvider/view-state-hooks.d.ts.map +1 -0
  22. package/dist/types/src/core/backends.d.ts +24 -0
  23. package/dist/types/src/core/backends.d.ts.map +1 -0
  24. package/dist/types/src/core/backends.test.d.ts.map +1 -0
  25. package/dist/types/src/core/index.d.ts +2 -0
  26. package/dist/types/src/core/index.d.ts.map +1 -0
  27. package/dist/types/src/hooks/index.d.ts +2 -0
  28. package/dist/types/src/hooks/index.d.ts.map +1 -0
  29. package/dist/types/src/hooks/useArticleKeyboardNavigation.d.ts.map +1 -0
  30. package/dist/types/src/hooks/useArticleKeyboardNavigation.test.d.ts.map +1 -0
  31. package/dist/types/src/index.d.ts +3 -4
  32. package/dist/types/src/index.d.ts.map +1 -1
  33. package/dist/types/src/{attention.d.ts → types/Attention.d.ts} +13 -2
  34. package/dist/types/src/types/Attention.d.ts.map +1 -0
  35. package/dist/types/src/types/Attention.test.d.ts +2 -0
  36. package/dist/types/src/types/Attention.test.d.ts.map +1 -0
  37. package/dist/types/src/{selection.d.ts → types/Selection.d.ts} +12 -10
  38. package/dist/types/src/types/Selection.d.ts.map +1 -0
  39. package/dist/types/src/types/Selection.test.d.ts +2 -0
  40. package/dist/types/src/types/Selection.test.d.ts.map +1 -0
  41. package/dist/types/src/types/ViewState.d.ts +66 -0
  42. package/dist/types/src/types/ViewState.d.ts.map +1 -0
  43. package/dist/types/src/types/ViewState.test.d.ts +2 -0
  44. package/dist/types/src/types/ViewState.test.d.ts.map +1 -0
  45. package/dist/types/src/types/index.d.ts +3 -3
  46. package/dist/types/src/types/index.d.ts.map +1 -1
  47. package/dist/types/tsconfig.tsbuildinfo +1 -1
  48. package/package.json +18 -20
  49. package/src/components/AttentionProvider/AttentionProvider.stories.tsx +1 -1
  50. package/src/components/AttentionProvider/AttentionProvider.tsx +4 -86
  51. package/src/components/AttentionProvider/attention-context.ts +81 -0
  52. package/src/components/AttentionProvider/index.ts +2 -0
  53. package/src/components/ViewStateProvider/ViewStateProvider.test.tsx +7 -5
  54. package/src/components/ViewStateProvider/ViewStateProvider.tsx +6 -110
  55. package/src/components/ViewStateProvider/index.ts +9 -0
  56. package/src/components/ViewStateProvider/view-state-hooks.ts +115 -0
  57. package/src/{view-state → core}/backends.test.ts +5 -5
  58. package/src/{view-state → core}/backends.ts +24 -17
  59. package/src/{view-state → core}/index.ts +0 -1
  60. package/src/hooks/index.ts +5 -0
  61. package/src/{useArticleKeyboardNavigation.ts → hooks/useArticleKeyboardNavigation.ts} +1 -1
  62. package/src/index.ts +3 -4
  63. package/src/testing/decorators/withAttention.ts +2 -2
  64. package/src/{attention.test.ts → types/Attention.test.ts} +2 -2
  65. package/src/{attention.ts → types/Attention.ts} +17 -2
  66. package/src/types/Selection.test.ts +100 -0
  67. package/src/{selection.ts → types/Selection.ts} +27 -17
  68. package/src/{view-state/view-state.test.ts → types/ViewState.test.ts} +6 -6
  69. package/src/types/ViewState.ts +101 -0
  70. package/src/types/index.ts +8 -7
  71. package/dist/lib/browser/chunk-4HYAJ4IO.mjs +0 -434
  72. package/dist/lib/browser/chunk-4HYAJ4IO.mjs.map +0 -7
  73. package/dist/lib/browser/chunk-I4FDY4AZ.mjs +0 -236
  74. package/dist/lib/browser/chunk-I4FDY4AZ.mjs.map +0 -7
  75. package/dist/lib/browser/index.mjs +0 -218
  76. package/dist/lib/browser/index.mjs.map +0 -7
  77. package/dist/lib/browser/meta.json +0 -1
  78. package/dist/lib/browser/testing/index.mjs +0 -30
  79. package/dist/lib/browser/testing/index.mjs.map +0 -7
  80. package/dist/lib/browser/types/index.mjs +0 -43
  81. package/dist/lib/browser/types/index.mjs.map +0 -7
  82. package/dist/lib/node-esm/chunk-DLBZMHST.mjs +0 -237
  83. package/dist/lib/node-esm/chunk-DLBZMHST.mjs.map +0 -7
  84. package/dist/lib/node-esm/chunk-HWN7KJDX.mjs +0 -436
  85. package/dist/lib/node-esm/chunk-HWN7KJDX.mjs.map +0 -7
  86. package/dist/lib/node-esm/index.mjs +0 -219
  87. package/dist/lib/node-esm/index.mjs.map +0 -7
  88. package/dist/lib/node-esm/meta.json +0 -1
  89. package/dist/lib/node-esm/testing/index.mjs +0 -31
  90. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  91. package/dist/lib/node-esm/types/index.mjs +0 -44
  92. package/dist/lib/node-esm/types/index.mjs.map +0 -7
  93. package/dist/types/src/attention.d.ts.map +0 -1
  94. package/dist/types/src/attention.test.d.ts +0 -2
  95. package/dist/types/src/attention.test.d.ts.map +0 -1
  96. package/dist/types/src/selection.d.ts.map +0 -1
  97. package/dist/types/src/selection.test.d.ts +0 -2
  98. package/dist/types/src/selection.test.d.ts.map +0 -1
  99. package/dist/types/src/useArticleKeyboardNavigation.d.ts.map +0 -1
  100. package/dist/types/src/useArticleKeyboardNavigation.test.d.ts.map +0 -1
  101. package/dist/types/src/view-state/backends.d.ts +0 -24
  102. package/dist/types/src/view-state/backends.d.ts.map +0 -1
  103. package/dist/types/src/view-state/backends.test.d.ts.map +0 -1
  104. package/dist/types/src/view-state/index.d.ts +0 -3
  105. package/dist/types/src/view-state/index.d.ts.map +0 -1
  106. package/dist/types/src/view-state/view-state.d.ts +0 -54
  107. package/dist/types/src/view-state/view-state.d.ts.map +0 -1
  108. package/dist/types/src/view-state/view-state.test.d.ts +0 -2
  109. package/dist/types/src/view-state/view-state.test.d.ts.map +0 -1
  110. package/src/selection.test.ts +0 -67
  111. package/src/view-state/view-state.ts +0 -91
  112. /package/dist/types/src/{view-state → core}/backends.test.d.ts +0 -0
  113. /package/dist/types/src/{useArticleKeyboardNavigation.d.ts → hooks/useArticleKeyboardNavigation.d.ts} +0 -0
  114. /package/dist/types/src/{useArticleKeyboardNavigation.test.d.ts → hooks/useArticleKeyboardNavigation.test.d.ts} +0 -0
  115. /package/src/{useArticleKeyboardNavigation.test.ts → hooks/useArticleKeyboardNavigation.test.ts} +0 -0
@@ -1,236 +0,0 @@
1
- import {
2
- AttentionManager,
3
- ViewStateManager,
4
- createDefaultBackends,
5
- getAttendables,
6
- resolveSelection,
7
- selectionAspect,
8
- toggleSelection
9
- } from "./chunk-4HYAJ4IO.mjs";
10
-
11
- // src/components/AttentionProvider/AttentionProvider.tsx
12
- import { RegistryContext } from "@effect-atom/atom-react";
13
- import { createContext } from "@radix-ui/react-context";
14
- import { Primitive } from "@radix-ui/react-primitive";
15
- import { Slot } from "@radix-ui/react-slot";
16
- import React, { forwardRef, useCallback, useContext, useEffect, useMemo, useState } from "react";
17
- import { log } from "@dxos/log";
18
- import { useDefaultValue } from "@dxos/react-hooks";
19
- import { mx } from "@dxos/ui-theme";
20
- var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-attention/src/components/AttentionProvider/AttentionProvider.tsx";
21
- var ATTENTION_NAME = "Attention";
22
- var ATTENDABLE_ATTRIBUTE = "data-attendable-id";
23
- var ATTENTION_SOURCE_ATTRIBUTE = "data-w-attention-source";
24
- var [AttentionContextProvider, useAttentionContext] = createContext(ATTENTION_NAME, {
25
- attention: void 0
26
- });
27
- var UNKNOWN_ATTENDABLE = {
28
- hasAttention: false,
29
- isAncestor: false,
30
- isRelated: false
31
- };
32
- var useAttention = (attendableId) => {
33
- const { attention } = useAttentionContext(ATTENTION_NAME);
34
- const [state, setState] = useState(UNKNOWN_ATTENDABLE);
35
- useEffect(() => {
36
- if (!attendableId || !attention) {
37
- setState(UNKNOWN_ATTENDABLE);
38
- return;
39
- }
40
- const currentState = attention.get(attendableId);
41
- setState(currentState);
42
- return attention.subscribe(attendableId, (newState) => {
43
- setState(newState);
44
- });
45
- }, [
46
- attention,
47
- attendableId
48
- ]);
49
- return state;
50
- };
51
- var useAttended = () => {
52
- const { attention } = useAttentionContext(ATTENTION_NAME);
53
- const [current, setCurrent] = useState([]);
54
- useEffect(() => {
55
- if (!attention) {
56
- return;
57
- }
58
- setCurrent(attention.getCurrent());
59
- return attention.subscribeCurrent((newCurrent) => {
60
- setCurrent(newCurrent);
61
- });
62
- }, [
63
- attention
64
- ]);
65
- return current;
66
- };
67
- var useAttentionAttributes = (attendableId) => {
68
- const { hasAttention } = useAttention(attendableId);
69
- return useMemo(() => {
70
- const attributes = {
71
- [ATTENDABLE_ATTRIBUTE]: attendableId
72
- };
73
- if (hasAttention) {
74
- attributes[ATTENTION_SOURCE_ATTRIBUTE] = "true";
75
- }
76
- return attributes;
77
- }, [
78
- attendableId,
79
- hasAttention
80
- ]);
81
- };
82
- var RootAttentionProvider = ({ children, attention: propsAttention, onChange }) => {
83
- const registry = useContext(RegistryContext);
84
- const attention = useDefaultValue(propsAttention, () => new AttentionManager(registry));
85
- const handleFocus = useCallback((event) => {
86
- log("focus", {
87
- related: event.relatedTarget,
88
- target: event.target
89
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 84, S: void 0 });
90
- const selector = [
91
- "[data-attendable-id]",
92
- ...Array.from(document.querySelectorAll("[aria-controls]")).map((el) => `[id="${el.getAttribute("aria-controls")}"]`)
93
- ].join(",");
94
- const prev = attention.getCurrent();
95
- const next = getAttendables(selector, event.target);
96
- if (next.length > 0 && (prev.length !== next.length || !!prev.find((id, index) => next[index] !== id))) {
97
- attention.update(next);
98
- onChange?.(next);
99
- }
100
- }, [
101
- attention,
102
- onChange
103
- ]);
104
- return /* @__PURE__ */ React.createElement(AttentionContextProvider, {
105
- attention
106
- }, /* @__PURE__ */ React.createElement("div", {
107
- className: "contents",
108
- onFocusCapture: handleFocus
109
- }, children));
110
- };
111
- var AttendableContainer = /* @__PURE__ */ forwardRef(({ id, classNames, children, asChild, ...props }, forwardedRef) => {
112
- const attentionAttrs = useAttentionAttributes(id);
113
- const Comp = asChild ? Slot : Primitive.div;
114
- return /* @__PURE__ */ React.createElement(Comp, {
115
- role: "none",
116
- ...props,
117
- ...attentionAttrs,
118
- className: mx("dx-attention-surface", props.tabIndex === 0 && "dx-focus-ring-inset-over-all", classNames),
119
- ref: forwardedRef
120
- }, children);
121
- });
122
-
123
- // src/components/ViewStateProvider/ViewStateProvider.tsx
124
- import { RegistryContext as RegistryContext2 } from "@effect-atom/atom-react";
125
- import { createContext as createContext2 } from "@radix-ui/react-context";
126
- import React2, { useContext as useContext2, useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
127
- import { invariant } from "@dxos/invariant";
128
- import { useDefaultValue as useDefaultValue2 } from "@dxos/react-hooks";
129
- var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-attention/src/components/ViewStateProvider/ViewStateProvider.tsx";
130
- var VIEW_STATE_NAME = "ViewState";
131
- var [ViewStateContextProvider, useViewStateContext] = createContext2(VIEW_STATE_NAME, {
132
- manager: void 0
133
- });
134
- var ViewStateProvider = ({ children, manager: managerProp }) => {
135
- const registry = useContext2(RegistryContext2);
136
- const manager = useDefaultValue2(managerProp, () => new ViewStateManager({
137
- registry,
138
- backends: createDefaultBackends(registry)
139
- }));
140
- return /* @__PURE__ */ React2.createElement(ViewStateContextProvider, {
141
- manager
142
- }, children);
143
- };
144
- var useViewStateManager = () => {
145
- const { manager } = useViewStateContext(VIEW_STATE_NAME);
146
- invariant(manager, "useViewStateManager() requires a ViewStateProvider ancestor.", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 29, S: void 0, A: ["manager", "'useViewStateManager() requires a ViewStateProvider ancestor.'"] });
147
- return manager;
148
- };
149
- var useViewStateManagerOptional = () => {
150
- const { manager } = useViewStateContext(VIEW_STATE_NAME);
151
- return manager;
152
- };
153
- var useViewState = (aspect, contextId) => {
154
- const { manager } = useViewStateContext(VIEW_STATE_NAME);
155
- const [value, setValue] = useState2(() => contextId && manager ? manager.get(aspect, contextId) : aspect.defaultValue());
156
- useEffect2(() => {
157
- if (!contextId || !manager) {
158
- setValue(aspect.defaultValue());
159
- return;
160
- }
161
- setValue(manager.get(aspect, contextId));
162
- return manager.subscribe(aspect, contextId, setValue);
163
- }, [
164
- manager,
165
- aspect,
166
- contextId
167
- ]);
168
- return value;
169
- };
170
- var useViewStateActions = (aspect, contextId) => {
171
- const { manager } = useViewStateContext(VIEW_STATE_NAME);
172
- return useMemo2(() => ({
173
- set: (value) => {
174
- if (contextId) {
175
- manager?.set(aspect, contextId, value);
176
- }
177
- },
178
- update: (fn) => {
179
- if (contextId) {
180
- manager?.update(aspect, contextId, fn);
181
- }
182
- },
183
- clear: () => {
184
- if (contextId) {
185
- manager?.set(aspect, contextId, aspect.defaultValue());
186
- }
187
- }
188
- }), [
189
- manager,
190
- aspect,
191
- contextId
192
- ]);
193
- };
194
- var useSelection = (contextId, mode = "multi") => resolveSelection(useViewState(selectionAspect, contextId), mode);
195
- var useSelectionActions = (contextId) => {
196
- const { update, clear } = useViewStateActions(selectionAspect, contextId);
197
- return useMemo2(() => ({
198
- single: (id) => update(() => ({
199
- mode: "single",
200
- id
201
- })),
202
- multi: (ids) => update(() => ({
203
- mode: "multi",
204
- ids: [
205
- ...ids
206
- ]
207
- })),
208
- range: (from, to) => update(() => ({
209
- mode: "range",
210
- from,
211
- to
212
- })),
213
- toggle: (id) => update((prev) => toggleSelection(prev, id)),
214
- clear
215
- }), [
216
- update,
217
- clear
218
- ]);
219
- };
220
-
221
- export {
222
- useAttentionContext,
223
- useAttention,
224
- useAttended,
225
- useAttentionAttributes,
226
- RootAttentionProvider,
227
- AttendableContainer,
228
- ViewStateProvider,
229
- useViewStateManager,
230
- useViewStateManagerOptional,
231
- useViewState,
232
- useViewStateActions,
233
- useSelection,
234
- useSelectionActions
235
- };
236
- //# sourceMappingURL=chunk-I4FDY4AZ.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/AttentionProvider/AttentionProvider.tsx", "../../../src/components/ViewStateProvider/ViewStateProvider.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { RegistryContext } from '@effect-atom/atom-react';\nimport { createContext } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { Slot } from '@radix-ui/react-slot';\nimport React, {\n type ComponentPropsWithRef,\n type FocusEvent,\n type PropsWithChildren,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from 'react';\n\nimport { log } from '@dxos/log';\nimport { useDefaultValue } from '@dxos/react-hooks';\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport { mx } from '@dxos/ui-theme';\n\nimport { type Attention, AttentionManager, getAttendables } from '../../attention';\n\nconst ATTENTION_NAME = 'Attention';\nconst ATTENDABLE_ATTRIBUTE = 'data-attendable-id';\nconst ATTENTION_SOURCE_ATTRIBUTE = 'data-w-attention-source';\n\ntype AttentionContextValue = {\n attention: AttentionManager;\n};\n\nconst [AttentionContextProvider, useAttentionContext] = createContext<AttentionContextValue>(ATTENTION_NAME, {\n attention: undefined as unknown as AttentionManager,\n});\n\nconst UNKNOWN_ATTENDABLE = { hasAttention: false, isAncestor: false, isRelated: false } as Attention;\n\n/**\n * Subscribe to the attention state for a qualified graph ID.\n */\n// TODO(burdon): Unify with seleciton and change to contextId?\nconst useAttention = (attendableId?: string): Attention => {\n const { attention } = useAttentionContext(ATTENTION_NAME);\n const [state, setState] = useState<Attention>(UNKNOWN_ATTENDABLE);\n useEffect(() => {\n if (!attendableId || !attention) {\n setState(UNKNOWN_ATTENDABLE);\n return;\n }\n\n const currentState = attention.get(attendableId);\n setState(currentState);\n\n return attention.subscribe(attendableId, (newState) => {\n setState(newState);\n });\n }, [attention, attendableId]);\n\n return state;\n};\n\nconst useAttended = () => {\n const { attention } = useAttentionContext(ATTENTION_NAME);\n const [current, setCurrent] = useState<readonly string[]>([]);\n useEffect(() => {\n if (!attention) {\n return;\n }\n\n setCurrent(attention.getCurrent());\n\n return attention.subscribeCurrent((newCurrent) => {\n setCurrent(newCurrent);\n });\n }, [attention]);\n\n return current;\n};\n\n/**\n * Computes HTML element attributes to apply so the attention system can detect changes.\n */\nconst useAttentionAttributes = (attendableId?: string) => {\n const { hasAttention } = useAttention(attendableId);\n return useMemo(() => {\n const attributes: Record<string, string | undefined> = { [ATTENDABLE_ATTRIBUTE]: attendableId };\n if (hasAttention) {\n attributes[ATTENTION_SOURCE_ATTRIBUTE] = 'true';\n }\n\n return attributes;\n }, [attendableId, hasAttention]);\n};\n\ntype RootAttentionProviderProps = PropsWithChildren<{\n attention?: AttentionManager;\n onChange?: (nextAttended: string[]) => void;\n}>;\n\nconst RootAttentionProvider = ({ children, attention: propsAttention, onChange }: RootAttentionProviderProps) => {\n const registry = useContext(RegistryContext);\n const attention = useDefaultValue(propsAttention, () => new AttentionManager(registry));\n\n const handleFocus = useCallback(\n (event: FocusEvent) => {\n // NOTE(thure): Use the following to debug focus movement across the app:\n log('focus', { related: event.relatedTarget, target: event.target });\n\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.getCurrent();\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 [attention, onChange],\n );\n\n return (\n <AttentionContextProvider attention={attention}>\n <div className='contents' onFocusCapture={handleFocus}>\n {children}\n </div>\n </AttentionContextProvider>\n );\n};\n\nexport type AttendableContainerProps = ThemedClassName<\n ComponentPropsWithRef<'div'> & { id: string; asChild?: boolean }\n>;\n\n/**\n * Note that DeckPlugin and StackPlugin both handle attention on their own,\n * and when rendering content in those cases it is not necessary to also render an `AttendableContainer`.\n * This component is primarily for Storybook stories and other testing scenarios,\n * or the rare cases where an attendable entity is rendered outside of either of those plugins.\n */\nconst AttendableContainer = forwardRef<HTMLDivElement, AttendableContainerProps>(\n ({ id, classNames, children, asChild, ...props }, forwardedRef) => {\n const attentionAttrs = useAttentionAttributes(id);\n const Comp = asChild ? Slot : Primitive.div;\n return (\n <Comp\n role='none'\n {...props}\n {...attentionAttrs}\n className={mx('dx-attention-surface', props.tabIndex === 0 && 'dx-focus-ring-inset-over-all', classNames)}\n ref={forwardedRef}\n >\n {children}\n </Comp>\n );\n },\n);\n\nexport {\n AttendableContainer,\n RootAttentionProvider,\n useAttended,\n useAttention,\n useAttentionAttributes,\n useAttentionContext,\n};\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport { RegistryContext } from '@effect-atom/atom-react';\nimport { createContext } from '@radix-ui/react-context';\nimport React, { type PropsWithChildren, useContext, useEffect, useMemo, useState } from 'react';\n\nimport { invariant } from '@dxos/invariant';\nimport { useDefaultValue } from '@dxos/react-hooks';\n\nimport {\n type SelectionMode,\n type SelectionResult,\n resolveSelection,\n selectionAspect,\n toggleSelection,\n} from '../../selection';\nimport { type AspectDef, ViewStateManager, createDefaultBackends } from '../../view-state';\n\nconst VIEW_STATE_NAME = 'ViewState';\n\ntype ViewStateContextValue = { manager?: ViewStateManager };\n\n// Default value lets consumers render outside a provider (isolated stories/tests) without throwing;\n// `manager` reads as `undefined` and hooks fall back to aspect defaults / no-op actions.\nconst [ViewStateContextProvider, useViewStateContext] = createContext<ViewStateContextValue>(VIEW_STATE_NAME, {\n manager: undefined,\n});\n\n/** Provides the per-context UI state manager. Replaces the former `SelectionProvider`. */\nexport const ViewStateProvider = ({\n children,\n manager: managerProp,\n}: PropsWithChildren<{ manager?: ViewStateManager }>) => {\n const registry = useContext(RegistryContext);\n const manager = useDefaultValue(\n managerProp,\n () => new ViewStateManager({ registry, backends: createDefaultBackends(registry) }),\n );\n return <ViewStateContextProvider manager={manager}>{children}</ViewStateContextProvider>;\n};\n\n/** Access the underlying ViewStateManager from context. Throws when used outside a `ViewStateProvider`. */\nexport const useViewStateManager = (): ViewStateManager => {\n const { manager } = useViewStateContext(VIEW_STATE_NAME);\n invariant(manager, 'useViewStateManager() requires a ViewStateProvider ancestor.');\n return manager;\n};\n\n/** Access the ViewStateManager if a provider is present; `undefined` otherwise (e.g. isolated stories/tests). */\nexport const useViewStateManagerOptional = (): ViewStateManager | undefined => {\n const { manager } = useViewStateContext(VIEW_STATE_NAME);\n return manager;\n};\n\n/** Reactive read of an aspect value for a context; yields the aspect default when unset or unprovided. */\nexport const useViewState = <T,>(aspect: AspectDef<T>, contextId?: string): T => {\n const { manager } = useViewStateContext(VIEW_STATE_NAME);\n const [value, setValue] = useState<T>(() =>\n contextId && manager ? manager.get(aspect, contextId) : aspect.defaultValue(),\n );\n useEffect(() => {\n if (!contextId || !manager) {\n setValue(aspect.defaultValue());\n return;\n }\n setValue(manager.get(aspect, contextId));\n return manager.subscribe(aspect, contextId, setValue);\n }, [manager, aspect, contextId]);\n return value;\n};\n\nexport type UseViewStateActions<T> = {\n set: (value: T) => void;\n update: (fn: (prev: T) => T) => void;\n clear: () => void;\n};\n\nexport const useViewStateActions = <T,>(aspect: AspectDef<T>, contextId?: string): UseViewStateActions<T> => {\n const { manager } = useViewStateContext(VIEW_STATE_NAME);\n return useMemo<UseViewStateActions<T>>(\n () => ({\n set: (value) => {\n if (contextId) {\n manager?.set(aspect, contextId, value);\n }\n },\n update: (fn) => {\n if (contextId) {\n manager?.update(aspect, contextId, fn);\n }\n },\n clear: () => {\n if (contextId) {\n manager?.set(aspect, contextId, aspect.defaultValue());\n }\n },\n }),\n [manager, aspect, contextId],\n );\n};\n\n/** Resolved selection value for `contextId` in the requested `mode` (default `multi`). */\nexport const useSelection = <T extends SelectionMode>(contextId?: string, mode: T = 'multi' as T): SelectionResult<T> =>\n resolveSelection(useViewState(selectionAspect, contextId), mode);\n\nexport type UseSelectionActions = {\n single: (id: string) => void;\n multi: (ids: string[]) => void;\n range: (from: string, to: string) => void;\n toggle: (id: string) => void;\n clear: () => void;\n};\n\n/** Selection mutators for a single context, built on the generic ViewState actions. */\nexport const useSelectionActions = (contextId?: string): UseSelectionActions => {\n const { update, clear } = useViewStateActions(selectionAspect, contextId);\n return useMemo<UseSelectionActions>(\n () => ({\n single: (id) => update(() => ({ mode: 'single', id })),\n multi: (ids) => update(() => ({ mode: 'multi', ids: [...ids] })),\n range: (from, to) => update(() => ({ mode: 'range', from, to })),\n toggle: (id) => update((prev) => toggleSelection(prev, id)),\n clear,\n }),\n [update, clear],\n );\n};\n"],
5
- "mappings": ";;;;;;;;;;;AAIA,SAASA,uBAAuB;AAChC,SAASC,qBAAqB;AAC9B,SAASC,iBAAiB;AAC1B,SAASC,YAAY;AACrB,OAAOC,SAILC,YACAC,aACAC,YACAC,WACAC,SACAC,gBACK;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BAAA,IAAA,QAAA,WAAA,KAAA;MACAS;;YAEIT,CAAAA,OAAAA;AACF,UAAA,WAAA;AACF,iBAAA,OAAA,QAAA,WAAA,EAAA;MACAU;;iBAEIV;AACF,UAAA,WAAA;AACF,iBAAA,IAAA,QAAA,WAAA,OAAA,aAAA,CAAA;MAEF;IAACA;EAASW,IAAAA;IAAQP;IAAU;IAE9B;EAEF,CAAA;AAYA;AAEiEA,IAAAA,eAAAA,CAAAA,WAAAA,OAAAA,YAAAA,iBAAAA,aAAAA,iBAAAA,SAAAA,GAAAA,IAAAA;AAEtD,IAAA,sBAAA,CAAA,cAAA;UACLQ,QAAQ,MAAQH,IAAAA,oBAAc,iBAAA,SAAA;yBAAEI;oBAAgBC,OAAAA,OAAAA;MAAG,MAAA;MAC3CC;;oBAAuCA,OAAK,OAAA;;WAAQ;QAAC,GAAA;MACrDC;;kBAA4CA,OAAAA,OAAAA,OAAAA;MAAMC,MAAAA;MAAG;MACpDH;IACTJ,EAAAA;IAEF,QAAA,CAAA,OAAA,OAAA,CAAA,SAAA,gBAAA,MAAA,EAAA,CAAA;IAACD;EAAQC,IAAAA;IAAM;IAEjB;;;",
6
- "names": ["RegistryContext", "createContext", "Primitive", "Slot", "React", "forwardRef", "useCallback", "useContext", "useEffect", "useMemo", "useState", "log", "useDefaultValue", "mx", "ATTENTION_NAME", "ATTENTION_SOURCE_ATTRIBUTE", "AttentionContextProvider", "attention", "undefined", "UNKNOWN_ATTENDABLE", "isAncestor", "isRelated", "setState", "useState", "useEffect", "attendableId", "subscribe", "newState", "useAttended", "setCurrent", "newCurrent", "attributes", "ATTENDABLE_ATTRIBUTE", "hasAttention", "useDefaultValue", "propsAttention", "AttentionManager", "registry", "handleFocus", "useCallback", "event", "log", "target", "selector", "join", "prev", "getCurrent", "next", "onChange", "div", "className", "onFocusCapture", "children", "Comp", "role", "attentionAttrs", "ref", "AttendableContainer", "RegistryContext", "createContext", "React", "useContext", "useEffect", "useMemo", "useState", "invariant", "useDefaultValue", "__dxlog_file", "VIEW_STATE_NAME", "createContext", "registry", "backends", "createDefaultBackends", "ViewStateContextProvider", "manager", "children", "defaultValue", "useEffect", "contextId", "setValue", "useMemo", "set", "value", "update", "clear", "aspect", "single", "mode", "id", "ids", "from", "to"]
7
- }
@@ -1,218 +0,0 @@
1
- import {
2
- AttendableContainer,
3
- RootAttentionProvider,
4
- ViewStateProvider,
5
- useAttended,
6
- useAttention,
7
- useAttentionAttributes,
8
- useAttentionContext,
9
- useSelection,
10
- useSelectionActions,
11
- useViewState,
12
- useViewStateActions,
13
- useViewStateManager,
14
- useViewStateManagerOptional
15
- } from "./chunk-I4FDY4AZ.mjs";
16
- import {
17
- AttentionManager,
18
- LocalBackend,
19
- MemoryBackend,
20
- SelectionSchema,
21
- ViewStateManager,
22
- createDefaultBackends,
23
- defaultSelection,
24
- defineViewState,
25
- expandAttendableId,
26
- getAttendables,
27
- getLinkedVariant,
28
- getParentId,
29
- getSegmentId,
30
- getSelectionSet,
31
- isLinkedSegment,
32
- linkedSegment,
33
- resolveSelection,
34
- selectionAspect,
35
- toggleSelection
36
- } from "./chunk-4HYAJ4IO.mjs";
37
-
38
- // src/components/AttentionGlyph/AttentionGlyph.tsx
39
- import React, { forwardRef, useMemo } from "react";
40
- import { Icon } from "@dxos/react-ui";
41
- import { mx } from "@dxos/ui-theme";
42
- var attentionGlyphStyles = mx("inline-block rounded-xs w-3 h-3 bg-transparent text-accent-text transition-colors", "[[data-contains-attended=true]_&]:bg-attention-contains", "[[data-attention=true]_&]:bg-accent-bg", "[[data-attention=true]_&]:text-accent-fg", "[[aria-current][data-attention=true]_&]:bg-accent-bg", "[[aria-current][data-attention=true]_&]:text-accent-fg", '[[aria-selected="true"][data-attention=true]_&]:bg-accent-bg', '[[aria-selected="true"][data-attention=true]_&]:text-accent-fg');
43
- var presenceIconStyles = mx("w-3 h-3");
44
- var PresenceOne = () => {
45
- return /* @__PURE__ */ React.createElement("svg", {
46
- width: "12",
47
- height: "12",
48
- viewBox: "0 0 12 12",
49
- className: presenceIconStyles,
50
- fill: "none",
51
- xmlns: "http://www.w3.org/2000/svg"
52
- }, /* @__PURE__ */ React.createElement("circle", {
53
- cx: "6",
54
- cy: "6",
55
- r: "2.5",
56
- fill: "currentColor"
57
- }));
58
- };
59
- var PresenceMany = () => {
60
- return /* @__PURE__ */ React.createElement("svg", {
61
- width: "12",
62
- height: "12",
63
- viewBox: "0 0 12 12",
64
- className: presenceIconStyles,
65
- fill: "none",
66
- xmlns: "http://www.w3.org/2000/svg"
67
- }, /* @__PURE__ */ React.createElement("path", {
68
- 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",
69
- fill: "currentColor"
70
- }), /* @__PURE__ */ React.createElement("circle", {
71
- cx: "4.25",
72
- cy: "6",
73
- r: "2.5",
74
- fill: "currentColor"
75
- }));
76
- };
77
- var Syncing = () => {
78
- const animationProps = useMemo(() => ({
79
- // Synchronize animations.
80
- animationDelay: `-${Date.now() % 2e3}ms`
81
- }), []);
82
- return /* @__PURE__ */ React.createElement("div", {
83
- role: "status",
84
- className: "flex items-center"
85
- }, /* @__PURE__ */ React.createElement(Icon, {
86
- icon: "ph--circle-notch--bold",
87
- size: 3,
88
- style: animationProps,
89
- classNames: "text-subdued animate-[spin_2s_linear_infinite]"
90
- }));
91
- };
92
- var AttentionGlyph = /* @__PURE__ */ forwardRef(({ presence, attended, syncing, containsAttended, classNames, ...props }, forwardedRef) => {
93
- const icon = syncing ? /* @__PURE__ */ React.createElement(Syncing, null) : presence === "many" ? /* @__PURE__ */ React.createElement(PresenceMany, null) : presence === "one" ? /* @__PURE__ */ React.createElement(PresenceOne, null) : null;
94
- return /* @__PURE__ */ React.createElement("div", {
95
- className: "flex group",
96
- "data-attention": attended,
97
- "data-contains-attended": containsAttended
98
- }, /* @__PURE__ */ React.createElement("span", {
99
- ...props,
100
- className: mx(attentionGlyphStyles, classNames),
101
- ref: forwardedRef
102
- }, icon));
103
- });
104
-
105
- // src/useArticleKeyboardNavigation.ts
106
- import { useEffect, useMemo as useMemo2 } from "react";
107
- import { Keyboard, nestKeyboardContext } from "@dxos/keyboard";
108
- var advance = ({ ids, currentId, delta }) => {
109
- if (ids.length === 0) {
110
- return void 0;
111
- }
112
- const idx = currentId ? ids.indexOf(currentId) : -1;
113
- if (idx === -1) {
114
- return delta === 1 ? ids[0] : ids[ids.length - 1];
115
- }
116
- const next = Math.max(0, Math.min(ids.length - 1, idx + delta));
117
- return ids[next];
118
- };
119
- var useArticleKeyboardNavigation = ({ articleId, items, currentId, getId, onSelect }) => {
120
- const { hasAttention } = useAttention(articleId);
121
- const ids = useMemo2(() => items.map((item) => getId ? getId(item) : item.id), [
122
- items,
123
- getId
124
- ]);
125
- useEffect(() => {
126
- if (!hasAttention) {
127
- return;
128
- }
129
- const contextPath = nestKeyboardContext(articleId);
130
- const context = Keyboard.singleton.getContext(contextPath);
131
- const prevContext = Keyboard.singleton.getCurrentContext();
132
- Keyboard.singleton.setCurrentContext(contextPath);
133
- const nextBinding = {
134
- shortcut: "j",
135
- handler: () => {
136
- const target = advance({
137
- ids,
138
- currentId,
139
- delta: 1
140
- });
141
- if (target !== void 0) {
142
- onSelect(target);
143
- }
144
- },
145
- data: "Next item",
146
- disableInput: true
147
- };
148
- const prevBinding = {
149
- shortcut: "k",
150
- handler: () => {
151
- const target = advance({
152
- ids,
153
- currentId,
154
- delta: -1
155
- });
156
- if (target !== void 0) {
157
- onSelect(target);
158
- }
159
- },
160
- data: "Previous item",
161
- disableInput: true
162
- };
163
- context.bind(nextBinding);
164
- context.bind(prevBinding);
165
- return () => {
166
- context.unbind("j");
167
- context.unbind("k");
168
- if (Keyboard.singleton.getCurrentContext() === contextPath) {
169
- Keyboard.singleton.setCurrentContext(prevContext);
170
- }
171
- };
172
- }, [
173
- articleId,
174
- ids,
175
- currentId,
176
- onSelect,
177
- hasAttention
178
- ]);
179
- };
180
- export {
181
- AttendableContainer,
182
- AttentionGlyph,
183
- AttentionManager,
184
- LocalBackend,
185
- MemoryBackend,
186
- RootAttentionProvider,
187
- SelectionSchema,
188
- Syncing,
189
- ViewStateManager,
190
- ViewStateProvider,
191
- advance,
192
- createDefaultBackends,
193
- defaultSelection,
194
- defineViewState,
195
- expandAttendableId,
196
- getAttendables,
197
- getLinkedVariant,
198
- getParentId,
199
- getSegmentId,
200
- getSelectionSet,
201
- isLinkedSegment,
202
- linkedSegment,
203
- resolveSelection,
204
- selectionAspect,
205
- toggleSelection,
206
- useArticleKeyboardNavigation,
207
- useAttended,
208
- useAttention,
209
- useAttentionAttributes,
210
- useAttentionContext,
211
- useSelection,
212
- useSelectionActions,
213
- useViewState,
214
- useViewStateActions,
215
- useViewStateManager,
216
- useViewStateManagerOptional
217
- };
218
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/AttentionGlyph/AttentionGlyph.tsx", "../../../src/useArticleKeyboardNavigation.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Primitive } from '@radix-ui/react-primitive';\nimport React, { type ComponentPropsWithRef, type CSSProperties, forwardRef, useMemo } from 'react';\n\nimport { Icon, type ThemedClassName } from '@dxos/react-ui';\nimport { mx } from '@dxos/ui-theme';\n\nconst attentionGlyphStyles = mx(\n 'inline-block rounded-xs w-3 h-3 bg-transparent text-accent-text transition-colors',\n '[[data-contains-attended=true]_&]:bg-attention-contains',\n '[[data-attention=true]_&]:bg-accent-bg',\n '[[data-attention=true]_&]:text-accent-fg',\n '[[aria-current][data-attention=true]_&]:bg-accent-bg',\n '[[aria-current][data-attention=true]_&]:text-accent-fg',\n '[[aria-selected=\"true\"][data-attention=true]_&]:bg-accent-bg',\n '[[aria-selected=\"true\"][data-attention=true]_&]:text-accent-fg',\n);\n\nconst presenceIconStyles = mx('w-3 h-3');\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 const Syncing = () => {\n const animationProps = useMemo<CSSProperties>(\n () => ({\n // Synchronize animations.\n animationDelay: `-${Date.now() % 2_000}ms`,\n }),\n [],\n );\n\n return (\n <div role='status' className='flex items-center'>\n <Icon\n icon='ph--circle-notch--bold'\n size={3}\n style={animationProps}\n classNames='text-subdued animate-[spin_2s_linear_infinite]'\n />\n </div>\n );\n};\n\nexport type AttentionGlyphProps = {\n attended?: boolean;\n containsAttended?: boolean;\n syncing?: boolean;\n presence?: 'none' | 'one' | 'many';\n} & ThemedClassName<Omit<ComponentPropsWithRef<typeof Primitive.span>, 'children'>>;\n\nexport const AttentionGlyph = forwardRef<HTMLSpanElement, AttentionGlyphProps>(\n ({ presence, attended, syncing, containsAttended, classNames, ...props }, forwardedRef) => {\n const icon = syncing ? (\n <Syncing />\n ) : presence === 'many' ? (\n <PresenceMany />\n ) : presence === 'one' ? (\n <PresenceOne />\n ) : null;\n\n return (\n <div className='flex group' data-attention={attended} data-contains-attended={containsAttended}>\n <span {...props} className={mx(attentionGlyphStyles, classNames)} ref={forwardedRef}>\n {icon}\n </span>\n </div>\n );\n },\n);\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport { useEffect, useMemo } from 'react';\n\nimport { Keyboard, nestKeyboardContext } from '@dxos/keyboard';\n\nimport { useAttention } from './components';\n\n/**\n * Compute the id to select after pressing 'j' (delta = 1) or 'k' (delta = -1).\n * Clamps at the list ends — pressing 'j' on the last item keeps the last item\n * selected (vim-style), and 'k' on the first item keeps the first.\n *\n * When no current selection exists, returns the first id (for delta = 1) or the\n * last id (for delta = -1) so the user can enter the list with either key.\n */\nexport const advance = ({\n ids,\n currentId,\n delta,\n}: {\n ids: readonly string[];\n currentId: string | undefined;\n delta: 1 | -1;\n}): string | undefined => {\n if (ids.length === 0) {\n return undefined;\n }\n\n const idx = currentId ? ids.indexOf(currentId) : -1;\n if (idx === -1) {\n return delta === 1 ? ids[0] : ids[ids.length - 1];\n }\n\n const next = Math.max(0, Math.min(ids.length - 1, idx + delta));\n return ids[next];\n};\n\nexport type UseArticleKeyboardNavigationOptions<T> = {\n /** Stable id for the article (used as the keyboard context path). */\n articleId: string;\n /** Ordered list of selectable items as they appear in the article. */\n items: readonly T[];\n /** Currently-selected id, if any. */\n currentId: string | undefined;\n /** Extracts the id from an item. Defaults to `item.id`. */\n getId?: (item: T) => string;\n /** Called with the id to select when the user presses 'j' or 'k'. */\n onSelect: (id: string) => void;\n};\n\n/**\n * Wire 'j' (next) and 'k' (previous) keyboard shortcuts for an article that\n * navigates a list of items (e.g., messages, events). Bindings are scoped to\n * the article's keyboard context so they only fire while the article has attention.\n *\n * Pass the items directly; ids are derived via `getId` (defaults to `item.id`).\n * Clamps at list boundaries. Active only when the article is attended.\n */\nexport const useArticleKeyboardNavigation: {\n <T extends { id: string }>(options: UseArticleKeyboardNavigationOptions<T>): void;\n <T>(options: UseArticleKeyboardNavigationOptions<T> & { getId: (item: T) => string }): void;\n} = <T>({ articleId, items, currentId, getId, onSelect }: UseArticleKeyboardNavigationOptions<T>): void => {\n const { hasAttention } = useAttention(articleId);\n\n // `getId` is optional only when `T extends { id: string }` (enforced by the overloads above),\n // so the fallback is sound; the cast bridges the generic erased by the implementation signature.\n const ids = useMemo(() => items.map((item) => (getId ? getId(item) : (item as { id: string }).id)), [items, getId]);\n\n useEffect(() => {\n if (!hasAttention) {\n return;\n }\n\n const contextPath = nestKeyboardContext(articleId);\n const context = Keyboard.singleton.getContext(contextPath);\n const prevContext = Keyboard.singleton.getCurrentContext();\n Keyboard.singleton.setCurrentContext(contextPath);\n\n const nextBinding = {\n shortcut: 'j',\n handler: () => {\n const target = advance({ ids, currentId, delta: 1 });\n if (target !== undefined) {\n onSelect(target);\n }\n },\n data: 'Next item',\n disableInput: true,\n };\n const prevBinding = {\n shortcut: 'k',\n handler: () => {\n const target = advance({ ids, currentId, delta: -1 });\n if (target !== undefined) {\n onSelect(target);\n }\n },\n data: 'Previous item',\n disableInput: true,\n };\n\n context.bind(nextBinding);\n context.bind(prevBinding);\n\n return () => {\n context.unbind('j');\n context.unbind('k');\n // Restore the prior context if we were the ones who set it.\n if (Keyboard.singleton.getCurrentContext() === contextPath) {\n Keyboard.singleton.setCurrentContext(prevContext);\n }\n };\n }, [articleId, ids, currentId, onSelect, hasAttention]);\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,OAAOA,SAAyDC,YAAYC,eAAe;AAE3F,SAASC,YAAkC;AAC3C,SAASC,UAAU;AAEnB,IAAMC,uBAAuBD,GAC3B,qFACA,2DACA,0CACA,4CACA,wDACA,0DACA,gEACA,gEAAA;AAGF,IAAME,qBAAqBF,GAAG,SAAA;AAE9B,IAAMG,cAAc,MAAA;AAClB,SACE,sBAAA,cAACC,OAAAA;IACCC,OAAM;IACNC,QAAO;IACPC,SAAQ;IACRC,WAAWN;IACXO,MAAK;IACLC,OAAM;KAEN,sBAAA,cAAC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AAKP,WAAAA;AACbP,YAAQc,KAAKD,WAAAA;AAEb,WAAO,MAAA;AACLb,cAAQe,OAAO,GAAA;AACff,cAAQe,OAAO,GAAA;AAEf,UAAId,SAASC,UAAUG,kBAAiB,MAAOP,aAAa;AAC1DG,iBAASC,UAAUI,kBAAkBF,WAAAA;MACvC;IACF;EACF,GAAG;IAACjB;IAAWZ;IAAKC;IAAWc;IAAUC;GAAa;AACxD;",
6
- "names": ["React", "forwardRef", "useMemo", "Icon", "mx", "attentionGlyphStyles", "presenceIconStyles", "PresenceOne", "svg", "width", "height", "viewBox", "className", "fill", "xmlns", "circle", "cx", "cy", "r", "PresenceMany", "path", "d", "Syncing", "animationProps", "animationDelay", "Date", "now", "div", "role", "icon", "size", "style", "classNames", "AttentionGlyph", "presence", "attended", "syncing", "containsAttended", "props", "forwardedRef", "data-attention", "data-contains-attended", "span", "ref", "useEffect", "useMemo", "Keyboard", "nestKeyboardContext", "advance", "ids", "currentId", "delta", "length", "undefined", "idx", "indexOf", "next", "Math", "max", "min", "useArticleKeyboardNavigation", "articleId", "items", "getId", "onSelect", "hasAttention", "useAttention", "useMemo", "map", "item", "id", "useEffect", "contextPath", "nestKeyboardContext", "context", "Keyboard", "singleton", "getContext", "prevContext", "getCurrentContext", "setCurrentContext", "nextBinding", "shortcut", "handler", "target", "data", "disableInput", "prevBinding", "bind", "unbind"]
7
- }
@@ -1 +0,0 @@
1
- {"inputs":{"src/attention.ts":{"bytes":25933,"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true}],"format":"esm"},"src/components/AttentionGlyph/AttentionGlyph.tsx":{"bytes":9775,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/components/AttentionGlyph/index.ts":{"bytes":394,"imports":[{"path":"src/components/AttentionGlyph/AttentionGlyph.tsx","kind":"import-statement","original":"./AttentionGlyph"}],"format":"esm"},"src/components/AttentionProvider/AttentionProvider.tsx":{"bytes":18161,"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-primitive","kind":"import-statement","external":true},{"path":"@radix-ui/react-slot","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/react-hooks","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true},{"path":"src/attention.ts","kind":"import-statement","original":"../../attention"}],"format":"esm"},"src/components/AttentionProvider/index.ts":{"bytes":401,"imports":[{"path":"src/components/AttentionProvider/AttentionProvider.tsx","kind":"import-statement","original":"./AttentionProvider"}],"format":"esm"},"src/view-state/view-state.ts":{"bytes":8199,"imports":[],"format":"esm"},"src/view-state/backends.ts":{"bytes":19210,"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"effect/Schema","kind":"import-statement","external":true}],"format":"esm"},"src/view-state/index.ts":{"bytes":470,"imports":[{"path":"src/view-state/view-state.ts","kind":"import-statement","original":"./view-state"},{"path":"src/view-state/backends.ts","kind":"import-statement","original":"./backends"}],"format":"esm"},"src/selection.ts":{"bytes":12380,"imports":[{"path":"effect/Match","kind":"import-statement","external":true},{"path":"effect/Schema","kind":"import-statement","external":true},{"path":"src/view-state/index.ts","kind":"import-statement","original":"./view-state"}],"format":"esm"},"src/components/ViewStateProvider/ViewStateProvider.tsx":{"bytes":15088,"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/react-hooks","kind":"import-statement","external":true},{"path":"src/selection.ts","kind":"import-statement","original":"../../selection"},{"path":"src/view-state/index.ts","kind":"import-statement","original":"../../view-state"}],"format":"esm"},"src/components/ViewStateProvider/index.ts":{"bytes":401,"imports":[{"path":"src/components/ViewStateProvider/ViewStateProvider.tsx","kind":"import-statement","original":"./ViewStateProvider"}],"format":"esm"},"src/components/index.ts":{"bytes":616,"imports":[{"path":"src/components/AttentionGlyph/index.ts","kind":"import-statement","original":"./AttentionGlyph"},{"path":"src/components/AttentionProvider/index.ts","kind":"import-statement","original":"./AttentionProvider"},{"path":"src/components/ViewStateProvider/index.ts","kind":"import-statement","original":"./ViewStateProvider"}],"format":"esm"},"src/useArticleKeyboardNavigation.ts":{"bytes":11909,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/keyboard","kind":"import-statement","external":true},{"path":"src/components/index.ts","kind":"import-statement","original":"./components"}],"format":"esm"},"src/index.ts":{"bytes":790,"imports":[{"path":"src/attention.ts","kind":"import-statement","original":"./attention"},{"path":"src/components/index.ts","kind":"import-statement","original":"./components"},{"path":"src/selection.ts","kind":"import-statement","original":"./selection"},{"path":"src/useArticleKeyboardNavigation.ts","kind":"import-statement","original":"./useArticleKeyboardNavigation"},{"path":"src/view-state/index.ts","kind":"import-statement","original":"./view-state"}],"format":"esm"},"src/testing/decorators/withAttention.ts":{"bytes":3505,"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"src/attention.ts","kind":"import-statement","original":"../../attention"},{"path":"src/components/index.ts","kind":"import-statement","original":"../../components"}],"format":"esm"},"src/testing/decorators/index.ts":{"bytes":389,"imports":[{"path":"src/testing/decorators/withAttention.ts","kind":"import-statement","original":"./withAttention"}],"format":"esm"},"src/testing/index.ts":{"bytes":382,"imports":[{"path":"src/testing/decorators/index.ts","kind":"import-statement","original":"./decorators"}],"format":"esm"},"src/types/index.ts":{"bytes":1166,"imports":[{"path":"src/attention.ts","kind":"import-statement","original":"../attention"},{"path":"src/selection.ts","kind":"import-statement","original":"../selection"},{"path":"src/view-state/index.ts","kind":"import-statement","original":"../view-state"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":11207},"dist/lib/browser/index.mjs":{"imports":[{"path":"dist/lib/browser/chunk-I4FDY4AZ.mjs","kind":"import-statement"},{"path":"dist/lib/browser/chunk-4HYAJ4IO.mjs","kind":"import-statement"},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/keyboard","kind":"import-statement","external":true}],"exports":["AttendableContainer","AttentionGlyph","AttentionManager","LocalBackend","MemoryBackend","RootAttentionProvider","SelectionSchema","Syncing","ViewStateManager","ViewStateProvider","advance","createDefaultBackends","defaultSelection","defineViewState","expandAttendableId","getAttendables","getLinkedVariant","getParentId","getSegmentId","getSelectionSet","isLinkedSegment","linkedSegment","resolveSelection","selectionAspect","toggleSelection","useArticleKeyboardNavigation","useAttended","useAttention","useAttentionAttributes","useAttentionContext","useSelection","useSelectionActions","useViewState","useViewStateActions","useViewStateManager","useViewStateManagerOptional"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":0},"src/components/AttentionGlyph/AttentionGlyph.tsx":{"bytesInOutput":2911},"src/useArticleKeyboardNavigation.ts":{"bytesInOutput":1979}},"bytes":6461},"dist/lib/browser/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":1875},"dist/lib/browser/testing/index.mjs":{"imports":[{"path":"dist/lib/browser/chunk-I4FDY4AZ.mjs","kind":"import-statement"},{"path":"dist/lib/browser/chunk-4HYAJ4IO.mjs","kind":"import-statement"},{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"exports":["withAttention"],"entryPoint":"src/testing/index.ts","inputs":{"src/testing/decorators/withAttention.ts":{"bytesInOutput":610},"src/testing/index.ts":{"bytesInOutput":0}},"bytes":863},"dist/lib/browser/chunk-I4FDY4AZ.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":15951},"dist/lib/browser/chunk-I4FDY4AZ.mjs":{"imports":[{"path":"dist/lib/browser/chunk-4HYAJ4IO.mjs","kind":"import-statement"},{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-primitive","kind":"import-statement","external":true},{"path":"@radix-ui/react-slot","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/react-hooks","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true},{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/react-hooks","kind":"import-statement","external":true}],"exports":["AttendableContainer","RootAttentionProvider","ViewStateProvider","useAttended","useAttention","useAttentionAttributes","useAttentionContext","useSelection","useSelectionActions","useViewState","useViewStateActions","useViewStateManager","useViewStateManagerOptional"],"inputs":{"src/components/AttentionProvider/AttentionProvider.tsx":{"bytesInOutput":3786},"src/components/ViewStateProvider/ViewStateProvider.tsx":{"bytesInOutput":3199}},"bytes":7620},"dist/lib/browser/types/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"dist/lib/browser/types/index.mjs":{"imports":[{"path":"dist/lib/browser/chunk-4HYAJ4IO.mjs","kind":"import-statement"}],"exports":["AttentionManager","LocalBackend","MemoryBackend","SelectionSchema","ViewStateManager","createDefaultBackends","defaultSelection","defineViewState","expandAttendableId","getAttendables","getLinkedVariant","getParentId","getSegmentId","getSelectionSet","isLinkedSegment","linkedSegment","resolveSelection","selectionAspect","toggleSelection"],"entryPoint":"src/types/index.ts","inputs":{"src/types/index.ts":{"bytesInOutput":0}},"bytes":806},"dist/lib/browser/chunk-4HYAJ4IO.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":33376},"dist/lib/browser/chunk-4HYAJ4IO.mjs":{"imports":[{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"effect/Schema","kind":"import-statement","external":true},{"path":"effect/Match","kind":"import-statement","external":true},{"path":"effect/Schema","kind":"import-statement","external":true}],"exports":["AttentionManager","LocalBackend","MemoryBackend","SelectionSchema","ViewStateManager","createDefaultBackends","defaultSelection","defineViewState","expandAttendableId","getAttendables","getLinkedVariant","getParentId","getSegmentId","getSelectionSet","isLinkedSegment","linkedSegment","resolveSelection","selectionAspect","toggleSelection"],"inputs":{"src/attention.ts":{"bytesInOutput":5433},"src/view-state/view-state.ts":{"bytesInOutput":1053},"src/view-state/backends.ts":{"bytesInOutput":3752},"src/selection.ts":{"bytesInOutput":2312}},"bytes":13071}}}
@@ -1,30 +0,0 @@
1
- import {
2
- RootAttentionProvider,
3
- ViewStateProvider
4
- } from "../chunk-I4FDY4AZ.mjs";
5
- import {
6
- AttentionManager
7
- } from "../chunk-4HYAJ4IO.mjs";
8
-
9
- // src/testing/decorators/withAttention.ts
10
- import { Registry, RegistryContext } from "@effect-atom/atom-react";
11
- import { createElement, useMemo } from "react";
12
- var withAttention = (initialAttendedId) => {
13
- return (Story) => {
14
- const registry = useMemo(() => Registry.make(), []);
15
- const attention = useMemo(() => initialAttendedId ? new AttentionManager(registry, [
16
- initialAttendedId
17
- ]) : void 0, [
18
- registry
19
- ]);
20
- return createElement(RegistryContext.Provider, {
21
- value: registry
22
- }, createElement(RootAttentionProvider, {
23
- attention
24
- }, createElement(ViewStateProvider, {}, createElement(Story))));
25
- };
26
- };
27
- export {
28
- withAttention
29
- };
30
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/testing/decorators/withAttention.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Registry, RegistryContext } from '@effect-atom/atom-react';\nimport { type Decorator } from '@storybook/react';\nimport { createElement, useMemo } from 'react';\n\nimport { AttentionManager } from '../../attention';\nimport { RootAttentionProvider, ViewStateProvider } from '../../components';\n\n/**\n * Storybook decorator that provides attention context.\n * @param initialAttendedId Optional ID to set as initially attended.\n */\nexport const withAttention = (initialAttendedId?: string): Decorator => {\n return (Story) => {\n const registry = useMemo(() => Registry.make(), []);\n const attention = useMemo(\n () => (initialAttendedId ? new AttentionManager(registry, [initialAttendedId]) : undefined),\n [registry],\n );\n\n return createElement(\n RegistryContext.Provider,\n { value: registry },\n createElement(RootAttentionProvider, { attention }, createElement(ViewStateProvider, {}, createElement(Story))),\n );\n };\n};\n"],
5
- "mappings": ";;;;;;;;;AAIA,SAASA,UAAUC,uBAAuB;AAE1C,SAASC,eAAeC,eAAe;AAShC,IAAMC,gBAAgB,CAACC,sBAAAA;AAC5B,SAAO,CAACC,UAAAA;AACN,UAAMC,WAAWC,QAAQ,MAAMC,SAASC,KAAI,GAAI,CAAA,CAAE;AAClD,UAAMC,YAAYH,QAChB,MAAOH,oBAAoB,IAAIO,iBAAiBL,UAAU;MAACF;KAAkB,IAAIQ,QACjF;MAACN;KAAS;AAGZ,WAAOO,cACLC,gBAAgBC,UAChB;MAAEC,OAAOV;IAAS,GAClBO,cAAcI,uBAAuB;MAAEP;IAAU,GAAGG,cAAcK,mBAAmB,CAAC,GAAGL,cAAcR,KAAAA,CAAAA,CAAAA,CAAAA;EAE3G;AACF;",
6
- "names": ["Registry", "RegistryContext", "createElement", "useMemo", "withAttention", "initialAttendedId", "Story", "registry", "useMemo", "Registry", "make", "attention", "AttentionManager", "undefined", "createElement", "RegistryContext", "Provider", "value", "RootAttentionProvider", "ViewStateProvider"]
7
- }
@@ -1,43 +0,0 @@
1
- import {
2
- AttentionManager,
3
- LocalBackend,
4
- MemoryBackend,
5
- SelectionSchema,
6
- ViewStateManager,
7
- createDefaultBackends,
8
- defaultSelection,
9
- defineViewState,
10
- expandAttendableId,
11
- getAttendables,
12
- getLinkedVariant,
13
- getParentId,
14
- getSegmentId,
15
- getSelectionSet,
16
- isLinkedSegment,
17
- linkedSegment,
18
- resolveSelection,
19
- selectionAspect,
20
- toggleSelection
21
- } from "../chunk-4HYAJ4IO.mjs";
22
- export {
23
- AttentionManager,
24
- LocalBackend,
25
- MemoryBackend,
26
- SelectionSchema,
27
- ViewStateManager,
28
- createDefaultBackends,
29
- defaultSelection,
30
- defineViewState,
31
- expandAttendableId,
32
- getAttendables,
33
- getLinkedVariant,
34
- getParentId,
35
- getSegmentId,
36
- getSelectionSet,
37
- isLinkedSegment,
38
- linkedSegment,
39
- resolveSelection,
40
- selectionAspect,
41
- toggleSelection
42
- };
43
- //# sourceMappingURL=index.mjs.map