diff --git a/Ooui/Button.cs b/Ooui/Button.cs index 5f09685..b01a2f0 100644 --- a/Ooui/Button.cs +++ b/Ooui/Button.cs @@ -4,5 +4,16 @@ namespace Ooui { public class Button : FormControl { + string typ = "submit"; + public string Type { + get => typ; + set => SetProperty (ref typ, value, "type"); + } + + string val = ""; + public string Value { + get => val; + set => SetProperty (ref val, value, "value"); + } } } diff --git a/Ooui/Client.js b/Ooui/Client.js index d14abc9..fadedcc 100644 --- a/Ooui/Client.js +++ b/Ooui/Client.js @@ -24,25 +24,25 @@ function msgCreate (m) { if (tagName !== "text") node.id = id; nodes[id] = node; - console.log ("Created Node", node); + console.log ("Created node", node); } function msgSet (m) { const id = m.id; const node = getNode (id); if (!node) { - console.error ("Unknown Node Id", m); + console.error ("Unknown node id", m); return; } node[m.k] = m.v; - console.log ("Set Property", node, m.k, m.v); + console.log ("Set property", node, m.k, m.v); } function msgCall (m) { const id = m.id; const node = getNode (id); if (!node) { - console.error ("Unknown Node Id", m); + console.error ("Unknown node id", m); return; } const f = node[m.k]; diff --git a/Ooui/Div.cs b/Ooui/Div.cs new file mode 100644 index 0000000..5302215 --- /dev/null +++ b/Ooui/Div.cs @@ -0,0 +1,8 @@ +using System; + +namespace Ooui +{ + public class Div : Element + { + } +} diff --git a/Ooui/Element.cs b/Ooui/Element.cs index 27fd9cb..0f53ec2 100644 --- a/Ooui/Element.cs +++ b/Ooui/Element.cs @@ -7,7 +7,19 @@ namespace Ooui string className = ""; public string ClassName { get => className; - set => SetProperty (ref className, "className", value); + set => SetProperty (ref className, value, "className"); + } + + string title = ""; + public string Title { + get => title; + set => SetProperty (ref title, value, "title"); + } + + bool hidden = false; + public bool IsHidden { + get => hidden; + set => SetProperty (ref hidden, value, "hidden"); } } } diff --git a/Ooui/Message.cs b/Ooui/Message.cs index e60b116..1b037fb 100644 --- a/Ooui/Message.cs +++ b/Ooui/Message.cs @@ -19,8 +19,28 @@ namespace Ooui [JsonProperty("k")] public string Key = ""; + object v = null; [JsonProperty("v")] - public object Value = ""; + public object Value { + get => v; + set => v = FixupValue (value); + } + + static object FixupValue (object v) + { + if (v is Array a) { + var na = new object[a.Length]; + for (var i = 0; i < a.Length; i++) { + na[i] = FixupValue (a.GetValue (i)); + } + return na; + } + else if (v is Node n) { + return "\u2999" + n.Id; + } + return v; + } + static long idCounter = 0; static long GenerateId () diff --git a/Ooui/Node.cs b/Ooui/Node.cs index 252e048..82e78fb 100644 --- a/Ooui/Node.cs +++ b/Ooui/Node.cs @@ -21,6 +21,13 @@ namespace Ooui .Concat (from c in children from m in c.AllMessages select m) .OrderBy (x => x.Id); + public string TextContent { + get { return String.Join ("", from c in children select c.TextContent); } + set { + ReplaceAll (new Text (value ?? "")); + } + } + public Node () { Mapping = Mapping.Get (GetType ()); @@ -61,6 +68,14 @@ namespace Ooui return child; } + protected void ReplaceAll (Node newNode) + { + var toRemove = new List (children); + foreach (var c in toRemove) + RemoveChild (c); + InsertBefore (newNode, null); + } + protected void Log (Message message) { messages.Add (message); @@ -100,6 +115,7 @@ namespace Ooui MessageType = MessageType.Call, TargetId = Id, Key = methodName, + Value = args, }); } diff --git a/Ooui/Server.cs b/Ooui/Server.cs index 1fed585..e374e5b 100644 --- a/Ooui/Server.cs +++ b/Ooui/Server.cs @@ -201,7 +201,7 @@ namespace Ooui TargetId = "document.body", MessageType = MessageType.Call, Key = "appendChild", - Value = new[] { "\u2999" + element.Id }, + Value = new[] { element }, }, token); // diff --git a/Ooui/Text.cs b/Ooui/Text.cs new file mode 100644 index 0000000..896f3b0 --- /dev/null +++ b/Ooui/Text.cs @@ -0,0 +1,22 @@ +using System; + +namespace Ooui +{ + public class Text : Node + { + string data = ""; + public string Data { + get => data; + set => SetProperty (ref data, value ?? "", "data"); + } + + public Text () + { + } + + public Text (string text) + { + Data = text; + } + } +} diff --git a/Samples/Program.cs b/Samples/Program.cs index cc0d114..a0cb439 100644 --- a/Samples/Program.cs +++ b/Samples/Program.cs @@ -8,8 +8,12 @@ namespace Samples static int Main (string[] args) { var server = new Server (); - var button = new Button(); - button.Name = "TestButton"; + var button = new Button() { + Title = "The best button", + Name = "TestButton", + Value = "Click Me", + TextContent = "I am a button, click me!" + }; server.Publish ("/button", button); server.RunAsync ("http://*:8080/").Wait (); return 0;