mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-11 03:19:42 +02:00
remove cleanClone
This commit is contained in:
@@ -1,24 +0,0 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
||||||
|
|
||||||
export function removeUndefined(data: any): any {
|
|
||||||
if (typeof data === 'object') {
|
|
||||||
const entries: [string, any][] = Object.entries(data).filter(
|
|
||||||
([, value]: [string, any]) => value !== undefined
|
|
||||||
);
|
|
||||||
|
|
||||||
const clean: any[][] = entries.map(([key, v]: [string, any]) => {
|
|
||||||
const value = typeof v == 'object' ? removeUndefined(v) : v;
|
|
||||||
return [key, value];
|
|
||||||
});
|
|
||||||
|
|
||||||
return Object.fromEntries(clean);
|
|
||||||
} else if (Array.isArray(data)) {
|
|
||||||
return data.filter((value: any) => value !== undefined);
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function structuredCleanClone<T = any>(defaultData: T, data?: Partial<T>): T {
|
|
||||||
const cleanValue: T = removeUndefined(data);
|
|
||||||
return structuredClone<T>({ ...defaultData, ...cleanValue });
|
|
||||||
}
|
|
@@ -15,7 +15,7 @@ import type { ParseDirectiveDefinition } from '../../diagram-api/types.js';
|
|||||||
import type { PieFields, PieDB, Sections } from './pieTypes.js';
|
import type { PieFields, PieDB, Sections } from './pieTypes.js';
|
||||||
import type { RequiredDeep } from 'type-fest';
|
import type { RequiredDeep } from 'type-fest';
|
||||||
import type { PieDiagramConfig } from '../../config.type.js';
|
import type { PieDiagramConfig } from '../../config.type.js';
|
||||||
import { structuredCleanClone } from '../../cleanClone.js';
|
import { cleanAndMerge } from '../../utils.js';
|
||||||
|
|
||||||
export const DEFAULT_PIE_CONFIG: Required<PieDiagramConfig> = {
|
export const DEFAULT_PIE_CONFIG: Required<PieDiagramConfig> = {
|
||||||
useMaxWidth: true,
|
useMaxWidth: true,
|
||||||
@@ -31,16 +31,16 @@ export const DEFAULT_PIE_DB: RequiredDeep<PieFields> = {
|
|||||||
|
|
||||||
let sections: Sections = DEFAULT_PIE_DB.sections;
|
let sections: Sections = DEFAULT_PIE_DB.sections;
|
||||||
let showData: boolean = DEFAULT_PIE_DB.showData;
|
let showData: boolean = DEFAULT_PIE_DB.showData;
|
||||||
let config: Required<PieDiagramConfig> = structuredCleanClone(DEFAULT_PIE_CONFIG);
|
let config: Required<PieDiagramConfig> = structuredClone(DEFAULT_PIE_CONFIG);
|
||||||
|
|
||||||
const setConfig = (conf: PieDiagramConfig): void => {
|
const setConfig = (conf: PieDiagramConfig): void => {
|
||||||
config = structuredCleanClone(DEFAULT_PIE_CONFIG, conf);
|
config = cleanAndMerge(DEFAULT_PIE_CONFIG, conf);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getConfig = (): Required<PieDiagramConfig> => config;
|
const getConfig = (): Required<PieDiagramConfig> => config;
|
||||||
|
|
||||||
const resetConfig = (): void => {
|
const resetConfig = (): void => {
|
||||||
config = structuredCleanClone(DEFAULT_PIE_CONFIG);
|
config = structuredClone(DEFAULT_PIE_CONFIG);
|
||||||
};
|
};
|
||||||
|
|
||||||
const parseDirective: ParseDirectiveDefinition = (statement, context, type) => {
|
const parseDirective: ParseDirectiveDefinition = (statement, context, type) => {
|
||||||
@@ -48,7 +48,7 @@ const parseDirective: ParseDirectiveDefinition = (statement, context, type) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const clear = (): void => {
|
const clear = (): void => {
|
||||||
sections = structuredCleanClone(DEFAULT_PIE_DB.sections);
|
sections = structuredClone(DEFAULT_PIE_DB.sections);
|
||||||
showData = DEFAULT_PIE_DB.showData;
|
showData = DEFAULT_PIE_DB.showData;
|
||||||
commonClear();
|
commonClear();
|
||||||
resetConfig();
|
resetConfig();
|
||||||
|
Reference in New Issue
Block a user