blockly

package
v0.0.0-...-56ca850 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package blockly wraps google's blocky javascript api for use with gopherjs. see also: https://developers.google.com/blockly https://github.com/gopherjs/gopherjs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	*js.Object        // Blockly.Block
	Id         string `js:"id"`
	Type       string `js:"type"`

	Tooltip      string `js:"tooltip"`
	ContextMenu  bool   `js:"contextMenu"`
	Comment      string `js:"comment"`
	IsInFlyout   bool   `js:"isInFlyout"`
	IsInMutator  bool   `js:"isInMutator"`
	Rtl          bool   `js:"RTL"`
	InputsInline bool   `js:"inputsInline"`
	// contains filtered or unexported fields
}

func (*Block) AppendDummyInput

func (b *Block) AppendDummyInput(name string) (ret block.Input)

AppendDummyInput for standalone fields.

func (*Block) AppendStatementInput

func (b *Block) AppendStatementInput(name string) (ret block.Input)

AppendStatementInput for blocks with previous statements. statements give a c-shape; they are slices

func (*Block) AppendValueInput

func (b *Block) AppendValueInput(name string) (ret block.Input)

AppendValueInput for blocks with output.

func (*Block) BlockId

func (b *Block) BlockId() string

func (*Block) BlockType

func (b *Block) BlockType() string

func (*Block) BlockWorkspace

func (b *Block) BlockWorkspace() block.Workspace

func (*Block) Dispose

func (b *Block) Dispose()

Dispose removes the block from the workspace. To prevent child blocks from *also* being disposed, Unplug() the block first.

func (*Block) GetColour

func (b *Block) GetColour() string

GetColour of the block as an #RRGGBB string.

func (*Block) GetField

func (b *Block) GetField(name string) (ret *Field)

func (b* Block)setOnChange (onchangeFn) { b.Call("setOnChange") }

func (*Block) GetFlag

func (b *Block) GetFlag(flag block.Flag) bool

func (*Block) GetInputsInline

func (b *Block) GetInputsInline() bool

func (*Block) GetParent

func (b *Block) GetParent() (ret *Block)

func (b* Block)lastConnectionInStack () { b.Call("lastConnectionInStack") }

func (*Block) GetRootBlock

func (b *Block) GetRootBlock() (ret *Block)

func (*Block) HasWorkspace

func (b *Block) HasWorkspace() bool

func (*Block) InitSvg

func (b *Block) InitSvg()

feels like this should have been asynchronous, hidden so that its called after initialiation automatically rather than the caller/creator deciding when its a good time. [ it gets littered after NewBlock() and is illegal in "headless" builds ]

func (*Block) Input

func (b *Block) Input(i int) block.Input

Inputs are zeroIndexed

func (*Block) InputByName

func (b *Block) InputByName(str string) (retInput block.Input, retIndex int)

func (*Block) Interpolate

func (b *Block) Interpolate(msg string, args []block.Dict)

func (b* Block)mixin (mixinObj, optDisableCheck) { b.Call("mixin") }

func (*Block) JsonInit

func (b *Block) JsonInit(opt block.Dict)

func (*Block) NextConnection

func (b *Block) NextConnection() block.Connection

connection to a piece in the following line

func (*Block) NumInputs

func (b *Block) NumInputs() int

func (*Block) OutputConnection

func (b *Block) OutputConnection() block.Connection

left side puzzle connector

func (*Block) PreviousConnection

func (b *Block) PreviousConnection() block.Connection

connection to a piece in the preceeding line

func (*Block) RemoveInput

func (b *Block) RemoveInput(name string)

func (*Block) SetColour

func (b *Block) SetColour(colour string)

func (*Block) SetFlag

func (b *Block) SetFlag(flag block.Flag, state bool)

func (*Block) SetHelpUrl

func (b *Block) SetHelpUrl(url string)

func (b* Block)setConnectionsHidden (hidden) { b.Call("setConnectionsHidden") } func (b* Block)getMatchingConnection (otherBlock, conn) { b.Call("getMatchingConnection") }

func (*Block) SetInput

func (b *Block) SetInput(i int, in block.Input)

func (*Block) SetInputsInline

func (b *Block) SetInputsInline(yes bool) (err error)

func (b* Block)setPreviousStatement (newBoolean, optCheck) { b.Call("setPreviousStatement") } func (b* Block)setNextStatement (newBoolean, optCheck) { b.Call("setNextStatement") } func (b* Block)setOutput (newBoolean, optCheck) { b.Call("setOutput") }

func (*Block) SetTooltip

func (b *Block) SetTooltip(text string)

func (*Block) Unplug

func (b *Block) Unplug(healStack bool)

func (b* Block)initModel () { b.Call("initModel") }

type BlockChange

type BlockChange struct {
	*Event
	// Element events include:
	//   collapsed - .collapsed status changed ( via setCollapsed )
	//   comment - comment text changed ( via setCommentText )
	//   disabled - disabled status changed ( via setDisabled )
	//   field - when checkbox, colour, dropdown, text input, variable, etc. ( via setValue )
	//   inline - inputs inline changed ( via setInputsInline )
	//   mutation - "a procedure definition changes its parameters". or workspaceChanged, -- via Blockly.Procedures.mutatateCallers.
	Element string `js:"element"`
	// Name of element affected
	Name     string     `js:"name"`
	OldValue *js.Object `js:"oldValue"`
	NewValue *js.Object `js:"newValue"`
}

BlockChange -- when the status of a block has changed. ( note, changes to inputs are reported by BlockMove. )

type BlockCreate

type BlockCreate struct {
	*Event
	// xml	*js.Object	An XML tree defining the new block and any connected child blocks.
	Ids *js.Object `js:"ids"` // 	An array containing the UUIDs of the new block and any connected child blocks.
}

triggered after the block has been added to the workspace; the block object can be found via the event's blockId

type BlockDelete

type BlockDelete struct {
	*Event
	// oldXml	*js.Object	An XML tree defining the deleted block and any connected child blocks.
	Ids *js.Object `js:"ids"` // An array containing the UUIDs of the deleted block and any connected child blocks.
}

type BlockMove

type BlockMove struct {
	*Event
}

BlockMove -- event when a block has been dragged/dropped into a new slot. for why this uses methods instead of properties see https://github.com/gopherjs/gopherjs/issues/617

func (*BlockMove) NextInputName

func (evt *BlockMove) NextInputName() (ret string)

NextInputName - Input in new parent ( if any ). Empty if it's the parent's next block.

func (*BlockMove) NextParentId

func (evt *BlockMove) NextParentId() (ret string)

NextParentId - UUID of new parent block. Empty if it is a top level block.

func (*BlockMove) PrevInputName

func (evt *BlockMove) PrevInputName() (ret string)

PrevInputName - Input in old parent ( if any ). Empty if it's the parent's next block.

func (*BlockMove) PrevParentId

func (evt *BlockMove) PrevParentId() (ret string)

PrevParentId - UUID of old parent block. Empty if it was a top level block.

type Blockly

type Blockly struct {
	*js.Object
	// contains filtered or unexported fields
}

type Callback

type Callback func(*js.Object, []*js.Object) (ret interface{})

type CommentChange

type CommentChange struct {
	*Event
}

type CommentCreate

type CommentCreate struct {
	*Event
}

type CommentDelete

type CommentDelete struct {
	*Event
}

type CommentMove

type CommentMove struct {
	*Event
}

type Connection

type Connection struct {
	*js.Object
	Type InputType `js:"type"`
	// contains filtered or unexported fields
}

Connection *potentially* connects to another block; it's more a "connector" than an "connection".

func (*Connection) Connect

func (c *Connection) Connect(o block.Connection)

func (*Connection) Disconnect

func (c *Connection) Disconnect()

func (*Connection) IsConnected

func (c *Connection) IsConnected() bool

func (*Connection) IsConnectionAllowed

func (c *Connection) IsConnectionAllowed() bool

func (*Connection) IsSuperior

func (c *Connection) IsSuperior() bool

func (*Connection) SourceBlock

func (c *Connection) SourceBlock() (ret block.Shape)

func (*Connection) String

func (c *Connection) String() string

func (*Connection) TargetBlock

func (c *Connection) TargetBlock() (ret block.Shape)

func (*Connection) TargetConnection

func (c *Connection) TargetConnection() block.Connection

type Event

type Event struct {
	*js.Object          // Blockly.Events.Abstract;
	Type        EventId `js:"type"`
	BlockId     string  `js:"blockId"`
	WorkspaceId string  `js:"workspaceId"`
	Group       string  `js:"group"`
	RecordUndo  bool    `js:"recordUndo"`
}

Event -- on the blockly side, events are raised with Blockly.Events.fire. there is no node "hierarchy" -- all listeners get all events.

type EventId

type EventId string

type Extensions

type Extensions struct {
	*js.Object
}

func (*Extensions) Apply

func (x *Extensions) Apply(name string, block *Block, isMutator bool)

func (*Extensions) Register

func (x *Extensions) Register(name string, cb Callback)

func (*Extensions) RegisterMixin

func (x *Extensions) RegisterMixin(name string, mixin Mixin)

func (*Extensions) RegisterMutator

func (x *Extensions) RegisterMutator(
	name string,
	mixin Mixin,
	postFn *js.Object,
	quarks []string,
)

type Field

type Field struct {
	*js.Object
	// contains filtered or unexported fields
}

func (*Field) GetSize

func (f *Field) GetSize() *Size

func (f *Field) setSourceBlock (block) { func (f *Field) init () { func (f *Field) initModel () { func (f *Field) dispose () { func (f *Field) updateEditable () { func (f *Field) isCurrentlyEditable () { func (f *Field) isVisible () { func (f *Field) setVisible (visible) { func (f *Field) setValidator (handler) { func (f *Field) getValidator () { func (f *Field) classValidator (text) { func (f *Field) callValidator (text) { func (f *Field) getSvgRoot () { func (f *Field) updateWidth () {

func (*Field) GetText

func (f *Field) GetText() (ret string)

func (*Field) GetValue

func (f *Field) GetValue() *js.Object

func (f *Field) forceRerender () {

func (*Field) Name

func (f *Field) Name() (ret string)

note: added, optionally, on by appendField; sometimes undefined.

func (*Field) SetText

func (f *Field) SetText(newText string)

func (*Field) SetTooltip

func (f *Field) SetTooltip(newTip string)

in blockly newTip can be an element as well

func (*Field) SetValue

func (f *Field) SetValue(newValue interface{})

in blockly, by default, this routes to setText

type FieldAngle

type FieldAngle float32

type FieldCheckbox

type FieldCheckbox bool

type FieldColour

type FieldColour string //'#rrggbb'

type FieldDropdown

type FieldDropdown []string

options seem to be image or text

type FieldImage

type FieldImage struct {
	Width, Height int
	Src           string
	Alt           string
}

type FieldImageDropdown

type FieldImageDropdown []FieldImage

type FieldLabel

type FieldLabel struct {
	*Field
	// contains filtered or unexported fields
}

type FieldNumber

type FieldNumber float32

type FieldText

type FieldText string // field_input, FieldTextInput; pre-existing validators inclde numberValidator, nongenativeIntegerValidator

type FieldVariable

type FieldVariable string

type Fields

type Fields struct {
	*js.Object
}

func (*Fields) Field

func (f *Fields) Field(i int) (ret *Field)

type Globals

type Globals struct {
	Blockly    *Blockly
	Extensions *Extensions
	Xml        *Xml
	Utils      *Utils
}

implements block.Project

func Project

func Project() *Globals

func (*Globals) GenerateUniqueName

func (p *Globals) GenerateUniqueName() (ret string)

func (*Globals) IsBlockRegistered

func (p *Globals) IsBlockRegistered(blockType string) (ret bool)

func (*Globals) NewBlankWorkspace

func (p *Globals) NewBlankWorkspace(isMutator bool) (ret *Workspace)

func (*Globals) NewWorkspace

func (p *Globals) NewWorkspace(elementId, mediaPath string, tools interface{}) *Workspace

note: toolbox can be an xml string containing the toolbox

func (*Globals) RegisterBlock

func (p *Globals) RegisterBlock(blockType string, desc block.Dict) (err error)

func (*Globals) RegisterMutator

func (p *Globals) RegisterMutator(name string, m block.Mutator) (err error)

type Input

type Input struct {
	*js.Object            // Blockly.Input
	Type       InputType  `js:"type"`
	Name       string     `js:"name"`
	Align      InputAlign `js:"align"`
	// contains filtered or unexported fields
}

func (*Input) AppendField

func (in *Input) AppendField(f *Field)

blockly's append field allows field to be a string, and then to pass an optional name see also: insertFieldAt

func (*Input) AppendNamedField

func (in *Input) AppendNamedField(name string, f *Field)

func (*Input) Block

func (in *Input) Block() *Block

func (*Input) Connection

func (in *Input) Connection() block.Connection

func (*Input) Dispose

func (in *Input) Dispose()

func (*Input) Fields

func (in *Input) Fields() (ret *Fields)

func (*Input) InputName

func (in *Input) InputName() string

func (*Input) InputType

func (in *Input) InputType() string

func (*Input) IsVisible

func (in *Input) IsVisible() bool

func (*Input) SetAlign

func (in *Input) SetAlign(a InputAlign)

func (*Input) SetCheck

func (in *Input) SetCheck(compatibleType string) (err error)

func (*Input) SetChecks

func (in *Input) SetChecks(compatibleTypes []string) (err error)

func (*Input) SetInvisible

func (in *Input) SetInvisible()

func (*Input) SetVisible

func (in *Input) SetVisible(visible bool)

type InputAlign

type InputAlign int
const (
	AlignLeft InputAlign = iota - 1
	AlignCentre
	AlignRight
)

func (InputAlign) String

func (i InputAlign) String() string

type InputType

type InputType int

InputType - describes both inputs and connections

const (
	InputValueType InputType = iota + 1
	OutputValueType
	NextStatementType     // used for connections between blocks, and for statement inputs
	PreviousStatementType // used for connections between blocks
	DummyInputType
)

func (InputType) String

func (i InputType) String() string

type Mixin

type Mixin map[string]*js.Object

map of name to funcion object

type Size

type Size struct {
	*js.Object
	Width  string `js:"width"`
	Height string `js:"width"`
}

goog.math.Size

type ToolboxPosition

type ToolboxPosition int
const (
	ToolboxAtTop ToolboxPosition = iota
	ToolboxAtBottom
	ToolboxAtLeft
	ToolboxAtRight
)

type UiChange

type UiChange struct {
	*Event
	Element  string     `js:"element"`
	OldValue *js.Object `js:"oldValue"`
	NewValue *js.Object `js:"newValue"`
}

ex. warningOpen ( showing or hding the warning bubble ), mutatorOpen, commentOpen, (block) click, (block) selected.

type Utils

type Utils struct {
	*js.Object
}

via Blockly.Utils

func (*Utils) GenUid

func (u *Utils) GenUid() (ret string)

returns string

type VarCreate

type VarCreate struct {
	*Event
	VarId   string `js:"varId"`
	VarName string `js:"varName"`
	VarType string `js:"varType"`
}

type VarDelete

type VarDelete struct {
	*Event
	VarId   string `js:"varId"`
	VarName string `js:"varName"`
	VarType string `js:"varType"`
}

type VarRename

type VarRename struct {
	*Event
	VarId   string `js:"varId"`
	OldName string `js:"oldName"`
	NewName string `js:"newName"`
}

type Workspace

type Workspace struct {
	*js.Object
	Id               string          `js:"id"`
	Options          *js.Object      `js:"options"`
	Rtl              bool            `js:"RTL"`
	HorizontalLayout bool            `js:"horizontalLayout"`
	ToolboxPosition  ToolboxPosition `js:"toolboxPosition"`
	Rendered         bool            `js:"rendered"`
	IsClearing       bool            `js:"isClearing"`
	IsMutator        bool            `js:"isMutator"` // from workspacesvg
	// contains filtered or unexported fields
}

Workspace - a container for Blockly blocks. The mutation popups, and the main editing space are examples of separate workspaces. ( The toolbox uses the main workspace. )

func (*Workspace) AddChangeListener

func (ws *Workspace) AddChangeListener(fn func(evt interface{})) *js.Object
func (ws* Workspace) remainingCapacity () {
 return ws.Call("remainingCapacity")
}
func (ws* Workspace) undo (redo) {
 return ws.Call("undo")
}
func (ws* Workspace) clearUndo () {
 return ws.Call("clearUndo")
}

func (*Workspace) Clear

func (ws *Workspace) Clear()
func (ws* Workspace) getCommentById (id) {
 return ws.Call("getCommentById")
}

func (ws* Workspace) allInputsFilled = function(

func (ws* Workspace) getPotentialVariableMap () {
 return ws.Call("getPotentialVariableMap")
}
func (ws* Workspace) createPotentialVariableMap () {
 return ws.Call("createPotentialVariableMap")
}
func (ws* Workspace) getVariableMap () {
 return ws.Call("getVariableMap")
}

func (*Workspace) ClearUndo

func (ws *Workspace) ClearUndo()

func (*Workspace) Dispose

func (ws *Workspace) Dispose()

func (*Workspace) GetBlockById

func (ws *Workspace) GetBlockById(id string) (ret *Block)

GetBlockById lookup ( and wrap ) a blockly block for use with go apis.

func (*Workspace) NewBlock

func (ws *Workspace) NewBlock(blockType string) (block.Shape, error)

func (*Workspace) NewBlockWithId

func (ws *Workspace) NewBlockWithId(blockId string, blockType string) (ret block.Shape, err error)

func (*Workspace) OnDelete

func (ws *Workspace) OnDelete(onDel block.OnDelete)

func (*Workspace) RemoveChangeListener

func (ws *Workspace) RemoveChangeListener(wrappedFn *js.Object)

func (*Workspace) WorkspaceId

func (ws *Workspace) WorkspaceId() string

type Xml

type Xml struct {
	*js.Object
}

via Blockly.Xml

func (*Xml) DomToBlock

func (x *Xml) DomToBlock(xmlBlock *jsdom.Element, ws *Workspace) (ret *Block)

func (x *Xml) clearWorkspaceAndLoadFromXml (xml, workspace) { func (x *Xml) domToWorkspace (xml, workspace) { func (x *Xml) appendDomToWorkspace (xml, workspace) {

func (*Xml) DomToText

func (x *Xml) DomToText(xml *jsdom.Element) (ret string)

func (x *Xml) workspaceToDom() (workspace, OptNoId) { func (x *Xml) variablesToDom (variableList) { func (x *Xml) blockToDomWithXY (block, OptNoId) { func (x *Xml) fieldToDomVariable_ (field) { func (x *Xml) fieldToDom_ (field) { func (x *Xml) allFieldsToDom_ (block, element) { func (x *Xml) blockToDom (block, OptNoId) { func (x *Xml) cloneShadow_ (shadow) {

func (*Xml) TextToDom

func (x *Xml) TextToDom(text string) (ret *jsdom.Element)

func (x *Xml) domToPrettyText (jsdom) {

Jump to

Keyboard shortcuts

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