@chordproject/editor 1.0.0 → 1.1.1

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 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");
@@ -111,6 +112,35 @@ function chordCompletionSource(context) {
111
112
 
112
113
  // src/autocomplete/snippets.ts
113
114
  var import_autocomplete = require("@codemirror/autocomplete");
115
+ function sectionShortcut(startDirective, endDirective, label, detail) {
116
+ return {
117
+ label,
118
+ type: "directive",
119
+ detail,
120
+ apply: (view, completion, from, to) => {
121
+ const line = view.state.doc.lineAt(from);
122
+ let closingAt = view.state.doc.length;
123
+ for (let lineNumber = line.number + 1; lineNumber <= view.state.doc.lines; lineNumber++) {
124
+ const nextLine = view.state.doc.line(lineNumber);
125
+ if (!nextLine.text.trim() || /^\s*\{\s*[A-Za-z_][\w]*\b/.test(nextLine.text)) {
126
+ closingAt = nextLine.from;
127
+ break;
128
+ }
129
+ }
130
+ const opening = `{${startDirective}}`;
131
+ const previousCharacter = closingAt > 0 ? view.state.doc.sliceString(closingAt - 1, closingAt) : "";
132
+ const closing = `${previousCharacter && previousCharacter !== "\n" ? "\n" : ""}{${endDirective}}
133
+ `;
134
+ view.dispatch({
135
+ changes: [
136
+ { from, to, insert: opening },
137
+ { from: closingAt, insert: closing }
138
+ ],
139
+ selection: { anchor: from + opening.length }
140
+ });
141
+ }
142
+ };
143
+ }
114
144
  var CHORDPRO_SNIPPETS = [
115
145
  (0, import_autocomplete.snippetCompletion)("{album: ${value}}", { label: "album", type: "directive" }),
116
146
  (0, import_autocomplete.snippetCompletion)("{arranger: ${value}}", { label: "arranger", type: "directive" }),
@@ -137,25 +167,25 @@ var CHORDPRO_SNIPPETS = [
137
167
  label: "chorus",
138
168
  type: "directive"
139
169
  }),
140
- (0, import_autocomplete.snippetCompletion)("{start_of_chorus}", { label: "soc", type: "directive", detail: "start_of_chorus" }),
170
+ sectionShortcut("start_of_chorus", "end_of_chorus", "soc", "start_of_chorus"),
141
171
  (0, import_autocomplete.snippetCompletion)("{end_of_chorus}", { label: "eoc", type: "directive", detail: "end_of_chorus" }),
142
172
  (0, import_autocomplete.snippetCompletion)("{start_of_verse: ${Verse} ${1}}\n${lyrics}\n{end_of_verse}", {
143
173
  label: "verse",
144
174
  type: "directive"
145
175
  }),
146
- (0, import_autocomplete.snippetCompletion)("{start_of_verse}", { label: "sov", type: "directive", detail: "start_of_verse" }),
176
+ sectionShortcut("start_of_verse", "end_of_verse", "sov", "start_of_verse"),
147
177
  (0, import_autocomplete.snippetCompletion)("{end_of_verse}", { label: "eov", type: "directive", detail: "end_of_verse" }),
148
178
  (0, import_autocomplete.snippetCompletion)("{start_of_bridge: ${Bridge}}\n${lyrics}\n{end_of_bridge}", {
149
179
  label: "bridge",
150
180
  type: "directive"
151
181
  }),
152
- (0, import_autocomplete.snippetCompletion)("{start_of_bridge}", { label: "sob", type: "directive", detail: "start_of_bridge" }),
182
+ sectionShortcut("start_of_bridge", "end_of_bridge", "sob", "start_of_bridge"),
153
183
  (0, import_autocomplete.snippetCompletion)("{end_of_bridge}", { label: "eob", type: "directive", detail: "end_of_bridge" }),
154
184
  (0, import_autocomplete.snippetCompletion)(
155
185
  "{start_of_tab}\ne|-${1}--------------------------------|\nB|----------------------------------|\nG|----------------------------------|\nD|----------------------------------|\nA|----------------------------------|\nE|----------------------------------|\n{end_of_tab}",
156
186
  { label: "tab", type: "directive" }
157
187
  ),
158
- (0, import_autocomplete.snippetCompletion)("{start_of_tab}", { label: "sot", type: "directive", detail: "start_of_tab" }),
188
+ sectionShortcut("start_of_tab", "end_of_tab", "sot", "start_of_tab"),
159
189
  (0, import_autocomplete.snippetCompletion)("{end_of_tab}", { label: "eot", type: "directive", detail: "end_of_tab" }),
160
190
  (0, import_autocomplete.snippetCompletion)("{define: ${Am} base-fret ${1} frets ${0 0 0 0 0 0} fingers ${0 0 0 0 0 0}}", {
161
191
  label: "define",
@@ -175,10 +205,15 @@ var CHORDPRO_SNIPPETS = [
175
205
 
176
206
  // src/autocomplete/index.ts
177
207
  var completeSnippets = (0, import_autocomplete2.completeFromList)(CHORDPRO_SNIPPETS);
208
+ var QUICK_SNIPPET_PREFIXES = new Set(
209
+ CHORDPRO_SNIPPETS.map((snippet) => snippet.label).filter((label) => label.length <= 3 && /^[a-z]+$/i.test(label))
210
+ );
178
211
  function chordProCompletionSource(context) {
179
212
  const chordCompletions = chordCompletionSource(context);
180
213
  if (chordCompletions) return chordCompletions;
181
- return context.explicit ? completeSnippets(context) : null;
214
+ const word = context.matchBefore(/[a-z]+$/i);
215
+ const isQuickSnippet = word && QUICK_SNIPPET_PREFIXES.has(word.text.toLowerCase());
216
+ return context.explicit || isQuickSnippet ? completeSnippets(context) : null;
182
217
  }
183
218
  function chordProAutocomplete() {
184
219
  return (0, import_autocomplete2.autocompletion)({ override: [chordProCompletionSource], activateOnTyping: true });
@@ -205,6 +240,7 @@ var import_view = require("@codemirror/view");
205
240
  var import_commands = require("@codemirror/commands");
206
241
  var import_language = require("@codemirror/language");
207
242
  var import_lint = require("@codemirror/lint");
243
+ var import_search = require("@codemirror/search");
208
244
  var import_autocomplete3 = require("@codemirror/autocomplete");
209
245
  function isInsideChordBrackets(view) {
210
246
  const pos = view.state.selection.main.head;
@@ -245,6 +281,7 @@ function basicSetup() {
245
281
  ...import_commands.historyKeymap,
246
282
  ...import_language.foldKeymap,
247
283
  ...import_lint.lintKeymap,
284
+ ...import_search.searchKeymap,
248
285
  // Override completionKeymap's Ctrl-Space/Option-`/Option-i (same keys, listed first so
249
286
  // they take precedence) to be chord-aware instead of plain startCompletion.
250
287
  { key: "Ctrl-Space", run: chordAwareCompletion },
@@ -516,6 +553,14 @@ function normalizeChordNotationText(content) {
516
553
  }
517
554
 
518
555
  // src/linting.ts
556
+ var defaultLintLabels = {
557
+ duplicateDirective: (directive, firstLine) => `"${directive}" was already defined on line ${firstLine}; this value replaces it.`,
558
+ parserWarning: (warning) => warning.message,
559
+ sectionMessage: (endDirective) => `This section must be closed with {${endDirective}}.`,
560
+ sectionAction: (endDirective) => `Insert {${endDirective}}`,
561
+ chordNotationMessage: (replacement, reason) => `Use "${replacement}". ${reason}`,
562
+ chordNotationAction: (replacement) => `Replace with ${replacement}`
563
+ };
519
564
  var SINGULAR_DIRECTIVES = {
520
565
  title: "title",
521
566
  t: "title",
@@ -530,63 +575,179 @@ var SINGULAR_DIRECTIVES = {
530
575
  time: "time"
531
576
  };
532
577
  var DIRECTIVE_LINE = /^\s*\{\s*([A-Za-z_][\w]*)\b/;
533
- var duplicateDirectiveLinter = (0, import_lint2.linter)((view) => {
534
- const diagnostics = [];
535
- const firstSeenAtLine = /* @__PURE__ */ new Map();
536
- for (let lineNumber = 1; lineNumber <= view.state.doc.lines; lineNumber++) {
537
- const line = view.state.doc.line(lineNumber);
538
- const match = line.text.match(DIRECTIVE_LINE);
539
- if (!match) continue;
540
- const canonical = SINGULAR_DIRECTIVES[match[1].toLowerCase()];
541
- if (!canonical) continue;
542
- const firstLine = firstSeenAtLine.get(canonical);
543
- if (firstLine === void 0) {
544
- firstSeenAtLine.set(canonical, lineNumber);
545
- continue;
578
+ var SECTION_STARTS = {
579
+ start_of_chorus: "end_of_chorus",
580
+ soc: "end_of_chorus",
581
+ chorus: "end_of_chorus",
582
+ start_of_verse: "end_of_verse",
583
+ sov: "end_of_verse",
584
+ start_of_bridge: "end_of_bridge",
585
+ sob: "end_of_bridge",
586
+ start_of_tab: "end_of_tab",
587
+ sot: "end_of_tab"
588
+ };
589
+ var SECTION_ENDS = /* @__PURE__ */ new Set(["end_of_chorus", "eoc", "end_of_verse", "eov", "end_of_bridge", "eob", "end_of_tab", "eot"]);
590
+ function createLintExtensions(getLabels = () => defaultLintLabels) {
591
+ const duplicateDirectiveLinter = (0, import_lint2.linter)((view) => {
592
+ const diagnostics = [];
593
+ const firstSeenAtLine = /* @__PURE__ */ new Map();
594
+ const labels = getLabels();
595
+ for (let lineNumber = 1; lineNumber <= view.state.doc.lines; lineNumber++) {
596
+ const line = view.state.doc.line(lineNumber);
597
+ const match = line.text.match(DIRECTIVE_LINE);
598
+ if (!match) continue;
599
+ const canonical = SINGULAR_DIRECTIVES[match[1].toLowerCase()];
600
+ if (!canonical) continue;
601
+ const firstLine = firstSeenAtLine.get(canonical);
602
+ if (firstLine === void 0) {
603
+ firstSeenAtLine.set(canonical, lineNumber);
604
+ continue;
605
+ }
606
+ diagnostics.push({
607
+ from: line.from,
608
+ to: line.from + match[0].length,
609
+ severity: "warning",
610
+ message: labels.duplicateDirective(canonical, firstLine)
611
+ });
546
612
  }
547
- diagnostics.push({
548
- from: line.from,
549
- to: line.from + match[0].length,
550
- severity: "warning",
551
- message: `"${canonical}" ya se defini\xF3 en la l\xEDnea ${firstLine}; este valor la reemplaza.`
613
+ return diagnostics;
614
+ });
615
+ const parserWarningLinter = (0, import_lint2.linter)((view) => {
616
+ const parser = new import_parser.ChordProParser();
617
+ parser.parse(view.state.doc.toString());
618
+ const labels = getLabels();
619
+ return parser.warnings.flatMap((warning) => {
620
+ if (warning.code === "empty_sheet") {
621
+ return [];
622
+ }
623
+ if (warning.lineNumber < 1 || warning.lineNumber > view.state.doc.lines) {
624
+ return [];
625
+ }
626
+ const line = view.state.doc.line(warning.lineNumber);
627
+ return [{
628
+ from: line.from,
629
+ to: line.to,
630
+ severity: "warning",
631
+ message: labels.parserWarning(warning)
632
+ }];
552
633
  });
553
- }
554
- return diagnostics;
555
- });
556
- var parserWarningLinter = (0, import_lint2.linter)((view) => {
557
- const parser = new import_parser.ChordProParser();
558
- parser.parse(view.state.doc.toString());
559
- return parser.warnings.flatMap((warning) => {
560
- if (warning.lineNumber < 1 || warning.lineNumber > view.state.doc.lines) {
561
- return [];
634
+ }, { delay: 0 });
635
+ const unclosedSectionLinter = (0, import_lint2.linter)((view) => {
636
+ const diagnostics = [];
637
+ let openSection = null;
638
+ let sectionHasContent = false;
639
+ for (let lineNumber = 1; lineNumber <= view.state.doc.lines; lineNumber++) {
640
+ const line = view.state.doc.line(lineNumber);
641
+ const match = line.text.match(DIRECTIVE_LINE);
642
+ const directive = match?.[1].toLowerCase();
643
+ if (directive && SECTION_STARTS[directive]) {
644
+ if (openSection) {
645
+ openSection.insertionAt = line.from;
646
+ openSection.insertionTo = line.from;
647
+ diagnostics.push(sectionDiagnostic(openSection, getLabels()));
648
+ }
649
+ openSection = {
650
+ endDirective: SECTION_STARTS[directive],
651
+ lineFrom: line.from,
652
+ lineTo: line.to,
653
+ insertionAt: line.from,
654
+ insertionTo: line.from
655
+ };
656
+ sectionHasContent = false;
657
+ continue;
658
+ }
659
+ if (directive && SECTION_ENDS.has(directive)) {
660
+ openSection = null;
661
+ sectionHasContent = false;
662
+ continue;
663
+ }
664
+ if (openSection && directive) {
665
+ openSection.insertionAt = line.from;
666
+ openSection.insertionTo = line.from;
667
+ diagnostics.push(sectionDiagnostic(openSection, getLabels()));
668
+ openSection = null;
669
+ sectionHasContent = false;
670
+ continue;
671
+ }
672
+ if (openSection && !line.text.trim()) {
673
+ const nextDirective = nextNonBlankDirective(view, lineNumber);
674
+ if (sectionHasContent) {
675
+ openSection.insertionAt = line.from;
676
+ openSection.insertionTo = nextDirective ? nextNonBlankDirectiveLine(view, lineNumber) : line.from;
677
+ diagnostics.push(sectionDiagnostic(openSection, getLabels()));
678
+ openSection = null;
679
+ sectionHasContent = false;
680
+ }
681
+ continue;
682
+ }
683
+ if (openSection && lineNumber === view.state.doc.lines) {
684
+ openSection.insertionAt = view.state.doc.length;
685
+ openSection.insertionTo = view.state.doc.length;
686
+ }
687
+ if (openSection) {
688
+ sectionHasContent = true;
689
+ }
690
+ }
691
+ function nextNonBlankDirective(view2, lineNumber) {
692
+ const directiveLine = nextNonBlankDirectiveLine(view2, lineNumber);
693
+ return directiveLine < view2.state.doc.length ? view2.state.doc.lineAt(directiveLine).text.match(DIRECTIVE_LINE)?.[1].toLowerCase() ?? null : null;
562
694
  }
563
- const line = view.state.doc.line(warning.lineNumber);
564
- return [{
565
- from: line.from,
566
- to: line.to,
695
+ function nextNonBlankDirectiveLine(view2, lineNumber) {
696
+ for (let nextLineNumber = lineNumber + 1; nextLineNumber <= view2.state.doc.lines; nextLineNumber++) {
697
+ const nextLine = view2.state.doc.line(nextLineNumber);
698
+ if (!nextLine.text.trim()) {
699
+ continue;
700
+ }
701
+ if (nextLine.text.match(DIRECTIVE_LINE)) {
702
+ return nextLine.from;
703
+ }
704
+ return view2.state.doc.length;
705
+ }
706
+ return view2.state.doc.length;
707
+ }
708
+ if (openSection) {
709
+ diagnostics.push(sectionDiagnostic(openSection, getLabels()));
710
+ }
711
+ return diagnostics;
712
+ }, { delay: 0 });
713
+ function sectionDiagnostic(section, labels) {
714
+ return {
715
+ from: section.lineFrom,
716
+ to: section.lineTo,
567
717
  severity: "warning",
568
- message: warning.message
569
- }];
570
- });
571
- });
572
- var chordNotationLinter = (0, import_lint2.linter)((view) => {
573
- const diagnostics = [];
574
- for (const replacement of findChordNotationReplacements(view.state.doc.toString())) {
575
- diagnostics.push({
576
- from: replacement.from,
577
- to: replacement.to,
578
- severity: "info",
579
- message: `Usa "${replacement.replacement}". ${replacement.reason}`,
718
+ message: labels.sectionMessage(section.endDirective),
580
719
  actions: [{
581
- name: `Reemplazar por ${replacement.replacement}`,
582
- apply: (targetView, actionFrom, actionTo) => {
583
- targetView.dispatch({ changes: { from: actionFrom, to: actionTo, insert: `[${replacement.replacement}]` } });
720
+ name: labels.sectionAction(section.endDirective),
721
+ apply: (view, from, to) => {
722
+ const previousCharacter = section.insertionAt > 0 ? view.state.doc.sliceString(section.insertionAt - 1, section.insertionAt) : "";
723
+ const needsLeadingNewline = previousCharacter !== "\n";
724
+ const insertion = `${needsLeadingNewline ? "\n" : ""}{${section.endDirective}}${section.insertionTo < view.state.doc.length ? "\n" : ""}`;
725
+ view.dispatch({ changes: { from: section.insertionAt, to: section.insertionTo, insert: insertion } });
584
726
  }
585
727
  }]
586
- });
728
+ };
587
729
  }
588
- return diagnostics;
589
- });
730
+ const chordNotationLinter = (0, import_lint2.linter)((view) => {
731
+ const diagnostics = [];
732
+ const labels = getLabels();
733
+ for (const replacement of findChordNotationReplacements(view.state.doc.toString())) {
734
+ diagnostics.push({
735
+ from: replacement.from,
736
+ to: replacement.to,
737
+ severity: "info",
738
+ message: labels.chordNotationMessage(replacement.replacement, replacement.reason),
739
+ actions: [{
740
+ name: labels.chordNotationAction(replacement.replacement),
741
+ apply: (targetView, actionFrom, actionTo) => {
742
+ targetView.dispatch({ changes: { from: actionFrom, to: actionTo, insert: `[${replacement.replacement}]` } });
743
+ }
744
+ }]
745
+ });
746
+ }
747
+ return diagnostics;
748
+ });
749
+ return [duplicateDirectiveLinter, parserWarningLinter, unclosedSectionLinter, chordNotationLinter];
750
+ }
590
751
 
591
752
  // src/themes/base.ts
592
753
  var import_view2 = require("@codemirror/view");
@@ -598,14 +759,182 @@ var baseTheme = import_view2.EditorView.baseTheme({
598
759
  flex: "1",
599
760
  overflow: "auto"
600
761
  },
762
+ ".cm-selectionLayer": {
763
+ zIndex: "-1 !important"
764
+ },
765
+ ".chord-search-panel": {
766
+ position: "absolute",
767
+ top: "0.4rem",
768
+ right: "0.5rem",
769
+ zIndex: "20",
770
+ pointerEvents: "auto",
771
+ display: "flex",
772
+ width: "min(100% - 1rem, 32rem)",
773
+ margin: "0",
774
+ border: "1px solid var(--color-neutral-700, #3f3f46)",
775
+ borderRadius: "0.45rem",
776
+ boxShadow: "0 0.5rem 1.25rem color-mix(in oklch, #000 28%, transparent)",
777
+ flexWrap: "wrap",
778
+ alignItems: "center",
779
+ gap: "0.3rem",
780
+ padding: "0.35rem 0.45rem",
781
+ borderBottom: "1px solid var(--color-neutral-200, #e4e4e7)",
782
+ backgroundColor: "var(--color-white, #ffffff)",
783
+ fontSize: "0.875rem"
784
+ },
785
+ ".chord-search-controls": {
786
+ display: "flex",
787
+ flex: "1 1 100%",
788
+ flexWrap: "nowrap",
789
+ alignItems: "center",
790
+ gap: "0.25rem"
791
+ },
792
+ ".chord-search-navigation": {
793
+ display: "flex",
794
+ flex: "0 0 auto",
795
+ alignItems: "center",
796
+ gap: "0.2rem"
797
+ },
798
+ ".chord-search-fields": {
799
+ display: "flex",
800
+ flex: "1 1 auto",
801
+ minWidth: "0",
802
+ flexDirection: "column",
803
+ gap: "0.25rem"
804
+ },
805
+ ".chord-search-replace-row": {
806
+ display: "flex",
807
+ flex: "1 1 100%",
808
+ flexWrap: "nowrap",
809
+ alignItems: "center",
810
+ gap: "0.25rem"
811
+ },
812
+ ".chord-search-replace-row[hidden]": {
813
+ display: "none"
814
+ },
815
+ ".chord-search-field": {
816
+ flex: "1 1 12rem",
817
+ border: "1px solid var(--color-neutral-300, #d4d4d8)",
818
+ borderRadius: "0.35rem",
819
+ backgroundColor: "var(--color-white, #ffffff)"
820
+ },
821
+ ".chord-search-match-count": {
822
+ flex: "0 0 auto",
823
+ minWidth: "3.5rem",
824
+ color: "var(--color-neutral-500, #71717a)",
825
+ fontSize: "0.75rem",
826
+ textAlign: "center",
827
+ whiteSpace: "nowrap"
828
+ },
829
+ ".chord-search-field input": {
830
+ boxSizing: "border-box",
831
+ width: "100%",
832
+ minHeight: "1.9rem",
833
+ padding: "0.3rem 0.5rem",
834
+ border: "none",
835
+ outline: "none",
836
+ backgroundColor: "transparent",
837
+ color: "inherit",
838
+ font: "inherit"
839
+ },
840
+ ".chord-search-input-with-options": {
841
+ display: "flex",
842
+ alignItems: "center",
843
+ gap: "0.1rem",
844
+ paddingRight: "0.15rem"
845
+ },
846
+ ".chord-search-input-with-options input": {
847
+ minWidth: "0",
848
+ border: "none",
849
+ outline: "none",
850
+ backgroundColor: "transparent",
851
+ paddingRight: "0.2rem"
852
+ },
853
+ ".chord-search-input-with-options .chord-search-option": {
854
+ minWidth: "1.6rem",
855
+ minHeight: "1.6rem",
856
+ zIndex: "2",
857
+ padding: "0.1rem",
858
+ border: "none",
859
+ backgroundColor: "transparent",
860
+ fontSize: "0.7rem"
861
+ },
862
+ ".chord-search-button": {
863
+ minHeight: "1.9rem",
864
+ minWidth: "1.9rem",
865
+ padding: "0.2rem 0.45rem",
866
+ border: "1px solid var(--color-neutral-300, #d4d4d8)",
867
+ borderRadius: "0.35rem",
868
+ backgroundColor: "var(--color-neutral-50, #fafafa)",
869
+ color: "inherit",
870
+ font: "inherit",
871
+ cursor: "pointer"
872
+ },
873
+ ".chord-search-button:hover": {
874
+ backgroundColor: "var(--color-neutral-100, #f4f4f5)"
875
+ },
876
+ ".chord-search-toggle-replace, .chord-search-previous, .chord-search-next, .chord-search-close": {
877
+ border: "none",
878
+ backgroundColor: "transparent"
879
+ },
880
+ ".chord-search-toggle-replace:hover, .chord-search-previous:hover, .chord-search-next:hover, .chord-search-close:hover": {
881
+ backgroundColor: "var(--color-neutral-100, #f4f4f5)"
882
+ },
883
+ ".chord-search-close": {
884
+ position: "static",
885
+ fontSize: "1.15rem",
886
+ lineHeight: "1"
887
+ },
888
+ ".chord-search-options": {
889
+ display: "flex",
890
+ flexWrap: "wrap",
891
+ gap: "0.8rem",
892
+ color: "var(--color-neutral-600, #52525b)"
893
+ },
894
+ ".chord-search-controls .chord-search-field": {
895
+ minWidth: "0",
896
+ flex: "1 1 auto"
897
+ },
898
+ ".chord-search-replace-row .chord-search-field": {
899
+ minWidth: "0",
900
+ flex: "1 1 auto"
901
+ },
902
+ ".chord-search-option": {
903
+ display: "inline-flex",
904
+ alignItems: "center",
905
+ gap: "0.35rem",
906
+ cursor: "pointer"
907
+ },
908
+ ".chord-search-toggle": {
909
+ minWidth: "2.25rem",
910
+ justifyContent: "center",
911
+ fontWeight: "600"
912
+ },
913
+ ".chord-search-toggle input": {
914
+ display: "none"
915
+ },
916
+ ".chord-search-toggle.is-active": {
917
+ borderColor: "var(--color-primary-500, #3b82f6)",
918
+ backgroundColor: "var(--color-primary-100, #dbeafe)",
919
+ color: "var(--color-primary-700, #1d4ed8)"
920
+ },
601
921
  ".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'
922
+ 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',
923
+ backgroundSize: "6px 3px",
924
+ backgroundPosition: "left bottom",
925
+ backgroundRepeat: "repeat-x"
603
926
  },
604
927
  ".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'
928
+ 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',
929
+ backgroundSize: "6px 3px",
930
+ backgroundPosition: "left bottom",
931
+ backgroundRepeat: "repeat-x"
606
932
  },
607
933
  ".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'
934
+ 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',
935
+ backgroundSize: "6px 3px",
936
+ backgroundPosition: "left bottom",
937
+ backgroundRepeat: "repeat-x"
609
938
  }
610
939
  });
611
940
 
@@ -620,23 +949,25 @@ var editorTheme = import_view3.EditorView.theme(
620
949
  color: "var(--color-neutral-100, #f4f4f5)"
621
950
  },
622
951
  ".cm-content": {
952
+ textDecoration: "none",
623
953
  caretColor: "var(--color-neutral-100, #f4f4f5)"
624
954
  },
625
955
  ".cm-cursor, .cm-dropCursor": {
626
956
  borderLeftColor: "var(--color-neutral-100, #f4f4f5)"
627
957
  },
628
958
  "&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": {
629
- backgroundColor: "color-mix(in oklch, var(--color-primary-400, #60a5fa) 88%, transparent) !important"
959
+ backgroundColor: "var(--color-primary-700, #1d4ed8) !important",
960
+ color: "inherit !important"
630
961
  },
631
962
  "&.cm-focused .cm-content:focus::selection, &.cm-focused .cm-content .cm-line::selection": {
632
- backgroundColor: "color-mix(in oklch, var(--color-primary-400, #60a5fa) 54%, transparent) !important",
963
+ backgroundColor: "var(--color-primary-700, #1d4ed8) !important",
633
964
  color: "inherit !important"
634
965
  },
635
966
  ".cm-selectionLayer .cm-selectionBackground": {
636
- boxShadow: "inset 0 -2px 0 var(--color-primary-200, #bfdbfe)"
967
+ boxShadow: "none"
637
968
  },
638
969
  ".cm-activeLine": {
639
- backgroundColor: "var(--color-neutral-800, #27272a)"
970
+ backgroundColor: "transparent"
640
971
  },
641
972
  ".cm-gutters": {
642
973
  backgroundColor: "var(--color-neutral-900, #18181b)",
@@ -646,11 +977,53 @@ var editorTheme = import_view3.EditorView.theme(
646
977
  ".cm-activeLineGutter": {
647
978
  backgroundColor: "var(--color-neutral-800, #27272a)"
648
979
  },
980
+ ".chord-search-panel": {
981
+ borderBottomColor: "var(--color-neutral-700, #3f3f46)",
982
+ backgroundColor: "var(--color-neutral-900, #18181b)",
983
+ borderColor: "var(--color-neutral-700, #3f3f46)"
984
+ },
985
+ ".chord-search-field input": {
986
+ backgroundColor: "var(--color-neutral-800, #27272a)",
987
+ color: "var(--color-neutral-100, #f4f4f5)"
988
+ },
989
+ ".chord-search-field": {
990
+ borderColor: "var(--color-neutral-700, #3f3f46)",
991
+ backgroundColor: "var(--color-neutral-800, #27272a)"
992
+ },
993
+ ".chord-search-input-with-options input": {
994
+ backgroundColor: "transparent"
995
+ },
996
+ ".chord-search-button": {
997
+ borderColor: "var(--color-neutral-700, #3f3f46)",
998
+ backgroundColor: "var(--color-neutral-800, #27272a)",
999
+ color: "var(--color-neutral-100, #f4f4f5)"
1000
+ },
1001
+ ".chord-search-button:hover": {
1002
+ backgroundColor: "var(--color-neutral-700, #3f3f46)"
1003
+ },
1004
+ ".chord-search-toggle-replace:hover, .chord-search-previous:hover, .chord-search-next:hover, .chord-search-close:hover": {
1005
+ backgroundColor: "var(--color-neutral-800, #27272a)"
1006
+ },
1007
+ ".chord-search-options": {
1008
+ color: "var(--color-neutral-300, #d4d4d8)"
1009
+ },
1010
+ ".chord-search-toggle.is-active": {
1011
+ borderColor: "var(--color-primary-400, #60a5fa)",
1012
+ backgroundColor: "var(--color-primary-950, #172554)",
1013
+ color: "var(--color-primary-200, #bfdbfe)"
1014
+ },
649
1015
  ".cm-completionIcon-chord-used + .cm-completionLabel": {
650
1016
  color: "var(--color-primary-300, #93c5fd)",
651
1017
  fontWeight: "600"
652
1018
  },
653
- '.cm-tooltip-autocomplete > ul > li[aria-selected="true"] .cm-completionIcon-chord-used + .cm-completionLabel': {
1019
+ ".cm-tooltip-autocomplete ul li[aria-selected] .cm-completionIcon-chord-used + .cm-completionLabel": {
1020
+ color: "var(--color-white, #ffffff)"
1021
+ },
1022
+ ".cm-tooltip-autocomplete ul li[aria-selected]": {
1023
+ backgroundColor: "var(--color-primary-700, #1d4ed8)",
1024
+ color: "var(--color-white, #ffffff)"
1025
+ },
1026
+ ".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
1027
  color: "var(--color-white, #ffffff)"
655
1028
  },
656
1029
  ".cm-lintRange-info": {
@@ -696,23 +1069,25 @@ var editorTheme2 = import_view4.EditorView.theme(
696
1069
  color: "var(--color-neutral-950, #09090b)"
697
1070
  },
698
1071
  ".cm-content": {
1072
+ textDecoration: "none",
699
1073
  caretColor: "var(--color-neutral-950, #09090b)"
700
1074
  },
701
1075
  ".cm-cursor, .cm-dropCursor": {
702
1076
  borderLeftColor: "var(--color-neutral-950, #09090b)"
703
1077
  },
704
1078
  "&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": {
705
- backgroundColor: "color-mix(in oklch, var(--color-primary-500, #3b82f6) 78%, transparent) !important"
1079
+ backgroundColor: "var(--color-primary-200, #bfdbfe) !important",
1080
+ color: "inherit !important"
706
1081
  },
707
1082
  "&.cm-focused .cm-content:focus::selection, &.cm-focused .cm-content .cm-line::selection": {
708
- backgroundColor: "color-mix(in oklch, var(--color-primary-500, #3b82f6) 52%, transparent) !important",
1083
+ backgroundColor: "var(--color-primary-200, #bfdbfe) !important",
709
1084
  color: "inherit !important"
710
1085
  },
711
1086
  ".cm-selectionLayer .cm-selectionBackground": {
712
- boxShadow: "inset 0 -2px 0 var(--color-primary-700, #1d4ed8)"
1087
+ boxShadow: "none"
713
1088
  },
714
1089
  ".cm-activeLine": {
715
- backgroundColor: "var(--color-neutral-100, #f4f4f5)"
1090
+ backgroundColor: "transparent"
716
1091
  },
717
1092
  ".cm-gutters": {
718
1093
  backgroundColor: "var(--color-neutral-50, #fafafa)",
@@ -726,7 +1101,14 @@ var editorTheme2 = import_view4.EditorView.theme(
726
1101
  color: "var(--color-primary-700, #1d4ed8)",
727
1102
  fontWeight: "600"
728
1103
  },
729
- '.cm-tooltip-autocomplete > ul > li[aria-selected="true"] .cm-completionIcon-chord-used + .cm-completionLabel': {
1104
+ ".cm-tooltip-autocomplete ul li[aria-selected] .cm-completionIcon-chord-used + .cm-completionLabel": {
1105
+ color: "var(--color-white, #ffffff)"
1106
+ },
1107
+ ".cm-tooltip-autocomplete ul li[aria-selected]": {
1108
+ backgroundColor: "var(--color-primary-600, #2563eb)",
1109
+ color: "var(--color-white, #ffffff)"
1110
+ },
1111
+ ".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
1112
  color: "var(--color-white, #ffffff)"
731
1113
  },
732
1114
  ".cm-lintRange-info": {
@@ -746,6 +1128,10 @@ var editorTheme2 = import_view4.EditorView.theme(
746
1128
  backgroundSize: "6px 3px",
747
1129
  backgroundPosition: "left bottom",
748
1130
  backgroundRepeat: "no-repeat"
1131
+ },
1132
+ ".chord-search-panel": {
1133
+ borderColor: "var(--color-neutral-300, #d4d4d8)",
1134
+ backgroundColor: "var(--color-white, #ffffff)"
749
1135
  }
750
1136
  },
751
1137
  { dark: false }
@@ -766,6 +1152,189 @@ function themeExtension(name) {
766
1152
  return [baseTheme, ...name === "dark" ? darkTheme : lightTheme];
767
1153
  }
768
1154
 
1155
+ // src/search-panel.ts
1156
+ var import_search2 = require("@codemirror/search");
1157
+ var defaultSearchLabels = {
1158
+ search: "Find",
1159
+ replace: "Replace",
1160
+ next: "Next match",
1161
+ previous: "Previous match",
1162
+ replaceOne: "Replace",
1163
+ replaceAll: "Replace all",
1164
+ close: "Close search",
1165
+ toggleReplace: "Show replace field",
1166
+ hideReplace: "Hide replace field",
1167
+ preserveCase: "Preserve case",
1168
+ caseSensitive: "Match case",
1169
+ wholeWord: "Whole word"
1170
+ };
1171
+ function createSearchPanel(view, labels = defaultSearchLabels) {
1172
+ const panel = document.createElement("form");
1173
+ panel.className = "chord-search-panel";
1174
+ panel.addEventListener("submit", (event) => event.preventDefault());
1175
+ const searchInput = createInput("chord-search-input", labels.search);
1176
+ const replaceInput = createInput("chord-replace-input", labels.replace);
1177
+ const nextButton = createButton("chord-search-next", labels.next, "\u203A");
1178
+ const previousButton = createButton("chord-search-previous", labels.previous, "\u2039");
1179
+ const replaceButton = createButton("chord-search-replace", labels.replaceOne, "\u21B5");
1180
+ const replaceAllButton = createButton("chord-search-replace-all", labels.replaceAll, "\u21B5\xD7");
1181
+ const replaceToggle = createButton("chord-search-toggle-replace", labels.toggleReplace, "\u2194");
1182
+ const closeButton = createButton("chord-search-close", labels.close, "\xD7");
1183
+ const matchCount = document.createElement("span");
1184
+ matchCount.className = "chord-search-match-count";
1185
+ matchCount.setAttribute("aria-live", "polite");
1186
+ const preserveCase = createToggle("chord-search-preserve-case", labels.preserveCase, "AB");
1187
+ const caseSensitive = createToggle("chord-search-case", labels.caseSensitive, "Aa");
1188
+ const wholeWord = createToggle("chord-search-whole-word", labels.wholeWord, "ab");
1189
+ searchInput.wrapper.classList.add("chord-search-input-with-options");
1190
+ searchInput.wrapper.append(caseSensitive.button, wholeWord.button);
1191
+ replaceInput.wrapper.classList.add("chord-search-input-with-options");
1192
+ replaceInput.wrapper.append(preserveCase.button);
1193
+ const controls = document.createElement("div");
1194
+ controls.className = "chord-search-controls";
1195
+ const replaceRow = document.createElement("div");
1196
+ replaceRow.className = "chord-search-replace-row";
1197
+ replaceRow.hidden = false;
1198
+ replaceRow.append(replaceInput.wrapper, replaceButton, replaceAllButton);
1199
+ const searchFields = document.createElement("div");
1200
+ searchFields.className = "chord-search-fields";
1201
+ searchFields.append(searchInput.wrapper, replaceRow);
1202
+ const navigation = document.createElement("div");
1203
+ navigation.className = "chord-search-navigation";
1204
+ navigation.append(previousButton, nextButton, closeButton);
1205
+ controls.append(replaceToggle, searchFields, matchCount, navigation);
1206
+ panel.append(controls);
1207
+ const updateQuery = () => {
1208
+ const current = (0, import_search2.getSearchQuery)(view.state);
1209
+ view.dispatch({
1210
+ effects: import_search2.setSearchQuery.of(new import_search2.SearchQuery({
1211
+ search: searchInput.input.value,
1212
+ replace: replaceInput.input.value,
1213
+ caseSensitive: caseSensitive.input.checked,
1214
+ wholeWord: wholeWord.input.checked,
1215
+ literal: current.literal
1216
+ }))
1217
+ });
1218
+ };
1219
+ const runCommand = (command) => {
1220
+ updateQuery();
1221
+ command(view);
1222
+ searchInput.input.focus();
1223
+ };
1224
+ searchInput.input.addEventListener("input", updateQuery);
1225
+ replaceInput.input.addEventListener("input", updateQuery);
1226
+ caseSensitive.input.addEventListener("change", updateQuery);
1227
+ caseSensitive.button.addEventListener("click", () => {
1228
+ caseSensitive.input.checked = !caseSensitive.input.checked;
1229
+ updateQuery();
1230
+ });
1231
+ wholeWord.button.addEventListener("click", () => {
1232
+ wholeWord.input.checked = !wholeWord.input.checked;
1233
+ updateQuery();
1234
+ });
1235
+ preserveCase.button.addEventListener("click", () => {
1236
+ preserveCase.input.checked = !preserveCase.input.checked;
1237
+ preserveCase.button.classList.toggle("is-active", preserveCase.input.checked);
1238
+ });
1239
+ wholeWord.input.addEventListener("change", updateQuery);
1240
+ searchInput.input.addEventListener("keydown", (event) => handleKey(event, () => runCommand(import_search2.findNext), () => runCommand(import_search2.findPrevious)));
1241
+ replaceInput.input.addEventListener("keydown", (event) => handleKey(event, () => runCommand(import_search2.findNext), () => runCommand(import_search2.findPrevious)));
1242
+ nextButton.addEventListener("click", () => runCommand(import_search2.findNext));
1243
+ previousButton.addEventListener("click", () => runCommand(import_search2.findPrevious));
1244
+ replaceButton.addEventListener("click", () => runCommand(import_search2.replaceNext));
1245
+ replaceAllButton.addEventListener("click", () => runCommand(import_search2.replaceAll));
1246
+ closeButton.addEventListener("click", () => (0, import_search2.closeSearchPanel)(view));
1247
+ replaceToggle.addEventListener("click", () => {
1248
+ replaceRow.hidden = !replaceRow.hidden;
1249
+ replaceToggle.classList.toggle("is-active", !replaceRow.hidden);
1250
+ replaceToggle.title = replaceRow.hidden ? labels.toggleReplace : labels.hideReplace;
1251
+ replaceToggle.setAttribute("aria-label", replaceToggle.title);
1252
+ replaceInput.input.focus();
1253
+ });
1254
+ replaceToggle.classList.add("is-active");
1255
+ replaceToggle.title = labels.hideReplace;
1256
+ replaceToggle.setAttribute("aria-label", labels.hideReplace);
1257
+ const update = () => {
1258
+ const query = (0, import_search2.getSearchQuery)(view.state);
1259
+ if (document.activeElement !== searchInput.input) searchInput.input.value = query.search;
1260
+ if (document.activeElement !== replaceInput.input) replaceInput.input.value = query.replace;
1261
+ caseSensitive.input.checked = query.caseSensitive;
1262
+ wholeWord.input.checked = query.wholeWord;
1263
+ caseSensitive.button.classList.toggle("is-active", query.caseSensitive);
1264
+ wholeWord.button.classList.toggle("is-active", query.wholeWord);
1265
+ preserveCase.button.classList.toggle("is-active", preserveCase.input.checked);
1266
+ updateMatchCount(query, view, matchCount);
1267
+ };
1268
+ update();
1269
+ return {
1270
+ dom: panel,
1271
+ top: true,
1272
+ mount: () => {
1273
+ update();
1274
+ searchInput.input.focus();
1275
+ searchInput.input.select();
1276
+ },
1277
+ update: (_update) => update()
1278
+ };
1279
+ }
1280
+ function updateMatchCount(query, view, target) {
1281
+ if (!query.valid || !query.search) {
1282
+ target.textContent = "";
1283
+ return;
1284
+ }
1285
+ const matches = [];
1286
+ const cursor = query.getCursor(view.state);
1287
+ for (let match = cursor.next(); !match.done; match = cursor.next()) {
1288
+ matches.push(match.value);
1289
+ }
1290
+ if (!matches.length) {
1291
+ target.textContent = "0";
1292
+ return;
1293
+ }
1294
+ const selection = view.state.selection.main;
1295
+ const current = matches.findIndex((match) => match.from === selection.from && match.to === selection.to);
1296
+ target.textContent = `${current >= 0 ? current + 1 : 1} / ${matches.length}`;
1297
+ }
1298
+ function createInput(className, placeholder) {
1299
+ const wrapper = document.createElement("label");
1300
+ wrapper.className = `chord-search-field ${className}`;
1301
+ const input = document.createElement("input");
1302
+ input.type = "text";
1303
+ input.placeholder = placeholder;
1304
+ input.setAttribute("aria-label", placeholder);
1305
+ wrapper.append(input);
1306
+ return { wrapper, input };
1307
+ }
1308
+ function createButton(className, label, text = label) {
1309
+ const button = document.createElement("button");
1310
+ button.type = "button";
1311
+ button.className = `chord-search-button ${className}`;
1312
+ button.textContent = text;
1313
+ button.title = label;
1314
+ button.setAttribute("aria-label", label);
1315
+ return button;
1316
+ }
1317
+ function createToggle(className, label, text) {
1318
+ const button = document.createElement("button");
1319
+ button.type = "button";
1320
+ button.className = `chord-search-option chord-search-toggle ${className}`;
1321
+ button.title = label;
1322
+ button.setAttribute("aria-label", label);
1323
+ const input = document.createElement("input");
1324
+ input.type = "checkbox";
1325
+ input.tabIndex = -1;
1326
+ input.setAttribute("aria-hidden", "true");
1327
+ const textElement = document.createElement("span");
1328
+ textElement.textContent = text;
1329
+ button.append(input, textElement);
1330
+ return { button, input };
1331
+ }
1332
+ function handleKey(event, next, previous) {
1333
+ if (event.key !== "Enter") return;
1334
+ event.preventDefault();
1335
+ event.shiftKey ? previous() : next();
1336
+ }
1337
+
769
1338
  // src/index.ts
770
1339
  function createChordProEditor(options) {
771
1340
  const themeCompartment = new import_state2.Compartment();
@@ -777,17 +1346,17 @@ function createChordProEditor(options) {
777
1346
  (update.view.hasFocus ? options.onFocus : options.onBlur)?.();
778
1347
  }
779
1348
  });
1349
+ const lintExtensions = createLintExtensions(options.lintLabels ?? (() => defaultLintLabels));
780
1350
  const state = import_state2.EditorState.create({
781
1351
  doc: options.doc ?? "",
782
1352
  extensions: [
783
1353
  basicSetup(),
784
1354
  chordPro(),
785
1355
  chordProFolding,
786
- duplicateDirectiveLinter,
787
- parserWarningLinter,
788
- chordNotationLinter,
1356
+ ...lintExtensions,
789
1357
  chordProAutocomplete(),
790
1358
  themeCompartment.of(themeExtension(options.theme ?? "light")),
1359
+ (0, import_search3.search)({ top: true, createPanel: (view2) => createSearchPanel(view2, options.searchLabels?.()) }),
791
1360
  updateListener,
792
1361
  ...options.extensions ?? []
793
1362
  ]
@@ -810,6 +1379,9 @@ function createChordProEditor(options) {
810
1379
  openCompletionList: () => {
811
1380
  openCompletionList(view);
812
1381
  },
1382
+ openSearch: () => {
1383
+ (0, import_search3.openSearchPanel)(view);
1384
+ },
813
1385
  getChordNotationSuggestions: () => getChordNotationSuggestions(view.state.doc.toString()),
814
1386
  normalizeChordNotation: () => {
815
1387
  const content = view.state.doc.toString();
@@ -822,6 +1394,7 @@ function createChordProEditor(options) {
822
1394
  }
823
1395
  return normalization.suggestions;
824
1396
  },
1397
+ refreshLint: () => view.dispatch({}),
825
1398
  focus: () => view.focus(),
826
1399
  destroy: () => view.destroy()
827
1400
  };