|
119 | 119 | )
|
120 | 120 | : false
|
121 | 121 |
|
122 |
| - function handleEditKey() { |
123 |
| - onCloseContextMenu() |
124 |
| - onEditKey() |
125 |
| - } |
126 |
| -
|
127 |
| - function handleEditValue() { |
128 |
| - onCloseContextMenu() |
129 |
| - onEditValue() |
130 |
| - } |
131 |
| -
|
132 |
| - function handleToggleEnforceString() { |
133 |
| - onCloseContextMenu() |
134 |
| - onToggleEnforceString() |
135 |
| - } |
136 |
| -
|
137 |
| - function handleCut() { |
138 |
| - onCloseContextMenu() |
139 |
| - onCut(true) |
140 |
| - } |
141 |
| -
|
142 |
| - function handleCutCompact() { |
143 |
| - onCloseContextMenu() |
144 |
| - onCut(false) |
145 |
| - } |
146 |
| -
|
147 |
| - function handleCopy() { |
148 |
| - onCloseContextMenu() |
149 |
| - onCopy(true) |
150 |
| - } |
151 |
| -
|
152 |
| - function handleCopyCompact() { |
153 |
| - onCloseContextMenu() |
154 |
| - onCopy(false) |
155 |
| - } |
156 |
| -
|
157 |
| - function handlePaste() { |
158 |
| - onCloseContextMenu() |
159 |
| - onPaste() |
160 |
| - } |
161 |
| -
|
162 |
| - function handleRemove() { |
163 |
| - onCloseContextMenu() |
164 |
| - onRemove() |
165 |
| - } |
166 |
| -
|
167 |
| - function handleDuplicate() { |
168 |
| - onCloseContextMenu() |
169 |
| - onDuplicate() |
170 |
| - } |
171 |
| -
|
172 |
| - function handleExtract() { |
173 |
| - onCloseContextMenu() |
174 |
| - onExtract() |
175 |
| - } |
176 |
| -
|
177 | 122 | function handleInsertOrConvert(type: InsertType) {
|
178 |
| - onCloseContextMenu() |
179 |
| -
|
180 | 123 | if (hasSelectionContents) {
|
181 | 124 | onConvert(type)
|
182 | 125 | } else {
|
183 | 126 | onInsert(type)
|
184 | 127 | }
|
185 | 128 | }
|
186 | 129 |
|
187 |
| - function handleSort() { |
188 |
| - onCloseContextMenu() |
189 |
| - onSort() |
190 |
| - } |
191 |
| -
|
192 |
| - function handleTransform() { |
193 |
| - onCloseContextMenu() |
194 |
| - onTransform() |
195 |
| - } |
196 |
| -
|
197 |
| - function handleInsertBefore() { |
198 |
| - onCloseContextMenu() |
199 |
| - onInsertBefore() |
200 |
| - } |
201 |
| -
|
202 |
| - function handleInsertAfter() { |
203 |
| - onCloseContextMenu() |
204 |
| - onInsertAfter() |
205 |
| - } |
206 |
| -
|
207 | 130 | let defaultItems: ContextMenuItem[]
|
208 | 131 | $: defaultItems = [
|
209 | 132 | {
|
210 | 133 | type: 'row',
|
211 | 134 | items: [
|
212 | 135 | {
|
213 | 136 | type: 'button',
|
214 |
| - onClick: handleEditKey, |
| 137 | + onClick: () => onEditKey(), |
215 | 138 | icon: faPen,
|
216 | 139 | text: 'Edit key',
|
217 | 140 | title: 'Edit the key (Double-click on the key)',
|
|
221 | 144 | type: 'dropdown-button',
|
222 | 145 | main: {
|
223 | 146 | type: 'button',
|
224 |
| - onClick: handleEditValue, |
| 147 | + onClick: () => onEditValue(), |
225 | 148 | icon: faPen,
|
226 | 149 | text: editValueText,
|
227 | 150 | title: 'Edit the value (Double-click on the value)',
|
|
234 | 157 | icon: faPen,
|
235 | 158 | text: editValueText,
|
236 | 159 | title: 'Edit the value (Double-click on the value)',
|
237 |
| - onClick: handleEditValue, |
| 160 | + onClick: () => onEditValue(), |
238 | 161 | disabled: !canEditValue
|
239 | 162 | },
|
240 | 163 | {
|
241 | 164 | type: 'button',
|
242 | 165 | icon: enforceString ? faCheckSquare : faSquare,
|
243 | 166 | text: 'Enforce string',
|
244 | 167 | title: 'Enforce keeping the value as string when it contains a numeric value',
|
245 |
| - onClick: handleToggleEnforceString, |
| 168 | + onClick: () => onToggleEnforceString(), |
246 | 169 | disabled: !canEnforceString
|
247 | 170 | }
|
248 | 171 | ]
|
|
257 | 180 | type: 'dropdown-button',
|
258 | 181 | main: {
|
259 | 182 | type: 'button',
|
260 |
| - onClick: handleCut, |
| 183 | + onClick: () => onCut(true), |
261 | 184 | icon: faCut,
|
262 | 185 | text: 'Cut',
|
263 | 186 | title: 'Cut selected contents, formatted with indentation (Ctrl+X)',
|
|
270 | 193 | icon: faCut,
|
271 | 194 | text: 'Cut formatted',
|
272 | 195 | title: 'Cut selected contents, formatted with indentation (Ctrl+X)',
|
273 |
| - onClick: handleCut, |
| 196 | + onClick: () => onCut(true), |
274 | 197 | disabled: !hasSelectionContents
|
275 | 198 | },
|
276 | 199 | {
|
277 | 200 | type: 'button',
|
278 | 201 | icon: faCut,
|
279 | 202 | text: 'Cut compacted',
|
280 | 203 | title: 'Cut selected contents, without indentation (Ctrl+Shift+X)',
|
281 |
| - onClick: handleCutCompact, |
| 204 | + onClick: () => onCut(false), |
282 | 205 | disabled: !hasSelectionContents
|
283 | 206 | }
|
284 | 207 | ]
|
|
287 | 210 | type: 'dropdown-button',
|
288 | 211 | main: {
|
289 | 212 | type: 'button',
|
290 |
| - onClick: handleCopy, |
| 213 | + onClick: () => onCopy(true), |
291 | 214 | icon: faCopy,
|
292 | 215 | text: 'Copy',
|
293 | 216 | title: 'Copy selected contents, formatted with indentation (Ctrl+C)',
|
|
300 | 223 | icon: faCopy,
|
301 | 224 | text: 'Copy formatted',
|
302 | 225 | title: 'Copy selected contents, formatted with indentation (Ctrl+C)',
|
303 |
| - onClick: handleCopy, |
| 226 | + onClick: () => onCopy(true), |
304 | 227 | disabled: !hasSelectionContents
|
305 | 228 | },
|
306 | 229 | {
|
307 | 230 | type: 'button',
|
308 | 231 | icon: faCopy,
|
309 | 232 | text: 'Copy compacted',
|
310 | 233 | title: 'Copy selected contents, without indentation (Ctrl+Shift+C)',
|
311 |
| - onClick: handleCopyCompact, |
| 234 | + onClick: () => onCopy(false), |
312 | 235 | disabled: !hasSelectionContents
|
313 | 236 | }
|
314 | 237 | ]
|
315 | 238 | },
|
316 | 239 | {
|
317 | 240 | type: 'button',
|
318 |
| - onClick: handlePaste, |
| 241 | + onClick: () => onPaste(), |
319 | 242 | icon: faPaste,
|
320 | 243 | text: 'Paste',
|
321 | 244 | title: 'Paste clipboard contents (Ctrl+V)',
|
|
332 | 255 | items: [
|
333 | 256 | {
|
334 | 257 | type: 'button',
|
335 |
| - onClick: handleDuplicate, |
| 258 | + onClick: () => onDuplicate(), |
336 | 259 | icon: faClone,
|
337 | 260 | text: 'Duplicate',
|
338 | 261 | title: 'Duplicate selected contents (Ctrl+D)',
|
339 | 262 | disabled: !canDuplicate
|
340 | 263 | },
|
341 | 264 | {
|
342 | 265 | type: 'button',
|
343 |
| - onClick: handleExtract, |
| 266 | + onClick: () => onExtract(), |
344 | 267 | icon: faCropAlt,
|
345 | 268 | text: 'Extract',
|
346 | 269 | title: 'Extract selected contents',
|
347 | 270 | disabled: !canExtract
|
348 | 271 | },
|
349 | 272 | {
|
350 | 273 | type: 'button',
|
351 |
| - onClick: handleSort, |
| 274 | + onClick: () => onSort(), |
352 | 275 | icon: faSortAmountDownAlt,
|
353 | 276 | text: 'Sort',
|
354 | 277 | title: 'Sort array or object contents',
|
355 | 278 | disabled: !hasSelectionContents
|
356 | 279 | },
|
357 | 280 | {
|
358 | 281 | type: 'button',
|
359 |
| - onClick: handleTransform, |
| 282 | + onClick: () => onTransform(), |
360 | 283 | icon: faFilter,
|
361 | 284 | text: 'Transform',
|
362 | 285 | title: 'Transform array or object contents (filter, sort, project)',
|
363 | 286 | disabled: !hasSelectionContents
|
364 | 287 | },
|
365 | 288 | {
|
366 | 289 | type: 'button',
|
367 |
| - onClick: handleRemove, |
| 290 | + onClick: () => onRemove(), |
368 | 291 | icon: faTrashCan,
|
369 | 292 | text: 'Remove',
|
370 | 293 | title: 'Remove selected contents (Delete)',
|
|
420 | 343 | items: [
|
421 | 344 | {
|
422 | 345 | type: 'button',
|
423 |
| - onClick: handleInsertBefore, |
| 346 | + onClick: () => onInsertBefore(), |
424 | 347 | icon: faCaretSquareUp,
|
425 | 348 | text: 'Insert before',
|
426 | 349 | title: 'Select area before current entry to insert or paste contents',
|
427 | 350 | disabled: !hasSelectionContents || rootSelected
|
428 | 351 | },
|
429 | 352 | {
|
430 | 353 | type: 'button',
|
431 |
| - onClick: handleInsertAfter, |
| 354 | + onClick: () => onInsertAfter(), |
432 | 355 | icon: faCaretSquareDown,
|
433 | 356 | text: 'Insert after',
|
434 | 357 | title: 'Select area after current entry to insert or paste contents',
|
|
443 | 366 |
|
444 | 367 | <ContextMenu
|
445 | 368 | {items}
|
| 369 | + {onCloseContextMenu} |
446 | 370 | tip={showTip ? 'Tip: you can open this context menu via right-click or with Ctrl+Q' : undefined}
|
447 | 371 | />
|
0 commit comments