smoosic 2.0.1 → 2.0.3
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/build/smoosic.js +171 -78
- package/package.json +82 -77
- package/release/smoosic.js +171 -78
- package/release/styles/fonts/MaterialIconsOutlined-Regular.otf +0 -0
- package/release/styles/menus.css +26 -0
- package/specs/022-text-reposition-on-resize/spec.md +1 -0
- package/specs/027-fix-bottom-modifier-lookup/checklists/requirements.md +38 -0
- package/specs/027-fix-bottom-modifier-lookup/contracts/division-lookup-contract.md +51 -0
- package/specs/027-fix-bottom-modifier-lookup/data-model.md +43 -0
- package/specs/027-fix-bottom-modifier-lookup/plan.md +77 -0
- package/specs/027-fix-bottom-modifier-lookup/quickstart.md +36 -0
- package/specs/027-fix-bottom-modifier-lookup/research.md +58 -0
- package/specs/027-fix-bottom-modifier-lookup/spec.md +105 -0
- package/specs/027-fix-bottom-modifier-lookup/tasks.md +167 -0
- package/specs/028-unsaved-changes-indicator/checklists/requirements.md +39 -0
- package/specs/028-unsaved-changes-indicator/contracts/score-change-contract.md +44 -0
- package/specs/028-unsaved-changes-indicator/data-model.md +64 -0
- package/specs/028-unsaved-changes-indicator/plan.md +96 -0
- package/specs/028-unsaved-changes-indicator/quickstart.md +54 -0
- package/specs/028-unsaved-changes-indicator/research.md +68 -0
- package/specs/028-unsaved-changes-indicator/spec.md +135 -0
- package/specs/028-unsaved-changes-indicator/tasks.md +173 -0
- package/specs/029-remove-promise-helpers/checklists/requirements.md +39 -0
- package/specs/029-remove-promise-helpers/contracts/public-api-contract.md +32 -0
- package/specs/029-remove-promise-helpers/data-model.md +45 -0
- package/specs/029-remove-promise-helpers/plan.md +86 -0
- package/specs/029-remove-promise-helpers/quickstart.md +53 -0
- package/specs/029-remove-promise-helpers/research.md +71 -0
- package/specs/029-remove-promise-helpers/spec.md +107 -0
- package/specs/029-remove-promise-helpers/tasks.md +164 -0
- package/specs/030-copy-paste-voices/checklists/requirements.md +39 -0
- package/specs/030-copy-paste-voices/contracts/voice-copy-paste-contract.md +47 -0
- package/specs/030-copy-paste-voices/data-model.md +63 -0
- package/specs/030-copy-paste-voices/plan.md +80 -0
- package/specs/030-copy-paste-voices/quickstart.md +50 -0
- package/specs/030-copy-paste-voices/research.md +80 -0
- package/specs/030-copy-paste-voices/spec.md +124 -0
- package/specs/030-copy-paste-voices/tasks.md +183 -0
- package/specs/031-select-voice/checklists/requirements.md +39 -0
- package/specs/031-select-voice/contracts/select-voice-contract.md +43 -0
- package/specs/031-select-voice/data-model.md +47 -0
- package/specs/031-select-voice/plan.md +79 -0
- package/specs/031-select-voice/quickstart.md +43 -0
- package/specs/031-select-voice/research.md +55 -0
- package/specs/031-select-voice/spec.md +113 -0
- package/specs/031-select-voice/tasks.md +171 -0
- package/src/application/application.ts +464 -459
- package/src/common/promiseHelpers.ts +2 -2
- package/src/render/audio/samples.ts +117 -118
- package/src/render/sui/pageDivisions.ts +58 -0
- package/src/render/sui/renderState.ts +469 -464
- package/src/render/sui/scoreChangeState.ts +62 -0
- package/src/render/sui/scoreView.ts +30 -0
- package/src/render/sui/scoreViewOperations.ts +2555 -2380
- package/src/render/sui/svgPageMap.ts +16 -17
- package/src/render/sui/textEdit.ts +310 -311
- package/src/render/sui/tracker.ts +40 -0
- package/src/render/vex/vxNote.ts +3 -1
- package/src/smo/xform/copypaste.ts +304 -4
- package/src/smo/xform/selections.ts +68 -0
- package/src/smo/xform/undo.ts +9 -0
- package/src/styles/menus.css +26 -0
- package/src/ui/buttons/ribbon.ts +3 -1
- package/src/ui/components/buttons/sidebar.vue +15 -6
- package/src/ui/components/dialogs/library.vue +3 -1
- package/src/ui/components/dialogs/unsavedChanges.vue +44 -0
- package/src/ui/dialogs/adapter.ts +181 -183
- package/src/ui/dialogs/addMeasure.ts +97 -97
- package/src/ui/dialogs/annotationVue.ts +56 -56
- package/src/ui/dialogs/audioSettings.ts +121 -123
- package/src/ui/dialogs/chordChangeVue.ts +46 -46
- package/src/ui/dialogs/clefChange.ts +53 -53
- package/src/ui/dialogs/customTuplets.ts +95 -96
- package/src/ui/dialogs/customTupletsVue.ts +47 -47
- package/src/ui/dialogs/dialog.ts +627 -620
- package/src/ui/dialogs/durations.ts +34 -34
- package/src/ui/dialogs/dynamics.ts +140 -142
- package/src/ui/dialogs/factory.ts +198 -198
- package/src/ui/dialogs/fileDialogs.ts +245 -179
- package/src/ui/dialogs/fonts.ts +93 -93
- package/src/ui/dialogs/globalLayout.ts +40 -40
- package/src/ui/dialogs/gracenote.ts +31 -31
- package/src/ui/dialogs/hairpin.ts +108 -110
- package/src/ui/dialogs/hairpinVue.ts +51 -51
- package/src/ui/dialogs/instrument.ts +111 -111
- package/src/ui/dialogs/keySignature.ts +175 -176
- package/src/ui/dialogs/keySignatureVue.ts +47 -47
- package/src/ui/dialogs/library.ts +207 -207
- package/src/ui/dialogs/libraryVue.ts +62 -48
- package/src/ui/dialogs/lyricVue.ts +46 -46
- package/src/ui/dialogs/measureFormat.ts +78 -78
- package/src/ui/dialogs/microtones.ts +147 -147
- package/src/ui/dialogs/noteHead.ts +319 -319
- package/src/ui/dialogs/pageLayout.ts +61 -61
- package/src/ui/dialogs/partInfo.ts +60 -60
- package/src/ui/dialogs/pedalMarking.ts +117 -117
- package/src/ui/dialogs/pedalMarkingVue.ts +73 -73
- package/src/ui/dialogs/pitch.ts +352 -352
- package/src/ui/dialogs/preferences.ts +40 -40
- package/src/ui/dialogs/rehearsalMark.ts +64 -64
- package/src/ui/dialogs/rehearsalMarkVue.ts +57 -57
- package/src/ui/dialogs/scoreId.ts +35 -36
- package/src/ui/dialogs/scoreView.ts +42 -42
- package/src/ui/dialogs/slur.ts +308 -310
- package/src/ui/dialogs/slurVue.ts +91 -91
- package/src/ui/dialogs/staffGroup.ts +112 -112
- package/src/ui/dialogs/tabNote.ts +84 -84
- package/src/ui/dialogs/tabStave.ts +182 -182
- package/src/ui/dialogs/tempo.ts +261 -263
- package/src/ui/dialogs/tempoVue.ts +73 -73
- package/src/ui/dialogs/textBlockVue.ts +127 -127
- package/src/ui/dialogs/textBracket.ts +114 -116
- package/src/ui/dialogs/textBracketVue.ts +56 -56
- package/src/ui/dialogs/tie.ts +140 -142
- package/src/ui/dialogs/timeSignature.ts +65 -66
- package/src/ui/dialogs/transposeScore.ts +39 -39
- package/src/ui/dialogs/unsavedChanges.ts +43 -0
- package/src/ui/dialogs/volta.ts +120 -122
- package/src/ui/dialogs/voltaVue.ts +51 -51
- package/src/ui/fileio/library.ts +110 -111
- package/src/ui/menus/edit.ts +100 -1
- package/src/ui/menus/file.ts +19 -3
- package/tests/pageDivisions.ts +156 -0
- package/tests/promiseHelpersUsage.ts +142 -0
- package/tests/scoreChangeState.ts +102 -0
- package/tests/selectVoice.ts +189 -0
- package/tests/voiceCopyPaste.ts +417 -0
package/src/ui/dialogs/dialog.ts
CHANGED
|
@@ -1,620 +1,627 @@
|
|
|
1
|
-
// [Smoosic](https://github.com/AaronDavidNewman/Smoosic)
|
|
2
|
-
// Copyright (c) Aaron David Newman 2021.
|
|
3
|
-
import { SvgHelpers } from '../../render/sui/svgHelpers';
|
|
4
|
-
import { buildDom, InputTrapper, draggable, createTopDomContainer } from '../../common/htmlHelpers';
|
|
5
|
-
// import { SmoTranslator } from '../i18n/language';
|
|
6
|
-
import { SmoModifier } from '../../smo/data/score';
|
|
7
|
-
import { SvgBox } from '../../smo/data/common';
|
|
8
|
-
import { SuiTracker } from '../../render/sui/tracker';
|
|
9
|
-
import { SuiScoreViewOperations } from '../../render/sui/scoreViewOperations';
|
|
10
|
-
import { CompleteNotifier } from '../common';
|
|
11
|
-
import { BrowserEventSource } from '../eventSource';
|
|
12
|
-
import { UndoBuffer } from '../../smo/xform/undo';
|
|
13
|
-
import { SuiDialogNotifier, DialogDefinitionElement,
|
|
14
|
-
SuiComponentBase, DialogDefinitionOption, SuiBaseComponentParams, SmoDynamicComponentCtor } from './components/baseComponent';
|
|
15
|
-
import { SuiScroller } from '../../render/sui/scroller';
|
|
16
|
-
import { SmoNote } from '../../smo/data/note';
|
|
17
|
-
import { EventHandler } from '../eventSource';
|
|
18
|
-
import { SmoUiConfiguration } from '../configuration';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
*
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
params.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
trapper.close();
|
|
108
|
-
params.dialogParams.view.navigation.hideDialogModal();
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
params.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
//
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
*
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
*
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
* @
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
this.
|
|
319
|
-
this.
|
|
320
|
-
|
|
321
|
-
this.
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
this.
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
this.
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
this.
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
this.
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
this.
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
this.
|
|
388
|
-
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
if (this.modifier === null) {
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
this.boundComponents.forEach((comp) => {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
//
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
const
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
//
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
this.
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
*
|
|
611
|
-
* @category SuiDialog
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
1
|
+
// [Smoosic](https://github.com/AaronDavidNewman/Smoosic)
|
|
2
|
+
// Copyright (c) Aaron David Newman 2021.
|
|
3
|
+
import { SvgHelpers } from '../../render/sui/svgHelpers';
|
|
4
|
+
import { buildDom, InputTrapper, draggable, createTopDomContainer } from '../../common/htmlHelpers';
|
|
5
|
+
// import { SmoTranslator } from '../i18n/language';
|
|
6
|
+
import { SmoModifier } from '../../smo/data/score';
|
|
7
|
+
import { SvgBox } from '../../smo/data/common';
|
|
8
|
+
import { SuiTracker } from '../../render/sui/tracker';
|
|
9
|
+
import { SuiScoreViewOperations } from '../../render/sui/scoreViewOperations';
|
|
10
|
+
import { CompleteNotifier } from '../common';
|
|
11
|
+
import { BrowserEventSource } from '../eventSource';
|
|
12
|
+
import { UndoBuffer } from '../../smo/xform/undo';
|
|
13
|
+
import { SuiDialogNotifier, DialogDefinitionElement,
|
|
14
|
+
SuiComponentBase, DialogDefinitionOption, SuiBaseComponentParams, SmoDynamicComponentCtor } from './components/baseComponent';
|
|
15
|
+
import { SuiScroller } from '../../render/sui/scroller';
|
|
16
|
+
import { SmoNote } from '../../smo/data/note';
|
|
17
|
+
import { EventHandler } from '../eventSource';
|
|
18
|
+
import { SmoUiConfiguration } from '../configuration';
|
|
19
|
+
import { createApp, ref, Ref, watch, App } from 'vue';
|
|
20
|
+
import { SuiNavigationDom } from '../navigation';
|
|
21
|
+
import { layoutDebug, SuiNavigation } from '../../../typedoc';
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
declare var $: any;
|
|
25
|
+
/**
|
|
26
|
+
* The key/mouse event handlers take this as a parameter when we are switching control
|
|
27
|
+
* of the input, due to a modal menu or dialog.
|
|
28
|
+
*/
|
|
29
|
+
class closeModalPromiser {
|
|
30
|
+
closeModalPromise: Promise<void>;
|
|
31
|
+
closeEvent: Ref<boolean>;
|
|
32
|
+
createUnbindPromise = async () => {
|
|
33
|
+
return new Promise<void>((resolve) => {
|
|
34
|
+
watch(this.closeEvent, () => {
|
|
35
|
+
resolve();
|
|
36
|
+
});
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
constructor(closeEvent: Ref<boolean>) {
|
|
40
|
+
this.closeEvent = closeEvent;
|
|
41
|
+
this.closeModalPromise = this.createUnbindPromise();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export type DialogCallback = () => Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Parameters for installing a dialog. VUE-based dialog logic.
|
|
47
|
+
* complete is a Ref that is set to true when the dialog is finished, used to
|
|
48
|
+
* hand off keyboard control between dialogs and menus.
|
|
49
|
+
* app is a VUE app, appParams are the parameters to pass to the app.
|
|
50
|
+
* we override commitCb, cancelCb, and removeCb to manage the dialog lifetime.
|
|
51
|
+
* root is the DOM id to mount the dialog in (without the '#')
|
|
52
|
+
* @category SuiDialog
|
|
53
|
+
*/
|
|
54
|
+
export interface DialogInstallParams {
|
|
55
|
+
root: string,
|
|
56
|
+
app: any,
|
|
57
|
+
appParams: any,
|
|
58
|
+
dialogParams: SuiDialogParams,
|
|
59
|
+
commitCb: DialogCallback,
|
|
60
|
+
cancelCb: DialogCallback,
|
|
61
|
+
removeCb?: DialogCallback,
|
|
62
|
+
/**
|
|
63
|
+
* Called after the dialog has been committed, closed and unmounted (not on cancel). Use this
|
|
64
|
+
* to do something that needs another dialog, which can't be shown until this one is gone.
|
|
65
|
+
*/
|
|
66
|
+
afterCloseCb?: DialogCallback
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* The callbacks can be confusing. Dialog CB button calls this callback,
|
|
70
|
+
* which in turn calls the user-supplied callback, and then hides the dialog.
|
|
71
|
+
* params.commitCb is the supplied callback,
|
|
72
|
+
* but appParams.commitCb is set to this function.
|
|
73
|
+
* @param params
|
|
74
|
+
*/
|
|
75
|
+
export const InstallDialog = async (params: DialogInstallParams) => {
|
|
76
|
+
// If the dialog is raised from another dialog or menu that hasn't closed, wait for it
|
|
77
|
+
// to close. This is required so we can keep keyboard/mouse event manager in sync.
|
|
78
|
+
if (params.dialogParams.startPromise) {
|
|
79
|
+
await params.dialogParams.startPromise;
|
|
80
|
+
}
|
|
81
|
+
const complete: Ref<boolean> = ref(false);
|
|
82
|
+
// Track the mounted app so we can explicitly unmount it on close (mirrors
|
|
83
|
+
// SuiMenuManager's menuApp handling). replaceVueRoot only detaches the DOM
|
|
84
|
+
// via jQuery .empty() the next time a dialog opens -- it never calls Vue's
|
|
85
|
+
// own unmount -- so without this, a dismissed dialog's component tree stays
|
|
86
|
+
// alive with its lifecycle hooks (onBeforeUnmount) never firing, letting
|
|
87
|
+
// things like the lyric/chord/text editors' debounced preview timers fire
|
|
88
|
+
// after close and redraw a cursor marker that never gets removed.
|
|
89
|
+
let dialogApp: App | null = null;
|
|
90
|
+
|
|
91
|
+
const trapper = new InputTrapper('#vue-modal-container');
|
|
92
|
+
trapper.trap();
|
|
93
|
+
const commitCb = async () => {
|
|
94
|
+
complete.value = true;
|
|
95
|
+
await params.commitCb();
|
|
96
|
+
params.dialogParams.view.groupUndo(false);
|
|
97
|
+
trapper.close();
|
|
98
|
+
params.dialogParams.view.navigation.hideDialogModal();
|
|
99
|
+
dialogApp?.unmount();
|
|
100
|
+
if (params.afterCloseCb) {
|
|
101
|
+
await params.afterCloseCb();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const cancelCb = async () => {
|
|
105
|
+
complete.value = true;
|
|
106
|
+
await params.cancelCb();
|
|
107
|
+
trapper.close();
|
|
108
|
+
params.dialogParams.view.navigation.hideDialogModal();
|
|
109
|
+
dialogApp?.unmount();
|
|
110
|
+
}
|
|
111
|
+
const removeCb = async () => {
|
|
112
|
+
if (params.removeCb) {
|
|
113
|
+
await params.removeCb();
|
|
114
|
+
}
|
|
115
|
+
trapper.close();
|
|
116
|
+
params.dialogParams.view.navigation.hideDialogModal();
|
|
117
|
+
complete.value = true;
|
|
118
|
+
dialogApp?.unmount();
|
|
119
|
+
}
|
|
120
|
+
$('#' + params.root).addClass('modal show fade');
|
|
121
|
+
params.appParams.commitCb = commitCb;
|
|
122
|
+
params.appParams.cancelCb = cancelCb;
|
|
123
|
+
if (params.removeCb) {
|
|
124
|
+
params.appParams.removeCb = removeCb;
|
|
125
|
+
}
|
|
126
|
+
dialogApp = createApp(params.app as any, params.appParams);
|
|
127
|
+
dialogApp.mount('#' + params.root);
|
|
128
|
+
|
|
129
|
+
// allow a dialog to be dismissed by esc.
|
|
130
|
+
const evKey = async (evdata: any) => {
|
|
131
|
+
if (evdata.key === 'Escape') {
|
|
132
|
+
cancelCb();
|
|
133
|
+
evdata.preventDefault();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// We take over he keyboard for the modal dialog so the user doesn't change the score
|
|
137
|
+
// while typing into the dialog. the 'completeNotifier' takes it back when we are done
|
|
138
|
+
params.dialogParams.completeNotifier.unbindKeyboardForModal(new closeModalPromiser(complete));
|
|
139
|
+
params.dialogParams.eventSource.bindKeydownHandler(evKey);
|
|
140
|
+
params.dialogParams.view.navigation.showDialogModal();
|
|
141
|
+
/* const cb = () => { };
|
|
142
|
+
draggable({
|
|
143
|
+
parent: $('#' + params.root).find('.attributeModal'),
|
|
144
|
+
handle: $('#' + params.root).find('.jsDbMove'),
|
|
145
|
+
animateDiv: '.draganime',
|
|
146
|
+
cb,
|
|
147
|
+
moveParent: true
|
|
148
|
+
});*/
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* The JSON dialog template is a declaritive structore for the html of the dialog
|
|
153
|
+
* and components.
|
|
154
|
+
* @param label for the dialog itself
|
|
155
|
+
* @param elements a series of elements that define the component
|
|
156
|
+
* @param staticText a hash of text for the dialog and components to use
|
|
157
|
+
* @category SuiDialog
|
|
158
|
+
*/
|
|
159
|
+
export interface DialogDefinition {
|
|
160
|
+
label: string,
|
|
161
|
+
elements: DialogDefinitionElement[],
|
|
162
|
+
staticText: Record<string, string>[]
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* A translation of the labels in DialogDefintionElement
|
|
166
|
+
* @param label the component label
|
|
167
|
+
* @param id used as a key in translation tool
|
|
168
|
+
* @param options options for dropdown and other array components
|
|
169
|
+
* @category SuiDialog
|
|
170
|
+
*/
|
|
171
|
+
export interface DialogTranslationElement {
|
|
172
|
+
label: string,
|
|
173
|
+
id: string,
|
|
174
|
+
options?: DialogDefinitionOption[]
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* A translation of all the strings in the dialog itself, used
|
|
178
|
+
* when switching languages.
|
|
179
|
+
* @param ctor the constructor for the dialog class, used to call static methods
|
|
180
|
+
* @param label the translated label
|
|
181
|
+
* @param dialogElements the translated component json
|
|
182
|
+
* @param staticText translated misc text
|
|
183
|
+
* @category SuiDialog
|
|
184
|
+
*/
|
|
185
|
+
export interface DialogTranslation {
|
|
186
|
+
ctor: string,
|
|
187
|
+
label: string,
|
|
188
|
+
dialogElements: DialogTranslationElement[],
|
|
189
|
+
staticText: Record<string, string>
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export const DialogTranslations: DialogTranslation[] = [];
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Dialog params always contain basic information about the runtime
|
|
196
|
+
* for modal functionality
|
|
197
|
+
* @param ctor dialog constructor
|
|
198
|
+
* @param id DOM id for the dialog
|
|
199
|
+
* @param tracker to get and set selections
|
|
200
|
+
* @param completeNotifier used to take over key/mouse control
|
|
201
|
+
* @param startPromise used if this is called from another modal element
|
|
202
|
+
* @param view the MVVM object to change the score
|
|
203
|
+
* @param eventSource event source to register for additional events like mouseup
|
|
204
|
+
* @param undoBuffer used to create undo
|
|
205
|
+
* @category SuiDialog
|
|
206
|
+
*/
|
|
207
|
+
export interface SuiDialogParams {
|
|
208
|
+
ctor: string,
|
|
209
|
+
id: string,
|
|
210
|
+
tracker: SuiTracker,
|
|
211
|
+
completeNotifier: CompleteNotifier,
|
|
212
|
+
startPromise: Promise<void> | null
|
|
213
|
+
view: SuiScoreViewOperations,
|
|
214
|
+
eventSource: BrowserEventSource,
|
|
215
|
+
// definition: DialogDefinition,
|
|
216
|
+
modifier?: any,
|
|
217
|
+
config?: SmoUiConfiguration
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* internal interface used to create the DOM
|
|
222
|
+
* @internal
|
|
223
|
+
*/
|
|
224
|
+
export interface SuiDomParams {
|
|
225
|
+
id: string,
|
|
226
|
+
top: number,
|
|
227
|
+
left: number,
|
|
228
|
+
label: string
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* DOM interface for the dialog
|
|
232
|
+
* @internal
|
|
233
|
+
* @param element parent element
|
|
234
|
+
* @param trapper used to trap focus events for the dialog
|
|
235
|
+
*/
|
|
236
|
+
export interface DialogDom {
|
|
237
|
+
element: any,
|
|
238
|
+
trapper: any
|
|
239
|
+
}
|
|
240
|
+
export const suiDialogTranslate = (dialog: DialogDefinition, ctor: string): DialogTranslation => {
|
|
241
|
+
const elements: DialogDefinitionElement[] = dialog.elements;
|
|
242
|
+
const output: DialogTranslationElement[] = [];
|
|
243
|
+
elements.forEach((element: DialogDefinitionElement) => {
|
|
244
|
+
const component: Partial<DialogTranslationElement> = {};
|
|
245
|
+
if (element.label) {
|
|
246
|
+
component.label = element.label ?? '';
|
|
247
|
+
component.id = element.smoName;
|
|
248
|
+
if (element.options) {
|
|
249
|
+
component.options = [];
|
|
250
|
+
|
|
251
|
+
element.options.forEach((option) => {
|
|
252
|
+
component.options!.push({ value: option.value, label: option.label, css: option.css });
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
output.push(component as DialogTranslationElement);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
// convert static text from an array of name/value pairs to a record for translation
|
|
259
|
+
const staticText: Record<string, string> = {};
|
|
260
|
+
const dialogStaticText: Record<string, string>[] = dialog.staticText;
|
|
261
|
+
if (dialogStaticText) {
|
|
262
|
+
dialogStaticText.forEach((st) => {
|
|
263
|
+
const key = Object.keys(st)[0];
|
|
264
|
+
staticText[key] = st[key];
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
return { ctor, label: dialog.label, dialogElements: output, staticText };
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Note: Most dialogs will inherit from SuiDialogAdapter, not SuiDialogBase.
|
|
271
|
+
* You will only want to inherit from SuiDialogBase under 2 conditions:
|
|
272
|
+
* 1. the dialog is triviailly simple, like an alert box that makes no changes to the score, or
|
|
273
|
+
* 2. the dialog is extremely complicated in how it interacts with the user, such that a form-based approach won't work
|
|
274
|
+
* @category SuiDialog
|
|
275
|
+
*/
|
|
276
|
+
export abstract class SuiDialogBase extends SuiDialogNotifier {
|
|
277
|
+
static get displayOptions(): Record<string, string> {
|
|
278
|
+
return {
|
|
279
|
+
BINDCOMPONENTS: 'bindComponents', DRAGGABLE: 'makeDraggable',
|
|
280
|
+
KEYBOARD_CAPTURE: 'captureKeyboardPromise', GLOBALPOS: 'positionGlobally',
|
|
281
|
+
SELECTIONPOS: 'positionFromSelection', MODIFIERPOS: 'positionFromModifier',
|
|
282
|
+
HIDEREMOVE: 'hideRemoveButton'
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
static getStaticText(staticText: Record<string, string>[]) {
|
|
287
|
+
const rv: Record<string, string> = {};
|
|
288
|
+
staticText.forEach((st) => {
|
|
289
|
+
const key = Object.keys(st)[0];
|
|
290
|
+
rv[key] = st[key];
|
|
291
|
+
});
|
|
292
|
+
return rv;
|
|
293
|
+
}
|
|
294
|
+
id: string;
|
|
295
|
+
ctor: string;
|
|
296
|
+
debug: layoutDebug;
|
|
297
|
+
boundKeyboard: boolean;
|
|
298
|
+
components: SuiComponentBase[] = [];
|
|
299
|
+
boundComponents: SuiComponentBase[] = [];
|
|
300
|
+
cmap: Record<string, SuiComponentBase> = {};
|
|
301
|
+
scroller: SuiScroller;
|
|
302
|
+
closeDialogPromise: Promise<void>;
|
|
303
|
+
label: string;
|
|
304
|
+
staticText: Record<string, string>[] = [];
|
|
305
|
+
startPromise: Promise<void> | null;
|
|
306
|
+
dialogElements: DialogDefinition;
|
|
307
|
+
eventSource: BrowserEventSource;
|
|
308
|
+
view: SuiScoreViewOperations;
|
|
309
|
+
completeNotifier: CompleteNotifier;
|
|
310
|
+
modifier: any;
|
|
311
|
+
dgDom: DialogDom;
|
|
312
|
+
displayOptions: string[] = ['BINDCOMPONENTS', 'DRAGGABLE', 'KEYBOARD_CAPTURE', 'GLOBALPOS', 'HIDEREMOVE'];
|
|
313
|
+
keydownHandler: EventHandler | null = null;
|
|
314
|
+
// ### SuiDialogBase ctor
|
|
315
|
+
// Creates the DOM element for the dialog and gets some initial elements
|
|
316
|
+
constructor(dialogElements: DialogDefinition, parameters: SuiDialogParams) {
|
|
317
|
+
super();
|
|
318
|
+
this.id = parameters.id;
|
|
319
|
+
this.boundKeyboard = false;
|
|
320
|
+
this.scroller = parameters.view.tracker.scroller;
|
|
321
|
+
this.label = dialogElements.label;
|
|
322
|
+
this.eventSource = parameters.eventSource;
|
|
323
|
+
this.view = parameters.view;
|
|
324
|
+
this.debug = parameters.view.debug;
|
|
325
|
+
this.completeNotifier = parameters.completeNotifier;
|
|
326
|
+
this.modifier = parameters.modifier;
|
|
327
|
+
this.ctor = parameters.ctor;
|
|
328
|
+
|
|
329
|
+
this.closeDialogPromise = new Promise<void>((resolve) => {
|
|
330
|
+
$('body').off('dialogDismiss').on('dialogDismiss', () => {
|
|
331
|
+
resolve();
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
this.staticText = dialogElements.staticText;
|
|
335
|
+
|
|
336
|
+
// If this dialog was spawned by a menu, wait for the menu to dismiss
|
|
337
|
+
// before continuing.
|
|
338
|
+
// this.startPromise = parameters.closeMenuPromise;
|
|
339
|
+
this.startPromise = parameters.startPromise;
|
|
340
|
+
|
|
341
|
+
this.dialogElements = dialogElements;
|
|
342
|
+
|
|
343
|
+
const left = $(this.view.navigation.scrollContainer).offset().left + $(this.view.navigation.scrollContainer).width() / 2;
|
|
344
|
+
const top = $(this.view.navigation.scrollContainer).offset().top + $(this.view.navigation.scrollContainer).height() / 2;
|
|
345
|
+
|
|
346
|
+
this.dgDom = this._constructDialog(dialogElements, {
|
|
347
|
+
id: 'dialog-' + this.id,
|
|
348
|
+
top,
|
|
349
|
+
left,
|
|
350
|
+
label: this.label
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
// SmoTranslator.registerDialog(this.ctor);
|
|
354
|
+
}
|
|
355
|
+
// ### display
|
|
356
|
+
// make3 the modal visible. bind events and elements.
|
|
357
|
+
display() {
|
|
358
|
+
$('body').addClass('showAttributeDialog');
|
|
359
|
+
this.bindComponents();
|
|
360
|
+
this.bindElements();
|
|
361
|
+
this.applyDisplayOptions();
|
|
362
|
+
this.initialValue();
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// ### bindElements
|
|
366
|
+
// bing the generic controls in most dialogs.
|
|
367
|
+
bindElements() {
|
|
368
|
+
var dgDom = this.dgDom;
|
|
369
|
+
$(dgDom.element).find('.ok-button').off('click').on('click', () => {
|
|
370
|
+
this.view.groupUndo(false);
|
|
371
|
+
this.commit();
|
|
372
|
+
this.complete();
|
|
373
|
+
});
|
|
374
|
+
$(dgDom.element).find('.cancel-button').off('click').on('click', () => {
|
|
375
|
+
this.view.groupUndo(false);
|
|
376
|
+
if (this.modifier) {
|
|
377
|
+
this.modifier.cancel();
|
|
378
|
+
}
|
|
379
|
+
this.complete();
|
|
380
|
+
});
|
|
381
|
+
$(dgDom.element).find('.remove-button').off('click').on('click', () => {
|
|
382
|
+
this.view.groupUndo(false);
|
|
383
|
+
this.complete();
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
bindComponents() {
|
|
387
|
+
this.components.forEach((component) => {
|
|
388
|
+
component.bind();
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
initialValue(){
|
|
392
|
+
if (this.modifier === null) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
this.boundComponents.forEach((comp) => {
|
|
396
|
+
(comp as any).setValue((this.modifier as any)[comp.smoName]);
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
async changed() {
|
|
400
|
+
if (this.modifier === null) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
this.boundComponents.forEach((comp) => {
|
|
404
|
+
if (comp.changeFlag) {
|
|
405
|
+
(this.modifier as any)[comp.smoName] = (comp as any).getValue();
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
getId(): string {
|
|
410
|
+
return this.id;
|
|
411
|
+
}
|
|
412
|
+
getModifier() : SmoModifier | null {
|
|
413
|
+
return this.modifier ?? null;
|
|
414
|
+
}
|
|
415
|
+
getEventSource() {
|
|
416
|
+
return this.eventSource;
|
|
417
|
+
}
|
|
418
|
+
getStaticText() {
|
|
419
|
+
return SuiDialogBase.getStaticText(this.staticText);
|
|
420
|
+
}
|
|
421
|
+
async commit(): Promise<any> {
|
|
422
|
+
}
|
|
423
|
+
get closeModalPromise(): Promise<any> {
|
|
424
|
+
return this.closeDialogPromise;
|
|
425
|
+
}
|
|
426
|
+
// ### position
|
|
427
|
+
// For dialogs based on selections, tries to place the dialog near the selection and also
|
|
428
|
+
// to scroll so the dialog is in view
|
|
429
|
+
static position(box: SvgBox, dgDom: DialogDom, scroller: SuiScroller, navigation: SuiNavigation) {
|
|
430
|
+
let y = (box.y + box.height) - scroller.netScroll.y;
|
|
431
|
+
let x = 0;
|
|
432
|
+
|
|
433
|
+
// TODO: adjust if db is clipped by the browser.
|
|
434
|
+
const dge = $(dgDom.element).find('.attributeModal');
|
|
435
|
+
const dgeHeight: number = $(dge).height();
|
|
436
|
+
const scrollRegion = $(navigation.scrollContainer);
|
|
437
|
+
const domRegion = $(navigation.outerContainer);
|
|
438
|
+
const maxY: number = scrollRegion.height();
|
|
439
|
+
const maxX: number = scrollRegion.width();
|
|
440
|
+
const offset: any = domRegion.offset();
|
|
441
|
+
y = y - (offset.top as number);
|
|
442
|
+
|
|
443
|
+
const offsetY = dgeHeight + y > window.innerHeight ? (dgeHeight + y) - window.innerHeight : 0;
|
|
444
|
+
y = (y < 0) ? -y : y - offsetY;
|
|
445
|
+
|
|
446
|
+
y = (y > maxY || y < 0) ? maxY / 2 : y;
|
|
447
|
+
|
|
448
|
+
$(dge).css('top', '' + y + 'px');
|
|
449
|
+
|
|
450
|
+
x = box.x - scroller.netScroll.x;
|
|
451
|
+
x = x - (offset.left as number);
|
|
452
|
+
const w: number = $(dge).width();
|
|
453
|
+
x = (x > window.innerWidth / 2) ? x - (w + 25) : x + (w + 25);
|
|
454
|
+
|
|
455
|
+
x = (x < 0 || x > maxX) ? maxX / 2 : x;
|
|
456
|
+
$(dge).css('left', '' + x + 'px');
|
|
457
|
+
}
|
|
458
|
+
getView() {
|
|
459
|
+
return this.view;
|
|
460
|
+
}
|
|
461
|
+
applyDisplayOptions() {
|
|
462
|
+
$('body').addClass('showAttributeDialog');
|
|
463
|
+
this.displayOptions.forEach((option) => {
|
|
464
|
+
(this as any)[SuiDialogBase.displayOptions[option]]();
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
// ### position
|
|
468
|
+
// Position the dialog near a selection. If the dialog is not visible due
|
|
469
|
+
// to scrolling, make sure it is visible.
|
|
470
|
+
position(box: SvgBox) {
|
|
471
|
+
SuiDialogBase.position(box, this.dgDom, this.view.tracker.scroller, this.view.navigation);
|
|
472
|
+
}
|
|
473
|
+
hideRemoveButton() {
|
|
474
|
+
$(this.dgDom.element).find('.remove-button').remove();
|
|
475
|
+
}
|
|
476
|
+
// ### positionModifier()
|
|
477
|
+
positionFromModifier() {
|
|
478
|
+
if (!this.modifier || this.modifier.logicalBox === null) {
|
|
479
|
+
this.positionGlobally();
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
const pageContext = this.view.renderer.pageMap.getRendererFromModifier(this.modifier);
|
|
483
|
+
const screenBox = this.view.renderer.pageMap.svgToClient(this.modifier.logicalBox);
|
|
484
|
+
this.position(screenBox);
|
|
485
|
+
}
|
|
486
|
+
// ### positionGlobally
|
|
487
|
+
// position the dialog box in the center of the current scroll region
|
|
488
|
+
positionGlobally() {
|
|
489
|
+
const box = SvgHelpers.boxPoints(250, 250, 1, 1);
|
|
490
|
+
SuiDialogBase.position(box, this.dgDom, this.view.tracker.scroller, this.view.navigation);
|
|
491
|
+
}
|
|
492
|
+
// ### postionFromSelection
|
|
493
|
+
// set initial position of dialog based on first selection
|
|
494
|
+
positionFromSelection() {
|
|
495
|
+
const note: SmoNote | null = this.view.tracker.selections[0].note;
|
|
496
|
+
if (note && note.logicalBox) {
|
|
497
|
+
const screenBox = this.view.renderer.pageMap.svgToClient(note.logicalBox);
|
|
498
|
+
this.position(screenBox);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
// ### build the html for the dialog, based on the instance-specific components.
|
|
502
|
+
_constructDialog(dialogElements: DialogDefinition, parameters: SuiDomParams) {
|
|
503
|
+
createTopDomContainer('.attributeDialog');
|
|
504
|
+
const id = parameters.id;
|
|
505
|
+
const b = buildDom;
|
|
506
|
+
const r = b('div').classes('attributeModal').attr('id', 'attr-modal-' + id)
|
|
507
|
+
.css('top', parameters.top + 'px').css('left', parameters.left + 'px')
|
|
508
|
+
.append(b('spanb').classes('draggable button').append(b('span').classes('icon icon-move jsDbMove')))
|
|
509
|
+
.append(b('h2').classes('dialog-label').text(this.label));
|
|
510
|
+
|
|
511
|
+
var ctrl = b('div').classes('smoControlContainer');
|
|
512
|
+
dialogElements.elements.filter((de) => de.control).forEach((de) => {
|
|
513
|
+
const classes = de.classes ? de.classes : '';
|
|
514
|
+
const compParams: SuiBaseComponentParams = {
|
|
515
|
+
classes, id: id + de.smoName, ...de
|
|
516
|
+
}
|
|
517
|
+
try {
|
|
518
|
+
const control: SuiComponentBase = SmoDynamicComponentCtor[de.control](this, compParams);
|
|
519
|
+
this.components.push(control);
|
|
520
|
+
this.cmap[de.smoName + 'Ctrl'] = control;
|
|
521
|
+
ctrl.append(control.html);
|
|
522
|
+
} catch (exp) {
|
|
523
|
+
console.error('bad ctor ' + de.smoName);
|
|
524
|
+
throw(exp);
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
r.append(ctrl);
|
|
528
|
+
r.append(
|
|
529
|
+
b('div').classes('buttonContainer').append(
|
|
530
|
+
b('button').classes('ok-button button-left btn btn-primary').text('OK')).append(
|
|
531
|
+
b('button').classes('cancel-button button-center btn btn-secondary').text('Cancel')).append(
|
|
532
|
+
b('button').classes('remove-button button-right btn btn-secondary').text('Remove').append(
|
|
533
|
+
b('span').classes('icon icon-cancel-circle'))));
|
|
534
|
+
$('.attributeDialog').html('');
|
|
535
|
+
|
|
536
|
+
$('.attributeDialog').append(r.dom());
|
|
537
|
+
|
|
538
|
+
const trapper = new InputTrapper('.attributeDialog');
|
|
539
|
+
trapper.trap();
|
|
540
|
+
$('.attributeDialog').find('.cancel-button').focus();
|
|
541
|
+
return {
|
|
542
|
+
element: $('.attributeDialog'),
|
|
543
|
+
trapper
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
// ### Complete
|
|
547
|
+
// Dialogs take over the keyboard, so release that and trigger an event
|
|
548
|
+
// that the dialog is closing that can resolve any outstanding promises.
|
|
549
|
+
complete() {
|
|
550
|
+
if (this.boundKeyboard && this.keydownHandler) {
|
|
551
|
+
this.eventSource.unbindKeydownHandler(this.keydownHandler);
|
|
552
|
+
}
|
|
553
|
+
$('body').removeClass('showAttributeDialog');
|
|
554
|
+
$('body').trigger('dialogDismiss');
|
|
555
|
+
this.dgDom.trapper.close();
|
|
556
|
+
}
|
|
557
|
+
// ### makeDraggable
|
|
558
|
+
// generic code to make the dialog box draggable so it doesn't
|
|
559
|
+
// get in front of stuff.
|
|
560
|
+
makeDraggable() {
|
|
561
|
+
createTopDomContainer('.draganime');
|
|
562
|
+
const cb = () => { };
|
|
563
|
+
draggable({
|
|
564
|
+
parent: $(this.dgDom.element).find('.attributeModal'),
|
|
565
|
+
handle: $(this.dgDom.element).find('.jsDbMove'),
|
|
566
|
+
animateDiv: '.draganime',
|
|
567
|
+
cb,
|
|
568
|
+
moveParent: true
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
// ### captureKeyboardPromise
|
|
572
|
+
// capture keyboard events until the dialog closes,
|
|
573
|
+
// then give control back to the current keyboard
|
|
574
|
+
async captureKeyboardPromise() {
|
|
575
|
+
if (!(this.startPromise)) {
|
|
576
|
+
this.completeNotifier.unbindKeyboardForModal(this);
|
|
577
|
+
this.bindKeyboard();
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
if (this.startPromise) {
|
|
581
|
+
await this.startPromise;
|
|
582
|
+
this.completeNotifier.unbindKeyboardForModal(this);
|
|
583
|
+
this.bindKeyboard();
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// ### handleKeydown
|
|
588
|
+
// allow a dialog to be dismissed by esc.
|
|
589
|
+
evKey(evdata: any) {
|
|
590
|
+
if (evdata.key === 'Escape') {
|
|
591
|
+
$(this.dgDom.element).find('.cancel-button').click();
|
|
592
|
+
evdata.preventDefault();
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// ### bindKeyboard
|
|
597
|
+
// generic logic to grab keyboard elements for modal
|
|
598
|
+
bindKeyboard() {
|
|
599
|
+
const evkey = async (ev: any) => {
|
|
600
|
+
this.evKey(ev);
|
|
601
|
+
}
|
|
602
|
+
this.boundKeyboard = true;
|
|
603
|
+
this.keydownHandler = this.eventSource.bindKeydownHandler(evkey);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Convenience functions
|
|
608
|
+
* @param type
|
|
609
|
+
* @param parameters
|
|
610
|
+
* @returns a new dialog of type T
|
|
611
|
+
* @category SuiDialog
|
|
612
|
+
*/
|
|
613
|
+
export function dialogConstructor<T extends SuiDialogBase>(type: { new(parameters: SuiDialogParams): T; }, parameters: SuiDialogParams ): T {
|
|
614
|
+
return new type(parameters);
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Convenience function to display a dialog
|
|
618
|
+
* @category SuiDialog
|
|
619
|
+
* @param ctor
|
|
620
|
+
* @param parameters
|
|
621
|
+
* @returns
|
|
622
|
+
*/
|
|
623
|
+
export function createAndDisplayDialog<T extends SuiDialogBase>(ctor: new (parameters: SuiDialogParams) => T, parameters: SuiDialogParams): T {
|
|
624
|
+
const instance: T = dialogConstructor<T>(ctor, parameters);
|
|
625
|
+
instance.display();
|
|
626
|
+
return instance;
|
|
627
|
+
}
|