This repository was archived by the owner on Feb 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathelement.go
More file actions
executable file
·121 lines (93 loc) · 2.4 KB
/
Copy pathelement.go
File metadata and controls
executable file
·121 lines (93 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package gas
import (
"fmt"
"strings"
"github.com/frankenbeanies/uuid4"
)
// Element stucture for basic strucutre nodes (html elements, etc)
type Element struct {
UUID string
IsPointer bool // by default element isn't pointer
Tag string
Attrs func() Map
RAttrs Map // last rendered Attrs
Handlers map[string]Handler // events handlers: onClick, onHover
HTML func() string
RHTML string
Childes, OldChildes []interface{}
Parent *Element // if element is root, parent is nil
RefName string
Component *Component // can be nil
RC *RenderCore
}
// NewElement create new element
func NewElement(el *Element, childes ...interface{}) *Element {
if el.Tag == "" {
el.Tag = "div"
} else {
el.Tag = strings.ToLower(el.Tag)
}
if len(el.UUID) == 0 {
el.UUID = uuid4.New().String()
}
el.Childes = UnSpliceBody(childes)
return el
}
// Bind dynamic component attribute
type Bind func() string
// HTMLDirective struct for HTML Directive - storing render function and pre rendered render
type HTMLDirective struct {
Render func() string
Rendered string // here storing rendered html for Update functions
}
// Handler function for triggering event
type Handler func(Event)
// Object wrapper for js.Value
type Object interface {
String() string
Int() int
Float() float64
Get(string) Object
Set(string, interface{})
GetString(string) string
GetBool(string) bool
GetInt(string) int
Call(string, ...interface{}) Object
Raw() interface{}
}
// Event wrapper for dom.Event
type Event interface {
Object
Value() string
ValueInt() int
ValueBool() bool
}
// BEElement return element in backend implementation
func (e *Element) BEElement() interface{} {
_el := e.RC.BE.GetElement(e)
if _el == nil {
e.RC.BE.ConsoleError(fmt.Sprintf("component Element: %s, returning nil", e.UUID))
return nil
}
return _el
}
// GetElementUnsafely return *dom.Element by component without warning
func (e *Element) GetElementUnsafely() interface{} {
return e.RC.BE.GetElement(e)
}
// ParentComponent return first component in element parents tree
func (e *Element) ParentComponent() *Element {
parent := e.Parent
if parent.Parent == nil || parent.Component != nil {
return parent
}
return parent.ParentComponent()
}
// ElementToComponent create static component from element
func ElementToComponent(el *Element) *Component {
return &Component{
Root: &EmptyRoot{
Element: el,
},
}
}