Skip to content

Commit 31e070f

Browse files
authored
ReadOnly (StefH#6)
* . * readonly * v * ci * ignore
1 parent 964b0ab commit 31e070f

File tree

15 files changed

+65
-4066
lines changed

15 files changed

+65
-4066
lines changed

.github/workflows/ci.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
name: DeployToGitHubPages
1+
name: CI
22
env:
33
PUBLISH_DIR: examples/jsMind.WASM.App/bin/Release/net5.0/publish/wwwroot
4-
PUBLISH_XXX: src/CoronaDashboard/bin/Release/net5.0/publish/wwwroot
54

65
on:
76
push:

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: DeployToGitHubPages
1+
name: 'Build and Deploy to GitHubPages'
22
env:
33
PUBLISH_DIR: examples/jsMind.WASM.App/bin/Release/net5.0/publish/wwwroot
44

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -353,5 +353,5 @@ MigrationBackup/
353353
# Custom
354354
/docs-temp
355355

356-
#src/jsMind.Blazor/wwwroot/*.js
357-
#src/jsMind.Blazor/wwwroot/*.css
356+
src/jsMind.Blazor/wwwroot/*.js
357+
src/jsMind.Blazor/wwwroot/*.css

examples/jsMind.WASM.App/Pages/Index.razor

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<h1>jsMind Demo</h1>
44

5-
<pre>SelectedNodeId = @_selectedNodeId</pre>
5+
<pre>SelectedNodeId = @_selectedNodeId</pre>
66
<pre>SelectedNodeIds = @string.Join(",", _selectedNodeIds)</pre>
77

88
<div>
@@ -19,6 +19,8 @@
1919
<button class="btn btn-primary oi oi-collapse-down" @onclick="CollapseTree"></button>
2020
<button class="btn btn-primary oi oi-check" @onclick="SelectTreeNode"></button>
2121
<button class="btn btn-primary oi oi-action-undo" @onclick="ClearSelect"></button>
22+
<button class="btn btn-primary oi oi-envelope-open" @onclick="MindMapClickable"></button>
23+
<button class="btn btn-primary oi oi-envelope-closed" @onclick="MindMapNotClickable"></button>
2224
</div>
2325
<hr />
2426
<div>
@@ -237,6 +239,16 @@
237239
await _myTreeNodeContainer.ClearSelect();
238240
}
239241

242+
async Task MindMapClickable()
243+
{
244+
await _myTreeNodeContainer.SetReadonly(false);
245+
}
246+
247+
async Task MindMapNotClickable()
248+
{
249+
await _myTreeNodeContainer.SetReadonly(true);
250+
}
251+
240252
async Task CollapseTree()
241253
{
242254
await _myTreeNodeContainer.Collapse();

examples/jsMind.WASM.App/wwwroot/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
<link type="text/css" rel="stylesheet" href="_content/jsMind.Blazor/jsmind.min.css" />
1717

18+
<!-- testing ... -->
1819
<script type="text/javascript" src="_content/jsMind.Blazor/jsmind.min.js"></script>
1920
<script type="text/javascript" src="_content/jsMind.Blazor/jsmind-interop.min.js"></script>
2021
</head>

src/jsMind.Blazor/Components/MindMapContainer.Interop.cs

+17
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ public ValueTask Collapse()
9292
return Runtime.InvokeVoidAsync("MindMap.collapse", _containerId);
9393
}
9494

95+
public async ValueTask SetReadonly(bool @readonly)
96+
{
97+
Options.Readonly = @readonly;
98+
99+
await Runtime.InvokeVoidAsync("MindMap.setReadOnly", _containerId, @readonly);
100+
101+
if (@readonly)
102+
{
103+
await SetEditable(false);
104+
}
105+
}
106+
107+
public bool IsReadonly()
108+
{
109+
return Options.Readonly;
110+
}
111+
95112
private ValueTask DisposeMindMap()
96113
{
97114
return Runtime.InvokeVoidAsync("MindMap.destroy", _containerId);

src/jsMind.Blazor/Components/MindMapContainer.cs

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
4242
builder.OpenElement(0, "div");
4343
builder.AddAttribute(1, "id", _containerId);
4444
builder.AddMultipleAttributes(2, AdditionalAttributes);
45+
46+
if (true)
47+
{
48+
builder.AddAttribute(3, "pointer-events", "none");
49+
}
50+
4551
builder.CloseElement();
4652
}
4753

src/jsMind.Blazor/Models/MindMapOptions.cs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public class MindMapOptions
66
{
77
public bool Editable { get; set; }
88

9+
public bool Readonly { get; set; }
10+
911
public bool MultiSelect { get; set; }
1012

1113
public string Theme { get; set; } = MindMapThemes.Primary;

src/jsMind.Blazor/Scripts/jsmind-interop.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ MindMap.show = function (dotnetReference, containerId, mindMapOptions, mindMapDa
2424
}
2525

2626
const mm = window.jsMind.show(options, mind);
27+
28+
// ReadOnly
29+
setReadOnly(mm, mindMapOptions.readOnly);
30+
31+
// MultiSelect
2732
mm["multiSelect"] = mindMapOptions.multiSelect;
2833

2934
const eventHandler = function (type, data) {
@@ -52,14 +57,18 @@ MindMap.show = function (dotnetReference, containerId, mindMapOptions, mindMapDa
5257
mm.selectedNodes = [];
5358

5459
const mousedownHandleMultiSelect = function (e) {
60+
if (!mm.options.default_event_handle.enable_mousedown_handle) {
61+
return;
62+
}
63+
5564
e.preventDefault();
5665

5766
const element = e.target || event.srcElement;
5867
const id = this.view.get_binded_nodeid(element);
5968
if (id && element.tagName.toLowerCase() === "jmnode") {
6069
const node = mm.get_node(id);
6170

62-
var selectedNodeId;
71+
let selectedNodeId;
6372

6473
// Check if already selected
6574
const index = mm.selectedNodes.indexOf(id);
@@ -175,6 +184,10 @@ MindMap.isEditable = function (containerId) {
175184
return instances[containerId].get_editable();
176185
}
177186

187+
MindMap.setReadOnly = function (containerId, isReadOnly) {
188+
return setReadOnly(instances[containerId], isReadOnly);
189+
}
190+
178191
updateSelectedClass = function (node, set) {
179192
if (set && !(/\s*selected\b/i).test(node._data.view.element.className)) {
180193
node._data.view.element.className += " selected";
@@ -194,4 +207,12 @@ mapNode = function (node) {
194207
data: node.data,
195208
parentId: node.parentId
196209
};
210+
}
211+
212+
setReadOnly = function (mm, isReadOnly) {
213+
mm.options.default_event_handle = {
214+
enable_mousedown_handle: !isReadOnly,
215+
enable_click_handle: !isReadOnly,
216+
enable_dblclick_handle: !isReadOnly
217+
};
197218
}

src/jsMind.Blazor/wwwroot/jsmind-interop.js

-197
This file was deleted.

src/jsMind.Blazor/wwwroot/jsmind-interop.min.js

-1
This file was deleted.

0 commit comments

Comments
 (0)