@chordproject/editor 1.1.1 → 1.1.2
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/README.md +32 -7
- package/dist/index.cjs +17 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -1
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
# ChordPro Editor
|
|
2
2
|
|
|
3
|
-
A CodeMirror 6
|
|
3
|
+
A CodeMirror 6 editor for ChordPro songs, with syntax highlighting, completions, folding,
|
|
4
|
+
search and replace, and inline diagnostics.
|
|
4
5
|
|
|
5
6
|
**Part of [ChordProject](https://chordproject.com/)**
|
|
6
7
|
|
|
7
8
|
## Overview
|
|
8
9
|
|
|
9
|
-
A CodeMirror 6 editor that
|
|
10
|
-
|
|
10
|
+
A standalone CodeMirror 6 editor that understands ChordPro directives, chords, comments, and tab
|
|
11
|
+
blocks. Its syntax support follows the official
|
|
11
12
|
[ChordPro directives](https://www.chordpro.org/chordpro/chordpro-directives/) and
|
|
12
13
|
[chord](https://www.chordpro.org/chordpro/chordpro-chords/) specification.
|
|
13
14
|
|
|
15
|
+
The editor also lints parser warnings, repeated single-value metadata, unclosed sections, and
|
|
16
|
+
valid but non-canonical chord spellings. Hosts can provide localized labels for diagnostics and
|
|
17
|
+
the search panel.
|
|
18
|
+
|
|
14
19
|
## Usage
|
|
15
20
|
|
|
16
21
|
### Requirements
|
|
@@ -49,6 +54,8 @@ standalone use. Ships with its own TypeScript types, no `@types/*` package neede
|
|
|
49
54
|
| `extensions` | `Extension[]?` | Extra CodeMirror 6 extensions to append (escape hatch). |
|
|
50
55
|
| `onChange` | `(value: string) => void` | Called with the full document on every change. |
|
|
51
56
|
| `onFocus` / `onBlur` | `() => void` | Called when the editor gains/loses focus. |
|
|
57
|
+
| `searchLabels` | `() => SearchLabels` | Supplies translated labels for the search and replace panel. |
|
|
58
|
+
| `lintLabels` | `() => LintLabels` | Supplies translated labels for all inline diagnostics. |
|
|
52
59
|
|
|
53
60
|
The returned `ChordProEditor` handle:
|
|
54
61
|
|
|
@@ -59,8 +66,10 @@ The returned `ChordProEditor` handle:
|
|
|
59
66
|
| `setTheme('light' \| 'dark')` | Swaps the theme without recreating the editor. |
|
|
60
67
|
| `insertChord()` | Inserts `"[]"` at the cursor (or wraps the selection) and opens chord suggestions - no keyboard shortcut needed, works from a button/tap. |
|
|
61
68
|
| `openCompletionList()` | Opens the completion list (chords or snippets, depending on cursor position) without any keyboard shortcut. |
|
|
69
|
+
| `openSearch()` | Opens the search and replace panel. |
|
|
62
70
|
| `getChordNotationSuggestions()` | Returns grouped suggestions for valid non-canonical chord spellings, such as `Asus` to `Asus4`. |
|
|
63
71
|
| `normalizeChordNotation()` | Replaces all suggested spellings in one undoable CodeMirror transaction and returns the applied groups. |
|
|
72
|
+
| `refreshLint()` | Re-runs diagnostics, for example after changing the active language. |
|
|
64
73
|
| `focus()` / `destroy()` | Focus the editor / tear it down and release its DOM node. |
|
|
65
74
|
|
|
66
75
|
Multiple independent `createChordProEditor()` instances can coexist on the same page.
|
|
@@ -83,19 +92,35 @@ $ npm test
|
|
|
83
92
|
The test suite covers grouped chord-notation suggestions and safe normalization of slash chords,
|
|
84
93
|
annotations, already canonical chords, and historical combined tokens.
|
|
85
94
|
|
|
95
|
+
## Publishing
|
|
96
|
+
|
|
97
|
+
Publishing uses npm Trusted Publishing from GitHub Actions; no npm token is stored in GitHub.
|
|
98
|
+
In npm package settings, add a GitHub Actions trusted publisher for organization `chordproject`,
|
|
99
|
+
repository `chordproject-editor`, and workflow file `publish.yml`. After merging changes, run
|
|
100
|
+
`npm run release` for a patch, or `npm run release:minor` / `npm run release:major`. These
|
|
101
|
+
commands run tests, bump the version, commit and tag it, then push; GitHub Actions publishes to
|
|
102
|
+
npmjs.org using OIDC. The tag must match `package.json`.
|
|
103
|
+
|
|
86
104
|
## Features
|
|
87
105
|
|
|
88
106
|
- Syntax highlighting: directives (known/custom/invalid), chords, comments, tab blocks, `{define:}`
|
|
89
107
|
- Chord autocomplete (common chord vocabulary, boosted by chords already used in the song)
|
|
90
108
|
- Directive snippets, expandable with `Tab` (see table below)
|
|
91
109
|
- Folding for `{start_of_x}`/`{end_of_x}` blocks
|
|
92
|
-
-
|
|
93
|
-
-
|
|
110
|
+
- Inline parser diagnostics for malformed directives, invalid metadata, and malformed chords
|
|
111
|
+
- Non-blocking warnings for repeated single-value metadata and unclosed sections, with an action to insert the missing closing directive
|
|
94
112
|
- Suggests canonical spellings for valid legacy abbreviations such as `Asus` to `Asus4`, `AM7` to `Amaj7`, and `D+` to `Daug`, with an individual replacement action
|
|
95
113
|
- Exposes `getChordNotationSuggestions()` and `normalizeChordNotationText(content)` for hosts that want to preview or apply grouped normalization
|
|
114
|
+
- Built-in search and replace, also available programmatically through `openSearch()`
|
|
96
115
|
- No fixed keyboard shortcut requirement: chords and snippets suggest themselves as you type,
|
|
97
|
-
and `insertChord()`/`openCompletionList()`
|
|
98
|
-
|
|
116
|
+
and `insertChord()`/`openCompletionList()` can be called from a button or touch control
|
|
117
|
+
|
|
118
|
+
### Localization
|
|
119
|
+
|
|
120
|
+
Provide `searchLabels` and `lintLabels` callbacks when creating the editor to translate the
|
|
121
|
+
search panel and lint messages. Call `refreshLint()` after changing the active language so
|
|
122
|
+
existing diagnostics are regenerated with the new labels. The exported `SearchLabels` and
|
|
123
|
+
`LintLabels` types describe the supported strings.
|
|
99
124
|
|
|
100
125
|
### Snippets
|
|
101
126
|
|
package/dist/index.cjs
CHANGED
|
@@ -587,6 +587,20 @@ var SECTION_STARTS = {
|
|
|
587
587
|
sot: "end_of_tab"
|
|
588
588
|
};
|
|
589
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 hasExplicitSectionEndAhead(view, lineNumber, endDirective) {
|
|
591
|
+
for (let nextLineNumber = lineNumber + 1; nextLineNumber <= view.state.doc.lines; nextLineNumber++) {
|
|
592
|
+
const nextLine = view.state.doc.line(nextLineNumber);
|
|
593
|
+
if (!nextLine.text.trim()) {
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
596
|
+
const directive = nextLine.text.match(DIRECTIVE_LINE)?.[1].toLowerCase();
|
|
597
|
+
if (!directive) {
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
return directive === endDirective || endDirective === "end_of_chorus" && directive === "eoc" || endDirective === "end_of_verse" && directive === "eov" || endDirective === "end_of_bridge" && directive === "eob" || endDirective === "end_of_tab" && directive === "eot";
|
|
601
|
+
}
|
|
602
|
+
return false;
|
|
603
|
+
}
|
|
590
604
|
function createLintExtensions(getLabels = () => defaultLintLabels) {
|
|
591
605
|
const duplicateDirectiveLinter = (0, import_lint2.linter)((view) => {
|
|
592
606
|
const diagnostics = [];
|
|
@@ -670,6 +684,9 @@ function createLintExtensions(getLabels = () => defaultLintLabels) {
|
|
|
670
684
|
continue;
|
|
671
685
|
}
|
|
672
686
|
if (openSection && !line.text.trim()) {
|
|
687
|
+
if (hasExplicitSectionEndAhead(view, lineNumber, openSection.endDirective)) {
|
|
688
|
+
continue;
|
|
689
|
+
}
|
|
673
690
|
const nextDirective = nextNonBlankDirective(view, lineNumber);
|
|
674
691
|
if (sectionHasContent) {
|
|
675
692
|
openSection.insertionAt = line.from;
|