@cognite/aura 1.47805.0 → 1.47818.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -47,11 +47,18 @@ function isSelectionHidden(selectedCount) {
|
|
|
47
47
|
}
|
|
48
48
|
function playToolbarMotion(node, keyframes, duration) {
|
|
49
49
|
if (typeof node.animate !== 'function') return null;
|
|
50
|
-
|
|
50
|
+
const animation = node.animate(keyframes, {
|
|
51
51
|
duration,
|
|
52
52
|
easing: 'linear',
|
|
53
53
|
fill: 'forwards'
|
|
54
54
|
});
|
|
55
|
+
// Cancelling (e.g. on rapid selection toggles or unmount) rejects `finished`
|
|
56
|
+
// with an AbortError; that's expected here, so swallow only that.
|
|
57
|
+
animation.finished.catch((error)=>{
|
|
58
|
+
if (error instanceof DOMException && error.name === 'AbortError') return;
|
|
59
|
+
throw error;
|
|
60
|
+
});
|
|
61
|
+
return animation;
|
|
55
62
|
}
|
|
56
63
|
function startToolbarMotion(node, hidden, motionRef, exitTimerRef, onExit) {
|
|
57
64
|
motionRef.current?.cancel();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/components/ui/core/action-toolbar/action-toolbar-motion.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nconst TOOLBAR_ENTER_MS = 420;\nconst TOOLBAR_EXIT_MS = 560;\nconst TOOLBAR_EXIT_UNMOUNT_FALLBACK_MS = 640;\nconst TOOLBAR_DRIFT_OFFSET = '0.75rem';\nconst TOOLBAR_TRAVEL_OFFSET = '3.5rem';\nconst TOOLBAR_EXIT_FADE_START = 0.4;\nconst TOOLBAR_ENTER_SETTLE_START = 0.6;\n\nconst TOOLBAR_ENTER_KEYFRAMES: Keyframe[] = [\n { transform: `translateY(${TOOLBAR_TRAVEL_OFFSET})`, opacity: 0 },\n {\n transform: `translateY(${TOOLBAR_DRIFT_OFFSET})`,\n opacity: 1,\n offset: TOOLBAR_ENTER_SETTLE_START,\n },\n { transform: 'translateY(0)', opacity: 1 },\n];\n\nconst TOOLBAR_EXIT_KEYFRAMES: Keyframe[] = [\n { transform: 'translateY(0)', opacity: 1 },\n // Drift down while the toolbar is still fully visible.\n // Fade only after that, while the rest of the travel finishes.\n {\n transform: `translateY(${TOOLBAR_DRIFT_OFFSET})`,\n opacity: 1,\n offset: TOOLBAR_EXIT_FADE_START,\n },\n { transform: `translateY(${TOOLBAR_TRAVEL_OFFSET})`, opacity: 0 },\n];\n\ntype ActionToolbarPresence = {\n mounted: boolean;\n selectedCount: number | undefined;\n bindMotion: (node: HTMLDivElement | null) => void;\n};\n\nfunction prefersReducedMotion(): boolean {\n if (typeof window === 'undefined') return false;\n return window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n\nfunction isSelectionHidden(selectedCount: number | undefined): boolean {\n return typeof selectedCount === 'number' && selectedCount === 0;\n}\n\nfunction playToolbarMotion(\n node: HTMLDivElement,\n keyframes: Keyframe[],\n duration: number\n): Animation | null {\n if (typeof node.animate !== 'function') return null;\n
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/core/action-toolbar/action-toolbar-motion.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nconst TOOLBAR_ENTER_MS = 420;\nconst TOOLBAR_EXIT_MS = 560;\nconst TOOLBAR_EXIT_UNMOUNT_FALLBACK_MS = 640;\nconst TOOLBAR_DRIFT_OFFSET = '0.75rem';\nconst TOOLBAR_TRAVEL_OFFSET = '3.5rem';\nconst TOOLBAR_EXIT_FADE_START = 0.4;\nconst TOOLBAR_ENTER_SETTLE_START = 0.6;\n\nconst TOOLBAR_ENTER_KEYFRAMES: Keyframe[] = [\n { transform: `translateY(${TOOLBAR_TRAVEL_OFFSET})`, opacity: 0 },\n {\n transform: `translateY(${TOOLBAR_DRIFT_OFFSET})`,\n opacity: 1,\n offset: TOOLBAR_ENTER_SETTLE_START,\n },\n { transform: 'translateY(0)', opacity: 1 },\n];\n\nconst TOOLBAR_EXIT_KEYFRAMES: Keyframe[] = [\n { transform: 'translateY(0)', opacity: 1 },\n // Drift down while the toolbar is still fully visible.\n // Fade only after that, while the rest of the travel finishes.\n {\n transform: `translateY(${TOOLBAR_DRIFT_OFFSET})`,\n opacity: 1,\n offset: TOOLBAR_EXIT_FADE_START,\n },\n { transform: `translateY(${TOOLBAR_TRAVEL_OFFSET})`, opacity: 0 },\n];\n\ntype ActionToolbarPresence = {\n mounted: boolean;\n selectedCount: number | undefined;\n bindMotion: (node: HTMLDivElement | null) => void;\n};\n\nfunction prefersReducedMotion(): boolean {\n if (typeof window === 'undefined') return false;\n return window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n\nfunction isSelectionHidden(selectedCount: number | undefined): boolean {\n return typeof selectedCount === 'number' && selectedCount === 0;\n}\n\nfunction playToolbarMotion(\n node: HTMLDivElement,\n keyframes: Keyframe[],\n duration: number\n): Animation | null {\n if (typeof node.animate !== 'function') return null;\n const animation = node.animate(keyframes, {\n duration,\n easing: 'linear',\n fill: 'forwards',\n });\n // Cancelling (e.g. on rapid selection toggles or unmount) rejects `finished`\n // with an AbortError; that's expected here, so swallow only that.\n animation.finished.catch((error: unknown) => {\n if (error instanceof DOMException && error.name === 'AbortError') return;\n throw error;\n });\n return animation;\n}\n\nfunction startToolbarMotion(\n node: HTMLDivElement,\n hidden: boolean,\n motionRef: { current: Animation | null },\n exitTimerRef: { current: number },\n onExit: () => void\n): () => void {\n motionRef.current?.cancel();\n\n if (!hidden) {\n motionRef.current = playToolbarMotion(\n node,\n TOOLBAR_ENTER_KEYFRAMES,\n TOOLBAR_ENTER_MS\n );\n return () => {\n motionRef.current?.cancel();\n };\n }\n\n const animation = playToolbarMotion(\n node,\n TOOLBAR_EXIT_KEYFRAMES,\n TOOLBAR_EXIT_MS\n );\n motionRef.current = animation;\n let finished = false;\n const finishExit = () => {\n if (finished) return;\n finished = true;\n window.clearTimeout(exitTimerRef.current);\n onExit();\n };\n // element.animate() reports completion through onfinish.\n // It does not dispatch animationend.\n if (animation) animation.onfinish = finishExit;\n exitTimerRef.current = window.setTimeout(\n finishExit,\n TOOLBAR_EXIT_UNMOUNT_FALLBACK_MS\n );\n\n return () => {\n window.clearTimeout(exitTimerRef.current);\n motionRef.current?.cancel();\n };\n}\n\nfunction useActionToolbarPresence(\n selectedCount: number | undefined\n): ActionToolbarPresence {\n const hidden = isSelectionHidden(selectedCount);\n const reducedMotion = prefersReducedMotion();\n const [trackedHidden, setTrackedHidden] = useState(hidden);\n const [mounted, setMounted] = useState(!hidden);\n const [displayedCount, setDisplayedCount] = useState(selectedCount);\n const nodeRef = useRef<HTMLDivElement | null>(null);\n const motionRef = useRef<Animation | null>(null);\n const exitTimerRef = useRef(0);\n\n if (hidden !== trackedHidden) {\n setTrackedHidden(hidden);\n if (!hidden) {\n setMounted(true);\n if (typeof selectedCount === 'number') setDisplayedCount(selectedCount);\n } else if (!mounted || reducedMotion) {\n setMounted(false);\n }\n } else if (\n !hidden &&\n typeof selectedCount === 'number' &&\n selectedCount !== displayedCount\n ) {\n setDisplayedCount(selectedCount);\n }\n\n const bindMotion = useCallback((node: HTMLDivElement | null) => {\n nodeRef.current = node;\n }, []);\n\n useEffect(() => {\n if (reducedMotion || !mounted) return undefined;\n const node = nodeRef.current;\n if (!node) return undefined;\n\n return startToolbarMotion(node, hidden, motionRef, exitTimerRef, () => {\n setMounted(false);\n });\n }, [hidden, mounted, reducedMotion]);\n\n return {\n mounted,\n selectedCount: hidden ? displayedCount : selectedCount,\n bindMotion,\n };\n}\n\nexport { TOOLBAR_EXIT_UNMOUNT_FALLBACK_MS, useActionToolbarPresence };\n"],"names":["useCallback","useEffect","useRef","useState","TOOLBAR_ENTER_MS","TOOLBAR_EXIT_MS","TOOLBAR_EXIT_UNMOUNT_FALLBACK_MS","TOOLBAR_DRIFT_OFFSET","TOOLBAR_TRAVEL_OFFSET","TOOLBAR_EXIT_FADE_START","TOOLBAR_ENTER_SETTLE_START","TOOLBAR_ENTER_KEYFRAMES","transform","opacity","offset","TOOLBAR_EXIT_KEYFRAMES","prefersReducedMotion","window","matchMedia","matches","isSelectionHidden","selectedCount","playToolbarMotion","node","keyframes","duration","animate","animation","easing","fill","finished","catch","error","DOMException","name","startToolbarMotion","hidden","motionRef","exitTimerRef","onExit","current","cancel","finishExit","clearTimeout","onfinish","setTimeout","useActionToolbarPresence","reducedMotion","trackedHidden","setTrackedHidden","mounted","setMounted","displayedCount","setDisplayedCount","nodeRef","bindMotion","undefined"],"mappings":"AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAEjE,MAAMC,mBAAmB;AACzB,MAAMC,kBAAkB;AACxB,MAAMC,mCAAmC;AACzC,MAAMC,uBAAuB;AAC7B,MAAMC,wBAAwB;AAC9B,MAAMC,0BAA0B;AAChC,MAAMC,6BAA6B;AAEnC,MAAMC,0BAAsC;IAC1C;QAAEC,WAAW,CAAC,WAAW,EAAEJ,sBAAsB,CAAC,CAAC;QAAEK,SAAS;IAAE;IAChE;QACED,WAAW,CAAC,WAAW,EAAEL,qBAAqB,CAAC,CAAC;QAChDM,SAAS;QACTC,QAAQJ;IACV;IACA;QAAEE,WAAW;QAAiBC,SAAS;IAAE;CAC1C;AAED,MAAME,yBAAqC;IACzC;QAAEH,WAAW;QAAiBC,SAAS;IAAE;IACzC,uDAAuD;IACvD,+DAA+D;IAC/D;QACED,WAAW,CAAC,WAAW,EAAEL,qBAAqB,CAAC,CAAC;QAChDM,SAAS;QACTC,QAAQL;IACV;IACA;QAAEG,WAAW,CAAC,WAAW,EAAEJ,sBAAsB,CAAC,CAAC;QAAEK,SAAS;IAAE;CACjE;AAQD,SAASG;IACP,IAAI,OAAOC,WAAW,aAAa,OAAO;IAC1C,OAAOA,OAAOC,UAAU,CAAC,oCAAoCC,OAAO;AACtE;AAEA,SAASC,kBAAkBC,aAAiC;IAC1D,OAAO,OAAOA,kBAAkB,YAAYA,kBAAkB;AAChE;AAEA,SA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