@blankdotpage/cake 0.1.5 → 0.1.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.
@@ -3,6 +3,7 @@ import { type CakeExtension, type EditCommand } from "../core/runtime";
3
3
  import type { SelectionRect } from "./selection/selection-geometry";
4
4
  type EngineOptions = {
5
5
  container: HTMLElement;
6
+ contentRoot?: HTMLElement;
6
7
  value: string;
7
8
  selection?: Selection;
8
9
  extensions?: CakeExtension[];
@@ -24,8 +25,6 @@ export declare class CakeEngine {
24
25
  private runtime;
25
26
  private extensions;
26
27
  private _state;
27
- private originalCaretRangeFromPoint;
28
- private patchedCaretRangeFromPoint;
29
28
  private get state();
30
29
  private set state(value);
31
30
  private contentRoot;
@@ -69,6 +68,8 @@ export declare class CakeEngine {
69
68
  private handleCompositionStartBound;
70
69
  private handleCompositionEndBound;
71
70
  private handleSelectionChangeBound;
71
+ private handleFocusInBound;
72
+ private handleFocusOutBound;
72
73
  private handleScrollBound;
73
74
  private handleResizeBound;
74
75
  private handleClickBound;
@@ -101,7 +102,8 @@ export declare class CakeEngine {
101
102
  getFocusRect(): SelectionRect | null;
102
103
  getContainer(): HTMLElement;
103
104
  getContentRoot(): HTMLElement | null;
104
- getOverlayRoot(): HTMLDivElement | null;
105
+ getLines(): import("./selection/selection-layout").LineInfo[];
106
+ getOverlayRoot(): HTMLDivElement;
105
107
  syncPlaceholder(): void;
106
108
  insertText(text: string): void;
107
109
  replaceText(oldText: string, newText: string): void;
@@ -118,13 +120,15 @@ export declare class CakeEngine {
118
120
  redo(): void;
119
121
  canUndo(): boolean;
120
122
  canRedo(): boolean;
121
- executeCommand(command: EditCommand): boolean;
123
+ executeCommand(command: EditCommand, options?: {
124
+ restoreFocus?: boolean;
125
+ }): boolean;
122
126
  private attachListeners;
123
127
  private attachDragListeners;
124
128
  private detachDragListeners;
125
129
  private detachListeners;
126
- private installCaretRangeFromPointShim;
127
- private uninstallCaretRangeFromPointShim;
130
+ private handleFocusIn;
131
+ private handleFocusOut;
128
132
  private render;
129
133
  private isEmptyParagraphDoc;
130
134
  private updatePlaceholder;
@@ -7,6 +7,7 @@ export declare function toLayoutRect(params: {
7
7
  left: number;
8
8
  };
9
9
  }): LayoutRect;
10
+ export declare function groupDomRectsByRow(rects: DOMRect[]): DOMRect[];
10
11
  export declare function createDomLayoutMeasurer(params: {
11
12
  root: HTMLElement;
12
13
  container: HTMLElement;
@@ -35,3 +36,14 @@ export declare function createOffsetToXMeasurer(params: {
35
36
  lines: LineInfo[];
36
37
  }): (lineIndex: number, offsetInLine: number) => number | null;
37
38
  export declare function cursorOffsetToDomOffset(cursorToCodeUnit: number[], offset: number): number;
39
+ export type HitTestResult = {
40
+ cursorOffset: number;
41
+ pastRowEnd: boolean;
42
+ };
43
+ export declare function hitTestFromLayout(params: {
44
+ clientX: number;
45
+ clientY: number;
46
+ root: HTMLElement;
47
+ container: HTMLElement;
48
+ lines: LineInfo[];
49
+ }): HitTestResult | null;
@@ -1,2 +1,3 @@
1
1
  export { CakeEditor } from "./react/CakeEditor";
2
2
  export type { CakeEditorProps, CakeEditorRef, CakeEditorSelection, CakeEditorUpdate, } from "./react/CakeEditor";
3
+ export type { EditCommand, CoreEditCommand, ExtensionCommand } from "./core/runtime";
@@ -1,5 +1,4 @@
1
- import type { StateCommand } from "@codemirror/state";
2
- import type { CakeExtension } from "../core/runtime";
1
+ import type { CakeExtension, EditCommand } from "../core/runtime";
3
2
  export type CakeEditorSelection = {
4
3
  start: number;
5
4
  end: number;
@@ -30,7 +29,22 @@ export interface CakeEditorRef {
30
29
  blur: () => void;
31
30
  hasFocus: () => boolean;
32
31
  selectAll: () => void;
33
- executeCommand: (command: StateCommand) => boolean;
32
+ /**
33
+ * Execute a semantic edit command.
34
+ *
35
+ * Semantic commands are defined by extensions and allow callers to use
36
+ * high-level commands like `{ type: "toggle-bold" }` instead of
37
+ * syntax-specific commands like `{ type: "toggle-inline", marker: "**" }`.
38
+ *
39
+ * Available commands depend on which extensions are registered.
40
+ *
41
+ * @param command - The command to execute
42
+ * @param options.restoreFocus - If true, refocus the editor after executing.
43
+ * Use this when calling from a toolbar button that steals focus.
44
+ */
45
+ executeCommand: (command: EditCommand, options?: {
46
+ restoreFocus?: boolean;
47
+ }) => boolean;
34
48
  applyUpdate: (update: CakeEditorUpdate) => void;
35
49
  getValue: () => string;
36
50
  getSelection: () => {