@dxos/react-ui-attention 0.8.3-main.672df60 → 0.8.3-main.7f5a14c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{chunk-GS3SZRGH.mjs → chunk-PL2OIVDU.mjs} +31 -7
- package/dist/lib/browser/{chunk-GS3SZRGH.mjs.map → chunk-PL2OIVDU.mjs.map} +3 -3
- package/dist/lib/browser/index.mjs +7 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/{chunk-FCPQP37W.cjs → chunk-UHRK5BJW.cjs} +38 -12
- package/dist/lib/node/chunk-UHRK5BJW.cjs.map +7 -0
- package/dist/lib/node/index.cjs +28 -24
- package/dist/lib/node/index.cjs.map +2 -2
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +2 -2
- package/dist/lib/node-esm/{chunk-ZGL23C7V.mjs → chunk-FJBSBKQ5.mjs} +31 -7
- package/dist/lib/node-esm/{chunk-ZGL23C7V.mjs.map → chunk-FJBSBKQ5.mjs.map} +3 -3
- package/dist/lib/node-esm/index.mjs +7 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +1 -1
- package/dist/types/src/components/SelectionProvider.d.ts +9 -8
- package/dist/types/src/components/SelectionProvider.d.ts.map +1 -1
- package/dist/types/src/selection.d.ts +10 -7
- package/dist/types/src/selection.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/components/SelectionProvider.tsx +19 -10
- package/src/selection.ts +33 -12
- package/dist/lib/node/chunk-FCPQP37W.cjs.map +0 -7
|
@@ -336,6 +336,20 @@ var defaultSelection = Match.type().pipe(Match.when("single", () => ({
|
|
|
336
336
|
mode: "multi-range",
|
|
337
337
|
ranges: []
|
|
338
338
|
})), Match.exhaustive);
|
|
339
|
+
var getSelectionSet = (selectionManager, contextId) => {
|
|
340
|
+
const ids = new Set(contextId ? [
|
|
341
|
+
contextId
|
|
342
|
+
] : []);
|
|
343
|
+
for (const context of selectionManager.getSelectionContexts()) {
|
|
344
|
+
const selection = selectionManager.getSelection(context);
|
|
345
|
+
if (selection?.mode === "multi") {
|
|
346
|
+
for (const id of selection.ids) {
|
|
347
|
+
ids.add(id);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return ids;
|
|
352
|
+
};
|
|
339
353
|
var SelectionManager = class {
|
|
340
354
|
constructor(initial = {}) {
|
|
341
355
|
this._state = live2({
|
|
@@ -347,6 +361,9 @@ var SelectionManager = class {
|
|
|
347
361
|
});
|
|
348
362
|
}
|
|
349
363
|
}
|
|
364
|
+
getSelectionContexts() {
|
|
365
|
+
return Object.keys(this._state.selections);
|
|
366
|
+
}
|
|
350
367
|
getSelection(contextId, mode = void 0) {
|
|
351
368
|
const selection = untracked2(() => this._state.selections[contextId]);
|
|
352
369
|
if (!mode || selection) {
|
|
@@ -357,11 +374,12 @@ var SelectionManager = class {
|
|
|
357
374
|
return this._state.selections[contextId];
|
|
358
375
|
});
|
|
359
376
|
}
|
|
377
|
+
// TODO(burdon): Disambiguate with getSelection?
|
|
360
378
|
getSelected(contextId, mode = "multi") {
|
|
361
379
|
const selection = this.getSelection(contextId, mode);
|
|
362
380
|
invariant(selection?.mode === mode, "Selection mode mismatch", {
|
|
363
381
|
F: __dxlog_file,
|
|
364
|
-
L:
|
|
382
|
+
L: 91,
|
|
365
383
|
S: this,
|
|
366
384
|
A: [
|
|
367
385
|
"selection?.mode === mode",
|
|
@@ -386,7 +404,7 @@ var SelectionManager = class {
|
|
|
386
404
|
const selection = this.getSelection(contextId, "single");
|
|
387
405
|
invariant(selection?.mode === "single", "Selection mode is not single", {
|
|
388
406
|
F: __dxlog_file,
|
|
389
|
-
L:
|
|
407
|
+
L: 104,
|
|
390
408
|
S: this,
|
|
391
409
|
A: [
|
|
392
410
|
"selection?.mode === 'single'",
|
|
@@ -401,7 +419,7 @@ var SelectionManager = class {
|
|
|
401
419
|
const selection = this.getSelection(contextId, "multi");
|
|
402
420
|
invariant(selection?.mode === "multi", "Selection mode is not multi", {
|
|
403
421
|
F: __dxlog_file,
|
|
404
|
-
L:
|
|
422
|
+
L: 112,
|
|
405
423
|
S: this,
|
|
406
424
|
A: [
|
|
407
425
|
"selection?.mode === 'multi'",
|
|
@@ -416,7 +434,7 @@ var SelectionManager = class {
|
|
|
416
434
|
const selection = this.getSelection(contextId, "range");
|
|
417
435
|
invariant(selection?.mode === "range", "Selection mode is not range", {
|
|
418
436
|
F: __dxlog_file,
|
|
419
|
-
L:
|
|
437
|
+
L: 120,
|
|
420
438
|
S: this,
|
|
421
439
|
A: [
|
|
422
440
|
"selection?.mode === 'range'",
|
|
@@ -432,7 +450,7 @@ var SelectionManager = class {
|
|
|
432
450
|
const selection = this.getSelection(contextId, "multi-range");
|
|
433
451
|
invariant(selection?.mode === "multi-range", "Selection mode is not multi-range", {
|
|
434
452
|
F: __dxlog_file,
|
|
435
|
-
L:
|
|
453
|
+
L: 129,
|
|
436
454
|
S: this,
|
|
437
455
|
A: [
|
|
438
456
|
"selection?.mode === 'multi-range'",
|
|
@@ -455,7 +473,7 @@ var SelectionManager = class {
|
|
|
455
473
|
const selection = this.getSelection(contextId, "multi");
|
|
456
474
|
invariant(selection?.mode === "multi", "Selection mode is not multi", {
|
|
457
475
|
F: __dxlog_file,
|
|
458
|
-
L:
|
|
476
|
+
L: 146,
|
|
459
477
|
S: this,
|
|
460
478
|
A: [
|
|
461
479
|
"selection?.mode === 'multi'",
|
|
@@ -493,6 +511,10 @@ var SelectionProvider = ({ children, selection: propsSelection }) => {
|
|
|
493
511
|
_effect.f();
|
|
494
512
|
}
|
|
495
513
|
};
|
|
514
|
+
var useSelectionManager = () => {
|
|
515
|
+
const { selection } = useSelectionContext(SELECTION_NAME);
|
|
516
|
+
return selection;
|
|
517
|
+
};
|
|
496
518
|
var useSelected = (contextId, mode = "multi") => {
|
|
497
519
|
const { selection } = useSelectionContext(SELECTION_NAME);
|
|
498
520
|
if (contextId) {
|
|
@@ -584,9 +606,11 @@ export {
|
|
|
584
606
|
AttentionProvider,
|
|
585
607
|
AttendableContainer,
|
|
586
608
|
defaultSelection,
|
|
609
|
+
getSelectionSet,
|
|
587
610
|
SelectionManager,
|
|
588
611
|
SelectionProvider,
|
|
612
|
+
useSelectionManager,
|
|
589
613
|
useSelected,
|
|
590
614
|
useSelectionActions
|
|
591
615
|
};
|
|
592
|
-
//# sourceMappingURL=chunk-
|
|
616
|
+
//# sourceMappingURL=chunk-PL2OIVDU.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/attention.ts", "../../../src/components/AttentionGlyph.tsx", "../../../src/components/AttentionProvider.tsx", "../../../src/selection.ts", "../../../src/components/SelectionProvider.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { untracked } from '@preact/signals-core';\nimport { Schema } from 'effect';\n\nimport { live, type Live } from '@dxos/live-object';\nimport { ComplexMap } from '@dxos/util';\n\n// NOTE: Chosen from RFC 1738’s `safe` characters: http://www.faqs.org/rfcs/rfc1738.html\nexport const ATTENDABLE_PATH_SEPARATOR = '~';\n\nexport const AttentionSchema = Schema.mutable(\n Schema.Struct({\n hasAttention: Schema.Boolean,\n isAncestor: Schema.Boolean,\n isRelated: Schema.Boolean,\n }),\n);\n\nexport type Attention = Schema.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[], Live<Attention>>(stringKey);\n private readonly _state = live<{ 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 * @reactive\n */\n get current(): Live<readonly string[]> {\n return this._state.current;\n }\n\n /**\n * All attention paths.\n */\n keys(): string[][] {\n return Array.from(this._map.keys());\n }\n\n /**\n * Get the attention state for a given path.\n */\n get(key: string[]): Live<Attention> {\n const object = this._map.get(key);\n if (object) {\n return object;\n }\n\n const newObject = live(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 * @internal\n */\n update(nextKey: string[]): void {\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>): void {\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.split(ATTENDABLE_PATH_SEPARATOR));\n // TODO: Attempt tail recursion.\n return !closestAttendable.parentElement ? acc : getAttendables(selector, closestAttendable.parentElement, acc);\n }\n }\n\n return [...new Set(acc)];\n};\n\nexport type AttendableId = { attendableId?: string };\n\nexport type Related = { related?: boolean };\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Primitive } from '@radix-ui/react-primitive';\nimport React, { type ComponentPropsWithRef, type CSSProperties, forwardRef, useMemo } from 'react';\n\nimport { Icon, 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-contains-attended=true]_&]:bg-attentionRelated [[data-attention=true]_&]:bg-accentSurface [[data-attention=true]_&]:text-accentSurfaceText [[aria-current][data-attention=true]_&]:bg-accentSurface [[aria-current][data-attention=true]_&]:text-accentSurfaceText';\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 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 role='none' className='flex' data-attention={attended} data-contains-attended={containsAttended}>\n <span role='none' {...props} className={mx(attentionGlyphStyles, classNames)} ref={forwardedRef}>\n {icon}\n </span>\n </div>\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 { Primitive } from '@radix-ui/react-primitive';\nimport { Slot } from '@radix-ui/react-slot';\nimport React, { useMemo, type FocusEvent, type PropsWithChildren, type ComponentPropsWithRef, forwardRef } from 'react';\n\nimport { useDefaultValue, type ThemedClassName } from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { ATTENDABLE_PATH_SEPARATOR, 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.split(ATTENDABLE_PATH_SEPARATOR), ...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 useAttentionAttributes = (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\n // NOTE(thure): Use the following to debug the macOS package issue #8540\n\n // const [startEl, setStartEl] = useState<HTMLElement | null>(null);\n // const [endEl, setEndEl] = useState<HTMLElement | null>(null);\n //\n // const handleEventDebug = useCallback((event: any) => {\n // console.log(`[${event.type}]`, event.target, event.currentTarget, [event.clientX, event.clientY]);\n // }, []);\n //\n // const handleStartDebug = useCallback(\n // (event: any) => {\n // setStartEl(event.target);\n // handleEventDebug(event);\n // },\n // [handleEventDebug],\n // );\n //\n // const handleEndDebug = useCallback(\n // (event: any) => {\n // setEndEl(event.target);\n // handleEventDebug(event);\n // },\n // [handleEventDebug],\n // );\n //\n // const handleClickDebug = useCallback(\n // (event: any) => {\n // console.log('[click compare]', startEl, endEl, startEl === endEl);\n // handleEventDebug(event);\n // },\n // [startEl, endEl, handleEventDebug],\n // );\n\n return (\n <AttentionContextProvider attention={attention} path={[]}>\n <div\n role='none'\n className='contents'\n onFocusCapture={handleFocus}\n // onClick={handleClickDebug}\n // onMouseDown={handleStartDebug}\n // onMouseUp={handleEndDebug}\n >\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 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, and when rendering content in those cases it\n * is not necessary to also render an `AttendableContainer`. This component is primarily for Storybook stories and other\n * testing scenarios, 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 Root = asChild ? Slot : Primitive.div;\n return (\n <Root\n role='none'\n {...attentionAttrs}\n {...props}\n className={mx('attention-surface', props.tabIndex === 0 && 'dx-focus-ring-inset-over-all', classNames)}\n ref={forwardedRef}\n >\n {children}\n </Root>\n );\n },\n);\n\nexport {\n RootAttentionProvider,\n AttentionProvider,\n AttendableContainer,\n useAttentionContext,\n useAttention,\n useAttended,\n useAttentionAttributes,\n useAttentionPath,\n ATTENTION_NAME,\n ATTENABLE_ATTRIBUTE,\n ATTENTION_SOURCE_ATTRIBUTE,\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { untracked } from '@preact/signals-core';\nimport { Match } from 'effect';\n\nimport { invariant } from '@dxos/invariant';\nimport { live, type Live } from '@dxos/live-object';\n\nexport type SelectionMode = 'single' | 'multi' | 'range' | 'multi-range';\n\nexport type Selection =\n | { mode: 'single'; id?: string }\n | { mode: 'multi'; ids: string[] }\n | { mode: 'range'; from?: string; to?: string }\n | { mode: 'multi-range'; ranges: { from: string; to: string }[] };\n\nexport const defaultSelection = Match.type<SelectionMode>().pipe(\n Match.when('single', () => ({ mode: 'single' }) as Selection),\n Match.when('multi', () => ({ mode: 'multi', ids: [] }) as Selection),\n Match.when('range', () => ({ mode: 'range' }) as Selection),\n Match.when('multi-range', () => ({ mode: 'multi-range', ranges: [] }) as Selection),\n Match.exhaustive,\n);\n\n/**\n * Manages selection state for different contexts.\n * Each context maintains its own selection mode and state.\n */\nexport class SelectionManager {\n private readonly _state = live<{ selections: Record<string, Selection> }>({ selections: {} });\n\n constructor(initial: Record<string, Selection> = {}) {\n if (Object.keys(initial).length > 0) {\n untracked(() => {\n this._state.selections = initial;\n });\n }\n }\n\n getSelection<T extends SelectionMode | undefined>(\n contextId: string,\n mode: T = undefined as T,\n ): T extends undefined ? Live<Selection> | undefined : Live<Selection> {\n const selection = untracked(() => this._state.selections[contextId]);\n if (!mode || selection) {\n return selection;\n }\n\n return untracked(() => {\n this._state.selections[contextId] = defaultSelection(mode);\n return this._state.selections[contextId];\n });\n }\n\n getSelected<T extends SelectionMode>(\n contextId: string,\n mode: T = 'multi' as T,\n ): T extends 'single'\n ? string | undefined\n : T extends 'multi'\n ? string[]\n : T extends 'range'\n ? { from: string; to: string } | undefined\n : T extends 'multi-range'\n ? { from: string; to: string }[]\n : never {\n const selection = this.getSelection(contextId, mode);\n invariant(selection?.mode === mode, 'Selection mode mismatch');\n return Match.type<Selection>().pipe(\n Match.when({ mode: 'single' }, (s) => s.id),\n Match.when({ mode: 'multi' }, (s) => s.ids),\n Match.when({ mode: 'range' }, (s) => (s.from && s.to ? { from: s.from, to: s.to } : undefined)),\n Match.when({ mode: 'multi-range' }, (s) => s.ranges),\n Match.exhaustive,\n )(selection) as any;\n }\n\n updateSingle(contextId: string, id: string): void {\n untracked(() => {\n const selection = this.getSelection(contextId, 'single');\n invariant(selection?.mode === 'single', 'Selection mode is not single');\n selection.id = id;\n });\n }\n\n updateMulti(contextId: string, ids: string[]) {\n untracked(() => {\n const selection = this.getSelection(contextId, 'multi');\n invariant(selection?.mode === 'multi', 'Selection mode is not multi');\n selection.ids = ids;\n });\n }\n\n updateRange(contextId: string, from: string, to: string) {\n untracked(() => {\n const selection = this.getSelection(contextId, 'range');\n invariant(selection?.mode === 'range', 'Selection mode is not range');\n selection.from = from;\n selection.to = to;\n });\n }\n\n updateMultiRange(contextId: string, ranges: { from: string; to: string }[]) {\n untracked(() => {\n const selection = this.getSelection(contextId, 'multi-range');\n invariant(selection?.mode === 'multi-range', 'Selection mode is not multi-range');\n selection.ranges = ranges;\n });\n }\n\n clearSelection(contextId: string): void {\n untracked(() => {\n const selection = this.getSelection(contextId);\n if (selection) {\n this._state.selections[contextId] = defaultSelection(selection.mode);\n }\n });\n }\n\n toggleSelection(contextId: string, id: string): void {\n untracked(() => {\n const selection = this.getSelection(contextId, 'multi');\n invariant(selection?.mode === 'multi', 'Selection mode is not multi');\n\n if (selection.ids.includes(id)) {\n const index = selection.ids.indexOf(id);\n selection.ids.splice(index, 1);\n } else {\n selection.ids.push(id);\n }\n });\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { createContext } from '@radix-ui/react-context';\nimport { Match } from 'effect';\nimport React, { useCallback, useMemo, type PropsWithChildren } from 'react';\n\nimport { useDefaultValue } from '@dxos/react-ui';\n\nimport { defaultSelection, SelectionManager, type Selection, type SelectionMode } from '../selection';\n\nconst SELECTION_NAME = 'Selection';\n\ntype SelectionContextValue = {\n selection: SelectionManager;\n};\n\nconst [SelectionContextProvider, useSelectionContext] = createContext<SelectionContextValue>(SELECTION_NAME, {\n selection: new SelectionManager(),\n});\n\n/**\n * Manages selection state across the app for multiple contexts.\n */\n// TODO(burdon): When is the selection removed?\nexport const SelectionProvider = ({\n children,\n selection: propsSelection,\n}: PropsWithChildren<{ selection?: SelectionManager }>) => {\n const selection = useDefaultValue(propsSelection, () => new SelectionManager());\n return <SelectionContextProvider selection={selection}>{children}</SelectionContextProvider>;\n};\n\nexport const useSelected = <T extends SelectionMode>(\n contextId?: string,\n mode: T = 'multi' as T,\n): T extends 'single'\n ? string | undefined\n : T extends 'multi'\n ? string[]\n : T extends 'range'\n ? { from: string; to: string } | undefined\n : T extends 'multi-range'\n ? { from: string; to: string }[]\n : never => {\n const { selection } = useSelectionContext(SELECTION_NAME);\n if (contextId) {\n return selection.getSelected(contextId, mode);\n }\n\n return Match.type<Selection>().pipe(\n Match.when({ mode: 'single' }, (s) => s.id),\n Match.when({ mode: 'multi' }, (s) => s.ids),\n Match.when({ mode: 'range' }, (s) => (s.from && s.to ? { from: s.from, to: s.to } : undefined)),\n Match.when({ mode: 'multi-range' }, (s) => s.ranges),\n Match.exhaustive,\n )(defaultSelection(mode)) as any;\n};\n\n/**\n * Provides functions to manage the selection state for multiple contexts.\n */\nexport const useSelectionActions = (contextIds: string[], mode: SelectionMode = 'multi') => {\n const stableContextIds = useMemo(() => contextIds, [JSON.stringify(contextIds)]); // TODO(burdon): Avoid stringify.\n const { selection } = useSelectionContext(SELECTION_NAME);\n\n const singleSelect = useCallback(\n (id: string) => {\n for (const contextId of stableContextIds) {\n selection.updateSingle(contextId, id);\n }\n },\n [selection, stableContextIds],\n );\n\n const multiSelect = useCallback(\n (ids: string[]) => {\n for (const contextId of stableContextIds) {\n selection.updateMulti(contextId, ids);\n }\n },\n [selection, stableContextIds],\n );\n\n const rangeSelect = useCallback(\n (from: string, to: string) => {\n for (const contextId of stableContextIds) {\n selection.updateRange(contextId, from, to);\n }\n },\n [selection, stableContextIds],\n );\n\n const toggle = useCallback(\n (id: string) => {\n for (const contextId of stableContextIds) {\n selection.toggleSelection(contextId, id);\n }\n },\n [selection, stableContextIds],\n );\n\n const clear = useCallback(() => {\n for (const contextId of stableContextIds) {\n selection.clearSelection(contextId);\n }\n }, [selection, stableContextIds]);\n\n return { singleSelect, multiSelect, rangeSelect, toggle, clear };\n};\n"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,iBAAiB;AAC1B,SAASC,cAAc;AAEvB,SAASC,YAAuB;AAChC,SAASC,kBAAkB;AAGpB,IAAMC,4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BC,iBAAiBd,IAAAA,CAAAA;AACrB;AAKO,IAAMe,sBAAsB,CAACC,YAAsBhB,OAAsB,YAAO;AACrF,QAAMiB,mBAAmBC,SAAQ,MAAMF,YAAY;IAACG,KAAKC,UAAUJ,UAAAA;GAAY;AAC/E,QAAM,EAAEzB,UAAS,IAAKF,oBAAoBF,cAAAA;AAE1C,QAAMkC,eAAeC,YACnB,CAACf,OAAAA;AACC,eAAWR,aAAakB,kBAAkB;AACxC1B,gBAAUgC,aAAaxB,WAAWQ,EAAAA;IACpC;EACF,GACA;IAAChB;IAAW0B;GAAiB;AAG/B,QAAMO,cAAcF,YAClB,CAACd,QAAAA;AACC,eAAWT,aAAakB,kBAAkB;AACxC1B,gBAAUkC,YAAY1B,WAAWS,GAAAA;IACnC;EACF,GACA;IAACjB;IAAW0B;GAAiB;AAG/B,QAAMS,cAAcJ,YAClB,CAACb,MAAcC,OAAAA;AACb,eAAWX,aAAakB,kBAAkB;AACxC1B,gBAAUoC,YAAY5B,WAAWU,MAAMC,EAAAA;IACzC;EACF,GACA;IAACnB;IAAW0B;GAAiB;AAG/B,QAAMW,SAASN,YACb,CAACf,OAAAA;AACC,eAAWR,aAAakB,kBAAkB;AACxC1B,gBAAUsC,gBAAgB9B,WAAWQ,EAAAA;IACvC;EACF,GACA;IAAChB;IAAW0B;GAAiB;AAG/B,QAAMa,QAAQR,YAAY,MAAA;AACxB,eAAWvB,aAAakB,kBAAkB;AACxC1B,gBAAUwC,eAAehC,SAAAA;IAC3B;EACF,GAAG;IAACR;IAAW0B;GAAiB;AAEhC,SAAO;IAAEI;IAAcG;IAAaE;IAAaE;IAAQE;EAAM;AACjE;",
|
|
6
|
-
"names": ["untracked", "Schema", "live", "ComplexMap", "ATTENDABLE_PATH_SEPARATOR", "AttentionSchema", "Schema", "mutable", "Struct", "hasAttention", "Boolean", "isAncestor", "isRelated", "stringKey", "key", "join", "AttentionManager", "initial", "_map", "ComplexMap", "_state", "live", "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", "split", "parentElement", "Set", "React", "forwardRef", "useMemo", "Icon", "mx", "attentionGlyphStyles", "presenceIconStyles", "PresenceOne", "svg", "width", "height", "viewBox", "className", "fill", "xmlns", "circle", "cx", "cy", "r", "PresenceMany", "path", "d", "Syncing", "animationProps", "useMemo", "animationDelay", "Date", "now", "div", "role", "Icon", "icon", "size", "style", "classNames", "AttentionGlyph", "forwardRef", "presence", "attended", "syncing", "containsAttended", "props", "forwardedRef", "data-attention", "data-contains-attended", "span", "mx", "ref", "createContext", "Primitive", "Slot", "React", "useMemo", "forwardRef", "useDefaultValue", "mx", "ATTENTION_NAME", "ATTENABLE_ATTRIBUTE", "ATTENTION_SOURCE_ATTRIBUTE", "AttentionContextProvider", "useAttentionContext", "createContext", "attention", "AttentionManager", "path", "UNKNOWN_ATTENDABLE", "hasAttention", "isAncestor", "isRelated", "useAttention", "attendableId", "current", "split", "ATTENDABLE_PATH_SEPARATOR", "get", "useAttended", "useAttentionAttributes", "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", "AttendableContainer", "forwardRef", "classNames", "asChild", "props", "forwardedRef", "attentionAttrs", "Root", "Slot", "Primitive", "mx", "tabIndex", "ref", "untracked", "Match", "invariant", "live", "defaultSelection", "type", "pipe", "when", "mode", "ids", "ranges", "exhaustive", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { untracked } from '@preact/signals-core';\nimport { Schema } from 'effect';\n\nimport { live, type Live } from '@dxos/live-object';\nimport { ComplexMap } from '@dxos/util';\n\n// NOTE: Chosen from RFC 1738’s `safe` characters: http://www.faqs.org/rfcs/rfc1738.html\nexport const ATTENDABLE_PATH_SEPARATOR = '~';\n\nexport const AttentionSchema = Schema.mutable(\n Schema.Struct({\n hasAttention: Schema.Boolean,\n isAncestor: Schema.Boolean,\n isRelated: Schema.Boolean,\n }),\n);\n\nexport type Attention = Schema.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[], Live<Attention>>(stringKey);\n private readonly _state = live<{ 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 * @reactive\n */\n get current(): Live<readonly string[]> {\n return this._state.current;\n }\n\n /**\n * All attention paths.\n */\n keys(): string[][] {\n return Array.from(this._map.keys());\n }\n\n /**\n * Get the attention state for a given path.\n */\n get(key: string[]): Live<Attention> {\n const object = this._map.get(key);\n if (object) {\n return object;\n }\n\n const newObject = live(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 * @internal\n */\n update(nextKey: string[]): void {\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>): void {\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.split(ATTENDABLE_PATH_SEPARATOR));\n // TODO: Attempt tail recursion.\n return !closestAttendable.parentElement ? acc : getAttendables(selector, closestAttendable.parentElement, acc);\n }\n }\n\n return [...new Set(acc)];\n};\n\nexport type AttendableId = { attendableId?: string };\n\nexport type Related = { related?: boolean };\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Primitive } from '@radix-ui/react-primitive';\nimport React, { type ComponentPropsWithRef, type CSSProperties, forwardRef, useMemo } from 'react';\n\nimport { Icon, 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-contains-attended=true]_&]:bg-attentionRelated [[data-attention=true]_&]:bg-accentSurface [[data-attention=true]_&]:text-accentSurfaceText [[aria-current][data-attention=true]_&]:bg-accentSurface [[aria-current][data-attention=true]_&]:text-accentSurfaceText';\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 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 role='none' className='flex' data-attention={attended} data-contains-attended={containsAttended}>\n <span role='none' {...props} className={mx(attentionGlyphStyles, classNames)} ref={forwardedRef}>\n {icon}\n </span>\n </div>\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 { Primitive } from '@radix-ui/react-primitive';\nimport { Slot } from '@radix-ui/react-slot';\nimport React, { useMemo, type FocusEvent, type PropsWithChildren, type ComponentPropsWithRef, forwardRef } from 'react';\n\nimport { useDefaultValue, type ThemedClassName } from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { ATTENDABLE_PATH_SEPARATOR, 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.split(ATTENDABLE_PATH_SEPARATOR), ...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 useAttentionAttributes = (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\n // NOTE(thure): Use the following to debug the macOS package issue #8540\n\n // const [startEl, setStartEl] = useState<HTMLElement | null>(null);\n // const [endEl, setEndEl] = useState<HTMLElement | null>(null);\n //\n // const handleEventDebug = useCallback((event: any) => {\n // console.log(`[${event.type}]`, event.target, event.currentTarget, [event.clientX, event.clientY]);\n // }, []);\n //\n // const handleStartDebug = useCallback(\n // (event: any) => {\n // setStartEl(event.target);\n // handleEventDebug(event);\n // },\n // [handleEventDebug],\n // );\n //\n // const handleEndDebug = useCallback(\n // (event: any) => {\n // setEndEl(event.target);\n // handleEventDebug(event);\n // },\n // [handleEventDebug],\n // );\n //\n // const handleClickDebug = useCallback(\n // (event: any) => {\n // console.log('[click compare]', startEl, endEl, startEl === endEl);\n // handleEventDebug(event);\n // },\n // [startEl, endEl, handleEventDebug],\n // );\n\n return (\n <AttentionContextProvider attention={attention} path={[]}>\n <div\n role='none'\n className='contents'\n onFocusCapture={handleFocus}\n // onClick={handleClickDebug}\n // onMouseDown={handleStartDebug}\n // onMouseUp={handleEndDebug}\n >\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 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, and when rendering content in those cases it\n * is not necessary to also render an `AttendableContainer`. This component is primarily for Storybook stories and other\n * testing scenarios, 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 Root = asChild ? Slot : Primitive.div;\n return (\n <Root\n role='none'\n {...attentionAttrs}\n {...props}\n className={mx('attention-surface', props.tabIndex === 0 && 'dx-focus-ring-inset-over-all', classNames)}\n ref={forwardedRef}\n >\n {children}\n </Root>\n );\n },\n);\n\nexport {\n RootAttentionProvider,\n AttentionProvider,\n AttendableContainer,\n useAttentionContext,\n useAttention,\n useAttended,\n useAttentionAttributes,\n useAttentionPath,\n ATTENTION_NAME,\n ATTENABLE_ATTRIBUTE,\n ATTENTION_SOURCE_ATTRIBUTE,\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { untracked } from '@preact/signals-core';\nimport { Match } from 'effect';\n\nimport { invariant } from '@dxos/invariant';\nimport { live, type Live } from '@dxos/live-object';\n\n// TODO(burdon): Reconcile with @dxos/graph.\n\nexport type SelectionMode = 'single' | 'multi' | 'range' | 'multi-range';\n\nexport type Selection =\n | { mode: 'single'; id?: string }\n | { mode: 'multi'; ids: string[] }\n | { mode: 'range'; from?: string; to?: string }\n | { mode: 'multi-range'; ranges: { from: string; to: string }[] };\n\nexport const defaultSelection = Match.type<SelectionMode>().pipe(\n Match.when('single', () => ({ mode: 'single' }) as Selection),\n Match.when('multi', () => ({ mode: 'multi', ids: [] }) as Selection),\n Match.when('range', () => ({ mode: 'range' }) as Selection),\n Match.when('multi-range', () => ({ mode: 'multi-range', ranges: [] }) as Selection),\n Match.exhaustive,\n);\n\nexport type SelectionResult<T extends SelectionMode> = T extends 'single'\n ? string | undefined\n : T extends 'multi'\n ? string[]\n : T extends 'range'\n ? { from: string; to: string } | undefined\n : T extends 'multi-range'\n ? { from: string; to: string }[]\n : never;\n\n// TODO(burdon): Refactor.\nexport const getSelectionSet = (selectionManager: SelectionManager, contextId?: string) => {\n const ids = new Set<string>(contextId ? [contextId] : []);\n for (const context of selectionManager.getSelectionContexts()) {\n const selection = selectionManager.getSelection(context);\n if (selection?.mode === 'multi') {\n for (const id of selection.ids) {\n ids.add(id);\n }\n }\n }\n\n return ids;\n};\n\n/**\n * Manages selection state for different contexts.\n * Each context maintains its own selection mode and state.\n */\nexport class SelectionManager {\n private readonly _state = live<{ selections: Record<string, Selection> }>({ selections: {} });\n\n constructor(initial: Record<string, Selection> = {}) {\n if (Object.keys(initial).length > 0) {\n untracked(() => {\n this._state.selections = initial;\n });\n }\n }\n\n getSelectionContexts(): string[] {\n return Object.keys(this._state.selections);\n }\n\n getSelection<T extends SelectionMode | undefined>(\n contextId: string,\n mode: T = undefined as T,\n ): T extends undefined ? Live<Selection> | undefined : Live<Selection> {\n const selection = untracked(() => this._state.selections[contextId]);\n if (!mode || selection) {\n return selection;\n }\n\n return untracked(() => {\n this._state.selections[contextId] = defaultSelection(mode);\n return this._state.selections[contextId];\n });\n }\n\n // TODO(burdon): Disambiguate with getSelection?\n getSelected<T extends SelectionMode>(contextId: string, mode: T = 'multi' as T): SelectionResult<T> {\n const selection = this.getSelection(contextId, mode);\n invariant(selection?.mode === mode, 'Selection mode mismatch');\n return Match.type<Selection>().pipe(\n Match.when({ mode: 'single' }, (s) => s.id),\n Match.when({ mode: 'multi' }, (s) => s.ids),\n Match.when({ mode: 'range' }, (s) => (s.from && s.to ? { from: s.from, to: s.to } : undefined)),\n Match.when({ mode: 'multi-range' }, (s) => s.ranges),\n Match.exhaustive,\n )(selection) as any;\n }\n\n updateSingle(contextId: string, id: string): void {\n untracked(() => {\n const selection = this.getSelection(contextId, 'single');\n invariant(selection?.mode === 'single', 'Selection mode is not single');\n selection.id = id;\n });\n }\n\n updateMulti(contextId: string, ids: string[]) {\n untracked(() => {\n const selection = this.getSelection(contextId, 'multi');\n invariant(selection?.mode === 'multi', 'Selection mode is not multi');\n selection.ids = ids;\n });\n }\n\n updateRange(contextId: string, from: string, to: string) {\n untracked(() => {\n const selection = this.getSelection(contextId, 'range');\n invariant(selection?.mode === 'range', 'Selection mode is not range');\n selection.from = from;\n selection.to = to;\n });\n }\n\n updateMultiRange(contextId: string, ranges: { from: string; to: string }[]) {\n untracked(() => {\n const selection = this.getSelection(contextId, 'multi-range');\n invariant(selection?.mode === 'multi-range', 'Selection mode is not multi-range');\n selection.ranges = ranges;\n });\n }\n\n clearSelection(contextId: string): void {\n untracked(() => {\n const selection = this.getSelection(contextId);\n if (selection) {\n this._state.selections[contextId] = defaultSelection(selection.mode);\n }\n });\n }\n\n toggleSelection(contextId: string, id: string): void {\n untracked(() => {\n const selection = this.getSelection(contextId, 'multi');\n invariant(selection?.mode === 'multi', 'Selection mode is not multi');\n\n if (selection.ids.includes(id)) {\n const index = selection.ids.indexOf(id);\n selection.ids.splice(index, 1);\n } else {\n selection.ids.push(id);\n }\n });\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { createContext } from '@radix-ui/react-context';\nimport { Match } from 'effect';\nimport React, { useCallback, useMemo, type PropsWithChildren } from 'react';\n\nimport { useDefaultValue } from '@dxos/react-ui';\n\nimport {\n defaultSelection,\n SelectionManager,\n type SelectionResult,\n type Selection,\n type SelectionMode,\n} from '../selection';\n\nconst SELECTION_NAME = 'Selection';\n\ntype SelectionContextValue = {\n selection: SelectionManager;\n};\n\nconst [SelectionContextProvider, useSelectionContext] = createContext<SelectionContextValue>(SELECTION_NAME, {\n selection: new SelectionManager(),\n});\n\n/**\n * Manages selection state across the app for multiple contexts.\n */\n// TODO(burdon): When is the selection removed?\nexport const SelectionProvider = ({\n children,\n selection: propsSelection,\n}: PropsWithChildren<{ selection?: SelectionManager }>) => {\n const selection = useDefaultValue(propsSelection, () => new SelectionManager());\n return <SelectionContextProvider selection={selection}>{children}</SelectionContextProvider>;\n};\n\n/**\n * Get the selection contexts.\n */\nexport const useSelectionManager = () => {\n const { selection } = useSelectionContext(SELECTION_NAME);\n return selection;\n};\n\n/**\n * Get the selected objects for a given context.\n */\nexport const useSelected = <T extends SelectionMode>(\n contextId?: string,\n mode: T = 'multi' as T,\n): SelectionResult<T> => {\n const { selection } = useSelectionContext(SELECTION_NAME);\n if (contextId) {\n return selection.getSelected(contextId, mode);\n }\n\n return Match.type<Selection>().pipe(\n Match.when({ mode: 'single' }, (s) => s.id),\n Match.when({ mode: 'multi' }, (s) => s.ids),\n Match.when({ mode: 'range' }, (s) => (s.from && s.to ? { from: s.from, to: s.to } : undefined)),\n Match.when({ mode: 'multi-range' }, (s) => s.ranges),\n Match.exhaustive,\n )(defaultSelection(mode)) as any;\n};\n\n/**\n * Provides functions to manage the selection state for multiple contexts.\n */\nexport const useSelectionActions = (contextIds: string[], mode: SelectionMode = 'multi') => {\n const stableContextIds = useMemo(() => contextIds, [JSON.stringify(contextIds)]); // TODO(burdon): Avoid stringify.\n const { selection } = useSelectionContext(SELECTION_NAME);\n\n const singleSelect = useCallback(\n (id: string) => {\n for (const contextId of stableContextIds) {\n selection.updateSingle(contextId, id);\n }\n },\n [selection, stableContextIds],\n );\n\n const multiSelect = useCallback(\n (ids: string[]) => {\n for (const contextId of stableContextIds) {\n selection.updateMulti(contextId, ids);\n }\n },\n [selection, stableContextIds],\n );\n\n const rangeSelect = useCallback(\n (from: string, to: string) => {\n for (const contextId of stableContextIds) {\n selection.updateRange(contextId, from, to);\n }\n },\n [selection, stableContextIds],\n );\n\n const toggle = useCallback(\n (id: string) => {\n for (const contextId of stableContextIds) {\n selection.toggleSelection(contextId, id);\n }\n },\n [selection, stableContextIds],\n );\n\n const clear = useCallback(() => {\n for (const contextId of stableContextIds) {\n selection.clearSelection(contextId);\n }\n }, [selection, stableContextIds]);\n\n return { singleSelect, multiSelect, rangeSelect, toggle, clear };\n};\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,iBAAiB;AAC1B,SAASC,cAAc;AAEvB,SAASC,YAAuB;AAChC,SAASC,kBAAkB;AAGpB,IAAMC,4BAA4B;AAElC,IAAMC,kBAAkBC,OAAOC,QACpCD,OAAOE,OAAO;EACZC,cAAcH,OAAOI;EACrBC,YAAYL,OAAOI;EACnBE,WAAWN,OAAOI;AACpB,CAAA,CAAA;AAMF,IAAMG,YAA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,eAAWvB,aAAakB,kBAAkB;AACxC3B,gBAAUyC,eAAehC,SAAAA;IAC3B;EACF,GAAG;IAACT;IAAW2B;GAAiB;AAEhC,SAAO;IAAEI;IAAcG;IAAaE;IAAaE;IAAQE;EAAM;AACjE;",
|
|
6
|
+
"names": ["untracked", "Schema", "live", "ComplexMap", "ATTENDABLE_PATH_SEPARATOR", "AttentionSchema", "Schema", "mutable", "Struct", "hasAttention", "Boolean", "isAncestor", "isRelated", "stringKey", "key", "join", "AttentionManager", "initial", "_map", "ComplexMap", "_state", "live", "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", "split", "parentElement", "Set", "React", "forwardRef", "useMemo", "Icon", "mx", "attentionGlyphStyles", "presenceIconStyles", "PresenceOne", "svg", "width", "height", "viewBox", "className", "fill", "xmlns", "circle", "cx", "cy", "r", "PresenceMany", "path", "d", "Syncing", "animationProps", "useMemo", "animationDelay", "Date", "now", "div", "role", "Icon", "icon", "size", "style", "classNames", "AttentionGlyph", "forwardRef", "presence", "attended", "syncing", "containsAttended", "props", "forwardedRef", "data-attention", "data-contains-attended", "span", "mx", "ref", "createContext", "Primitive", "Slot", "React", "useMemo", "forwardRef", "useDefaultValue", "mx", "ATTENTION_NAME", "ATTENABLE_ATTRIBUTE", "ATTENTION_SOURCE_ATTRIBUTE", "AttentionContextProvider", "useAttentionContext", "createContext", "attention", "AttentionManager", "path", "UNKNOWN_ATTENDABLE", "hasAttention", "isAncestor", "isRelated", "useAttention", "attendableId", "current", "split", "ATTENDABLE_PATH_SEPARATOR", "get", "useAttended", "useAttentionAttributes", "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", "AttendableContainer", "forwardRef", "classNames", "asChild", "props", "forwardedRef", "attentionAttrs", "Root", "Slot", "Primitive", "mx", "tabIndex", "ref", "untracked", "Match", "invariant", "live", "defaultSelection", "type", "pipe", "when", "mode", "ids", "ranges", "exhaustive", "getSelectionSet", "selectionManager", "contextId", "Set", "context", "getSelectionContexts", "selection", "getSelection", "id", "add", "SelectionManager", "initial", "_state", "selections", "Object", "keys", "length", "undefined", "getSelected", "s", "from", "to", "updateSingle", "updateMulti", "updateRange", "updateMultiRange", "clearSelection", "toggleSelection", "includes", "index", "indexOf", "splice", "push", "createContext", "Match", "React", "useCallback", "useMemo", "useDefaultValue", "SELECTION_NAME", "SelectionContextProvider", "useSelectionContext", "createContext", "selection", "SelectionManager", "SelectionProvider", "children", "propsSelection", "useDefaultValue", "React", "useSelectionManager", "useSelected", "contextId", "mode", "getSelected", "Match", "type", "pipe", "when", "s", "id", "ids", "from", "to", "undefined", "ranges", "exhaustive", "defaultSelection", "useSelectionActions", "contextIds", "stableContextIds", "useMemo", "JSON", "stringify", "singleSelect", "useCallback", "updateSingle", "multiSelect", "updateMulti", "rangeSelect", "updateRange", "toggle", "toggleSelection", "clear", "clearSelection"]
|
|
7
7
|
}
|
|
@@ -14,14 +14,16 @@ import {
|
|
|
14
14
|
Syncing,
|
|
15
15
|
defaultSelection,
|
|
16
16
|
getAttendables,
|
|
17
|
+
getSelectionSet,
|
|
17
18
|
useAttended,
|
|
18
19
|
useAttention,
|
|
19
20
|
useAttentionAttributes,
|
|
20
21
|
useAttentionContext,
|
|
21
22
|
useAttentionPath,
|
|
22
23
|
useSelected,
|
|
23
|
-
useSelectionActions
|
|
24
|
-
|
|
24
|
+
useSelectionActions,
|
|
25
|
+
useSelectionManager
|
|
26
|
+
} from "./chunk-PL2OIVDU.mjs";
|
|
25
27
|
export {
|
|
26
28
|
ATTENABLE_ATTRIBUTE,
|
|
27
29
|
ATTENDABLE_PATH_SEPARATOR,
|
|
@@ -38,12 +40,14 @@ export {
|
|
|
38
40
|
Syncing,
|
|
39
41
|
defaultSelection,
|
|
40
42
|
getAttendables,
|
|
43
|
+
getSelectionSet,
|
|
41
44
|
useAttended,
|
|
42
45
|
useAttention,
|
|
43
46
|
useAttentionAttributes,
|
|
44
47
|
useAttentionContext,
|
|
45
48
|
useAttentionPath,
|
|
46
49
|
useSelected,
|
|
47
|
-
useSelectionActions
|
|
50
|
+
useSelectionActions,
|
|
51
|
+
useSelectionManager
|
|
48
52
|
};
|
|
49
53
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/ui/react-ui-attention/src/attention.ts":{"bytes":16529,"imports":[{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/live-object","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":11213,"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","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":20808,"imports":[{"path":"@preact-signals/safe-react/tracking","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/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","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/selection.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/ui/react-ui-attention/src/attention.ts":{"bytes":16529,"imports":[{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/live-object","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":11213,"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","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":20808,"imports":[{"path":"@preact-signals/safe-react/tracking","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/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","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/selection.ts":{"bytes":17918,"imports":[{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"format":"esm"},"packages/ui/react-ui-attention/src/components/SelectionProvider.tsx":{"bytes":11932,"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"effect","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/selection.ts","kind":"import-statement","original":"../selection"}],"format":"esm"},"packages/ui/react-ui-attention/src/components/index.ts":{"bytes":721,"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"},{"path":"packages/ui/react-ui-attention/src/components/SelectionProvider.tsx","kind":"import-statement","original":"./SelectionProvider"}],"format":"esm"},"packages/ui/react-ui-attention/src/index.ts":{"bytes":658,"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"},{"path":"packages/ui/react-ui-attention/src/selection.ts","kind":"import-statement","original":"./selection"}],"format":"esm"},"packages/ui/react-ui-attention/src/testing/decorators/withAttention.ts":{"bytes":1350,"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":506,"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":484,"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-PL2OIVDU.mjs","kind":"import-statement"}],"exports":["ATTENABLE_ATTRIBUTE","ATTENDABLE_PATH_SEPARATOR","ATTENTION_NAME","ATTENTION_SOURCE_ATTRIBUTE","AttendableContainer","AttentionGlyph","AttentionManager","AttentionProvider","AttentionSchema","RootAttentionProvider","SelectionManager","SelectionProvider","Syncing","defaultSelection","getAttendables","getSelectionSet","useAttended","useAttention","useAttentionAttributes","useAttentionContext","useAttentionPath","useSelected","useSelectionActions","useSelectionManager"],"entryPoint":"packages/ui/react-ui-attention/src/index.ts","inputs":{"packages/ui/react-ui-attention/src/index.ts":{"bytesInOutput":0}},"bytes":1077},"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-PL2OIVDU.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-PL2OIVDU.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":38660},"packages/ui/react-ui-attention/dist/lib/browser/chunk-PL2OIVDU.mjs":{"imports":[{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"@preact-signals/safe-react/tracking","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/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true}],"exports":["ATTENABLE_ATTRIBUTE","ATTENDABLE_PATH_SEPARATOR","ATTENTION_NAME","ATTENTION_SOURCE_ATTRIBUTE","AttendableContainer","AttentionGlyph","AttentionManager","AttentionProvider","AttentionSchema","RootAttentionProvider","SelectionManager","SelectionProvider","Syncing","defaultSelection","getAttendables","getSelectionSet","useAttended","useAttention","useAttentionAttributes","useAttentionContext","useAttentionPath","useSelected","useSelectionActions","useSelectionManager"],"inputs":{"packages/ui/react-ui-attention/src/attention.ts":{"bytesInOutput":3644},"packages/ui/react-ui-attention/src/components/AttentionGlyph.tsx":{"bytesInOutput":3714},"packages/ui/react-ui-attention/src/components/AttentionProvider.tsx":{"bytesInOutput":3705},"packages/ui/react-ui-attention/src/selection.ts":{"bytesInOutput":4871},"packages/ui/react-ui-attention/src/components/SelectionProvider.tsx":{"bytesInOutput":2762},"packages/ui/react-ui-attention/src/components/index.ts":{"bytesInOutput":0}},"bytes":19564}}}
|
|
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var chunk_UHRK5BJW_exports = {};
|
|
30
|
+
__export(chunk_UHRK5BJW_exports, {
|
|
31
31
|
ATTENABLE_ATTRIBUTE: () => ATTENABLE_ATTRIBUTE,
|
|
32
32
|
ATTENDABLE_PATH_SEPARATOR: () => ATTENDABLE_PATH_SEPARATOR,
|
|
33
33
|
ATTENTION_NAME: () => ATTENTION_NAME,
|
|
@@ -43,15 +43,17 @@ __export(chunk_FCPQP37W_exports, {
|
|
|
43
43
|
Syncing: () => Syncing,
|
|
44
44
|
defaultSelection: () => defaultSelection,
|
|
45
45
|
getAttendables: () => getAttendables,
|
|
46
|
+
getSelectionSet: () => getSelectionSet,
|
|
46
47
|
useAttended: () => useAttended,
|
|
47
48
|
useAttention: () => useAttention,
|
|
48
49
|
useAttentionAttributes: () => useAttentionAttributes,
|
|
49
50
|
useAttentionContext: () => useAttentionContext,
|
|
50
51
|
useAttentionPath: () => useAttentionPath,
|
|
51
52
|
useSelected: () => useSelected,
|
|
52
|
-
useSelectionActions: () => useSelectionActions
|
|
53
|
+
useSelectionActions: () => useSelectionActions,
|
|
54
|
+
useSelectionManager: () => useSelectionManager
|
|
53
55
|
});
|
|
54
|
-
module.exports = __toCommonJS(
|
|
56
|
+
module.exports = __toCommonJS(chunk_UHRK5BJW_exports);
|
|
55
57
|
var import_signals_core = require("@preact/signals-core");
|
|
56
58
|
var import_effect = require("effect");
|
|
57
59
|
var import_live_object = require("@dxos/live-object");
|
|
@@ -386,6 +388,20 @@ var defaultSelection = import_effect2.Match.type().pipe(import_effect2.Match.whe
|
|
|
386
388
|
mode: "multi-range",
|
|
387
389
|
ranges: []
|
|
388
390
|
})), import_effect2.Match.exhaustive);
|
|
391
|
+
var getSelectionSet = (selectionManager, contextId) => {
|
|
392
|
+
const ids = new Set(contextId ? [
|
|
393
|
+
contextId
|
|
394
|
+
] : []);
|
|
395
|
+
for (const context of selectionManager.getSelectionContexts()) {
|
|
396
|
+
const selection = selectionManager.getSelection(context);
|
|
397
|
+
if (selection?.mode === "multi") {
|
|
398
|
+
for (const id of selection.ids) {
|
|
399
|
+
ids.add(id);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return ids;
|
|
404
|
+
};
|
|
389
405
|
var SelectionManager = class {
|
|
390
406
|
constructor(initial = {}) {
|
|
391
407
|
this._state = (0, import_live_object2.live)({
|
|
@@ -397,6 +413,9 @@ var SelectionManager = class {
|
|
|
397
413
|
});
|
|
398
414
|
}
|
|
399
415
|
}
|
|
416
|
+
getSelectionContexts() {
|
|
417
|
+
return Object.keys(this._state.selections);
|
|
418
|
+
}
|
|
400
419
|
getSelection(contextId, mode = void 0) {
|
|
401
420
|
const selection = (0, import_signals_core2.untracked)(() => this._state.selections[contextId]);
|
|
402
421
|
if (!mode || selection) {
|
|
@@ -407,11 +426,12 @@ var SelectionManager = class {
|
|
|
407
426
|
return this._state.selections[contextId];
|
|
408
427
|
});
|
|
409
428
|
}
|
|
429
|
+
// TODO(burdon): Disambiguate with getSelection?
|
|
410
430
|
getSelected(contextId, mode = "multi") {
|
|
411
431
|
const selection = this.getSelection(contextId, mode);
|
|
412
432
|
(0, import_invariant.invariant)(selection?.mode === mode, "Selection mode mismatch", {
|
|
413
433
|
F: __dxlog_file,
|
|
414
|
-
L:
|
|
434
|
+
L: 91,
|
|
415
435
|
S: this,
|
|
416
436
|
A: [
|
|
417
437
|
"selection?.mode === mode",
|
|
@@ -436,7 +456,7 @@ var SelectionManager = class {
|
|
|
436
456
|
const selection = this.getSelection(contextId, "single");
|
|
437
457
|
(0, import_invariant.invariant)(selection?.mode === "single", "Selection mode is not single", {
|
|
438
458
|
F: __dxlog_file,
|
|
439
|
-
L:
|
|
459
|
+
L: 104,
|
|
440
460
|
S: this,
|
|
441
461
|
A: [
|
|
442
462
|
"selection?.mode === 'single'",
|
|
@@ -451,7 +471,7 @@ var SelectionManager = class {
|
|
|
451
471
|
const selection = this.getSelection(contextId, "multi");
|
|
452
472
|
(0, import_invariant.invariant)(selection?.mode === "multi", "Selection mode is not multi", {
|
|
453
473
|
F: __dxlog_file,
|
|
454
|
-
L:
|
|
474
|
+
L: 112,
|
|
455
475
|
S: this,
|
|
456
476
|
A: [
|
|
457
477
|
"selection?.mode === 'multi'",
|
|
@@ -466,7 +486,7 @@ var SelectionManager = class {
|
|
|
466
486
|
const selection = this.getSelection(contextId, "range");
|
|
467
487
|
(0, import_invariant.invariant)(selection?.mode === "range", "Selection mode is not range", {
|
|
468
488
|
F: __dxlog_file,
|
|
469
|
-
L:
|
|
489
|
+
L: 120,
|
|
470
490
|
S: this,
|
|
471
491
|
A: [
|
|
472
492
|
"selection?.mode === 'range'",
|
|
@@ -482,7 +502,7 @@ var SelectionManager = class {
|
|
|
482
502
|
const selection = this.getSelection(contextId, "multi-range");
|
|
483
503
|
(0, import_invariant.invariant)(selection?.mode === "multi-range", "Selection mode is not multi-range", {
|
|
484
504
|
F: __dxlog_file,
|
|
485
|
-
L:
|
|
505
|
+
L: 129,
|
|
486
506
|
S: this,
|
|
487
507
|
A: [
|
|
488
508
|
"selection?.mode === 'multi-range'",
|
|
@@ -505,7 +525,7 @@ var SelectionManager = class {
|
|
|
505
525
|
const selection = this.getSelection(contextId, "multi");
|
|
506
526
|
(0, import_invariant.invariant)(selection?.mode === "multi", "Selection mode is not multi", {
|
|
507
527
|
F: __dxlog_file,
|
|
508
|
-
L:
|
|
528
|
+
L: 146,
|
|
509
529
|
S: this,
|
|
510
530
|
A: [
|
|
511
531
|
"selection?.mode === 'multi'",
|
|
@@ -536,6 +556,10 @@ var SelectionProvider = ({ children, selection: propsSelection }) => {
|
|
|
536
556
|
_effect.f();
|
|
537
557
|
}
|
|
538
558
|
};
|
|
559
|
+
var useSelectionManager = () => {
|
|
560
|
+
const { selection } = useSelectionContext(SELECTION_NAME);
|
|
561
|
+
return selection;
|
|
562
|
+
};
|
|
539
563
|
var useSelected = (contextId, mode = "multi") => {
|
|
540
564
|
const { selection } = useSelectionContext(SELECTION_NAME);
|
|
541
565
|
if (contextId) {
|
|
@@ -624,12 +648,14 @@ var useSelectionActions = (contextIds, mode = "multi") => {
|
|
|
624
648
|
Syncing,
|
|
625
649
|
defaultSelection,
|
|
626
650
|
getAttendables,
|
|
651
|
+
getSelectionSet,
|
|
627
652
|
useAttended,
|
|
628
653
|
useAttention,
|
|
629
654
|
useAttentionAttributes,
|
|
630
655
|
useAttentionContext,
|
|
631
656
|
useAttentionPath,
|
|
632
657
|
useSelected,
|
|
633
|
-
useSelectionActions
|
|
658
|
+
useSelectionActions,
|
|
659
|
+
useSelectionManager
|
|
634
660
|
});
|
|
635
|
-
//# sourceMappingURL=chunk-
|
|
661
|
+
//# sourceMappingURL=chunk-UHRK5BJW.cjs.map
|