diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 45847c445..1515f781c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,14 +2,13 @@ name: Deploy Live Editor on: push: branches: - - master + - develop pull_request: branches: - - master - develop jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v3 @@ -21,7 +20,7 @@ jobs: - name: Build & Deploy env: - MERMAID_DOMAIN: 'mermaid.live' + MERMAID_DOMAIN: 'https://noobtolinux.github.io/mermaid-live-editor/' MERMAID_ANALYTICS_URL: 'https://p.mermaid.live' MERMAID_RENDERER_URL: 'https://mermaid.ink' MERMAID_KROKI_RENDERER_URL: 'https://kroki.io' @@ -37,8 +36,9 @@ jobs: - name: Deploy uses: peaceiris/actions-gh-pages@v3 - if: ${{ github.ref == 'refs/heads/master' }} + if: ${{ github.ref == 'refs/heads/develop' }} with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./docs + publish_branch: gh-pages # Especificamos la rama de despliegue, en este caso 'gh-pages' keep_files: true diff --git a/.prettierignore b/.prettierignore index 9661ca5e8..b69f9470a 100644 --- a/.prettierignore +++ b/.prettierignore @@ -5,4 +5,8 @@ build/** node_modules/** coverage/** __snapshots__/** -snapshots.js \ No newline at end of file +snapshots.js + +tsconfig.json +src/lib/util/mermaid.ts +/.github/workflows/deploy.yml \ No newline at end of file diff --git a/README.md b/README.md index 02a0c7b59..6e311d6ae 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Edit, preview and share mermaid charts/diagrams. ## Live demo -You can try out a live version [here](https://mermaid.live/). +You can try out a live version [here](https://mermaid.live/). ---> [From this repo](https://noobtolinux.github.io/mermaid-live-editor/) ## Docker diff --git a/src/lib/util/mermaid.ts b/src/lib/util/mermaid.ts index c4a5c6c5f..f29283d57 100644 --- a/src/lib/util/mermaid.ts +++ b/src/lib/util/mermaid.ts @@ -6,6 +6,107 @@ import mermaid from 'mermaid'; mermaid.registerLayoutLoaders(elkLayouts); const init = mermaid.registerExternalDiagrams([zenuml]); + + + + +//----------------------------------------- + +class ExtensionData { + name: string; + url: string; +} + +class alias { + parent: string; +} +class Aliases { + [x: string] : alias; +} + +class Icon { + body: string; + width: number; + height: number; +} + +class IconNameData { + [x: string] : Icon; +} + +class Module { + lastModified: number; + height: number; + width: number; + prefix: string; + icons: IconNameData; + aliases: Aliases; +} + +type WrapFunction = () => Module; + +class MermaidRegisterObject { + name: string; + loader: WrapFunction; +} + +async function loader_function(url: string): Promise { + const response = await fetch(url); // Tipo: Response + const module = await response.json() as Module; // El tipo de `json()` es `any`, pero lo asignamos a `Module` + + // Asegurándonos de que el JSON tenga la forma correcta de `Module` + return module; // Aquí estamos afirmando que el JSON tiene la forma de `Module` +} + +async function UrlsToRegisterObject(extension_value: ExtensionData): Promise { + const name = extension_value.name + const url = extension_value.url + + const module = await loader_function(url); + + function wrap(): Module {return module;} + + return { + name: name, + loader: wrap, + } +} //Comment for commit, you can ignore this + +function checkIfExtensionIsPresent(){ + //Just to have true false value instead of null document + return document.querySelector('#extension-data') ? true : false; +} + +// Tipar la función loadInputs correctamente +async function loadInputs(): Promise { + //waitSync(1000); //Just to try to see if it loads the data + if (!checkIfExtensionIsPresent()){return null;} + + const dataElement = document.querySelector('#extension-data'); + const extension_data = JSON.parse(dataElement.textContent) as ExtensionData[]; + + const data: MermaidRegisterObject[] = []; + for (const item of extension_data) { + const mermaidRegister = await UrlsToRegisterObject(item); + data.push(mermaidRegister); + } + // + + return data; +} + + // La función mermaidRegisterProcess +async function mermaidRegisterProcess() { + const inputs = await loadInputs(); + if (inputs) { + mermaid.registerIconPacks(inputs); + } +} + + + +//------- + export const render = async ( config: MermaidConfig, code: string, @@ -15,6 +116,7 @@ export const render = async ( // Should be able to call this multiple times without any issues. mermaid.initialize(config); + await mermaidRegisterProcess(); return await mermaid.render(id, code); }; diff --git a/tsconfig.json b/tsconfig.json index 91263b2e3..200eb304f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,8 @@ "resolveJsonModule": true, "allowSyntheticDefaultImports": true, "strictNullChecks": true, - "types": ["vitest/importMeta"] + "types": ["vitest/importMeta"], + "lib": [ "es2015", "dom" ] }, "extends": "./.svelte-kit/tsconfig.json" }