Skip to content

Commit

Permalink
Merge pull request #95 from gaelj/release
Browse files Browse the repository at this point in the history
Release 0.3.2
  • Loading branch information
gaelj authored Feb 6, 2024
2 parents 39f3fa3 + f850299 commit 8950a9d
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 16 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 0.3.2 - 2024-02-06

### ⚡️ Improve performance

- Add "Visible" property to allow hiding the editor without destroying it

### ✨ Introduce new features

- Add linting that checks csv column count relative to first line
- Disable initial setting of line wrapping in csv mode

### 🐛 Fix a bug

- Fix tabulating csv columns skipped the last / first ones

### 📝 Add or update documentation

- Update README

## 0.3.1 - 2024-02-06

### 🐛 Fix a bug
Expand Down
2 changes: 1 addition & 1 deletion CodeMirror6/CodeMirror6.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AssemblyName>GaelJ.BlazorCodeMirror6</AssemblyName>
<IsPackable>true</IsPackable>
<PackageId>GaelJ.BlazorCodeMirror6</PackageId>
<Version>0.3.1</Version>
<Version>0.3.2</Version>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
1 change: 1 addition & 0 deletions CodeMirror6/CodeMirror6Wrapper.razor
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
FileNameOrExtension="@FileNameOrExtension"
HighlightWhitespace="@HighlightWhitespace"
HighlightTrailingWhitespace="@HighlightTrailingWhitespace"
Visible="@Visible"
/>
</ChildContent>
<ErrorContent Context="c">
Expand Down
5 changes: 5 additions & 0 deletions CodeMirror6/CodeMirror6Wrapper.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ public partial class CodeMirror6Wrapper : ComponentBase
/// <value></value>
[Parameter] public bool HighlightWhitespace { get; set; }
/// <summary>
/// Whether the editor is visible
/// </summary>
/// <value></value>
[Parameter] public bool Visible { get; set; }
/// <summary>
/// Additional attributes to be applied to the container element
/// </summary>
/// <value></value>
Expand Down
4 changes: 2 additions & 2 deletions CodeMirror6/CodeMirror6WrapperInternal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div
id=@LoadingDivId
@attributes=@AdditionalAttributes
class="editor-loading"
class="editor-loading @VisibleClass"
>
@for (var i = 0; i < (Doc?.Split("\n").Length ?? 10); i++) {
var randomWidth = new Random().Next(20, 80);
Expand All @@ -14,7 +14,7 @@
</div>
}

<div>
<div class=@VisibleClass>
<div
id=@Id
@attributes=@AdditionalAttributes
Expand Down
6 changes: 6 additions & 0 deletions CodeMirror6/CodeMirror6WrapperInternal.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ public partial class CodeMirror6WrapperInternal : ComponentBase, IAsyncDisposabl
/// <value></value>
[Parameter] public bool HighlightWhitespace { get; set; }
/// <summary>
/// Whether the editor is visible
/// </summary>
/// <value></value>
[Parameter] public bool Visible { get; set; }
/// <summary>
/// Additional attributes to be applied to the container element
/// </summary>
/// <value></value>
Expand All @@ -183,6 +188,7 @@ public partial class CodeMirror6WrapperInternal : ComponentBase, IAsyncDisposabl
: AllowVerticalResize ? "vertical"
: AllowHorizontalResize ? "horizontal"
: "none";
private string VisibleClass => Visible ? string.Empty : " d-none ";

/// <summary>
/// JavaScript interop instance
Expand Down
35 changes: 35 additions & 0 deletions CodeMirror6/NodeLib/src/CmColumns.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Decoration, ViewPlugin, EditorView, KeyBinding } from "@codemirror/view";
import { Extension, RangeSetBuilder, Transaction } from "@codemirror/state";
import { buildWidget } from "./lib/codemirror-kit";
import { Diagnostic } from "@codemirror/lint";


function createColumnReplaceDecoration(content: string, from: number) {
Expand Down Expand Up @@ -49,6 +50,11 @@ function getRelativeColumnOffset(text: string, separator: string, position: numb
} else if (char === '\\') {
escapeNext = true
offset++
} else if (char === '\n' && previous) {
previousColumnOffset = offset
offset++
} else if (char === '\n' && i >= position) {
return offset
} else if (char === separator && !inQuotes && previous) {
previousColumnOffset = offset
offset++
Expand Down Expand Up @@ -133,6 +139,35 @@ export const getColumnStylingKeymap = (separator: string): KeyBinding[] => [
}},
]

export function getSeparator(languageName: string) {
if (languageName === "CSV") return ','
if (languageName === "TSV") return '\t'
return null
}

export async function columnLintSource(view: EditorView, separator: string): Promise<readonly Diagnostic[]> {
try {
const code = view.state.doc.toString()
const data = parseCSV(code, separator)
const nbCols = data[0].length
const errors: Diagnostic[] = []
for (let i = 1; i < data.length; i++) {
if (data[i].length !== nbCols && data[i].length !== 1) {
const message = `Expected ${nbCols} columns, found ${data[i].length}`
const from = view.state.doc.line(i + 1).from
const to = view.state.doc.line(i + 1).to
errors.push({ from, to, message, severity: 'error' })
}
}
if (errors.length > 0)
console.log('Linter found:', errors)
return errors
} catch (error) {
console.error('Linter error:', error)
return
}
}

function moveCursor(view: EditorView, inc: number) {
console.log("moveCursors")
const { state } = view
Expand Down
3 changes: 2 additions & 1 deletion CodeMirror6/NodeLib/src/CmLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export async function externalLintSource(view: EditorView, dotnetHelper: DotNet.
try {
const code = view.state.doc.toString()
const errors: Diagnostic[] = await dotnetHelper.invokeMethodAsync("LintingRequestedFromJS", code)
console.log('Linter found:', errors)
if (errors.length > 0)
console.log('Linter found:', errors)
return errors
} catch (error) {
console.error('Linter error:', error)
Expand Down
17 changes: 13 additions & 4 deletions CodeMirror6/NodeLib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import { DotNet } from "@microsoft/dotnet-js-interop"
import { markdownTableExtension } from "./CmMarkdownTable"
import { dynamicDiagramsExtension } from "./CmDiagrams"
import { hideMarksExtension } from "./CmHideMarkdownMarks"
import { getColumnStylingKeymap, columnStylingPlugin } from "./CmColumns"
import { getColumnStylingKeymap, columnStylingPlugin, columnLintSource, getSeparator } from "./CmColumns"

/**
* Initialize a new CodeMirror instance
Expand Down Expand Up @@ -99,13 +99,17 @@ export async function initCodeMirror(
CMInstances[id].emojiReplacerCompartment.of(replaceEmojiExtension(initialConfig.replaceEmojiCodes)),
lastOperationWasUndo,
indentationMarkers(),
CMInstances[id].lineWrappingCompartment.of(initialConfig.lineWrapping ? EditorView.lineWrapping : []),
CMInstances[id].lineWrappingCompartment.of(initialConfig.lineWrapping && initialConfig.languageName !== "CSV" && initialConfig.languageName !== "TSV" ? EditorView.lineWrapping : []),
CMInstances[id].unifiedMergeViewCompartment.of(initialConfig.mergeViewConfiguration ? unifiedMergeView(initialConfig.mergeViewConfiguration) : []),
CMInstances[id].highlightTrailingWhitespaceCompartment.of(initialConfig.highlightTrailingWhitespace ? highlightTrailingWhitespace() : []),
CMInstances[id].highlightWhitespaceCompartment.of(initialConfig.highlightWhitespace ? highlightWhitespace() : []),
CMInstances[id].columnsStylingCompartment.of(
initialConfig.languageName === "CSV" || initialConfig.languageName === "TSV"
? [columnStylingPlugin(initialConfig.languageName === "CSV" ? ',' : '\t'), keymap.of(getColumnStylingKeymap(initialConfig.languageName === "CSV" ? ',' : '\t'))]
? [
columnStylingPlugin(getSeparator(initialConfig.languageName)),
keymap.of(getColumnStylingKeymap(getSeparator(initialConfig.languageName))),
linter(async view => columnLintSource(view, getSeparator(initialConfig.languageName))),
]
: []
),

Expand Down Expand Up @@ -304,6 +308,7 @@ export async function setLanguage(id: string, languageName: string, fileNameOrEx
const customKeyMap = getLanguageKeyMaps(languageName, fileNameOrExtension)
if (languageName !== "CSV" && languageName !== "TSV")
customKeyMap.push(indentWithTab)
const separator = getSeparator(languageName)

CMInstances[id].view.dispatch({
effects: [
Expand All @@ -313,7 +318,11 @@ export async function setLanguage(id: string, languageName: string, fileNameOrEx
CMInstances[id].markdownStylingCompartment.reconfigure(autoFormatMarkdownExtensions(id, languageName === 'Markdown')),
CMInstances[id].columnsStylingCompartment.reconfigure(
languageName === "CSV" || languageName === "TSV"
? [columnStylingPlugin(languageName === "CSV" ? ',' : '\t'), keymap.of(getColumnStylingKeymap(languageName === "CSV" ? ',' : '\t'))]
? [
columnStylingPlugin(separator),
keymap.of(getColumnStylingKeymap(separator)),
linter(async view => columnLintSource(view, separator)),
]
: []
),
]
Expand Down
2 changes: 1 addition & 1 deletion Examples.BlazorServer/Examples.BlazorServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>0.3.1</Version>
<Version>0.3.2</Version>
</PropertyGroup>
<ItemGroup>
<SupportedPlatform Include="browser" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<Version>0.3.1</Version>
<Version>0.3.2</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Sentry.AspNetCore" Version="3.41.4" />
Expand Down
2 changes: 1 addition & 1 deletion Examples.BlazorWasm/Examples.BlazorWasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<Version>0.3.1</Version>
<Version>0.3.2</Version>
</PropertyGroup>
<ItemGroup>
<SupportedPlatform Include="browser-wasm" />
Expand Down
2 changes: 1 addition & 1 deletion Examples.Common/Examples.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<Version>0.3.1</Version>
<Version>0.3.2</Version>
</PropertyGroup>
<ItemGroup>
<SupportedPlatform Include="browser" />
Expand Down
15 changes: 12 additions & 3 deletions NEW_CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
### ⚡️ Improve performance

- Add "Visible" property to allow hiding the editor without destroying it

### ✨ Introduce new features

- Add linting that checks csv column count relative to first line
- Disable initial setting of line wrapping in csv mode

### 🐛 Fix a bug

- Fix shift-tab in csv not working on last cell
- Fix tabulating csv columns skipped the last / first ones

### 🥅 Catch errors
### 📝 Add or update documentation

- Silence errors when DOM elements are no longer available in Diagrams (SVG) and file upload (main div)
- Update README
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Visit the [live demo](https://gaelj.github.io/BlazorCodeMirror6/) to see the com
- [x] support C# language
- [x] update doc in dotnet either on text changes or on blur
- [x] diff viewer
- [x] CSV mode: add column paddings for alignment, navigate columns with tab / shift-tab
- [ ] search & replace toolbar button
- [ ] toolbar with toolbar button template
- [ ] support read-only paragraphs
Expand All @@ -47,7 +48,6 @@ Visit the [live demo](https://gaelj.github.io/BlazorCodeMirror6/) to see the com
- [ ] automatic translation
- [ ] deleting a file link deletes the file from the server
- [ ] button (visible when editor is hovered), to copy raw editor content to clipboard
- [ ] CSV mode

### Markdown specific

Expand Down

0 comments on commit 8950a9d

Please sign in to comment.