Add TextContent

This commit is contained in:
Frank A. Krueger 2017-06-13 00:51:24 -07:00
parent ad3035140e
commit ad637bae92
9 changed files with 102 additions and 9 deletions

View File

@ -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");
}
}
}

View File

@ -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];

8
Ooui/Div.cs Normal file
View File

@ -0,0 +1,8 @@
using System;
namespace Ooui
{
public class Div : Element
{
}
}

View File

@ -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");
}
}
}

View File

@ -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 ()

View File

@ -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<Node> (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,
});
}

View File

@ -201,7 +201,7 @@ namespace Ooui
TargetId = "document.body",
MessageType = MessageType.Call,
Key = "appendChild",
Value = new[] { "\u2999" + element.Id },
Value = new[] { element },
}, token);
//

22
Ooui/Text.cs Normal file
View File

@ -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;
}
}
}

View File

@ -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;