Skip to content

Commit

Permalink
Merge branch 'main' into uwp-net8-windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Arlodotexe authored Dec 13, 2024
2 parents ce173c4 + a37acd3 commit 1f3d7b4
Show file tree
Hide file tree
Showing 25 changed files with 250 additions and 81 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,19 @@ jobs:
with:
vs-version: '[17.9,)'

- name: Define excluded MultiTargets (WinUI 2)
if: ${{ matrix.winui == '2' }}
run: |
echo "EXCLUDED_MULTITARGETS=wasdk" >> $env:GITHUB_ENV
- name: Define excluded MultiTargets (WinUI 3)
if: ${{ matrix.winui == '3' }}
run: |
echo "EXCLUDED_MULTITARGETS=uwp" >> $env:GITHUB_ENV
# Build and pack component nupkg
- name: Build and pack component packages
run: ./tooling/Build-Toolkit-Components.ps1 -MultiTargets all -WinUIMajorVersion ${{ matrix.winui }} -DateForVersion ${{ env.VERSION_DATE }} ${{ env.VERSION_PROPERTY != '' && format('-PreviewVersion "{0}"', env.VERSION_PROPERTY) || '' }} ${{ env.ENABLE_DIAGNOSTICS == 'true' && '-EnableBinlogs' || '' }} ${{ env.ENABLE_DIAGNOSTICS == 'true' && '-Verbose' || '' }} -BinlogOutput ./ -NupkgOutput ./ -Release
run: ./tooling/Build-Toolkit-Components.ps1 -MultiTargets all -ExcludeMultiTargets ${{ env.EXCLUDED_MULTITARGETS }} -WinUIMajorVersion ${{ matrix.winui }} -DateForVersion ${{ env.VERSION_DATE }} ${{ env.VERSION_PROPERTY != '' && format('-PreviewVersion "{0}"', env.VERSION_PROPERTY) || '' }} ${{ env.ENABLE_DIAGNOSTICS == 'true' && '-EnableBinlogs' || '' }} ${{ env.ENABLE_DIAGNOSTICS == 'true' && '-Verbose' || '' }} -BinlogOutput ./ -NupkgOutput ./ -Release

- name: Validate package names
if: ${{ env.VERSION_PROPERTY != '' }}
Expand Down
5 changes: 4 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>$(NoWarn);Uno0001</NoWarn>
<NoWarn>$(NoWarn);Uno0001</NoWarn>

<!-- See https://github.com/CommunityToolkit/Labs-Windows/pull/605#issuecomment-2498743676 -->
<WarningsNotAsErrors>NU1901;NU1902;NU1903;NU1904</WarningsNotAsErrors>
</PropertyGroup>

<Import Project="Windows.Toolkit.Common.props" />
Expand Down
16 changes: 16 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ If you find an experiment useful, please up-vote 👍 its corresponding issue an

Otherwise, you can clone the repo, open the `components` directory, navigate within the folder for a particular experiment and open up it's solution file in Visual Studio. Run one of the project heads (_ExperimentName.Uwp/Wasm/WinAppSDK_) to see its samples.

**List of current experiments**
- [AppServices](https://github.com/CommunityToolkit/Labs-Windows/tree/main/components/AppServices)
- [CanvasLayout](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/CanvasLayout/samples/CanvasLayout.md)
- [CanvasView](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/CanvasView/samples/CanvasView.md)
- [DataTable](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/DataTable/samples/DataTable.md)
- [Extensions.DependencyInjection](https://github.com/CommunityToolkit/Labs-Windows/tree/main/components/Extensions.DependencyInjection)
- [MarkdownTextBlock](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/MarkdownTextBlock/samples/MarkdownTextBlock.md)
- [MarqueeText](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/MarqueeText/samples/MarqueeText.md)
- [Notifications](https://github.com/CommunityToolkit/Labs-Windows/tree/main/components/Notifications)
- [Ribbon](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/Ribbon/samples/Ribbon.md)
- [RivePlayer](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/RivePlayer/samples/RivePlayer.md)
- [Shimmer](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/Shimmer/samples/Shimmer.md)
- [TitleBar](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/TitleBar/samples/TitleBar.md)
- [TokenView](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/TokenView/samples/TokenView.md)
- [TransitionHelper](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/TransitionHelper/samples/TransitionHelper.md)

## Clone the repository

The [tooling](https://github.com/CommunityToolkit/Tooling-Windows-Submodule) is in a submodule, so you'll need to use `--recurse-submodules` when cloning or pulling for the first time:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<Page x:Class="MarkdownTextBlockExperiment.Samples.MarkdownTextBlockCustomSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand All @@ -25,7 +25,8 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<controls:MarkdownTextBlock Grid.Column="0"
<controls:MarkdownTextBlock x:Name="MarkdownTextBlock1"
Grid.Column="0"
Config="{x:Bind LiveMarkdownConfig, Mode=OneTime}"
Text="{x:Bind MarkdownTextBox.Text, Mode=OneWay}" />
<TextBox x:Name="MarkdownTextBox"
Expand All @@ -37,7 +38,8 @@
FontSize="16"
FontWeight="Bold"
Text="Built-in Sample" />
<controls:MarkdownTextBlock Grid.Row="3"
<controls:MarkdownTextBlock x:Name="MarkdownTextBlock2"
Grid.Row="3"
Config="{x:Bind MarkdownConfig, Mode=OneTime}"
Text="{x:Bind Text, Mode=OneTime}" />
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,5 +607,12 @@ public MarkdownTextBlockCustomSample()
_liveConfig = new MarkdownConfig();
_text = _markdown;
MarkdownTextBox.Text = "# Hello World\n\n";
MarkdownTextBlock1.OnLinkClicked += MarkdownTextBlock_OnLinkClicked;
MarkdownTextBlock2.OnLinkClicked += MarkdownTextBlock_OnLinkClicked;
}

private void MarkdownTextBlock_OnLinkClicked(object? sender, LinkClickedEventArgs e)
{
Debug.WriteLine($"Link Clicked: {e.Uri}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
</ItemGroup>
<ItemGroup>
<!--<PackageReference Include="ColorCode.Core" Version="2.0.14" />-->
<PackageReference Include="HtmlAgilityPack" Version="1.11.48" />
<PackageReference Include="Markdig" Version="0.31.0" />
<PackageReference Include="Roman-Numerals" Version="2.0.0" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.71" />
<PackageReference Include="Markdig" Version="0.38.0" />
<PackageReference Include="Roman-Numerals" Version="2.0.1" />
</ItemGroup>
<ItemGroup Condition="'$(IsUwp)' == 'true'">
<Using Include="Windows.UI" />
Expand Down
11 changes: 11 additions & 0 deletions components/MarkdownTextBlock/src/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Xml.Linq;
using System.Globalization;
using Windows.UI.ViewManagement;
using HtmlAgilityPack;

namespace CommunityToolkit.Labs.WinUI.MarkdownTextBlock;

Expand Down Expand Up @@ -722,4 +723,14 @@ public static SolidColorBrush GetAccentColorBrush()

return accentBrush;
}

public static string GetAttribute(this HtmlNode node, string attributeName, string defaultValue)
{
if (attributeName == null)
{
throw new ArgumentNullException(nameof(attributeName));
}

return node.Attributes?[attributeName]?.Value ?? defaultValue;
}
}
14 changes: 12 additions & 2 deletions components/MarkdownTextBlock/src/HtmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,21 @@ public static void WriteHtml(WinUIRenderer renderer, HtmlNodeCollection nodes)
IAddChild hyperLink;
if (node.ChildNodes.Any(n => n.Name != "#text"))
{
hyperLink = new MyHyperlinkButton(node, renderer.Config.BaseUrl);
var myHyperlinkButton = new MyHyperlinkButton(node, renderer.Config.BaseUrl);
myHyperlinkButton.ClickEvent += (sender, e) =>
{
renderer.MarkdownTextBlock.RaiseLinkClickedEvent(((HyperlinkButton)sender).NavigateUri);
};
hyperLink = myHyperlinkButton;
}
else
{
hyperLink = new MyHyperlink(node, renderer.Config.BaseUrl);
var myHyperlink = new MyHyperlink(node, renderer.Config.BaseUrl);
myHyperlink.ClickEvent += (sender, e) =>
{
renderer.MarkdownTextBlock.RaiseLinkClickedEvent(sender.NavigateUri);
};
hyperLink = myHyperlink;
}
renderer.Push(hyperLink);
WriteHtml(renderer, node.ChildNodes);
Expand Down
15 changes: 15 additions & 0 deletions components/MarkdownTextBlock/src/LinkClickedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace CommunityToolkit.Labs.WinUI.MarkdownTextBlock;

public class LinkClickedEventArgs : EventArgs
{
public Uri Uri { get; }

public LinkClickedEventArgs(Uri uri)
{
this.Uri = uri;
}
}
33 changes: 27 additions & 6 deletions components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using CommunityToolkit.Labs.WinUI.MarkdownTextBlock.Renderers;
using CommunityToolkit.Labs.WinUI.MarkdownTextBlock.TextElements;
using Markdig;
using Markdig.Syntax;

namespace CommunityToolkit.Labs.WinUI.MarkdownTextBlock;

Expand All @@ -30,6 +31,12 @@ public partial class MarkdownTextBlock : Control
typeof(MarkdownTextBlock),
new PropertyMetadata(null, OnTextChanged));

private static readonly DependencyProperty MarkdownDocumentProperty = DependencyProperty.Register(
nameof(MarkdownDocument),
typeof(MarkdownDocument),
typeof(MarkdownTextBlock),
new PropertyMetadata(null));

public MarkdownConfig Config
{
get => (MarkdownConfig)GetValue(ConfigProperty);
Expand All @@ -42,6 +49,16 @@ public string Text
set => SetValue(TextProperty, value);
}

public MarkdownDocument? MarkdownDocument
{
get => (MarkdownDocument)GetValue(MarkdownDocumentProperty);
private set => SetValue(MarkdownDocumentProperty, value);
}

public event EventHandler<LinkClickedEventArgs>? OnLinkClicked;

internal void RaiseLinkClickedEvent(Uri uri) => OnLinkClicked?.Invoke(this, new LinkClickedEventArgs(uri));

private static void OnConfigChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is MarkdownTextBlock self && e.NewValue != null)
Expand All @@ -54,7 +71,7 @@ private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedE
{
if (d is MarkdownTextBlock self && e.NewValue != null)
{
self.ApplyText(self.Text, true);
self.ApplyText(true);
}
}

Expand Down Expand Up @@ -87,16 +104,20 @@ private void ApplyConfig(MarkdownConfig config)
}
}

private void ApplyText(string text, bool rerender)
private void ApplyText(bool rerender)
{
var markdown = Markdown.Parse(text, _pipeline);
if (_renderer != null)
{
if (rerender)
{
_renderer.ReloadDocument();
}
_renderer.Render(markdown);

if (!string.IsNullOrEmpty(Text))
{
this.MarkdownDocument = Markdown.Parse(Text, _pipeline);
_renderer.Render(this.MarkdownDocument);
}
}
}

Expand All @@ -106,10 +127,10 @@ private void Build()
{
if (_renderer == null)
{
_renderer = new WinUIRenderer(_document, Config);
_renderer = new WinUIRenderer(_document, Config, this);
}
_pipeline.Setup(_renderer);
ApplyText(Text, false);
ApplyText(false);
}
}
}
8 changes: 8 additions & 0 deletions components/MarkdownTextBlock/src/MarkdownThemes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ public sealed class MarkdownThemes : DependencyObject

public FontWeight H6FontWeight { get; set; } = FontWeights.Normal;

public Thickness H1Margin { get; set; } = new(left: 0, top: 14, right: 0, bottom: 0);
public Thickness H2Margin { get; set; } = new(left: 0, top: 14, right: 0, bottom: 0);
public Thickness H3Margin { get; set; } = new(left: 0, top: 14, right: 0, bottom: 0);
public Thickness H4Margin { get; set; } = new(left: 0, top: 14, right: 0, bottom: 0);
public Thickness H5Margin { get; set; } = new(left: 0, top: 8, right: 0, bottom: 0);
public Thickness H6Margin { get; set; } = new(left: 0, top: 8, right: 0, bottom: 0);

public Brush InlineCodeBackground { get; set; } = (Brush)Application.Current.Resources["ExpanderHeaderBackground"];
public Brush InlineCodeForeground { get; set; } = (Brush)Application.Current.Resources["TextFillColorPrimaryBrush"];

public Brush InlineCodeBorderBrush { get; set; } = new SolidColorBrush(Colors.Gray);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ protected override void Write(WinUIRenderer renderer, AutolinkInline link)
}

var autolink = new MyAutolinkInline(link);
autolink.ClickEvent += (sender, e) =>
{
renderer.MarkdownTextBlock.RaiseLinkClickedEvent(sender.NavigateUri);
};

renderer.Push(autolink);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,20 @@ protected override void Write(WinUIRenderer renderer, LinkInline link)
{
if (link.FirstChild is LinkInline linkInlineChild && linkInlineChild.IsImage)
{
renderer.Push(new MyHyperlinkButton(link, renderer.Config.BaseUrl));
var myHyperlinkButton = new MyHyperlinkButton(link, renderer.Config.BaseUrl);
myHyperlinkButton.ClickEvent += (sender, e) =>
{
renderer.MarkdownTextBlock.RaiseLinkClickedEvent(((HyperlinkButton)sender).NavigateUri);
};
renderer.Push(myHyperlinkButton);
}
else
{
var hyperlink = new MyHyperlink(link, renderer.Config.BaseUrl);
hyperlink.ClickEvent += (sender, e) =>
{
renderer.MarkdownTextBlock.RaiseLinkClickedEvent(sender.NavigateUri);
};

renderer.Push(hyperlink);
}
Expand Down
4 changes: 3 additions & 1 deletion components/MarkdownTextBlock/src/Renderers/WinUIRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ public MarkdownConfig Config
get => _config;
set => _config = value;
}
public MarkdownTextBlock MarkdownTextBlock { get; }

public WinUIRenderer(MyFlowDocument document, MarkdownConfig config)
public WinUIRenderer(MyFlowDocument document, MarkdownConfig config, MarkdownTextBlock markdownTextBlock)
{
_buffer = new char[1024];
Config = config;
MarkdownTextBlock = markdownTextBlock;
FlowDocument = document;
// set style
_stack.Push(FlowDocument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public TextElement TextElement
public MyBlock(HtmlNode block)
{
_htmlNode = block;
var align = _htmlNode.GetAttributeValue("align", "left");
var align = _htmlNode.GetAttribute("align", "left");
_richTextBlocks = new List<RichTextBlock>();
_paragraph = new Paragraph();
_paragraph.TextAlignment = align switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ internal class MyAutolinkInline : IAddChild

public TextElement TextElement { get; private set; }

public event TypedEventHandler<Hyperlink, HyperlinkClickEventArgs>? ClickEvent
{
add
{
((Hyperlink)TextElement).Click += value;
}
remove
{
((Hyperlink)TextElement).Click -= value;
}
}

public MyAutolinkInline(AutolinkInline autoLinkInline)
{
_autoLinkInline = autoLinkInline;
Expand All @@ -21,7 +33,6 @@ public MyAutolinkInline(AutolinkInline autoLinkInline)
};
}


public void AddChild(IAddChild child)
{
try
Expand Down
19 changes: 11 additions & 8 deletions components/MarkdownTextBlock/src/TextElements/MyCodeBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public MyCodeBlock(CodeBlock codeBlock, MarkdownConfig config)
border.CornerRadius = _config.Themes.CornerRadius;
var richTextBlock = new RichTextBlock();

#if false
if (codeBlock is FencedCodeBlock fencedCodeBlock)
{
//#if !WINAPPSDK
Expand Down Expand Up @@ -68,17 +69,19 @@ public MyCodeBlock(CodeBlock codeBlock, MarkdownConfig config)
}
else
{
foreach (var line in codeBlock.Lines.Lines)
#endif

foreach (var line in codeBlock.Lines.Lines)
{
var paragraph = new Paragraph();
var lineString = line.ToString();
if (!String.IsNullOrWhiteSpace(lineString))
{
var paragraph = new Paragraph();
var lineString = line.ToString();
if (!String.IsNullOrWhiteSpace(lineString))
{
paragraph.Inlines.Add(new Run() { Text = lineString });
}
richTextBlock.Blocks.Add(paragraph);
paragraph.Inlines.Add(new Run() { Text = lineString });
}
richTextBlock.Blocks.Add(paragraph);
}

border.Child = richTextBlock;
container.Child = border;
_paragraph.Inlines.Add(container);
Expand Down
Loading

0 comments on commit 1f3d7b4

Please sign in to comment.