constructor()

in src/executable-code/index.js [75:175]


  constructor(target, config = {}, eventFunctions) {
    const targetNode = typeof target === 'string' ? document.querySelector(target) : target;
    let highlightOnly = config.highlightOnly ? true
      : targetNode.getAttribute(ATTRIBUTES.HIGHLIGHT_ONLY) === READ_ONLY_TAG
        ? targetNode.getAttribute(ATTRIBUTES.HIGHLIGHT_ONLY)
        : targetNode.hasAttribute(ATTRIBUTES.HIGHLIGHT_ONLY);
    const noneMarkers = targetNode.hasAttribute(ATTRIBUTES.NONE_MARKERS);
    const indent = targetNode.hasAttribute(ATTRIBUTES.INDENT) ? parseInt(targetNode.getAttribute(ATTRIBUTES.INDENT)) : DEFAULT_INDENT;
    const from = targetNode.hasAttribute(ATTRIBUTES.FROM) ? parseInt(targetNode.getAttribute(ATTRIBUTES.FROM)) : null;
    const to = targetNode.hasAttribute(ATTRIBUTES.TO) ? parseInt(targetNode.getAttribute(ATTRIBUTES.TO)) : null;
    const editorTheme = this.getTheme(targetNode);
    const args = targetNode.hasAttribute(ATTRIBUTES.ARGUMENTS) ? targetNode.getAttribute(ATTRIBUTES.ARGUMENTS) : "";
    const hiddenDependencies = this.getHiddenDependencies(targetNode);
    const outputHeight = targetNode.getAttribute(ATTRIBUTES.OUTPUT_HEIGHT) || null;
    const targetPlatform = getTargetById(targetNode.getAttribute(ATTRIBUTES.PLATFORM)) || TargetPlatforms.JAVA;
    const targetNodeStyle = targetNode.getAttribute(ATTRIBUTES.STYLE);
    const jsLibs = this.getJsLibraries(targetNode, targetPlatform);
    const isFoldedButton = targetNode.getAttribute(ATTRIBUTES.FOLDED_BUTTON) !== "false";
    const lines = targetNode.getAttribute(ATTRIBUTES.LINES) === "true";
    const onFlyHighLight = targetNode.getAttribute(ATTRIBUTES.ON_FLY_HIGHLIGHT) === "true";
    const autoComplete = targetNode.getAttribute(ATTRIBUTES.COMPLETE) === "true";
    const matchBrackets = targetNode.getAttribute(ATTRIBUTES.MATCH_BRACKETS) === "true";
    const autoIndent = targetNode.getAttribute(ATTRIBUTES.AUTO_INDENT) === "true";
    const dataTrackRunId = targetNode.getAttribute(ATTRIBUTES.TRACK_RUN_ID);
    const dataShorterHeight = targetNode.getAttribute(ATTRIBUTES.SHORTER_HEIGHT);
    const dataScrollbarStyle = targetNode.getAttribute(ATTRIBUTES.SCROLLBAR_STYLE);
    const mode = this.getMode(targetNode);
    const code = replaceWhiteSpaces(targetNode.textContent);
    const cfg = merge(defaultConfig, config);

    // no run code in none kotlin mode
    if (mode !== MODES.KOTLIN && highlightOnly !== READ_ONLY_TAG) {
      highlightOnly = true;
    }

    let crosslink = null;

    const crosslinkValue = targetNode.getAttribute(ATTRIBUTES.CROSSLINK);

    const isCrosslinkDisabled = (
      crosslinkValue !== 'enabled' && (
        crosslinkValue === 'disabled' || // disabled by developer
        highlightOnly || // highlighted only not worked in...
        ( // Unsupported external deps
          (jsLibs && !!jsLibs.size) ||
          (hiddenDependencies && hiddenDependencies.length > 0)
        )
      )
    );

    if (!isCrosslinkDisabled) crosslink = generateCrosslink(code, {
      code: code,
      targetPlatform: targetPlatform.id,
      // hiddenDependencies, // multi-file support needs
      compilerVersion: cfg.compilerVersion,
    });

    let shorterHeight = parseInt(dataShorterHeight, 10) || 0;

    targetNode.style.display = 'none';
    targetNode.setAttribute(INITED_ATTRIBUTE_NAME, 'true');
    const mountNode = document.createElement('div');
    insertAfter(mountNode, targetNode);

    const view = ExecutableFragment.render(mountNode, {eventFunctions});
    view.update(Object.assign({
      code: code,
      lines: lines,
      theme: editorTheme,
      indent: indent,
      args: args,
      mode: mode,
      crosslink,
      matchBrackets: matchBrackets,
      from: from,
      to: to,
      autoComplete: autoComplete,
      hiddenDependencies: hiddenDependencies,
      compilerVersion: cfg.compilerVersion,
      noneMarkers: noneMarkers,
      onFlyHighLight: onFlyHighLight,
      autoIndent: autoIndent,
      highlightOnly: highlightOnly,
      targetPlatform: targetPlatform,
      jsLibs: jsLibs,
      isFoldedButton: isFoldedButton,
      dataTrackRunId,
      shorterHeight,
      outputHeight,
      scrollbarStyle: dataScrollbarStyle
    }, eventFunctions));

    this.config = cfg;
    this.node = mountNode;
    this.targetNode = targetNode;
    this.targetNodeStyle = targetNodeStyle;
    this.view = view;

    targetNode.KotlinPlayground = this;
    if (eventFunctions && eventFunctions.callback) eventFunctions.callback(targetNode, mountNode);
  }