kirby-types 1.2.0 → 1.3.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.
- package/README.md +92 -0
- package/index.d.ts +22 -0
- package/package.json +7 -3
- package/src/blueprint.d.ts +660 -0
- package/src/panel/features.d.ts +8 -9
- package/src/panel/helpers.d.ts +3 -3
- package/src/panel/index.d.ts +74 -158
- package/src/panel/libraries.d.ts +11 -36
- package/src/panel/textarea.d.ts +192 -0
- package/src/panel/writer.d.ts +570 -13
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for Kirby Textarea toolbar buttons.
|
|
3
|
+
*
|
|
4
|
+
* This module provides types for custom textarea toolbar buttons
|
|
5
|
+
* that can be registered via `window.panel.plugin("name", { textareaButtons: { ... } })`.
|
|
6
|
+
*
|
|
7
|
+
* @see https://getkirby.com/docs/reference/plugins/extensions/textarea-buttons
|
|
8
|
+
* @since 4.0.0
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// =============================================================================
|
|
12
|
+
// Textarea Toolbar Context
|
|
13
|
+
// =============================================================================
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The toolbar component context available as `this` in button click handlers.
|
|
17
|
+
*
|
|
18
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/components/Forms/Toolbar.vue
|
|
19
|
+
*/
|
|
20
|
+
export interface TextareaToolbarContext {
|
|
21
|
+
/**
|
|
22
|
+
* Emits a command to the textarea input component.
|
|
23
|
+
*
|
|
24
|
+
* Available commands:
|
|
25
|
+
* - `"dialog"` - Opens a dialog component
|
|
26
|
+
* - `"insert"` - Inserts the given text at the current selection
|
|
27
|
+
* - `"prepend"` - Prepends the given text to the current selection/line
|
|
28
|
+
* - `"toggle"` - Toggles wrapping of current selection (accepts before, after texts)
|
|
29
|
+
* - `"upload"` - Opens the file upload dialog
|
|
30
|
+
* - `"wrap"` - Wraps the current selection with the given text
|
|
31
|
+
* - `"file"` - Opens the file picker
|
|
32
|
+
*
|
|
33
|
+
* @param name - Command name
|
|
34
|
+
* @param args - Command arguments
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```js
|
|
38
|
+
* this.command("toggle", "**"); // Toggle bold
|
|
39
|
+
* this.command("prepend", "# "); // Add heading
|
|
40
|
+
* this.command("dialog", "link"); // Open link dialog
|
|
41
|
+
* this.command("insert", (input, selection) => selection.toUpperCase());
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
command: (
|
|
45
|
+
name:
|
|
46
|
+
| "dialog"
|
|
47
|
+
| "insert"
|
|
48
|
+
| "prepend"
|
|
49
|
+
| "toggle"
|
|
50
|
+
| "upload"
|
|
51
|
+
| "wrap"
|
|
52
|
+
| "file",
|
|
53
|
+
...args: any[]
|
|
54
|
+
) => void;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Closes all dropdowns.
|
|
58
|
+
*/
|
|
59
|
+
close: () => void;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Vue translation function.
|
|
63
|
+
*/
|
|
64
|
+
$t: (key: string, ...args: any[]) => string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// =============================================================================
|
|
68
|
+
// Textarea Button
|
|
69
|
+
// =============================================================================
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A custom textarea toolbar button.
|
|
73
|
+
*
|
|
74
|
+
* These buttons are registered via `window.panel.plugin("name", { textareaButtons: { ... } })`
|
|
75
|
+
* and appear in the Kirby textarea field toolbar.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```js
|
|
79
|
+
* window.panel.plugin("my-plugin", {
|
|
80
|
+
* textareaButtons: {
|
|
81
|
+
* timestamp: {
|
|
82
|
+
* label: "Insert Timestamp",
|
|
83
|
+
* icon: "clock",
|
|
84
|
+
* click() {
|
|
85
|
+
* // `this` is the toolbar component with `command()` method
|
|
86
|
+
* this.command("insert", () => new Date().toISOString());
|
|
87
|
+
* },
|
|
88
|
+
* shortcut: "t"
|
|
89
|
+
* }
|
|
90
|
+
* }
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @see https://getkirby.com/docs/reference/plugins/extensions/textarea-buttons
|
|
95
|
+
*/
|
|
96
|
+
export interface TextareaButton {
|
|
97
|
+
/**
|
|
98
|
+
* Display label for the button (appears in tooltip).
|
|
99
|
+
*/
|
|
100
|
+
label: string;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Icon name from Kirby's icon set.
|
|
104
|
+
*/
|
|
105
|
+
icon: string;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Click handler.
|
|
109
|
+
*
|
|
110
|
+
* Called with `this` bound to the toolbar component, which provides:
|
|
111
|
+
* - `this.command(name, ...args)` - Execute a textarea command
|
|
112
|
+
*
|
|
113
|
+
* Available commands:
|
|
114
|
+
* - `dialog` - Opens a dialog component
|
|
115
|
+
* - `insert` - Inserts text at the cursor (can be a function receiving input and selection)
|
|
116
|
+
* - `prepend` - Prepends text to the current line
|
|
117
|
+
* - `toggle` - Toggles wrapping of selection with before/after text
|
|
118
|
+
* - `upload` - Opens the file upload dialog
|
|
119
|
+
* - `wrap` - Wraps the selection with given text
|
|
120
|
+
* - `file` - Opens the file picker
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```js
|
|
124
|
+
* click() {
|
|
125
|
+
* this.command("toggle", "**"); // Toggle bold
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```js
|
|
131
|
+
* click() {
|
|
132
|
+
* this.command("insert", (input, selection) => {
|
|
133
|
+
* return selection.toUpperCase();
|
|
134
|
+
* });
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
click: (this: TextareaToolbarContext) => void;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Keyboard shortcut key (without modifier).
|
|
142
|
+
*
|
|
143
|
+
* Will be triggered with Cmd/Ctrl + the specified key.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```js
|
|
147
|
+
* shortcut: "b" // Cmd+B or Ctrl+B
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
shortcut?: string;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Dropdown menu items.
|
|
154
|
+
*
|
|
155
|
+
* If provided, the button shows a dropdown instead of executing click directly.
|
|
156
|
+
*/
|
|
157
|
+
dropdown?: TextareaDropdownItem[];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// =============================================================================
|
|
161
|
+
// Textarea Dropdown Item
|
|
162
|
+
// =============================================================================
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* A dropdown menu item for textarea toolbar buttons.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```js
|
|
169
|
+
* dropdown: [
|
|
170
|
+
* {
|
|
171
|
+
* label: "Option 1",
|
|
172
|
+
* icon: "check",
|
|
173
|
+
* click() {
|
|
174
|
+
* this.command("insert", "text");
|
|
175
|
+
* }
|
|
176
|
+
* }
|
|
177
|
+
* ]
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export interface TextareaDropdownItem {
|
|
181
|
+
/** Display label */
|
|
182
|
+
label: string;
|
|
183
|
+
|
|
184
|
+
/** Icon name */
|
|
185
|
+
icon: string;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Click handler. Called with `this` bound to the toolbar context.
|
|
189
|
+
* Use a regular function (not arrow function) to access `this.command()`.
|
|
190
|
+
*/
|
|
191
|
+
click: (this: TextareaToolbarContext) => void;
|
|
192
|
+
}
|