@@ -3,69 +3,125 @@ import * as popup from "jsr:@denops/std@^7.3.2/popup";
33import type { Border } from "jsr:@vim-fall/std@^0.4.0/theme" ;
44import type { Dimension } from "jsr:@vim-fall/std@^0.4.0/coordinator" ;
55
6+ const HIGHLIGHT_NORMAL = "FallNormal" ;
7+ const HIHGLIGHT_BORDER = "FallBorder" ;
8+
9+ /**
10+ * Properties that define the appearance and behavior of a component.
11+ */
612export type ComponentProperties = {
7- title ?: string ;
8- border ?: Border ;
9- zindex ?: number ;
13+ /** The title of the component */
14+ readonly title ?: string ;
15+
16+ /** The border style for the component */
17+ readonly border ?: Border ;
18+
19+ /** The z-index of the component */
20+ readonly zindex ?: number ;
1021} ;
1122
23+ /**
24+ * Information about the component's current state, including window ID and buffer number.
25+ */
1226export type ComponentInfo = {
13- bufnr : number ;
14- winid : number ;
15- dimension : Readonly < Dimension > ;
27+ /** The buffer number associated with the component */
28+ readonly bufnr : number ;
29+
30+ /** The window ID associated with the component */
31+ readonly winid : number ;
32+
33+ /** The dimension (size and position) of the component */
34+ readonly dimension : Readonly < Dimension > ;
1635} ;
1736
37+ /**
38+ * Options for interacting with the component, such as abort signals.
39+ */
40+ export type ComponentOptions = {
41+ /** Signal used to abort operations */
42+ signal ?: AbortSignal ;
43+ } ;
44+
45+ /**
46+ * The base interface for a component that can be opened, moved, updated, rendered, and closed.
47+ * Provides methods to manipulate the component's window and update its properties.
48+ */
1849export type Component = AsyncDisposable & {
50+ /**
51+ * Opens the component window with the specified dimensions.
52+ * @param denops The Denops instance.
53+ * @param dimension The dimensions of the component.
54+ * @param options Additional options such as the abort signal.
55+ * @returns A disposable object to manage the component window's lifecycle.
56+ */
1957 open (
2058 denops : Denops ,
21- dimension : Readonly < Partial < Dimension > > ,
22- option ?: { signal ?: AbortSignal } ,
59+ dimension : Readonly < Dimension > ,
60+ options ?: ComponentOptions ,
2361 ) : Promise < AsyncDisposable > ;
2462
63+ /**
64+ * Moves the component window to new dimensions.
65+ * @param denops The Denops instance.
66+ * @param dimension The new dimensions of the component.
67+ * @param options Additional options such as the abort signal.
68+ */
2569 move (
2670 denops : Denops ,
2771 dimension : Readonly < Partial < Dimension > > ,
28- options ?: { signal ?: AbortSignal } ,
72+ options ?: ComponentOptions ,
2973 ) : Promise < void > ;
3074
75+ /**
76+ * Updates the component's properties.
77+ * @param denops The Denops instance.
78+ * @param properties The new properties of the component.
79+ * @param options Additional options such as the abort signal.
80+ */
3181 update (
3282 denops : Denops ,
3383 properties : Readonly < ComponentProperties > ,
34- options ?: { signal ?: AbortSignal } ,
84+ options ?: ComponentOptions ,
3585 ) : Promise < void > ;
3686
87+ /**
88+ * Renders the component.
89+ * @param denops The Denops instance.
90+ * @param options Additional options such as the abort signal.
91+ * @returns A promise that resolves to `true` or `void` when rendering is complete.
92+ * If the component does not need to render anything, it can resolve with `void`.
93+ */
3794 render (
3895 denops : Denops ,
39- options ?: { signal ?: AbortSignal } ,
96+ options ?: ComponentOptions ,
4097 ) : Promise < true | void > ;
4198
99+ /**
100+ * Closes the component.
101+ */
42102 close ( ) : Promise < void > ;
43103} ;
44104
45105/**
46- * ```
47- * width
48- * ┌───────────────────────────────────┐
49- * ╭─────────────────────────────────────╮
50- * │ │ ┐
51- * │ │ │
52- * │ │ │height
53- * │ │ │
54- * │ │ ┘
55- * ╰─────────────────────────────────────╯
56- * ```
106+ * A base class for a component that can be opened, moved, updated, rendered, and closed.
107+ * This class uses the `popup` module to manage the window and display the component.
57108 */
58109export class BaseComponent implements Component {
59110 #opened?: {
60111 readonly window : popup . PopupWindow ;
61112 readonly dimension : Readonly < Dimension > ;
62113 } ;
114+
63115 protected properties : Readonly < ComponentProperties > ;
64116
65117 constructor ( properties : Readonly < ComponentProperties > = { } ) {
66118 this . properties = properties ;
67119 }
68120
121+ /**
122+ * Returns information about the component's current state (buffer number, window ID, and dimensions).
123+ * If the component is not opened, returns `undefined`.
124+ */
69125 get info ( ) : Readonly < ComponentInfo > | undefined {
70126 if ( ! this . #opened) {
71127 return undefined ;
@@ -77,7 +133,7 @@ export class BaseComponent implements Component {
77133 async open (
78134 denops : Denops ,
79135 dimension : Readonly < Dimension > ,
80- { signal } : { signal ?: AbortSignal } = { } ,
136+ { signal } : ComponentOptions = { } ,
81137 ) : Promise < AsyncDisposable > {
82138 if ( this . #opened) {
83139 return this ;
@@ -90,8 +146,8 @@ export class BaseComponent implements Component {
90146 relative : "editor" ,
91147 anchor : "NW" ,
92148 highlight : {
93- normal : "FallNormal" ,
94- border : "FallBorder" ,
149+ normal : HIGHLIGHT_NORMAL ,
150+ border : HIHGLIGHT_BORDER ,
95151 } ,
96152 noRedraw : true ,
97153 } ) ,
@@ -103,7 +159,7 @@ export class BaseComponent implements Component {
103159 async move (
104160 denops : Denops ,
105161 dimension : Readonly < Partial < Dimension > > ,
106- { signal } : { signal ?: AbortSignal } = { } ,
162+ { signal } : ComponentOptions = { } ,
107163 ) : Promise < void > {
108164 if ( this . #opened) {
109165 this . #opened = {
@@ -125,7 +181,7 @@ export class BaseComponent implements Component {
125181 async update (
126182 denops : Denops ,
127183 properties : Readonly < ComponentProperties > ,
128- { signal } : { signal ?: AbortSignal } = { } ,
184+ { signal } : ComponentOptions = { } ,
129185 ) : Promise < void > {
130186 this . properties = {
131187 ...this . properties ,
@@ -142,7 +198,7 @@ export class BaseComponent implements Component {
142198
143199 render (
144200 _denops : Denops ,
145- _option ?: { signal ?: AbortSignal } ,
201+ _options : ComponentOptions = { } ,
146202 ) : Promise < true | void > {
147203 return Promise . resolve ( true ) ;
148204 }
0 commit comments