Skip to content

Commit

Permalink
Merge pull request #141 from gaelj/release
Browse files Browse the repository at this point in the history
Release 0.6.4
  • Loading branch information
gaelj authored Feb 14, 2024
2 parents 8e30a6f + 94b0068 commit 31b5547
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 49 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## 0.6.4 - 2024-02-14

### ✨ Introduce new features

- Add ShowMarkdownControlCharactersAroundCursor parameter

### ⬆️ Upgrade dependencies

- Update Microsoft to 8.0.2

### 🎨 Improve structure / format of the code

- Improve local storage management

### 💄 Add or update the UI and style files

- Ensure correct aspect ratio of svg diagrams

## 0.6.3 - 2024-02-14

### ✨ Introduce new features
Expand Down
6 changes: 3 additions & 3 deletions 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.6.3</Version>
<Version>0.6.4</Version>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down Expand Up @@ -38,8 +38,8 @@
<SupportedPlatform Include="browser-wasm" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.26" Condition="'$(TargetFramework)'=='net6.0'" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.15" Condition="'$(TargetFramework)'=='net7.0'" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.27" Condition="'$(TargetFramework)'=='net6.0'" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.16" Condition="'$(TargetFramework)'=='net7.0'" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.2" Condition="'$(TargetFramework)'=='net8.0'" />
</ItemGroup>
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions CodeMirror6/CodeMirror6Wrapper.razor
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
LineNumbers="@LineNumbers"
PreviewImages="@PreviewImages"
ScrollPastEnd="@ScrollPastEnd"
ShowMarkdownControlCharactersAroundCursor="@ShowMarkdownControlCharactersAroundCursor"
/>
</ChildContent>
<ErrorContent Context="c">
Expand Down
4 changes: 4 additions & 0 deletions CodeMirror6/CodeMirror6Wrapper.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ public partial class CodeMirror6Wrapper : ComponentBase
/// </summary>
[Parameter] public bool ScrollPastEnd { get; init; } = true;
/// <summary>
/// Whether to show the markdown control characters around the cursor
/// </summary>
[Parameter] public bool ShowMarkdownControlCharactersAroundCursor { get; init; } = true;
/// <summary>
/// Additional attributes to be applied to the container element
/// </summary>
[Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; }
Expand Down
11 changes: 10 additions & 1 deletion CodeMirror6/CodeMirror6WrapperInternal.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ public partial class CodeMirror6WrapperInternal : ComponentBase, IAsyncDisposabl
/// </summary>
[Parameter] public bool ScrollPastEnd { get; init; } = true;
/// <summary>
/// Whether to show the markdown control characters around the cursor
/// </summary>
[Parameter] public bool ShowMarkdownControlCharactersAroundCursor { get; init; } = true;
/// <summary>
/// Additional attributes to be applied to the container element
/// </summary>
[Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; }
Expand Down Expand Up @@ -283,7 +287,8 @@ protected override async Task OnInitializedAsync()
DropCursor,
PreviewImages,
ScrollPastEnd,
HighlightActiveLine
HighlightActiveLine,
ShowMarkdownControlCharactersAroundCursor
);
try {
if (IsWASM)
Expand Down Expand Up @@ -441,6 +446,10 @@ protected override async Task OnParametersSetAsync()
Config.HighlightActiveLine = HighlightActiveLine;
updated = true;
}
if (Config.ShowMarkdownControlCharactersAroundCursor != ShowMarkdownControlCharactersAroundCursor) {
Config.ShowMarkdownControlCharactersAroundCursor = ShowMarkdownControlCharactersAroundCursor;
updated = true;
}
if (updated)
await CmJsInterop.PropertySetters.SetConfiguration();
}
Expand Down
9 changes: 8 additions & 1 deletion CodeMirror6/Models/CodeMirrorConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace GaelJ.BlazorCodeMirror6.Models;
/// <param name="previewImages"></param>
/// <param name="scrollPastEnd"></param>
/// <param name="highlightActiveLine"></param>
/// <param name="showMarkdownControlCharactersAroundCursor"></param>
public class CodeMirrorConfiguration(
string? doc,
string? placeholder,
Expand Down Expand Up @@ -62,7 +63,8 @@ public class CodeMirrorConfiguration(
bool dropCursor,
bool previewImages,
bool scrollPastEnd,
bool highlightActiveLine)
bool highlightActiveLine,
bool showMarkdownControlCharactersAroundCursor)
{
/// <summary>
/// The text to display in the editor
Expand Down Expand Up @@ -203,4 +205,9 @@ public class CodeMirrorConfiguration(
/// Can the user scroll past the end of the document
/// </summary>
[JsonPropertyName("scrollPastEnd")] public bool ScrollPastEnd { get; internal set; } = scrollPastEnd;

/// <summary>
/// Whether to show markdown control characters around the cursor
/// </summary>
[JsonPropertyName("showMarkdownControlCharactersAroundCursor")] public bool ShowMarkdownControlCharactersAroundCursor { get; internal set; } = showMarkdownControlCharactersAroundCursor;
}
1 change: 1 addition & 0 deletions CodeMirror6/NodeLib/src/CmConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class CmConfiguration {
public previewImages: boolean
public scrollPastEnd: boolean
public highlightActiveLine: boolean
public showMarkdownControlCharactersAroundCursor: boolean
}

export interface UnifiedMergeConfig {
Expand Down
1 change: 1 addition & 0 deletions CodeMirror6/NodeLib/src/CmDiagrams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class DiagramWidget extends WidgetType {
svgElement.style.maxHeight = '800px'
svgElement.style.maxWidth = 'calc(100% - 2em)'
svgElement.style.objectFit = 'scale-down'
svgElement.setAttribute('preserveAspectRatio', "xMinYMin meet")
}
container.style.fontStyle = ''
container.style.color = ''
Expand Down
6 changes: 5 additions & 1 deletion CodeMirror6/NodeLib/src/CmHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import type { EditorState, Extension, Range } from '@codemirror/state'
import type { EditorState } from '@codemirror/state'
import { syntaxTree } from '@codemirror/language'
import { CMInstances } from './CmInstance'
import { getIdFromState } from './CmId'


const hasOverlap = (x1: number, x2: number, y1: number, y2: number) => {
return Math.max(x1, y1) <= Math.min(x2, y2)
}

export const isCursorInRange = (state: EditorState, from: number, to: number) => {
const id = getIdFromState(state)
if (!CMInstances[id].config.showMarkdownControlCharactersAroundCursor) return false
return state.selection.ranges.some((range) => {
return hasOverlap(from, to, range.from, range.to)
})
Expand Down
19 changes: 19 additions & 0 deletions CodeMirror6/NodeLib/src/CmId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { EditorState, StateField, StateEffect, Extension } from "@codemirror/state";


const idField = StateField.define<string>({
create() {
return ""
},
update(value, tr) {
return value;
}
});

export function createEditorWithId(id: string): Extension {
return idField.init(() => id)
}

export function getIdFromState(state: EditorState): string {
return state.field(idField)
}
32 changes: 16 additions & 16 deletions CodeMirror6/NodeLib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import { dynamicDiagramsExtension } from "./CmDiagrams"
import { foldMarkdownCodeBlocks, hideMarksExtension } from "./CmHideMarkdownMarks"
import { getColumnStylingKeymap, columnStylingPlugin, columnLintSource, getSeparator } from "./CmColumns"
import { consoleLog } from "./CmLogging"
import { createEditorWithId } from "./CmId"

/**
* Initialize a new CodeMirror instance
Expand Down Expand Up @@ -110,6 +111,7 @@ export async function initCodeMirror(
customKeyMap.push(indentWithTab)

let extensions = [
createEditorWithId(id),
CMInstances[id].keymapCompartment.of(keymap.of(customKeyMap)),
CMInstances[id].languageCompartment.of(await getLanguage(id, initialConfig.languageName, initialConfig.fileNameOrExtension) ?? []),
CMInstances[id].markdownStylingCompartment.of(initialConfig.languageName !== "Markdown" ? [] : autoFormatMarkdownExtensions(id, initialConfig.autoFormatMarkdown)),
Expand Down Expand Up @@ -452,42 +454,40 @@ function setDoc(id: string, text: string) {

function setLocalStorageKey(id: string, value: string) {
consoleLog(id, `${id} Setting local storage key to ${value}`)
if (CMInstances[id].config.localStorageKey === value) return
saveToLocalStorage(id)
CMInstances[id].config.localStorageKey = value
if (value)
loadFromLocalStorage(id)
else
clearLocalStorage(id)
}

export function clearLocalStorage(id: string) {
const localStorageKey = CMInstances[id].config.localStorageKey
if (!localStorageKey) return
consoleLog(id, `${id} Clearing local storage ${localStorageKey}`)
localStorage.removeItem(localStorageKey)
}

function loadFromLocalStorage(id: string) {
const localStorageKey = CMInstances[id].config.localStorageKey
if (!localStorageKey) return
consoleLog(id, `${id} Loading text from local storage key ${localStorageKey}`)
if (localStorageKey) {
const value = localStorage.getItem(localStorageKey)
setDoc(id, value)
}
const value = localStorage.getItem(localStorageKey)
setDoc(id, value)
}

function saveToLocalStorage(id: string) {
const localStorageKey = CMInstances[id].config.localStorageKey
if (!localStorageKey) return
consoleLog(id, `${id} Saving to local storage key ${localStorageKey}`)
if (localStorageKey) {
const value = CMInstances[id].view.state.doc.toString()
if (value) {
consoleLog(id, `Setting value to ${value}`)
localStorage.setItem(localStorageKey, value)
}
else {
consoleLog(id, `Removing item from local storage`)
localStorage.removeItem(localStorageKey)
}
const value = CMInstances[id].view.state.doc.toString()
if (value) {
consoleLog(id, `Setting value to ${value}`)
localStorage.setItem(localStorageKey, value)
}
else {
consoleLog(id, `Removing item from local storage`)
localStorage.removeItem(localStorageKey)
}
}

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.6.3</Version>
<Version>0.6.4</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.6.3</Version>
<Version>0.6.4</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Sentry.AspNetCore" Version="4.1.0" />
Expand Down
6 changes: 3 additions & 3 deletions Examples.BlazorWasm/Examples.BlazorWasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<Version>0.6.3</Version>
<Version>0.6.4</Version>
</PropertyGroup>
<ItemGroup>
<SupportedPlatform Include="browser-wasm" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.2" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CodeMirror6\CodeMirror6.csproj" />
Expand Down
1 change: 1 addition & 0 deletions Examples.Common/Example.razor
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
ScrollPastEnd=@(!ReadOnly)
DropCursor=@(!ReadOnly)
DrawSelection=@(!ReadOnly)
ShowMarkdownControlCharactersAroundCursor=@(!ReadOnly)
PreviewImages=@true
LineWrapping=@LineWrapping
MergeViewConfiguration=@MergeViewConfiguration
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.6.3</Version>
<Version>0.6.4</Version>
</PropertyGroup>
<ItemGroup>
<SupportedPlatform Include="browser" />
Expand Down
26 changes: 5 additions & 21 deletions NEW_CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
### ✨ Introduce new features

- Add ScrollIntoView command

### ⚡️ Improve performance

- Don't dispatch empty changes in setConfiguration
- Add ShowMarkdownControlCharactersAroundCursor parameter

### ⬆️ Upgrade dependencies

- Update Microsoft.AspNetCore.Components.Web to 8.0.2
- Update Microsoft to 8.0.2

### 🎨 Improve structure / format of the code

- Cleanup diagrams

### 🔊 Add or update logs

- Add loggings for local storage

### 🔧 Add or update configuration files

- Add github source link

### 🗑️ Deprecate code that needs to be cleaned up

- Remove useless localStorageKey copy
- Improve local storage management

### 🚚 Move or rename resources (e.g., files, paths)
### 💄 Add or update the UI and style files

- Move initial logs earlier
- Ensure correct aspect ratio of svg diagrams

0 comments on commit 31b5547

Please sign in to comment.