@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.
@@ -1,4 +1,4 @@
1
1
  export var PACKAGE_SOURCE = "board-components";
2
- export var PACKAGE_VERSION = "3.0.0 (a1dd58c7)";
2
+ export var PACKAGE_VERSION = "3.0.0 (49652ff5)";
3
3
  export var THEME = "open-source-visual-refresh";
4
4
  export var ALWAYS_VISUAL_REFRESH = true;
@@ -0,0 +1,6 @@
1
+ {
2
+ "PACKAGE_SOURCE": "board-components",
3
+ "PACKAGE_VERSION": "3.0.0 (49652ff5)",
4
+ "THEME": "open-source-visual-refresh",
5
+ "ALWAYS_VISUAL_REFRESH": true
6
+ }
@@ -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,
@@ -1,3 +1,3 @@
1
1
  {
2
- "commit": "a1dd58c7cb3157d4d806d7d6c3910b9cc8376b7d"
2
+ "commit": "49652ff586f1bf37480d83de685ced23a5bbf1fc"
3
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudscape-design/board-components",
3
- "version": "3.0.27",
3
+ "version": "3.0.28",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cloudscape-design/board-components.git"
@@ -1,2 +0,0 @@
1
- /// <reference types="react" />
2
- export declare function useDensityMode(elementRef: React.RefObject<HTMLElement>): "comfortable" | "compact";
@@ -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
- }