@dxos/react-ui-attention 0.6.12-main.5cc132e → 0.6.12-main.c974201
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/index.mjs +11 -2
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/AttentionProvider.d.ts +2 -1
- package/dist/types/src/components/AttentionProvider.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/components/AttentionProvider.tsx +13 -3
|
@@ -48,7 +48,7 @@ var AttentionGlyph = /* @__PURE__ */ forwardRef(({ presence, classNames, ...prop
|
|
|
48
48
|
// packages/ui/react-ui-attention/src/components/AttentionProvider.tsx
|
|
49
49
|
import { createContext } from "@radix-ui/react-context";
|
|
50
50
|
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
51
|
-
import React2 from "react";
|
|
51
|
+
import React2, { useMemo } from "react";
|
|
52
52
|
var ATTENTION_NAME = "Attention";
|
|
53
53
|
var [AttentionContextProvider, useAttentionContext] = createContext(ATTENTION_NAME, {
|
|
54
54
|
attended: /* @__PURE__ */ new Set()
|
|
@@ -62,6 +62,12 @@ var useIsDirectlyAttended = (attendableId) => {
|
|
|
62
62
|
const attendedArray = Array.from(attended);
|
|
63
63
|
return attendedArray.length === 1 && attendedArray[0] === attendableId;
|
|
64
64
|
};
|
|
65
|
+
var useAttendedIds = () => {
|
|
66
|
+
const { attended } = useAttentionContext(ATTENTION_NAME);
|
|
67
|
+
return useMemo(() => Array.from(attended), [
|
|
68
|
+
attended
|
|
69
|
+
]);
|
|
70
|
+
};
|
|
65
71
|
var createAttendableAttributes = (attendableId) => {
|
|
66
72
|
return {
|
|
67
73
|
"data-attendable-id": attendableId
|
|
@@ -102,7 +108,9 @@ var AttentionProvider = ({ children, attended: propsAttended, defaultAttended, o
|
|
|
102
108
|
Array.from(attended),
|
|
103
109
|
Array.from(nextAttended)
|
|
104
110
|
];
|
|
105
|
-
(prev.length !== next.length || !!prev.find((id, index) => next[index] !== id))
|
|
111
|
+
if (next.length > 0 && (prev.length !== next.length || !!prev.find((id, index) => next[index] !== id))) {
|
|
112
|
+
setAttended(nextAttended);
|
|
113
|
+
}
|
|
106
114
|
};
|
|
107
115
|
return /* @__PURE__ */ React2.createElement(AttentionContextProvider, {
|
|
108
116
|
attended
|
|
@@ -117,6 +125,7 @@ export {
|
|
|
117
125
|
AttentionGlyph,
|
|
118
126
|
AttentionProvider,
|
|
119
127
|
createAttendableAttributes,
|
|
128
|
+
useAttendedIds,
|
|
120
129
|
useAttentionContext,
|
|
121
130
|
useHasAttention,
|
|
122
131
|
useIsDirectlyAttended
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/AttentionGlyph.tsx", "../../../src/components/AttentionProvider.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Primitive } from '@radix-ui/react-primitive';\nimport React, { type ComponentPropsWithRef, forwardRef } from 'react';\n\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\nconst attentionGlyphStyles =\n 'inline-block rounded-sm is-3 bs-3 bg-transparent text-accentText transition-colors [[data-attention=true]_&]:bg-accentSurface [[data-attention=true]_&]:text-inverse [[aria-current][data-attention=true]_&]:bg-accentSurface [[aria-current][data-attention=true]_&]:text-inverse';\n\nconst presenceIconStyles =\n 'is-3 bs-3 group-[[aria-current]_&:hover]/attentionGlyphButton:hidden group-[[aria-current]_&:focus]/attentionGlyphButton:hidden group-[[data-attention=true]_&:hover]/attentionGlyphButton:hidden group-[[data-attention=true]_&:focus]/attentionGlyphButton:hidden group-[[aria-current][data-attention=true]_&:hover]/attentionGlyphButton:hidden group-[[aria-current][data-attention=true]_&:focus]/attentionGlyphButton:hidden';\n\nconst PresenceOne = () => {\n return (\n <svg\n width='12'\n height='12'\n viewBox='0 0 12 12'\n className={presenceIconStyles}\n fill='none'\n xmlns='http://www.w3.org/2000/svg'\n >\n <circle cx='6' cy='6' r='2.5' fill='currentColor' />\n </svg>\n );\n};\n\nconst PresenceMany = () => {\n return (\n <svg\n width='12'\n height='12'\n viewBox='0 0 12 12'\n className={presenceIconStyles}\n fill='none'\n xmlns='http://www.w3.org/2000/svg'\n >\n <path\n d='M6.75 8.27311C7.38815 7.72296 7.79212 6.90866 7.79212 6C7.79212 5.09134 7.38815 4.27704 6.75 3.72689C7.06722 3.58122 7.42019 3.5 7.79212 3.5C9.17283 3.5 10.2921 4.61929 10.2921 6C10.2921 7.38071 9.17283 8.5 7.79212 8.5C7.42019 8.5 7.06723 8.41878 6.75 8.27311Z'\n fill='currentColor'\n />\n <circle cx='4.25' cy='6' r='2.5' fill='currentColor' />\n </svg>\n );\n};\n\nexport type AttentionGlyphProps = {\n presence?: 'none' | 'one' | 'many';\n} & ThemedClassName<Omit<ComponentPropsWithRef<typeof Primitive.span>, 'children'>>;\n\nexport const AttentionGlyph = forwardRef<HTMLSpanElement, AttentionGlyphProps>(\n ({ presence, classNames, ...props }, forwardedRef) => {\n return (\n <span role='none' {...props} className={mx(attentionGlyphStyles, classNames)} ref={forwardedRef}>\n {presence === 'many' && <PresenceMany />}\n {presence === 'one' && <PresenceOne />}\n </span>\n );\n },\n);\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// NOTE(thure): The following unused imports quell TS2742 (“likely not portable”).\n\n// eslint-disable-next-line unused-imports/no-unused-imports\nimport { createContext, type Scope, type CreateScope } from '@radix-ui/react-context';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\n// eslint-disable-next-line unused-imports/no-unused-imports\nimport React, {
|
|
5
|
-
"mappings": ";AAKA,OAAOA,SAAqCC,kBAAkB;AAG9D,SAASC,UAAU;AAEnB,IAAMC,uBACJ;AAEF,IAAMC,qBACJ;AAEF,IAAMC,cAAc,MAAA;AAClB,SACE,sBAAA,cAACC,OAAAA;IACCC,OAAM;IACNC,QAAO;IACPC,SAAQ;IACRC,WAAWN;IACXO,MAAK;IACLC,OAAM;KAEN,sBAAA,cAACC,UAAAA;IAAOC,IAAG;IAAIC,IAAG;IAAIC,GAAE;IAAML,MAAK;;AAGzC;AAEA,IAAMM,eAAe,MAAA;AACnB,SACE,sBAAA,cAACX,OAAAA;IACCC,OAAM;IACNC,QAAO;IACPC,SAAQ;IACRC,WAAWN;IACXO,MAAK;IACLC,OAAM;KAEN,sBAAA,cAACM,QAAAA;IACCC,GAAE;IACFR,MAAK;MAEP,sBAAA,cAACE,UAAAA;IAAOC,IAAG;IAAOC,IAAG;IAAIC,GAAE;IAAML,MAAK;;AAG5C;AAMO,IAAMS,iBAAiBC,2BAC5B,CAAC,EAAEC,UAAUC,YAAY,GAAGC,MAAAA,GAASC,iBAAAA;AACnC,SACE,sBAAA,cAACC,QAAAA;IAAKC,MAAK;IAAQ,GAAGH;IAAOd,WAAWkB,GAAGzB,sBAAsBoB,UAAAA;IAAaM,KAAKJ;KAChFH,aAAa,UAAU,sBAAA,cAACL,cAAAA,IAAAA,GACxBK,aAAa,SAAS,sBAAA,cAACjB,aAAAA,IAAAA,CAAAA;AAG9B,CAAA;;;ACvDF,SAASyB,qBAAmD;AAC5D,SAASC,4BAA4B;AAErC,OAAOC,
|
|
6
|
-
"names": ["React", "forwardRef", "mx", "attentionGlyphStyles", "presenceIconStyles", "PresenceOne", "svg", "width", "height", "viewBox", "className", "fill", "xmlns", "circle", "cx", "cy", "r", "PresenceMany", "path", "d", "AttentionGlyph", "forwardRef", "presence", "classNames", "props", "forwardedRef", "span", "role", "mx", "ref", "createContext", "useControllableState", "React", "ATTENTION_NAME", "AttentionContextProvider", "useAttentionContext", "createContext", "attended", "Set", "useHasAttention", "attendableId", "has", "useIsDirectlyAttended", "attendedArray", "Array", "from", "length", "createAttendableAttributes", "getAttendables", "selector", "cursor", "acc", "closestAttendable", "closest", "getAttribute", "trigger", "document", "querySelector", "push", "parentElement", "AttentionProvider", "children", "propsAttended", "defaultAttended", "onChangeAttend", "setAttended", "useControllableState", "prop", "defaultProp", "onChange", "handleFocus", "event", "querySelectorAll", "map", "el", "join", "nextAttended", "target", "prev", "next", "find", "id", "index", "React", "div", "role", "className", "onFocusCapture"]
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Primitive } from '@radix-ui/react-primitive';\nimport React, { type ComponentPropsWithRef, forwardRef } from 'react';\n\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\nconst attentionGlyphStyles =\n 'inline-block rounded-sm is-3 bs-3 bg-transparent text-accentText transition-colors [[data-attention=true]_&]:bg-accentSurface [[data-attention=true]_&]:text-inverse [[aria-current][data-attention=true]_&]:bg-accentSurface [[aria-current][data-attention=true]_&]:text-inverse';\n\nconst presenceIconStyles =\n 'is-3 bs-3 group-[[aria-current]_&:hover]/attentionGlyphButton:hidden group-[[aria-current]_&:focus]/attentionGlyphButton:hidden group-[[data-attention=true]_&:hover]/attentionGlyphButton:hidden group-[[data-attention=true]_&:focus]/attentionGlyphButton:hidden group-[[aria-current][data-attention=true]_&:hover]/attentionGlyphButton:hidden group-[[aria-current][data-attention=true]_&:focus]/attentionGlyphButton:hidden';\n\nconst PresenceOne = () => {\n return (\n <svg\n width='12'\n height='12'\n viewBox='0 0 12 12'\n className={presenceIconStyles}\n fill='none'\n xmlns='http://www.w3.org/2000/svg'\n >\n <circle cx='6' cy='6' r='2.5' fill='currentColor' />\n </svg>\n );\n};\n\nconst PresenceMany = () => {\n return (\n <svg\n width='12'\n height='12'\n viewBox='0 0 12 12'\n className={presenceIconStyles}\n fill='none'\n xmlns='http://www.w3.org/2000/svg'\n >\n <path\n d='M6.75 8.27311C7.38815 7.72296 7.79212 6.90866 7.79212 6C7.79212 5.09134 7.38815 4.27704 6.75 3.72689C7.06722 3.58122 7.42019 3.5 7.79212 3.5C9.17283 3.5 10.2921 4.61929 10.2921 6C10.2921 7.38071 9.17283 8.5 7.79212 8.5C7.42019 8.5 7.06723 8.41878 6.75 8.27311Z'\n fill='currentColor'\n />\n <circle cx='4.25' cy='6' r='2.5' fill='currentColor' />\n </svg>\n );\n};\n\nexport type AttentionGlyphProps = {\n presence?: 'none' | 'one' | 'many';\n} & ThemedClassName<Omit<ComponentPropsWithRef<typeof Primitive.span>, 'children'>>;\n\nexport const AttentionGlyph = forwardRef<HTMLSpanElement, AttentionGlyphProps>(\n ({ presence, classNames, ...props }, forwardedRef) => {\n return (\n <span role='none' {...props} className={mx(attentionGlyphStyles, classNames)} ref={forwardedRef}>\n {presence === 'many' && <PresenceMany />}\n {presence === 'one' && <PresenceOne />}\n </span>\n );\n },\n);\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// NOTE(thure): The following unused imports quell TS2742 (“likely not portable”).\n\n// eslint-disable-next-line unused-imports/no-unused-imports\nimport { createContext, type Scope, type CreateScope } from '@radix-ui/react-context';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\n// eslint-disable-next-line unused-imports/no-unused-imports\nimport React, { type FocusEvent, type PropsWithChildren, useMemo } from 'react';\n\nconst ATTENTION_NAME = 'Attention';\n\ntype AttentionContextValue = {\n attended: Set<string>;\n};\n\nconst [AttentionContextProvider, useAttentionContext] = createContext<AttentionContextValue>(ATTENTION_NAME, {\n attended: new Set(),\n});\n\nconst useHasAttention = (attendableId?: string) => {\n const { attended } = useAttentionContext(ATTENTION_NAME);\n return attendableId ? attended.has(attendableId) : false;\n};\n\nconst useIsDirectlyAttended = (attendableId?: string) => {\n const { attended } = useAttentionContext(ATTENTION_NAME);\n const attendedArray = Array.from(attended);\n return attendedArray.length === 1 && attendedArray[0] === attendableId;\n};\n\nconst useAttendedIds = () => {\n const { attended } = useAttentionContext(ATTENTION_NAME);\n return useMemo(() => Array.from(attended), [attended]);\n};\n\n/**\n * Computes HTML element attributes to apply so the attention system can detect changes\n * @param attendableId\n */\nconst createAttendableAttributes = (attendableId?: string) => {\n return { 'data-attendable-id': attendableId };\n};\n\n/**\n * Accumulates all attendable id’s between the element provided and the root, inclusive.\n */\nconst getAttendables = (selector: string, cursor: Element, acc: string[] = []): string[] => {\n // Find the closest element with `data-attendable-id`, if any; start from cursor and move up the DOM tree.\n const closestAttendable = cursor.closest(selector);\n if (!closestAttendable) {\n return acc;\n } else {\n const attendableId = closestAttendable.getAttribute('data-attendable-id');\n if (!attendableId) {\n // this has an id of an aria-controls elsewhere on the page, move cursor to that trigger\n const trigger = document.querySelector(`[aria-controls=\"${closestAttendable.getAttribute('id')}\"]`);\n if (!trigger) {\n return acc;\n } else {\n return getAttendables(selector, trigger, acc);\n }\n } else {\n acc.push(attendableId);\n // (attempt tail recursion)\n return !closestAttendable.parentElement ? acc : getAttendables(selector, closestAttendable.parentElement, acc);\n }\n }\n};\n\nconst AttentionProvider = ({\n children,\n attended: propsAttended,\n defaultAttended,\n onChangeAttend,\n}: PropsWithChildren<\n Partial<{\n attended: Set<string>;\n onChangeAttend: (nextAttended: Set<string>) => void;\n defaultAttended: Set<string>;\n }>\n>) => {\n const [attended = new Set(), setAttended] = useControllableState<Set<string>>({\n prop: propsAttended,\n defaultProp: defaultAttended,\n onChange: onChangeAttend,\n });\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 nextAttended = new Set(getAttendables(selector, event.target));\n const [prev, next] = [Array.from(attended), Array.from(nextAttended)];\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 setAttended(nextAttended);\n }\n };\n return (\n <AttentionContextProvider attended={attended}>\n <div role='none' className='contents' onFocusCapture={handleFocus}>\n {children}\n </div>\n </AttentionContextProvider>\n );\n};\n\nexport {\n AttentionProvider,\n useAttentionContext,\n useHasAttention,\n useIsDirectlyAttended,\n useAttendedIds,\n createAttendableAttributes,\n ATTENTION_NAME,\n};\n\nexport type { AttentionContextValue };\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["React", "forwardRef", "mx", "attentionGlyphStyles", "presenceIconStyles", "PresenceOne", "svg", "width", "height", "viewBox", "className", "fill", "xmlns", "circle", "cx", "cy", "r", "PresenceMany", "path", "d", "AttentionGlyph", "forwardRef", "presence", "classNames", "props", "forwardedRef", "span", "role", "mx", "ref", "createContext", "useControllableState", "React", "useMemo", "ATTENTION_NAME", "AttentionContextProvider", "useAttentionContext", "createContext", "attended", "Set", "useHasAttention", "attendableId", "has", "useIsDirectlyAttended", "attendedArray", "Array", "from", "length", "useAttendedIds", "useMemo", "createAttendableAttributes", "getAttendables", "selector", "cursor", "acc", "closestAttendable", "closest", "getAttribute", "trigger", "document", "querySelector", "push", "parentElement", "AttentionProvider", "children", "propsAttended", "defaultAttended", "onChangeAttend", "setAttended", "useControllableState", "prop", "defaultProp", "onChange", "handleFocus", "event", "querySelectorAll", "map", "el", "join", "nextAttended", "target", "prev", "next", "find", "id", "index", "React", "div", "role", "className", "onFocusCapture"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/ui/react-ui-attention/src/components/AttentionGlyph.tsx":{"bytes":7599,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"format":"esm"},"packages/ui/react-ui-attention/src/components/AttentionProvider.tsx":{"bytes":
|
|
1
|
+
{"inputs":{"packages/ui/react-ui-attention/src/components/AttentionGlyph.tsx":{"bytes":7599,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"format":"esm"},"packages/ui/react-ui-attention/src/components/AttentionProvider.tsx":{"bytes":14373,"imports":[{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"packages/ui/react-ui-attention/src/components/index.ts":{"bytes":644,"imports":[{"path":"packages/ui/react-ui-attention/src/components/AttentionGlyph.tsx","kind":"import-statement","original":"./AttentionGlyph"},{"path":"packages/ui/react-ui-attention/src/components/AttentionProvider.tsx","kind":"import-statement","original":"./AttentionProvider"}],"format":"esm"},"packages/ui/react-ui-attention/src/index.ts":{"bytes":508,"imports":[{"path":"packages/ui/react-ui-attention/src/components/index.ts","kind":"import-statement","original":"./components"}],"format":"esm"}},"outputs":{"packages/ui/react-ui-attention/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":11029},"packages/ui/react-ui-attention/dist/lib/browser/index.mjs":{"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"exports":["ATTENTION_NAME","AttentionGlyph","AttentionProvider","createAttendableAttributes","useAttendedIds","useAttentionContext","useHasAttention","useIsDirectlyAttended"],"entryPoint":"packages/ui/react-ui-attention/src/index.ts","inputs":{"packages/ui/react-ui-attention/src/components/AttentionGlyph.tsx":{"bytesInOutput":2349},"packages/ui/react-ui-attention/src/components/index.ts":{"bytesInOutput":0},"packages/ui/react-ui-attention/src/components/AttentionProvider.tsx":{"bytesInOutput":2739},"packages/ui/react-ui-attention/src/index.ts":{"bytesInOutput":0}},"bytes":5446}}}
|
|
@@ -6,6 +6,7 @@ type AttentionContextValue = {
|
|
|
6
6
|
declare const useAttentionContext: (consumerName: string) => AttentionContextValue;
|
|
7
7
|
declare const useHasAttention: (attendableId?: string) => boolean;
|
|
8
8
|
declare const useIsDirectlyAttended: (attendableId?: string) => boolean;
|
|
9
|
+
declare const useAttendedIds: () => string[];
|
|
9
10
|
/**
|
|
10
11
|
* Computes HTML element attributes to apply so the attention system can detect changes
|
|
11
12
|
* @param attendableId
|
|
@@ -18,6 +19,6 @@ declare const AttentionProvider: ({ children, attended: propsAttended, defaultAt
|
|
|
18
19
|
onChangeAttend: (nextAttended: Set<string>) => void;
|
|
19
20
|
defaultAttended: Set<string>;
|
|
20
21
|
}>>) => React.JSX.Element;
|
|
21
|
-
export { AttentionProvider, useAttentionContext, useHasAttention, useIsDirectlyAttended, createAttendableAttributes, ATTENTION_NAME, };
|
|
22
|
+
export { AttentionProvider, useAttentionContext, useHasAttention, useIsDirectlyAttended, useAttendedIds, createAttendableAttributes, ATTENTION_NAME, };
|
|
22
23
|
export type { AttentionContextValue };
|
|
23
24
|
//# sourceMappingURL=AttentionProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttentionProvider.d.ts","sourceRoot":"","sources":["../../../../src/components/AttentionProvider.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"AttentionProvider.d.ts","sourceRoot":"","sources":["../../../../src/components/AttentionProvider.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,EAAmB,KAAK,iBAAiB,EAAW,MAAM,OAAO,CAAC;AAEhF,QAAA,MAAM,cAAc,cAAc,CAAC;AAEnC,KAAK,qBAAqB,GAAG;IAC3B,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACvB,CAAC;AAEF,QAAA,MAAiC,mBAAmB,iDAElD,CAAC;AAEH,QAAA,MAAM,eAAe,kBAAmB,MAAM,YAG7C,CAAC;AAEF,QAAA,MAAM,qBAAqB,kBAAmB,MAAM,YAInD,CAAC;AAEF,QAAA,MAAM,cAAc,gBAGnB,CAAC;AAEF;;;GAGG;AACH,QAAA,MAAM,0BAA0B,kBAAmB,MAAM;;CAExD,CAAC;AA4BF,QAAA,MAAM,iBAAiB,4EAKpB,iBAAiB,CAClB,OAAO,CAAC;IACN,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACtB,cAAc,EAAE,CAAC,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IACpD,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC9B,CAAC,CACH,sBA6BA,CAAC;AAEF,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,0BAA0B,EAC1B,cAAc,GACf,CAAC;AAEF,YAAY,EAAE,qBAAqB,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-attention",
|
|
3
|
-
"version": "0.6.12-main.
|
|
3
|
+
"version": "0.6.12-main.c974201",
|
|
4
4
|
"description": "Signifier components and providers for attention system.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"@radix-ui/react-primitive": "^1.0.2",
|
|
29
29
|
"@radix-ui/react-slot": "^1.0.1",
|
|
30
30
|
"@radix-ui/react-use-controllable-state": "^1.0.0",
|
|
31
|
-
"@dxos/react-ui": "0.6.12-main.
|
|
32
|
-
"@dxos/util": "0.6.12-main.
|
|
33
|
-
"@dxos/react-ui-theme": "0.6.12-main.
|
|
31
|
+
"@dxos/react-ui": "0.6.12-main.c974201",
|
|
32
|
+
"@dxos/util": "0.6.12-main.c974201",
|
|
33
|
+
"@dxos/react-ui-theme": "0.6.12-main.c974201"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@phosphor-icons/react": "^2.1.5",
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
"react": "~18.2.0",
|
|
40
40
|
"react-dom": "~18.2.0",
|
|
41
41
|
"vite": "5.4.7",
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/storybook-utils": "0.6.12-main.
|
|
44
|
-
"@dxos/
|
|
42
|
+
"@dxos/random": "0.6.12-main.c974201",
|
|
43
|
+
"@dxos/storybook-utils": "0.6.12-main.c974201",
|
|
44
|
+
"@dxos/app-graph": "0.6.12-main.c974201"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@phosphor-icons/react": "^2.1.5",
|
|
48
|
-
"react": "
|
|
49
|
-
"react-dom": "
|
|
48
|
+
"react": "~18.2.0",
|
|
49
|
+
"react-dom": "~18.2.0"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { createContext, type Scope, type CreateScope } from '@radix-ui/react-context';
|
|
9
9
|
import { useControllableState } from '@radix-ui/react-use-controllable-state';
|
|
10
10
|
// eslint-disable-next-line unused-imports/no-unused-imports
|
|
11
|
-
import React, {
|
|
11
|
+
import React, { type FocusEvent, type PropsWithChildren, useMemo } from 'react';
|
|
12
12
|
|
|
13
13
|
const ATTENTION_NAME = 'Attention';
|
|
14
14
|
|
|
@@ -31,6 +31,11 @@ const useIsDirectlyAttended = (attendableId?: string) => {
|
|
|
31
31
|
return attendedArray.length === 1 && attendedArray[0] === attendableId;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
const useAttendedIds = () => {
|
|
35
|
+
const { attended } = useAttentionContext(ATTENTION_NAME);
|
|
36
|
+
return useMemo(() => Array.from(attended), [attended]);
|
|
37
|
+
};
|
|
38
|
+
|
|
34
39
|
/**
|
|
35
40
|
* Computes HTML element attributes to apply so the attention system can detect changes
|
|
36
41
|
* @param attendableId
|
|
@@ -91,8 +96,12 @@ const AttentionProvider = ({
|
|
|
91
96
|
].join(',');
|
|
92
97
|
const nextAttended = new Set(getAttendables(selector, event.target));
|
|
93
98
|
const [prev, next] = [Array.from(attended), Array.from(nextAttended)];
|
|
94
|
-
//
|
|
95
|
-
|
|
99
|
+
// TODO(wittjosiah): Not allowing empty state means that the attended item is not strictly guaranteed to be in the DOM.
|
|
100
|
+
// Currently this depends on the deck in order to ensure that when the attended item is removed something else is attended.
|
|
101
|
+
// Only update state if the result is different and not empty.
|
|
102
|
+
if (next.length > 0 && (prev.length !== next.length || !!prev.find((id, index) => next[index] !== id))) {
|
|
103
|
+
setAttended(nextAttended);
|
|
104
|
+
}
|
|
96
105
|
};
|
|
97
106
|
return (
|
|
98
107
|
<AttentionContextProvider attended={attended}>
|
|
@@ -108,6 +117,7 @@ export {
|
|
|
108
117
|
useAttentionContext,
|
|
109
118
|
useHasAttention,
|
|
110
119
|
useIsDirectlyAttended,
|
|
120
|
+
useAttendedIds,
|
|
111
121
|
createAttendableAttributes,
|
|
112
122
|
ATTENTION_NAME,
|
|
113
123
|
};
|