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