@fusion.dev/helix-headless 0.238.1 → 0.239.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/api.json +1 -1
- package/custom-elements.json +1 -1
- package/dist/editor/root/editor-root.d.ts +106 -7
- package/dist/editor/root/editor-root.js +273 -50
- package/dist/navigation/root/navigation-root.d.ts +115 -1
- package/dist/navigation/root/navigation-root.js +220 -8
- package/lint.json +1 -1
- package/package.json +5 -5
- package/types/jsx.d.ts +122 -1
- package/types/vue.d.ts +46 -0
- package/types/words.d.ts +20 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { auditName, customElement, drawIcon, formatWords, HelixElement, MIRROR_RULE, onApple, stopPress, words, } from '@fusion.dev/helix-core';
|
|
3
|
-
import { arrowClockwise, arrowCounterClockwise, caretDown, check, code, link, linkBreak, listBullets, listNumbers, magnifyingGlass, quotes, textB, textItalic, textStrikethrough, x, } from '@fusion.dev/helix-icons';
|
|
2
|
+
import { auditName, customElement, drawIcon, formatWords, HelixElement, MIRROR_RULE, OverflowController, onApple, stopPress, words, } from '@fusion.dev/helix-core';
|
|
3
|
+
import { arrowClockwise, arrowCounterClockwise, caretDown, check, code, dotsThree, link, linkBreak, listBullets, listNumbers, magnifyingGlass, quotes, textAa, textB, textItalic, textStrikethrough, x, } from '@fusion.dev/helix-icons';
|
|
4
4
|
import { nothing } from 'lit';
|
|
5
5
|
import { property, state } from 'lit/decorators.js';
|
|
6
6
|
import { live } from 'lit/directives/live.js';
|
|
@@ -48,9 +48,44 @@ const TOOL_PARTS = [
|
|
|
48
48
|
'ordered-list',
|
|
49
49
|
'quote',
|
|
50
50
|
'find-toggle',
|
|
51
|
+
'more',
|
|
51
52
|
]
|
|
52
53
|
.map((name) => `[part~="${name}"]`)
|
|
53
54
|
.join(', ');
|
|
55
|
+
const BAR = [
|
|
56
|
+
'undo',
|
|
57
|
+
'redo',
|
|
58
|
+
'block',
|
|
59
|
+
'bold',
|
|
60
|
+
'italic',
|
|
61
|
+
'strike',
|
|
62
|
+
'code',
|
|
63
|
+
'link',
|
|
64
|
+
'bullet-list',
|
|
65
|
+
'ordered-list',
|
|
66
|
+
'quote',
|
|
67
|
+
'find',
|
|
68
|
+
];
|
|
69
|
+
const BAR_GROUPS = [
|
|
70
|
+
['undo', 'redo'],
|
|
71
|
+
['block'],
|
|
72
|
+
['bold', 'italic', 'strike', 'code'],
|
|
73
|
+
['link'],
|
|
74
|
+
['bullet-list', 'ordered-list', 'quote'],
|
|
75
|
+
['find'],
|
|
76
|
+
];
|
|
77
|
+
const GLYPHS = {
|
|
78
|
+
block: textAa,
|
|
79
|
+
bold: textB,
|
|
80
|
+
'bullet-list': listBullets,
|
|
81
|
+
code,
|
|
82
|
+
find: magnifyingGlass,
|
|
83
|
+
italic: textItalic,
|
|
84
|
+
link,
|
|
85
|
+
'ordered-list': listNumbers,
|
|
86
|
+
quote: quotes,
|
|
87
|
+
strike: textStrikethrough,
|
|
88
|
+
};
|
|
54
89
|
const NO_FORMATS = { applied: [], block: '', link: '', unavailable: [] };
|
|
55
90
|
const commandWith = (event, key) => event.key.toLowerCase() === key &&
|
|
56
91
|
!event.altKey &&
|
|
@@ -77,6 +112,7 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
77
112
|
this.linkFieldLabel = 'Address';
|
|
78
113
|
this.linkLabel = 'Link';
|
|
79
114
|
this.linkRemoveLabel = 'Remove link';
|
|
115
|
+
this.moreLabel = 'More tools';
|
|
80
116
|
this.orderedListLabel = 'Numbered list';
|
|
81
117
|
this.paragraphLabel = 'Paragraph';
|
|
82
118
|
this.placeholder = '';
|
|
@@ -92,7 +128,11 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
92
128
|
this.findOpen = false;
|
|
93
129
|
this.hasActions = false;
|
|
94
130
|
this.escaped = false;
|
|
95
|
-
this.
|
|
131
|
+
this.overflow = new OverflowController(this, {
|
|
132
|
+
apply: (step) => this.fold(step),
|
|
133
|
+
box: () => this.partNamed('controls'),
|
|
134
|
+
steps: () => this.onBar.length,
|
|
135
|
+
});
|
|
96
136
|
this.handleLinkInput = (event) => {
|
|
97
137
|
this.draft = event.target.value;
|
|
98
138
|
};
|
|
@@ -164,9 +204,10 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
164
204
|
}
|
|
165
205
|
};
|
|
166
206
|
this.handleMenuToggle = (event) => {
|
|
167
|
-
if (event.newState === 'closed' && this.
|
|
168
|
-
|
|
169
|
-
this.
|
|
207
|
+
if (event.newState === 'closed' && this.afterMenu) {
|
|
208
|
+
const after = this.afterMenu;
|
|
209
|
+
this.afterMenu = undefined;
|
|
210
|
+
after();
|
|
170
211
|
}
|
|
171
212
|
};
|
|
172
213
|
}
|
|
@@ -310,7 +351,7 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
310
351
|
this.closeLink();
|
|
311
352
|
}
|
|
312
353
|
focusToolbar() {
|
|
313
|
-
const tools = [...this.renderRoot.querySelectorAll(TOOL_PARTS)].filter((one) => !one.hasAttribute('disabled'));
|
|
354
|
+
const tools = [...this.renderRoot.querySelectorAll(TOOL_PARTS)].filter((one) => !one.hasAttribute('disabled') && one.closest('[hidden]') === null);
|
|
314
355
|
const stop = tools.find((one) => one.shadowRoot?.querySelector('[tabindex="0"]')) ?? tools[0];
|
|
315
356
|
stop?.focus();
|
|
316
357
|
}
|
|
@@ -352,7 +393,43 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
352
393
|
}
|
|
353
394
|
choose(tool) {
|
|
354
395
|
this.run(tool);
|
|
355
|
-
this.
|
|
396
|
+
this.afterMenu = () => this.returnFocus();
|
|
397
|
+
}
|
|
398
|
+
chooseFolded(tool) {
|
|
399
|
+
if (this.disabled(tool)) {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
this.run(tool);
|
|
403
|
+
this.afterMenu = () => this.returnFocus();
|
|
404
|
+
}
|
|
405
|
+
get onBar() {
|
|
406
|
+
if (this.readOnly) {
|
|
407
|
+
return [];
|
|
408
|
+
}
|
|
409
|
+
return BAR.filter((tool) => tool === 'block'
|
|
410
|
+
? EDITOR_BLOCKS.some((one) => this.draws(one))
|
|
411
|
+
: tool === 'find'
|
|
412
|
+
? this.drawsFind
|
|
413
|
+
: this.draws(tool));
|
|
414
|
+
}
|
|
415
|
+
foldedAt(step) {
|
|
416
|
+
const bar = this.onBar;
|
|
417
|
+
return new Set(step <= 0 ? [] : bar.slice(Math.max(0, bar.length - step)));
|
|
418
|
+
}
|
|
419
|
+
allFolded(tools) {
|
|
420
|
+
const folded = this.foldedAt(this.overflow.step);
|
|
421
|
+
return tools.length > 0 && tools.every((tool) => folded.has(tool));
|
|
422
|
+
}
|
|
423
|
+
fold(step) {
|
|
424
|
+
const folded = this.foldedAt(step);
|
|
425
|
+
for (const element of this.renderRoot.querySelectorAll('[data-fold]')) {
|
|
426
|
+
const tools = (element.dataset.fold ?? '').split(' ');
|
|
427
|
+
element.hidden = tools.every((tool) => folded.has(tool));
|
|
428
|
+
}
|
|
429
|
+
const menu = this.partNamed('overflow');
|
|
430
|
+
if (menu) {
|
|
431
|
+
menu.hidden = folded.size === 0;
|
|
432
|
+
}
|
|
356
433
|
}
|
|
357
434
|
connectedCallback() {
|
|
358
435
|
super.connectedCallback();
|
|
@@ -390,6 +467,10 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
390
467
|
}
|
|
391
468
|
this.toggleState('link-open', this.linkOpen);
|
|
392
469
|
this.toggleState('find-open', this.findOpen);
|
|
470
|
+
if ([...changed.keys()].some((key) => key !== 'formats' && key !== 'draft') ||
|
|
471
|
+
changed.size === 0) {
|
|
472
|
+
this.overflow.request();
|
|
473
|
+
}
|
|
393
474
|
}
|
|
394
475
|
get blockEmphasis() {
|
|
395
476
|
return undefined;
|
|
@@ -402,32 +483,54 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
402
483
|
${unsafeSVG(glyph.content)}
|
|
403
484
|
</svg>`;
|
|
404
485
|
}
|
|
486
|
+
glyphOf(tool) {
|
|
487
|
+
if (tool === 'undo') {
|
|
488
|
+
return this.renderPointing(arrowCounterClockwise);
|
|
489
|
+
}
|
|
490
|
+
if (tool === 'redo') {
|
|
491
|
+
return this.renderPointing(arrowClockwise);
|
|
492
|
+
}
|
|
493
|
+
return drawIcon(GLYPHS[tool]);
|
|
494
|
+
}
|
|
495
|
+
renderBarIcon(tool) {
|
|
496
|
+
return this.foldedAt(this.overflow.step).has(tool)
|
|
497
|
+
? this.glyphOf(tool)
|
|
498
|
+
: html `<slot name=${`${tool}-icon`}>${this.glyphOf(tool)}</slot>`;
|
|
499
|
+
}
|
|
500
|
+
drawnOf(tools) {
|
|
501
|
+
const bar = this.onBar;
|
|
502
|
+
return tools.filter((tool) => bar.includes(tool));
|
|
503
|
+
}
|
|
405
504
|
renderHistory() {
|
|
406
505
|
if (!this.draws('undo') && !this.draws('redo')) {
|
|
407
506
|
return nothing;
|
|
408
507
|
}
|
|
409
508
|
const button = this.tag('icon-button');
|
|
410
|
-
return html `<div part="tools">${this.draws('undo')
|
|
509
|
+
return html `<div part="tools" data-fold=${this.drawnOf(['undo', 'redo']).join(' ')} ?hidden=${this.allFolded(this.drawnOf(['undo', 'redo']))}>${this.draws('undo')
|
|
411
510
|
? html `<${button}
|
|
412
511
|
part="undo"
|
|
413
512
|
exportparts="button: undo-button, live: undo-live, spinner: undo-spinner, text: undo-text"
|
|
513
|
+
data-fold="undo"
|
|
514
|
+
?hidden=${this.allFolded(['undo'])}
|
|
414
515
|
?disabled=${this.disabled('undo')}
|
|
415
516
|
label=${this.undoLabel}
|
|
416
517
|
@click=${() => this.press('undo')}
|
|
417
518
|
@helix-press=${stopPress}
|
|
418
519
|
>
|
|
419
|
-
|
|
520
|
+
${this.renderBarIcon('undo')}
|
|
420
521
|
</${button}>`
|
|
421
522
|
: nothing}${this.draws('redo')
|
|
422
523
|
? html `<${button}
|
|
423
524
|
part="redo"
|
|
424
525
|
exportparts="button: redo-button, live: redo-live, spinner: redo-spinner, text: redo-text"
|
|
526
|
+
data-fold="redo"
|
|
527
|
+
?hidden=${this.allFolded(['redo'])}
|
|
425
528
|
?disabled=${this.disabled('redo')}
|
|
426
529
|
label=${this.redoLabel}
|
|
427
530
|
@click=${() => this.press('redo')}
|
|
428
531
|
@helix-press=${stopPress}
|
|
429
532
|
>
|
|
430
|
-
|
|
533
|
+
${this.renderBarIcon('redo')}
|
|
431
534
|
</${button}>`
|
|
432
535
|
: nothing}</div>`;
|
|
433
536
|
}
|
|
@@ -436,53 +539,61 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
436
539
|
return nothing;
|
|
437
540
|
}
|
|
438
541
|
const button = this.tag('icon-button');
|
|
439
|
-
return html `<div part="tools">${this.draws('bold')
|
|
542
|
+
return html `<div part="tools" data-fold=${this.drawnOf(['bold', 'italic', 'strike', 'code']).join(' ')} ?hidden=${this.allFolded(this.drawnOf(['bold', 'italic', 'strike', 'code']))}>${this.draws('bold')
|
|
440
543
|
? html `<${button}
|
|
441
544
|
part="bold${this.pressed('bold') ? ' bold-pressed' : ''}"
|
|
442
545
|
exportparts="button: bold-button, live: bold-live, spinner: bold-spinner, text: bold-text"
|
|
546
|
+
data-fold="bold"
|
|
547
|
+
?hidden=${this.allFolded(['bold'])}
|
|
443
548
|
aria-pressed=${this.pressed('bold') ? 'true' : 'false'}
|
|
444
549
|
?disabled=${this.disabled('bold')}
|
|
445
550
|
label=${this.boldLabel}
|
|
446
551
|
@click=${() => this.press('bold')}
|
|
447
552
|
@helix-press=${stopPress}
|
|
448
553
|
>
|
|
449
|
-
|
|
554
|
+
${this.renderBarIcon('bold')}
|
|
450
555
|
</${button}>`
|
|
451
556
|
: nothing}${this.draws('italic')
|
|
452
557
|
? html `<${button}
|
|
453
558
|
part="italic${this.pressed('italic') ? ' italic-pressed' : ''}"
|
|
454
559
|
exportparts="button: italic-button, live: italic-live, spinner: italic-spinner, text: italic-text"
|
|
560
|
+
data-fold="italic"
|
|
561
|
+
?hidden=${this.allFolded(['italic'])}
|
|
455
562
|
aria-pressed=${this.pressed('italic') ? 'true' : 'false'}
|
|
456
563
|
?disabled=${this.disabled('italic')}
|
|
457
564
|
label=${this.italicLabel}
|
|
458
565
|
@click=${() => this.press('italic')}
|
|
459
566
|
@helix-press=${stopPress}
|
|
460
567
|
>
|
|
461
|
-
|
|
568
|
+
${this.renderBarIcon('italic')}
|
|
462
569
|
</${button}>`
|
|
463
570
|
: nothing}${this.draws('strike')
|
|
464
571
|
? html `<${button}
|
|
465
572
|
part="strike${this.pressed('strike') ? ' strike-pressed' : ''}"
|
|
466
573
|
exportparts="button: strike-button, live: strike-live, spinner: strike-spinner, text: strike-text"
|
|
574
|
+
data-fold="strike"
|
|
575
|
+
?hidden=${this.allFolded(['strike'])}
|
|
467
576
|
aria-pressed=${this.pressed('strike') ? 'true' : 'false'}
|
|
468
577
|
?disabled=${this.disabled('strike')}
|
|
469
578
|
label=${this.strikeLabel}
|
|
470
579
|
@click=${() => this.press('strike')}
|
|
471
580
|
@helix-press=${stopPress}
|
|
472
581
|
>
|
|
473
|
-
|
|
582
|
+
${this.renderBarIcon('strike')}
|
|
474
583
|
</${button}>`
|
|
475
584
|
: nothing}${this.draws('code')
|
|
476
585
|
? html `<${button}
|
|
477
586
|
part="code${this.pressed('code') ? ' code-pressed' : ''}"
|
|
478
587
|
exportparts="button: code-button, live: code-live, spinner: code-spinner, text: code-text"
|
|
588
|
+
data-fold="code"
|
|
589
|
+
?hidden=${this.allFolded(['code'])}
|
|
479
590
|
aria-pressed=${this.pressed('code') ? 'true' : 'false'}
|
|
480
591
|
?disabled=${this.disabled('code')}
|
|
481
592
|
label=${this.codeLabel}
|
|
482
593
|
@click=${() => this.press('code')}
|
|
483
594
|
@helix-press=${stopPress}
|
|
484
595
|
>
|
|
485
|
-
|
|
596
|
+
${this.renderBarIcon('code')}
|
|
486
597
|
</${button}>`
|
|
487
598
|
: nothing}</div>`;
|
|
488
599
|
}
|
|
@@ -495,6 +606,8 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
495
606
|
return html `<${button}
|
|
496
607
|
part="link${linked ? ' link-pressed' : ''}"
|
|
497
608
|
exportparts="button: link-button, live: link-live, spinner: link-spinner, text: link-text"
|
|
609
|
+
data-fold="link"
|
|
610
|
+
?hidden=${this.allFolded(['link'])}
|
|
498
611
|
aria-pressed=${linked ? 'true' : 'false'}
|
|
499
612
|
.expanded=${this.linkOpen}
|
|
500
613
|
?disabled=${this.disabled('link')}
|
|
@@ -502,7 +615,7 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
502
615
|
@click=${() => (this.linkOpen ? this.closeLink() : this.openLink())}
|
|
503
616
|
@helix-press=${stopPress}
|
|
504
617
|
>
|
|
505
|
-
|
|
618
|
+
${this.renderBarIcon('link')}
|
|
506
619
|
</${button}>`;
|
|
507
620
|
}
|
|
508
621
|
renderLists() {
|
|
@@ -514,25 +627,29 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
514
627
|
? html `<${button}
|
|
515
628
|
part="bullet-list${this.pressed('bullet-list') ? ' bullet-list-pressed' : ''}"
|
|
516
629
|
exportparts="button: bullet-list-button, live: bullet-list-live, spinner: bullet-list-spinner, text: bullet-list-text"
|
|
630
|
+
data-fold="bullet-list"
|
|
631
|
+
?hidden=${this.allFolded(['bullet-list'])}
|
|
517
632
|
aria-pressed=${this.pressed('bullet-list') ? 'true' : 'false'}
|
|
518
633
|
?disabled=${this.disabled('bullet-list')}
|
|
519
634
|
label=${this.bulletListLabel}
|
|
520
635
|
@click=${() => this.press('bullet-list')}
|
|
521
636
|
@helix-press=${stopPress}
|
|
522
637
|
>
|
|
523
|
-
|
|
638
|
+
${this.renderBarIcon('bullet-list')}
|
|
524
639
|
</${button}>`
|
|
525
640
|
: nothing}${this.draws('ordered-list')
|
|
526
641
|
? html `<${button}
|
|
527
642
|
part="ordered-list${this.pressed('ordered-list') ? ' ordered-list-pressed' : ''}"
|
|
528
643
|
exportparts="button: ordered-list-button, live: ordered-list-live, spinner: ordered-list-spinner, text: ordered-list-text"
|
|
644
|
+
data-fold="ordered-list"
|
|
645
|
+
?hidden=${this.allFolded(['ordered-list'])}
|
|
529
646
|
aria-pressed=${this.pressed('ordered-list') ? 'true' : 'false'}
|
|
530
647
|
?disabled=${this.disabled('ordered-list')}
|
|
531
648
|
label=${this.orderedListLabel}
|
|
532
649
|
@click=${() => this.press('ordered-list')}
|
|
533
650
|
@helix-press=${stopPress}
|
|
534
651
|
>
|
|
535
|
-
|
|
652
|
+
${this.renderBarIcon('ordered-list')}
|
|
536
653
|
</${button}>`
|
|
537
654
|
: nothing}`;
|
|
538
655
|
}
|
|
@@ -541,7 +658,7 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
541
658
|
const quote = this.renderQuote();
|
|
542
659
|
return lists === nothing && quote === nothing
|
|
543
660
|
? nothing
|
|
544
|
-
: html `<div part="tools">${lists}${quote}</div>`;
|
|
661
|
+
: html `<div part="tools" data-fold=${this.drawnOf(['bullet-list', 'ordered-list', 'quote']).join(' ')} ?hidden=${this.allFolded(this.drawnOf(['bullet-list', 'ordered-list', 'quote']))}>${lists}${quote}</div>`;
|
|
545
662
|
}
|
|
546
663
|
renderQuote() {
|
|
547
664
|
if (!this.draws('quote')) {
|
|
@@ -551,13 +668,15 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
551
668
|
return html `<${button}
|
|
552
669
|
part="quote${this.pressed('quote') ? ' quote-pressed' : ''}"
|
|
553
670
|
exportparts="button: quote-button, live: quote-live, spinner: quote-spinner, text: quote-text"
|
|
671
|
+
data-fold="quote"
|
|
672
|
+
?hidden=${this.allFolded(['quote'])}
|
|
554
673
|
aria-pressed=${this.pressed('quote') ? 'true' : 'false'}
|
|
555
674
|
?disabled=${this.disabled('quote')}
|
|
556
675
|
label=${this.quoteLabel}
|
|
557
676
|
@click=${() => this.press('quote')}
|
|
558
677
|
@helix-press=${stopPress}
|
|
559
678
|
>
|
|
560
|
-
|
|
679
|
+
${this.renderBarIcon('quote')}
|
|
561
680
|
</${button}>`;
|
|
562
681
|
}
|
|
563
682
|
renderBlockMenu() {
|
|
@@ -566,12 +685,13 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
566
685
|
return nothing;
|
|
567
686
|
}
|
|
568
687
|
const menu = this.tag('menu');
|
|
569
|
-
const item = this.tag('menu-item');
|
|
570
688
|
const button = this.tag('button');
|
|
571
689
|
const current = this.formats.block;
|
|
572
690
|
const shown = current === '' ? 'paragraph' : current;
|
|
573
691
|
return html `<${menu}
|
|
574
692
|
part="block-menu"
|
|
693
|
+
data-fold="block"
|
|
694
|
+
?hidden=${this.allFolded(['block'])}
|
|
575
695
|
exportparts="back: block-menu-back, back-mark: block-menu-back-mark, empty: block-menu-empty,
|
|
576
696
|
header: block-menu-header, live: block-menu-live, loading: block-menu-loading,
|
|
577
697
|
search-field: block-menu-search-field, surface: block-menu-surface,
|
|
@@ -593,30 +713,38 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
593
713
|
</span>
|
|
594
714
|
${drawIcon(caretDown, { slot: 'end' })}
|
|
595
715
|
</${button}>
|
|
596
|
-
${
|
|
597
|
-
part="block-option"
|
|
598
|
-
exportparts="end: block-option-end, item: block-option-item, mark: block-option-mark,
|
|
599
|
-
shortcut: block-option-shortcut, shortcut-kbd: block-option-shortcut-kbd,
|
|
600
|
-
shortcut-key: block-option-shortcut-key, shortcut-separator: block-option-shortcut-separator,
|
|
601
|
-
start: block-option-start, surface: block-option-surface"
|
|
602
|
-
value=${tool}
|
|
603
|
-
checkable
|
|
604
|
-
exclusive
|
|
605
|
-
?checked=${tool === current}
|
|
606
|
-
?disabled=${this.disabled(tool)}
|
|
607
|
-
shortcut=${SHORTCUTS[tool] ?? nothing}
|
|
608
|
-
@helix-before-check=${this.keepTick}
|
|
609
|
-
@helix-before-select=${() => this.choose(tool)}
|
|
610
|
-
>
|
|
611
|
-
${this.nameOf(tool)}
|
|
612
|
-
</${item}>`)}
|
|
716
|
+
${this.renderBlockOptions()}
|
|
613
717
|
</${menu}>`;
|
|
614
718
|
}
|
|
615
|
-
|
|
719
|
+
renderBlockOptions(slot) {
|
|
720
|
+
const item = this.tag('menu-item');
|
|
721
|
+
const current = this.formats.block;
|
|
722
|
+
return EDITOR_BLOCKS.filter((tool) => this.draws(tool)).map((tool) => html `<${item}
|
|
723
|
+
part="block-option"
|
|
724
|
+
exportparts="end: block-option-end, item: block-option-item, mark: block-option-mark,
|
|
725
|
+
shortcut: block-option-shortcut, shortcut-kbd: block-option-shortcut-kbd,
|
|
726
|
+
shortcut-key: block-option-shortcut-key, shortcut-separator: block-option-shortcut-separator,
|
|
727
|
+
start: block-option-start, surface: block-option-surface"
|
|
728
|
+
slot=${slot ?? nothing}
|
|
729
|
+
value=${tool}
|
|
730
|
+
checkable
|
|
731
|
+
exclusive
|
|
732
|
+
?checked=${tool === current}
|
|
733
|
+
?disabled=${this.disabled(tool)}
|
|
734
|
+
shortcut=${SHORTCUTS[tool] ?? nothing}
|
|
735
|
+
@helix-before-check=${this.keepTick}
|
|
736
|
+
@helix-before-select=${() => this.choose(tool)}
|
|
737
|
+
>
|
|
738
|
+
${this.nameOf(tool)}
|
|
739
|
+
</${item}>`);
|
|
740
|
+
}
|
|
741
|
+
renderDivider(tools = []) {
|
|
616
742
|
const divider = this.tag('divider');
|
|
617
743
|
return html `<${divider}
|
|
618
744
|
part="divider"
|
|
619
745
|
exportparts="content: divider-content, line: divider-line"
|
|
746
|
+
data-fold=${tools.length > 0 ? tools.join(' ') : nothing}
|
|
747
|
+
?hidden=${this.allFolded(tools)}
|
|
620
748
|
orientation="vertical"
|
|
621
749
|
></${divider}>`;
|
|
622
750
|
}
|
|
@@ -628,13 +756,15 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
628
756
|
return html `<${button}
|
|
629
757
|
part="find-toggle"
|
|
630
758
|
exportparts="button: find-toggle-button, live: find-toggle-live, spinner: find-toggle-spinner, text: find-toggle-text"
|
|
759
|
+
data-fold="find"
|
|
760
|
+
?hidden=${this.allFolded(['find'])}
|
|
631
761
|
.expanded=${this.findOpen}
|
|
632
762
|
?disabled=${!this.renderer}
|
|
633
763
|
label=${this.findLabel}
|
|
634
764
|
@click=${() => (this.findOpen ? this.find?.element.hide() : void this.openFind())}
|
|
635
765
|
@helix-press=${stopPress}
|
|
636
766
|
>
|
|
637
|
-
|
|
767
|
+
${this.renderBarIcon('find')}
|
|
638
768
|
</${button}>`;
|
|
639
769
|
}
|
|
640
770
|
renderFind() {
|
|
@@ -653,21 +783,110 @@ let HelixHeadlessEditor = class HelixHeadlessEditor extends HelixElement {
|
|
|
653
783
|
}
|
|
654
784
|
renderControls() {
|
|
655
785
|
const toolbar = this.tag('toolbar');
|
|
786
|
+
const drawn = [
|
|
787
|
+
this.renderHistory(),
|
|
788
|
+
this.renderBlockMenu(),
|
|
789
|
+
this.renderMarks(),
|
|
790
|
+
this.renderLinkTool(),
|
|
791
|
+
this.renderBlocks(),
|
|
792
|
+
this.renderFindTool(),
|
|
793
|
+
];
|
|
656
794
|
const groups = this.readOnly
|
|
657
795
|
? []
|
|
658
|
-
: [
|
|
659
|
-
this.renderHistory(),
|
|
660
|
-
this.renderBlockMenu(),
|
|
661
|
-
this.renderMarks(),
|
|
662
|
-
this.renderLinkTool(),
|
|
663
|
-
this.renderBlocks(),
|
|
664
|
-
this.renderFindTool(),
|
|
665
|
-
].filter((group) => group !== nothing);
|
|
796
|
+
: BAR_GROUPS.map((tools, at) => ({ template: drawn[at], tools: this.drawnOf(tools) })).filter((group) => group.template !== nothing);
|
|
666
797
|
return html `<${toolbar} part="controls" exportparts="toolbar: controls-toolbar" label=${this.controlsLabel} @keydown=${this.handleToolbarKeys}>
|
|
667
|
-
${groups.map((group, at) =>
|
|
798
|
+
${groups.map((group, at) => at === 0 ? group.template : html `${this.renderDivider(group.tools)}${group.template}`)}
|
|
799
|
+
${this.renderOverflow()}
|
|
668
800
|
<slot name="actions" part="actions" ?hidden=${!this.hasActions} @slotchange=${this.handleActions}></slot>
|
|
669
801
|
</${toolbar}>`;
|
|
670
802
|
}
|
|
803
|
+
renderOverflow() {
|
|
804
|
+
const bar = this.onBar;
|
|
805
|
+
if (bar.length === 0) {
|
|
806
|
+
return nothing;
|
|
807
|
+
}
|
|
808
|
+
const menu = this.tag('menu');
|
|
809
|
+
const button = this.tag('icon-button');
|
|
810
|
+
const divider = this.tag('divider');
|
|
811
|
+
const folded = this.foldedAt(this.overflow.step);
|
|
812
|
+
const groups = BAR_GROUPS.map((tools) => tools.filter((tool) => folded.has(tool))).filter((tools) => tools.length > 0);
|
|
813
|
+
return html `<${menu}
|
|
814
|
+
part="overflow"
|
|
815
|
+
exportparts="back: overflow-back, back-mark: overflow-back-mark, empty: overflow-empty,
|
|
816
|
+
header: overflow-header, live: overflow-live, loading: overflow-loading,
|
|
817
|
+
search-field: overflow-search-field, surface: overflow-surface,
|
|
818
|
+
title: overflow-title"
|
|
819
|
+
label=${this.moreLabel}
|
|
820
|
+
placement="bottom-end"
|
|
821
|
+
?hidden=${folded.size === 0}
|
|
822
|
+
@toggle=${this.handleMenuToggle}
|
|
823
|
+
>
|
|
824
|
+
<${button}
|
|
825
|
+
part="more"
|
|
826
|
+
exportparts="button: more-button, live: more-live, spinner: more-spinner, text: more-text"
|
|
827
|
+
slot="trigger"
|
|
828
|
+
label=${this.moreLabel}
|
|
829
|
+
@helix-press=${stopPress}
|
|
830
|
+
>
|
|
831
|
+
<slot name="more-icon">${drawIcon(dotsThree)}</slot>
|
|
832
|
+
</${button}>
|
|
833
|
+
${groups.map((tools, at) => html `${at === 0 ? nothing : html `<${divider} part="overflow-divider" exportparts="content: overflow-divider-content, line: overflow-divider-line"></${divider}>`}${tools.map((tool) => this.renderFolded(tool))}`)}
|
|
834
|
+
</${menu}>`;
|
|
835
|
+
}
|
|
836
|
+
renderFolded(tool) {
|
|
837
|
+
const item = this.tag('menu-item');
|
|
838
|
+
const icon = html `<slot name=${`${tool}-icon`} slot="start">${this.glyphOf(tool)}</slot>`;
|
|
839
|
+
if (tool === 'block') {
|
|
840
|
+
return html `<${item}
|
|
841
|
+
part="overflow-option"
|
|
842
|
+
exportparts="end: overflow-option-end, item: overflow-option-item, mark: overflow-option-mark,
|
|
843
|
+
shortcut: overflow-option-shortcut, shortcut-kbd: overflow-option-shortcut-kbd,
|
|
844
|
+
shortcut-key: overflow-option-shortcut-key, shortcut-separator: overflow-option-shortcut-separator,
|
|
845
|
+
start: overflow-option-start, surface: overflow-option-surface"
|
|
846
|
+
value="block"
|
|
847
|
+
?disabled=${!this.renderer}
|
|
848
|
+
>
|
|
849
|
+
${drawIcon(textAa, { slot: 'start' })}
|
|
850
|
+
${this.blockLabel}
|
|
851
|
+
${this.renderBlockOptions('submenu')}
|
|
852
|
+
</${item}>`;
|
|
853
|
+
}
|
|
854
|
+
if (tool === 'link' || tool === 'find') {
|
|
855
|
+
const open = tool === 'link' ? () => this.openLink() : () => void this.openFind();
|
|
856
|
+
return html `<${item}
|
|
857
|
+
part="overflow-option"
|
|
858
|
+
exportparts="end: overflow-option-end, item: overflow-option-item, mark: overflow-option-mark,
|
|
859
|
+
shortcut: overflow-option-shortcut, shortcut-kbd: overflow-option-shortcut-kbd,
|
|
860
|
+
shortcut-key: overflow-option-shortcut-key, shortcut-separator: overflow-option-shortcut-separator,
|
|
861
|
+
start: overflow-option-start, surface: overflow-option-surface"
|
|
862
|
+
value=${tool}
|
|
863
|
+
?disabled=${tool === 'link' ? this.disabled('link') : !this.renderer}
|
|
864
|
+
@helix-before-select=${() => {
|
|
865
|
+
this.afterMenu = open;
|
|
866
|
+
}}
|
|
867
|
+
>
|
|
868
|
+
${icon}
|
|
869
|
+
${tool === 'link' ? this.linkLabel : this.findLabel}
|
|
870
|
+
</${item}>`;
|
|
871
|
+
}
|
|
872
|
+
const checks = tool !== 'undo' && tool !== 'redo';
|
|
873
|
+
return html `<${item}
|
|
874
|
+
part="overflow-option"
|
|
875
|
+
exportparts="end: overflow-option-end, item: overflow-option-item, mark: overflow-option-mark,
|
|
876
|
+
shortcut: overflow-option-shortcut, shortcut-kbd: overflow-option-shortcut-kbd,
|
|
877
|
+
shortcut-key: overflow-option-shortcut-key, shortcut-separator: overflow-option-shortcut-separator,
|
|
878
|
+
start: overflow-option-start, surface: overflow-option-surface"
|
|
879
|
+
value=${tool}
|
|
880
|
+
?checkable=${checks}
|
|
881
|
+
?checked=${checks && this.pressed(tool)}
|
|
882
|
+
?disabled=${this.disabled(tool)}
|
|
883
|
+
@helix-before-check=${this.keepTick}
|
|
884
|
+
@helix-before-select=${() => this.chooseFolded(tool)}
|
|
885
|
+
>
|
|
886
|
+
${icon}
|
|
887
|
+
${this.nameOf(tool)}
|
|
888
|
+
</${item}>`;
|
|
889
|
+
}
|
|
671
890
|
renderLink() {
|
|
672
891
|
if (this.readOnly || !this.draws('link')) {
|
|
673
892
|
return nothing;
|
|
@@ -806,6 +1025,10 @@ __decorate([
|
|
|
806
1025
|
words,
|
|
807
1026
|
property({ attribute: 'link-remove-label' })
|
|
808
1027
|
], HelixHeadlessEditor.prototype, "linkRemoveLabel", void 0);
|
|
1028
|
+
__decorate([
|
|
1029
|
+
words,
|
|
1030
|
+
property({ attribute: 'more-label' })
|
|
1031
|
+
], HelixHeadlessEditor.prototype, "moreLabel", void 0);
|
|
809
1032
|
__decorate([
|
|
810
1033
|
words,
|
|
811
1034
|
property({ attribute: 'ordered-list-label' })
|