@vertigis/react-ui 11.27.0 → 11.28.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vertigis/react-ui",
3
- "version": "11.27.0",
3
+ "version": "11.28.0",
4
4
  "description": "Utilities and React components used in VertiGIS applications.",
5
5
  "keywords": [
6
6
  "vertigis",
@@ -26,7 +26,6 @@
26
26
  "clsx": "^1.2.1",
27
27
  "color": "^4.2.3",
28
28
  "lodash.escape": "^4.0.1",
29
- "lodash.merge": "^4.6.2",
30
29
  "marked": "^4.2.12",
31
30
  "react-color": "^2.19.3",
32
31
  "tslib": "^2.1.0",
@@ -37,7 +36,6 @@
37
36
  "@types/autosuggest-highlight": "^3.2.0",
38
37
  "@types/color": "^3.0.1",
39
38
  "@types/lodash.escape": "^4.0.1",
40
- "@types/lodash.merge": "^4.6.7",
41
39
  "@types/marked": "^4.0.2",
42
40
  "@types/react-color": "^3.0.6",
43
41
  "@vertigis/icons": "5.0.581"
@@ -12,3 +12,12 @@ export interface CreateThemeOptions extends ThemeOptions {
12
12
  declare function createTheme(options?: CreateThemeOptions): Theme;
13
13
  export default createTheme;
14
14
  export type { Direction } from "@mui/material/styles";
15
+ /**
16
+ * Merges theme overrides with a base theme.
17
+ *
18
+ * @param theme The theme to override.
19
+ * @param overrides New theme settings that will be deeply merged with the
20
+ * original theme.
21
+ * @returns A new theme that is the merger of the original theme plus overrides.
22
+ */
23
+ export declare function overrideTheme(theme: Theme, overrides: Partial<Theme>): Theme;
@@ -1,5 +1,4 @@
1
1
  import { alpha, createTheme as createMuiTheme } from "@mui/material/styles";
2
- import merge from "lodash.merge";
3
2
  import blue from "../colors/blue.js";
4
3
  import common from "../colors/common.js";
5
4
  import green from "../colors/green.js";
@@ -938,9 +937,50 @@ function createTheme(options = {}) {
938
937
  // If we are using light mode, then we want to use our defined light theme palette
939
938
  const modeOptions = mode === "light" ? lightThemeOverrides : {};
940
939
  const { dense = false, ...overrides } = options;
941
- /* eslint-disable @typescript-eslint/no-unsafe-call */
942
- const mergedOptions = merge({}, defaultOptions, modeOptions, dense ? defaultDenseOptions : {}, overrides);
940
+ const mergedOptions = deepAssign({}, defaultOptions, modeOptions, dense ? defaultDenseOptions : {}, overrides);
943
941
  const createdTheme = createMuiTheme(mergedOptions);
944
- return merge({}, getOverrides(createdTheme), createdTheme);
942
+ return overrideTheme(createdTheme, getOverrides(createdTheme));
945
943
  }
946
944
  export default createTheme;
945
+ /**
946
+ * Merges theme overrides with a base theme.
947
+ *
948
+ * @param theme The theme to override.
949
+ * @param overrides New theme settings that will be deeply merged with the
950
+ * original theme.
951
+ * @returns A new theme that is the merger of the original theme plus overrides.
952
+ */
953
+ export function overrideTheme(theme, overrides) {
954
+ return deepAssign({}, theme, overrides);
955
+ }
956
+ /**
957
+ * A recursive version of Object.assign().
958
+ */
959
+ function deepAssign(target, ...sources) {
960
+ if (target === null || target === undefined) {
961
+ throw new TypeError("Cannot convert undefined or null to object.");
962
+ }
963
+ const result = Object(target);
964
+ sources.forEach(source => {
965
+ if (!source) {
966
+ return;
967
+ }
968
+ const sourceObj = Object(source);
969
+ for (const key of Object.keys(sourceObj)) {
970
+ const sourceValue = sourceObj[key];
971
+ if (result[key] && typeof result[key] === "object") {
972
+ deepAssign(result[key], sourceValue);
973
+ }
974
+ else if (Array.isArray(sourceValue)) {
975
+ result[key] = deepAssign([], sourceValue);
976
+ }
977
+ else if (sourceValue && typeof sourceValue === "object") {
978
+ result[key] = deepAssign({}, sourceValue);
979
+ }
980
+ else {
981
+ result[key] = sourceValue;
982
+ }
983
+ }
984
+ });
985
+ return result;
986
+ }