/** * @license * Visual Blocks Editor * * Copyright 2012 Google Inc. * https://developers.google.com/blockly/ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Collections.Generic; using Bridge; using Bridge.Html5; namespace WebMrbc { /** * @fileoverview Core JavaScript library for Blockly. * @author fraser@google.com (Neil Fraser) */ [External, Name("Blockly")] public partial class Blockly { [Name(false)] public static Xml Xml; [Name(false)] public static Events Events; [Name(false)] public static Procedures Procedures; [Name(false)] public static Variables Variables; [Name(false)] public static Names Names; /// /// Number of pixels the mouse must move before a drag starts. /// [Name(false)] public static int DRAG_RADIUS = 5; /// /// Maximum misalignment between connections for them to snap together. /// [Name(false)] public static int SNAP_RADIUS = 20; /// /// Delay in ms between trigger and bumping unconnected block out of alignment. /// [Name(false)] public static int BUMP_DELAY = 250; /// /// Number of characters to truncate a collapsed block to. /// [Name(false)] public static int COLLAPSE_CHARS = 30; /// /// Length in ms for a touch to become a long press. /// [Name(false)] public static int LONGPRESS = 750; /// /// Prevent a sound from playing if another sound preceded it within this many /// miliseconds. /// [Name(false)] public static int SOUND_LIMIT = 100; /// /// The richness of block colours, regardless of the hue. /// Must be in the range of 0 (inclusive) to 1 (exclusive). /// [Name(false)] public static double HSV_SATURATION = 0.45; /// /// The intensity of block colours, regardless of the hue. /// Must be in the range of 0 (inclusive) to 1 (exclusive). /// [Name(false)] public static double HSV_VALUE = 0.65; /// /// Sprited icons and images. /// [Name(false)] public static object SPRITE = new { width = 96, height = 124, url = "sprites.png" }; /// /// Required name space for SVG elements. /// [Name(false)] public static readonly string SVG_NS = "http://www.w3.org/2000/svg"; /// /// Required name space for HTML elements. /// [Name(false)] public static readonly string HTML_NS = "http://www.w3.org/1999/xhtml"; /// /// ENUM for a right-facing value input. E.g. 'set item to' or 'return'. /// [Name(false)] public static int INPUT_VALUE = 1; /// /// ENUM for a left-facing value output. E.g. 'random fraction'. /// [Name(false)] public static int OUTPUT_VALUE = 2; /// /// ENUM for a down-facing block stack. E.g. 'if-do' or 'else'. /// [Name(false)] public static int NEXT_STATEMENT = 3; /// /// ENUM for an up-facing block stack. E.g. 'break out of loop'. /// [Name(false)] public static int PREVIOUS_STATEMENT = 4; /// /// ENUM for an dummy input. Used to add field(s) with no input. /// [Name(false)] public static int DUMMY_INPUT = 5; /// /// ENUM for left alignment. /// [Name(false)] public static int ALIGN_LEFT = -1; /// /// ENUM for centre alignment. /// [Name(false)] public static int ALIGN_CENTRE = 0; /// /// ENUM for right alignment. /// [Name(false)] public static int ALIGN_RIGHT = 1; /// /// ENUM for no drag operation. /// [Name(false)] public static int DRAG_NONE = 0; /// /// ENUM for inside the sticky DRAG_RADIUS. /// [Name(false)] public static int DRAG_STICKY = 1; /// /// ENUM for inside the non-sticky DRAG_RADIUS, for differentiating between /// clicks and drags. /// [Name(false)] public static int DRAG_BEGIN = 1; /// /// ENUM for freely draggable (outside the DRAG_RADIUS, if one applies). /// [Name(false)] public static int DRAG_FREE = 2; /// /// Lookup table for determining the opposite type of a connection. /// [Name(false)] public static int[] OPPOSITE_TYPE = { 0, OUTPUT_VALUE, INPUT_VALUE, PREVIOUS_STATEMENT, NEXT_STATEMENT }; /// /// ENUM for toolbox and flyout at top of screen. /// [Name(false)] public static int TOOLBOX_AT_TOP = 0; /// /// ENUM for toolbox and flyout at bottom of screen. /// [Name(false)] public static int TOOLBOX_AT_BOTTOM = 1; /// /// ENUM for toolbox and flyout at left of screen. /// [Name(false)] public static int TOOLBOX_AT_LEFT = 2; /// /// ENUM for toolbox and flyout at right of screen. /// [Name(false)] public static int TOOLBOX_AT_RIGHT = 3; /// /// The main workspace most recently used. /// Set by Blockly.WorkspaceSvg.prototype.markFocused /// public static WorkspaceSvg mainWorkspace; /// /// Currently selected block. /// public static Block selected; [Name(false)] public static Blocks Blocks; /// /// Register a callback function associated with a given key, for clicks on /// buttons and labels in the flyout. /// For instance, a button specified by the XML /// /// should be matched by a call to /// registerButtonCallback("CREATE_VARIABLE", yourCallbackFunction). /// /// The name to use to look up this function. /// The function to call when the /// given button is clicked. internal static void registerButtonCallback(string key, Action func) { throw new NotImplementedException(); } /// /// Convert a hue (HSV model) into an RGB hex triplet. /// /// Hue on a colour wheel (0-360). /// RGB code, e.g. '#5ba65b'. public static string hueToRgb(int hue) { throw new NotImplementedException(); } /// /// Returns the dimensions of the specified SVG image. /// /// SVG image. /// Contains width and height properties. public static goog.math.Size svgSize(Element svg) { throw new NotImplementedException(); } /// /// Size the workspace when the contents change. This also updates /// scrollbars accordingly. /// /// public static void resizeSvgContents(WorkspaceSvg workspace) { throw new NotImplementedException(); } /// /// Size the SVG image to completely fill its container. Call this when the view /// actually changes sizes (e.g. on a window resize/device orientation change). /// See Blockly.resizeSvgContents to resize the workspace when the contents /// change (e.g. when a block is added or removed). /// Record the height/width of the SVG image. /// /// Any workspace in the SVG. public static void svgResize(WorkspaceSvg workspace) { throw new NotImplementedException(); } /// /// Close tooltips, context menus, dropdown selections, etc. /// /// If true, don't close the toolbox. public static void hideChaff(bool opt_allowToolbox = false) { throw new NotImplementedException(); } /// /// When something in Blockly's workspace changes, call a function. /// /// Function to call. /// Opaque data that can be passed to removeChangeListener. public static Action addChangeListener(Action func) { // Backwards compatability from before there could be multiple workspaces. App.WriteLine("Deprecated call to Blockly.addChangeListener, " + "use workspace.addChangeListener instead."); return getMainWorkspace().addChangeListener(func); } /// /// Returns the main workspace. Returns the last used main workspace (based on /// focus). Try not to use this function, particularly if there are multiple /// Blockly instances on a page. /// /// The main workspace. public static WorkspaceSvg getMainWorkspace() { return mainWorkspace; } /// /// Wrapper to window.alert() that app developers may override to /// provide alternatives to the modal browser window. /// /// The message to display to the user. /// The callback when the alert is dismissed. internal static void alert(string message, Action opt_callback = null) { throw new NotImplementedException(); } /// /// Wrapper to window.prompt() that app developers may override to provide /// alternatives to the modal browser window. Built-in browser prompts are /// often used for better text input experience on mobile device. We strongly /// recommend testing mobile when overriding this. /// /// The message to display to the user. /// The value to initialize the prompt with. /// The callback for handling user reponse. internal static void prompt(string message, string defaultValue, Action callback) { throw new NotImplementedException(); } /// /// Inject a Blockly editor into the specified container element (usually a div). /// /// Containing element, or its ID, or a CSS selector. /// opt_options Optional dictionary of options. /// Newly created main workspace. public static WorkspaceSvg inject(Union container, object opt_options = null) { throw new NotImplementedException(); } /// /// Modify the block tree on the existing toolbox. /// /// DOM tree of blocks, or text representation of same. public static void updateToolbox(Union tree) { throw new NotImplementedException(); } /// /// Don't do anything for this event, just halt propagation. /// /// An event. public static void noEvent(Event e) { // This event has been handled. No need to bubble up to the document. e.PreventDefault(); e.StopPropagation(); } /// /// Helper method for creating SVG elements. /// /// Element's tag name. /// Dictionary of attribute names and values. /// Optional parent on which to append the element. /// Optional workspace for access to context (scale...). /// Newly created SVG element. public static Element createSvgElement(string name, object attrs, Element parent, Workspace opt_workspace) { throw new NotImplementedException(); } /// /// Is this event a right-click? /// /// Mouse event. /// True if right-click. public static bool isRightButton(Event e) { throw new NotImplementedException(); } /// /// Return the converted coordinates of the given mouse event. /// The origin (0,0) is the top-left corner of the Blockly svg. /// /// Mouse event. /// SVG element. /// Inverted screen CTM to use. /// Object with .x and .y properties. public static goog.math.Coordinate mouseToSvg(Event e, Element svg, SVGMatrix matrix) { throw new NotImplementedException(); } /// /// Given an array of strings, return the length of the shortest one. /// /// Array of strings. /// Length of shortest string. public static int shortestStringLength(string[] array) { throw new NotImplementedException(); } /// /// Given an array of strings, return the length of the common prefix. /// Words may not be split. Any space after a word is included in the length. /// /// Array of strings. /// Length of shortest string. /// Length of common prefix. public static int commonWordPrefix(string[] array, int opt_shortest = 0) { throw new NotImplementedException(); } /// /// Given an array of strings, return the length of the common suffix. /// Words may not be split. Any space after a word is included in the length. /// /// Array of strings. /// Length of shortest string. /// Length of common suffix. public static int commonWordSuffix(string[] array, int opt_shortest = 0) { throw new NotImplementedException(); } /// /// Is the given string a number (includes negative and decimals). /// /// Input string. /// True if number, false otherwise. public static bool isNumber(string str) { throw new NotImplementedException(); } /// /// Parse a string with any number of interpolation tokens (%1, %2, ...). /// '%' characters may be self-escaped (%%). /// /// Text containing interpolation tokens. /// Array of strings and numbers. public static Union tokenizeInterpolation(string message) { throw new NotImplementedException(); } /// /// Generate a unique ID. This should be globally unique. /// 87 characters ^ 20 length > 128 bits (better than a UUID). /// /// A globally unique ID string. public static string genUid() { throw new NotImplementedException(); } /// /// Wrap text to the specified width. /// /// Text to wrap. /// Width to wrap each line. /// public static string wrap(string text, int wrap) { throw new NotImplementedException(); } } [External, Name("Blockly.Xml")] public class Xml { /// /// Encode a block tree as XML. /// /// workspace The workspace containing blocks. /// XML document. public Element workspaceToDom(Workspace workspace) { throw new NotImplementedException(); } /// /// Encode a block subtree as XML with XY coordinates. /// /// The root block to encode. /// Tree of XML elements. public Element blockToDomWithXY(Block block) { throw new NotImplementedException(); } /// /// Encode a block subtree as XML. /// /// The root block to encode. /// Tree of XML elements. public Element blockToDom(Block block) { throw new NotImplementedException(); } /// /// Converts a DOM structure into plain text. /// Currently the text format is fairly ugly: all one line with no whitespace. /// /// A tree of XML elements. /// Text representation. public string domToText(Element dom) { throw new NotImplementedException(); } /// /// Converts a DOM structure into properly indented text. /// /// A tree of XML elements. /// Text representation. public string domToPrettyText(Element dom) { throw new NotImplementedException(); } /// /// Converts plain text into a DOM structure. /// Throws an error if XML doesn't parse. /// /// Text representation. /// A tree of XML elements. public Element textToDom(string text) { throw new NotImplementedException(); } /// /// Decode an XML DOM and create blocks on the workspace. /// /// XML DOM. /// The workspace. public void domToWorkspace(Element xml, Workspace workspace) { throw new NotImplementedException(); } /// /// Decode an XML block tag and create a block (and possibly sub blocks) on the /// workspace. /// /// XML block element. /// The workspace. /// The root block created. public Block domToBlock(Element xmlBlock, Workspace workspace) { throw new NotImplementedException(); } /// /// Remove any 'next' block (statements in a stack). /// /// XML block element. public void deleteNext(Element xmlBlock) { throw new NotImplementedException(); } } /** * @fileoverview Object representing a workspace. * @author fraser@google.com (Neil Fraser) */ [External, Name("Blockly.Workspace")] public class Workspace { public string id; public Options options; public bool RTL; public bool horizontalLayout; public int toolboxPosition; public bool isFlyout; /// /// A list of all of the named variables in the workspace, including variables /// that are not currently in use. /// public string[] variableList; /// /// Workspaces may be headless. /// True if visible. False if headless. /// public bool rendered; /// /// Maximum number of undo events in stack. /// 0 to turn off undo, Infinity for unlimited. /// public int MAX_UNDO = 1024; /// /// Class for a workspace. This is a data structure that contains blocks. /// There is no UI, and can be created headlessly. /// /// Dictionary of options. public Workspace(Options opt_options = null) { options = opt_options; } /// /// Dispose of this workspace. /// Unlink from all DOM elements to prevent memory leaks. /// public void dispose() { } /// /// Angle away from the horizontal to sweep for blocks. Order of execution is /// generally top to bottom, but a small angle changes the scan to give a bit of /// a left to right bias (reversed in RTL). Units are in degrees. /// See: http://tvtropes.org/pmwiki/pmwiki.php/Main/DiagonalBilling. /// public int SCAN_ANGLE = 3; /// /// Add a block to the list of top blocks. /// /// Block to remove. public void addTopBlock(Block block) { throw new NotImplementedException(); } /// /// Remove a block from the list of top blocks. /// /// Block to remove. public void removeTopBlock(Block block) { throw new NotImplementedException(); } /// /// Finds the top-level blocks and returns them. Blocks are optionally sorted /// by position; top to bottom (with slight LTR or RTL bias). /// /// Sort the list if true. /// The top-level block objects. public Block[] getTopBlocks(bool ordered) { throw new NotImplementedException(); } /// /// Find all blocks in workspace. No particular order. /// /// public Block[] getAllBlocks() { throw new NotImplementedException(); } /// /// Dispose of all blocks in workspace. /// public void clear() { throw new NotImplementedException(); } /// /// Returns the horizontal offset of the workspace. /// Intended for LTR/RTL compatibility in XML. /// Not relevant for a headless workspace. /// /// Width. public int getWidth() { throw new NotImplementedException(); } /// /// Obtain a newly created block. /// /// Name of the language object containing /// type-specific functions for this block. /// Optional ID. Use this ID if provided, otherwise /// create a new id. /// The created block. public Block newBlock(string prototypeName, string opt_id = null) { throw new NotImplementedException(); } /// /// The number of blocks that may be added to the workspace before reaching /// the maxBlocks. /// /// public int remainingCapacity() { throw new NotImplementedException(); } /// /// Undo or redo the previous action. /// /// False if undo, true if redo. public void undo(bool redo) { throw new NotImplementedException(); } /// /// Clear the undo/redo stacks. /// public void clearUndo() { throw new NotImplementedException(); } /// /// When something in this workspace changes, call a function. /// /// Function to call. /// Function that can be passed to /// removeChangeListener. public Action addChangeListener(Action func) { throw new NotImplementedException(); } /// /// Stop listening for this workspace's changes. /// /// Function to stop calling. public void removeChangeListener(Action func) { throw new NotImplementedException(); } /// /// Fire a change event. /// /// Event to fire. public void fireChangeListener(Abstract @event) { throw new NotImplementedException(); } /// /// Find the block on this workspace with the specified ID. /// /// ID of block to find. /// The sought after block or null if not found. public Block getBlockById(string id) { throw new NotImplementedException(); } /// /// Find the workspace with the specified ID. /// /// ID of workspace to find. /// The sought after workspace or null if not found. public Workspace getById(string id) { throw new NotImplementedException(); } /** * Create a variable with the given name. * TODO: #468 * @param {string} name The new variable's name. */ public void createVariable(string newText) { throw new NotImplementedException(); } /// /// Check whether a variable exists with the given name. The check is /// case-insensitive. /// /// The name to check for. /// The index of the name in the variable list, or -1 if it is /// not present. internal int variableIndexOf(string name) { throw new NotImplementedException(); } } [External, Name("Blockly.WorkspaceSvg")] public class WorkspaceSvg : Workspace { public WorkspaceSvg(Options options) : base(options) { } public Metrics getMetrics() { throw new NotImplementedException(); } public void setMetrics(Metrics metrics) { throw new NotImplementedException(); } /// /// Getter for the inverted screen CTM. /// /// The matrix to use in mouseToSvg public SVGMatrix getInverseScreenCTM() { throw new NotImplementedException(); } /// /// Update the inverted screen CTM. /// public void updateInverseScreenCTM() { throw new NotImplementedException(); } /// /// Save resize handler data so we can delete it later in dispose. /// /// Data that can be passed to unbindEvent_. public void setResizeHandlerWrapper(Action handler) { throw new NotImplementedException(); } /// /// Create the workspace DOM elements. /// /// opt_backgroundClass Either 'blocklyMainBackground' or /// 'blocklyMutatorBackground'. /// The workspace's SVG group. public Element createDom(string opt_backgroundClass = null) { throw new NotImplementedException(); } /// /// Dispose of this workspace. /// Unlink from all DOM elements to prevent memory leaks. /// public new void dispose() { throw new NotImplementedException(); } /// /// Obtain a newly created block. /// /// Name of the language object containing /// type-specific functions for this block. /// Optional ID. Use this ID if provided, otherwise /// create a new id. /// The created block. public new BlockSvg newBlock(string prototypeName, string opt_id = null) { throw new NotImplementedException(); } /// /// Resize the parts of the workspace that change when the workspace /// contents (e.g. block positions) change. This will also scroll the /// workspace contents if needed. /// public void resizeContents() { throw new NotImplementedException(); } /// /// Resize and reposition all of the workspace chrome (toolbox, /// trash, scrollbars etc.) /// This should be called when something changes that /// requires recalculating dimensions and positions of the /// trash, zoom, toolbox, etc. (e.g.window resize). /// public void resize() { throw new NotImplementedException(); } /// /// Get the SVG element that forms the drawing surface. /// /// SVG element. public Element getCanvas() { throw new NotImplementedException(); } /// /// Get the SVG element that forms the bubble surface. /// /// SVG element. public Element getBubbleCanvas() { throw new NotImplementedException(); } /// /// Get the SVG element that contains this workspace. /// /// SVG element. public Element getParentSvg() { throw new NotImplementedException(); } /// /// Translate this workspace to new coordinates. /// /// Horizontal translation. /// Vertical translation. public void translate(int x, int y) { throw new NotImplementedException(); } /// /// Returns the horizontal offset of the workspace. /// Intended for LTR/RTL compatibility in XML. /// /// Width. public new int getWidth() { throw new NotImplementedException(); } /// /// Toggles the visibility of the workspace. /// Currently only intended for main workspace. /// /// True if workspace should be visible. public void setVisible(bool isVisible) { throw new NotImplementedException(); } /// /// Render all blocks in workspace. /// public void render() { throw new NotImplementedException(); } /// /// Turn the visual trace functionality on or off. /// /// True if the trace should be on. public void traceOn(bool armed) { throw new NotImplementedException(); } /// /// Highlight a block in the workspace. /// /// ID of block to find. public void highlightBlock(string id) { throw new NotImplementedException(); } /// /// Paste the provided block onto the workspace. /// /// XML block element. public void paste(Element xmlBlock) { throw new NotImplementedException(); } /// /// Make a list of all the delete areas for this workspace. /// public void recordDeleteAreas() { throw new NotImplementedException(); } /// /// Is the mouse event over a delete area (toolbox or non-closing flyout)? /// Opens or closes the trashcan and sets the cursor as a side effect. /// /// Mouse move event. /// public bool isDeleteArea(Event e) { throw new NotImplementedException(); } /// /// Start tracking a drag of an object on this workspace. /// /// Mouse down event. /// Starting location of object. public void startDrag(Event e, goog.math.Coordinate xy) { throw new NotImplementedException(); } /// /// Track a drag of an object on this workspace. /// /// Mouse move event. /// New location of object. public goog.math.Coordinate moveDrag(Event e) { throw new NotImplementedException(); } /// /// Is the user currently dragging a block or scrolling the flyout/workspace? /// /// True if currently dragging or scrolling. public bool isDragging() { throw new NotImplementedException(); } /// /// Calculate the bounding box for the blocks on the workspace. /// /// Contains the position and size of the bounding box /// containing the blocks on the workspace. /// {x: 0, y: 0, width: 0, height: 0} public object getBlocksBoundingBox() { throw new NotImplementedException(); } /// /// Play a named sound at specified volume. If volume is not specified, /// use full volume (1). /// /// Name of sound. /// Volume of sound (0-1). public void playAudio(string name, double opt_volume = 1) { throw new NotImplementedException(); } /// /// Modify the block tree on the existing toolbox. /// /// DOM tree of blocks, or text representation of same. public void updateToolbox(Union tree) { throw new NotImplementedException(); } /// /// Mark this workspace as the currently focused main workspace. /// public void markFocused() { throw new NotImplementedException(); } /// /// Zooming the blocks centered in (x, y) coordinate with zooming in or out. /// /// X coordinate of center. /// Y coordinate of center. /// Type of zooming (-1 zooming out and 1 zooming in). public void zoom(double x, double y, double type) { throw new NotImplementedException(); } /// /// Zooming the blocks centered in the center of view with zooming in or out. /// /// public void zoomCenter(double type) { throw new NotImplementedException(); } /// /// Zoom the blocks to fit in the workspace if possible. /// public void zoomToFit() { throw new NotImplementedException(); } /// /// Center the workspace. /// public void scrollCenter() { throw new NotImplementedException(); } /// /// Set the workspace's zoom factor. /// /// Zoom factor. public void setScale(double newScale) { throw new NotImplementedException(); } } [External, Name("Blockly.Metrics")] public class Metrics { ///Height of the visible rectangle public double viewHeight; ///Width of the visible rectangle public double viewWidth; ///Height of the contents public double contentHeight; ///Width of the contents public double contentWidth; ///Offset of top edge of visible rectangle from parent public double viewTop; ///Offset of the top-most content from the y=0 coordinate public double contentTop; ///Top-edge of view public double absoluteTop; ///Offset of the left edge of visible rectangle from parent public double viewLeft; ///Offset of the left-most content from the x=0 coordinate public double contentLeft; ///Left-edge of view public double absoluteLeft; } [External, Name("Blockly.Events")] public class Events { public const string CREATE = "create"; public const string DELETE = "delete"; public const string CHANGE = "change"; public const string MOVE = "move"; public const string UI = "ui"; internal string group_ = ""; public bool recordUndo = false; internal string[] getDescendantIds_(Block block) { throw new NotImplementedException(); } internal void enable() { throw new NotImplementedException(); } internal void disable() { throw new NotImplementedException(); } internal void setGroup(string group) { throw new NotImplementedException(); } internal void fire(Abstract ev) { throw new NotImplementedException(); } } [External, Name("Blockly.Events.Abstract")] public class Abstract { /// /// One of Blockly.Events.CREATE, Blockly.Events.DELETE, Blockly.Events.CHANGE, Blockly.Events.MOVE, Blockly.Events.UI. /// internal string type; /// /// UUID of workspace. The workspace can be found with Workspace.getById(event.workspaceId) /// internal string workspaceId; /// /// UUID of block. The block can be found with workspace.getBlockById(event.blockId) /// internal string blockId; /// /// UUID of group. Some events are part of an indivisible group, such as inserting a statement in a stack. /// internal string group; internal bool recordUndo; public Abstract(Block block, string type) { this.type = type; if (block != null) { blockId = block.id; workspaceId = block.workspace.id; } group = Blockly.Events.group_; recordUndo = Blockly.Events.recordUndo; } } [External, Name("Blockly.Events.Create")] public class Create : Abstract { /// /// An XML tree defining the new block and any connected child blocks. /// internal Element xml; /// /// An array containing the UUIDs of the new block and any connected child blocks. /// internal string[] ids; /// /// Class for a block creation event. /// /// The created block. Null for a blank event. public Create(Block block) : base(block, Events.CHANGE) { if (block == null) { return; // Blank event to be populated by fromJson. } xml = Blockly.Xml.blockToDomWithXY(block); ids = Blockly.Events.getDescendantIds_(block); } } [External, Name("Blockly.Events.Delete")] public class Delete : Abstract { /// /// An XML tree defining the deleted block and any connected child blocks. /// internal object oldXml; /// /// An array containing the UUIDs of the deleted block and any connected child blocks. /// internal string[] ids; /// /// Class for a block deletion event. /// /// The deleted block. Null for a blank event. public Delete(Block block) : base(block, Events.DELETE) { if (block == null) { return; // Blank event to be populated by fromJson. } if (block.getParent() != null) { throw new Exception("Connected blocks cannot be deleted."); } oldXml = Blockly.Xml.blockToDomWithXY(block); ids = Blockly.Events.getDescendantIds_(block); } } [External, Name("Blockly.Events.Change")] public class Change : Abstract { /// /// One of 'field', 'comment', 'collapsed', 'disabled', 'inline', 'mutate' /// internal string element; /// /// Name of the field if this is a change to a field. /// internal string name; /// /// Original value. /// internal object oldValue; /// /// Changed value. /// internal object newValue; /// /// Class for a block change event. /// /// The changed block. Null for a blank event. /// One of 'field', 'comment', 'disabled', etc. /// Name of input or field affected, or null. /// Previous value of element. /// New value of element. public Change(Block block, string element, string name, string oldValue, string newValue) : base(block, Events.CHANGE) { if (block == null) { return; // Blank event to be populated by fromJson. } this.element = element; this.name = name; this.oldValue = oldValue; this.newValue = newValue; } } [External, Name("Blockly.Events.Move")] public class Move : Abstract { /// /// UUID of old parent block. Undefined if it was a top level block. /// internal string oldParentId; /// /// Name of input on old parent. Undefined if it was a top level block or parent's next block. /// internal string oldInputName; /// /// X and Y coordinates if it was a top level block. Undefined if it had a parent. /// internal object oldCoordinate; /// /// UUID of new parent block. Undefined if it is a top level block. /// internal string newParentId; /// /// Name of input on new parent. Undefined if it is a top level block or parent's next block. /// internal string newInputName; /// /// X and Y coordinates if it is a top level block. Undefined if it has a parent. /// internal object newCoordinate; /// /// Class for a block move event. Created before the move. /// /// The moved block. Null for a blank event. public Move(Block block) : base(block, Events.MOVE) { if (block == null) { return; // Blank event to be populated by fromJson. } var location = this.currentLocation_(); this.oldParentId = location.parentId; this.oldInputName = location.inputName; this.oldCoordinate = location.coordinate; } /** * Record the block's new location. Called after the move. */ public void recordNew() { var location = this.currentLocation_(); this.newParentId = location.parentId; this.newInputName = location.inputName; this.newCoordinate = location.coordinate; } class Location { public string parentId; public string inputName; public object coordinate; public Location(string parentId, string inputName, object coordinate) { this.parentId = parentId; this.inputName = inputName; this.coordinate = coordinate; } } /** * Returns the parentId and input if the block is connected, * or the XY location if disconnected. * @return {!Object} Collection of location info. * @private */ private Location currentLocation_() { throw new NotImplementedException(); } } [External, Name("Blockly.Events.Ui")] public class Ui : Abstract { /// /// One of 'selected', 'category', 'click', 'commentOpen', 'mutatorOpen', 'warningOpen' /// internal string element; /// /// Original value. /// internal object oldValue; /// /// Changed value. /// internal object newValue; /// /// Class for a UI event. /// /// The affected block. /// One of 'selected', 'comment', 'mutator', etc. /// Previous value of element. /// New value of element. public Ui(Block block, string element, string oldValue, string newValue) : base(block, Events.UI) { this.element = element; this.oldValue = oldValue; this.newValue = newValue; } } [External, Name("Blockly.Options")] public class Options { public Node languageTree; public bool oneBasedIndex; public Workspace parentWorkspace; public bool comments; } [External, Name("Blockly.BlockSvg")] public class BlockSvg : Block { [Name(false)] public int TAB_HEIGHT = 20; public BlockSvg(string type) : base(type) { } } [External, Name("Blockly.Comment")] public class Comment : Block { public Comment(string type) : base(type) { } } [External, Name("Blockly.Input")] public class Input { public int type; public string name; public Block block; public Connection connection; public Field[] fieldRow; /// /// Class for an input with an optional field. /// /// The type of the input. /// Language-neutral identifier which may used to find this /// input again. /// The block containing this input. /// Optional connection for this input. public Input(int type, string name, Block block, Connection connection) { this.type = type; this.name = name; this.block = block; this.connection = connection; } /// /// Add an item to the end of the input's field row. /// /// Something to add as a field. /// Language-neutral identifier which may used to find /// this field again.Should be unique to the host block. /// The input being append to (to allow chaining). public Input appendField(Union field, string opt_name = null) { throw new NotImplementedException(); } /// /// Add an item to the end of the input's field row. /// /// Something to add as a field. /// Language-neutral identifier which may used to find /// this field again.Should be unique to the host block. /// The input being append to (to allow chaining). public Input appendTitle(Union field, string opt_name = null) { throw new NotImplementedException(); } /// /// Remove a field from this input. /// /// The name of the field. public void removeField(string name) { throw new NotImplementedException(); } /// /// Gets whether this input is visible or not. /// /// True if visible. public bool isVisible() { throw new NotImplementedException(); } /// /// Sets whether this input is visible or not. /// Used to collapse/uncollapse a block. /// /// True if visible. /// List of blocks to render. public Block[] setVisible(bool visible) { throw new NotImplementedException(); } /// /// Change a connection's compatibility. /// /// Compatible value type or /// list of value types.Null if all types are compatible. /// The input being modified (to allow chaining). public Input setCheck(Union check) { throw new NotImplementedException(); } /// /// Change the alignment of the connection's field(s). /// /// align One of Blockly.ALIGN_LEFT, ALIGN_CENTRE, ALIGN_RIGHT. /// In RTL mode directions are reversed, and ALIGN_RIGHT aligns to the left. /// The input being modified (to allow chaining). public Input setAlign(double align) { throw new NotImplementedException(); } /// /// Initialize the fields on this input. /// public void init() { throw new NotImplementedException(); } /// /// Sever all links to this input. /// public void dispose() { throw new NotImplementedException(); } } [External, Name("Blockly.Icon")] public class Icon { public Icon(Block block) { } } [External, Name("Blockly.Mutator")] public class Mutator : Icon { public Workspace workspace_; public Mutator(string[] quarkNames) : base(null) { } /// /// Reconnect an block to a mutated input. /// /// Connection on child block. /// Parent block. /// Name of input on parent block. /// True iff a reconnection was made, false otherwise. internal static bool reconnect(Connection connectionChild, Block block, string inputName) { throw new NotImplementedException(); } internal bool isVisible() { throw new NotImplementedException(); } } [External, Name("Blockly.Connection")] public class Connection { public Connection targetConnection; public Connection(Block source, int type) { } public void connect(Connection previousConnection) { throw new NotImplementedException(); } public void disconnect() { throw new NotImplementedException(); } public Block targetBlock() { throw new NotImplementedException(); } public bool checkType_(Connection connection) { throw new NotImplementedException(); } public Connection setCheck(object check) { throw new NotImplementedException(); } internal Block getSourceBlock() { throw new NotImplementedException(); } } [External, Name("Blockly.RenderedConnection")] public class RenderedConnection : Connection { public RenderedConnection(Block source, int type) : base(source, type) { } } [External, Name("Blockly.Field")] public class Field { public goog.math.Size size_; public string text_; public Block sourceBlock_; /// /// Abstract class for an editable field. /// /// The initial content of the field. /// An optional function that is called /// to validate any constraints on what the user entered. Takes the new /// text as an argument and returns either the accepted text, a replacement /// text, or null to abort the change. public Field(string text, Func opt_validator = null) { size_ = new goog.math.Size(0, 25); setValue(text); setValidator(opt_validator); } /// /// Name of field. Unique within each block. /// Static labels are usually unnamed. /// public string name; /// /// Maximum characters of text to display before adding an ellipsis. /// public int maxDisplayLength; /// /// Non-breaking space. /// [Name(false)] public const string NBSP = "\u00A0"; /// /// Editable fields are saved by the XML renderer, non-editable fields are not. /// [Name(false)] public bool EDITABLE = true; /// /// Attach this field to a block. /// /// The block containing this field. public void setSourceBlock(Block block) { throw new NotImplementedException(); } /// /// Install this field on a block. /// public virtual void init() { throw new NotImplementedException(); } /// /// Dispose of all DOM objects belonging to this editable field. /// public virtual void dispose() { throw new NotImplementedException(); } /// /// Add or remove the UI indicating if this field is editable or not. /// public void updateEditable() { throw new NotImplementedException(); } /// /// Gets whether this editable field is visible or not. /// /// True if visible. public bool isVisible() { throw new NotImplementedException(); } /// /// Sets whether this editable field is visible or not. /// /// True if visible. public void setVisible(bool visible) { throw new NotImplementedException(); } /// /// Sets a new validation function for editable fields. /// /// New validation function, or null. public virtual void setValidator(Func handler) { throw new NotImplementedException(); } /// /// Gets the validation function for editable fields. /// /// Validation function, or null. public Func getValidator() { throw new NotImplementedException(); } /// /// Gets the group element for this editable field. /// Used for measuring the size and for positioning. /// /// The group element. public virtual Element getSvgRoot() { throw new NotImplementedException(); } /// /// Start caching field widths. Every call to this function MUST also call /// stopCache. Caches must not survive between execution threads. /// public void startCache() { throw new NotImplementedException(); } /// /// Stop caching field widths. Unless caching was already on when the /// corresponding call to startCache was made. /// public void stopCache() { throw new NotImplementedException(); } /// /// Returns the height and width of the field. /// /// Height and width. public goog.math.Size getSize() { throw new NotImplementedException(); } /// /// Get the text from this field. /// /// Current text. public virtual string getText() { throw new NotImplementedException(); } /// /// Set the text in this field. Trigger a rerender of the source block. /// /// New text. public virtual void setText(string text) { throw new NotImplementedException(); } /// /// By default there is no difference between the human-readable text and /// the language-neutral values. Subclasses (such as dropdown) may define this. /// /// Current text. public virtual string getValue() { throw new NotImplementedException(); } /// /// By default there is no difference between the human-readable text and /// the language-neutral values. Subclasses (such as dropdown) may define this. /// /// New text. public virtual void setValue(string newText) { throw new NotImplementedException(); } /// /// Change the tooltip text for this field. /// /// newTip Text for tooltip or a parent element to /// link to for its tooltip. public virtual void setTooltip(Union newTip) { throw new NotImplementedException(); } } [External, Name("Blockly.FieldLabel")] public class FieldLabel : Field { /// /// Class for a non-editable field. /// /// The initial content of the field. /// Optional CSS class for the field's text. public FieldLabel(string text, string opt_class = null) : base(text) { } /// /// Install this text on a block. /// public override void init() { base.init(); } /// /// Dispose of all DOM objects belonging to this text. /// public override void dispose() { base.dispose(); } /// /// Gets the group element for this field. /// Used for measuring the size and for positioning. /// /// public override Element getSvgRoot() { return base.getSvgRoot(); } /// /// Change the tooltip text for this field. /// /// Text for tooltip or a parent element to /// link to for its tooltip. public override void setTooltip(Union newTip) { base.setTooltip(newTip); } } [External, Name("Blockly.FieldCheckbox")] public class FieldCheckbox : Field { /// /// Class for a checkbox field. /// /// The initial state of the field ('TRUE' or 'FALSE'). /// A function that is executed when a new /// option is selected. Its sole argument is the new checkbox state. If /// it returns a value, this becomes the new checkbox state, unless the /// value is null, in which case the change is aborted. public FieldCheckbox(string state, Func opt_validator = null) : base("", opt_validator) { } /// /// Character for the checkmark. /// public string CHECK_CHAR = "\u2713"; /// /// Mouse cursor style when over the hotspot that initiates editability. /// public string CURSOR = "default"; /// /// Install this checkbox on a block. /// public override void init() { base.init(); } /// /// Return 'TRUE' if the checkbox is checked, 'FALSE' otherwise. /// /// Current state. public override string getValue() { return base.getValue(); } /// /// Set the checkbox to be checked if strBool is 'TRUE', unchecks otherwise. /// /// New state. public override void setValue(string strBool) { base.setValue(strBool); } } [External, Name("Blockly.FieldDropdown")] public class FieldDropdown : Field { /// /// Class for an editable dropdown field. /// /// An array of /// options for a dropdown list, or a function which generates these options. /// A function that is executed when a new /// option is selected, with the newly selected value as its sole argument. /// If it returns a value, that value (which must be one of the options) will /// become selected in place of the newly selected option, unless the return /// value is null, in which case the change is aborted. /// public FieldDropdown(Union> menuGenerator, Func opt_validator = null) : base(menuGenerator.As()[0][1], opt_validator) { } /// /// Horizontal distance that a checkmark ovehangs the dropdown. /// public int CHECKMARK_OVERHANG = 25; /// /// Android can't (in 2014) display "▾", so use "▼" instead. /// public string ARROW_CHAR = "\u25BE"; /// /// Mouse cursor style when over the hotspot that initiates the editor. /// public string CURSOR = "default"; /// /// Install this dropdown on a block. /// public override void init() { base.init(); } /// /// Get the language-neutral value from this dropdown menu. /// /// Current text. public override string getValue() { return base.getValue(); } /// /// Set the language-neutral value for this dropdown menu. /// /// New value to set. public override void setValue(string newText) { base.setValue(newText); } /// /// Set the text in this field. Trigger a rerender of the source block. /// /// New text. public override void setText(string text) { base.setText(text); } /// /// Close the dropdown menu if this input is being deleted. /// public override void dispose() { base.dispose(); } } [External, Name("Blockly.FieldTextInput")] public class FieldTextInput : Field { public Action onFinishEditing_; /// /// Class for an editable text field. /// /// The initial content of the field. /// An optional function that is called /// to validate any constraints on what the user entered. Takes the new /// text as an argument and returns either the accepted text, a replacement /// text, or null to abort the change. public FieldTextInput(string text, Func opt_validator = null) : base(text, opt_validator) { } /// /// Point size of text. Should match blocklyText's font-size in CSS. /// public int FONTSIZE = 11; /// /// Mouse cursor style when over the hotspot that initiates the editor. /// public string CURSOR = "text"; /// /// Close the input widget if this input is being deleted. /// public override void dispose() { base.dispose(); } /// /// Set the text in this field. /// /// New text. public override void setValue(string text) { base.setValue(text); } /// /// Set whether this field is spellchecked by the browser. /// /// True if checked. public void setSpellcheck(bool check) { throw new NotImplementedException(); } /// /// Ensure that only a number may be entered. /// /// The user's text. /// A string representing a valid number, or null if invalid. public virtual string numberValidator(string text) { throw new NotImplementedException(); } /// /// Ensure that only a nonnegative integer may be entered. /// /// The user's text. /// A string representing a valid int, or null if invalid. public string nonnegativeIntegerValidator(string test) { throw new NotImplementedException(); } } [External, Name("Blockly.FieldDate")] public class FieldDate : Field { /// /// Class for a date input field. /// /// The initial date. /// A function that is executed when a new /// date is selected. Its sole argument is the new date value. Its /// return value becomes the selected date, unless it is undefined, in /// which case the new date stands, or it is null, in which case the change /// is aborted. public FieldDate(string date, Func opt_validator = null) : base(date, opt_validator) { } /// /// Mouse cursor style when over the hotspot that initiates the editor. /// public string CURSOR = "text"; /// /// Close the colour picker if this input is being deleted. /// public override void dispose() { base.dispose(); } /// /// Return the current date. /// /// Current date. public override string getValue() { return base.getValue(); } /// /// Set the date. /// /// The new date. public override void setValue(string newText) { base.setValue(newText); } /// /// CSS for date picker. See css.js for use. /// public string[] CSS = new string[0]; } [External, Name("Blockly.FieldColour")] public class FieldColour : Field { /// /// Class for a colour input field. /// /// The initial colour in '#rrggbb' format. /// A function that is executed when a new /// colour is selected. Its sole argument is the new colour value. Its /// return value becomes the selected colour, unless it is undefined, in /// which case the new colour stands, or it is null, in which case the change /// is aborted. public FieldColour(string colour, Func opt_validator = null) : base(colour, opt_validator) { } /// /// Install this field on a block. /// public override void init() { base.init(); } /// /// Mouse cursor style when over the hotspot that initiates the editor. /// public string CURSOR = "default"; /// /// Close the colour picker if this input is being deleted. /// public override void dispose() { base.dispose(); } /// /// Return the current colour. /// /// Current colour in '#rrggbb' format. public override string getValue() { return base.getValue(); } /// /// Set the colour. /// /// The new colour in '#rrggbb' format. public override void setValue(string colour) { base.setValue(colour); } /// /// Get the text from this field. Used when the block is collapsed. /// /// Current text. public override string getText() { return base.getText(); } /// /// An array of colour strings for the palette. /// See bottom of this page for the default: /// http://docs.closure-library.googlecode.com/git/closure_goog_ui_colorpicker.js.source.html /// public string[] COLOURS = new string[0]; /// /// Set a custom colour grid for this field. /// /// Array of colours for this block, /// or null to use default (FieldColour.COLOURS). /// Returns itself (for method chaining). public FieldColour setColours(string[] colours) { throw new NotImplementedException(); } /// /// Set a custom grid size for this field. /// /// Number of columns for this block, /// or 0 to use default (FieldColour.COLUMNS). /// Returns itself (for method chaining). public FieldColour setColumns(int columns) { throw new NotImplementedException(); } } [External, Name("Blockly.FieldNumber")] public class FieldNumber : FieldTextInput { /// /// Class for an editable number field. /// /// The initial content of the field. /// Minimum value. /// Maximum value. /// Precision for value. /// An optional function that is called /// to validate any constraints on what the user entered. Takes the new /// text as an argument and returns either the accepted text, a replacement /// text, or null to abort the change. public FieldNumber(string value, Union opt_min, Union opt_max, Union opt_precision, Func opt_validator = null) : base(value, opt_validator) { } /// /// Set the maximum, minimum and precision constraints on this field. /// Any of these properties may be undefiend or NaN to be disabled. /// Setting precision (usually a power of 10) enforces a minimum step between /// values. That is, the user's value will rounded to the closest multiple of /// precision. The least significant digit place is inferred from the precision. /// Integers values can be enforces by choosing an integer precision. /// /// Minimum value. /// Maximum value. /// Precision for value. public void setConstraints(Union min, Union max, Union precision) { throw new NotImplementedException(); } /// /// Sets a new change handler for number field. /// /// New change handler, or null. public override void setValidator(Func handler) { base.setValidator(handler); } /// /// Ensure that only a number in the correct range may be entered. /// /// The user's text. /// A string representing a valid number, or null if invalid. public override string numberValidator(string text) { return base.numberValidator(text); } } [External, Name("Blockly.FieldAngle")] public class FieldAngle : FieldTextInput { /// /// Class for an editable angle field. /// /// The initial content of the field. /// An optional function that is called /// to validate any constraints on what the user entered. Takes the new /// text as an argument and returns the accepted text or null to abort /// the change. public FieldAngle(string text, Func opt_validator = null) : base(text, opt_validator) { } /// /// Sets a new change handler for angle field. /// /// New change handler, or null. public override void setValidator(Func handler) { base.setValidator(handler); } /// /// Round angles to the nearest 15 degrees when using mouse. /// Set to 0 to disable rounding. /// public int ROUND = 15; /// /// Half the width of protractor image. /// public static int HALF = 100 / 2; /// /// Angle increases clockwise (true) or counterclockwise (false). /// public bool CLOCKWISE = false; /// /// Offset the location of 0 degrees (and all angles) by a constant. /// Usually either 0 (0 = right) or 90 (0 = up). /// public int OFFSET = 0; /// /// Maximum allowed angle before wrapping. /// Usually either 360 (for 0 to 359.9) or 180 (for -179.9 to 180). /// public int WRAP = 360; /// /// Radius of protractor circle. Slightly smaller than protractor size since /// otherwise SVG crops off half the border at the edges. /// public int RADIUS = HALF - 1; /// /// Set the angle to match the mouse's position. /// /// Mouse move event. public void onMouseMove(Event e) { throw new NotImplementedException(); } /// /// Insert a degree symbol. /// /// New text. public override void setText(string text) { base.setText(text); } /// /// Ensure that only an angle may be entered. /// /// The user's text. /// A string representing a valid angle, or null if invalid. public string angleValidator(string text) { throw new NotImplementedException(); } } [External, Name("Blockly.FieldImage")] public class FieldImage : Field { /// /// Class for an image. /// /// The URL of the image. /// Width of the image. /// Height of the image. /// Optional alt text for when block is collapsed. public FieldImage(string src, int width, int height, string opt_alt = "") : base(src) { } /// /// Install this image on a block. /// public override void init() { base.init(); } /// /// Dispose of all DOM objects belonging to this text. /// public override void dispose() { base.dispose(); } /// /// Change the tooltip text for this field. /// /// Text for tooltip or a parent element to /// link to for its tooltip. public override void setTooltip(Union newTip) { base.setTooltip(newTip); } /// /// Get the source URL of this image. /// /// Current text. public override string getValue() { return base.getValue(); } /// /// Set the source URL of this image. /// /// New source. public override void setValue(string newText) { base.setValue(newText); } /// /// Set the alt text of this image. /// /// New alt text. public override void setText(string alt) { base.setText(alt); } } [External, Name("Blockly.FieldVariable")] public class FieldVariable : Field { /// /// Class for a variable's dropdown field. /// /// The default name for the variable. If null, /// a unique variable name will be generated. /// A function that is executed when a new /// option is selected. Its sole argument is the new option value. public FieldVariable(string varname, Func opt_validator = null) : base(varname, opt_validator) { } /// /// Sets a new change handler for angle field. /// /// New change handler, or null. public override void setValidator(Func handler) { base.setValidator(handler); } /// /// Install this dropdown on a block. /// public override void init() { base.init(); } /// /// Get the variable's name (use a variableDB to convert into a real name). /// Unline a regular dropdown, variables are literal and have no neutral value. /// /// Current text. public override string getValue() { return base.getValue(); } /// /// Set the variable name. /// /// New text. public override void setValue(string newValue) { base.setValue(newValue); } /// /// Return a sorted list of variable names for variable dropdown menus. /// Include a special option at the end for creating a new variable name. /// /// Array of variable names. public string[] dropdownCreate() { throw new NotImplementedException(); } /// /// Event handler for a change in variable name. /// Special case the 'New variable...' and 'Rename variable...' options. /// In both of these special cases, prompt the user for a new name. /// /// The selected dropdown menu option. /// An acceptable new variable name, or null if /// change is to be either aborted (cancel button) or has been already /// handled (rename), or undefined if an existing variable was chosen. public string dropdownChange(string text) { throw new NotImplementedException(); } } [External, Name("Blockly.Rectangle")] public class Rectangle { public goog.math.Coordinate topLeft; public goog.math.Coordinate bottomRight; } [External, Name("Blockly.ContextMenu")] public class ContextMenu { public static Action callbackFactory(Block block, Element xml) { throw new NotImplementedException(); } } [External, Name("Blockly.FlyoutButton")] public class FlyoutButton { internal Workspace getTargetWorkspace() { throw new NotImplementedException(); } } /// /// Allow for switching between one and zero based indexing for lists and text, /// one based by default. /// [External, Name("Blockly.Blocks")] public class Blocks { public bool ONE_BASED_INDEXING = true; } } /// /// Google's common JavaScript library /// https://developers.google.com/closure/library/ /// [External] public static class goog { public static string getMsg(string str, object opt_values) { throw new NotImplementedException(); } public static class dom { public static Element createDom(string v, object o = null, Union t = null) { throw new NotImplementedException(); } } public static class math { public class Size { public double width; public double height; public Size(double width, double hieght) { this.width = width; this.height = hieght; } } public class Coordinate { public double x; public double y; } } public static class @string { public class CaseInsensitiveCompare : IComparer { public int Compare(string x, string y) { return x.ToLower().CompareTo(y.ToLower()); } } public static CaseInsensitiveCompare caseInsensitiveCompare = new CaseInsensitiveCompare(); } public static class array { internal static bool equals(Array a, Array b) { throw new NotImplementedException(); } } public static class asserts { internal static void assert(bool cond, string format, params string[] args) { if (!cond) throw new NotImplementedException(); } internal static void assertArray(object array, string format, params string[] args) { assert(array is Array, format, args); } internal static void assertFunction(object func, string format, params string[] args) { assert(func is System.Reflection.MethodInfo, format, args); } internal static void assertString(object str, string format, params string[] args) { assert(str is String, format, args); } internal static void fail(string format, params string[] args) { throw new NotImplementedException(); } } }