ianstormtaylor / slate-plugins

A set of my personal Slate editor plugins, in a monorepo.
https://slate-plugins.netlify.com
Other
248 stars 68 forks source link

Could not get Autoreplace to work #39

Open FrancisVila opened 5 years ago

FrancisVila commented 5 years ago

This module's objective fits exactly what I'm trying to do, but I can't get it to work! it does not produce any errors, but when I type (c) in the editor nothing happens.

I installed it with npm install --save slate-auto-replace

VScode give me a warning on the import import AutoReplace from 'slate-auto-replace' the suggestion goes like this:

Could not find a declaration file for module 'slate-auto-replace'. 'c:/react/hoveringmenu/node_modules/slate-auto-replace/lib/slate-auto-replace.js' implicitly has an 'any' type. Try npm install @types/slate-auto-replace if it exists or add a new declaration (.d.ts) file containing declare module 'slate-auto-replace';

npm install @types/slate-auto-replace gives an error. 404 Not Found: @types/slate-auto-replace@latest

Here's the code of my app;

import AutoReplace from 'slate-auto-replace'

const  plugins = [
  AutoReplace({
    trigger: ')',
    before: /(\(c)$/i,
// i also tried without the before
    change: transform => transform.insertText('©')
  }),
]

  render() {
    return (
      <div>
        <Editor
          placeholder="Enter some text..."
          value={this.state.value}
          onChange={this.onChange}
          renderEditor={this.renderEditor}
          renderMark={this.renderMark}
          onKeyDown={this.onKeyDown}
          plugins={plugins}
        />
      </div>
    )
  }
arnaudambro commented 2 years ago

I don't know why it's not working but VSCode warning has nothing to do with this. If I paraphrase VSCode warning, I'd say :

Hey you user ! There is no types and no TypeScript in this project... yet. Which is fine, but maybe the author of the library put the types outside slate-auto-replace, like in @types/slate-auto-replace ? You can try to installed @types/slate-auto-replace if you want

which you did, but @types/slate-auto-replace does not exist, that's why you got a 404.

This being said, it doesn't tell you why it's not working. Sorry !