@simple-mark/codemirror 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,7 +19,11 @@ const view = createEditor(document.getElementById('editor')!, {
19
19
  table. Korean, Chinese and Japanese line up (drawn exactly two columns wide), and typing
20
20
  them with an IME is safe.
21
21
  - **Images** and `$$` math preview below their source; `$inline$` math in a tooltip. Math
22
- (`@simple-mark/math`) loads only when a document has math.
22
+ (`@simple-mark/math`) loads only when a document has math; when bundling, alias MathJax's
23
+ `#default-font/*` as its README shows, so MathJax's default font isn't bundled.
24
+ - **Colors** in fenced code blocks, as VS Code's Markdown preview colors them
25
+ (`@simple-mark/highlight`, highlight.js; each language loads when a block needs it), and
26
+ in TeX: commands, brackets by nesting depth, an unmatched brace in red.
23
27
  - **Links**: Ctrl+Click (⌘+Click on macOS) follows a link — a plain click keeps placing the
24
28
  cursor, since links are editable text. `#heading` links jump within the document; other
25
29
  schemes than http(s)/mailto are refused; web pages and paths go to `openLink` (default: a
@@ -28,4 +32,4 @@ const view = createEditor(document.getElementById('editor')!, {
28
32
  - Accurate scroll heights for documents with many images and formulas.
29
33
  - `simpleMark(theme)` gives the extensions for your own `EditorState`.
30
34
 
31
- MIT
35
+ MIT. Values copied from other projects are credited in `THIRD_PARTY_NOTICES.txt`.
@@ -0,0 +1,23 @@
1
+ @simple-mark/codemirror: third-party notices
2
+
3
+ @simple-mark/codemirror is MIT-licensed (see LICENSE). Its dependencies come with their own licenses;
4
+ it copies the values described below from these projects.
5
+
6
+ ==============================================================================
7
+ DESIGN REFERENCES: values copied into this code
8
+ ==============================================================================
9
+
10
+ github-markdown-css (MIT)
11
+ https://github.com/sindresorhus/github-markdown-css
12
+ Used for:
13
+ - codemirror: Error and loading message colors (src/previews.ts).
14
+
15
+ MIT License
16
+
17
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
18
+
19
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/index.d.ts CHANGED
@@ -42,11 +42,15 @@ export declare const markdownTheme: Facet<Theme, Theme>;
42
42
  /** A look as an inline CSS declaration list. */
43
43
  export declare function lookCss(look: ResolvedLineLook, theme: Theme): string;
44
44
  declare class MarkdownDecorations {
45
+ private view;
45
46
  decorations: DecorationSet;
46
47
  private theme;
47
48
  private fixWide;
48
49
  private cache;
50
+ private destroyed;
51
+ private highlight;
49
52
  constructor(view: EditorView);
53
+ destroy(): void;
50
54
  update(update: ViewUpdate): void;
51
55
  private build;
52
56
  /**
package/index.js CHANGED
@@ -4,6 +4,7 @@ import { EditorState, Facet, Prec, StateEffect, StateField } from "@codemirror/s
4
4
  import { Decoration, EditorView, ViewPlugin, WidgetType, hoverTooltip, keymap, showTooltip } from "@codemirror/view";
5
5
  import { STROKES, cellAt, charWidth, defaultTheme, headingAnchors, linkAt, linkKind, markdownExtensions, markdownStyles, mathSource, parseTable, previewBlocks, renderTable, resolveLineLook, resolveLook, rowLine } from "@simple-mark/model";
6
6
  import { ensureSyntaxTree, syntaxTree } from "@codemirror/language";
7
+ import { createHighlighter } from "@simple-mark/highlight";
7
8
  //#region packages/codemirror/src/image-resolver.ts
8
9
  /** The URLs a resolver gives for `src`, in order; undefined while the host is still loading. */
9
10
  function resolvedUrls(resolve, src) {
@@ -173,33 +174,47 @@ function cjkFitsColumns(family) {
173
174
  return fits;
174
175
  }
175
176
  const headingText = Decoration.mark({ class: "sm-heading-text" });
177
+ /** A code block's language has loaded: draw its colors. */
178
+ const languageLoaded = StateEffect.define();
176
179
  /** The lines holding a cursor, as a comparable string. */
177
180
  function cursorLinesKey(state) {
178
181
  return state.selection.ranges.map((r) => state.doc.lineAt(r.head).from).join(",");
179
182
  }
180
183
  var MarkdownDecorations = class {
184
+ view;
181
185
  decorations;
182
186
  theme;
183
187
  fixWide;
184
188
  cache = /* @__PURE__ */ new Map();
189
+ destroyed = false;
190
+ highlight = createHighlighter(() => {
191
+ if (!this.destroyed) this.view.dispatch({ effects: languageLoaded.of(null) });
192
+ });
185
193
  constructor(view) {
194
+ this.view = view;
186
195
  this.theme = view.state.facet(markdownTheme);
187
196
  this.fixWide = !cjkFitsColumns(this.theme.monospaceFamily);
188
197
  this.decorations = this.build(view);
189
198
  }
199
+ destroy() {
200
+ this.destroyed = true;
201
+ }
190
202
  update(update) {
191
203
  const theme = update.state.facet(markdownTheme);
192
204
  if (theme !== this.theme) {
193
205
  this.theme = theme;
194
206
  this.fixWide = !cjkFitsColumns(theme.monospaceFamily);
195
207
  this.cache.clear();
196
- } else if (!update.docChanged && !update.viewportChanged && syntaxTree(update.state) === syntaxTree(update.startState) && !(this.fixWide && update.selectionSet && cursorLinesKey(update.state) !== cursorLinesKey(update.startState))) return;
208
+ } else if (!update.docChanged && !update.viewportChanged && syntaxTree(update.state) === syntaxTree(update.startState) && !update.transactions.some((tr) => tr.effects.some((e) => e.is(languageLoaded))) && !(this.fixWide && update.selectionSet && cursorLinesKey(update.state) !== cursorLinesKey(update.startState))) return;
197
209
  this.decorations = this.build(update.view);
198
210
  }
199
211
  build(view) {
200
212
  const { doc } = view.state;
201
213
  const { from, to } = view.viewport;
202
- const { blocks, spans } = markdownStyles(syntaxTree(view.state), from, to);
214
+ const { blocks, spans } = markdownStyles(syntaxTree(view.state), from, to, {
215
+ slice: (a, b) => doc.sliceString(a, b),
216
+ highlight: this.highlight
217
+ });
203
218
  /** Block styles of each line, and the styles whose block starts or ends there. */
204
219
  const lines = /* @__PURE__ */ new Map();
205
220
  for (const block of blocks) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simple-mark/codemirror",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "CodeMirror 6 editor that styles Markdown without hiding its syntax.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -28,7 +28,8 @@
28
28
  "@codemirror/state": "^6.7.6",
29
29
  "@codemirror/view": "^6.43.15",
30
30
  "@lezer/common": "^1.5.3",
31
- "@simple-mark/math": "^0.3.5",
32
- "@simple-mark/model": "^0.3.5"
31
+ "@simple-mark/highlight": "^0.3.7",
32
+ "@simple-mark/math": "^0.3.7",
33
+ "@simple-mark/model": "^0.3.7"
33
34
  }
34
35
  }