dom

package
v0.0.2-0...-a5fe278 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package dom contains bits for making dealing with the DOM easier.

Index

Constants

View Source
const (
	// Ace modes.
	AceGoMode   = "ace/mode/golang"
	AceJSONMode = "ace/mode/json"

	// Ace themes.
	AceChromeTheme              = "ace/theme/chrome"
	AceTomorrowNightBrightTheme = "ace/theme/tomorrow_night_bright"
)

Ace editor modes and themes.

View Source
const (
	SVGNamespaceURI   = "http://www.w3.org/2000/svg"
	XHTMLNamespaceURI = "http://www.w3.org/1999/xhtml"
)

Well-known Namespace URIs.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ace

type Ace struct {
	Object
}

Ace wraps an "ace" object (usually global).

func GlobalAce

func GlobalAce() *Ace

GlobalAce returns the global "ace" object.

func (Ace) Edit

func (ace Ace) Edit(id string) *AceEditor

Edit attaches an Ace edit session to an element and returns the editor object, or nil (if ace.edit returns null).

type AceEditor

type AceEditor struct {
	Object
}

AceEditor is an Ace editor.

func (*AceEditor) Session

func (e *AceEditor) Session() *AceSession

Session returns a session for this editor.

func (*AceEditor) SetTheme

func (e *AceEditor) SetTheme(theme string) *AceEditor

SetTheme sets the editor theme.

type AceSession

type AceSession struct {
	Object
}

AceSession is an Ace editor session.

func (*AceSession) On

func (s *AceSession) On(event string, h func(e Object)) *AceSession

On adds a handler (on change, etc).

func (*AceSession) SetMode

func (s *AceSession) SetMode(mode string) *AceSession

SetMode sets the session mode (language).

func (*AceSession) SetUseSoftTabs

func (s *AceSession) SetUseSoftTabs(b bool) *AceSession

SetUseSoftTabs changes the soft-tabs mode of the session.

func (*AceSession) SetValue

func (s *AceSession) SetValue(contents string)

SetValue puts new contents in the session.

func (*AceSession) Value

func (s *AceSession) Value() string

Value returns the session's current contents.

type ClassList

type ClassList interface {
	Add(classes ...string)
	Remove(classes ...string)
	Toggle(class string)
	Contains(class string) bool
	Replace(oldClass, newClass string)
}

ClassList abstracts the DOMTokenList returned by element.classList.

type Document

type Document interface {
	Element

	ElementByID(string) Element
	MakeTextNode(string) Element
	MakeSVGElement(string) Element
}

Document describes some things the JS document global can do.

func CurrentDocument

func CurrentDocument() Document

CurrentDocument returns the global document object or nil if it does not exist.

type Element

type Element interface {
	Object

	// ID returns the element ID.
	ID() string

	// GetAttribute gets the JS getAttribute method, returning the requested attribute.
	GetAttribute(string) Object

	// SetAttribute calls the JS setAttribute method, returning the element for chaining.
	SetAttribute(string, interface{}) Element

	// RemoveAttribute calls the JS removeAttribute method, returning the element for chaining.
	RemoveAttribute(string) Element

	// AddChildren calls the JS method appendChild for each element, returning the element for chaining.
	AddChildren(...Element) Element

	// RemoveChildren calls the JS method removeChild for each element, returning the element for chaining.
	RemoveChildren(...Element) Element

	// AddEventListener calls the JS method addEventListener, returning the element for chaining.
	AddEventListener(string, func(Object)) Element

	// Show sets the display attribute of the style to "", returning the element for chaining.
	Show() Element

	// Hide sets the display attribute of the style to "none", returning the element for chaining.
	Hide() Element

	// Display sets the display attribute of the style to the given value, returning the element for chaining.
	Display(string) Element

	// Parent returns the parent element.
	Parent() Element

	// ClassList returns the classList.
	ClassList() ClassList
}

Element represents a DOM element.

func WrapElement

func WrapElement(o Object) Element

WrapElement turns a Object into an Element, or returns nil if o is nil.

type FakeClassList

type FakeClassList map[string]struct{}

FakeClassList implements a virtual classList (DOMTokenList). Unlike a real DOMTokenList, it doesn't preserve order.

func (FakeClassList) Add

func (c FakeClassList) Add(classes ...string)

Add adds a class to the classlist.

func (FakeClassList) Contains

func (c FakeClassList) Contains(class string) bool

Contains tests if the class is present.

func (FakeClassList) Remove

func (c FakeClassList) Remove(classes ...string)

Remove removes a class from the classlist.

func (FakeClassList) Replace

func (c FakeClassList) Replace(oldClass, newClass string)

Replace swaps an old class for a new one.

func (FakeClassList) String

func (c FakeClassList) String() string

func (FakeClassList) Toggle

func (c FakeClassList) Toggle(class string)

Toggle adds if the class is not present, and removes if it is.

type FakeDocument

type FakeDocument struct {
	FakeElement
}

FakeDocument implements a fake Document.

func MakeFakeDocument

func MakeFakeDocument() *FakeDocument

MakeFakeDocument makes a fake document.

func (*FakeDocument) ElementByID

func (d *FakeDocument) ElementByID(id string) Element

ElementByID searches the fake document for a matching element.

func (*FakeDocument) MakeSVGElement

func (d *FakeDocument) MakeSVGElement(class string) Element

MakeSVGElement makes an SVG element.

func (*FakeDocument) MakeTextNode

func (d *FakeDocument) MakeTextNode(text string) Element

MakeTextNode makes something that looks like a text node.

type FakeElement

type FakeElement struct {
	FakeObject
	Class          string
	NamespaceURI   string
	Attributes     map[string]interface{}
	Children       []*FakeElement
	EventListeners map[string][]func(Object)
	Classes        FakeClassList
	// contains filtered or unexported fields
}

FakeElement implements a virtual DOM element.

func MakeFakeElement

func MakeFakeElement(class, nsuri string) *FakeElement

MakeFakeElement makes a fake element.

func (*FakeElement) AddChildren

func (e *FakeElement) AddChildren(children ...Element) Element

AddChildren adds child elements (*FakeElement only).

func (*FakeElement) AddEventListener

func (e *FakeElement) AddEventListener(event string, handler func(Object)) Element

AddEventListener adds an event listener.

func (*FakeElement) ClassList

func (e *FakeElement) ClassList() ClassList

ClassList returns the list of classes.

func (*FakeElement) Display

func (e *FakeElement) Display(style string) Element

Display sets the display attribute to whatever.

func (*FakeElement) GetAttribute

func (e *FakeElement) GetAttribute(attr string) Object

GetAttribute gets an attribute value.

func (*FakeElement) Hide

func (e *FakeElement) Hide() Element

Hide sets the display attribute to "none".

func (*FakeElement) ID

func (e *FakeElement) ID() string

ID returns e.Get("id").String() (so, set the embedded FakeObject's id property).

func (*FakeElement) Parent

func (e *FakeElement) Parent() Element

Parent returns the parent element.

func (*FakeElement) RemoveAttribute

func (e *FakeElement) RemoveAttribute(attr string) Element

RemoveAttribute removes an attribute.

func (*FakeElement) RemoveChildren

func (e *FakeElement) RemoveChildren(children ...Element) Element

RemoveChildren removes child elements. It does it with the straightforward, naïve O(len(e.Children) * len(children)) method.

func (*FakeElement) SetAttribute

func (e *FakeElement) SetAttribute(attr string, value interface{}) Element

SetAttribute sets an attribute.

func (*FakeElement) Show

func (e *FakeElement) Show() Element

Show removes the display attribute.

type FakeObject

type FakeObject struct {
	Value      interface{}
	Properties map[string]interface{}
	Methods    map[string]MethodFunc
}

FakeObject implements a fake Object that sort of works like *js.Object.

func MakeFakeObject

func MakeFakeObject(value interface{}) *FakeObject

MakeFakeObject makes a FakeObject.

func (*FakeObject) Bool

func (o *FakeObject) Bool() bool

Bool returns o.Value asserted as a bool.

func (*FakeObject) Call

func (o *FakeObject) Call(method string, args ...interface{}) Object

Call calls a method. In the case of fakes, this returns a pointer that gets used as a key in ObjectsToValues.

func (*FakeObject) Delete

func (o *FakeObject) Delete(key string)

Delete deletes the property with the given key.

func (*FakeObject) Float

func (o *FakeObject) Float() float64

Float returns o.Value asserted as a float64.

func (*FakeObject) Get

func (o *FakeObject) Get(key string) Object

Get gets a "property value". In the case of fakes, this is a pointer that gets used as a key in ObjectsToValues.

func (*FakeObject) Index

func (o *FakeObject) Index(i int) Object

Index returns the element at index i of o.Value.

func (*FakeObject) Int

func (o *FakeObject) Int() int

Int returns o.Value asserted as an int.

func (*FakeObject) Int64

func (o *FakeObject) Int64() int64

Int64 returns o.Value asserted as an int64.

func (*FakeObject) Interface

func (o *FakeObject) Interface() interface{}

Interface returns o.Value.

func (*FakeObject) Invoke

func (o *FakeObject) Invoke(args ...interface{}) Object

Invoke calls the function in o.Value.

func (*FakeObject) Length

func (o *FakeObject) Length() int

Length returns the length of o.Value.

func (*FakeObject) New

func (o *FakeObject) New(args ...interface{}) Object

New calls the function in o.Value.

func (*FakeObject) Set

func (o *FakeObject) Set(key string, value interface{})

Set sets a property value.

func (*FakeObject) SetIndex

func (o *FakeObject) SetIndex(i int, value interface{})

SetIndex sets the value at index i of o.Value to value.

func (*FakeObject) String

func (o *FakeObject) String() string

String returns o.Value asserted as a string.

func (*FakeObject) Uint64

func (o *FakeObject) Uint64() uint64

Uint64 returns o.Value asserted as a uint64.

func (*FakeObject) Unsafe

func (o *FakeObject) Unsafe() uintptr

Unsafe returns o.Value asserted as a uintptr.

type Hterm

type Hterm struct {
	*js.Object
}

Hterm represents a global hterm object.

func GlobalHterm

func GlobalHterm() Hterm

GlobalHterm gets the global hterm object.

func (Hterm) NewTerminal

func (h Hterm) NewTerminal(profile string) Terminal

NewTerminal creates a new Terminal with the given profile.

type IO

type IO struct {
	*js.Object
}

IO represents a hterm IO object.

func (IO) OnVTKeystroke

func (io IO) OnVTKeystroke(h func(string))

OnVTKeystroke registers a keystroke handler.

func (IO) Pop

func (io IO) Pop()

Pop unpushes this IO.

func (IO) Print

func (io IO) Print(s string)

Print prints some text to the terminal.

func (IO) Push

func (io IO) Push() IO

Push pushes an IO, something something nested IO sessions, see hterm documentation.

func (IO) SendString

func (io IO) SendString(h func(string))

SendString registers a handler for sendString.

type MethodFunc

type MethodFunc func(...interface{}) interface{}

MethodFunc is what a typical method looks like... sort of.

type Object

type Object interface {
	Get(string) Object
	Set(string, interface{})
	Delete(string)
	Length() int
	Index(int) Object
	SetIndex(int, interface{})
	Call(string, ...interface{}) Object
	Invoke(...interface{}) Object
	New(...interface{}) Object
	Bool() bool
	String() string
	Int() int
	Int64() int64
	Uint64() uint64
	Float() float64
	Interface() interface{}
	Unsafe() uintptr
}

Object is some stuff JS objects can do. This is essentially an extracted interface of *js.Object.

func Global

func Global(name string) Object

Global returns a name from the global namespace.

func WrapObject

func WrapObject(o *js.Object) Object

WrapObject returns a wrapper for *js.Object that conforms to Object.

type Terminal

type Terminal struct {
	*js.Object
}

Terminal represents a Hterm Terminal.

func (Terminal) ClearHome

func (t Terminal) ClearHome()

ClearHome clears the terminal and returns the cursor to 0,0.

func (Terminal) Decorate

func (t Terminal) Decorate(e Element)

Decorate decorates a sacrificial DOM element with the terminal.

func (Terminal) IO

func (t Terminal) IO() IO

IO returns a terminal's IO.

func (Terminal) InstallKeyboard

func (t Terminal) InstallKeyboard()

InstallKeyboard installs the hterm keyboard handler.

func (Terminal) OnTerminalReady

func (t Terminal) OnTerminalReady(cb func())

OnTerminalReady registers a callback for when the terminal is ready.

func (Terminal) SetAutoCR

func (t Terminal) SetAutoCR(enable bool)

SetAutoCR sets the auto-carriage return feature.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL