-
-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(entity-reference): add helper and command to entity-reference ext…
…ension (#1742) * fix(entity-reference): add `getEntityReferenceById` helper and `scrollToEntityReference` command * Update packages/remirror__extension-entity-reference/src/entity-reference-extension.ts Co-authored-by: ocavue <ocavue@users.noreply.github.com> * Add unit test for selection of scrollIntoEntityReference command * Add story for scrolling into an entity reference * Update packages/remirror__extension-entity-reference/src/entity-reference-extension.ts Co-authored-by: Will Hawker <whawker@users.noreply.github.com> * Update packages/remirror__extension-entity-reference/src/entity-reference-extension.ts Co-authored-by: Will Hawker <whawker@users.noreply.github.com> * Update test scrollToEntityReferene to select all the doc instead of remove selection" Remove unnecessary dispatch call Co-authored-by: Idriss mahjoubi <mahjoubi.idriss@gmail.com> Co-authored-by: ocavue <ocavue@users.noreply.github.com> Co-authored-by: Will Hawker <whawker@users.noreply.github.com>
- Loading branch information
1 parent
f2f053b
commit 2e7d7f0
Showing
4 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/storybook-react/stories/extension-entity-reference/entity-reference.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import Highlights from './highlights'; | ||
import ScrollIntoHighlight from './scroll-to-highlight'; | ||
|
||
export default { title: 'Extensions / EntityReference' }; | ||
|
||
export { Highlights as Highlight }; | ||
export { ScrollIntoHighlight as ScrollIntoHighlight }; |
37 changes: 37 additions & 0 deletions
37
packages/storybook-react/stories/extension-entity-reference/scroll-to-highlight.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'remirror/styles/all.css'; | ||
import './styles.css'; | ||
|
||
import React from 'react'; | ||
import { EntityReferenceExtension } from 'remirror/extensions'; | ||
import { Remirror, ThemeProvider, useRemirror } from '@remirror/react'; | ||
|
||
const extensions = () => [new EntityReferenceExtension()]; | ||
|
||
const TEST_ID = 'testId'; | ||
const lineBreakHTML = `<p><br class="ProseMirror-trailingBreak"></p>`; | ||
const numberOfLineBreaks = 100; | ||
|
||
const ScrollIntoHighlight = (): JSX.Element => { | ||
const { manager, state, onChange } = useRemirror({ | ||
extensions: extensions, | ||
content: `${lineBreakHTML.repeat( | ||
numberOfLineBreaks, | ||
)}<p>Highlight <span data-entity-reference=${TEST_ID}>important and interesting</span> text</p>`, | ||
stringHandler: 'html', | ||
}); | ||
|
||
return ( | ||
<ThemeProvider> | ||
<Remirror manager={manager} onChange={onChange} initialContent={state} autoRender='end'> | ||
<button | ||
onMouseDown={(event) => event.preventDefault()} | ||
onClick={() => manager.store.commands.scrollToEntityReference(TEST_ID)} | ||
> | ||
Scroll into highlight | ||
</button> | ||
</Remirror> | ||
</ThemeProvider> | ||
); | ||
}; | ||
|
||
export default ScrollIntoHighlight; |
2e7d7f0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Deployed on https://62c541b6b1b2573e007bcad9--remirror.netlify.app