@chordproject/editor 1.0.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/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # ChordPro Editor
2
+
3
+ A CodeMirror 6 based editor for ChordPro songs. **~26 KB** (~7 KB gzipped).
4
+
5
+ **Part of [ChordProject](https://chordproject.com/)**
6
+
7
+ ## Overview
8
+
9
+ A CodeMirror 6 editor that highlights ChordPro syntax (directives, chords, comments, tab blocks),
10
+ aligned with the official
11
+ [ChordPro directives](https://www.chordpro.org/chordpro/chordpro-directives/) and
12
+ [chord](https://www.chordpro.org/chordpro/chordpro-chords/) specification.
13
+
14
+ ## Usage
15
+
16
+ ### Requirements
17
+
18
+ - Node.js 20.19.0 or newer for development and builds.
19
+ - `@chordproject/parser` version 1 or newer is a peer dependency and must be installed by the consuming application.
20
+
21
+ ```sh
22
+ $ npm i @chordproject/editor
23
+ ```
24
+
25
+ ```ts
26
+ import { createChordProEditor } from '@chordproject/editor';
27
+
28
+ const editor = createChordProEditor({
29
+ parent: document.querySelector('#editor'),
30
+ doc: '{title: Amazing Grace}\n[G]Amazing [C]grace...',
31
+ theme: 'light', // or 'dark'
32
+ onChange: (value) => console.log(value),
33
+ });
34
+ ```
35
+
36
+ Colors read the same CSS custom properties as [chordproject-client](https://github.com/chordproject/chordproject-client)
37
+ (`--color-primary-*`, `--color-error-*`, `--color-neutral-*`), with sensible fallbacks for
38
+ standalone use. Ships with its own TypeScript types, no `@types/*` package needed.
39
+
40
+ ## API
41
+
42
+ ### `createChordProEditor(options): ChordProEditor`
43
+
44
+ | Option | Type | Description |
45
+ | --- | --- | --- |
46
+ | `parent` | `HTMLElement` | **Required.** Element that will contain the editor. |
47
+ | `doc` | `string?` | Initial document content. |
48
+ | `theme` | `'light' \| 'dark'?` | Initial theme. Defaults to `'light'`. |
49
+ | `extensions` | `Extension[]?` | Extra CodeMirror 6 extensions to append (escape hatch). |
50
+ | `onChange` | `(value: string) => void` | Called with the full document on every change. |
51
+ | `onFocus` / `onBlur` | `() => void` | Called when the editor gains/loses focus. |
52
+
53
+ The returned `ChordProEditor` handle:
54
+
55
+ | Member | Description |
56
+ | --- | --- |
57
+ | `view` | The underlying CodeMirror `EditorView`, for anything not covered below. |
58
+ | `getValue()` / `setValue(value)` | Read/replace the whole document. |
59
+ | `setTheme('light' \| 'dark')` | Swaps the theme without recreating the editor. |
60
+ | `insertChord()` | Inserts `"[]"` at the cursor (or wraps the selection) and opens chord suggestions - no keyboard shortcut needed, works from a button/tap. |
61
+ | `openCompletionList()` | Opens the completion list (chords or snippets, depending on cursor position) without any keyboard shortcut. |
62
+ | `getChordNotationSuggestions()` | Returns grouped suggestions for valid non-canonical chord spellings, such as `Asus` to `Asus4`. |
63
+ | `normalizeChordNotation()` | Replaces all suggested spellings in one undoable CodeMirror transaction and returns the applied groups. |
64
+ | `focus()` / `destroy()` | Focus the editor / tear it down and release its DOM node. |
65
+
66
+ Multiple independent `createChordProEditor()` instances can coexist on the same page.
67
+
68
+ ## Demo
69
+
70
+ ```sh
71
+ $ npm i
72
+ $ npm run dev
73
+ ```
74
+
75
+ Open http://localhost:5173/ to try it.
76
+
77
+ ## Tests
78
+
79
+ ```sh
80
+ $ npm test
81
+ ```
82
+
83
+ The test suite covers grouped chord-notation suggestions and safe normalization of slash chords,
84
+ annotations, already canonical chords, and historical combined tokens.
85
+
86
+ ## Features
87
+
88
+ - Syntax highlighting: directives (known/custom/invalid), chords, comments, tab blocks, `{define:}`
89
+ - Chord autocomplete (common chord vocabulary, boosted by chords already used in the song)
90
+ - Directive snippets, expandable with `Tab` (see table below)
91
+ - Folding for `{start_of_x}`/`{end_of_x}` blocks
92
+ - Parser warnings displayed on their source line for malformed directives, invalid metadata, and malformed chords
93
+ - Warns (non-blocking) when a "once per song" directive like `{title:}` or `{key:}` is repeated
94
+ - 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
+ - Exposes `getChordNotationSuggestions()` and `normalizeChordNotationText(content)` for hosts that want to preview or apply grouped normalization
96
+ - No fixed keyboard shortcut requirement: chords and snippets suggest themselves as you type,
97
+ and `insertChord()`/`openCompletionList()` work from a button/tap - useful since `Ctrl+Space`
98
+ and its usual alternates are unreliable across OS/keyboard layouts
99
+
100
+ ### Snippets
101
+
102
+ Type the snippet and press `Tab` to expand it.
103
+
104
+ | Snippet | Result |
105
+ | --- | --- |
106
+ | `title` or `t` | `{title: value}` |
107
+ | `subtitle` or `st` | `{subtitle: value}` |
108
+ | `artist` or `a` | `{artist: value}` |
109
+ | `album` | `{album: value}` |
110
+ | `arranger` | `{arranger: value}` |
111
+ | `composer` | `{composer: value}` |
112
+ | `lyricist` | `{lyricist: value}` |
113
+ | `copyright` | `{copyright: value}` |
114
+ | `capo` | `{capo: 5}` |
115
+ | `key` or `k` | `{key: Am}` |
116
+ | `tempo` | `{tempo: 120}` |
117
+ | `time` | `{time: 4/4}` |
118
+ | `duration` | `{duration: 4:00}` |
119
+ | `year` | `{year: 2020}` |
120
+ | `meta` | `{meta: label value}` |
121
+ | `comment` or `c` | `{comment: value}` |
122
+ | `chorus` / `soc` / `eoc` | Chorus block / `{start_of_chorus}` / `{end_of_chorus}` |
123
+ | `verse` / `sov` / `eov` | Verse block / `{start_of_verse}` / `{end_of_verse}` |
124
+ | `bridge` / `sob` / `eob` | Bridge block / `{start_of_bridge}` / `{end_of_bridge}` |
125
+ | `tab` / `sot` / `eot` | Tab block with a 6-string template / `{start_of_tab}` / `{end_of_tab}` |
126
+ | `define` or `d` | `{define: Am base-fret 1 frets 0 0 0 0 0 0 fingers 0 0 0 0 0 0}` |
127
+ | `[` | Inserts a chord (`[Am]`) |
128
+
129
+ ## Contributing
130
+
131
+ This project welcomes contributions of all types. If you find any bug or want some new features, please feel free to create an issue or submit a pull request.
132
+
133
+ Join the community and chat with us on **[Discord](https://discord.gg/ZQAgwBC9c8)**
134
+
135
+ ## License
136
+ [GNU Affero General Public License v3.0](LICENSE)