From 65f8c98571f63abc13d5b6d9ba29228189f4ff50 Mon Sep 17 00:00:00 2001 From: BearToCode Date: Tue, 7 Nov 2023 12:57:05 +0100 Subject: [PATCH 001/127] ci: run `semantic-release-monorepo` in all packages --- package.json | 2 +- packages/carta-md/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e2437b7..2be59b1 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "format": "prettier --plugin-search-dir . --write .", "prepare": "husky install", "commit": "cz", - "publish": "cd packages/carta-md && npx --no-install semantic-release -e semantic-release-monorepo" + "publish": "pnpm -r --workspace-concurrency=1 exec -- npx --no-install semantic-release -e semantic-release-monorepo" }, "devDependencies": { "@types/node": "^18.16.3", diff --git a/packages/carta-md/package.json b/packages/carta-md/package.json index adf55e6..4048048 100644 --- a/packages/carta-md/package.json +++ b/packages/carta-md/package.json @@ -18,7 +18,7 @@ "./light.css": "./dist/light.css", "./dark.css": "./dist/dark.css" }, - "version": "2.8.0", + "version": "3.0.0", "scripts": { "dev": "vite dev", "build": "svelte-kit sync && svelte-package", From a7352bcb6f5081e95ec23fb278baac9b0d5aa811 Mon Sep 17 00:00:00 2001 From: BearToCode Date: Tue, 7 Nov 2023 13:01:34 +0100 Subject: [PATCH 002/127] build: set plugin-attachment version --- packages/plugin-attachment/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-attachment/package.json b/packages/plugin-attachment/package.json index 10ea5ca..253d6e8 100644 --- a/packages/plugin-attachment/package.json +++ b/packages/plugin-attachment/package.json @@ -1,6 +1,6 @@ { "name": "@cartamd/plugin-attachment", - "version": "2.8.0", + "version": "3.0.0", "type": "module", "main": "./dist/index.js", "types": "./dist/index.d.ts", From 8231dc533b6d7c243f0f9aea04dfda32977b1adc Mon Sep 17 00:00:00 2001 From: BearToCode Date: Tue, 7 Nov 2023 14:54:49 +0100 Subject: [PATCH 003/127] ci: use manually specified packages --- package.json | 4 ++-- scripts/packages.js | 10 +++++++--- scripts/publish.js | 9 +++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 scripts/publish.js diff --git a/package.json b/package.json index 2be59b1..d978986 100644 --- a/package.json +++ b/package.json @@ -14,11 +14,11 @@ "dev": "cd demo && npm run dev", "check": "cd packages/carta-md && npm run check", "build": "node scripts/build.js", + "publish": "node scripts/publish.js", "lint": "prettier --plugin-search-dir . --check . && eslint .", "format": "prettier --plugin-search-dir . --write .", "prepare": "husky install", - "commit": "cz", - "publish": "pnpm -r --workspace-concurrency=1 exec -- npx --no-install semantic-release -e semantic-release-monorepo" + "commit": "cz" }, "devDependencies": { "@types/node": "^18.16.3", diff --git a/scripts/packages.js b/scripts/packages.js index c914f80..5cbccb1 100644 --- a/scripts/packages.js +++ b/scripts/packages.js @@ -1,21 +1,25 @@ import * as childProcess from 'child_process'; +import { stderr, stdout } from 'process'; -export const execAsync = (command, cwd = undefined) => +export const execAsync = (command, cwd = undefined, options = { showLog: false }) => new Promise((resolve, reject) => { const child = childProcess.spawn(command, { cwd, shell: true }); let out = ''; child.stdout.setEncoding('utf8'); child.stdout.on('data', function (data) { - out += 'stdout: ' + data.toString(); + if (options?.showLog) stdout(data); + else out += 'stdout: ' + data.toString(); }); child.stderr.setEncoding('utf8'); child.stderr.on('data', function (data) { - out += 'stderr: ' + data.toString(); + if (options?.showLog) stderr(data); + else out += 'stderr: ' + data.toString(); }); child.on('error', (e) => { + if (options?.showLog) return; console.log(out); console.log(e); }); diff --git a/scripts/publish.js b/scripts/publish.js new file mode 100644 index 0000000..2984d85 --- /dev/null +++ b/scripts/publish.js @@ -0,0 +1,9 @@ +import { execAsync, packages } from './packages'; + +for (const pkg of packages) { + await execAsync( + `npx --no-install semantic-release -e semantic-release-monorepo`, + `packages/${pkg}`, + { showLog: true } + ); +} From 39847fd3e7e83bf5217a6efa4732b0a2c3d4f717 Mon Sep 17 00:00:00 2001 From: BearToCode Date: Tue, 7 Nov 2023 15:06:18 +0100 Subject: [PATCH 004/127] ci: fix publish script --- scripts/packages.js | 4 ++-- scripts/publish.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/packages.js b/scripts/packages.js index 5cbccb1..29f6705 100644 --- a/scripts/packages.js +++ b/scripts/packages.js @@ -8,13 +8,13 @@ export const execAsync = (command, cwd = undefined, options = { showLog: false } child.stdout.setEncoding('utf8'); child.stdout.on('data', function (data) { - if (options?.showLog) stdout(data); + if (options?.showLog) stdout.write(data); else out += 'stdout: ' + data.toString(); }); child.stderr.setEncoding('utf8'); child.stderr.on('data', function (data) { - if (options?.showLog) stderr(data); + if (options?.showLog) stderr.write(data); else out += 'stderr: ' + data.toString(); }); diff --git a/scripts/publish.js b/scripts/publish.js index 2984d85..e8764c6 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -1,9 +1,9 @@ -import { execAsync, packages } from './packages'; +import { execAsync, packages } from './packages.js'; for (const pkg of packages) { await execAsync( `npx --no-install semantic-release -e semantic-release-monorepo`, - `packages/${pkg}`, + `./packages/${pkg}`, { showLog: true } ); } From 03ad622870bdda4183d5da7fb4f550d920254998 Mon Sep 17 00:00:00 2001 From: BearToCode Date: Tue, 7 Nov 2023 17:55:32 +0100 Subject: [PATCH 005/127] docs: update links after renaming repo --- README.md | 20 ++++++++++---------- demo/package.json | 2 +- demo/src/routes/placeholder.ts | 2 +- demo/svelte.config.js | 2 +- package.json | 2 +- packages/carta-md/README.md | 20 ++++++++++---------- packages/carta-md/package.json | 2 +- packages/plugin-attachment/package.json | 2 +- packages/plugin-code/package.json | 2 +- packages/plugin-emoji/package.json | 2 +- packages/plugin-math/package.json | 2 +- packages/plugin-slash/package.json | 2 +- packages/plugin-tikz/package.json | 2 +- 13 files changed, 31 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 3cd09a4..176bfe2 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@
npm bundle - license + license demo
@@ -92,20 +92,20 @@ Editor component exported properties: Each plugin's _readme_ includes a guide on its use. -| Name | Description | -| -------------------------------------------------------------------------------------------------- | --------------------------------------- | -| [plugin-math](https://github.com/BearToCode/carta-md/tree/master/packages/plugin-math) | Katex support | -| [plugin-slash](https://github.com/BearToCode/carta-md/tree/master/packages/plugin-slash) | Slash commands support | -| [plugin-emoji](https://github.com/BearToCode/carta-md/tree/master/packages/plugin-emoji) | Emojis support, including inline search | -| [plugin-code](https://github.com/BearToCode/carta-md/tree/master/packages/plugin-code) | Code blocks syntax highlighting | -| [plugin-tikz](https://github.com/BearToCode/carta-md/tree/master/packages/plugin-tikz) | TikZ support using TikZJax | -| [plugin-attachment](https://github.com/BearToCode/carta-md/tree/master/packages/plugin-attachment) | Attachments support | +| Name | Description | +| ----------------------------------------------------------------------------------------------- | --------------------------------------- | +| [plugin-math](https://github.com/BearToCode/carta/tree/master/packages/plugin-math) | Katex support | +| [plugin-slash](https://github.com/BearToCode/carta/tree/master/packages/plugin-slash) | Slash commands support | +| [plugin-emoji](https://github.com/BearToCode/carta/tree/master/packages/plugin-emoji) | Emojis support, including inline search | +| [plugin-code](https://github.com/BearToCode/carta/tree/master/packages/plugin-code) | Code blocks syntax highlighting | +| [plugin-tikz](https://github.com/BearToCode/carta/tree/master/packages/plugin-tikz) | TikZ support using TikZJax | +| [plugin-attachment](https://github.com/BearToCode/carta/tree/master/packages/plugin-attachment) | Attachments support | ## Themes customization By using the `theme` property in `CartaEditor` and `CartaPreview` you can change their classes to `carta-editor__{theme}` and `carta-viewer__{theme}`. -Check out the [default theme](https://github.com/BearToCode/carta-md/blob/master/packages/carta-md/src/lib/default-theme.css) to customize it. +Check out the [default theme](https://github.com/BearToCode/carta/blob/master/packages/carta-md/src/lib/default-theme.css) to customize it. If you are using a plugin, look at its _readme_ for its customization. diff --git a/demo/package.json b/demo/package.json index a4f1d50..892ece0 100644 --- a/demo/package.json +++ b/demo/package.json @@ -5,7 +5,7 @@ "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/BearToCode/carta-md.git" + "url": "git+https://github.com/BearToCode/carta.git" }, "scripts": { "dev": "vite dev", diff --git a/demo/src/routes/placeholder.ts b/demo/src/routes/placeholder.ts index 567dde5..3731509 100644 --- a/demo/src/routes/placeholder.ts +++ b/demo/src/routes/placeholder.ts @@ -30,7 +30,7 @@ Orbiting this at a distance of roughly _ninety-two million miles_ is an utterly # Basic Markdown -You can have different types of text: **bold**, _italic_, \`code\` and ~~strikethrough~~. This is a [link](http://beartocode.github.io/carta-md/) to the page you are currently viewing. +You can have different types of text: **bold**, _italic_, \`code\` and ~~strikethrough~~. This is a [link](http://beartocode.github.io/carta/) to the page you are currently viewing. Here is a quote: diff --git a/demo/svelte.config.js b/demo/svelte.config.js index 9fc3ba8..c3da9f2 100644 --- a/demo/svelte.config.js +++ b/demo/svelte.config.js @@ -13,7 +13,7 @@ const config = { assets: 'build' }), paths: { - base: process.env.NODE_ENV === 'production' ? '/carta-md' : '' + base: process.env.NODE_ENV === 'production' ? '/carta' : '' } } }; diff --git a/package.json b/package.json index d978986..f525ec7 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/BearToCode/carta-md.git" + "url": "git+https://github.com/BearToCode/carta.git" }, "scripts": { "preinstall": "npx only-allow pnpm", diff --git a/packages/carta-md/README.md b/packages/carta-md/README.md index 3cd09a4..176bfe2 100644 --- a/packages/carta-md/README.md +++ b/packages/carta-md/README.md @@ -7,7 +7,7 @@
npm bundle - license + license demo
@@ -92,20 +92,20 @@ Editor component exported properties: Each plugin's _readme_ includes a guide on its use. -| Name | Description | -| -------------------------------------------------------------------------------------------------- | --------------------------------------- | -| [plugin-math](https://github.com/BearToCode/carta-md/tree/master/packages/plugin-math) | Katex support | -| [plugin-slash](https://github.com/BearToCode/carta-md/tree/master/packages/plugin-slash) | Slash commands support | -| [plugin-emoji](https://github.com/BearToCode/carta-md/tree/master/packages/plugin-emoji) | Emojis support, including inline search | -| [plugin-code](https://github.com/BearToCode/carta-md/tree/master/packages/plugin-code) | Code blocks syntax highlighting | -| [plugin-tikz](https://github.com/BearToCode/carta-md/tree/master/packages/plugin-tikz) | TikZ support using TikZJax | -| [plugin-attachment](https://github.com/BearToCode/carta-md/tree/master/packages/plugin-attachment) | Attachments support | +| Name | Description | +| ----------------------------------------------------------------------------------------------- | --------------------------------------- | +| [plugin-math](https://github.com/BearToCode/carta/tree/master/packages/plugin-math) | Katex support | +| [plugin-slash](https://github.com/BearToCode/carta/tree/master/packages/plugin-slash) | Slash commands support | +| [plugin-emoji](https://github.com/BearToCode/carta/tree/master/packages/plugin-emoji) | Emojis support, including inline search | +| [plugin-code](https://github.com/BearToCode/carta/tree/master/packages/plugin-code) | Code blocks syntax highlighting | +| [plugin-tikz](https://github.com/BearToCode/carta/tree/master/packages/plugin-tikz) | TikZ support using TikZJax | +| [plugin-attachment](https://github.com/BearToCode/carta/tree/master/packages/plugin-attachment) | Attachments support | ## Themes customization By using the `theme` property in `CartaEditor` and `CartaPreview` you can change their classes to `carta-editor__{theme}` and `carta-viewer__{theme}`. -Check out the [default theme](https://github.com/BearToCode/carta-md/blob/master/packages/carta-md/src/lib/default-theme.css) to customize it. +Check out the [default theme](https://github.com/BearToCode/carta/blob/master/packages/carta-md/src/lib/default-theme.css) to customize it. If you are using a plugin, look at its _readme_ for its customization. diff --git a/packages/carta-md/package.json b/packages/carta-md/package.json index 4048048..2bca0d2 100644 --- a/packages/carta-md/package.json +++ b/packages/carta-md/package.json @@ -6,7 +6,7 @@ "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/BearToCode/carta-md.git" + "url": "git+https://github.com/BearToCode/carta.git" }, "exports": { ".": { diff --git a/packages/plugin-attachment/package.json b/packages/plugin-attachment/package.json index 253d6e8..4ac6bc3 100644 --- a/packages/plugin-attachment/package.json +++ b/packages/plugin-attachment/package.json @@ -16,7 +16,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/BearToCode/carta-md.git" + "url": "git+https://github.com/BearToCode/carta.git" }, "exports": { ".": { diff --git a/packages/plugin-code/package.json b/packages/plugin-code/package.json index 2cc8e3e..d2589e7 100644 --- a/packages/plugin-code/package.json +++ b/packages/plugin-code/package.json @@ -6,7 +6,7 @@ "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/BearToCode/carta-md.git" + "url": "git+https://github.com/BearToCode/carta.git" }, "exports": { ".": "./dist/index.js", diff --git a/packages/plugin-emoji/package.json b/packages/plugin-emoji/package.json index fd8d12c..0a3c3a9 100644 --- a/packages/plugin-emoji/package.json +++ b/packages/plugin-emoji/package.json @@ -16,7 +16,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/BearToCode/carta-md.git" + "url": "git+https://github.com/BearToCode/carta.git" }, "exports": { ".": { diff --git a/packages/plugin-math/package.json b/packages/plugin-math/package.json index d0ac80a..68d9e82 100644 --- a/packages/plugin-math/package.json +++ b/packages/plugin-math/package.json @@ -6,7 +6,7 @@ "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/BearToCode/carta-md.git" + "url": "git+https://github.com/BearToCode/carta.git" }, "exports": { ".": { diff --git a/packages/plugin-slash/package.json b/packages/plugin-slash/package.json index 317bca2..415d4db 100644 --- a/packages/plugin-slash/package.json +++ b/packages/plugin-slash/package.json @@ -16,7 +16,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/BearToCode/carta-md.git" + "url": "git+https://github.com/BearToCode/carta.git" }, "exports": { ".": { diff --git a/packages/plugin-tikz/package.json b/packages/plugin-tikz/package.json index 1cf5637..fad3d25 100644 --- a/packages/plugin-tikz/package.json +++ b/packages/plugin-tikz/package.json @@ -6,7 +6,7 @@ "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/BearToCode/carta-md.git" + "url": "git+https://github.com/BearToCode/carta.git" }, "exports": { ".": { From f1be96caec852c0f99cbb383badd9d4041b38edf Mon Sep 17 00:00:00 2001 From: BearToCode Date: Tue, 7 Nov 2023 17:56:45 +0100 Subject: [PATCH 006/127] docs: update demo links --- README.md | 4 ++-- packages/carta-md/README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 176bfe2..55bb385 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,12 @@ npm bundle license - demo + demo
-Carta is a **lightweight**, **fast** and **extensible** Svelte Markdown editor and viewer, based on [Marked](https://github.com/markedjs/marked). Check out the [demo](http://beartocode.github.io/carta-md/) to see it in action. +Carta is a **lightweight**, **fast** and **extensible** Svelte Markdown editor and viewer, based on [Marked](https://github.com/markedjs/marked). Check out the [demo](http://beartocode.github.io/carta/) to see it in action. Differently from most editors, Carta includes neither ProseMirror nor CodeMirror, allowing for an extremely small bundle size and fast loading time. ## Features diff --git a/packages/carta-md/README.md b/packages/carta-md/README.md index 176bfe2..55bb385 100644 --- a/packages/carta-md/README.md +++ b/packages/carta-md/README.md @@ -8,12 +8,12 @@ npm bundle license - demo + demo
-Carta is a **lightweight**, **fast** and **extensible** Svelte Markdown editor and viewer, based on [Marked](https://github.com/markedjs/marked). Check out the [demo](http://beartocode.github.io/carta-md/) to see it in action. +Carta is a **lightweight**, **fast** and **extensible** Svelte Markdown editor and viewer, based on [Marked](https://github.com/markedjs/marked). Check out the [demo](http://beartocode.github.io/carta/) to see it in action. Differently from most editors, Carta includes neither ProseMirror nor CodeMirror, allowing for an extremely small bundle size and fast loading time. ## Features From a503558671c457300d5833cc2b2b8351501e924f Mon Sep 17 00:00:00 2001 From: BearToCode Date: Sat, 11 Nov 2023 10:57:30 +0100 Subject: [PATCH 007/127] build: match carta-md major version BREAKING CHANGE: match carta-md major version --- packages/plugin-code/package.json | 2 +- packages/plugin-emoji/package.json | 2 +- packages/plugin-math/package.json | 2 +- packages/plugin-slash/package.json | 2 +- packages/plugin-tikz/package.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/plugin-code/package.json b/packages/plugin-code/package.json index d2589e7..0435842 100644 --- a/packages/plugin-code/package.json +++ b/packages/plugin-code/package.json @@ -23,7 +23,7 @@ "marked": "^9.1.5" }, "peerDependencies": { - "carta-md": "^2.8.0" + "carta-md": "^3.0.0" }, "files": [ "dist" diff --git a/packages/plugin-emoji/package.json b/packages/plugin-emoji/package.json index 0a3c3a9..19cc986 100644 --- a/packages/plugin-emoji/package.json +++ b/packages/plugin-emoji/package.json @@ -38,7 +38,7 @@ "node-emoji": "^1.11.0" }, "peerDependencies": { - "carta-md": "^2.8.0", + "carta-md": "^3.0.0", "marked": "^9.1.5", "svelte": "^3.54.0 || ^4.0.0" }, diff --git a/packages/plugin-math/package.json b/packages/plugin-math/package.json index 68d9e82..119ea93 100644 --- a/packages/plugin-math/package.json +++ b/packages/plugin-math/package.json @@ -23,7 +23,7 @@ "marked": "^9.1.5" }, "peerDependencies": { - "carta-md": "^2.8.0", + "carta-md": "^3.0.0", "katex": "^0.16.7", "marked": "^9.1.5" }, diff --git a/packages/plugin-slash/package.json b/packages/plugin-slash/package.json index 415d4db..8e33114 100644 --- a/packages/plugin-slash/package.json +++ b/packages/plugin-slash/package.json @@ -37,7 +37,7 @@ "bezier-easing": "^2.1.0" }, "peerDependencies": { - "carta-md": "^2.8.0", + "carta-md": "^3.0.0", "svelte": "^3.54.0 || ^4.0.0" }, "devDependencies": { diff --git a/packages/plugin-tikz/package.json b/packages/plugin-tikz/package.json index fad3d25..202e69a 100644 --- a/packages/plugin-tikz/package.json +++ b/packages/plugin-tikz/package.json @@ -30,7 +30,7 @@ "marked": "^9.1.5" }, "peerDependencies": { - "carta-md": "^2.8.0", + "carta-md": "^3.0.0", "marked": "^9.1.5" }, "files": [ From 06eebf8c93524fbc525930e8953035c4ebfe2cc9 Mon Sep 17 00:00:00 2001 From: BearToCode Date: Sat, 11 Nov 2023 10:58:45 +0100 Subject: [PATCH 008/127] build(plugin-attachment): update carta-md peer dependency version --- packages/plugin-attachment/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-attachment/package.json b/packages/plugin-attachment/package.json index 4ac6bc3..a396b4c 100644 --- a/packages/plugin-attachment/package.json +++ b/packages/plugin-attachment/package.json @@ -34,7 +34,7 @@ "!dist/**/*.spec.*" ], "peerDependencies": { - "carta-md": "^2.8.0", + "carta-md": "^3.0.0", "marked": "^9.1.5", "svelte": "^3.54.0 || ^4.0.0" }, From 0b9606e6cbe74e6db2c5256265ef71a002627327 Mon Sep 17 00:00:00 2001 From: BearToCode Date: Sat, 11 Nov 2023 11:19:52 +0100 Subject: [PATCH 009/127] refactor: use consistent file name for default styles --- README.md | 4 ++-- demo/src/routes/+page.svelte | 6 +++--- packages/carta-md/README.md | 4 ++-- packages/carta-md/package.json | 3 ++- .../carta-md/src/lib/{default-theme.css => default.css} | 0 packages/carta-md/src/lib/index.ts | 2 +- packages/carta-md/src/routes/+page.svelte | 2 +- packages/plugin-attachment/src/routes/+page.svelte | 2 +- packages/plugin-emoji/README.md | 2 +- packages/plugin-emoji/package.json | 6 ++---- .../plugin-emoji/src/lib/{default-theme.css => default.css} | 0 packages/plugin-emoji/src/lib/index.ts | 2 +- packages/plugin-emoji/src/routes/+page.svelte | 4 ++-- packages/plugin-slash/README.md | 2 +- packages/plugin-slash/package.json | 6 ++---- .../plugin-slash/src/lib/{default-theme.css => default.css} | 0 packages/plugin-slash/src/lib/index.ts | 2 +- packages/plugin-slash/src/routes/+page.svelte | 4 ++-- 18 files changed, 24 insertions(+), 27 deletions(-) rename packages/carta-md/src/lib/{default-theme.css => default.css} (100%) rename packages/plugin-emoji/src/lib/{default-theme.css => default.css} (100%) rename packages/plugin-slash/src/lib/{default-theme.css => default.css} (100%) diff --git a/README.md b/README.md index 55bb385..5be5154 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ npm i @cartamd/plugin-name + * + *
+ * + *
+ * + * ``` + */ + public bindToCaret( + element: HTMLElement, + portal = document.querySelector('body') as HTMLBodyElement + ) { + if (this.input) { + return this.input.$bindToCaret(element, portal); + } else { + let callback: (() => void) | undefined; + + // Bind the element later, when the input is ready + this.elementsToBind.push({ elem: element, portal, callback }); + + return { + destroy() { + if (callback) { + callback(); + } + } + }; + } + } } diff --git a/packages/carta-md/src/lib/internal/input.ts b/packages/carta-md/src/lib/internal/input.ts index de3ea9c..39ba4e3 100644 --- a/packages/carta-md/src/lib/internal/input.ts +++ b/packages/carta-md/src/lib/internal/input.ts @@ -1,7 +1,7 @@ import type { CartaListener } from './carta'; -import { CartaHistory, type CartaHistoryOptions } from './history'; import type { Prefix } from './prefixes'; import type { KeyboardShortcut } from './shortcuts'; +import { CartaHistory, type CartaHistoryOptions } from './history'; import { areEqualSets } from './utils'; /** @@ -22,16 +22,17 @@ export interface InputSettings { readonly prefixes: Prefix[]; // eslint-disable-next-line @typescript-eslint/no-explicit-any readonly listeners: CartaListener[]; - readonly callback: () => void; readonly historyOpts?: Partial; } export class CartaInput { private pressedKeys: Set; - public readonly history: CartaHistory; // Used to detect keys that actually changed the textarea value private onKeyDownValue: string | undefined; + public readonly history: CartaHistory; + public readonly events = new EventTarget(); + constructor( public readonly textarea: HTMLTextAreaElement, public readonly container: HTMLDivElement, @@ -113,7 +114,7 @@ export class CartaInput { // Save state for shortcuts if (!shortcut.preventSave) this.history.saveState(this.textarea.value, this.textarea.selectionStart); - this.settings.callback(); + this.update(); } this.onKeyDownValue = undefined; @@ -166,14 +167,14 @@ export class CartaInput { const line = this.getLine(lineStartingIndex); this.removeAt(lineStartingIndex, line.value.length); this.textarea.setSelectionRange(line.start, line.start); - this.settings.callback(); + this.update(); return; } const newPrefix = prefix.maker(match, line); this.insertAt(cursor, '\n' + newPrefix); - this.settings.callback(); + this.update(); // Update cursor position const newCursorPosition = cursor + newPrefix.length + 1; this.textarea.setSelectionRange(newCursorPosition, newCursorPosition); @@ -317,7 +318,7 @@ export class CartaInput { /** * Update the textarea. */ - public update = () => this.settings.callback(); + public update = () => this.events.dispatchEvent(new Event('update')); /** * Returns x, y coordinates for absolute positioning of a span within a given text input @@ -364,7 +365,7 @@ export class CartaInput { /** * Moves an element next to the caret. Shall be called every time the element - * changes width, height or the caret position changes. + * changes width, height or the caret position changes. Consider using `bindToCaret` instead. * * @example * ```svelte @@ -437,6 +438,71 @@ export class CartaInput { elem.style.bottom = bottom !== undefined ? bottom + 'px' : 'unset'; } + /** + * **Internal**: Svelte action to bind an element to the caret position. + * Use `bindToCaret` from the `carta` instance instead. + * @param elem The element to position. + * @param portal The portal to append the element to. Defaults to `document.body`. + */ + public $bindToCaret(elem: HTMLElement, portal: HTMLElement) { + // Move the element to body + portal.appendChild(elem); + elem.style.position = 'absolute'; + + const callback = () => { + const relativePosition = this.getCursorXY(); + const absolutePosition = { + x: relativePosition.x + this.textarea.getBoundingClientRect().left, + y: relativePosition.y + this.textarea.getBoundingClientRect().top + }; + + const fontSize = this.getRowHeight(); + const width = elem.clientWidth; + const height = elem.clientHeight; + + // Left/Right + let left: number | undefined = absolutePosition.x; + let right: number | undefined; + + if (left + width >= window.innerWidth) { + right = window.innerWidth - left; + left = undefined; + } + + // Top/Bottom + let top: number | undefined = absolutePosition.y; + let bottom: number | undefined; + + if (top + height >= window.innerHeight) { + bottom = window.innerHeight - top; + top = undefined; + } + + elem.style.left = left !== undefined ? left + 'px' : 'unset'; + elem.style.right = right !== undefined ? right + 'px' : 'unset'; + elem.style.top = top !== undefined ? top + fontSize + 'px' : 'unset'; + elem.style.bottom = bottom !== undefined ? bottom + 'px' : 'unset'; + }; + + this.textarea.addEventListener('input', callback); + window.addEventListener('resize', callback); + + // Initial positioning + callback(); + + return { + destroy: () => { + try { + portal.removeChild(elem); + } catch (e: unknown) { + // Ignore + } + this.textarea.removeEventListener('input', callback); + window.removeEventListener('resize', callback); + } + }; + } + /** * Get rough value for a row of the textarea. */ diff --git a/packages/carta-md/src/lib/internal/utils.ts b/packages/carta-md/src/lib/internal/utils.ts index 538d31d..3d1ce8b 100644 --- a/packages/carta-md/src/lib/internal/utils.ts +++ b/packages/carta-md/src/lib/internal/utils.ts @@ -53,3 +53,13 @@ export function mergeDefaultInterface( }); return final; } + +// Node does not implement CustomEvent until v19, so we +// "declare" it ourself for backward compatibility. +export class CustomEvent extends Event { + detail: T; + constructor(message: string, data: EventInit & { detail: T }) { + super(message, data); + this.detail = data.detail; + } +} From 1db7fc42b7ea973f019f7ba5693dfe9072ecaad3 Mon Sep 17 00:00:00 2001 From: BearToCode Date: Tue, 14 Nov 2023 18:31:24 +0100 Subject: [PATCH 014/127] fix: tsconfig TS6310 may not disable emit --- tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index d944659..d8ac207 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,5 +15,6 @@ "outDir": "./dist", "module": "ESNext", "target": "ESNext" - } + }, + "files": [] } From 20bc2819c91bb8da604ea6551cece6d5c7935355 Mon Sep 17 00:00:00 2001 From: BearToCode Date: Tue, 14 Nov 2023 18:37:19 +0100 Subject: [PATCH 015/127] fix: remove typescript project references --- packages/plugin-code/tsconfig.json | 3 +-- packages/plugin-math/tsconfig.json | 3 +-- packages/plugin-tikz/tsconfig.json | 3 +-- packages/tsconfig.json | 11 ----------- 4 files changed, 3 insertions(+), 17 deletions(-) delete mode 100644 packages/tsconfig.json diff --git a/packages/plugin-code/tsconfig.json b/packages/plugin-code/tsconfig.json index 0d0b887..ae53f4c 100644 --- a/packages/plugin-code/tsconfig.json +++ b/packages/plugin-code/tsconfig.json @@ -5,6 +5,5 @@ "rootDir": "src", "typeRoots": ["./node_modules/@types"] }, - "include": ["./src"], - "references": [{ "path": "../carta-md" }] + "include": ["./src"] } diff --git a/packages/plugin-math/tsconfig.json b/packages/plugin-math/tsconfig.json index 6b69ac1..6b8bc7f 100644 --- a/packages/plugin-math/tsconfig.json +++ b/packages/plugin-math/tsconfig.json @@ -5,6 +5,5 @@ "rootDir": "src", "typeRoots": ["./node_modules/@types"] }, - "include": ["./src"], - "references": [{ "path": "../carta-md" }] + "include": ["./src"] } diff --git a/packages/plugin-tikz/tsconfig.json b/packages/plugin-tikz/tsconfig.json index 6b69ac1..6b8bc7f 100644 --- a/packages/plugin-tikz/tsconfig.json +++ b/packages/plugin-tikz/tsconfig.json @@ -5,6 +5,5 @@ "rootDir": "src", "typeRoots": ["./node_modules/@types"] }, - "include": ["./src"], - "references": [{ "path": "../carta-md" }] + "include": ["./src"] } diff --git a/packages/tsconfig.json b/packages/tsconfig.json deleted file mode 100644 index dc1da2c..0000000 --- a/packages/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "references": [ - { "path": "carta-md" }, - { "path": "plugin-math" }, - { "path": "plugin-emoji" }, - { "path": "plugin-slash" }, - { "path": "plugin-code" }, - { "path": "plugin-tikz" }, - { "path": "plugin-attachment" } - ] -} From e5e4ad4f06859cd03c081d91ecb26fa260b055fd Mon Sep 17 00:00:00 2001 From: BearToCode Date: Tue, 14 Nov 2023 18:44:18 +0100 Subject: [PATCH 016/127] feat: better caret-bounded components positioning --- packages/plugin-emoji/package.json | 2 +- packages/plugin-emoji/src/lib/Emoji.svelte | 11 +---------- packages/plugin-slash/package.json | 2 +- packages/plugin-slash/src/lib/Slash.svelte | 16 ++-------------- 4 files changed, 5 insertions(+), 26 deletions(-) diff --git a/packages/plugin-emoji/package.json b/packages/plugin-emoji/package.json index ca11132..35f5779 100644 --- a/packages/plugin-emoji/package.json +++ b/packages/plugin-emoji/package.json @@ -36,7 +36,7 @@ "node-emoji": "^1.11.0" }, "peerDependencies": { - "carta-md": "^3.0.0", + "carta-md": "^3.1.0", "marked": "^9.1.5", "svelte": "^3.54.0 || ^4.0.0" }, diff --git a/packages/plugin-emoji/src/lib/Emoji.svelte b/packages/plugin-emoji/src/lib/Emoji.svelte index 7ff9a23..0f910b1 100644 --- a/packages/plugin-emoji/src/lib/Emoji.svelte +++ b/packages/plugin-emoji/src/lib/Emoji.svelte @@ -12,7 +12,6 @@ export let outTransition: (node: Element) => TransitionConfig; let visible = false; - let caretPosition = { left: 0, right: 0, top: 0, bottom: 0 }; let filter = ''; let colonPosition = 0; let hoveringIndex = 0; @@ -75,7 +74,6 @@ } else if (e.key === ':') { // Open visible = true; - caretPosition = carta.input.getCursorXY(); colonPosition = carta.input.textarea.selectionStart; filter = ''; } @@ -107,14 +105,6 @@ carta.input.update(); } - $: { - if (elem) { - // Make statement reactive - caretPosition, elem.clientWidth, elem.clientHeight; - carta.input?.moveElemToCaret(elem); - } - } - $: { // Scroll to make hovering emoji always visible const hovering = emojisElements.at(hoveringIndex); @@ -135,6 +125,7 @@ bind:this={elem} in:inTransition out:outTransition + use:carta.bindToCaret > {#each emojis as emoji, i} + + + + +
+
+
+
+