Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body onload="init()">
  <div id="myDiagramDiv" style="border: solid 1px black; width:400px; height:400px"></div>
  <p><a href="https://gojs.net"/>gojs.net<a/></p>
</body>
              
            
!

CSS

              
                
              
            
!

JS

              
                function init() {
  var $ = go.GraphObject.make;

  myDiagram =
    $(go.Diagram, "myDiagramDiv",
      {
        // default text editor is now a SelectBox
        'textEditingTool.defaultTextEditor': window.TextEditorSelectBox, // defined in textEditorSelectBox.js
        'textEditingTool.starting': go.TextEditingStarting.SingleClick,
        "undoManager.isEnabled": true
      }
    );

  // define a simple Node template
  myDiagram.nodeTemplate =
    $(go.Node, "Auto",  // the Shape will go around the TextBlock
      $(go.Shape, "RoundedRectangle", { strokeWidth: 0 },
        // Shape.fill is bound to Node.data.color
        new go.Binding("fill", "color")),
      $(go.TextBlock,
        { margin: 8, editable: true, text: 'Alpha' },  // some room around the text
        new go.Binding('choices'))
    );

  // but use the default Link template, by not setting Diagram.linkTemplate

  // create the model data that will be represented by Nodes and Links
  myDiagram.model = new go.GraphLinksModel(
  [
    { key: "Alpha", color: "lightblue", choices: ['Alpha', 'Beta', 'Gamma', 'Theta'] },
    { key: "Beta", color: "orange", choices: ['Alpha', 'Beta', 'Gamma', 'Theta'] },
    { key: "Gamma", color: "lightgreen", choices: ['Alpha', 'Beta', 'Gamma', 'Theta'] },
    { key: "Delta", color: "pink", choices: ['Alpha', 'Beta', 'Gamma', 'Theta'] }
  ],
  [
    { from: "Alpha", to: "Beta" },
    { from: "Alpha", to: "Gamma" },
    { from: "Beta", to: "Beta" },
    { from: "Gamma", to: "Delta" },
    { from: "Delta", to: "Alpha" }
  ]);
}

/*
 *  Copyright (C) 1998-2024 by Northwoods Software Corporation. All Rights Reserved.
 */
/*
 * This is an extension and not part of the main GoJS library.
 * Note that the API for this class may change with any version, even point releases.
 * If you intend to use an extension in production, you should copy the code to your own source directory.
 * Extensions can be found in the GoJS kit under the extensions or extensionsJSM folders.
 * See the Extensions intro page (https://gojs.net/latest/intro/extensions.html) for more information.
 */

// HTML + JavaScript text editor using an HTML Select Element and HTMLInfo.
// This file exposes one instance of HTMLInfo, window.TextEditorSelectBox
// Typical usage is:
// ```js
//   new go.Diagram(...,
//      {
//        "textEditingTool.defaultTextEditor": window.TextEditorSelectBox,
//        . . .
//      })
// ```
// or:
// ```js
//    myDiagram.toolManager.textEditingTool.defaultTextEditor = window.TextEditorSelectBox;
// ```
// or:
// ```js
//   $(go.Node, . . .,
//     . . .
//       $(go.TextBlock, { textEditor: window.TextEditorSelectBox, . . . })
//     . . .
//   )
// ```
// see /samples/customTextEditingTool.html
// see also textEditorRadioButton.js for another custom editor
// see also textEditor.html for a re-implementation of the default text editor
((window) => {
    const inputElement = document.createElement('nav');
    const customEditor = new go.HTMLInfo();
    customEditor.show = (textBlock, diagram, tool) => {
        if (!(textBlock instanceof go.TextBlock))
            return;
        // Populate the select box:
        inputElement.innerHTML = '';
        var part = textBlock.part;
        const choices = textBlock.choices; // Array of choice strings
        const initialValue = textBlock.text; // Selected option initially
        const loc = textBlock.getDocumentPoint(go.Spot.TopLeft);
        const pos = diagram.transformDocToView(loc);
        inputElement.style.border = '1px solid #ccc';
        inputElement.style.padding = '8px';
        inputElement.style.cursor = 'pointer';
        inputElement.style.backgroundColor = '#fff';
        inputElement.style.borderRadius = '4px'; // Rounded corners
        inputElement.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.1)';
        inputElement.style.position = 'absolute';
        inputElement.style.left = `${pos.x}px`;
        inputElement.style.top = `${pos.y + 13}px`;
        inputElement.style.zIndex = '100';
        // Add transition for smooth effect
        inputElement.style.transition = 'border-color 0.2s';
        inputElement.value = initialValue;  // ensure value is set to current text
        
        const dropdownList = document.createElement('ul');
        dropdownList.style.listStyleType = 'none';
        dropdownList.style.margin = '0';
        dropdownList.style.padding = '0';
        dropdownList.style.border = '1px solid #ccc';
        dropdownList.style.borderRadius = '4px'; // Rounded corners
        dropdownList.style.maxHeight = '200px'; // Maximum height
        dropdownList.style.overflowY = 'auto'; // Scroll if too many items
        dropdownList.style.backgroundColor = '#fff';
        // Populate the dropdown list
        choices.forEach(choice => {
          const listItem = document.createElement('li');
          listItem.innerText = choice;
          listItem.style.padding = '8px'; // Padding for list items
          listItem.style.cursor = 'pointer';
          listItem.style.width = '20rem';
          listItem.style.border = '0.1rem solid #e7e7e7';
          initialValue === choice ? listItem.style.backgroundColor = 'blue' : true;

          // Add hover effect
          listItem.addEventListener('mouseenter', () => {
            initialValue !== choice ? listItem.style.backgroundColor = '#e9e9e9' : true; // Highlight on hover
          });
          listItem.addEventListener('mouseleave', () => {
            initialValue !== choice ? listItem.style.backgroundColor = 'white' : true;
          });

          // Handle the selection
          listItem.addEventListener('click', () => selectChoice(choice));
          dropdownList.appendChild(listItem);
        });
       inputElement.appendChild(dropdownList);
        diagram.div?.appendChild(inputElement);

        var selectChoice = (choice) => {
          inputElement.value = choice;
          tool.acceptText(go.TextEditingAccept.Tab);
        };
    };
    customEditor.hide = (diagram, tool) => {
        if (diagram.div !== null)
            diagram.div.removeChild(inputElement);
    };
    customEditor.valueFunction = () => inputElement.value;
    window.TextEditorSelectBox = customEditor;
})(window);

              
            
!
999px

Console