How to use the slate.Editor function in slate

To help you get started, we’ve selected a few slate 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 enzoferey / slate-instant-replace / test / index.js View on Github external
it("should ignore the event", () => {
      const value = initialValue;
      const fakeTransform = fake();
      const plugins = [AutoReplacePlugin(fakeTransform)];
      let simulator = new Editor({ value, plugins });

      // Press enter
      simulator.run("onKeyDown", keyEvent("Enter"));

      expect(fakeTransform.callCount).to.equal(0);
    });
  });
github enzoferey / slate-instant-replace / test / getLastWord.js View on Github external
it("should return the last word", () => {
      const editor = new Editor({ value: Plain.deserialize("hello world") });

      // Anchor at the end of the first word
      expect(getLastWord(editor.moveForward(5))).to.equal("hello");

      // Anchor at the beginning of the second word
      expect(getLastWord(editor.moveForward(1))).to.equal("");

      // Anchor at the end of the second word
      expect(getLastWord(editor.moveForward(5))).to.equal("world");
    });
  });
github ahixon / slate-sync-bridge / test / slate / bridge.js View on Github external
fixtures(__dirname, 'commands', ({ module }) => {
      const { input, output, options = {}, plugins: module_plugins } = module
      const fn = module.default
      const editor = new Editor({
        plugins: module_plugins ? plugins.concat(module_plugins) : plugins,
      })
      const opts = { preserveSelection: true, ...options }
      // if (Object.keys(options).length) {
      //   throw new TypeError('bad test, cannot use options yet');
      // }

      const inputSyncDoc = toSyncDocument(input.document.toJSON());
      
      editor.setValue(input)
      fn(editor)
      
      // re-apply the operations from the test
      const actualSyncDoc = editor.operations.reduce((doc, op) => applyOperation(doc, op), inputSyncDoc);
      const actualDoc = toSlateDocument(actualSyncDoc)
github ConvertKit / slate-plugins / packages / slate-testing-library / src / index.js View on Github external
const createUnnormalizedValue = children => {
    const editor = new Editor({
      normalize: false
    });
    const value = html`
      
        ${children}
      
    `;

    editor.setValue(value);
    return editor.value;
  };

  const editor = new Editor(options);

  return { editor, createValue, createUnnormalizedValue };
};
github ConvertKit / slate-plugins / packages / slate-testing-library / src / index.js View on Github external
const createUnnormalizedValue = children => {
    const editor = new Editor({
      normalize: false
    });
    const value = html`
      
        ${children}
      
    `;

    editor.setValue(value);
    return editor.value;
  };
github ianstormtaylor / slate / packages / slate-react / src / components / editor.js View on Github external
this.tmp.resolves++
      const react = TheReactPlugin({
        ...this.props,
        editor: this,
        value: this.props.value || this.state.value,
      })

      const onChange = change => {
        if (this.tmp.mounted) {
          this.handleChange(change)
        } else {
          this.tmp.change = change
        }
      }

      this.controller = new Controller(
        { plugins: [react], onChange },
        { controller: this, construct: false }
      )

      this.controller.run('onConstruct')
    }
  )
github ianstormtaylor / slate / benchmark / slate / models / get-texts-at-range.js View on Github external
{Array.from(Array(10)).map(() => (
        
          
            
              This is editable <b>rich</b> text, <i>much</i> better than a
              textarea!
            
          
        
      ))}
    
  
)

const editor = new Editor({ value })
editor.moveToRangeOfDocument()
value = editor.value

module.exports.input = function() {
  return value
}
github ianstormtaylor / slate / benchmark / slate / models / get-leaf-blocks-at-range.js View on Github external
{Array.from(Array(10)).map(() =&gt; (
        
          
            
              This is editable <b>rich</b> text, <i>much</i> better than a
              textarea!
            
          
        
      ))}
    
  
)

const editor = new Editor({ value })
editor.moveToRangeOfDocument()
value = editor.value

module.exports.input = () =&gt; {
  return value
}
github ianstormtaylor / slate / benchmark / slate / models / get-marks-at-range.js View on Github external
{Array.from(Array(10)).map(() =&gt; (
        
          
            
              This is editable <b>rich</b> text, <i>much</i> better than a
              textarea!
            
          
        
      ))}
    
  
)

const editor = new Editor({ value })
editor.moveToRangeOfDocument()
value = editor.value

module.exports.input = function() {
  return value
}