@chordproject/editor 1.0.0 → 1.1.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/dist/index.cjs +546 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +555 -15
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { Compartment, EditorState as EditorState2 } from "@codemirror/state";
|
|
3
3
|
import { EditorView as EditorView5 } from "@codemirror/view";
|
|
4
|
+
import { openSearchPanel, search } from "@codemirror/search";
|
|
4
5
|
|
|
5
6
|
// src/autocomplete/index.ts
|
|
6
7
|
import {
|
|
@@ -152,10 +153,15 @@ var CHORDPRO_SNIPPETS = [
|
|
|
152
153
|
|
|
153
154
|
// src/autocomplete/index.ts
|
|
154
155
|
var completeSnippets = completeFromList(CHORDPRO_SNIPPETS);
|
|
156
|
+
var QUICK_SNIPPET_PREFIXES = new Set(
|
|
157
|
+
CHORDPRO_SNIPPETS.map((snippet) => snippet.label).filter((label) => label.length <= 3 && /^[a-z]+$/i.test(label))
|
|
158
|
+
);
|
|
155
159
|
function chordProCompletionSource(context) {
|
|
156
160
|
const chordCompletions = chordCompletionSource(context);
|
|
157
161
|
if (chordCompletions) return chordCompletions;
|
|
158
|
-
|
|
162
|
+
const word = context.matchBefore(/[a-z]+$/i);
|
|
163
|
+
const isQuickSnippet = word && QUICK_SNIPPET_PREFIXES.has(word.text.toLowerCase());
|
|
164
|
+
return context.explicit || isQuickSnippet ? completeSnippets(context) : null;
|
|
159
165
|
}
|
|
160
166
|
function chordProAutocomplete() {
|
|
161
167
|
return autocompletion({ override: [chordProCompletionSource], activateOnTyping: true });
|
|
@@ -188,6 +194,7 @@ import {
|
|
|
188
194
|
import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
|
|
189
195
|
import { bracketMatching, foldGutter, foldKeymap } from "@codemirror/language";
|
|
190
196
|
import { lintGutter, lintKeymap } from "@codemirror/lint";
|
|
197
|
+
import { searchKeymap } from "@codemirror/search";
|
|
191
198
|
import {
|
|
192
199
|
acceptCompletion,
|
|
193
200
|
closeBrackets,
|
|
@@ -235,6 +242,7 @@ function basicSetup() {
|
|
|
235
242
|
...historyKeymap,
|
|
236
243
|
...foldKeymap,
|
|
237
244
|
...lintKeymap,
|
|
245
|
+
...searchKeymap,
|
|
238
246
|
// Override completionKeymap's Ctrl-Space/Option-`/Option-i (same keys, listed first so
|
|
239
247
|
// they take precedence) to be chord-aware instead of plain startCompletion.
|
|
240
248
|
{ key: "Ctrl-Space", run: chordAwareCompletion },
|
|
@@ -520,6 +528,18 @@ var SINGULAR_DIRECTIVES = {
|
|
|
520
528
|
time: "time"
|
|
521
529
|
};
|
|
522
530
|
var DIRECTIVE_LINE = /^\s*\{\s*([A-Za-z_][\w]*)\b/;
|
|
531
|
+
var SECTION_STARTS = {
|
|
532
|
+
start_of_chorus: "end_of_chorus",
|
|
533
|
+
soc: "end_of_chorus",
|
|
534
|
+
chorus: "end_of_chorus",
|
|
535
|
+
start_of_verse: "end_of_verse",
|
|
536
|
+
sov: "end_of_verse",
|
|
537
|
+
start_of_bridge: "end_of_bridge",
|
|
538
|
+
sob: "end_of_bridge",
|
|
539
|
+
start_of_tab: "end_of_tab",
|
|
540
|
+
sot: "end_of_tab"
|
|
541
|
+
};
|
|
542
|
+
var SECTION_ENDS = /* @__PURE__ */ new Set(["end_of_chorus", "eoc", "end_of_verse", "eov", "end_of_bridge", "eob", "end_of_tab", "eot"]);
|
|
523
543
|
var duplicateDirectiveLinter = linter((view) => {
|
|
524
544
|
const diagnostics = [];
|
|
525
545
|
const firstSeenAtLine = /* @__PURE__ */ new Map();
|
|
@@ -547,6 +567,9 @@ var parserWarningLinter = linter((view) => {
|
|
|
547
567
|
const parser = new ChordProParser();
|
|
548
568
|
parser.parse(view.state.doc.toString());
|
|
549
569
|
return parser.warnings.flatMap((warning) => {
|
|
570
|
+
if (warning.code === "empty_sheet") {
|
|
571
|
+
return [];
|
|
572
|
+
}
|
|
550
573
|
if (warning.lineNumber < 1 || warning.lineNumber > view.state.doc.lines) {
|
|
551
574
|
return [];
|
|
552
575
|
}
|
|
@@ -558,7 +581,102 @@ var parserWarningLinter = linter((view) => {
|
|
|
558
581
|
message: warning.message
|
|
559
582
|
}];
|
|
560
583
|
});
|
|
561
|
-
});
|
|
584
|
+
}, { delay: 0 });
|
|
585
|
+
var unclosedSectionLinter = linter((view) => {
|
|
586
|
+
const diagnostics = [];
|
|
587
|
+
let openSection = null;
|
|
588
|
+
let sectionHasContent = false;
|
|
589
|
+
for (let lineNumber = 1; lineNumber <= view.state.doc.lines; lineNumber++) {
|
|
590
|
+
const line = view.state.doc.line(lineNumber);
|
|
591
|
+
const match = line.text.match(DIRECTIVE_LINE);
|
|
592
|
+
const directive = match?.[1].toLowerCase();
|
|
593
|
+
if (directive && SECTION_STARTS[directive]) {
|
|
594
|
+
if (openSection) {
|
|
595
|
+
openSection.insertionAt = line.from;
|
|
596
|
+
openSection.insertionTo = line.from;
|
|
597
|
+
diagnostics.push(sectionDiagnostic(openSection));
|
|
598
|
+
}
|
|
599
|
+
openSection = {
|
|
600
|
+
endDirective: SECTION_STARTS[directive],
|
|
601
|
+
lineFrom: line.from,
|
|
602
|
+
lineTo: line.to,
|
|
603
|
+
insertionAt: line.from,
|
|
604
|
+
insertionTo: line.from
|
|
605
|
+
};
|
|
606
|
+
sectionHasContent = false;
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
if (directive && SECTION_ENDS.has(directive)) {
|
|
610
|
+
openSection = null;
|
|
611
|
+
sectionHasContent = false;
|
|
612
|
+
continue;
|
|
613
|
+
}
|
|
614
|
+
if (openSection && directive) {
|
|
615
|
+
openSection.insertionAt = line.from;
|
|
616
|
+
openSection.insertionTo = line.from;
|
|
617
|
+
diagnostics.push(sectionDiagnostic(openSection));
|
|
618
|
+
openSection = null;
|
|
619
|
+
sectionHasContent = false;
|
|
620
|
+
continue;
|
|
621
|
+
}
|
|
622
|
+
if (openSection && !line.text.trim()) {
|
|
623
|
+
const nextDirective = nextNonBlankDirective(view, lineNumber);
|
|
624
|
+
if (sectionHasContent) {
|
|
625
|
+
openSection.insertionAt = line.from;
|
|
626
|
+
openSection.insertionTo = nextDirective ? nextNonBlankDirectiveLine(view, lineNumber) : line.from;
|
|
627
|
+
diagnostics.push(sectionDiagnostic(openSection));
|
|
628
|
+
openSection = null;
|
|
629
|
+
sectionHasContent = false;
|
|
630
|
+
}
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
if (openSection && lineNumber === view.state.doc.lines) {
|
|
634
|
+
openSection.insertionAt = view.state.doc.length;
|
|
635
|
+
openSection.insertionTo = view.state.doc.length;
|
|
636
|
+
}
|
|
637
|
+
if (openSection) {
|
|
638
|
+
sectionHasContent = true;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
function nextNonBlankDirective(view2, lineNumber) {
|
|
642
|
+
const directiveLine = nextNonBlankDirectiveLine(view2, lineNumber);
|
|
643
|
+
return directiveLine < view2.state.doc.length ? view2.state.doc.lineAt(directiveLine).text.match(DIRECTIVE_LINE)?.[1].toLowerCase() ?? null : null;
|
|
644
|
+
}
|
|
645
|
+
function nextNonBlankDirectiveLine(view2, lineNumber) {
|
|
646
|
+
for (let nextLineNumber = lineNumber + 1; nextLineNumber <= view2.state.doc.lines; nextLineNumber++) {
|
|
647
|
+
const nextLine = view2.state.doc.line(nextLineNumber);
|
|
648
|
+
if (!nextLine.text.trim()) {
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
if (nextLine.text.match(DIRECTIVE_LINE)) {
|
|
652
|
+
return nextLine.from;
|
|
653
|
+
}
|
|
654
|
+
return view2.state.doc.length;
|
|
655
|
+
}
|
|
656
|
+
return view2.state.doc.length;
|
|
657
|
+
}
|
|
658
|
+
if (openSection) {
|
|
659
|
+
diagnostics.push(sectionDiagnostic(openSection));
|
|
660
|
+
}
|
|
661
|
+
return diagnostics;
|
|
662
|
+
}, { delay: 0 });
|
|
663
|
+
function sectionDiagnostic(section) {
|
|
664
|
+
return {
|
|
665
|
+
from: section.lineFrom,
|
|
666
|
+
to: section.lineTo,
|
|
667
|
+
severity: "warning",
|
|
668
|
+
message: `Falta cerrar esta secci\xF3n con {${section.endDirective}}.`,
|
|
669
|
+
actions: [{
|
|
670
|
+
name: `Insertar {${section.endDirective}}`,
|
|
671
|
+
apply: (view, from, to) => {
|
|
672
|
+
const previousCharacter = section.insertionAt > 0 ? view.state.doc.sliceString(section.insertionAt - 1, section.insertionAt) : "";
|
|
673
|
+
const needsLeadingNewline = previousCharacter !== "\n";
|
|
674
|
+
const insertion = `${needsLeadingNewline ? "\n" : ""}{${section.endDirective}}${section.insertionTo < view.state.doc.length ? "\n" : ""}`;
|
|
675
|
+
view.dispatch({ changes: { from: section.insertionAt, to: section.insertionTo, insert: insertion } });
|
|
676
|
+
}
|
|
677
|
+
}]
|
|
678
|
+
};
|
|
679
|
+
}
|
|
562
680
|
var chordNotationLinter = linter((view) => {
|
|
563
681
|
const diagnostics = [];
|
|
564
682
|
for (const replacement of findChordNotationReplacements(view.state.doc.toString())) {
|
|
@@ -588,14 +706,182 @@ var baseTheme = EditorView2.baseTheme({
|
|
|
588
706
|
flex: "1",
|
|
589
707
|
overflow: "auto"
|
|
590
708
|
},
|
|
709
|
+
".cm-selectionLayer": {
|
|
710
|
+
zIndex: "-1 !important"
|
|
711
|
+
},
|
|
712
|
+
".chord-search-panel": {
|
|
713
|
+
position: "absolute",
|
|
714
|
+
top: "0.4rem",
|
|
715
|
+
right: "0.5rem",
|
|
716
|
+
zIndex: "20",
|
|
717
|
+
pointerEvents: "auto",
|
|
718
|
+
display: "flex",
|
|
719
|
+
width: "min(100% - 1rem, 32rem)",
|
|
720
|
+
margin: "0",
|
|
721
|
+
border: "1px solid var(--color-neutral-700, #3f3f46)",
|
|
722
|
+
borderRadius: "0.45rem",
|
|
723
|
+
boxShadow: "0 0.5rem 1.25rem color-mix(in oklch, #000 28%, transparent)",
|
|
724
|
+
flexWrap: "wrap",
|
|
725
|
+
alignItems: "center",
|
|
726
|
+
gap: "0.3rem",
|
|
727
|
+
padding: "0.35rem 0.45rem",
|
|
728
|
+
borderBottom: "1px solid var(--color-neutral-200, #e4e4e7)",
|
|
729
|
+
backgroundColor: "var(--color-white, #ffffff)",
|
|
730
|
+
fontSize: "0.875rem"
|
|
731
|
+
},
|
|
732
|
+
".chord-search-controls": {
|
|
733
|
+
display: "flex",
|
|
734
|
+
flex: "1 1 100%",
|
|
735
|
+
flexWrap: "nowrap",
|
|
736
|
+
alignItems: "center",
|
|
737
|
+
gap: "0.25rem"
|
|
738
|
+
},
|
|
739
|
+
".chord-search-navigation": {
|
|
740
|
+
display: "flex",
|
|
741
|
+
flex: "0 0 auto",
|
|
742
|
+
alignItems: "center",
|
|
743
|
+
gap: "0.2rem"
|
|
744
|
+
},
|
|
745
|
+
".chord-search-fields": {
|
|
746
|
+
display: "flex",
|
|
747
|
+
flex: "1 1 auto",
|
|
748
|
+
minWidth: "0",
|
|
749
|
+
flexDirection: "column",
|
|
750
|
+
gap: "0.25rem"
|
|
751
|
+
},
|
|
752
|
+
".chord-search-replace-row": {
|
|
753
|
+
display: "flex",
|
|
754
|
+
flex: "1 1 100%",
|
|
755
|
+
flexWrap: "nowrap",
|
|
756
|
+
alignItems: "center",
|
|
757
|
+
gap: "0.25rem"
|
|
758
|
+
},
|
|
759
|
+
".chord-search-replace-row[hidden]": {
|
|
760
|
+
display: "none"
|
|
761
|
+
},
|
|
762
|
+
".chord-search-field": {
|
|
763
|
+
flex: "1 1 12rem",
|
|
764
|
+
border: "1px solid var(--color-neutral-300, #d4d4d8)",
|
|
765
|
+
borderRadius: "0.35rem",
|
|
766
|
+
backgroundColor: "var(--color-white, #ffffff)"
|
|
767
|
+
},
|
|
768
|
+
".chord-search-match-count": {
|
|
769
|
+
flex: "0 0 auto",
|
|
770
|
+
minWidth: "3.5rem",
|
|
771
|
+
color: "var(--color-neutral-500, #71717a)",
|
|
772
|
+
fontSize: "0.75rem",
|
|
773
|
+
textAlign: "center",
|
|
774
|
+
whiteSpace: "nowrap"
|
|
775
|
+
},
|
|
776
|
+
".chord-search-field input": {
|
|
777
|
+
boxSizing: "border-box",
|
|
778
|
+
width: "100%",
|
|
779
|
+
minHeight: "1.9rem",
|
|
780
|
+
padding: "0.3rem 0.5rem",
|
|
781
|
+
border: "none",
|
|
782
|
+
outline: "none",
|
|
783
|
+
backgroundColor: "transparent",
|
|
784
|
+
color: "inherit",
|
|
785
|
+
font: "inherit"
|
|
786
|
+
},
|
|
787
|
+
".chord-search-input-with-options": {
|
|
788
|
+
display: "flex",
|
|
789
|
+
alignItems: "center",
|
|
790
|
+
gap: "0.1rem",
|
|
791
|
+
paddingRight: "0.15rem"
|
|
792
|
+
},
|
|
793
|
+
".chord-search-input-with-options input": {
|
|
794
|
+
minWidth: "0",
|
|
795
|
+
border: "none",
|
|
796
|
+
outline: "none",
|
|
797
|
+
backgroundColor: "transparent",
|
|
798
|
+
paddingRight: "0.2rem"
|
|
799
|
+
},
|
|
800
|
+
".chord-search-input-with-options .chord-search-option": {
|
|
801
|
+
minWidth: "1.6rem",
|
|
802
|
+
minHeight: "1.6rem",
|
|
803
|
+
zIndex: "2",
|
|
804
|
+
padding: "0.1rem",
|
|
805
|
+
border: "none",
|
|
806
|
+
backgroundColor: "transparent",
|
|
807
|
+
fontSize: "0.7rem"
|
|
808
|
+
},
|
|
809
|
+
".chord-search-button": {
|
|
810
|
+
minHeight: "1.9rem",
|
|
811
|
+
minWidth: "1.9rem",
|
|
812
|
+
padding: "0.2rem 0.45rem",
|
|
813
|
+
border: "1px solid var(--color-neutral-300, #d4d4d8)",
|
|
814
|
+
borderRadius: "0.35rem",
|
|
815
|
+
backgroundColor: "var(--color-neutral-50, #fafafa)",
|
|
816
|
+
color: "inherit",
|
|
817
|
+
font: "inherit",
|
|
818
|
+
cursor: "pointer"
|
|
819
|
+
},
|
|
820
|
+
".chord-search-button:hover": {
|
|
821
|
+
backgroundColor: "var(--color-neutral-100, #f4f4f5)"
|
|
822
|
+
},
|
|
823
|
+
".chord-search-toggle-replace, .chord-search-previous, .chord-search-next, .chord-search-close": {
|
|
824
|
+
border: "none",
|
|
825
|
+
backgroundColor: "transparent"
|
|
826
|
+
},
|
|
827
|
+
".chord-search-toggle-replace:hover, .chord-search-previous:hover, .chord-search-next:hover, .chord-search-close:hover": {
|
|
828
|
+
backgroundColor: "var(--color-neutral-100, #f4f4f5)"
|
|
829
|
+
},
|
|
830
|
+
".chord-search-close": {
|
|
831
|
+
position: "static",
|
|
832
|
+
fontSize: "1.15rem",
|
|
833
|
+
lineHeight: "1"
|
|
834
|
+
},
|
|
835
|
+
".chord-search-options": {
|
|
836
|
+
display: "flex",
|
|
837
|
+
flexWrap: "wrap",
|
|
838
|
+
gap: "0.8rem",
|
|
839
|
+
color: "var(--color-neutral-600, #52525b)"
|
|
840
|
+
},
|
|
841
|
+
".chord-search-controls .chord-search-field": {
|
|
842
|
+
minWidth: "0",
|
|
843
|
+
flex: "1 1 auto"
|
|
844
|
+
},
|
|
845
|
+
".chord-search-replace-row .chord-search-field": {
|
|
846
|
+
minWidth: "0",
|
|
847
|
+
flex: "1 1 auto"
|
|
848
|
+
},
|
|
849
|
+
".chord-search-option": {
|
|
850
|
+
display: "inline-flex",
|
|
851
|
+
alignItems: "center",
|
|
852
|
+
gap: "0.35rem",
|
|
853
|
+
cursor: "pointer"
|
|
854
|
+
},
|
|
855
|
+
".chord-search-toggle": {
|
|
856
|
+
minWidth: "2.25rem",
|
|
857
|
+
justifyContent: "center",
|
|
858
|
+
fontWeight: "600"
|
|
859
|
+
},
|
|
860
|
+
".chord-search-toggle input": {
|
|
861
|
+
display: "none"
|
|
862
|
+
},
|
|
863
|
+
".chord-search-toggle.is-active": {
|
|
864
|
+
borderColor: "var(--color-primary-500, #3b82f6)",
|
|
865
|
+
backgroundColor: "var(--color-primary-100, #dbeafe)",
|
|
866
|
+
color: "var(--color-primary-700, #1d4ed8)"
|
|
867
|
+
},
|
|
591
868
|
".cm-lintRange-info": {
|
|
592
|
-
backgroundImage: 'url("data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="6" height="3"><path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="%23dc2626" fill="none" stroke-width="1"/></svg>") !important'
|
|
869
|
+
backgroundImage: 'url("data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="6" height="3"><path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="%23dc2626" fill="none" stroke-width="1"/></svg>") !important',
|
|
870
|
+
backgroundSize: "6px 3px",
|
|
871
|
+
backgroundPosition: "left bottom",
|
|
872
|
+
backgroundRepeat: "repeat-x"
|
|
593
873
|
},
|
|
594
874
|
".cm-lintRange-warning": {
|
|
595
|
-
backgroundImage: 'url("data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="6" height="3"><path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="%23d97706" fill="none" stroke-width="1"/></svg>") !important'
|
|
875
|
+
backgroundImage: 'url("data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="6" height="3"><path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="%23d97706" fill="none" stroke-width="1"/></svg>") !important',
|
|
876
|
+
backgroundSize: "6px 3px",
|
|
877
|
+
backgroundPosition: "left bottom",
|
|
878
|
+
backgroundRepeat: "repeat-x"
|
|
596
879
|
},
|
|
597
880
|
".cm-lintRange-error": {
|
|
598
|
-
backgroundImage: 'url("data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="6" height="3"><path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="%23dc2626" fill="none" stroke-width="1"/></svg>") !important'
|
|
881
|
+
backgroundImage: 'url("data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="6" height="3"><path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="%23dc2626" fill="none" stroke-width="1"/></svg>") !important',
|
|
882
|
+
backgroundSize: "6px 3px",
|
|
883
|
+
backgroundPosition: "left bottom",
|
|
884
|
+
backgroundRepeat: "repeat-x"
|
|
599
885
|
}
|
|
600
886
|
});
|
|
601
887
|
|
|
@@ -610,23 +896,25 @@ var editorTheme = EditorView3.theme(
|
|
|
610
896
|
color: "var(--color-neutral-100, #f4f4f5)"
|
|
611
897
|
},
|
|
612
898
|
".cm-content": {
|
|
899
|
+
textDecoration: "none",
|
|
613
900
|
caretColor: "var(--color-neutral-100, #f4f4f5)"
|
|
614
901
|
},
|
|
615
902
|
".cm-cursor, .cm-dropCursor": {
|
|
616
903
|
borderLeftColor: "var(--color-neutral-100, #f4f4f5)"
|
|
617
904
|
},
|
|
618
905
|
"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": {
|
|
619
|
-
backgroundColor: "
|
|
906
|
+
backgroundColor: "var(--color-primary-700, #1d4ed8) !important",
|
|
907
|
+
color: "inherit !important"
|
|
620
908
|
},
|
|
621
909
|
"&.cm-focused .cm-content:focus::selection, &.cm-focused .cm-content .cm-line::selection": {
|
|
622
|
-
backgroundColor: "
|
|
910
|
+
backgroundColor: "var(--color-primary-700, #1d4ed8) !important",
|
|
623
911
|
color: "inherit !important"
|
|
624
912
|
},
|
|
625
913
|
".cm-selectionLayer .cm-selectionBackground": {
|
|
626
|
-
boxShadow: "
|
|
914
|
+
boxShadow: "none"
|
|
627
915
|
},
|
|
628
916
|
".cm-activeLine": {
|
|
629
|
-
backgroundColor: "
|
|
917
|
+
backgroundColor: "transparent"
|
|
630
918
|
},
|
|
631
919
|
".cm-gutters": {
|
|
632
920
|
backgroundColor: "var(--color-neutral-900, #18181b)",
|
|
@@ -636,11 +924,53 @@ var editorTheme = EditorView3.theme(
|
|
|
636
924
|
".cm-activeLineGutter": {
|
|
637
925
|
backgroundColor: "var(--color-neutral-800, #27272a)"
|
|
638
926
|
},
|
|
927
|
+
".chord-search-panel": {
|
|
928
|
+
borderBottomColor: "var(--color-neutral-700, #3f3f46)",
|
|
929
|
+
backgroundColor: "var(--color-neutral-900, #18181b)",
|
|
930
|
+
borderColor: "var(--color-neutral-700, #3f3f46)"
|
|
931
|
+
},
|
|
932
|
+
".chord-search-field input": {
|
|
933
|
+
backgroundColor: "var(--color-neutral-800, #27272a)",
|
|
934
|
+
color: "var(--color-neutral-100, #f4f4f5)"
|
|
935
|
+
},
|
|
936
|
+
".chord-search-field": {
|
|
937
|
+
borderColor: "var(--color-neutral-700, #3f3f46)",
|
|
938
|
+
backgroundColor: "var(--color-neutral-800, #27272a)"
|
|
939
|
+
},
|
|
940
|
+
".chord-search-input-with-options input": {
|
|
941
|
+
backgroundColor: "transparent"
|
|
942
|
+
},
|
|
943
|
+
".chord-search-button": {
|
|
944
|
+
borderColor: "var(--color-neutral-700, #3f3f46)",
|
|
945
|
+
backgroundColor: "var(--color-neutral-800, #27272a)",
|
|
946
|
+
color: "var(--color-neutral-100, #f4f4f5)"
|
|
947
|
+
},
|
|
948
|
+
".chord-search-button:hover": {
|
|
949
|
+
backgroundColor: "var(--color-neutral-700, #3f3f46)"
|
|
950
|
+
},
|
|
951
|
+
".chord-search-toggle-replace:hover, .chord-search-previous:hover, .chord-search-next:hover, .chord-search-close:hover": {
|
|
952
|
+
backgroundColor: "var(--color-neutral-800, #27272a)"
|
|
953
|
+
},
|
|
954
|
+
".chord-search-options": {
|
|
955
|
+
color: "var(--color-neutral-300, #d4d4d8)"
|
|
956
|
+
},
|
|
957
|
+
".chord-search-toggle.is-active": {
|
|
958
|
+
borderColor: "var(--color-primary-400, #60a5fa)",
|
|
959
|
+
backgroundColor: "var(--color-primary-950, #172554)",
|
|
960
|
+
color: "var(--color-primary-200, #bfdbfe)"
|
|
961
|
+
},
|
|
639
962
|
".cm-completionIcon-chord-used + .cm-completionLabel": {
|
|
640
963
|
color: "var(--color-primary-300, #93c5fd)",
|
|
641
964
|
fontWeight: "600"
|
|
642
965
|
},
|
|
643
|
-
|
|
966
|
+
".cm-tooltip-autocomplete ul li[aria-selected] .cm-completionIcon-chord-used + .cm-completionLabel": {
|
|
967
|
+
color: "var(--color-white, #ffffff)"
|
|
968
|
+
},
|
|
969
|
+
".cm-tooltip-autocomplete ul li[aria-selected]": {
|
|
970
|
+
backgroundColor: "var(--color-primary-700, #1d4ed8)",
|
|
971
|
+
color: "var(--color-white, #ffffff)"
|
|
972
|
+
},
|
|
973
|
+
".cm-tooltip-autocomplete ul li[aria-selected] .cm-completionLabel, .cm-tooltip-autocomplete ul li[aria-selected] .cm-completionDetail, .cm-tooltip-autocomplete ul li[aria-selected] .cm-completionMatchedText": {
|
|
644
974
|
color: "var(--color-white, #ffffff)"
|
|
645
975
|
},
|
|
646
976
|
".cm-lintRange-info": {
|
|
@@ -686,23 +1016,25 @@ var editorTheme2 = EditorView4.theme(
|
|
|
686
1016
|
color: "var(--color-neutral-950, #09090b)"
|
|
687
1017
|
},
|
|
688
1018
|
".cm-content": {
|
|
1019
|
+
textDecoration: "none",
|
|
689
1020
|
caretColor: "var(--color-neutral-950, #09090b)"
|
|
690
1021
|
},
|
|
691
1022
|
".cm-cursor, .cm-dropCursor": {
|
|
692
1023
|
borderLeftColor: "var(--color-neutral-950, #09090b)"
|
|
693
1024
|
},
|
|
694
1025
|
"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": {
|
|
695
|
-
backgroundColor: "
|
|
1026
|
+
backgroundColor: "var(--color-primary-200, #bfdbfe) !important",
|
|
1027
|
+
color: "inherit !important"
|
|
696
1028
|
},
|
|
697
1029
|
"&.cm-focused .cm-content:focus::selection, &.cm-focused .cm-content .cm-line::selection": {
|
|
698
|
-
backgroundColor: "
|
|
1030
|
+
backgroundColor: "var(--color-primary-200, #bfdbfe) !important",
|
|
699
1031
|
color: "inherit !important"
|
|
700
1032
|
},
|
|
701
1033
|
".cm-selectionLayer .cm-selectionBackground": {
|
|
702
|
-
boxShadow: "
|
|
1034
|
+
boxShadow: "none"
|
|
703
1035
|
},
|
|
704
1036
|
".cm-activeLine": {
|
|
705
|
-
backgroundColor: "
|
|
1037
|
+
backgroundColor: "transparent"
|
|
706
1038
|
},
|
|
707
1039
|
".cm-gutters": {
|
|
708
1040
|
backgroundColor: "var(--color-neutral-50, #fafafa)",
|
|
@@ -716,7 +1048,14 @@ var editorTheme2 = EditorView4.theme(
|
|
|
716
1048
|
color: "var(--color-primary-700, #1d4ed8)",
|
|
717
1049
|
fontWeight: "600"
|
|
718
1050
|
},
|
|
719
|
-
|
|
1051
|
+
".cm-tooltip-autocomplete ul li[aria-selected] .cm-completionIcon-chord-used + .cm-completionLabel": {
|
|
1052
|
+
color: "var(--color-white, #ffffff)"
|
|
1053
|
+
},
|
|
1054
|
+
".cm-tooltip-autocomplete ul li[aria-selected]": {
|
|
1055
|
+
backgroundColor: "var(--color-primary-600, #2563eb)",
|
|
1056
|
+
color: "var(--color-white, #ffffff)"
|
|
1057
|
+
},
|
|
1058
|
+
".cm-tooltip-autocomplete ul li[aria-selected] .cm-completionLabel, .cm-tooltip-autocomplete ul li[aria-selected] .cm-completionDetail, .cm-tooltip-autocomplete ul li[aria-selected] .cm-completionMatchedText": {
|
|
720
1059
|
color: "var(--color-white, #ffffff)"
|
|
721
1060
|
},
|
|
722
1061
|
".cm-lintRange-info": {
|
|
@@ -736,6 +1075,10 @@ var editorTheme2 = EditorView4.theme(
|
|
|
736
1075
|
backgroundSize: "6px 3px",
|
|
737
1076
|
backgroundPosition: "left bottom",
|
|
738
1077
|
backgroundRepeat: "no-repeat"
|
|
1078
|
+
},
|
|
1079
|
+
".chord-search-panel": {
|
|
1080
|
+
borderColor: "var(--color-neutral-300, #d4d4d8)",
|
|
1081
|
+
backgroundColor: "var(--color-white, #ffffff)"
|
|
739
1082
|
}
|
|
740
1083
|
},
|
|
741
1084
|
{ dark: false }
|
|
@@ -756,6 +1099,198 @@ function themeExtension(name) {
|
|
|
756
1099
|
return [baseTheme, ...name === "dark" ? darkTheme : lightTheme];
|
|
757
1100
|
}
|
|
758
1101
|
|
|
1102
|
+
// src/search-panel.ts
|
|
1103
|
+
import {
|
|
1104
|
+
closeSearchPanel,
|
|
1105
|
+
findNext,
|
|
1106
|
+
findPrevious,
|
|
1107
|
+
getSearchQuery,
|
|
1108
|
+
replaceAll,
|
|
1109
|
+
replaceNext,
|
|
1110
|
+
SearchQuery,
|
|
1111
|
+
setSearchQuery
|
|
1112
|
+
} from "@codemirror/search";
|
|
1113
|
+
var defaultSearchLabels = {
|
|
1114
|
+
search: "Find",
|
|
1115
|
+
replace: "Replace",
|
|
1116
|
+
next: "Next match",
|
|
1117
|
+
previous: "Previous match",
|
|
1118
|
+
replaceOne: "Replace",
|
|
1119
|
+
replaceAll: "Replace all",
|
|
1120
|
+
close: "Close search",
|
|
1121
|
+
toggleReplace: "Show replace field",
|
|
1122
|
+
hideReplace: "Hide replace field",
|
|
1123
|
+
preserveCase: "Preserve case",
|
|
1124
|
+
caseSensitive: "Match case",
|
|
1125
|
+
wholeWord: "Whole word"
|
|
1126
|
+
};
|
|
1127
|
+
function createSearchPanel(view, labels = defaultSearchLabels) {
|
|
1128
|
+
const panel = document.createElement("form");
|
|
1129
|
+
panel.className = "chord-search-panel";
|
|
1130
|
+
panel.addEventListener("submit", (event) => event.preventDefault());
|
|
1131
|
+
const searchInput = createInput("chord-search-input", labels.search);
|
|
1132
|
+
const replaceInput = createInput("chord-replace-input", labels.replace);
|
|
1133
|
+
const nextButton = createButton("chord-search-next", labels.next, "\u203A");
|
|
1134
|
+
const previousButton = createButton("chord-search-previous", labels.previous, "\u2039");
|
|
1135
|
+
const replaceButton = createButton("chord-search-replace", labels.replaceOne, "\u21B5");
|
|
1136
|
+
const replaceAllButton = createButton("chord-search-replace-all", labels.replaceAll, "\u21B5\xD7");
|
|
1137
|
+
const replaceToggle = createButton("chord-search-toggle-replace", labels.toggleReplace, "\u2194");
|
|
1138
|
+
const closeButton = createButton("chord-search-close", labels.close, "\xD7");
|
|
1139
|
+
const matchCount = document.createElement("span");
|
|
1140
|
+
matchCount.className = "chord-search-match-count";
|
|
1141
|
+
matchCount.setAttribute("aria-live", "polite");
|
|
1142
|
+
const preserveCase = createToggle("chord-search-preserve-case", labels.preserveCase, "AB");
|
|
1143
|
+
const caseSensitive = createToggle("chord-search-case", labels.caseSensitive, "Aa");
|
|
1144
|
+
const wholeWord = createToggle("chord-search-whole-word", labels.wholeWord, "ab");
|
|
1145
|
+
searchInput.wrapper.classList.add("chord-search-input-with-options");
|
|
1146
|
+
searchInput.wrapper.append(caseSensitive.button, wholeWord.button);
|
|
1147
|
+
replaceInput.wrapper.classList.add("chord-search-input-with-options");
|
|
1148
|
+
replaceInput.wrapper.append(preserveCase.button);
|
|
1149
|
+
const controls = document.createElement("div");
|
|
1150
|
+
controls.className = "chord-search-controls";
|
|
1151
|
+
const replaceRow = document.createElement("div");
|
|
1152
|
+
replaceRow.className = "chord-search-replace-row";
|
|
1153
|
+
replaceRow.hidden = false;
|
|
1154
|
+
replaceRow.append(replaceInput.wrapper, replaceButton, replaceAllButton);
|
|
1155
|
+
const searchFields = document.createElement("div");
|
|
1156
|
+
searchFields.className = "chord-search-fields";
|
|
1157
|
+
searchFields.append(searchInput.wrapper, replaceRow);
|
|
1158
|
+
const navigation = document.createElement("div");
|
|
1159
|
+
navigation.className = "chord-search-navigation";
|
|
1160
|
+
navigation.append(previousButton, nextButton, closeButton);
|
|
1161
|
+
controls.append(replaceToggle, searchFields, matchCount, navigation);
|
|
1162
|
+
panel.append(controls);
|
|
1163
|
+
const updateQuery = () => {
|
|
1164
|
+
const current = getSearchQuery(view.state);
|
|
1165
|
+
view.dispatch({
|
|
1166
|
+
effects: setSearchQuery.of(new SearchQuery({
|
|
1167
|
+
search: searchInput.input.value,
|
|
1168
|
+
replace: replaceInput.input.value,
|
|
1169
|
+
caseSensitive: caseSensitive.input.checked,
|
|
1170
|
+
wholeWord: wholeWord.input.checked,
|
|
1171
|
+
literal: current.literal
|
|
1172
|
+
}))
|
|
1173
|
+
});
|
|
1174
|
+
};
|
|
1175
|
+
const runCommand = (command) => {
|
|
1176
|
+
updateQuery();
|
|
1177
|
+
command(view);
|
|
1178
|
+
searchInput.input.focus();
|
|
1179
|
+
};
|
|
1180
|
+
searchInput.input.addEventListener("input", updateQuery);
|
|
1181
|
+
replaceInput.input.addEventListener("input", updateQuery);
|
|
1182
|
+
caseSensitive.input.addEventListener("change", updateQuery);
|
|
1183
|
+
caseSensitive.button.addEventListener("click", () => {
|
|
1184
|
+
caseSensitive.input.checked = !caseSensitive.input.checked;
|
|
1185
|
+
updateQuery();
|
|
1186
|
+
});
|
|
1187
|
+
wholeWord.button.addEventListener("click", () => {
|
|
1188
|
+
wholeWord.input.checked = !wholeWord.input.checked;
|
|
1189
|
+
updateQuery();
|
|
1190
|
+
});
|
|
1191
|
+
preserveCase.button.addEventListener("click", () => {
|
|
1192
|
+
preserveCase.input.checked = !preserveCase.input.checked;
|
|
1193
|
+
preserveCase.button.classList.toggle("is-active", preserveCase.input.checked);
|
|
1194
|
+
});
|
|
1195
|
+
wholeWord.input.addEventListener("change", updateQuery);
|
|
1196
|
+
searchInput.input.addEventListener("keydown", (event) => handleKey(event, () => runCommand(findNext), () => runCommand(findPrevious)));
|
|
1197
|
+
replaceInput.input.addEventListener("keydown", (event) => handleKey(event, () => runCommand(findNext), () => runCommand(findPrevious)));
|
|
1198
|
+
nextButton.addEventListener("click", () => runCommand(findNext));
|
|
1199
|
+
previousButton.addEventListener("click", () => runCommand(findPrevious));
|
|
1200
|
+
replaceButton.addEventListener("click", () => runCommand(replaceNext));
|
|
1201
|
+
replaceAllButton.addEventListener("click", () => runCommand(replaceAll));
|
|
1202
|
+
closeButton.addEventListener("click", () => closeSearchPanel(view));
|
|
1203
|
+
replaceToggle.addEventListener("click", () => {
|
|
1204
|
+
replaceRow.hidden = !replaceRow.hidden;
|
|
1205
|
+
replaceToggle.classList.toggle("is-active", !replaceRow.hidden);
|
|
1206
|
+
replaceToggle.title = replaceRow.hidden ? labels.toggleReplace : labels.hideReplace;
|
|
1207
|
+
replaceToggle.setAttribute("aria-label", replaceToggle.title);
|
|
1208
|
+
replaceInput.input.focus();
|
|
1209
|
+
});
|
|
1210
|
+
replaceToggle.classList.add("is-active");
|
|
1211
|
+
replaceToggle.title = labels.hideReplace;
|
|
1212
|
+
replaceToggle.setAttribute("aria-label", labels.hideReplace);
|
|
1213
|
+
const update = () => {
|
|
1214
|
+
const query = getSearchQuery(view.state);
|
|
1215
|
+
if (document.activeElement !== searchInput.input) searchInput.input.value = query.search;
|
|
1216
|
+
if (document.activeElement !== replaceInput.input) replaceInput.input.value = query.replace;
|
|
1217
|
+
caseSensitive.input.checked = query.caseSensitive;
|
|
1218
|
+
wholeWord.input.checked = query.wholeWord;
|
|
1219
|
+
caseSensitive.button.classList.toggle("is-active", query.caseSensitive);
|
|
1220
|
+
wholeWord.button.classList.toggle("is-active", query.wholeWord);
|
|
1221
|
+
preserveCase.button.classList.toggle("is-active", preserveCase.input.checked);
|
|
1222
|
+
updateMatchCount(query, view, matchCount);
|
|
1223
|
+
};
|
|
1224
|
+
update();
|
|
1225
|
+
return {
|
|
1226
|
+
dom: panel,
|
|
1227
|
+
top: true,
|
|
1228
|
+
mount: () => {
|
|
1229
|
+
update();
|
|
1230
|
+
searchInput.input.focus();
|
|
1231
|
+
searchInput.input.select();
|
|
1232
|
+
},
|
|
1233
|
+
update: (_update) => update()
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
function updateMatchCount(query, view, target) {
|
|
1237
|
+
if (!query.valid || !query.search) {
|
|
1238
|
+
target.textContent = "";
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
const matches = [];
|
|
1242
|
+
const cursor = query.getCursor(view.state);
|
|
1243
|
+
for (let match = cursor.next(); !match.done; match = cursor.next()) {
|
|
1244
|
+
matches.push(match.value);
|
|
1245
|
+
}
|
|
1246
|
+
if (!matches.length) {
|
|
1247
|
+
target.textContent = "0";
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
const selection = view.state.selection.main;
|
|
1251
|
+
const current = matches.findIndex((match) => match.from === selection.from && match.to === selection.to);
|
|
1252
|
+
target.textContent = `${current >= 0 ? current + 1 : 1} / ${matches.length}`;
|
|
1253
|
+
}
|
|
1254
|
+
function createInput(className, placeholder) {
|
|
1255
|
+
const wrapper = document.createElement("label");
|
|
1256
|
+
wrapper.className = `chord-search-field ${className}`;
|
|
1257
|
+
const input = document.createElement("input");
|
|
1258
|
+
input.type = "text";
|
|
1259
|
+
input.placeholder = placeholder;
|
|
1260
|
+
input.setAttribute("aria-label", placeholder);
|
|
1261
|
+
wrapper.append(input);
|
|
1262
|
+
return { wrapper, input };
|
|
1263
|
+
}
|
|
1264
|
+
function createButton(className, label, text = label) {
|
|
1265
|
+
const button = document.createElement("button");
|
|
1266
|
+
button.type = "button";
|
|
1267
|
+
button.className = `chord-search-button ${className}`;
|
|
1268
|
+
button.textContent = text;
|
|
1269
|
+
button.title = label;
|
|
1270
|
+
button.setAttribute("aria-label", label);
|
|
1271
|
+
return button;
|
|
1272
|
+
}
|
|
1273
|
+
function createToggle(className, label, text) {
|
|
1274
|
+
const button = document.createElement("button");
|
|
1275
|
+
button.type = "button";
|
|
1276
|
+
button.className = `chord-search-option chord-search-toggle ${className}`;
|
|
1277
|
+
button.title = label;
|
|
1278
|
+
button.setAttribute("aria-label", label);
|
|
1279
|
+
const input = document.createElement("input");
|
|
1280
|
+
input.type = "checkbox";
|
|
1281
|
+
input.tabIndex = -1;
|
|
1282
|
+
input.setAttribute("aria-hidden", "true");
|
|
1283
|
+
const textElement = document.createElement("span");
|
|
1284
|
+
textElement.textContent = text;
|
|
1285
|
+
button.append(input, textElement);
|
|
1286
|
+
return { button, input };
|
|
1287
|
+
}
|
|
1288
|
+
function handleKey(event, next, previous) {
|
|
1289
|
+
if (event.key !== "Enter") return;
|
|
1290
|
+
event.preventDefault();
|
|
1291
|
+
event.shiftKey ? previous() : next();
|
|
1292
|
+
}
|
|
1293
|
+
|
|
759
1294
|
// src/index.ts
|
|
760
1295
|
function createChordProEditor(options) {
|
|
761
1296
|
const themeCompartment = new Compartment();
|
|
@@ -775,9 +1310,11 @@ function createChordProEditor(options) {
|
|
|
775
1310
|
chordProFolding,
|
|
776
1311
|
duplicateDirectiveLinter,
|
|
777
1312
|
parserWarningLinter,
|
|
1313
|
+
unclosedSectionLinter,
|
|
778
1314
|
chordNotationLinter,
|
|
779
1315
|
chordProAutocomplete(),
|
|
780
1316
|
themeCompartment.of(themeExtension(options.theme ?? "light")),
|
|
1317
|
+
search({ top: true, createPanel: (view2) => createSearchPanel(view2, options.searchLabels?.()) }),
|
|
781
1318
|
updateListener,
|
|
782
1319
|
...options.extensions ?? []
|
|
783
1320
|
]
|
|
@@ -800,6 +1337,9 @@ function createChordProEditor(options) {
|
|
|
800
1337
|
openCompletionList: () => {
|
|
801
1338
|
openCompletionList(view);
|
|
802
1339
|
},
|
|
1340
|
+
openSearch: () => {
|
|
1341
|
+
openSearchPanel(view);
|
|
1342
|
+
},
|
|
803
1343
|
getChordNotationSuggestions: () => getChordNotationSuggestions(view.state.doc.toString()),
|
|
804
1344
|
normalizeChordNotation: () => {
|
|
805
1345
|
const content = view.state.doc.toString();
|