{"name":"prosemirror-suggest","version":"1.0.0-pr706.d0b3ea524","description":"Primitives for building your prosemirror suggestion and autocomplete functionality","homepage":"https://github.com/remirror/remirror/tree/HEAD/packages/prosemirror-suggest","repository":{"type":"git","url":"https://github.com/remirror/remirror/tree/HEAD/packages/prosemirror-suggest"},"license":"MIT","contributors":[{"name":"Ifiok Jr.","email":"ifiokotung@gmail.com"}],"sideEffects":false,"exports":{".":{"import":"./dist/prosemirror-suggest.esm.js","require":"./dist/prosemirror-suggest.cjs.js","browser":"./dist/prosemirror-suggest.browser.esm.js","types":"./dist/prosemirror-suggest.cjs.d.ts","default":"./dist/prosemirror-suggest.esm.js"},"./package.json":"./package.json","./types/*":"./dist/declarations/src/*.d.ts"},"main":"dist/prosemirror-suggest.cjs.js","module":"dist/prosemirror-suggest.esm.js","browser":{"./dist/prosemirror-suggest.cjs.js":"./dist/prosemirror-suggest.browser.cjs.js","./dist/prosemirror-suggest.esm.js":"./dist/prosemirror-suggest.browser.esm.js"},"types":"dist/prosemirror-suggest.cjs.d.ts","dependencies":{"@babel/runtime":"^7.12.13","@remirror/core-constants":"1.0.0-pr706.d0b3ea524","@remirror/core-helpers":"1.0.0-pr706.d0b3ea524","escape-string-regexp":"^4.0.0","type-fest":"^0.20.2"},"devDependencies":{"@types/prosemirror-keymap":"^1.0.4","@types/prosemirror-model":"^1.11.2","@types/prosemirror-state":"^1.2.6","@types/prosemirror-view":"^1.17.1","prosemirror-model":"^1.13.1","prosemirror-state":"^1.3.4","prosemirror-view":"^1.17.3"},"peerDependencies":{"@types/prosemirror-model":"^1.7.0","@types/prosemirror-state":"^1.2.5","@types/prosemirror-view":"^1.15.0","prosemirror-model":"^1.11.0","prosemirror-state":"^1.3.3","prosemirror-view":"^1.14.9"},"peerDependenciesMeta":{"@types/prosemirror-model":{"optional":true},"@types/prosemirror-state":{"optional":true},"@types/prosemirror-view":{"optional":true}},"publishConfig":{"access":"public"},"@remirror":{"sizeLimit":"10 KB"},"rn:dev":"src/index.ts","readme":"# prosemirror-suggest\n\n> Primitives for building your prosemirror suggestion and autocomplete functionality.\n\n[![Version][version]][npm] [![Weekly Downloads][downloads-badge]][npm] [![Bundled size][size-badge]][size] [![Typed Codebase][typescript]](#) [![MIT License][license]](#)\n\n[version]: https://flat.badgen.net/npm/v/prosemirror-suggest/next\n[npm]: https://npmjs.com/package/prosemirror-suggest/v/next\n[license]: https://flat.badgen.net/badge/license/MIT/purple\n[size]: https://bundlephobia.com/result?p=prosemirror-suggest\n[size-badge]: https://flat.badgen.net/bundlephobia/minzip/prosemirror-suggest\n[typescript]: https://flat.badgen.net/badge/icon/TypeScript?icon=typescript&label\n[downloads-badge]: https://badgen.net/npm/dw/prosemirror-suggest/red?icon=npm\n\n<br />\n\n## The problem\n\nYou want to create a plugin for your prosemirror editor that responds to an activation character to create suggesters or options or actions for the user. Doing this from scratch can be difficult.\n\n## This solution\n\n`prosemirror-suggest` provides the suggestion primitives needed for building this functionality into your editor. You might be building user mentions, emoji search, an actions dropdown or anything that extracts a query from the editor after the activation character(s).\n\nThis implementation doesn't attempt to be magical. There's still a lot of work that goes into setting up your configuration. However, with this toolkit, you you will be building on a well-tested foundation with a structured API.\n\n<br />\n\n## Installation\n\n```bash\n# yarn\nyarn add prosemirror-suggest prosemirror-view prosemirror-state prosemirror-keymap\n\n# pnpm\npnpm add prosemirror-suggest prosemirror-view prosemirror-state prosemirror-keymap\n\n# npm\nnpm install prosemirror-suggest prosemirror-view prosemirror-state prosemirror-keymap\n```\n\nThe installation requires the installation of the peer dependencies `prosemirror-view`, `prosemirror-state` and `prosemirror-model` to avoid version clashes.\n\n<br />\n\n## Getting Started\n\nThis documentation will be updated soon.\n\n`prosemirror-suggest` uses configuration objects called `Suggester`<!-- -->'s to define the behaviour of the suggesters you create. By calling the exported `suggest` method with all required `Suggester`<!-- -->'s the functionality is added to the editor in one plugin.\n\nIn the following example we're creating an emoji suggestion plugin that responds to the colon character with a query and presents a list of matching emojis based on the query typed so far.\n\n```ts\nimport { schema } from 'prosemirror-schema-basic';\nimport { suggest, Suggester } from 'prosemirror-suggest';\n\nconst maxResults = 10;\nlet selectedIndex = 0;\nlet emojiList: string[] = [];\nlet showSuggestions = false;\n\nconst suggestEmojis: Suggester = {\n  // By default decorations are used to highlight the currently matched\n  // suggestion in the dom.\n  // In this example we don't need decorations (in fact they cause problems when the\n  // emoji string replaces the query text in the dom).\n  noDecorations: true,\n  char: ':', // The character to match against\n  name: 'emoji-suggestion', // a unique name\n  appendText: '', // Text to append to the created match\n\n  // Keybindings are similar to prosemirror keymaps with a few extra niceties.\n  // The key identifier can also include modifiers (e.g.) `Cmd-Space: () => false`\n  // Return true to prevent any further keyboard handlers from running.\n  keyBindings: {\n    ArrowUp: () => {\n      selectedIndex = rotateSelectionBackwards(selectedIndex, emojiList.length);\n    },\n    ArrowDown: () => {\n      selectedIndex = rotateSelectionForwards(selectedIndex, emojiList.length);\n    },\n    Enter: ({ command }) => {\n      if (showSuggestions) {\n        command(emojiList[selectedIndex]);\n      }\n    },\n    Esc: () => {\n      showSuggestions = false;\n    },\n  },\n\n  onChange: (params) => {\n    const query = params.query.full;\n    emojiList = sortEmojiMatches({ query, maxResults });\n    selectedIndex = 0;\n    showSuggestions = true;\n  },\n\n  onExit: () => {\n    showSuggestions = false;\n    emojiList = [];\n    selectedIndex = 0;\n  },\n\n  // Create a  function that is passed into the change, exit and keybinding handlers.\n  // This is useful when these handlers are called in a different part of the app.\n  createCommand: ({ match, view }) => {\n    return (emoji, skinVariation) => {\n      if (!emoji) {\n        throw new Error('An emoji is required when calling the emoji suggesters command');\n      }\n\n      const tr = view.state.tr;\n      const { from, end: to } = match.range;\n      tr.insertText(emoji, from, to);\n      view.dispatch(tr);\n    };\n  },\n};\n\n// Create the plugin with the above configuration. It also supports multiple plugins being added.\nconst suggestionPlugin = suggest(suggestEmojis);\n\n// Include the plugin in the created editor state.\nconst state = EditorState.create({ schema, plugins: [suggestionPlugin] });\n```\n\nYou can see this example brought to life in the `remirror` codebase under the `@remirror/extension-emoji` and the `@remirror/extension-mention` packages.\n\nThe following examples are available for you to try out on the [docs site](https://remirror.io/docs/showcase/social)\n\n**Search emoji on `:` key**\n\nThe emojis are inserted as plain text. It’s up to you whether you insert the emoji as a node, mark or plaintext.\n\n![A gif showing emoji being inserted after typing the colon (:) key. First a laughing emoji then a heart and finally the poop emoji](https://media.githubusercontent.com/media/ifiokjr/assets/master/remirror/emoji.gif 'A gif showing emoji being inserted after typing the colon (:) key. First a laughing emoji then a heart and finally the poop emoji')\n\n**Editable mention on `@` key**\n\nEach mention is a mark that wraps the mentioned text with a spec property of `inclusive: false`\n\n![A gif showing mentions being suggested as the user types with editing supported](https://media.githubusercontent.com/media/ifiokjr/assets/master/remirror/mentions.gif 'A gif showing mentions being suggested as the user types with editing supported')\n\n<br />\n\n## Core API\n\n### `suggest`\n\nThis creates a suggestion plugin with all the suggesters provided.\n\n<b>Signature:</b>\n\n```ts\n// eslint-disable-next-line @typescript-eslint/no-unused-expressions\n(...suggesters: Suggester[]) => Plugin;\n```\n\nThe priority of the suggesters is the order in which they are passed into this function.\n\n```ts\nconst plugin = suggest(two, one, three);\n```\n\nIn the above example `two` will be checked first, then `one` and then `three`.\n\nOnly one suggester can match at any given time. The order and specificity of the regex parameters help determines which suggester will be active.\n\n<br />\n\n### `Suggester`\n\nThis `Suggester` interface defines all the options required to create a suggester within your editor.\n\n<b>Signature:</b>\n\n```typescript\nexport interface Suggester<GCommand extends AnyFunction<void> = AnyFunction<void>>\n```\n\n#### Properties\n\n| Property | Type | Description |\n| --- | --- | --- |\n| `appendText` | <code>string</code> | Text to append after the mention has been added. |\n| `char` | <code>string</code> | The activation character(s) to match against. |\n| `ignoredClassName` | <code>string</code> | Set a class for the ignored suggester decoration. |\n| `ignoredTag` | <code>string</code> | Set a tag for the ignored suggester decoration. |\n| `invalidPrefixCharacters` | <code>RegExp &#124; string</code> | A regex expression used to invalidate the text directly before the match. |\n| `keyBindings` | <code>SuggestKeyBindingMap&lt;GCommand&gt;</code> | An object that describes how certain key bindings should be handled. |\n| `matchOffset` | <code>number</code> | Sets the characters that need to be present after the initial character match before a match is triggered. |\n| `name` | <code>string</code> | A unique identifier for the suggester. |\n| `noDecorations` | <code>boolean</code> | When true, decorations are not created when this mention is being edited.. |\n| `startOfLine` | <code>boolean</code> | Whether to only match from the start of the line |\n| `suggestClassName` | <code>string</code> | Class name to use for the decoration (while the suggester is still being written) |\n| `suggestTag` | <code>string</code> | Tag for the prosemirror decoration which wraps an active match. |\n| `supportedCharacters` | <code>RegExp &#124; string</code> | A regex containing all supported characters when within a suggester. |\n| `validPrefixCharacters` | <code>RegExp &#124; string</code> | A regex expression used to validate the text directly before the match. |\n\n#### Methods\n\n| Method | Description |\n| --- | --- |\n| `createCommand(params)` | Create the suggested actions which are made available to the <code>onExit</code> and on<code>onChange</code> handlers. |\n| `onChange(params)` | Called whenever a suggester becomes active or changes in anyway. |\n| `onCharacterEntry(params)` | Called for each character entry and can be used to disable certain characters. |\n| `onExit(params)` | Called when a suggester is exited with the pre-exit match value. |\n\nThe options are passed to the `suggest` method which uses them.\n\n<br />\n\n## Package API\n\n### Enumerations\n\n| Enumeration    | Description                                     |\n| -------------- | ----------------------------------------------- |\n| `ChangeReason` | The potential reason for changes                |\n| `ExitReason`   | The potential reasons for an exit of a mention. |\n\n### Interfaces\n\n| Interface | Description |\n| --- | --- |\n| `AddIgnoredParameter` | The parameters needed for the `SuggestIgnoreParameter.addIgnored()` action method available to the suggest plugin handlers. |\n| `CompareMatchParameter` | A parameter builder interface which compares the previous and next match. |\n| `CreateSuggestCommandParameter` | The parameters passed into the <code>createSuggest</code> suggester property. |\n| `FromToEndParameter` | A parameter builder interface describing a <code>from</code>/<code>to</code>/<code>end</code> range. |\n| `KeyboardEventParameter` | A parameter builder interface describing the event which triggers the keyboard event handler. |\n| `MatchValue` | The match value with the full and partial text. |\n| `OnKeyDownParameter` | The parameters required by the . |\n| `ReasonMatchParameter` | A parameter builder interface which adds the match property. |\n| `ReasonParameter` | A parameter builder interface indicating the reason the handler was called. |\n| `RemoveIgnoredParameter` | The parameters needed for the action method available to the suggest plugin handlers. |\n| `SuggestCallbackParameter` |  |\n| `SuggestChangeHandlerParameter` | The parameters passed to the `Suggester.onChange()` method. |\n| `SuggestCharacterEntryParameter` | The parameters passed to the `Suggester.onCharacterEntry()` method. |\n| `SuggestCommandParameter` | A parameter builder interface which adds the command property. |\n| `Suggester` | This <code>Suggester</code> interface defines all the options required to create a suggestion within your editor. |\n| `SuggesterParameter` |  |\n| `SuggestExitHandlerParameter` | The parameters passed to the `Suggester.onExit()` method. |\n| `SuggestIgnoreParameter` | A parameter builder interface describing the ignore methods available to the `Suggester` handlers. |\n| `SuggestKeyBindingParameter` | The parameters required by the `SuggestKeyBinding` method. |\n| `SuggestMarkParameter` | A special parameter needed when creating editable suggester using prosemirror <code>Marks</code>. The method should be called when removing a suggester that was identified by a prosemirror <code>Mark</code>. |\n| `SuggestReasonMap` | A mapping of the handler matches with their reasons for occurring within the suggest state. |\n| `SuggestStateMatch` | Describes the properties of a match which includes range and the text as well as information of the suggester that created the match. |\n| `SuggestStateMatchParameter` | A parameter builder interface describing match found by the suggest plugin. |\n| `SuggestStateMatchReason` |  |\n\n### Variables\n\n| Variable | Description |\n| --- | --- |\n| `createRegexFromSuggester` | Create a regex expression to evaluate matches directly from the suggester properties. |\n| `DEFAULT_SUGGEST_ACTIONS` |  |\n| `DEFAULT_SUGGESTER` |  |\n| `escapeChar` |  |\n| `getRegexPrefix` | Find regex prefix when depending on whether the mention only supports the start of a line or not |\n| `getSuggestPluginState` | Get the state of the suggest plugin. |\n| `isChange` | Is this a change in the current suggestion (added or deleted characters)? |\n| `isChangeReason` |  |\n| `isEntry` | Are we entering a new suggestion? |\n| `isExit` | Are we exiting a suggestion? |\n| `isExitReason` | Check that the passed in value is an ExitReason |\n| `isInvalidSplitReason` | Checks that the reason was caused by a split at a point where there is no query. |\n| `isJump` | Is this a jump from one suggestion to another? |\n| `isJumpReason` | Checks to see if this is a jump reason. |\n| `isMove` | Has the cursor moved within the current suggestion (added or deleted characters)? |\n| `isRemovedReason` | Checks that the reason was caused by a deletion. |\n| `isSplitReason` | Checks that the reason passed is a split reason. This typically means that we should default to a partial update / creation of the mention. |\n| `isValidMatch` | True when the match is currently active (i.e. it's query has a value) |\n| `regexToString` | Convert a RegExp into a string |\n| `selectionOutsideMatch` | True when the current selection is outside the match. |\n| `suggest` | This creates a suggestion plugin with all the suggesters provided. |\n\n### Type Aliases\n\n| Type Alias | Description |\n| --- | --- |\n| `SuggestKeyBinding` | A method for performing actions when a certain key / pattern is pressed. |\n| `SuggestKeyBindingMap` | The keybindings shape for the `Suggester.keyBindings` property. |\n| `SuggestReplacementType` | Determines whether to replace the full match or the partial match (up to the cursor position). |\n","readmeFilename":"readme.md","_id":"prosemirror-suggest@1.0.0-pr706.d0b3ea524","_nodeVersion":"14.15.3","_npmVersion":"6.14.9","dist":{"integrity":"sha512-MJYydLhqbjHystUQs1dJ+PcFC9wf/2coEHMTaBS+tGTCjElCKPqTo0gG4DpvA3LgpRUGzLye0u81B/3vbq8r3Q==","shasum":"705c951aeee7523f7c28b0cede15e133b03c4b8e","tarball":"http://registry-npm.ywwl.com/prosemirror-suggest/download/prosemirror-suggest-1.0.0-pr706.d0b3ea524.tgz","fileCount":17,"unpackedSize":315613,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgGqctCRA9TVsSAnZWagAAv/cP/1vo9vh8klcR1f4UX+Xi\nI7tOBey/L4LTfHFk7cBDEG/Zfk/oDSwy1laPRjn2nThrjKkl6d95qn2oGORS\nFT9QxmEdxx9yHSMKEZOATlFhD4Ve+Iv4zSJ9KreWg4zXzOiDKtcfVlg0XYNW\nveN72rO9NOWJjV4kAGGIzz/hE5rGQTnAu4NyHQ3ZxfNOlQi521/ZfRggVGbu\nqNR0IEB6IHSwW2PMIN1AVLN31hoae/LvBe+KNs2s7OxVqhkpgEVWSy1q0y46\nyFFTBPvhEPDpvI53GbX0v2LhxgexerD9UvhaY9CmUlELEk1ii7DN8ox+BRBy\nhqHpnAtwMbsaUjOgQmn+2RNbooB0H0eyklT43eGVYSOm2sNaq+Y5IIA07S58\nG8diYY+yLpLAAMSORqUxV0FtZLbqTD+itLly0b2zPKtXmaum00LnJPDBfuW7\nZZLic0E3m7I58V0u1/fqrblhKLODi55Yf1QhBE2DoIslzstX1yMZVNfM0Y0+\nq2vDbWa0K99Y/pP6DhbP1XC5N56QWoCdnxOvmN4oUoOhvFIk32G7s7j8qpVl\n6B7UjDL11jigjZsc5Ko7rV/Hx+k/d+ZttTj776oumW/a4DjJzIfIyZzCgLrd\nHcEHmtsEiy1M8DW0yF4UnmaYzJqraeHFTs5lNknfzj9NgsPSrgMO/MV4sZ75\n4Fcw\r\n=GG1J\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFW/aOi7tx4xRf0l0j+6/aDQo0s5CVOb5fXi4xo0/hdVAiA7u1yuIl7937YVVd2scKWrdKOTWs3WNToatJJ53Nzf1g=="}],"size":76387,"noattachment":false,"key":"/prosemirror-suggest/-/prosemirror-suggest-1.0.0-pr706.d0b3ea524.tgz"},"_npmUser":{"name":"ifiokjr","email":"ifiokotung@gmail.com"},"directories":{},"maintainers":[{"name":"ifiokjr","email":"ifiokotung@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/prosemirror-suggest_1.0.0-pr706.d0b3ea524_1612359469197_0.2624345853254122"},"_hasShrinkwrap":false,"deprecated":"Faulty deployment from pull request 706","publish_time":1612359469377,"_cnpm_publish_time":1612359469377,"dist-tags":{"beta":"3.0.0-beta.6","ci":"0.7.3-ci.1577125215.2","latest":"3.0.0","next":"1.0.0-next.60","pnpm-temp":"1.0.0-next.22","pr1031":"0.0.0-pr1031.1","pr1102":"0.0.0-pr1102.1","pr1158":"0.0.0-pr1158.1","pr1161":"0.0.0-pr1161.2","pr1174":"0.0.0-pr1174.1","pr1242":"0.0.0-pr1242.4","pr1305":"0.0.0-pr1305.1","pr1310":"0.0.0-pr1310.1","pr1340":"0.0.0-pr1340.1","pr1344":"0.0.0-pr1344.1","pr1365":"0.0.0-pr1365.1","pr1367":"0.0.0-pr1367.1","pr1392":"0.0.0-pr1392.1","pr1452":"0.0.0-pr1452.1","pr1463":"0.0.0-pr1463.1","pr1496":"0.0.0-pr1496.1","pr1532":"0.0.0-pr1532.1","pr1545":"0.0.0-pr1545.1","pr1549":"0.0.0-pr1549.1","pr1552":"0.0.0-pr1552.3","pr1558":"0.0.0-pr1558.1","pr1581":"0.0.0-pr1581.3","pr1586":"0.0.0-pr1586.1","pr1608":"0.0.0-pr1608.1","pr1629":"0.0.0-pr1629.1","pr1654":"0.0.0-pr1654.1","pr1713":"0.0.0-pr1713.12","pr1801":"0.0.0-pr1801.3","pr1862":"0.0.0-pr1862.1","pr1873":"0.0.0-pr1873.1","pr1879":"0.0.0-pr1879.1","pr1881":"0.0.0-pr1881.2","pr1885":"0.0.0-pr1885.1","pr1887":"0.0.0-pr1887.1","pr1922":"0.0.0-pr1922.2","pr1938":"0.0.0-pr1938.1","pr1942":"0.0.0-pr1942.1","pr1948":"0.0.0-pr1948.1","pr1966":"0.0.0-pr1966.1","pr2100":"0.0.0-pr2100.1","pr2118":"0.0.0-pr2118.1","pr2128":"0.0.0-pr2128.4","pr2156":"0.0.0-pr2156.1","pr2166":"0.0.0-pr2166.4","pr2169":"0.0.0-pr2169.2","pr2222":"0.0.0-pr2222.1","pr2223":"0.0.0-pr2223.1","pr2271":"0.0.0-pr2271.2","pr706":"0.0.0-pr706.36","pr862":"0.0.0-pr862.2","pr877":"0.0.0-pr877.9","pr885":"0.0.0-pr885.1","pr901":"0.0.0-pr901.1","pr905":"0.0.0-pr905.4","pr911":"0.0.0-pr911.2","pr919":"0.0.0-pr919.2","pr920":"0.0.0-pr920.1","pr922":"0.0.0-pr922.1","pr930":"0.0.0-pr930.1","pr941":"0.0.0-pr941.2","pr950":"0.0.0-pr950.7","pr956":"0.0.0-pr956.1","pr959":"0.0.0-pr959.1","pr960":"0.0.0-pr960.1","pr963":"0.0.0-pr963.1","pr965":"0.0.0-pr965.1","pr993":"0.0.0-pr993.1","pr997":"0.0.0-pr997.1"}}