diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..197e04802 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "pwa-chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:3000", + "webRoot": "${workspaceFolder}" + } + ] +} diff --git a/cypress/e2e/diagramUpdate.spec.ts b/cypress/e2e/diagramUpdate.spec.ts index b0075aa2f..a4c3d50af 100644 --- a/cypress/e2e/diagramUpdate.spec.ts +++ b/cypress/e2e/diagramUpdate.spec.ts @@ -3,6 +3,7 @@ describe('Auto sync tests', () => { cy.clearLocalStorage(); cy.visit('/'); }); + it('should dim diagram when code is edited', () => { cy.contains('Auto sync').click(); cy.get('#view').should('not.have.class', 'outOfSync'); @@ -40,4 +41,17 @@ describe('Auto sync tests', () => { cy.get('#editor').type(`{uparrow}{${cmd}}/`); cy.get('#view').contains('Car').should('exist'); }); + + it('supports editing code when code is incorrect', () => { + cy.visit( + '/edit#pako:eNpljjEKwzAMRa8SNOcEnlt6gK5eVFvYJsgOqkwpIXevg9smEE1PnyfxF3DFExgISW-CczQ2D21cYU7a-SGYXRwyvTp9jUhuKlVP-eHy7zA-leQsMEmg_QOM0BLG5FujZVMsaCQmC6ahR5ks2Lw2r84ela4-aREwKpVGwKrl_s7ut3fnkjAIcg_XDzuaUhs' + ); + cy.get('#editor').type(`{enter}branch test`); + cy.get('#editor').contains('branch test').should('exist'); + cy.get('#errorContainer') + .contains( + 'Error: Trying to checkout branch which is not yet created. (Help try using "branch master")' + ) + .should('exist'); + }); }); diff --git a/cypress/snapshots.js b/cypress/snapshots.js index 05581857a..7e54bcb93 100644 --- a/cypress/snapshots.js +++ b/cypress/snapshots.js @@ -16,7 +16,7 @@ module.exports = { "1": "{\"code\":\"graph TD\\n A[Party] -->|Get money| B(Go shopping!!)\\n \",\"mermaid\":\"{\\n \\\"theme\\\": \\\"forest\\\",\\n \\\"test\\\": \\\"hello world\\\"\\n}\",\"updateEditor\":false,\"autoSync\":true,\"updateDiagram\":true,\"loader\":{\"type\":\"files\",\"config\":{\"codeURL\":\"https://gist.githubusercontent.com/sidharthv96/6268a23e673a533dcb198f241fd7012a/raw/4eb03887e6a41397e80bdcdbf94017c498f8f1e2/code.mmd\",\"configURL\":\"https://gist.githubusercontent.com/sidharthv96/6268a23e673a533dcb198f241fd7012a/raw/4eb03887e6a41397e80bdcdbf94017c498f8f1e2/config.json\"}}}" } }, - "__version": "10.2.0", + "__version": "10.3.0", "Auto sync tests": { "should dim diagram when code is edited": { "1": "{\"code\":\"graph TD\\n A[Christmas] -->|Get money| B(Go shopping)\\n B --> C{Let me think}\\n C -->|One| D[Laptop]\\n C -->|Two| E[iPhone]\\n C -->|Three| F[fa:fa-car Car]\\n C --> Test\",\"mermaid\":\"{\\n \\\"theme\\\": \\\"default\\\"\\n}\",\"updateEditor\":false,\"autoSync\":false,\"updateDiagram\":false}" diff --git a/src/lib/components/actions.svelte b/src/lib/components/actions.svelte index 7a23e0149..e504de0dd 100644 --- a/src/lib/components/actions.svelte +++ b/src/lib/components/actions.svelte @@ -4,7 +4,7 @@ import Card from '$lib/components/card/card.svelte'; import { krokiRendererUrl, rendererUrl } from '$lib/util/env'; import { pakoSerde } from '$lib/util/serde'; - import { serializedState, codeStore } from '$lib/util/state'; + import { stateStore } from '$lib/util/state'; import { toBase64 } from 'js-base64'; import moment from 'moment'; @@ -57,6 +57,7 @@ const svgEl: HTMLElement = document .querySelector('#container svg') .cloneNode(true) as HTMLElement; + svgEl.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); const fontAwesomeCdnUrl = Array.from(document.head.getElementsByTagName('link')) .map((l) => l.href) .find((h) => h && h.includes('font-awesome')); @@ -130,10 +131,10 @@ }; let gistURL = ''; - codeStore.subscribe((state) => { - if (state.loader?.type === 'gist') { + stateStore.subscribe(({ loader }) => { + if (loader?.type === 'gist') { // @ts-ignore Gist will have url - gistURL = state.loader.config.url; + gistURL = loader.config.url; } }); @@ -155,11 +156,11 @@ if (browser && ['mermaid.live', 'netlify'].some((path) => window.location.host.includes(path))) { isNetlify = true; } - serializedState.subscribe((encodedState: string) => { - iUrl = `${rendererUrl}/img/${encodedState}`; - svgUrl = `${rendererUrl}/svg/${encodedState}`; - krokiUrl = `${krokiRendererUrl}/mermaid/svg/${pakoSerde.serialize($codeStore.code)}`; - mdCode = `[![](${iUrl})](${window.location.protocol}//${window.location.host}${window.location.pathname}#${encodedState})`; + stateStore.subscribe(({ code, serialized }) => { + iUrl = `${rendererUrl}/img/${serialized}`; + svgUrl = `${rendererUrl}/svg/${serialized}`; + krokiUrl = `${krokiRendererUrl}/mermaid/svg/${pakoSerde.serialize(code)}`; + mdCode = `[![](${iUrl})](${window.location.protocol}//${window.location.host}${window.location.pathname}#${serialized})`; }); diff --git a/src/lib/components/editor.svelte b/src/lib/components/editor.svelte index 536bb427a..1399a3506 100644 --- a/src/lib/components/editor.svelte +++ b/src/lib/components/editor.svelte @@ -1,6 +1,6 @@ diff --git a/src/lib/components/view.svelte b/src/lib/components/view.svelte index 6bb96687c..a4036093e 100644 --- a/src/lib/components/view.svelte +++ b/src/lib/components/view.svelte @@ -1,7 +1,5 @@ +{#if error && $stateStore.error instanceof Error} +
{$stateStore.error}
+{/if} +