@cloudscape-design/board-components 3.0.27 → 3.0.28
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/internal/environment.js
CHANGED
package/internal/grid/grid.js
CHANGED
|
@@ -2,13 +2,13 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
import { useContainerQuery } from "@cloudscape-design/component-toolkit";
|
|
5
|
+
import { useDensityMode } from "@cloudscape-design/component-toolkit/internal";
|
|
5
6
|
import clsx from "clsx";
|
|
6
7
|
import { Children, useRef } from "react";
|
|
7
8
|
import { useMergeRefs } from "../utils/use-merge-refs";
|
|
8
9
|
import { zipTwoArrays } from "../utils/zip-arrays";
|
|
9
10
|
import GridItem from "./item";
|
|
10
11
|
import styles from "./styles.css.js";
|
|
11
|
-
import { useDensityMode } from "./use-density-mode";
|
|
12
12
|
/* Matches grid gap in CSS. */
|
|
13
13
|
const GRID_GAP = {
|
|
14
14
|
comfortable: 20,
|
package/internal/manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { findUpUntil } from "@cloudscape-design/component-toolkit/dom";
|
|
4
|
-
import { useEffect, useState } from "react";
|
|
5
|
-
import { unstable_batchedUpdates } from "react-dom";
|
|
6
|
-
import { useStableEventHandler } from "../utils/use-stable-event-handler";
|
|
7
|
-
// Matches: https://github.com/cloudscape-design/components/blob/main/src/internal/hooks/use-visual-mode/index.ts
|
|
8
|
-
export function useDensityMode(elementRef) {
|
|
9
|
-
const [value, setValue] = useState("comfortable");
|
|
10
|
-
useMutationObserver(elementRef, (node) => {
|
|
11
|
-
const compactModeParent = findUpUntil(node, (node) => node.classList.contains("awsui-polaris-compact-mode") || node.classList.contains("awsui-compact-mode"));
|
|
12
|
-
setValue(compactModeParent ? "compact" : "comfortable");
|
|
13
|
-
});
|
|
14
|
-
return value;
|
|
15
|
-
}
|
|
16
|
-
const useMutationSingleton = createSingletonHandler((handler) => {
|
|
17
|
-
const observer = new MutationObserver(() => handler());
|
|
18
|
-
observer.observe(document.body, { attributes: true, subtree: true });
|
|
19
|
-
return () => observer.disconnect();
|
|
20
|
-
});
|
|
21
|
-
function useMutationObserver(elementRef, onChange) {
|
|
22
|
-
const handler = useStableEventHandler(() => {
|
|
23
|
-
if (elementRef.current) {
|
|
24
|
-
onChange(elementRef.current);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
useMutationSingleton(handler);
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
handler();
|
|
30
|
-
}, [handler]);
|
|
31
|
-
}
|
|
32
|
-
function createSingletonHandler(factory) {
|
|
33
|
-
const listeners = [];
|
|
34
|
-
const callback = (value) => {
|
|
35
|
-
unstable_batchedUpdates(() => {
|
|
36
|
-
for (const listener of listeners) {
|
|
37
|
-
listener(value);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
let cleanup;
|
|
42
|
-
return function useSingleton(listener) {
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (listeners.length === 0) {
|
|
45
|
-
cleanup = factory(callback);
|
|
46
|
-
}
|
|
47
|
-
listeners.push(listener);
|
|
48
|
-
return () => {
|
|
49
|
-
listeners.splice(listeners.indexOf(listener), 1);
|
|
50
|
-
if (listeners.length === 0) {
|
|
51
|
-
cleanup();
|
|
52
|
-
cleanup = undefined;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
// register handlers only on mount
|
|
56
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
57
|
-
}, []);
|
|
58
|
-
};
|
|
59
|
-
}
|