@rcarls/rc-textarea 0.3.1 → 0.4.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,4 +1,6 @@
1
1
  import { LitElement, CSSResultGroup } from 'lit';
2
+ import { NativeChildController } from '@rcarls/rc-common';
3
+ import { RCDocument } from './document.ts';
2
4
  import { SavedSelection } from './selection.ts';
3
5
  import { Decoration, DecorationInput, RCTextareaPlugin, RCTextareaPluginAPI, TextPattern } from './types.ts';
4
6
  declare global {
@@ -6,6 +8,11 @@ declare global {
6
8
  'rc-textarea': RCTextarea;
7
9
  }
8
10
  }
11
+ interface UndoEntry {
12
+ value: string;
13
+ anchorOffset: number;
14
+ focusOffset: number;
15
+ }
9
16
  /**
10
17
  * Textarea wrapper with line decorations, gutter rendering, inline widgets, and plugin hooks.
11
18
  *
@@ -36,6 +43,22 @@ declare global {
36
43
  * @fires rc-textarea-change - Fired when the field value changes
37
44
  * @fires rc-textarea-blur - Fired when the field loses focus
38
45
  *
46
+ * @csspart root - The outer flex container wrapping the gutter and editor area.
47
+ * @csspart gutter - The gutter column container.
48
+ * @csspart gutter-cells - The gutter's line-label list.
49
+ * @csspart editor-area - The container positioning the editor over the slotted textarea.
50
+ * @csspart editor - The contenteditable field surface.
51
+ *
52
+ * @attr line-numbers - Show sequential line numbers in the gutter. Enables the gutter implicitly.
53
+ * @attr list-numbers - Deprecated alias for sparse line numbering; removed before v1.0.
54
+ * @attr gutter - Enable the gutter column without any built-in content.
55
+ * @attr word-wrap - Wrap long lines within the field to prevent horizontal overflow.
56
+ * @attr auto-grow - Allow the field to grow vertically with content to prevent vertical overflow.
57
+ * @attr read-only - Disable editing. The field renders as a styled read-only display.
58
+ * @attr label - Deprecated accessible-name override; removed before v1.0.
59
+ * @attr value - Current field value.
60
+ * @attr default-value - Initial uncontrolled value.
61
+ *
39
62
  * @cssprop [--rc-textarea-border=1px solid ButtonBorder] - Border around the field
40
63
  * @cssprop [--rc-textarea-border-radius=2px] - Border radius of the field
41
64
  * @cssprop [--rc-textarea-background=Field] - Background color of the field
@@ -50,6 +73,8 @@ declare global {
50
73
  * @cssprop [--rc-textarea-gutter-bg=Canvas] - Gutter background color
51
74
  * @cssprop [--rc-textarea-gutter-color=GrayText] - Gutter text color
52
75
  * @cssprop [--rc-textarea-gutter-border=1px solid ButtonBorder] - Gutter right border
76
+ * @cssprop [--rc-textarea-gutter-font-family=var(--rc-textarea-font-family, monospace)] - Gutter font family
77
+ * @cssprop [--rc-textarea-gutter-padding-inline-end=0.75em] - Space between gutter labels and text
53
78
  */
54
79
  export declare class RCTextarea extends LitElement {
55
80
  static styles: CSSResultGroup;
@@ -64,6 +89,8 @@ export declare class RCTextarea extends LitElement {
64
89
  /** Show sequential line numbers in the gutter. Enables the gutter implicitly. */
65
90
  lineNumbers: boolean;
66
91
  /**
92
+ * Legacy alias for sparse (non-blank-line) list-style numbering.
93
+ *
67
94
  * @deprecated Use a plugin with `LineDecoration.gutterContent` to implement
68
95
  * sparse line numbering. This property will be removed before v1.0.
69
96
  */
@@ -84,6 +111,8 @@ export declare class RCTextarea extends LitElement {
84
111
  /** Disable editing. The field renders as a styled read-only display. */
85
112
  readOnly: boolean;
86
113
  /**
114
+ * Accessible-name override, applied to the editor's `aria-label`.
115
+ *
87
116
  * @deprecated Set `aria-label` on the slotted `<textarea>` instead, or
88
117
  * associate a `<label>` element via its `for`/`id` pair. This property
89
118
  * will be removed before v1.0.
@@ -119,39 +148,39 @@ export declare class RCTextarea extends LitElement {
119
148
  private _defaultValue;
120
149
  private _initialValueResolved;
121
150
  private _valueSetByHost;
122
- private _document;
123
- private _$textareaRef;
124
- private readonly _textareaController;
151
+ protected _document: RCDocument | null;
152
+ protected _$textareaRef: WeakRef<HTMLTextAreaElement> | null;
153
+ protected readonly _textareaController: NativeChildController<HTMLTextAreaElement>;
125
154
  /** Plugin-owned decorations */
126
155
  protected _pluginDecorations: Map<string, Decoration>;
127
156
  /** Pattern-generated decorations (rebuilt on each value change). */
128
- private _patternDecorations;
157
+ protected _patternDecorations: Decoration[];
129
158
  /** Imperative decorations (set directly via the `decorations` property) */
130
159
  private _externalDecorations;
131
160
  /** Registered patterns. */
132
- private _patterns;
161
+ protected _patterns: Map<string, TextPattern>;
133
162
  protected _plugin: RCTextareaPlugin | null;
134
163
  private _pluginProperty;
135
164
  protected _pluginApi: RCTextareaPluginAPI | null;
136
165
  /** Sequence counter for async plugin safety (discard stale results). */
137
- private _pluginSeq;
166
+ protected _pluginSeq: number;
138
167
  /** Stylesheets adopted into the shadow root by the active plugin. */
139
- private _pluginSheets;
168
+ protected _pluginSheets: Set<CSSStyleSheet>;
140
169
  protected _savedSelection: SavedSelection | null;
141
- private _rafHandle;
142
- private _composing;
143
- private _isRendering;
170
+ protected _rafHandle: number | null;
171
+ protected _composing: boolean;
172
+ protected _isRendering: boolean;
144
173
  /** The currently highlighted `.line` element (active line). */
145
- private _$activeLine;
174
+ protected _$activeLine: HTMLElement | null;
146
175
  /** Callbacks registered via PluginAPI.onCursorMove(). */
147
- private _cursorCallbacks;
148
- private _docSelectionChangeHandler;
176
+ protected _cursorCallbacks: Set<(start: number, end: number) => void>;
177
+ protected _docSelectionChangeHandler: () => void;
149
178
  /** Synthetic undo/redo stack (DOM rebuilds invalidate native undo) */
150
- private _undoStack;
151
- private _undoIndex;
152
- private _resizeObserver;
179
+ protected _undoStack: UndoEntry[];
180
+ protected _undoIndex: number;
181
+ protected _resizeObserver: ResizeObserver | null;
153
182
  /** Cached per-line gutter labels from the last render — reused by ResizeObserver. */
154
- private _gutterLabels;
183
+ protected _gutterLabels: (string | null)[];
155
184
  /**
156
185
  * The current field value.
157
186
  *
@@ -169,16 +198,17 @@ export declare class RCTextarea extends LitElement {
169
198
  firstUpdated(): void;
170
199
  updated(changed: Map<string, unknown>): void;
171
200
  render(): import('lit').TemplateResult<1>;
172
- private _onSlotChange;
173
- private _setupTextarea;
174
- private _onTextareaInvalid;
175
- private _bindEditorEvents;
176
- private _onInputEvent;
177
- private _onInput;
178
- private _onSelectionChange;
179
- private _updateActiveLine;
180
- private _updateActiveGutterCell;
181
- private _onKeyDown;
201
+ protected _onSlotChange(): void;
202
+ protected _setupTextarea($textarea: HTMLTextAreaElement | null, $previousTextarea?: HTMLTextAreaElement | null): void;
203
+ protected _onTextareaInvalid: () => void;
204
+ protected _bindEditorEvents($editor: HTMLElement): void;
205
+ protected _onInputEvent: () => void;
206
+ protected _onBeforeInput: (event: InputEvent) => void;
207
+ protected _onInput(): void;
208
+ protected _onSelectionChange: () => void;
209
+ protected _updateActiveLine(): void;
210
+ protected _updateActiveGutterCell(): void;
211
+ protected _onKeyDown: (e: KeyboardEvent) => void;
182
212
  protected _insertText(text: string): void;
183
213
  /**
184
214
  * Wrap the current selection with `prefix` and `suffix`.
@@ -195,13 +225,13 @@ export declare class RCTextarea extends LitElement {
195
225
  * When the selection is collapsed this is equivalent to `insertText`.
196
226
  */
197
227
  replaceSelection(text: string): void;
198
- private _onPaste;
228
+ protected _onPaste: (e: ClipboardEvent) => void;
199
229
  /** Reset the undo/redo history. Call when the field receives entirely new content. */
200
230
  clearHistory(): void;
201
231
  protected _pushUndo(sel: SavedSelection | null): void;
202
- private _undo;
203
- private _redo;
204
- private _applyUndoEntry;
232
+ protected _undo(): void;
233
+ protected _redo(): void;
234
+ protected _applyUndoEntry(entry: UndoEntry): void;
205
235
  /**
206
236
  * Register and mount a plugin imperatively.
207
237
  * Replaces any currently active plugin. Prefer the `plugin` property for
@@ -215,11 +245,16 @@ export declare class RCTextarea extends LitElement {
215
245
  * `mount()` call. Each getter delegates to the component's live state so the
216
246
  * API stays accurate across render frames without needing to be rebuilt.
217
247
  */
218
- private _buildPluginApi;
219
- private _clearPluginSheets;
248
+ protected _buildPluginApi(): RCTextareaPluginAPI;
249
+ protected _clearPluginSheets(): void;
220
250
  /**
221
251
  * Register a text pattern that generates decorations on every render pass.
222
252
  * Returns the pattern ID, which can be passed to `removePattern` to unregister it.
253
+ *
254
+ * @example
255
+ * const id = editor.addPattern({ pattern: /TODO/g, className: 'highlight-todo' });
256
+ * // Later:
257
+ * editor.removePattern(id);
223
258
  */
224
259
  addPattern(pattern: Omit<TextPattern, 'id'>): string;
225
260
  /** Remove a previously registered pattern by the ID returned from `addPattern`. */
@@ -227,7 +262,7 @@ export declare class RCTextarea extends LitElement {
227
262
  /** Remove all registered patterns and trigger a re-render. */
228
263
  clearPatterns(): void;
229
264
  protected _scheduleRender(): void;
230
- private _performRender;
265
+ protected _performRender(): Promise<void>;
231
266
  /**
232
267
  * Compute the label string for each gutter cell based on the current gutter
233
268
  * mode (`lineNumbers`, `listNumbers` (deprecated), `gutter`) and any
@@ -237,7 +272,7 @@ export declare class RCTextarea extends LitElement {
237
272
  * - `string` — the label to display
238
273
  * - `null` — render an empty cell
239
274
  */
240
- private _computeGutterLabels;
275
+ protected _computeGutterLabels(allDecorations: Decoration[], value?: string): (string | null)[];
241
276
  /**
242
277
  * Synchronize the pixel height of each gutter cell to match the
243
278
  * corresponding `.line` element in the editor.
@@ -248,16 +283,17 @@ export declare class RCTextarea extends LitElement {
248
283
  * Also copies the editor's computed `paddingTop`/`paddingBottom` to the
249
284
  * gutter to compensate for browser UA overrides on contenteditable.
250
285
  */
251
- private _syncGutterHeights;
286
+ protected _syncGutterHeights(): void;
252
287
  /**
253
288
  * Add, remove, or update `.gutter-cell` spans so their count and text
254
289
  * content match `labels`. When `labels` is provided the cached
255
290
  * `_gutterLabels` is updated first; otherwise the cached labels are reused
256
291
  * (called by the `ResizeObserver` without a new render pass).
257
292
  */
258
- private _syncGutter;
259
- private _syncLabel;
260
- private _syncTypography;
293
+ protected _syncGutter(labels?: (string | null)[]): void;
294
+ protected _syncLabel(): void;
295
+ protected _syncTypography($textarea: HTMLTextAreaElement): void;
261
296
  protected _syncTextareaValue(fromUser?: boolean): void;
262
297
  protected _dispatchChange(value: string): void;
263
298
  }
299
+ export {};
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.3.1",
6
+ "version": "0.4.0",
7
7
  "description": "Textarea wrapper with line decorations, gutter rendering, inline widgets, and plugin hooks.",
8
8
  "repository": {
9
9
  "type": "git",