How to use the slate-plain-serializer.serialize function in slate-plain-serializer

To help you get started, we’ve selected a few slate-plain-serializer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github grafana / grafana / public / app / plugins / datasource / grafana-azure-monitor-datasource / editor / KustoQueryField.tsx View on Github external
// distinct
      } else if (modelPrefix.match(/(distinct\s(.+\b)?$)/i)) {
        typeaheadContext = 'context-distinct';
        suggestionGroups = this.getColumnSuggestions();

        // database()
      } else if (modelPrefix.match(/(database\(\"(\w+)\"\)\.(.+\b)?$)/i)) {
        typeaheadContext = 'context-database-table';
        const db = this.getDBFromDatabaseFunction(modelPrefix);
        console.log(db);
        suggestionGroups = this.getTableSuggestions(db);
        prefix = prefix.replace('.', '');

        // new
      } else if (normalizeQuery(Plain.serialize(this.state.value)).match(/^\s*\w*$/i)) {
        typeaheadContext = 'context-new';
        if (this.schema) {
          suggestionGroups = this.getInitialSuggestions();
        } else {
          this.fetchSchema();
          setTimeout(this.onTypeahead, 0);
          return;
        }

        // built-in
      } else if (prefix && !wrapperClasses.contains('argument') && !force) {
        // Use only last typed word as a prefix for searching
        if (modelPrefix.match(/\s$/i)) {
          prefix = '';
          return;
        }
github OpusCapita / react-markdown / src / client / components / PlainMarkdownInput / PlainMarkdownInput.react.js View on Github external
}
    }

    if (numBlock !== -1) {
      const text = editorState.texts.get(0).text;
      const nodes = editorState.document.nodes.asMutable();
      this.setDataToNode(nodes, numBlock, text);
      editorState = this.setNodesToState(editorState, nodes);
    }

    // Slate emits onChange not only when text changes,
    // but also when caret changes position or editor gains/loses focus.
    // Slate needs this because it's inner state essentially changes,
    // (cursor position, focused status, etc), but we need to emit only real changes in text value.
    const oldValue = Plain.serialize(this.state.editorState);
    const newValue = Plain.serialize(editorState);
    if (oldValue !== newValue) {
      this.props.onChange(newValue);
    }

    this.setState({ editorState });

    setTimeout(() => {
      autoScrollToTop();
      if (isSetFocus) {
        const editorState = setSelectionToState(this.state.editorState, selection);
        this.setState({ editorState });
      }
    }, 0);
  };
github ianstormtaylor / slate / packages / slate-react / src / utils / clone-fragment.js View on Github external
// COMPAT: In Chrome and Safari, if we don't add the `white-space` style
    // then leading and trailing spaces will be ignored. (2017/09/21)
    span.style.whiteSpace = 'pre'

    span.appendChild(attach)
    contents.appendChild(span)
    attach = span
  }

  attach.setAttribute(DATA_ATTRS.FRAGMENT, encoded)

  //  Creates value from only the selected blocks
  //  Then gets plaintext for clipboard with proper linebreaks for BLOCK elements
  //  Via Plain serializer
  const valFromSelection = Value.create({ document: fragment })
  const plainText = Plain.serialize(valFromSelection)

  // Add the phony content to a div element. This is needed to copy the
  // contents into the html clipboard register.
  const div = window.document.createElement('div')
  div.appendChild(contents)

  // For browsers supporting it, we set the clipboard registers manually,
  // since the result is more predictable.
  // COMPAT: IE supports the setData method, but only in restricted sense.
  // IE doesn't support arbitrary MIME types or common ones like 'text/plain';
  // it only accepts "Text" (which gets mapped to 'text/plain') and "Url"
  // (mapped to 'text/url-list'); so, we should only enter block if !IS_IE
  if (event.clipboardData && event.clipboardData.setData && !IS_IE) {
    event.preventDefault()
    event.clipboardData.setData(TEXT, plainText)
    event.clipboardData.setData(FRAGMENT, encoded)
github olymp / olymp / packages / slate / pug / editor.es6 View on Github external
onChange: change =>
      console.log(
        toSlate(
          Plain.serialize(
            Value.fromJSON({
              document: change,
              kind: 'value',
            }),
          ),
        ),
      ),
  })),
github grafana / grafana / public / app / plugins / datasource / grafana-azure-monitor-datasource / editor / KustoQueryField.tsx View on Github external
private getTableFromContext() {
    const query = Plain.serialize(this.state.value);
    const tablePattern = /^\s*(\w+)\s*|/g;
    const normalizedQuery = normalizeQuery(query);
    const match = tablePattern.exec(normalizedQuery);
    if (match && match.length > 1 && match[0] && match[1]) {
      return match[1];
    } else {
      return null;
    }
  }
github OpusCapita / react-markdown / src / client / components / PlainMarkdownInput / slate / __specs__ / transforms.spec.js View on Github external
change = newState.change();
      newState = wrapHeader(change.state, 5);
      expect(Plain.serialize(newState)).to.equal('##### Header');

      change = newState.change();
      newState = unwrapHeader(change.state, 5);
      expect(Plain.serialize(newState)).to.equal('Header');

      change = newState.change();
      newState = wrapHeader(change.state, 6);
      expect(Plain.serialize(newState)).to.equal('###### Header');

      change = newState.change();
      newState = unwrapHeader(change.state, 6);
      expect(Plain.serialize(newState)).to.equal('Header');
    });
github GridProtectionAlliance / openHistorian / Source / Applications / openHistorian / openHistorian / Grafana / public / app / features / explore / QueryField.tsx View on Github external
updateLogsHighlights = () => {
    const { onChange } = this.props;

    if (onChange) {
      onChange(Plain.serialize(this.state.value));
    }
  };
github grafana / grafana / packages / grafana-ui / src / components / DataLinks / DataLinkInput.tsx View on Github external
const onVariableSelect = (item: VariableSuggestion, editor = editorRef.current!) => {
      const includeDollarSign = Plain.serialize(editor.value).slice(-1) !== '$';
      if (item.origin !== VariableOrigin.Template || item.value === DataLinkBuiltInVars.includeVars) {
        editor.insertText(`${includeDollarSign ? '$' : ''}\{${item.value}}`);
      } else {
        editor.insertText(`var-${item.value}=$\{${item.value}}`);
      }

      setLinkUrl(editor.value);
      setShowingSuggestions(false);

      setSuggestionsIndex(0);
      stateRef.current.onChange(Plain.serialize(editor.value));
    };
github GridProtectionAlliance / openHistorian / Source / Applications / openHistorian / openHistorian / Grafana / public / app / features / explore / QueryField.tsx View on Github external
handleBlur = (event: Event, editor: CoreEditor, next: Function) => {
    const { lastExecutedValue } = this.state;
    const previousValue = lastExecutedValue ? Plain.serialize(this.state.lastExecutedValue) : null;
    const currentValue = Plain.serialize(editor.value);

    if (previousValue !== currentValue) {
      this.executeOnChangeAndRunQueries();
    }

    editor.blur();

    return next();
  };
github OpusCapita / react-markdown / src / client / components / PlainMarkdownInput / PlainMarkdownInput.spec.js View on Github external
value={nodeText}
        fullScreen={false}
        readOnly={false}
      />);

      wrapper = mount(component);
      editorState = wrapper.state('editorState');
      change = editorState.change();
      change.moveOffsetsTo(0, nodeText.length);
      editorState = change.state;
      wrapperInstance = wrapper.instance();
      wrapperInstance.handleChange = sinon.spy();
      wrapperInstance.toggleAccent(editorState, 'italic');
      expect(wrapperInstance.handleChange.callCount).to.equal(1);
      newState = wrapperInstance.handleChange.getCall(0).args[0];
      expect(Plain.serialize(newState)).to.equal('_italic text_');
    });
  });