@k2b/editor 0.10.0 → 0.11.0

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.
@@ -1,7 +1,7 @@
1
1
  import { i18n } from "@k2b/stdlib";
2
2
  import { CopyButton, IconButton, LocaleProvider, prepareChartSnapshot, toast } from "@k2b/ui";
3
3
  import { type ChartTooltip, inspectChart } from "@k2b/ui/chart-inspection";
4
- import { calendarInspectionNavigation, mountCalendarScroll, sankeyInspectionNavigation } from "@k2b/ui/charts";
4
+ import { calendarInspectionNavigation, mountBalanceFlow, mountCalendarScroll, sankeyInspectionNavigation } from "@k2b/ui/charts";
5
5
  import { createSignal, onCleanup, Show } from "solid-js";
6
6
  import { render } from "solid-js/web";
7
7
  import { type ChartInput, type ChartTable, chartMarkKey, chartReferenceMark, chartRenderOptions, chartRows, chartTooltip } from "../charts";
@@ -106,6 +106,8 @@ function ChartControls(props: { figure: HTMLElement; viewport: HTMLElement; draw
106
106
  */
107
107
  export function enhanceNotebookCharts(root: HTMLElement, locale: string, options: Pick<MarkdownChartOptions, "schema">): () => void {
108
108
  const cleanups: (() => void)[] = [];
109
+ for (const frame of root.querySelectorAll<HTMLElement>("[data-balance-flow]:not([data-balance-mounted])"))
110
+ cleanups.push(mountBalanceFlow(frame, { locale }));
109
111
  for (const figure of root.querySelectorAll<HTMLElement>("figure.notebook-book-chart[data-chart]:not([data-enhanced])")) {
110
112
  const chart = figure.querySelector<HTMLElement>(".notebook-book-chart__viewport > .k2b-chart");
111
113
  const viewport = chart?.parentElement;
@@ -58,7 +58,15 @@ import { Decoration, type DecorationSet, EditorView, keymap, WidgetType } from "
58
58
  import { i18n } from "@k2b/stdlib";
59
59
  import { clipboard } from "@k2b/stdlib/browser";
60
60
  import { type EvalContext, type EvalResult, evaluateFormula, isFormula } from "../formula";
61
- import { holdsDecorations, refreshMarkdownDecorationsEffect, selectionIntersectsRange, treeOrDocChanged } from "./_lib/cursor-zone-field";
61
+ import {
62
+ holdsDecorations,
63
+ markdownEditorFocused,
64
+ placeMarkdownCaret,
65
+ refreshesMarkdownDecorations,
66
+ revealedSelection,
67
+ selectionIntersectsRange,
68
+ treeOrDocChanged,
69
+ } from "./_lib/cursor-zone-field";
62
70
  import { splitTableLineCells, tableCellText } from "./_lib/table-cell";
63
71
  import { isNamedBlockHandle } from "./lib/named-blocks";
64
72
  import { applyLigatures } from "./ligatures";
@@ -322,7 +330,7 @@ class TableWidget extends WidgetType {
322
330
  }
323
331
  event.preventDefault();
324
332
  event.stopPropagation();
325
- view.dispatch({ selection: { anchor: this.fromPos } });
333
+ view.dispatch({ selection: { anchor: this.fromPos }, effects: placeMarkdownCaret.of() });
326
334
  view.focus();
327
335
  };
328
336
  // CM's default `dblclick` handler runs INDEPENDENTLY of mousedown.
@@ -423,8 +431,8 @@ type TablesState = {
423
431
  * This makes the table behave consistently regardless of approach
424
432
  * direction. */
425
433
  const cursorTableKey = (state: EditorState, ranges: TableRange[]): string | null => {
426
- if (ranges.length === 0) return null;
427
- const cursor = state.selection.main;
434
+ const cursor = revealedSelection(state)?.main;
435
+ if (ranges.length === 0 || !cursor) return null;
428
436
  const hits: number[] = [];
429
437
  for (const r of ranges) {
430
438
  const prevLineStart = state.doc.lineAt(Math.max(r.from - 1, 0)).from;
@@ -444,7 +452,7 @@ const scanTables = (state: EditorState, presentation: PrettyTableOptions): Table
444
452
  const decorations: Range<Decoration>[] = [];
445
453
  const blockWidgetDecorations: Range<Decoration>[] = [];
446
454
  const tableRanges: TableRange[] = [];
447
- const cursor = state.selection.main;
455
+ const cursor = revealedSelection(state)?.main;
448
456
 
449
457
  syntaxTree(state).iterate({
450
458
  enter: (node) => {
@@ -504,7 +512,7 @@ export const tablesExtension = (presentation: PrettyTableOptions = {}): Extensio
504
512
  return scanTables(state, presentation);
505
513
  },
506
514
  update(value, tr) {
507
- if (tr.effects.some((effect) => effect.is(refreshMarkdownDecorationsEffect))) {
515
+ if (refreshesMarkdownDecorations(tr)) {
508
516
  return scanTables(tr.state, presentation);
509
517
  }
510
518
  // Doc or syntax tree changed → tables may have appeared /
@@ -677,7 +685,7 @@ export const tablesExtension = (presentation: PrettyTableOptions = {}): Extensio
677
685
  // No view-level mousedown handler — the widget's own onmousedown
678
686
  // captures the click + stopPropagation prevents CM's internal
679
687
  // logic from running posAtDOM against widget-DOM targets.
680
- return [stateField, theme, tableNavKeymap];
688
+ return [markdownEditorFocused, stateField, theme, tableNavKeymap];
681
689
  };
682
690
 
683
691
  /** Check whether the document range [from, to] is covered by a
package/src/slash-menu.ts CHANGED
@@ -6,10 +6,12 @@ import {
6
6
  type CompletionSource,
7
7
  pickedCompletion,
8
8
  } from "@codemirror/autocomplete";
9
+ import { syntaxTree } from "@codemirror/language";
9
10
  import type { Extension } from "@codemirror/state";
10
11
  import { type EditorView, ViewPlugin } from "@codemirror/view";
11
12
  import { fuzzy } from "@k2b/stdlib";
12
13
  import type { EditorAction } from "./editor-state";
14
+ import { isInsideFencedCode } from "./markdown/editor-scope";
13
15
  import { caretIntoTableCell, tableCellCompletions } from "./table-cells";
14
16
 
15
17
  /** One entry of the slash menu: an editor action reached by typing `/` and its name. */
@@ -120,6 +122,12 @@ export const slashCompletionSource = (actions: SlashAction[]) => {
120
122
  const line = context.state.doc.lineAt(context.pos);
121
123
  const match = trigger.exec(line.text.slice(0, context.pos - line.from));
122
124
  if (!match) return null;
125
+ if (isInsideFencedCode(context)) return null;
126
+ for (let node = syntaxTree(context.state).resolveInner(context.pos, -1); ; ) {
127
+ if (node.name === "InlineCode") return null;
128
+ if (!node.parent) break;
129
+ node = node.parent;
130
+ }
123
131
  const typed = match[2] ?? "";
124
132
  const from = line.from + match.index + (match[1] ?? "").length;
125
133
  const enabled = actions.filter((action) => action.isEnabled?.(context.state) !== false);