From 03419c691cf890eb3c0c5138c4b797c0bd5c3052 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 19 Feb 2023 14:13:47 +0530 Subject: [PATCH 01/13] Remove Readme --- packages/mermaid/README.md | 346 ------------------------------- packages/mermaid/README.zh-CN.md | 334 ----------------------------- 2 files changed, 680 deletions(-) delete mode 100644 packages/mermaid/README.md delete mode 100644 packages/mermaid/README.zh-CN.md diff --git a/packages/mermaid/README.md b/packages/mermaid/README.md deleted file mode 100644 index d453d2ec0..000000000 --- a/packages/mermaid/README.md +++ /dev/null @@ -1,346 +0,0 @@ -# mermaid - -[![Build CI Status](https://github.com/mermaid-js/mermaid/actions/workflows/build.yml/badge.svg)](https://github.com/mermaid-js/mermaid/actions/workflows/build.yml) [![NPM](https://img.shields.io/npm/v/mermaid)](https://www.npmjs.com/package/mermaid) [![npm minified gzipped bundle size](https://img.shields.io/bundlephobia/minzip/mermaid)](https://bundlephobia.com/package/mermaid) [![Coverage Status](https://coveralls.io/repos/github/mermaid-js/mermaid/badge.svg?branch=master)](https://coveralls.io/github/mermaid-js/mermaid?branch=master) [![CDN Status](https://img.shields.io/jsdelivr/npm/hm/mermaid)](https://www.jsdelivr.com/package/npm/mermaid) [![NPM](https://img.shields.io/npm/dm/mermaid)](https://www.npmjs.com/package/mermaid) [![Join our Slack!](https://img.shields.io/static/v1?message=join%20chat&color=9cf&logo=slack&label=slack)](https://join.slack.com/t/mermaid-talk/shared_invite/enQtNzc4NDIyNzk4OTAyLWVhYjQxOTI2OTg4YmE1ZmJkY2Y4MTU3ODliYmIwOTY3NDJlYjA0YjIyZTdkMDMyZTUwOGI0NjEzYmEwODcwOTE) [![Twitter Follow](https://img.shields.io/twitter/follow/mermaidjs_?style=social)](https://twitter.com/mermaidjs_) - -English | [简体中文](./README.zh-CN.md) - - - -:trophy: **Mermaid was nominated and won the [JS Open Source Awards (2019)](https://osawards.com/javascript/2019) in the category "The most exciting use of technology"!!!** - -**Thanks to all involved, people committing pull requests, people answering questions! 🙏** - -Explore Mermaid.js in depth, with real-world examples, tips & tricks from the creator... The first official book on Mermaid is available for purchase. Check it out! - -## About - - - -Mermaid is a JavaScript-based diagramming and charting tool that uses Markdown-inspired text definitions and a renderer to create and modify complex diagrams. The main purpose of Mermaid is to help documentation catch up with development. - -> Doc-Rot is a Catch-22 that Mermaid helps to solve. - -Diagramming and documentation costs precious developer time and gets outdated quickly. -But not having diagrams or docs ruins productivity and hurts organizational learning.
-Mermaid addresses this problem by enabling users to create easily modifiable diagrams. It can also be made part of production scripts (and other pieces of code).
-
- -Mermaid allows even non-programmers to easily create detailed diagrams through the [Mermaid Live Editor](https://mermaid.live/).
-[Tutorials](./docs/Tutorials.md) has video tutorials. -Use Mermaid with your favorite applications, check out the list of [Integrations and Usages of Mermaid](./docs/integrations.md). - -You can also use Mermaid within [GitHub](https://github.blog/2022-02-14-include-diagrams-markdown-files-mermaid/) as well many of your other favorite applications—check out the list of [Integrations and Usages of Mermaid](./docs/integrations.md). - -For a more detailed introduction to Mermaid and some of its more basic uses, look to the [Beginner's Guide](./docs/n00b-overview.md), [Usage](./docs/usage.md) and [Tutorials](./docs/Tutorials.md). - -🌐 [CDN](https://www.jsdelivr.com/package/npm/mermaid) | 📖 [Documentation](https://mermaidjs.github.io) | 🙌 [Contribution](https://github.com/mermaid-js/mermaid/blob/develop/CONTRIBUTING.md) | 📜 [Changelog](./docs/CHANGELOG.md) - -In our release process we rely heavily on visual regression tests using [applitools](https://applitools.com/). Applitools is a great service which has been easy to use and integrate with our tests. - - - - - - - -## Examples - -**The following are some examples of the diagrams, charts and graphs that can be made using Mermaid. Click here to jump into the [text syntax](https://mermaid-js.github.io/mermaid/#/n00b-syntaxReference).** - - - -### Flowchart [docs - live editor] - -``` -flowchart LR - -A[Hard] -->|Text| B(Round) -B --> C{Decision} -C -->|One| D[Result 1] -C -->|Two| E[Result 2] -``` - -```mermaid -flowchart LR - -A[Hard] -->|Text| B(Round) -B --> C{Decision} -C -->|One| D[Result 1] -C -->|Two| E[Result 2] -``` - -### Sequence diagram [docs - live editor] - -``` -sequenceDiagram -Alice->>John: Hello John, how are you? -loop Healthcheck - John->>John: Fight against hypochondria -end -Note right of John: Rational thoughts! -John-->>Alice: Great! -John->>Bob: How about you? -Bob-->>John: Jolly good! -``` - -```mermaid -sequenceDiagram -Alice->>John: Hello John, how are you? -loop Healthcheck - John->>John: Fight against hypochondria -end -Note right of John: Rational thoughts! -John-->>Alice: Great! -John->>Bob: How about you? -Bob-->>John: Jolly good! -``` - -### Gantt chart [docs - live editor] - -``` -gantt - section Section - Completed :done, des1, 2014-01-06,2014-01-08 - Active :active, des2, 2014-01-07, 3d - Parallel 1 : des3, after des1, 1d - Parallel 2 : des4, after des1, 1d - Parallel 3 : des5, after des3, 1d - Parallel 4 : des6, after des4, 1d -``` - -```mermaid -gantt - section Section - Completed :done, des1, 2014-01-06,2014-01-08 - Active :active, des2, 2014-01-07, 3d - Parallel 1 : des3, after des1, 1d - Parallel 2 : des4, after des1, 1d - Parallel 3 : des5, after des3, 1d - Parallel 4 : des6, after des4, 1d -``` - -### Class diagram [docs - live editor] - -``` -classDiagram -Class01 <|-- AveryLongClass : Cool -<> Class01 -Class09 --> C2 : Where am I? -Class09 --* C3 -Class09 --|> Class07 -Class07 : equals() -Class07 : Object[] elementData -Class01 : size() -Class01 : int chimp -Class01 : int gorilla -class Class10 { - <> - int id - size() -} -``` - -```mermaid -classDiagram -Class01 <|-- AveryLongClass : Cool -<> Class01 -Class09 --> C2 : Where am I? -Class09 --* C3 -Class09 --|> Class07 -Class07 : equals() -Class07 : Object[] elementData -Class01 : size() -Class01 : int chimp -Class01 : int gorilla -class Class10 { - <> - int id - size() -} -``` - -### State diagram [docs - live editor] - -``` -stateDiagram-v2 -[*] --> Still -Still --> [*] -Still --> Moving -Moving --> Still -Moving --> Crash -Crash --> [*] -``` - -```mermaid -stateDiagram-v2 -[*] --> Still -Still --> [*] -Still --> Moving -Moving --> Still -Moving --> Crash -Crash --> [*] -``` - -### Pie chart [docs - live editor] - -``` -pie -"Dogs" : 386 -"Cats" : 85.9 -"Rats" : 15 -``` - -```mermaid -pie -"Dogs" : 386 -"Cats" : 85.9 -"Rats" : 15 -``` - -### Git graph [experimental - live editor] - -### User Journey diagram [docs - live editor] - -``` - journey - title My working day - section Go to work - Make tea: 5: Me - Go upstairs: 3: Me - Do work: 1: Me, Cat - section Go home - Go downstairs: 5: Me - Sit down: 3: Me -``` - -```mermaid - journey - title My working day - section Go to work - Make tea: 5: Me - Go upstairs: 3: Me - Do work: 1: Me, Cat - section Go home - Go downstairs: 5: Me - Sit down: 3: Me -``` - -### C4 diagram [docs] - -``` -C4Context -title System Context diagram for Internet Banking System - -Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.") -Person(customerB, "Banking Customer B") -Person_Ext(customerC, "Banking Customer C") -System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.") - -Person(customerD, "Banking Customer D", "A customer of the bank,
with personal bank accounts.") - -Enterprise_Boundary(b1, "BankBoundary") { - - SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.") - - System_Boundary(b2, "BankBoundary2") { - System(SystemA, "Banking System A") - System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts.") - } - - System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.") - SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.") - - Boundary(b3, "BankBoundary3", "boundary") { - SystemQueue(SystemF, "Banking System F Queue", "A system of the bank, with personal bank accounts.") - SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.") - } -} - -BiRel(customerA, SystemAA, "Uses") -BiRel(SystemAA, SystemE, "Uses") -Rel(SystemAA, SystemC, "Sends e-mails", "SMTP") -Rel(SystemC, customerA, "Sends e-mails to") -``` - -```mermaid -C4Context -title System Context diagram for Internet Banking System - -Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.") -Person(customerB, "Banking Customer B") -Person_Ext(customerC, "Banking Customer C") -System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.") - -Person(customerD, "Banking Customer D", "A customer of the bank,
with personal bank accounts.") - -Enterprise_Boundary(b1, "BankBoundary") { - - SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.") - - System_Boundary(b2, "BankBoundary2") { - System(SystemA, "Banking System A") - System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts.") - } - - System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.") - SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.") - - Boundary(b3, "BankBoundary3", "boundary") { - SystemQueue(SystemF, "Banking System F Queue", "A system of the bank, with personal bank accounts.") - SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.") - } -} - -BiRel(customerA, SystemAA, "Uses") -BiRel(SystemAA, SystemE, "Uses") -Rel(SystemAA, SystemC, "Sends e-mails", "SMTP") -Rel(SystemC, customerA, "Sends e-mails to") -``` - -## Release - -For those who have the permission to do so: - -Update version number in `package.json`. - -```sh -npm publish -``` - -The above command generates files into the `dist` folder and publishes them to npmjs.org. - -## Related projects - -- [Command Line Interface](https://github.com/mermaid-js/mermaid-cli) -- [Live Editor](https://github.com/mermaid-js/mermaid-live-editor) -- [HTTP Server](https://github.com/TomWright/mermaid-server) - -## Contributors [![Good first issue](https://img.shields.io/github/labels/mermaid-js/mermaid/Good%20first%20issue%21)](https://github.com/mermaid-js/mermaid/issues?q=is%3Aissue+is%3Aopen+label%3A%22Good+first+issue%21%22) [![Contributors](https://img.shields.io/github/contributors/mermaid-js/mermaid)](https://github.com/mermaid-js/mermaid/graphs/contributors) [![Commits](https://img.shields.io/github/commit-activity/m/mermaid-js/mermaid)](https://github.com/mermaid-js/mermaid/graphs/contributors) - -Mermaid is a growing community and is always accepting new contributors. There's a lot of different ways to help out and we're always looking for extra hands! Look at [this issue](https://github.com/mermaid-js/mermaid/issues/866) if you want to know where to start helping out. - -Detailed information about how to contribute can be found in the [contribution guide](CONTRIBUTING.md) - -## Security and safe diagrams - -For public sites, it can be precarious to retrieve text from users on the internet, storing that content for presentation in a browser at a later stage. The reason is that the user content can contain embedded malicious scripts that will run when the data is presented. For Mermaid this is a risk, specially as mermaid diagrams contain many characters that are used in html which makes the standard sanitation unusable as it also breaks the diagrams. We still make an effort to sanitise the incoming code and keep refining the process but it is hard to guarantee that there are no loop holes. - -As an extra level of security for sites with external users we are happy to introduce a new security level in which the diagram is rendered in a sandboxed iframe preventing javascript in the code from being executed. This is a great step forward for better security. - -_Unfortunately you can not have a cake and eat it at the same time which in this case means that some of the interactive functionality gets blocked along with the possible malicious code._ - -## Reporting vulnerabilities - -To report a vulnerability, please e-mail security@mermaid.live with a description of the issue, the steps you took to create the issue, affected versions, and if known, mitigations for the issue. - -## Appreciation - -A quick note from Knut Sveidqvist: - -> _Many thanks to the [d3](https://d3js.org/) and [dagre-d3](https://github.com/cpettitt/dagre-d3) projects for providing the graphical layout and drawing libraries!_ >_Thanks also to the [js-sequence-diagram](https://bramp.github.io/js-sequence-diagrams) project for usage of the grammar for the sequence diagrams. Thanks to Jessica Peter for inspiration and starting point for gantt rendering._ >_Thank you to [Tyler Long](https://github.com/tylerlong) who has been a collaborator since April 2017._ -> -> _Thank you to the ever-growing list of [contributors](https://github.com/knsv/mermaid/graphs/contributors) that brought the project this far!_ - ---- - -_Mermaid was created by Knut Sveidqvist for easier documentation._ diff --git a/packages/mermaid/README.zh-CN.md b/packages/mermaid/README.zh-CN.md deleted file mode 100644 index 3612ba0a9..000000000 --- a/packages/mermaid/README.zh-CN.md +++ /dev/null @@ -1,334 +0,0 @@ -# mermaid - -[![Build CI Status](https://github.com/mermaid-js/mermaid/actions/workflows/build.yml/badge.svg)](https://github.com/mermaid-js/mermaid/actions/workflows/build.yml) [![NPM](https://img.shields.io/npm/v/mermaid)](https://www.npmjs.com/package/mermaid) [![npm minified gzipped bundle size](https://img.shields.io/bundlephobia/minzip/mermaid)](https://bundlephobia.com/package/mermaid) [![Coverage Status](https://coveralls.io/repos/github/mermaid-js/mermaid/badge.svg?branch=master)](https://coveralls.io/github/mermaid-js/mermaid?branch=master) [![CDN Status](https://img.shields.io/jsdelivr/npm/hm/mermaid)](https://www.jsdelivr.com/package/npm/mermaid) [![NPM](https://img.shields.io/npm/dm/mermaid)](https://www.npmjs.com/package/mermaid) [![Join our Slack!](https://img.shields.io/static/v1?message=join%20chat&color=9cf&logo=slack&label=slack)](https://join.slack.com/t/mermaid-talk/shared_invite/enQtNzc4NDIyNzk4OTAyLWVhYjQxOTI2OTg4YmE1ZmJkY2Y4MTU3ODliYmIwOTY3NDJlYjA0YjIyZTdkMDMyZTUwOGI0NjEzYmEwODcwOTE) [![Twitter Follow](https://img.shields.io/twitter/follow/mermaidjs_?style=social)](https://twitter.com/mermaidjs_) - -[English](./README.md) | 简体中文 - - - -:trophy: **Mermaid 被提名并获得了 [JS Open Source Awards (2019)](https://osawards.com/javascript/2019) 的 "The most exciting use of technology" 奖项!!!** - -**感谢所有参与进来提交 PR,解答疑问的人们! 🙏** - -Explore Mermaid.js in depth, with real-world examples, tips & tricks from the creator... The first official book on Mermaid is available for purchase. Check it out! - -## 关于 Mermaid - - - -Mermaid 是一个基于 Javascript 的图表绘制工具,通过解析类 Markdown 的文本语法来实现图表的创建和动态修改。Mermaid 诞生的主要目的是让文档的更新能够及时跟上开发进度。 - -> Doc-Rot 是 Mermaid 致力于解决的一个难题。 - -绘图和编写文档花费了开发者宝贵的开发时间,而且随着业务的变更,它很快就会过期。 但是如果缺少了图表或文档,对于生产力和团队新人的业务学习都会产生巨大的阻碍。
-Mermaid 通过允许用户创建便于修改的图表来解决这一难题,它也可以作为生产脚本(或其他代码)的一部分。
-
-Mermaid 甚至能让非程序员也能通过 [Mermaid Live Editor](https://mermaid.live/) 轻松创建详细的图表。
-你可以访问 [教程](./docs/Tutorials.md) 来查看 Live Editor 的视频教程,也可以查看 [Mermaid 的集成和使用](./docs/integrations.md) 这个清单来检查你的文档工具是否已经集成了 Mermaid 支持。 - -如果想要查看关于 Mermaid 更详细的介绍及基础使用方式,可以查看 [入门指引](./docs/n00b-overview.md), [用法](./docs/usage.md) 和 [教程](./docs/Tutorials.md). - -🌐 [CDN](https://www.jsdelivr.com/package/npm/mermaid) | 📖 [文档](https://mermaidjs.github.io) | 🙌 [贡献](https://github.com/mermaid-js/mermaid/blob/develop/CONTRIBUTING.md) | 📜 [更新日志](./docs/CHANGELOG.md) - - - -## 示例 - -**下面是一些可以使用 Mermaid 创建的图表示例。点击 [语法](https://mermaid-js.github.io/mermaid/#/n00b-syntaxReference) 查看详情。** - - - - -### 流程图 [文档 - live editor] - -``` -flowchart LR -A[Hard] -->|Text| B(Round) -B --> C{Decision} -C -->|One| D[Result 1] -C -->|Two| E[Result 2] -``` - -```mermaid -flowchart LR -A[Hard] -->|Text| B(Round) -B --> C{Decision} -C -->|One| D[Result 1] -C -->|Two| E[Result 2] -``` - -### 时序图 [文档 - live editor] - -``` -sequenceDiagram -Alice->>John: Hello John, how are you? -loop Healthcheck - John->>John: Fight against hypochondria -end -Note right of John: Rational thoughts! -John-->>Alice: Great! -John->>Bob: How about you? -Bob-->>John: Jolly good! -``` - -```mermaid -sequenceDiagram -Alice->>John: Hello John, how are you? -loop Healthcheck - John->>John: Fight against hypochondria -end -Note right of John: Rational thoughts! -John-->>Alice: Great! -John->>Bob: How about you? -Bob-->>John: Jolly good! -``` - -### 甘特图 [文档 - live editor] - -``` -gantt - section Section - Completed :done, des1, 2014-01-06,2014-01-08 - Active :active, des2, 2014-01-07, 3d - Parallel 1 : des3, after des1, 1d - Parallel 2 : des4, after des1, 1d - Parallel 3 : des5, after des3, 1d - Parallel 4 : des6, after des4, 1d -``` - -```mermaid -gantt - section Section - Completed :done, des1, 2014-01-06,2014-01-08 - Active :active, des2, 2014-01-07, 3d - Parallel 1 : des3, after des1, 1d - Parallel 2 : des4, after des1, 1d - Parallel 3 : des5, after des3, 1d - Parallel 4 : des6, after des4, 1d -``` - -### 类图 [文档 - live editor] - -``` -classDiagram -Class01 <|-- AveryLongClass : Cool -<> Class01 -Class09 --> C2 : Where am I? -Class09 --* C3 -Class09 --|> Class07 -Class07 : equals() -Class07 : Object[] elementData -Class01 : size() -Class01 : int chimp -Class01 : int gorilla -class Class10 { - <> - int id - size() -} -``` - -```mermaid -classDiagram -Class01 <|-- AveryLongClass : Cool -<> Class01 -Class09 --> C2 : Where am I? -Class09 --* C3 -Class09 --|> Class07 -Class07 : equals() -Class07 : Object[] elementData -Class01 : size() -Class01 : int chimp -Class01 : int gorilla -class Class10 { - <> - int id - size() -} -``` - -### 状态图 [[docs - live editor] - -``` -stateDiagram-v2 -[*] --> Still -Still --> [*] -Still --> Moving -Moving --> Still -Moving --> Crash -Crash --> [*] -``` - -```mermaid -stateDiagram-v2 -[*] --> Still -Still --> [*] -Still --> Moving -Moving --> Still -Moving --> Crash -Crash --> [*] -``` - -### 饼图 [文档 - live editor] - -``` -pie -"Dogs" : 386 -"Cats" : 85 -"Rats" : 15 -``` - -```mermaid -pie -"Dogs" : 386 -"Cats" : 85 -"Rats" : 15 -``` - -### Git 图 [实验特性 - live editor] - -### 用户体验旅程图 [文档 - live editor] - -``` - journey - title My working day - section Go to work - Make tea: 5: Me - Go upstairs: 3: Me - Do work: 1: Me, Cat - section Go home - Go downstairs: 5: Me - Sit down: 3: Me -``` - -```mermaid - journey - title My working day - section Go to work - Make tea: 5: Me - Go upstairs: 3: Me - Do work: 1: Me, Cat - section Go home - Go downstairs: 5: Me - Sit down: 3: Me -``` - -### C4 图 [文档] - -``` -C4Context -title System Context diagram for Internet Banking System - -Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.") -Person(customerB, "Banking Customer B") -Person_Ext(customerC, "Banking Customer C") -System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.") - -Person(customerD, "Banking Customer D", "A customer of the bank,
with personal bank accounts.") - -Enterprise_Boundary(b1, "BankBoundary") { - - SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.") - - System_Boundary(b2, "BankBoundary2") { - System(SystemA, "Banking System A") - System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts.") - } - - System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.") - SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.") - - Boundary(b3, "BankBoundary3", "boundary") { - SystemQueue(SystemF, "Banking System F Queue", "A system of the bank, with personal bank accounts.") - SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.") - } -} - -BiRel(customerA, SystemAA, "Uses") -BiRel(SystemAA, SystemE, "Uses") -Rel(SystemAA, SystemC, "Sends e-mails", "SMTP") -Rel(SystemC, customerA, "Sends e-mails to") -``` - -```mermaid -C4Context -title System Context diagram for Internet Banking System - -Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.") -Person(customerB, "Banking Customer B") -Person_Ext(customerC, "Banking Customer C") -System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.") - -Person(customerD, "Banking Customer D", "A customer of the bank,
with personal bank accounts.") - -Enterprise_Boundary(b1, "BankBoundary") { - - SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.") - - System_Boundary(b2, "BankBoundary2") { - System(SystemA, "Banking System A") - System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts.") - } - - System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.") - SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.") - - Boundary(b3, "BankBoundary3", "boundary") { - SystemQueue(SystemF, "Banking System F Queue", "A system of the bank, with personal bank accounts.") - SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.") - } -} - -BiRel(customerA, SystemAA, "Uses") -BiRel(SystemAA, SystemE, "Uses") -Rel(SystemAA, SystemC, "Sends e-mails", "SMTP") -Rel(SystemC, customerA, "Sends e-mails to") -``` - -## 发布 - -对于有权限的同学来说,你可以通过以下步骤来完成发布操作: - -更新 `package.json` 中的版本号,然后执行如下命令: - -```sh -npm publish -``` - -以上的命令会将文件打包到 `dist` 目录并发布至 npmjs.org. - -## 相关项目 - -- [Command Line Interface](https://github.com/mermaid-js/mermaid-cli) -- [Live Editor](https://github.com/mermaid-js/mermaid-live-editor) -- [HTTP Server](https://github.com/TomWright/mermaid-server) - -## 贡献者 [![Good first issue](https://img.shields.io/github/labels/mermaid-js/mermaid/Good%20first%20issue%21)](https://github.com/mermaid-js/mermaid/issues?q=is%3Aissue+is%3Aopen+label%3A%22Good+first+issue%21%22) [![Contributors](https://img.shields.io/github/contributors/mermaid-js/mermaid)](https://github.com/mermaid-js/mermaid/graphs/contributors) [![Commits](https://img.shields.io/github/commit-activity/m/mermaid-js/mermaid)](https://github.com/mermaid-js/mermaid/graphs/contributors) - -Mermaid 是一个不断发展中的社区,并且还在接收新的贡献者。有很多不同的方式可以参与进来,而且我们还在寻找额外的帮助。如果你想知道如何开始贡献,请查看 [这个 issue](https://github.com/mermaid-js/mermaid/issues/866)。 - -关于如何贡献的详细信息可以在 [贡献指南](CONTRIBUTING.md) 中找到。 - -## 安全 - -对于公开网站来说,从互联网上的用户处检索文本、存储供后续在浏览器中展示的内容可能是不安全的,理由是用户的内容可能嵌入一些数据加载完成之后就会运行的恶意脚本,这些对于 Mermaid 来说毫无疑问是一个风险,尤其是 mermaid 图表还包含了许多在 html 中使用的字符,这意味着我们难以使用常规的手段来过滤不安全代码,因为这些常规手段会造成图表损坏。我们仍然在努力对获取到的代码进行安全过滤并不断完善我们的程序,但很难保证没有漏洞。 - -作为拥有外部用户的网站的额外安全级别,我们很高兴推出一个新的安全级别,其中的图表在沙盒 iframe 中渲染,防止代码中的 javascript 被执行,这是在安全性方面迈出的一大步。 - -_很不幸的是,鱼与熊掌不可兼得,在这个场景下它意味着在可能的恶意代码被阻止时,也会损失部分交互能力_。 - -## 报告漏洞 - -如果想要报告漏洞,请发送邮件到 security@mermaid.live, 并附上问题的描述、复现问题的步骤、受影响的版本,以及解决问题的方案(如果有的话)。 - -## 鸣谢 - -来自 Knut Sveidqvist: - -> _特别感谢 [d3](https://d3js.org/) 和 [dagre-d3](https://github.com/cpettitt/dagre-d3) 这两个优秀的项目,它们提供了图形布局和绘图工具库! _ >_同样感谢 [js-sequence-diagram](https://bramp.github.io/js-sequence-diagrams) 提供了时序图语法的使用。 感谢 Jessica Peter 提供了甘特图渲染的灵感。_ >_感谢 [Tyler Long](https://github.com/tylerlong) 从 2017 年四月开始成为了项目的合作者。_ -> -> _感谢越来越多的 [贡献者们](https://github.com/knsv/mermaid/graphs/contributors),没有你们,就没有这个项目的今天!_ - ---- - -_Mermaid 是由 Knut Sveidqvist 创建,它为了更简单的文档编写而生。_ From 6ded32880d023527756cb88e824177890a50896b Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Mon, 20 Feb 2023 18:24:24 +0530 Subject: [PATCH 02/13] Fix lockfile --- pnpm-lock.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4275d10fc..d35d9fe7a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4214,7 +4214,7 @@ packages: /axios/0.21.4_debug@4.3.2: resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==} dependencies: - follow-redirects: 1.15.2 + follow-redirects: 1.15.2_debug@4.3.4 transitivePeerDependencies: - debug dev: true @@ -4222,7 +4222,7 @@ packages: /axios/0.27.2_debug@4.3.4: resolution: {integrity: sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==} dependencies: - follow-redirects: 1.15.2_debug@4.3.2 + follow-redirects: 1.15.2_debug@4.3.4 form-data: 4.0.0 transitivePeerDependencies: - debug @@ -6779,7 +6779,7 @@ packages: resolution: {integrity: sha512-XGozTsMPYkm+6b5QL3Z9wQcJjNYxp0CYn3U1gO7dwD6PAqU1SVWZxI9CCg3z+ml3YfqdPnrBehaBrnH2AGKbNA==} dev: true - /follow-redirects/1.15.2: + /follow-redirects/1.15.2_debug@4.3.4: resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==} engines: {node: '>=4.0'} peerDependencies: @@ -6787,6 +6787,8 @@ packages: peerDependenciesMeta: debug: optional: true + dependencies: + debug: 4.3.4 dev: true /foreground-child/2.0.0: @@ -7326,7 +7328,7 @@ packages: engines: {node: '>=8.0.0'} dependencies: eventemitter3: 4.0.7 - follow-redirects: 1.15.2 + follow-redirects: 1.15.2_debug@4.3.4 requires-port: 1.0.0 transitivePeerDependencies: - debug From a8162634cdf0f0b5144182cabb7dcb94371d7ef4 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 19 Feb 2023 14:18:09 +0530 Subject: [PATCH 03/13] fix Server --- .vite/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vite/server.ts b/.vite/server.ts index 0f1fef91d..055b931cf 100644 --- a/.vite/server.ts +++ b/.vite/server.ts @@ -19,7 +19,7 @@ async function createServer() { appType: 'custom', // don't include Vite's default HTML handling middlewares }); - app.use(cors); + app.use(cors()); app.use(express.static('./packages/mermaid/dist')); // app.use(express.static('./packages/mermaid-example-diagram/dist')); app.use(express.static('./packages/mermaid-example-diagram/dist')); From 067b6adc20396235dcd4fa0442986115fba4baad Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Mon, 20 Feb 2023 21:23:06 +0530 Subject: [PATCH 04/13] fix(E2E): Add cors package --- .vite/server.ts | 13 +++---------- package.json | 4 +++- pnpm-lock.yaml | 48 +++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/.vite/server.ts b/.vite/server.ts index 055b931cf..569d20135 100644 --- a/.vite/server.ts +++ b/.vite/server.ts @@ -1,14 +1,7 @@ -import express, { NextFunction, Request, Response } from 'express'; +import express from 'express'; +import cors from 'cors'; import { createServer as createViteServer } from 'vite'; -const cors = (req: Request, res: Response, next: NextFunction) => { - res.header('Access-Control-Allow-Origin', '*'); - res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); - res.header('Access-Control-Allow-Headers', 'Content-Type'); - - next(); -}; - async function createServer() { const app = express(); @@ -16,7 +9,7 @@ async function createServer() { const vite = await createViteServer({ configFile: './vite.config.ts', server: { middlewareMode: true }, - appType: 'custom', // don't include Vite's default HTML handling middlewares + appType: 'custom', // don't include Vite's default HTML handling middleware }); app.use(cors()); diff --git a/package.json b/package.json index ddbb61381..8e4c50118 100644 --- a/package.json +++ b/package.json @@ -58,8 +58,9 @@ "@commitlint/cli": "^17.2.0", "@commitlint/config-conventional": "^17.2.0", "@cspell/eslint-plugin": "^6.14.2", + "@types/cors": "^2.8.13", "@types/eslint": "^8.4.10", - "@types/express": "^4.17.14", + "@types/express": "^4.17.17", "@types/js-yaml": "^4.0.5", "@types/jsdom": "^21.0.0", "@types/lodash": "^4.14.188", @@ -73,6 +74,7 @@ "@vitest/spy": "^0.28.4", "@vitest/ui": "^0.28.4", "concurrently": "^7.5.0", + "cors": "^2.8.5", "coveralls": "^3.1.1", "cypress": "^12.0.0", "cypress-image-snapshot": "^4.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d35d9fe7a..376f4532e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,12 +16,15 @@ importers: '@cspell/eslint-plugin': specifier: ^6.14.2 version: 6.14.2 + '@types/cors': + specifier: ^2.8.13 + version: 2.8.13 '@types/eslint': specifier: ^8.4.10 version: 8.4.10 '@types/express': - specifier: ^4.17.14 - version: 4.17.14 + specifier: ^4.17.17 + version: 4.17.17 '@types/js-yaml': specifier: ^4.0.5 version: 4.0.5 @@ -61,6 +64,9 @@ importers: concurrently: specifier: ^7.5.0 version: 7.5.0 + cors: + specifier: ^2.8.5 + version: 2.8.5 coveralls: specifier: ^3.1.1 version: 3.1.1 @@ -2640,7 +2646,7 @@ packages: /@types/connect-history-api-fallback/1.3.5: resolution: {integrity: sha512-h8QJa8xSb1WD4fpKBDcATDNGXghFj6/3GRWG6dhmRcu0RX1Ubasur2Uvx5aeEwlf0MwblEC2bMzzMQntxnw/Cw==} dependencies: - '@types/express-serve-static-core': 4.17.31 + '@types/express-serve-static-core': 4.17.33 '@types/node': 18.11.9 dev: true @@ -2650,6 +2656,12 @@ packages: '@types/node': 18.11.9 dev: true + /@types/cors/2.8.13: + resolution: {integrity: sha512-RG8AStHlUiV5ysZQKq97copd2UmVYw3/pRMLefISZ3S1hK104Cwm7iLQ3fTKx+lsUH2CE8FlLaYeEA2LSeqYUA==} + dependencies: + '@types/node': 18.11.9 + dev: true + /@types/cytoscape/3.19.9: resolution: {integrity: sha512-oqCx0ZGiBO0UESbjgq052vjDAy2X53lZpMrWqiweMpvVwKw/2IiYDdzPFK6+f4tMfdv9YKEM9raO5bAZc3UYBg==} dev: true @@ -2867,8 +2879,8 @@ packages: resolution: {integrity: sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==} dev: true - /@types/express-serve-static-core/4.17.31: - resolution: {integrity: sha512-DxMhY+NAsTwMMFHBTtJFNp5qiHKJ7TeqOo23zVEM9alT1Ml27Q3xcTH0xwxn7Q0BbMcVEJOs/7aQtUWupUQN3Q==} + /@types/express-serve-static-core/4.17.33: + resolution: {integrity: sha512-TPBqmR/HRYI3eC2E5hmiivIzv+bidAfXofM+sbonAGvyDhySGw9/PQZFt2BLOrjUUR++4eJVpx6KnLQK1Fk9tA==} dependencies: '@types/node': 18.11.9 '@types/qs': 6.9.7 @@ -2879,7 +2891,16 @@ packages: resolution: {integrity: sha512-TEbt+vaPFQ+xpxFLFssxUDXj5cWCxZJjIcB7Yg0k0GMHGtgtQgpvx/MUQUeAkNbA9AAGrwkAsoeItdTgS7FMyg==} dependencies: '@types/body-parser': 1.19.2 - '@types/express-serve-static-core': 4.17.31 + '@types/express-serve-static-core': 4.17.33 + '@types/qs': 6.9.7 + '@types/serve-static': 1.15.0 + dev: true + + /@types/express/4.17.17: + resolution: {integrity: sha512-Q4FmmuLGBG58btUnfS1c1r/NQdlp3DMfGDGig8WhfpA2YRUtEkxAjkZb0yvplJGYdF1fsQ81iMDcH24sSCNC/Q==} + dependencies: + '@types/body-parser': 1.19.2 + '@types/express-serve-static-core': 4.17.33 '@types/qs': 6.9.7 '@types/serve-static': 1.15.0 dev: true @@ -3058,7 +3079,7 @@ packages: /@types/serve-index/1.9.1: resolution: {integrity: sha512-d/Hs3nWDxNL2xAczmOVZNj92YZCS6RGxfBPjKzuu/XirCgXdpKEb88dYNbrYGint6IVWLNP+yonwVAuRC0T2Dg==} dependencies: - '@types/express': 4.17.14 + '@types/express': 4.17.17 dev: true /@types/serve-static/1.15.0: @@ -4965,6 +4986,14 @@ packages: resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==} dev: true + /cors/2.8.5: + resolution: {integrity: sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==} + engines: {node: '>= 0.10'} + dependencies: + object-assign: 4.1.1 + vary: 1.1.2 + dev: true + /cose-base/1.0.3: resolution: {integrity: sha512-s9whTXInMSgAp/NVXVNuVxVKzGH2qck3aQlVHxDCdAEPgtMKwc4Wq6/QKhgdEdgbLSi9rBTAcPoRa6JpiG4ksg==} dependencies: @@ -9466,6 +9495,11 @@ packages: resolution: {integrity: sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==} dev: true + /object-assign/4.1.1: + resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} + engines: {node: '>=0.10.0'} + dev: true + /object-inspect/1.12.2: resolution: {integrity: sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==} dev: true From 704506835ffca9bafa8670576e8f4dd1db25984a Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Thu, 16 Feb 2023 20:17:57 +0000 Subject: [PATCH 05/13] refactor(deps): replace `moment` with `dayjs` Replace Mermaid's dependency on `moment` with `dayjs`. [Moment is now in maintenance mode][1], and they don't recommend using it. [Dayjs][2] has almost exactly the same API as moment, and is still curently being maintained. Unlike moment, dayjs objects are immutable, which makes our life much easier, but we need to do `a = a.add(1, "day")` instead of just `a.add(1, "day")`. We can't use `dayjs.duration`, because unlike `moment.duration`, [dayjs durations always degrade to ms][3]. This causes issues with daylight savings, since it assumes that each day is 24 hours, when some days have 23/25 hours with daylight savings. (it also assumes that each month is 30 days). However, `dayjs.add(1, "d");` correctly adds 1 days, even when that day is only 23 hours long, so we can use that instead. [1]: https://momentjs.com/docs/#/-project-status/ [2]: https://day.js.org/ [3]: https://day.js.org/docs/en/durations/durations Co-authored-by: Alois Klink --- docs/syntax/gantt.md | 4 +- packages/mermaid/package.json | 4 +- .../mermaid/src/diagrams/gantt/ganttDb.js | 99 ++++++++--- .../src/diagrams/gantt/ganttDb.spec.ts | 138 +++++++-------- .../src/diagrams/gantt/ganttRenderer.js | 14 +- packages/mermaid/src/docs/syntax/gantt.md | 4 +- packages/mermaid/src/logger.ts | 4 +- packages/mermaid/src/tests/util.ts | 8 +- pnpm-lock.yaml | 164 ++++++------------ 9 files changed, 212 insertions(+), 227 deletions(-) diff --git a/docs/syntax/gantt.md b/docs/syntax/gantt.md index 8e9ad3cfd..6a7af3331 100644 --- a/docs/syntax/gantt.md +++ b/docs/syntax/gantt.md @@ -184,7 +184,7 @@ The following formatting options are supported: | `YY` | 14 | 2 digit year | | `Q` | 1..4 | Quarter of year. Sets month to first month in quarter. | | `M MM` | 1..12 | Month number | -| `MMM MMMM` | January..Dec | Month name in locale set by `moment.locale()` | +| `MMM MMMM` | January..Dec | Month name in locale set by `dayjs.locale()` | | `D DD` | 1..31 | Day of month | | `Do` | 1st..31st | Day of month with ordinal | | `DDD DDDD` | 1..365 | Day of year | @@ -200,7 +200,7 @@ The following formatting options are supported: | `SSS` | 0..999 | Thousandths of a second | | `Z ZZ` | +12:00 | Offset from UTC as +-HH:mm, +-HHmm, or Z | -More info in: +More info in: ### Output date format on the axis diff --git a/packages/mermaid/package.json b/packages/mermaid/package.json index 08b6a57ac..4a928d6df 100644 --- a/packages/mermaid/package.json +++ b/packages/mermaid/package.json @@ -57,12 +57,12 @@ "cytoscape-cose-bilkent": "^4.1.0", "cytoscape-fcose": "^2.1.0", "d3": "^7.4.0", - "dagre-d3-es": "7.0.8", + "dagre-d3-es": "7.0.9", + "dayjs": "^1.11.7", "dompurify": "2.4.3", "elkjs": "^0.8.2", "khroma": "^2.0.0", "lodash-es": "^4.17.21", - "moment-mini": "^2.29.4", "non-layered-tidy-tree-layout": "^2.0.2", "stylis": "^4.1.2", "ts-dedent": "^2.2.0", diff --git a/packages/mermaid/src/diagrams/gantt/ganttDb.js b/packages/mermaid/src/diagrams/gantt/ganttDb.js index a1c74dd62..27ad1a0b8 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttDb.js +++ b/packages/mermaid/src/diagrams/gantt/ganttDb.js @@ -1,5 +1,8 @@ -import moment from 'moment-mini'; import { sanitizeUrl } from '@braintree/sanitize-url'; +import dayjs from 'dayjs'; +import dayjsIsoWeek from 'dayjs/plugin/isoWeek'; +import dayjsCustomParseFormat from 'dayjs/plugin/customParseFormat'; +import dayjsAdvancedFormat from 'dayjs/plugin/advancedFormat'; import { log } from '../../logger'; import * as configApi from '../../config'; import utils from '../../utils'; @@ -15,6 +18,10 @@ import { getDiagramTitle, } from '../../commonDb'; +dayjs.extend(dayjsIsoWeek); +dayjs.extend(dayjsCustomParseFormat); +dayjs.extend(dayjsAdvancedFormat); + let dateFormat = ''; let axisFormat = ''; let tickInterval = undefined; @@ -162,18 +169,58 @@ export const isInvalidDate = function (date, dateFormat, excludes, includes) { return excludes.includes(date.format(dateFormat.trim())); }; +/** + * TODO: fully document what this function does and what types it accepts + * + * @param {object} task - The task to check. + * @param {string | Date} task.startTime - Might be a `Date` or a `string`. + * TODO: is this always a Date? + * @param {string | Date} task.endTime - Might be a `Date` or a `string`. + * TODO: is this always a Date? + * @param {string} dateFormat - Dayjs date format string. + * @param {*} excludes + * @param {*} includes + */ const checkTaskDates = function (task, dateFormat, excludes, includes) { if (!excludes.length || task.manualEndTime) { return; } - let startTime = moment(task.startTime, dateFormat, true); - startTime.add(1, 'd'); - let endTime = moment(task.endTime, dateFormat, true); - let renderEndTime = fixTaskDates(startTime, endTime, dateFormat, excludes, includes); - task.endTime = endTime.toDate(); + let startTime; + if (task.startTime instanceof Date) { + startTime = dayjs(task.startTime); + } else { + startTime = dayjs(task.startTime, dateFormat, true); + } + startTime = startTime.add(1, 'd'); + + let originalEndTime; + if (task.endTime instanceof Date) { + originalEndTime = dayjs(task.endTime); + } else { + originalEndTime = dayjs(task.endTime, dateFormat, true); + } + const [fixedEndTime, renderEndTime] = fixTaskDates( + startTime, + originalEndTime, + dateFormat, + excludes, + includes + ); + task.endTime = fixedEndTime.toDate(); task.renderEndTime = renderEndTime; }; +/** + * TODO: what does this function do? + * + * @param {dayjs.Dayjs} startTime - The start time. + * @param {dayjs.Dayjs} endTime - The original end time (will return a different end time if it's invalid). + * @param {string} dateFormat - Dayjs date format string. + * @param {*} excludes + * @param {*} includes + * @returns {[endTime: dayjs.Dayjs, renderEndTime: Date | null]} The new `endTime`, and the end time to render. + * `renderEndTime` may be `null` if `startTime` is newer than `endTime`. + */ const fixTaskDates = function (startTime, endTime, dateFormat, excludes, includes) { let invalid = false; let renderEndTime = null; @@ -183,11 +230,11 @@ const fixTaskDates = function (startTime, endTime, dateFormat, excludes, include } invalid = isInvalidDate(startTime, dateFormat, excludes, includes); if (invalid) { - endTime.add(1, 'd'); + endTime = endTime.add(1, 'd'); } - startTime.add(1, 'd'); + startTime = startTime.add(1, 'd'); } - return renderEndTime; + return [endTime, renderEndTime]; }; const getStartDate = function (prevTime, dateFormat, str) { @@ -223,7 +270,7 @@ const getStartDate = function (prevTime, dateFormat, str) { } // Check for actual date set - let mDate = moment(str, dateFormat.trim(), true); + let mDate = dayjs(str, dateFormat.trim(), true); if (mDate.isValid()) { return mDate.toDate(); } else { @@ -238,11 +285,14 @@ const getStartDate = function (prevTime, dateFormat, str) { }; /** - * Parse a string as a moment duration. + * Parse a string into the args for `dayjs.add()`. * * The string have to be compound by a value and a shorthand duration unit. For example `5d` * represents 5 days. * + * Please be aware that 1 day may be 23 or 25 hours, if the user lives in an area + * that has daylight savings time (or even 23.5/24.5 hours in Lord Howe Island!) + * * Shorthand unit supported are: * * - `y` for years @@ -254,33 +304,36 @@ const getStartDate = function (prevTime, dateFormat, str) { * - `ms` for milliseconds * * @param {string} str - A string representing the duration. - * @returns {moment.Duration} A moment duration, including an invalid moment for invalid input - * string. + * @returns {[value: number, unit: dayjs.ManipulateType]} Arguments to pass to `dayjs.add()` */ const parseDuration = function (str) { const statement = /^(\d+(?:\.\d+)?)([Mdhmswy]|ms)$/.exec(str.trim()); if (statement !== null) { - return moment.duration(Number.parseFloat(statement[1]), statement[2]); + return [Number.parseFloat(statement[1]), statement[2]]; } - return moment.duration.invalid(); + // NaN means an invalid duration + return [NaN, 'ms']; }; const getEndDate = function (prevTime, dateFormat, str, inclusive = false) { str = str.trim(); // Check for actual date - let mDate = moment(str, dateFormat.trim(), true); + let mDate = dayjs(str, dateFormat.trim(), true); if (mDate.isValid()) { if (inclusive) { - mDate.add(1, 'd'); + mDate = mDate.add(1, 'd'); } return mDate.toDate(); } - const endTime = moment(prevTime); - const duration = parseDuration(str); - if (duration.isValid()) { - endTime.add(duration); + let endTime = dayjs(prevTime); + const [durationValue, durationUnit] = parseDuration(str); + if (!Number.isNaN(durationValue)) { + const newEndTime = endTime.add(durationValue, durationUnit); + if (newEndTime.isValid()) { + endTime = newEndTime; + } } return endTime.toDate(); }; @@ -346,7 +399,7 @@ const compileData = function (prevTask, dataStr) { if (endTimeData) { task.endTime = getEndDate(task.startTime, dateFormat, endTimeData, inclusiveEndDates); - task.manualEndTime = moment(endTimeData, 'YYYY-MM-DD', true).isValid(); + task.manualEndTime = dayjs(endTimeData, 'YYYY-MM-DD', true).isValid(); checkTaskDates(task, dateFormat, excludes, includes); } @@ -496,7 +549,7 @@ const compileTasks = function () { ); if (rawTasks[pos].endTime) { rawTasks[pos].processed = true; - rawTasks[pos].manualEndTime = moment( + rawTasks[pos].manualEndTime = dayjs( rawTasks[pos].raw.endTime.data, 'YYYY-MM-DD', true diff --git a/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts b/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts index 09df96f12..dadcdcc40 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts +++ b/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts @@ -1,5 +1,5 @@ // @ts-nocheck TODO: Fix TS -import moment from 'moment-mini'; +import dayjs from 'dayjs'; import ganttDb from './ganttDb'; import { convert } from '../../tests/util'; @@ -9,7 +9,7 @@ describe('when using the ganttDb', function () { }); describe('when using duration', function () { - it.each([{ str: '1d', expected: moment.duration(1, 'd') }])( + it.each([{ str: '1d', expected: [1, 'd'] }])( 'should %s resulting in $o duration', ({ str, expected }) => { expect(ganttDb.parseDuration(str)).toEqual(expected); @@ -19,11 +19,11 @@ describe('when using the ganttDb', function () { it.each( convert` str | expected - ${'1d'} | ${moment.duration(1, 'd')} - ${'2w'} | ${moment.duration(2, 'w')} - ${'1ms'} | ${moment.duration(1, 'ms')} - ${'0.1s'} | ${moment.duration(100, 'ms')} - ${'1f'} | ${moment.duration.invalid()} + ${'1d'} | ${[1, 'd']} + ${'2w'} | ${[2, 'w']} + ${'1ms'} | ${[1, 'ms']} + ${'0.1s'} | ${[0.1, 's']} + ${'1f'} | ${[NaN, 'ms']} ` )('should $str resulting in $expected duration', ({ str, expected }) => { expect(ganttDb.parseDuration(str)).toEqual(expected); @@ -171,44 +171,44 @@ describe('when using the ganttDb', function () { const tasks = ganttDb.getTasks(); - expect(tasks[0].startTime).toEqual(moment('2019-02-01', 'YYYY-MM-DD').toDate()); - expect(tasks[0].endTime).toEqual(moment('2019-02-04', 'YYYY-MM-DD').toDate()); - expect(tasks[0].renderEndTime).toEqual(moment('2019-02-02', 'YYYY-MM-DD').toDate()); + expect(tasks[0].startTime).toEqual(dayjs('2019-02-01', 'YYYY-MM-DD').toDate()); + expect(tasks[0].endTime).toEqual(dayjs('2019-02-04', 'YYYY-MM-DD').toDate()); + expect(tasks[0].renderEndTime).toEqual(dayjs('2019-02-02', 'YYYY-MM-DD').toDate()); expect(tasks[0].id).toEqual('id1'); expect(tasks[0].task).toEqual('test1'); - expect(tasks[1].startTime).toEqual(moment('2019-02-04', 'YYYY-MM-DD').toDate()); - expect(tasks[1].endTime).toEqual(moment('2019-02-07', 'YYYY-MM-DD').toDate()); - expect(tasks[1].renderEndTime).toEqual(moment('2019-02-06', 'YYYY-MM-DD').toDate()); + expect(tasks[1].startTime).toEqual(dayjs('2019-02-04', 'YYYY-MM-DD').toDate()); + expect(tasks[1].endTime).toEqual(dayjs('2019-02-07', 'YYYY-MM-DD').toDate()); + expect(tasks[1].renderEndTime).toEqual(dayjs('2019-02-06', 'YYYY-MM-DD').toDate()); expect(tasks[1].id).toEqual('id2'); expect(tasks[1].task).toEqual('test2'); - expect(tasks[2].startTime).toEqual(moment('2019-02-07', 'YYYY-MM-DD').toDate()); - expect(tasks[2].endTime).toEqual(moment('2019-02-20', 'YYYY-MM-DD').toDate()); - expect(tasks[2].renderEndTime).toEqual(moment('2019-02-20', 'YYYY-MM-DD').toDate()); + expect(tasks[2].startTime).toEqual(dayjs('2019-02-07', 'YYYY-MM-DD').toDate()); + expect(tasks[2].endTime).toEqual(dayjs('2019-02-20', 'YYYY-MM-DD').toDate()); + expect(tasks[2].renderEndTime).toEqual(dayjs('2019-02-20', 'YYYY-MM-DD').toDate()); expect(tasks[2].id).toEqual('id3'); expect(tasks[2].task).toEqual('test3'); - expect(tasks[3].startTime).toEqual(moment('2019-02-01', 'YYYY-MM-DD').toDate()); - expect(tasks[3].endTime).toEqual(moment('2019-02-20', 'YYYY-MM-DD').toDate()); + expect(tasks[3].startTime).toEqual(dayjs('2019-02-01', 'YYYY-MM-DD').toDate()); + expect(tasks[3].endTime).toEqual(dayjs('2019-02-20', 'YYYY-MM-DD').toDate()); expect(tasks[3].renderEndTime).toBeNull(); // Fixed end expect(tasks[3].id).toEqual('id4'); expect(tasks[3].task).toEqual('test4'); - expect(tasks[4].startTime).toEqual(moment('2019-02-20', 'YYYY-MM-DD').toDate()); - expect(tasks[4].endTime).toEqual(moment('2019-02-21', 'YYYY-MM-DD').toDate()); - expect(tasks[4].renderEndTime).toEqual(moment('2019-02-21', 'YYYY-MM-DD').toDate()); + expect(tasks[4].startTime).toEqual(dayjs('2019-02-20', 'YYYY-MM-DD').toDate()); + expect(tasks[4].endTime).toEqual(dayjs('2019-02-21', 'YYYY-MM-DD').toDate()); + expect(tasks[4].renderEndTime).toEqual(dayjs('2019-02-21', 'YYYY-MM-DD').toDate()); expect(tasks[4].id).toEqual('id5'); expect(tasks[4].task).toEqual('test5'); - expect(tasks[5].startTime).toEqual(moment('2019-02-13', 'YYYY-MM-DD').toDate()); - expect(tasks[5].endTime).toEqual(moment('2019-02-18', 'YYYY-MM-DD').toDate()); - expect(tasks[5].renderEndTime).toEqual(moment('2019-02-15', 'YYYY-MM-DD').toDate()); + expect(tasks[5].startTime).toEqual(dayjs('2019-02-13', 'YYYY-MM-DD').toDate()); + expect(tasks[5].endTime).toEqual(dayjs('2019-02-18', 'YYYY-MM-DD').toDate()); + expect(tasks[5].renderEndTime).toEqual(dayjs('2019-02-15', 'YYYY-MM-DD').toDate()); expect(tasks[5].id).toEqual('id6'); expect(tasks[5].task).toEqual('test6'); - expect(tasks[6].startTime).toEqual(moment('2019-02-18', 'YYYY-MM-DD').toDate()); - expect(tasks[6].endTime).toEqual(moment('2019-02-19', 'YYYY-MM-DD').toDate()); + expect(tasks[6].startTime).toEqual(dayjs('2019-02-18', 'YYYY-MM-DD').toDate()); + expect(tasks[6].endTime).toEqual(dayjs('2019-02-19', 'YYYY-MM-DD').toDate()); expect(tasks[6].id).toEqual('id7'); expect(tasks[6].task).toEqual('test7'); }); @@ -243,109 +243,103 @@ describe('when using the ganttDb', function () { const tasks = ganttDb.getTasks(); // Section - A section - expect(tasks[0].startTime).toEqual(moment('2014-01-06', 'YYYY-MM-DD').toDate()); - expect(tasks[0].endTime).toEqual(moment('2014-01-08', 'YYYY-MM-DD').toDate()); + expect(tasks[0].startTime).toEqual(dayjs('2014-01-06', 'YYYY-MM-DD').toDate()); + expect(tasks[0].endTime).toEqual(dayjs('2014-01-08', 'YYYY-MM-DD').toDate()); expect(tasks[0].order).toEqual(0); expect(tasks[0].id).toEqual('des1'); expect(tasks[0].task).toEqual('Completed task'); - expect(tasks[1].startTime).toEqual(moment('2014-01-09', 'YYYY-MM-DD').toDate()); - expect(tasks[1].endTime).toEqual(moment('2014-01-12', 'YYYY-MM-DD').toDate()); + expect(tasks[1].startTime).toEqual(dayjs('2014-01-09', 'YYYY-MM-DD').toDate()); + expect(tasks[1].endTime).toEqual(dayjs('2014-01-12', 'YYYY-MM-DD').toDate()); expect(tasks[1].order).toEqual(1); expect(tasks[1].id).toEqual('des2'); expect(tasks[1].task).toEqual('Active task'); - expect(tasks[2].startTime).toEqual(moment('2014-01-12', 'YYYY-MM-DD').toDate()); - expect(tasks[2].endTime).toEqual(moment('2014-01-17', 'YYYY-MM-DD').toDate()); + expect(tasks[2].startTime).toEqual(dayjs('2014-01-12', 'YYYY-MM-DD').toDate()); + expect(tasks[2].endTime).toEqual(dayjs('2014-01-17', 'YYYY-MM-DD').toDate()); expect(tasks[2].order).toEqual(2); expect(tasks[2].id).toEqual('des3'); expect(tasks[2].task).toEqual('Future task'); - expect(tasks[3].startTime).toEqual(moment('2014-01-17', 'YYYY-MM-DD').toDate()); - expect(tasks[3].endTime).toEqual(moment('2014-01-22', 'YYYY-MM-DD').toDate()); + expect(tasks[3].startTime).toEqual(dayjs('2014-01-17', 'YYYY-MM-DD').toDate()); + expect(tasks[3].endTime).toEqual(dayjs('2014-01-22', 'YYYY-MM-DD').toDate()); expect(tasks[3].order).toEqual(3); expect(tasks[3].id).toEqual('des4'); expect(tasks[3].task).toEqual('Future task2'); // Section - Critical tasks - expect(tasks[4].startTime).toEqual(moment('2014-01-06', 'YYYY-MM-DD').toDate()); - expect(tasks[4].endTime).toEqual(moment('2014-01-07', 'YYYY-MM-DD').toDate()); + expect(tasks[4].startTime).toEqual(dayjs('2014-01-06', 'YYYY-MM-DD').toDate()); + expect(tasks[4].endTime).toEqual(dayjs('2014-01-07', 'YYYY-MM-DD').toDate()); expect(tasks[4].order).toEqual(4); expect(tasks[4].id).toEqual('task1'); expect(tasks[4].task).toEqual('Completed task in the critical line'); - expect(tasks[5].startTime).toEqual(moment('2014-01-08', 'YYYY-MM-DD').toDate()); - expect(tasks[5].endTime).toEqual(moment('2014-01-10', 'YYYY-MM-DD').toDate()); + expect(tasks[5].startTime).toEqual(dayjs('2014-01-08', 'YYYY-MM-DD').toDate()); + expect(tasks[5].endTime).toEqual(dayjs('2014-01-10', 'YYYY-MM-DD').toDate()); expect(tasks[5].order).toEqual(5); expect(tasks[5].id).toEqual('task2'); expect(tasks[5].task).toEqual('Implement parser and jison'); - expect(tasks[6].startTime).toEqual(moment('2014-01-10', 'YYYY-MM-DD').toDate()); - expect(tasks[6].endTime).toEqual(moment('2014-01-13', 'YYYY-MM-DD').toDate()); + expect(tasks[6].startTime).toEqual(dayjs('2014-01-10', 'YYYY-MM-DD').toDate()); + expect(tasks[6].endTime).toEqual(dayjs('2014-01-13', 'YYYY-MM-DD').toDate()); expect(tasks[6].order).toEqual(6); expect(tasks[6].id).toEqual('task3'); expect(tasks[6].task).toEqual('Create tests for parser'); - expect(tasks[7].startTime).toEqual(moment('2014-01-13', 'YYYY-MM-DD').toDate()); - expect(tasks[7].endTime).toEqual(moment('2014-01-18', 'YYYY-MM-DD').toDate()); + expect(tasks[7].startTime).toEqual(dayjs('2014-01-13', 'YYYY-MM-DD').toDate()); + expect(tasks[7].endTime).toEqual(dayjs('2014-01-18', 'YYYY-MM-DD').toDate()); expect(tasks[7].order).toEqual(7); expect(tasks[7].id).toEqual('task4'); expect(tasks[7].task).toEqual('Future task in critical line'); - expect(tasks[8].startTime).toEqual(moment('2014-01-18', 'YYYY-MM-DD').toDate()); - expect(tasks[8].endTime).toEqual(moment('2014-01-20', 'YYYY-MM-DD').toDate()); + expect(tasks[8].startTime).toEqual(dayjs('2014-01-18', 'YYYY-MM-DD').toDate()); + expect(tasks[8].endTime).toEqual(dayjs('2014-01-20', 'YYYY-MM-DD').toDate()); expect(tasks[8].order).toEqual(8); expect(tasks[8].id).toEqual('task5'); expect(tasks[8].task).toEqual('Create tests for renderer'); - expect(tasks[9].startTime).toEqual(moment('2014-01-20', 'YYYY-MM-DD').toDate()); - expect(tasks[9].endTime).toEqual(moment('2014-01-21', 'YYYY-MM-DD').toDate()); + expect(tasks[9].startTime).toEqual(dayjs('2014-01-20', 'YYYY-MM-DD').toDate()); + expect(tasks[9].endTime).toEqual(dayjs('2014-01-21', 'YYYY-MM-DD').toDate()); expect(tasks[9].order).toEqual(9); expect(tasks[9].id).toEqual('task6'); expect(tasks[9].task).toEqual('Add to mermaid'); // Section - Documentation - expect(tasks[10].startTime).toEqual(moment('2014-01-08', 'YYYY-MM-DD').toDate()); - expect(tasks[10].endTime).toEqual(moment('2014-01-11', 'YYYY-MM-DD').toDate()); + expect(tasks[10].startTime).toEqual(dayjs('2014-01-08', 'YYYY-MM-DD').toDate()); + expect(tasks[10].endTime).toEqual(dayjs('2014-01-11', 'YYYY-MM-DD').toDate()); expect(tasks[10].order).toEqual(10); expect(tasks[10].id).toEqual('a1'); expect(tasks[10].task).toEqual('Describe gantt syntax'); - expect(tasks[11].startTime).toEqual(moment('2014-01-11', 'YYYY-MM-DD').toDate()); - expect(tasks[11].endTime).toEqual( - moment('2014-01-11 20:00:00', 'YYYY-MM-DD HH:mm:ss').toDate() - ); + expect(tasks[11].startTime).toEqual(dayjs('2014-01-11', 'YYYY-MM-DD').toDate()); + expect(tasks[11].endTime).toEqual(dayjs('2014-01-11 20:00:00', 'YYYY-MM-DD HH:mm:ss').toDate()); expect(tasks[11].order).toEqual(11); expect(tasks[11].id).toEqual('task7'); expect(tasks[11].task).toEqual('Add gantt diagram to demo page'); - expect(tasks[12].startTime).toEqual(moment('2014-01-11', 'YYYY-MM-DD').toDate()); - expect(tasks[12].endTime).toEqual(moment('2014-01-13', 'YYYY-MM-DD').toDate()); + expect(tasks[12].startTime).toEqual(dayjs('2014-01-11', 'YYYY-MM-DD').toDate()); + expect(tasks[12].endTime).toEqual(dayjs('2014-01-13', 'YYYY-MM-DD').toDate()); expect(tasks[12].order).toEqual(12); expect(tasks[12].id).toEqual('doc1'); expect(tasks[12].task).toEqual('Add another diagram to demo page'); // Section - Last section - expect(tasks[13].startTime).toEqual(moment('2014-01-13', 'YYYY-MM-DD').toDate()); - expect(tasks[13].endTime).toEqual(moment('2014-01-16', 'YYYY-MM-DD').toDate()); + expect(tasks[13].startTime).toEqual(dayjs('2014-01-13', 'YYYY-MM-DD').toDate()); + expect(tasks[13].endTime).toEqual(dayjs('2014-01-16', 'YYYY-MM-DD').toDate()); expect(tasks[13].order).toEqual(13); expect(tasks[13].id).toEqual('task8'); expect(tasks[13].task).toEqual('Describe gantt syntax'); - expect(tasks[14].startTime).toEqual(moment('2014-01-16', 'YYYY-MM-DD').toDate()); - expect(tasks[14].endTime).toEqual( - moment('2014-01-16 20:00:00', 'YYYY-MM-DD HH:mm:ss').toDate() - ); + expect(tasks[14].startTime).toEqual(dayjs('2014-01-16', 'YYYY-MM-DD').toDate()); + expect(tasks[14].endTime).toEqual(dayjs('2014-01-16 20:00:00', 'YYYY-MM-DD HH:mm:ss').toDate()); expect(tasks[14].order).toEqual(14); expect(tasks[14].id).toEqual('task9'); expect(tasks[14].task).toEqual('Add gantt diagram to demo page'); expect(tasks[15].startTime).toEqual( - moment('2014-01-16 20:00:00', 'YYYY-MM-DD HH:mm:ss').toDate() - ); - expect(tasks[15].endTime).toEqual( - moment('2014-01-18 20:00:00', 'YYYY-MM-DD HH:mm:ss').toDate() + dayjs('2014-01-16 20:00:00', 'YYYY-MM-DD HH:mm:ss').toDate() ); + expect(tasks[15].endTime).toEqual(dayjs('2014-01-18 20:00:00', 'YYYY-MM-DD HH:mm:ss').toDate()); expect(tasks[15].order).toEqual(15); expect(tasks[15].id).toEqual('task10'); expect(tasks[15].task).toEqual('Add another diagram to demo page'); @@ -358,14 +352,14 @@ describe('when using the ganttDb', function () { ganttDb.addTask('test2', 'id2,after id1,20d'); const tasks = ganttDb.getTasks(); - expect(tasks[0].startTime).toEqual(moment('2019-09-30', 'YYYY-MM-DD').toDate()); - expect(tasks[0].endTime).toEqual(moment('2019-10-11', 'YYYY-MM-DD').toDate()); + expect(tasks[0].startTime).toEqual(dayjs('2019-09-30', 'YYYY-MM-DD').toDate()); + expect(tasks[0].endTime).toEqual(dayjs('2019-10-11', 'YYYY-MM-DD').toDate()); expect(tasks[1].renderEndTime).toBeNull(); // Fixed end expect(tasks[0].id).toEqual('id1'); expect(tasks[0].task).toEqual('test1'); - expect(tasks[1].startTime).toEqual(moment('2019-10-11', 'YYYY-MM-DD').toDate()); - expect(tasks[1].endTime).toEqual(moment('2019-10-31', 'YYYY-MM-DD').toDate()); + expect(tasks[1].startTime).toEqual(dayjs('2019-10-11', 'YYYY-MM-DD').toDate()); + expect(tasks[1].endTime).toEqual(dayjs('2019-10-31', 'YYYY-MM-DD').toDate()); expect(tasks[1].renderEndTime).toBeNull(); // Fixed end expect(tasks[1].id).toEqual('id2'); expect(tasks[1].task).toEqual('test2'); @@ -380,13 +374,13 @@ describe('when using the ganttDb', function () { }); it('should automatically add one day to all end dates', function () { const tasks = ganttDb.getTasks(); - expect(tasks[0].startTime).toEqual(moment('2019-02-01', 'YYYY-MM-DD').toDate()); - expect(tasks[0].endTime).toEqual(moment('2019-02-02', 'YYYY-MM-DD').toDate()); + expect(tasks[0].startTime).toEqual(dayjs('2019-02-01', 'YYYY-MM-DD').toDate()); + expect(tasks[0].endTime).toEqual(dayjs('2019-02-02', 'YYYY-MM-DD').toDate()); expect(tasks[0].id).toEqual('id1'); expect(tasks[0].task).toEqual('test1'); - expect(tasks[1].startTime).toEqual(moment('2019-02-01', 'YYYY-MM-DD').toDate()); - expect(tasks[1].endTime).toEqual(moment('2019-02-04', 'YYYY-MM-DD').toDate()); + expect(tasks[1].startTime).toEqual(dayjs('2019-02-01', 'YYYY-MM-DD').toDate()); + expect(tasks[1].endTime).toEqual(dayjs('2019-02-04', 'YYYY-MM-DD').toDate()); expect(tasks[1].renderEndTime).toBeNull(); // Fixed end expect(tasks[1].manualEndTime).toBeTruthy(); expect(tasks[1].id).toEqual('id2'); diff --git a/packages/mermaid/src/diagrams/gantt/ganttRenderer.js b/packages/mermaid/src/diagrams/gantt/ganttRenderer.js index faec35a86..7a012beb5 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttRenderer.js +++ b/packages/mermaid/src/diagrams/gantt/ganttRenderer.js @@ -1,4 +1,4 @@ -import moment from 'moment-mini'; +import dayjs from 'dayjs'; import { log } from '../../logger'; import { select, @@ -435,16 +435,16 @@ export const draw = function (text, id, version, diagObj) { const excludeRanges = []; let range = null; - let d = moment(minTime); + let d = dayjs(minTime); while (d.valueOf() <= maxTime) { if (diagObj.db.isInvalidDate(d, dateFormat, excludes, includes)) { if (!range) { range = { - start: d.clone(), - end: d.clone(), + start: d, + end: d, }; } else { - range.end = d.clone(); + range.end = d; } } else { if (range) { @@ -452,7 +452,7 @@ export const draw = function (text, id, version, diagObj) { range = null; } } - d.add(1, 'd'); + d = d.add(1, 'd'); } const rectangles = svg.append('g').selectAll('rect').data(excludeRanges).enter(); @@ -467,7 +467,7 @@ export const draw = function (text, id, version, diagObj) { }) .attr('y', conf.gridLineStartPadding) .attr('width', function (d) { - const renderEnd = d.end.clone().add(1, 'day'); + const renderEnd = d.end.add(1, 'day'); return timeScale(renderEnd) - timeScale(d.start); }) .attr('height', h - theTopPad - conf.gridLineStartPadding) diff --git a/packages/mermaid/src/docs/syntax/gantt.md b/packages/mermaid/src/docs/syntax/gantt.md index 0cc915ca1..7c446d91f 100644 --- a/packages/mermaid/src/docs/syntax/gantt.md +++ b/packages/mermaid/src/docs/syntax/gantt.md @@ -116,7 +116,7 @@ The following formatting options are supported: | `YY` | 14 | 2 digit year | | `Q` | 1..4 | Quarter of year. Sets month to first month in quarter. | | `M MM` | 1..12 | Month number | -| `MMM MMMM` | January..Dec | Month name in locale set by `moment.locale()` | +| `MMM MMMM` | January..Dec | Month name in locale set by `dayjs.locale()` | | `D DD` | 1..31 | Day of month | | `Do` | 1st..31st | Day of month with ordinal | | `DDD DDDD` | 1..365 | Day of year | @@ -132,7 +132,7 @@ The following formatting options are supported: | `SSS` | 0..999 | Thousandths of a second | | `Z ZZ` | +12:00 | Offset from UTC as +-HH:mm, +-HHmm, or Z | -More info in: https://momentjs.com/docs/#/parsing/string-format/ +More info in: https://day.js.org/docs/en/parse/string-format/ ### Output date format on the axis diff --git a/packages/mermaid/src/logger.ts b/packages/mermaid/src/logger.ts index b1c035e22..44b98315c 100644 --- a/packages/mermaid/src/logger.ts +++ b/packages/mermaid/src/logger.ts @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-empty-function */ /* eslint-disable no-console */ -import moment from 'moment-mini'; +import dayjs from 'dayjs'; export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal'; @@ -85,6 +85,6 @@ export const setLogLevel = function (level: keyof typeof LEVELS | number | strin * @returns The format with the timestamp and log level */ const format = (level: Uppercase): string => { - const time = moment().format('ss.SSS'); + const time = dayjs().format('ss.SSS'); return `%c${time} : ${level} : `; }; diff --git a/packages/mermaid/src/tests/util.ts b/packages/mermaid/src/tests/util.ts index 042f2cb43..922078876 100644 --- a/packages/mermaid/src/tests/util.ts +++ b/packages/mermaid/src/tests/util.ts @@ -7,8 +7,8 @@ Jest code ```ts it.each` str | expected -${'1d'} | ${moment.duration(1, 'd')} -${'2w'} | ${moment.duration(2, 'w')} +${'1d'} | ${dayjs.duration(1, 'd')} +${'2w'} | ${dayjs.duration(2, 'w')} `('should parse $str to $expected duration', ({ str, expected }) => { expect(yourFunction(str)).toEqual(expected); }); @@ -18,8 +18,8 @@ Vitest code ```ts it.each(convert` str | expected -${'1d'} | ${moment.duration(1, 'd')} -${'2w'} | ${moment.duration(2, 'w')} +${'1d'} | ${dayjs.duration(1, 'd')} +${'2w'} | ${dayjs.duration(2, 'w')} `)('should parse $str to $expected duration', ({ str, expected }) => { expect(yourFunction(str)).toEqual(expected); }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 376f4532e..229e1577e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -48,10 +48,10 @@ importers: version: 4.2.1 '@typescript-eslint/eslint-plugin': specifier: ^5.48.2 - version: 5.48.2_azmbqzqvrlvblbdtiwxwvyvjjy + version: 5.48.2_iljmjqxcygjq3saipl7gerxpvi '@typescript-eslint/parser': specifier: ^5.48.2 - version: 5.48.2_et5x32uxl7z5ldub3ye5rhlyqm + version: 5.48.2_yygwinqv3a2io74xmwofqb7uka '@vitest/coverage-c8': specifier: ^0.28.4 version: 0.28.4_vun5xzxu3tkrssf3erdbijyyki @@ -93,7 +93,7 @@ importers: version: 7.1.0 eslint-plugin-jest: specifier: ^27.1.5 - version: 27.1.5_i5clxtuiaceouxhg5syqkw5wwi + version: 27.1.5_5rcd23qw3h5vuffwo2owxb3hw4 eslint-plugin-jsdoc: specifier: ^39.6.2 version: 39.6.2_eslint@8.32.0 @@ -162,10 +162,10 @@ importers: version: 1.15.4 ts-node: specifier: ^10.9.1 - version: 10.9.1_w6ufic3jqylcjznzspnj4wjqfe + version: 10.9.1_cbe7ovvae6zqfnmtgctpgpys54 typescript: specifier: ^4.8.4 - version: 4.9.5 + version: 4.8.4 vite: specifier: ^4.1.1 version: 4.1.1_@types+node@18.11.9 @@ -191,8 +191,11 @@ importers: specifier: ^7.4.0 version: 7.8.2 dagre-d3-es: - specifier: 7.0.8 - version: 7.0.8 + specifier: 7.0.9 + version: 7.0.9 + dayjs: + specifier: ^1.11.7 + version: 1.11.7 dompurify: specifier: 2.4.3 version: 2.4.3 @@ -205,9 +208,6 @@ importers: lodash-es: specifier: ^4.17.21 version: 4.17.21 - moment-mini: - specifier: ^2.29.4 - version: 2.29.4 non-layered-tidy-tree-layout: specifier: ^2.0.2 version: 2.0.2 @@ -1266,11 +1266,11 @@ packages: '@types/node': 14.18.29 chalk: 4.1.2 cosmiconfig: 7.0.1 - cosmiconfig-typescript-loader: 4.1.0_2uclxasecupgvdn72amnhmyg7y + cosmiconfig-typescript-loader: 4.1.0_nxlrwu45zhpwmwjzs33dzt3ak4 lodash: 4.17.21 resolve-from: 5.0.0 - ts-node: 10.9.1_yxpazyh7n5pql7jdaglasgwqki - typescript: 4.9.5 + ts-node: 10.9.1_sqjhzn5m3vxyw66a2xhtc43hby + typescript: 4.8.4 transitivePeerDependencies: - '@swc/core' - '@swc/wasm' @@ -3182,7 +3182,7 @@ packages: - supports-color dev: true - /@typescript-eslint/eslint-plugin/5.48.2_azmbqzqvrlvblbdtiwxwvyvjjy: + /@typescript-eslint/eslint-plugin/5.48.2_iljmjqxcygjq3saipl7gerxpvi: resolution: {integrity: sha512-sR0Gja9Ky1teIq4qJOl0nC+Tk64/uYdX+mi+5iB//MH8gwyx8e3SOyhEzeLZEFEEfCaLf8KJq+Bd/6je1t+CAg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -3193,18 +3193,18 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/parser': 5.48.2_et5x32uxl7z5ldub3ye5rhlyqm + '@typescript-eslint/parser': 5.48.2_yygwinqv3a2io74xmwofqb7uka '@typescript-eslint/scope-manager': 5.48.2 - '@typescript-eslint/type-utils': 5.48.2_et5x32uxl7z5ldub3ye5rhlyqm - '@typescript-eslint/utils': 5.48.2_et5x32uxl7z5ldub3ye5rhlyqm + '@typescript-eslint/type-utils': 5.48.2_yygwinqv3a2io74xmwofqb7uka + '@typescript-eslint/utils': 5.48.2_yygwinqv3a2io74xmwofqb7uka debug: 4.3.4 eslint: 8.32.0 ignore: 5.2.0 natural-compare-lite: 1.4.0 regexpp: 3.2.0 semver: 7.3.8 - tsutils: 3.21.0_typescript@4.9.5 - typescript: 4.9.5 + tsutils: 3.21.0_typescript@4.8.4 + typescript: 4.8.4 transitivePeerDependencies: - supports-color dev: true @@ -3229,7 +3229,7 @@ packages: - supports-color dev: true - /@typescript-eslint/parser/5.48.2_et5x32uxl7z5ldub3ye5rhlyqm: + /@typescript-eslint/parser/5.48.2_yygwinqv3a2io74xmwofqb7uka: resolution: {integrity: sha512-38zMsKsG2sIuM5Oi/olurGwYJXzmtdsHhn5mI/pQogP+BjYVkK5iRazCQ8RGS0V+YLk282uWElN70zAAUmaYHw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -3241,10 +3241,10 @@ packages: dependencies: '@typescript-eslint/scope-manager': 5.48.2 '@typescript-eslint/types': 5.48.2 - '@typescript-eslint/typescript-estree': 5.48.2_typescript@4.9.5 + '@typescript-eslint/typescript-estree': 5.48.2_typescript@4.8.4 debug: 4.3.4 eslint: 8.32.0 - typescript: 4.9.5 + typescript: 4.8.4 transitivePeerDependencies: - supports-color dev: true @@ -3285,7 +3285,7 @@ packages: - supports-color dev: true - /@typescript-eslint/type-utils/5.48.2_et5x32uxl7z5ldub3ye5rhlyqm: + /@typescript-eslint/type-utils/5.48.2_yygwinqv3a2io74xmwofqb7uka: resolution: {integrity: sha512-QVWx7J5sPMRiOMJp5dYshPxABRoZV1xbRirqSk8yuIIsu0nvMTZesKErEA3Oix1k+uvsk8Cs8TGJ6kQ0ndAcew==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -3295,12 +3295,12 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/typescript-estree': 5.48.2_typescript@4.9.5 - '@typescript-eslint/utils': 5.48.2_et5x32uxl7z5ldub3ye5rhlyqm + '@typescript-eslint/typescript-estree': 5.48.2_typescript@4.8.4 + '@typescript-eslint/utils': 5.48.2_yygwinqv3a2io74xmwofqb7uka debug: 4.3.4 eslint: 8.32.0 - tsutils: 3.21.0_typescript@4.9.5 - typescript: 4.9.5 + tsutils: 3.21.0_typescript@4.8.4 + typescript: 4.8.4 transitivePeerDependencies: - supports-color dev: true @@ -3336,28 +3336,7 @@ packages: - supports-color dev: true - /@typescript-eslint/typescript-estree/5.42.1_typescript@4.9.5: - resolution: {integrity: sha512-qElc0bDOuO0B8wDhhW4mYVgi/LZL+igPwXtV87n69/kYC/7NG3MES0jHxJNCr4EP7kY1XVsRy8C/u3DYeTKQmw==} - engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} - peerDependencies: - typescript: '*' - peerDependenciesMeta: - typescript: - optional: true - dependencies: - '@typescript-eslint/types': 5.42.1 - '@typescript-eslint/visitor-keys': 5.42.1 - debug: 4.3.4 - globby: 11.1.0 - is-glob: 4.0.3 - semver: 7.3.8 - tsutils: 3.21.0_typescript@4.9.5 - typescript: 4.9.5 - transitivePeerDependencies: - - supports-color - dev: true - - /@typescript-eslint/typescript-estree/5.48.2_typescript@4.9.5: + /@typescript-eslint/typescript-estree/5.48.2_typescript@4.8.4: resolution: {integrity: sha512-bibvD3z6ilnoVxUBFEgkO0k0aFvUc4Cttt0dAreEr+nrAHhWzkO83PEVVuieK3DqcgL6VAK5dkzK8XUVja5Zcg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -3372,32 +3351,12 @@ packages: globby: 11.1.0 is-glob: 4.0.3 semver: 7.3.8 - tsutils: 3.21.0_typescript@4.9.5 - typescript: 4.9.5 + tsutils: 3.21.0_typescript@4.8.4 + typescript: 4.8.4 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/utils/5.42.1_et5x32uxl7z5ldub3ye5rhlyqm: - resolution: {integrity: sha512-Gxvf12xSp3iYZd/fLqiQRD4uKZjDNR01bQ+j8zvhPjpsZ4HmvEFL/tC4amGNyxN9Rq+iqvpHLhlqx6KTxz9ZyQ==} - engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} - peerDependencies: - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 - dependencies: - '@types/json-schema': 7.0.11 - '@types/semver': 7.3.12 - '@typescript-eslint/scope-manager': 5.42.1 - '@typescript-eslint/types': 5.42.1 - '@typescript-eslint/typescript-estree': 5.42.1_typescript@4.9.5 - eslint: 8.32.0 - eslint-scope: 5.1.1 - eslint-utils: 3.0.0_eslint@8.32.0 - semver: 7.3.8 - transitivePeerDependencies: - - supports-color - - typescript - dev: true - /@typescript-eslint/utils/5.42.1_yygwinqv3a2io74xmwofqb7uka: resolution: {integrity: sha512-Gxvf12xSp3iYZd/fLqiQRD4uKZjDNR01bQ+j8zvhPjpsZ4HmvEFL/tC4amGNyxN9Rq+iqvpHLhlqx6KTxz9ZyQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -3418,7 +3377,7 @@ packages: - typescript dev: true - /@typescript-eslint/utils/5.48.2_et5x32uxl7z5ldub3ye5rhlyqm: + /@typescript-eslint/utils/5.48.2_yygwinqv3a2io74xmwofqb7uka: resolution: {integrity: sha512-2h18c0d7jgkw6tdKTlNaM7wyopbLRBiit8oAxoP89YnuBOzCZ8g8aBCaCqq7h208qUTroL7Whgzam7UY3HVLow==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -3428,7 +3387,7 @@ packages: '@types/semver': 7.3.12 '@typescript-eslint/scope-manager': 5.48.2 '@typescript-eslint/types': 5.48.2 - '@typescript-eslint/typescript-estree': 5.48.2_typescript@4.9.5 + '@typescript-eslint/typescript-estree': 5.48.2_typescript@4.8.4 eslint: 8.32.0 eslint-scope: 5.1.1 eslint-utils: 3.0.0_eslint@8.32.0 @@ -5006,7 +4965,7 @@ packages: layout-base: 2.0.1 dev: false - /cosmiconfig-typescript-loader/4.1.0_2uclxasecupgvdn72amnhmyg7y: + /cosmiconfig-typescript-loader/4.1.0_nxlrwu45zhpwmwjzs33dzt3ak4: resolution: {integrity: sha512-HbWIuR5O+XO5Oj9SZ5bzgrD4nN+rfhrm2PMb0FVx+t+XIvC45n8F0oTNnztXtspWGw0i2IzHaUWFD5LzV1JB4A==} engines: {node: '>=12', npm: '>=6'} peerDependencies: @@ -5017,8 +4976,8 @@ packages: dependencies: '@types/node': 14.18.29 cosmiconfig: 7.0.1 - ts-node: 10.9.1_yxpazyh7n5pql7jdaglasgwqki - typescript: 4.9.5 + ts-node: 10.9.1_sqjhzn5m3vxyw66a2xhtc43hby + typescript: 4.8.4 dev: true /cosmiconfig/7.0.1: @@ -5370,7 +5329,7 @@ packages: cli-table3: 0.6.3 commander: 5.1.0 common-tags: 1.8.2 - dayjs: 1.11.5 + dayjs: 1.11.7 debug: 4.3.4_supports-color@8.1.1 enquirer: 2.3.6 eventemitter2: 6.4.7 @@ -5672,8 +5631,8 @@ packages: d3-zoom: 3.0.0 dev: false - /dagre-d3-es/7.0.8: - resolution: {integrity: sha512-eykdoYQ4FwCJinEYS0gPL2f2w+BPbSLvnQSJ3Ye1vAoPjdkq6xIMKBv+UkICd3qZE26wBKIn3p+6n0QC7R1LyA==} + /dagre-d3-es/7.0.9: + resolution: {integrity: sha512-rYR4QfVmy+sR44IBDvVtcAmOReGBvRCWDpO2QjYwqgh9yijw6eSHBqaPG/LIOEy7aBsniLvtMW6pg19qJhq60w==} dependencies: d3: 7.8.2 lodash-es: 4.17.21 @@ -5710,9 +5669,8 @@ packages: engines: {node: '>=0.11'} dev: true - /dayjs/1.11.5: - resolution: {integrity: sha512-CAdX5Q3YW3Gclyo5Vpqkgpj8fSdLQcRuzfX6mC6Phy0nfJ0eGYOeS7m4mt2plDWLAtA4TqTakvbboHvUxfe4iA==} - dev: true + /dayjs/1.11.7: + resolution: {integrity: sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ==} /debug/2.6.9: resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} @@ -6232,7 +6190,7 @@ packages: htmlparser2: 8.0.1 dev: true - /eslint-plugin-jest/27.1.5_i5clxtuiaceouxhg5syqkw5wwi: + /eslint-plugin-jest/27.1.5_5rcd23qw3h5vuffwo2owxb3hw4: resolution: {integrity: sha512-CK2dekZ5VBdzsOSOH5Fc1rwC+cWXjkcyrmf1RV714nDUDKu+o73TTJiDxpbILG8PtPPpAAl3ywzh5QA7Ft0mjA==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} peerDependencies: @@ -6245,8 +6203,8 @@ packages: jest: optional: true dependencies: - '@typescript-eslint/eslint-plugin': 5.48.2_azmbqzqvrlvblbdtiwxwvyvjjy - '@typescript-eslint/utils': 5.42.1_et5x32uxl7z5ldub3ye5rhlyqm + '@typescript-eslint/eslint-plugin': 5.48.2_iljmjqxcygjq3saipl7gerxpvi + '@typescript-eslint/utils': 5.42.1_yygwinqv3a2io74xmwofqb7uka eslint: 8.32.0 jest: 29.3.1_odkjkoia5xunhxkdrka32ib6vi transitivePeerDependencies: @@ -7874,7 +7832,7 @@ packages: pretty-format: 29.3.1 slash: 3.0.0 strip-json-comments: 3.1.1 - ts-node: 10.9.1_w6ufic3jqylcjznzspnj4wjqfe + ts-node: 10.9.1_cbe7ovvae6zqfnmtgctpgpys54 transitivePeerDependencies: - supports-color dev: true @@ -8251,8 +8209,8 @@ packages: '@sideway/pinpoint': 2.0.0 dev: true - /joi/17.7.1: - resolution: {integrity: sha512-teoLhIvWE298R6AeJywcjR4sX2hHjB3/xJX4qPjg+gTg+c0mzUDsziYlqPmLomq9gVsfaMcgPaGc7VxtD/9StA==} + /joi/17.8.3: + resolution: {integrity: sha512-q5Fn6Tj/jR8PfrLrx4fpGH4v9qM6o+vDUfD4/3vxxyg34OmKcNqYZ1qn2mpLza96S8tL0p0rIw2gOZX+/cTg9w==} dependencies: '@hapi/hoek': 9.3.0 '@hapi/topo': 5.1.0 @@ -9330,10 +9288,6 @@ packages: ufo: 1.0.1 dev: true - /moment-mini/2.29.4: - resolution: {integrity: sha512-uhXpYwHFeiTbY9KSgPPRoo1nt8OxNVdMVoTBYHfSEKeRkIkwGpO+gERmhuhBtzfaeOyTkykSrm2+noJBgqt3Hg==} - dev: false - /mri/1.2.0: resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} engines: {node: '>=4'} @@ -11344,7 +11298,7 @@ packages: engines: {node: '>=6.10'} dev: false - /ts-node/10.9.1_w6ufic3jqylcjznzspnj4wjqfe: + /ts-node/10.9.1_cbe7ovvae6zqfnmtgctpgpys54: resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true peerDependencies: @@ -11370,12 +11324,12 @@ packages: create-require: 1.1.1 diff: 4.0.2 make-error: 1.3.6 - typescript: 4.9.5 + typescript: 4.8.4 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 dev: true - /ts-node/10.9.1_yxpazyh7n5pql7jdaglasgwqki: + /ts-node/10.9.1_sqjhzn5m3vxyw66a2xhtc43hby: resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true peerDependencies: @@ -11401,7 +11355,7 @@ packages: create-require: 1.1.1 diff: 4.0.2 make-error: 1.3.6 - typescript: 4.9.5 + typescript: 4.8.4 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 dev: true @@ -11424,16 +11378,6 @@ packages: typescript: 4.8.4 dev: true - /tsutils/3.21.0_typescript@4.9.5: - resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} - engines: {node: '>= 6'} - peerDependencies: - typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta' - dependencies: - tslib: 1.14.1 - typescript: 4.9.5 - dev: true - /tunnel-agent/0.6.0: resolution: {integrity: sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==} dependencies: @@ -11536,12 +11480,6 @@ packages: hasBin: true dev: true - /typescript/4.9.5: - resolution: {integrity: sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==} - engines: {node: '>=4.2.0'} - hasBin: true - dev: true - /uc.micro/1.0.6: resolution: {integrity: sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==} dev: true @@ -12138,7 +12076,7 @@ packages: hasBin: true dependencies: axios: 0.27.2_debug@4.3.4 - joi: 17.7.1 + joi: 17.8.3 lodash: 4.17.21 minimist: 1.2.8 rxjs: 7.8.0 From 61bf7c577c87b4281228fbf7ab28914c9b7881dc Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Sat, 25 Feb 2023 20:14:09 +0000 Subject: [PATCH 06/13] test(gantt): test daylight savings in ganttdb Add a quick test that ensures `ganttDb` correctly adds `1d` (1 day), even on days with 25 hours. This test only runs if the test PC has the TZ='America/Los_Angeles' set (California has daylight savings). I've added a test to the GitHub Actions `test.yml` action too for this. It should only add about 5 seconds to each test, so it isn't too bad. --- .github/workflows/test.yml | 8 +++++ .../src/diagrams/gantt/ganttDb.spec.ts | 34 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6397e5305..6c01ba1b9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,6 +33,14 @@ jobs: run: | pnpm run ci --coverage + - name: Run ganttDb tests using California timezone + env: + # Makes sure that gantt db works even in a timezone that has daylight savings + # since some days have 25 hours instead of 24. + TZ: America/Los_Angeles + run: | + pnpm exec vitest run ./packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts + - name: Upload Coverage to Coveralls # it feels a bit weird to use @master, but that's what the docs use # (coveralls also doesn't publish a @v1 we can use) diff --git a/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts b/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts index dadcdcc40..d65f2fdfd 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts +++ b/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts @@ -365,6 +365,40 @@ describe('when using the ganttDb', function () { expect(tasks[1].task).toEqual('test2'); }); + /** + * Unfortunately, Vitest has no way of modifying the timezone at runtime, so + * in order to test this, please run this test with + * + * ```bash + * TZ='America/Los_Angeles' pnpm exec vitest run ganttDb + * ``` + */ + /* c8 ignore start */ // tell code-coverage to ignore this block of code + describe.skipIf(process.env.TZ != 'America/Los_Angeles')( + 'when using a timezone with daylight savings (only run if TZ="America/Los_Angeles")', + () => { + it('should add 1 day even on days with 25 hours', function () { + const startTime = new Date(2020, 10, 1); + expect(startTime.toISOString()).toBe('2020-11-01T07:00:00.000Z'); + + const endTime = new Date(2020, 10, 2); + expect(endTime.toISOString()).toBe('2020-11-02T08:00:00.000Z'); + + ganttDb.setDateFormat('YYYY-MM-DD'); + ganttDb.addSection('Task handles 25 hour day'); + ganttDb.addTask('daylight savings day', 'id1,2020-11-01,1d'); + const tasks = ganttDb.getTasks(); + expect(tasks[0].startTime).toEqual(startTime); + expect(tasks[0].endTime).toEqual(endTime); + + // In USA states that use daylight savings, 2020-11-01 had 25 hours + const millisecondsIn25Hours = 25 * 60 * 60 * 1000; + expect(endTime - startTime).toEqual(millisecondsIn25Hours); + }); + } + ); + /* c8 ignore stop */ + describe('when setting inclusive end dates', function () { beforeEach(function () { ganttDb.setDateFormat('YYYY-MM-DD'); From 2a838e645ce23cd4f310716e9486afe50a72e516 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Tue, 28 Feb 2023 20:31:03 +0530 Subject: [PATCH 07/13] Revert "Split cytoscape" This reverts commit f81f9f7c958848758d26e1e2bf05a98808152a25. --- .../src/diagrams/mindmap/mindmapRenderer.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.js b/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.js index 0d814212e..0e68a1015 100644 --- a/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.js +++ b/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.js @@ -4,9 +4,13 @@ import { log } from '../../logger'; import { getConfig } from '../../config'; import { setupGraphViewbox } from '../../setupGraphViewbox'; import svgDraw from './svgDraw'; +import cytoscape from 'cytoscape'; +import coseBilkent from 'cytoscape-cose-bilkent'; import * as db from './mindmapDb'; -let cytoscape; +// Inject the layout algorithm into cytoscape +cytoscape.use(coseBilkent); + /** * @param {any} svg The svg element to draw the diagram onto * @param {object} mindmap The mindmap data and hierarchy @@ -89,14 +93,7 @@ function addNodes(mindmap, cy, conf, level) { * @param conf * @param cy */ -async function layoutMindmap(node, conf) { - if (!cytoscape) { - cytoscape = (await import('cytoscape')).default; - const coseBilkent = (await import('cytoscape-cose-bilkent')).default; - // Inject the layout algorithm into cytoscape - cytoscape.use(coseBilkent); - } - +function layoutMindmap(node, conf) { return new Promise((resolve) => { // Add temporary render element const renderEl = select('body').append('div').attr('id', 'cy').attr('style', 'display:none'); From b6db75fe3e411e85449d182ecefaf608463f4b12 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Tue, 28 Feb 2023 20:39:06 +0530 Subject: [PATCH 08/13] Revert "chore: Defer elk loading" This reverts commit 037504785c26dd18ee797cfdf93a5e9f5f551f6a. --- .../src/diagrams/flowchart/elk/flowRenderer-elk.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/mermaid/src/diagrams/flowchart/elk/flowRenderer-elk.js b/packages/mermaid/src/diagrams/flowchart/elk/flowRenderer-elk.js index b8458efeb..0a92af1b3 100644 --- a/packages/mermaid/src/diagrams/flowchart/elk/flowRenderer-elk.js +++ b/packages/mermaid/src/diagrams/flowchart/elk/flowRenderer-elk.js @@ -9,8 +9,8 @@ import { log } from '../../../logger'; import { setupGraphViewbox } from '../../../setupGraphViewbox'; import common, { evaluate } from '../../common/common'; import { interpolateToCurve, getStylesFromArray } from '../../../utils'; - -let elk; +import ELK from 'elkjs/lib/elk.bundled.js'; +const elk = new ELK(); const portPos = {}; @@ -765,10 +765,6 @@ const insertChildren = (nodeArray, parentLookupDb) => { */ export const draw = async function (text, id, _version, diagObj) { - if (!elk) { - const ELK = (await import('elkjs/lib/elk.bundled.js')).default; - elk = new ELK(); - } // Add temporary render element diagObj.db.clear(); nodeDb = {}; From a7847038a53d518daa806fa97b690218b3d9cc19 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Tue, 28 Feb 2023 20:40:56 +0530 Subject: [PATCH 09/13] Use cytoscape esm --- packages/mermaid/src/diagrams/mindmap/mindmapRenderer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.js b/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.js index 0e68a1015..e82239123 100644 --- a/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.js +++ b/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.js @@ -4,7 +4,7 @@ import { log } from '../../logger'; import { getConfig } from '../../config'; import { setupGraphViewbox } from '../../setupGraphViewbox'; import svgDraw from './svgDraw'; -import cytoscape from 'cytoscape'; +import cytoscape from 'cytoscape/dist/cytoscape.esm.js'; import coseBilkent from 'cytoscape-cose-bilkent'; import * as db from './mindmapDb'; From d24ddca03f7e3905fff783abaedaec9f06d2c8a2 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Tue, 28 Feb 2023 21:49:49 +0530 Subject: [PATCH 10/13] chore: Rename diagram-definitions with specific names --- packages/mermaid/src/diagrams/flowchart/elk/detector.ts | 2 +- .../elk/{diagram-definition.ts => flowchart-elk-definition.ts} | 0 packages/mermaid/src/diagrams/mindmap/detector.ts | 2 +- .../mindmap/{diagram-definition.ts => mindmap-definition.ts} | 0 packages/mermaid/src/diagrams/timeline/detector.ts | 2 +- .../timeline/{diagram-definition.ts => timeline-definition.ts} | 0 6 files changed, 3 insertions(+), 3 deletions(-) rename packages/mermaid/src/diagrams/flowchart/elk/{diagram-definition.ts => flowchart-elk-definition.ts} (100%) rename packages/mermaid/src/diagrams/mindmap/{diagram-definition.ts => mindmap-definition.ts} (100%) rename packages/mermaid/src/diagrams/timeline/{diagram-definition.ts => timeline-definition.ts} (100%) diff --git a/packages/mermaid/src/diagrams/flowchart/elk/detector.ts b/packages/mermaid/src/diagrams/flowchart/elk/detector.ts index 41760ff4d..c6fa77957 100644 --- a/packages/mermaid/src/diagrams/flowchart/elk/detector.ts +++ b/packages/mermaid/src/diagrams/flowchart/elk/detector.ts @@ -16,7 +16,7 @@ const detector: DiagramDetector = (txt: string, config?: MermaidConfig): boolean }; const loader = async () => { - const { diagram } = await import('./diagram-definition.js'); + const { diagram } = await import('./flowchart-elk-definition.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/flowchart/elk/diagram-definition.ts b/packages/mermaid/src/diagrams/flowchart/elk/flowchart-elk-definition.ts similarity index 100% rename from packages/mermaid/src/diagrams/flowchart/elk/diagram-definition.ts rename to packages/mermaid/src/diagrams/flowchart/elk/flowchart-elk-definition.ts diff --git a/packages/mermaid/src/diagrams/mindmap/detector.ts b/packages/mermaid/src/diagrams/mindmap/detector.ts index c96b19097..2e2b1c7d6 100644 --- a/packages/mermaid/src/diagrams/mindmap/detector.ts +++ b/packages/mermaid/src/diagrams/mindmap/detector.ts @@ -6,7 +6,7 @@ const detector = (txt: string) => { }; const loader = async () => { - const { diagram } = await import('./diagram-definition.js'); + const { diagram } = await import('./mindmap-definition.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/mindmap/diagram-definition.ts b/packages/mermaid/src/diagrams/mindmap/mindmap-definition.ts similarity index 100% rename from packages/mermaid/src/diagrams/mindmap/diagram-definition.ts rename to packages/mermaid/src/diagrams/mindmap/mindmap-definition.ts diff --git a/packages/mermaid/src/diagrams/timeline/detector.ts b/packages/mermaid/src/diagrams/timeline/detector.ts index faa86a72c..9bd2b5ece 100644 --- a/packages/mermaid/src/diagrams/timeline/detector.ts +++ b/packages/mermaid/src/diagrams/timeline/detector.ts @@ -7,7 +7,7 @@ const detector = (txt: string) => { }; const loader = async () => { - const { diagram } = await import('./diagram-definition.js'); + const { diagram } = await import('./timeline-definition.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/timeline/diagram-definition.ts b/packages/mermaid/src/diagrams/timeline/timeline-definition.ts similarity index 100% rename from packages/mermaid/src/diagrams/timeline/diagram-definition.ts rename to packages/mermaid/src/diagrams/timeline/timeline-definition.ts From 1ecf15669a7d931a7431b7ea86193b52f2738f9a Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Tue, 28 Feb 2023 21:51:31 +0530 Subject: [PATCH 11/13] 9.4.2-rc.2 --- packages/mermaid/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mermaid/package.json b/packages/mermaid/package.json index 4a928d6df..09133c892 100644 --- a/packages/mermaid/package.json +++ b/packages/mermaid/package.json @@ -1,6 +1,6 @@ { "name": "mermaid", - "version": "9.4.2-rc.1", + "version": "9.4.2-rc.2", "description": "Markdown-ish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.", "main": "./dist/mermaid.min.js", "module": "./dist/mermaid.core.mjs", From 86aa7ab91e5466f5840368ce9b7c9bf66fb051a5 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Tue, 7 Mar 2023 18:09:33 +0530 Subject: [PATCH 12/13] Fix mindmap demo --- demos/mindmap.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/demos/mindmap.html b/demos/mindmap.html index a5b554a1a..2e7d47719 100644 --- a/demos/mindmap.html +++ b/demos/mindmap.html @@ -40,7 +40,6 @@