Skip to content

Commit

Permalink
chore: Change where PartialMermaidConfig is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed May 13, 2024
1 parent 453802d commit d7ce7ae
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 36 deletions.
32 changes: 11 additions & 21 deletions docs/config/setup/modules/config.md
Expand Up @@ -6,16 +6,6 @@
# Module: config

## Type Aliases

### PartialMermaidConfig

Ƭ **PartialMermaidConfig**: `PartialDeep`<`MermaidConfig`>

#### Defined in

[config.ts:10](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L10)

## Variables

### defaultConfig
Expand All @@ -24,7 +14,7 @@

#### Defined in

[config.ts:9](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L9)
[config.ts:8](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L8)

## Functions

Expand All @@ -46,7 +36,7 @@ Pushes in a directive to the configuration

#### Defined in

[config.ts:193](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L193)
[config.ts:191](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L191)

---

Expand All @@ -70,7 +60,7 @@ The currentConfig

#### Defined in

[config.ts:136](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L136)
[config.ts:134](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L134)

---

Expand All @@ -94,7 +84,7 @@ The siteConfig

#### Defined in

[config.ts:101](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L101)
[config.ts:99](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L99)

---

Expand Down Expand Up @@ -128,7 +118,7 @@ The siteConfig

#### Defined in

[config.ts:223](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L223)
[config.ts:221](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L221)

---

Expand Down Expand Up @@ -157,7 +147,7 @@ options in-place

#### Defined in

[config.ts:151](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L151)
[config.ts:149](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L149)

---

Expand All @@ -177,7 +167,7 @@ options in-place

#### Defined in

[config.ts:80](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L80)
[config.ts:78](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L78)

---

Expand Down Expand Up @@ -209,7 +199,7 @@ The currentConfig merged with the sanitized conf

#### Defined in

[config.ts:118](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L118)
[config.ts:116](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L116)

---

Expand Down Expand Up @@ -242,7 +232,7 @@ The new siteConfig

#### Defined in

[config.ts:66](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L66)
[config.ts:64](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L64)

---

Expand All @@ -263,7 +253,7 @@ The new siteConfig

#### Defined in

[config.ts:17](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L17)
[config.ts:15](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L15)

---

Expand All @@ -283,4 +273,4 @@ The new siteConfig

#### Defined in

[config.ts:84](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L84)
[config.ts:82](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L82)
4 changes: 2 additions & 2 deletions packages/mermaid/src/config.spec.ts
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import * as configApi from './config.js';
import type { MermaidConfig } from './config.type.js';
import type { MermaidConfig, PartialMermaidConfig } from './config.type.js';

describe('when working with site config', () => {
beforeEach(() => {
Expand All @@ -24,7 +24,7 @@ describe('when working with site config', () => {
secure: [...configApi.defaultConfig.secure!, 'fontSize'],
} as MermaidConfig;
configApi.setSiteConfig(config_0);
const directive: configApi.PartialMermaidConfig = {
const directive: PartialMermaidConfig = {
fontFamily: 'baf',
// fontSize and securityLevel shouldn't be changed
fontSize: 54321,
Expand Down
4 changes: 1 addition & 3 deletions packages/mermaid/src/config.ts
@@ -1,13 +1,11 @@
import type { PartialDeep } from 'type-fest';
import assignWithDepth from './assignWithDepth.js';
import type { MermaidConfig } from './config.type.js';
import type { MermaidConfig, PartialMermaidConfig } from './config.type.js';
import config from './defaultConfig.js';
import { log } from './logger.js';
import theme from './themes/index.js';
import { sanitizeDirective } from './utils/sanitizeDirective.js';

export const defaultConfig: MermaidConfig = Object.freeze(config);
export type PartialMermaidConfig = PartialDeep<MermaidConfig>;

let siteConfig: MermaidConfig = assignWithDepth({}, defaultConfig);
let configFromInitialize: PartialMermaidConfig;
Expand Down
7 changes: 7 additions & 0 deletions packages/mermaid/src/config.type.ts
Expand Up @@ -9,6 +9,13 @@
* Configuration options to pass to the `dompurify` library.
*/
export type DOMPurifyConfiguration = import('dompurify').Config;
/**
* MermaidConfig with all fields optional
*
* This interface was referenced by `MermaidConfig`'s JSON-Schema
* via the `definition` "PartialMermaidConfig".
*/
export type PartialMermaidConfig = import('type-fest').PartialDeep<MermaidConfig>;
/**
* JavaScript function that returns a `FontConfig`.
*
Expand Down
3 changes: 1 addition & 2 deletions packages/mermaid/src/diagram-api/frontmatter.ts
@@ -1,5 +1,4 @@
import type { PartialMermaidConfig } from '../config.js';
import type { GanttDiagramConfig } from '../config.type.js';
import type { GanttDiagramConfig, PartialMermaidConfig } from '../config.type.js';
import { frontMatterRegex } from './regexes.js';
// The "* as yaml" part is necessary for tree-shaking
import * as yaml from 'js-yaml';
Expand Down
3 changes: 1 addition & 2 deletions packages/mermaid/src/diagram-api/types.ts
Expand Up @@ -2,8 +2,7 @@
import type * as d3 from 'd3';
import type { SetRequired } from 'type-fest';
import type { Diagram } from '../Diagram.js';
import type { PartialMermaidConfig } from '../config.js';
import type { BaseDiagramConfig } from '../config.type.js';
import type { BaseDiagramConfig, PartialMermaidConfig } from '../config.type.js';

export interface DiagramMetadata {
title?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/mermaidAPI.ts
Expand Up @@ -20,7 +20,7 @@ import { version } from '../package.json';
import { Diagram } from './Diagram.js';
import { addSVGa11yTitleDescription, setA11yDiagramInfo } from './accessibility.js';
import * as configApi from './config.js';
import type { MermaidConfig } from './config.type.js';
import type { MermaidConfig, PartialMermaidConfig } from './config.type.js';
import { addDiagrams } from './diagram-api/diagram-orchestration.js';
import type { DiagramMetadata, DiagramStyleClassDef } from './diagram-api/types.js';
import { evaluate } from './diagrams/common/common.js';
Expand Down Expand Up @@ -517,7 +517,7 @@ const render = async function (
/**
* @param options - Initial Mermaid options
*/
function initialize(options: configApi.PartialMermaidConfig = {}) {
function initialize(options: PartialMermaidConfig = {}) {
// Handle legacy location of font-family configuration
if (options?.fontFamily && !options.themeVariables?.fontFamily) {
if (!options.themeVariables) {
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/preprocess.ts
@@ -1,4 +1,4 @@
import type { PartialMermaidConfig } from './config.js';
import type { PartialMermaidConfig } from './config.type.js';
import { cleanupComments } from './diagram-api/comments.js';
import { extractFrontMatter } from './diagram-api/frontmatter.js';
import type { DiagramMetadata } from './diagram-api/types.js';
Expand Down
@@ -1,7 +1,7 @@
import type { Content } from 'mdast';
import { fromMarkdown } from 'mdast-util-from-markdown';
import { dedent } from 'ts-dedent';
import type { PartialMermaidConfig } from '../config.js';
import type { PartialMermaidConfig } from '../config.type.js';
import type { MarkdownLine, MarkdownWordType } from './types.js';

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/mermaid/src/schemas/config.schema.yaml
Expand Up @@ -261,6 +261,11 @@ properties:
This is useful when you want to control how to handle syntax errors in your application.
$defs: # JSON Schema definition (maybe we should move these to a separate file)
PartialMermaidConfig:
title: PartialMermaidConfig
description: MermaidConfig with all fields optional
type: object
tsType: "import('type-fest').PartialDeep<MermaidConfig>"
BaseDiagramConfig:
# TODO: More config needs to be moved here
title: Base Diagram Config
Expand Down
3 changes: 1 addition & 2 deletions packages/mermaid/src/utils.ts
Expand Up @@ -26,8 +26,7 @@ import {
import memoize from 'lodash-es/memoize.js';
import merge from 'lodash-es/merge.js';
import assignWithDepth from './assignWithDepth.js';
import type { PartialMermaidConfig } from './config.js';
import type { MermaidConfig } from './config.type.js';
import type { MermaidConfig, PartialMermaidConfig } from './config.type.js';
import { detectType } from './diagram-api/detectType.js';
import { directiveRegex } from './diagram-api/regexes.js';
import common from './diagrams/common/common.js';
Expand Down

0 comments on commit d7ce7ae

Please sign in to comment.