Skip to content

Commit

Permalink
refactor!: remove MermaidConfig type enum fallback
Browse files Browse the repository at this point in the history
Currently (in Mermaid v10), pretty much all enum types in the
MermaidConfig have generic `string` or `number` fallbacks,
for backwards compatibility.

This commit drops this. The MermaidConfig TypeScript types now expects
a limited amount of values.

BREAKING-CHANGE: Remove `MermaidConfig` generic type fallbacks for
                 enum values.
  • Loading branch information
aloisklink committed Sep 2, 2023
1 parent 77ba7c9 commit b48136d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 49 deletions.
41 changes: 13 additions & 28 deletions packages/mermaid/src/config.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface MermaidConfig {
* You may also use `themeCSS` to override this value.
*
*/
theme?: string | 'default' | 'forest' | 'dark' | 'neutral' | 'null';
theme?: 'default' | 'forest' | 'dark' | 'neutral' | 'null';
themeVariables?: any;
themeCSS?: string;
/**
Expand All @@ -82,26 +82,11 @@ export interface MermaidConfig {
* This option decides the amount of logging to be used by mermaid.
*
*/
logLevel?:
| number
| string
| 0
| 2
| 1
| 'trace'
| 'debug'
| 'info'
| 'warn'
| 'error'
| 'fatal'
| 3
| 4
| 5
| undefined;
logLevel?: 'trace' | 0 | 'debug' | 1 | 'info' | 2 | 'warn' | 3 | 'error' | 4 | 'fatal' | 5;
/**
* Level of trust for parsed diagram
*/
securityLevel?: string | 'strict' | 'loose' | 'antiscript' | 'sandbox' | undefined;
securityLevel?: 'strict' | 'loose' | 'antiscript' | 'sandbox';
/**
* Dictates whether mermaid starts on Page load
*/
Expand Down Expand Up @@ -723,7 +708,7 @@ export interface ErDiagramConfig extends BaseDiagramConfig {
/**
* Directional bias for layout of entities
*/
layoutDirection?: string | 'TB' | 'BT' | 'LR' | 'RL';
layoutDirection?: 'TB' | 'BT' | 'LR' | 'RL';
/**
* The minimum width of an entity box. Expressed in pixels.
*/
Expand Down Expand Up @@ -788,7 +773,7 @@ export interface StateDiagramConfig extends BaseDiagramConfig {
* Decides which rendering engine that is to be used for the rendering.
*
*/
defaultRenderer?: string | 'dagre-d3' | 'dagre-wrapper' | 'elk';
defaultRenderer?: 'dagre-d3' | 'dagre-wrapper' | 'elk';
}
/**
* This interface was referenced by `MermaidConfig`'s JSON-Schema
Expand All @@ -812,7 +797,7 @@ export interface ClassDiagramConfig extends BaseDiagramConfig {
* Decides which rendering engine that is to be used for the rendering.
*
*/
defaultRenderer?: string | 'dagre-d3' | 'dagre-wrapper' | 'elk';
defaultRenderer?: 'dagre-d3' | 'dagre-wrapper' | 'elk';
nodeSpacing?: number;
rankSpacing?: number;
/**
Expand Down Expand Up @@ -872,7 +857,7 @@ export interface JourneyDiagramConfig extends BaseDiagramConfig {
/**
* Multiline message alignment
*/
messageAlign?: string | 'left' | 'center' | 'right';
messageAlign?: 'left' | 'center' | 'right';
/**
* Prolongs the edge of the diagram downwards.
*
Expand Down Expand Up @@ -951,7 +936,7 @@ export interface TimelineDiagramConfig extends BaseDiagramConfig {
/**
* Multiline message alignment
*/
messageAlign?: string | 'left' | 'center' | 'right';
messageAlign?: 'left' | 'center' | 'right';
/**
* Prolongs the edge of the diagram downwards.
*
Expand Down Expand Up @@ -1062,7 +1047,7 @@ export interface GanttDiagramConfig extends BaseDiagramConfig {
* Controls the display mode.
*
*/
displayMode?: string | 'compact';
displayMode?: '' | 'compact';
/**
* On which day a week-based interval should start
*
Expand Down Expand Up @@ -1121,7 +1106,7 @@ export interface SequenceDiagramConfig extends BaseDiagramConfig {
/**
* Multiline message alignment
*/
messageAlign?: string | 'left' | 'center' | 'right';
messageAlign?: 'left' | 'center' | 'right';
/**
* Mirror actors under diagram
*
Expand Down Expand Up @@ -1178,7 +1163,7 @@ export interface SequenceDiagramConfig extends BaseDiagramConfig {
/**
* This sets the text alignment of actor-attached notes
*/
noteAlign?: string | 'left' | 'center' | 'right';
noteAlign?: 'left' | 'center' | 'right';
/**
* This sets the font size of actor messages
*/
Expand Down Expand Up @@ -1254,7 +1239,7 @@ export interface FlowchartDiagramConfig extends BaseDiagramConfig {
* Defines how mermaid renders curves for flowcharts.
*
*/
curve?: string | 'basis' | 'linear' | 'cardinal';
curve?: 'basis' | 'linear' | 'cardinal';
/**
* Represents the padding between the labels and the shape
*
Expand All @@ -1266,7 +1251,7 @@ export interface FlowchartDiagramConfig extends BaseDiagramConfig {
* Decides which rendering engine that is to be used for the rendering.
*
*/
defaultRenderer?: string | 'dagre-d3' | 'dagre-wrapper' | 'elk';
defaultRenderer?: 'dagre-d3' | 'dagre-wrapper' | 'elk';
/**
* Width of nodes where text is wrapped.
*
Expand Down
21 changes: 0 additions & 21 deletions packages/mermaid/src/schemas/config.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ properties:
meta:enum:
'null': Can be set to disable any pre-defined mermaid theme
default: 'default'
# Allow any string for typescript backwards compatibility (fix in Mermaid v10)
tsType: 'string | "default" | "forest" | "dark" | "neutral" | "null"'
themeVariables:
tsType: any
themeCSS:
Expand Down Expand Up @@ -115,8 +113,6 @@ properties:
error: Equivalent to 4
fatal: Equivalent to 5 (default)
default: 5
# Allow any number or string for typescript backwards compatibility (fix in Mermaid v10)
tsType: 'number | string | 0 | 2 | 1 | "trace" | "debug" | "info" | "warn" | "error" | "fatal" | 3 | 4 | 5 | undefined'
securityLevel:
description: Level of trust for parsed diagram
type: string
Expand All @@ -134,8 +130,6 @@ properties:
This prevent any JavaScript from running in the context.
This may hinder interactive functionality of the diagram, like scripts, popups in the sequence diagram, or links to other tabs or targets, etc.
default: strict
# Allow any string for typescript backwards compatibility (fix in Mermaid v10)
tsType: 'string | "strict" | "loose" | "antiscript" | "sandbox" | undefined'
startOnLoad:
description: Dictates whether mermaid starts on Page load
type: boolean
Expand Down Expand Up @@ -1021,8 +1015,6 @@ $defs: # JSON Schema definition (maybe we should move these to a seperate file)
LR: Left-Right
RL: Right to Left
default: TB
# Allow any string for typescript backwards compatibility (fix in Mermaid v10)
tsType: 'string | "TB" | "BT" | "LR" | "RL"'
minEntityWidth:
description: The minimum width of an entity box. Expressed in pixels.
type: integer
Expand Down Expand Up @@ -1135,8 +1127,6 @@ $defs: # JSON Schema definition (maybe we should move these to a seperate file)
dagre-d3: The [dagre-d3-es](https://www.npmjs.com/package/dagre-d3-es) library.
dagre-wrapper: wrapper for dagre implemented in mermaid
elk: Layout using [elkjs](https://github.com/kieler/elkjs)
# Allow any string for typescript backwards compatibility (fix in Mermaid v10)
tsType: 'string | "dagre-d3" | "dagre-wrapper" | "elk"'

ClassDiagramConfig:
title: Class Diagram Config
Expand Down Expand Up @@ -1252,8 +1242,6 @@ $defs: # JSON Schema definition (maybe we should move these to a seperate file)
- center
- right
default: center
# Allow any string for typescript backwards compatibility (fix in Mermaid v10)
tsType: 'string | "left" | "center" | "right"'
bottomMarginAdj:
description: |
Prolongs the edge of the diagram downwards.
Expand Down Expand Up @@ -1378,8 +1366,6 @@ $defs: # JSON Schema definition (maybe we should move these to a seperate file)
- center
- right
default: center
# Allow any string for typescript backwards compatibility (fix in Mermaid v10)
tsType: 'string | "left" | "center" | "right"'
bottomMarginAdj:
description: |
Prolongs the edge of the diagram downwards.
Expand Down Expand Up @@ -1543,13 +1529,10 @@ $defs: # JSON Schema definition (maybe we should move these to a seperate file)
meta:enum:
compact: Enables displaying multiple tasks on the same row.
default: ''
# Allow any string for typescript backwards compatibility (fix in Mermaid v10)
tsType: 'string | "compact"'
weekday:
description: |
On which day a week-based interval should start
type: string
tsType: '"monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday" | "sunday"'
enum:
- monday
- tuesday
Expand Down Expand Up @@ -1691,8 +1674,6 @@ $defs: # JSON Schema definition (maybe we should move these to a seperate file)
type: string
enum: ['left', 'center', 'right']
default: 'center'
# Allow any string for typescript backwards compatibility (fix in Mermaid v10)
tsType: 'string | "left" | "center" | "right"'

messageFontSize:
description: This sets the font size of actor messages
Expand Down Expand Up @@ -1780,8 +1761,6 @@ $defs: # JSON Schema definition (maybe we should move these to a seperate file)
type: string
enum: ['basis', 'linear', 'cardinal']
default: 'basis'
# Allow any string for typescript backwards compatibility (fix in Mermaid v10)
tsType: 'string | "basis" | "linear" | "cardinal"'
padding:
description: |
Represents the padding between the labels and the shape
Expand Down

0 comments on commit b48136d

Please sign in to comment.