florian03-1 / blazorsvgeditor Goto Github PK
View Code? Open in Web Editor NEWBlazor Svg Editor
Home Page: https://florian03-1.github.io/BlazorSvgEditor/
License: MIT License
Blazor Svg Editor
Home Page: https://florian03-1.github.io/BlazorSvgEditor/
License: MIT License
I'm current search solution to export the configuration of shapes in order to inject the configuration into any data source ( database / form /etc.. )
if you have a simple solution I'll take it!
I write following line do add this feature.
SvgEditor.PublicMethods.cs
public async Task DuplicateSelectedShape()
{
if (SelectedShape != null)
{
int deletedShapeId = SelectedShape.CustomId;
Shape ? shape = Shapes.FirstOrDefault(s => s.CustomId == deletedShapeId);
if (shape != null)
{
var newShape = shape.Clone();
if (Shapes.Count > 0) newShape.CustomId = Math.Min(Enumerable.Min<Shape>(Shapes, x => x.CustomId) - 1, newShape.CustomId);
Shapes.Add(newShape);
await OnShapeChanged.InvokeAsync(ShapeChangedEventArgs.ShapeAdded(newShape));
}
}
else
{
if (ShowDiagnosticInformation) Console.WriteLine("No shape selected - so nothing to duplicate");
}
}
preview.razor
<div class="inline-flex mt-2" role="group">
<button @onclick="DuplicateShape" type="button" class="shadow-sm flex-grow focus:outline-none text-white bg-yellow-400 hover:bg-yellow-500 focus:ring-4 focus:ring-yellow-300 font-medium rounded-lg text-sm px-5 py-2 mr-2">Duplicate Shape</button>
<button @onclick="DeleteShape" type="button" class="shadow-sm flex-grow focus:outline-none text-white bg-red-700 hover:bg-red-800 focus:ring-4 focus:ring-red-300 font-medium rounded-lg text-sm px-5 py-2">Delete Shape</button>
</div>
preview.razor.cs
private void DuplicateShape()
{
svgEditor?.DuplicateSelectedShape();
}
shape.cs
public Shape Clone()
{
Shape temp = (Shape)this.MemberwiseClone();
return temp;
}
Why use int
for shape identification, when Guid
is simpler?
Possibility to receive the SelectedShapeIdChanged event when the readonly property is true.
Or have an event that indicates that a shape has been clicked regardless of the value of the ReadOnly property
This is useful for once the shapes have been defined in an editor, to show a viewer to the user so that they can select one of the shapes.
Modifying the SelectAsync method of the ShapeEditor class as follows also raises the event when the property ReadOnly=true
protected async Task SelectAsync(PointerEventArgs eventArgs)
{
if(eventArgs.PointerType == "touch") return; //Touch events are handled separately
if (SvgElement.SvgEditor.EditMode == EditMode.Add) return;
if (SvgElement.SvgEditor.ReadOnly)
{
await SvgElement.SvgEditor.SelectedShapeIdChanged.InvokeAsync(SvgElement.CustomId);
return;
}
SvgElement.SelectShape();
SvgElement.SvgEditor.SelectShape(SvgElement, eventArgs);
}
New shape should be selected...
As you can see in the demo site, the image is not automatically centred in first render. With "centred" I mean is just like what "Reset Transformation" button does.
I tried to use the method ResetTransform() in OnAfterRenderAsync, after the ReloadImage(), and it does not do the same transformation as if i click the "Reset Transformation" button.
Hello!
I am wondering if it's possible somehow to get the position and size of each shape in the SvgEditor?
For example X, Y, Width and Height of a Rectangle.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.