@jpmorganchase/mosaic-content-editor-plugin 0.1.0-beta.71 → 0.1.0-beta.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/chunk-55WG3HBR.js +1 -0
  2. package/dist/chunk-HIIAB4W2.js +1 -0
  3. package/dist/{chunk-7O2SLISS.js → chunk-JLXXPRWJ.js} +1 -1
  4. package/dist/{chunk-CBQZGN4Y.js → chunk-U52GJYI4.js} +1 -1
  5. package/dist/chunk-UFRXMSJP.js +1 -0
  6. package/dist/{chunk-WOLMNJ7G.js → chunk-X5M73NRM.js} +1 -1
  7. package/dist/chunk-YDLF23AQ.js +1 -0
  8. package/dist/components/Dialog.d.ts +1 -1
  9. package/dist/components/Dialog.js +1 -1
  10. package/dist/components/Editor.js +1 -1
  11. package/dist/components/PersistEditDialog/index.js +1 -1
  12. package/dist/components/Toolbar/InsertImage.js +1 -1
  13. package/dist/components/Toolbar/InsertLink.js +1 -1
  14. package/dist/components/Toolbar/Toolbar.js +1 -1
  15. package/dist/index.js +1 -1
  16. package/dist/plugins/FloatingToolbarPlugin.js +1 -1
  17. package/dist/plugins/MarkdownLinkPlugin.js +1 -1
  18. package/dist/plugins/PreviewPlugin.js +1 -1
  19. package/package.json +9 -6
  20. package/.turbo/turbo-build.log +0 -4
  21. package/CHANGELOG.md +0 -673
  22. package/dist/chunk-CXTIKD2Y.js +0 -1
  23. package/dist/chunk-EPOQVSZ5.js +0 -1
  24. package/dist/chunk-LQBKKB6A.js +0 -1
  25. package/dist/chunk-XSZUCLBY.js +0 -1
  26. package/src/components/ActionMenu/ActionMenu.css.ts +0 -9
  27. package/src/components/ActionMenu/ActionMenu.tsx +0 -26
  28. package/src/components/BaseToolbar/BaseToolbar.css.ts +0 -21
  29. package/src/components/BaseToolbar/BaseToolbar.tsx +0 -13
  30. package/src/components/BaseTooltray/BaseTooltray.css.ts +0 -31
  31. package/src/components/BaseTooltray/BaseTooltray.tsx +0 -22
  32. package/src/components/ContentEditor.tsx +0 -14
  33. package/src/components/Dialog.css.ts +0 -7
  34. package/src/components/Dialog.tsx +0 -12
  35. package/src/components/Editor.css.ts +0 -64
  36. package/src/components/Editor.tsx +0 -145
  37. package/src/components/EditorControls.css.ts +0 -6
  38. package/src/components/EditorControls.tsx +0 -37
  39. package/src/components/LinkEditor/EditLinkButton.tsx +0 -9
  40. package/src/components/LinkEditor/LinkEditor.css.ts +0 -15
  41. package/src/components/LinkEditor/LinkEditor.tsx +0 -136
  42. package/src/components/LinkEditor/SaveAdornment.tsx +0 -17
  43. package/src/components/PersistEditDialog/PersistStatus.css.ts +0 -21
  44. package/src/components/PersistEditDialog/PersistStatus.tsx +0 -57
  45. package/src/components/PersistEditDialog/__tests__/index.test.tsx +0 -90
  46. package/src/components/PersistEditDialog/index.css.ts +0 -14
  47. package/src/components/PersistEditDialog/index.tsx +0 -150
  48. package/src/components/Popper/Popper.css.ts +0 -12
  49. package/src/components/Popper/Popper.tsx +0 -36
  50. package/src/components/SaveButton.tsx +0 -23
  51. package/src/components/ScrollableSection/ScrollableSection.css.ts +0 -10
  52. package/src/components/ScrollableSection/ScrollableSection.tsx +0 -20
  53. package/src/components/StatusBanner.tsx +0 -16
  54. package/src/components/Toolbar/InsertBlockDropdown.tsx +0 -134
  55. package/src/components/Toolbar/InsertHorizontalRule.tsx +0 -18
  56. package/src/components/Toolbar/InsertImage.css.ts +0 -7
  57. package/src/components/Toolbar/InsertImage.tsx +0 -130
  58. package/src/components/Toolbar/InsertLink.css.ts +0 -7
  59. package/src/components/Toolbar/InsertLink.tsx +0 -140
  60. package/src/components/Toolbar/InsertTable.css.ts +0 -52
  61. package/src/components/Toolbar/InsertTable.tsx +0 -196
  62. package/src/components/Toolbar/TextFormatTooltray.css.ts +0 -22
  63. package/src/components/Toolbar/TextFormatTooltray.tsx +0 -113
  64. package/src/components/Toolbar/Toolbar.tsx +0 -52
  65. package/src/components/Toolbar/ToolbarButton.css.ts +0 -11
  66. package/src/components/Toolbar/ToolbarButton.tsx +0 -41
  67. package/src/components/Toolbar/ToolbarSeparator.css.ts +0 -28
  68. package/src/components/Toolbar/ToolbarSepartor.tsx +0 -13
  69. package/src/components/__tests__/EditorControls.test.tsx +0 -69
  70. package/src/components/__tests__/StatusBanner.test.tsx +0 -33
  71. package/src/hooks/useEditHistory.ts +0 -49
  72. package/src/hooks/useWorkflowFeed.ts +0 -69
  73. package/src/index.ts +0 -5
  74. package/src/nodes/index.ts +0 -23
  75. package/src/plugins/FloatingToolbarPlugin.css.ts +0 -14
  76. package/src/plugins/FloatingToolbarPlugin.tsx +0 -101
  77. package/src/plugins/HorizontalRulePlugin.tsx +0 -39
  78. package/src/plugins/MarkdownImagePlugin.tsx +0 -58
  79. package/src/plugins/MarkdownLinkPlugin.tsx +0 -69
  80. package/src/plugins/PreviewPlugin.tsx +0 -71
  81. package/src/plugins/TableActionMenuPlugin.css.ts +0 -29
  82. package/src/plugins/TableActionMenuPlugin.tsx +0 -274
  83. package/src/store/__tests__/index.test.ts +0 -171
  84. package/src/store/index.ts +0 -84
  85. package/src/theme/index.css.ts +0 -39
  86. package/src/theme/index.ts +0 -22
  87. package/src/transformers/horizontalRule.ts +0 -25
  88. package/src/transformers/index.ts +0 -6
  89. package/src/transformers/link.ts +0 -3
  90. package/src/transformers/tableRule.ts +0 -193
  91. package/src/utils/getSelectedNode.ts +0 -16
  92. package/tsconfig.json +0 -8
@@ -1,90 +0,0 @@
1
- import React from 'react';
2
- import { render, screen, waitFor } from '@testing-library/react';
3
- import userEvent from '@testing-library/user-event';
4
- import { LexicalComposer } from '@lexical/react/LexicalComposer';
5
-
6
- import { PersistDialog } from '../index';
7
- import { usePageState } from '../../../store';
8
- import { nodes } from '../../../nodes';
9
- import useWorkflowFeed from '../../../hooks/useWorkflowFeed';
10
-
11
- jest.mock('../../../store', () => ({
12
- ...jest.requireActual('../../../store'),
13
- __esModule: true,
14
- usePageState: jest.fn()
15
- }));
16
-
17
- const mockSendWorkflowProgressMessage = jest.fn();
18
- jest.mock('../../../hooks/useWorkflowFeed');
19
- jest
20
- .mocked(useWorkflowFeed)
21
- .mockReturnValue({ sendWorkflowProgressMessage: mockSendWorkflowProgressMessage });
22
-
23
- const setPageStateSpy = jest.fn();
24
- const setErrorMessageSpy = jest.fn();
25
- const mockMeta = { sourceId: 'source-1', route: 'route' };
26
-
27
- jest.mock('@lexical/markdown', () => ({
28
- ...jest.requireActual('@lexical/markdown'),
29
- $convertToMarkdownString: jest.fn().mockReturnValue('## Test Markdown')
30
- }));
31
-
32
- const renderPersistDialog = (props = { meta: mockMeta }) => {
33
- render(
34
- <LexicalComposer
35
- initialConfig={{ namespace: 'persist-dialog-test', nodes, onError: jest.fn() }}
36
- >
37
- <PersistDialog {...props} />
38
- </LexicalComposer>
39
- );
40
- };
41
-
42
- describe('GIVEN a PersistEditDialog', () => {
43
- beforeAll(() => {
44
- jest.mocked(usePageState).mockReturnValue({
45
- pageState: 'SAVING',
46
- setErrorMessage: setErrorMessageSpy,
47
- setPageState: setPageStateSpy,
48
- errorMessage: undefined
49
- });
50
- });
51
-
52
- test('THEN the dialog is open when SAVING', () => {
53
- // arrange
54
- renderPersistDialog();
55
- // assert
56
- expect(
57
- screen.getByText(
58
- 'The content of this page resides in a Git repository and to update it requires a Pull Request which will be reviewed by the content owners.'
59
- )
60
- ).toBeDefined();
61
- });
62
-
63
- test('THEN cancelling returns the page to edit mode', async () => {
64
- // arrange
65
- renderPersistDialog();
66
- // act
67
- const cancelButton = screen.getByText('Cancel');
68
- await userEvent.click(cancelButton);
69
- // assert
70
- expect(setPageStateSpy).toBeCalledTimes(1);
71
- expect(setPageStateSpy.mock.calls[0][0]).toEqual('EDIT');
72
- });
73
-
74
- describe.skip('AND WHEN we can create a Pull Request', () => {
75
- beforeAll(() => {
76
- server.use(postSaveContentSuccessHandler);
77
- });
78
- test('THEN raising a PR provides a link to the PR', async () => {
79
- // arrange
80
- renderPersistDialog();
81
- // act
82
- const raisePrButton = screen.getByText('Raise Pull Request');
83
- userEvent.click(raisePrButton);
84
- // assert
85
- await waitFor(() => {
86
- expect(screen.getByText('A Pull Request for your changes has been created.'));
87
- });
88
- });
89
- });
90
- });
@@ -1,14 +0,0 @@
1
- import { globalStyle, style } from '@vanilla-extract/css';
2
- import { vars } from '@jpmorganchase/mosaic-theme';
3
-
4
- const title = style({
5
- alignItems: 'center'
6
- });
7
-
8
- export default {
9
- title
10
- };
11
-
12
- globalStyle(`${title} [role=heading] `, {
13
- paddingLeft: vars.space.horizontal.x2
14
- });
@@ -1,150 +0,0 @@
1
- import React, { FC, useState } from 'react';
2
- import md5 from 'md5';
3
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
4
- import { $convertToMarkdownString } from '@lexical/markdown';
5
- import { Link, P2, Button } from '@jpmorganchase/mosaic-components';
6
- import { ButtonBar, DialogTitle, DialogContent, DialogActions } from '@salt-ds/lab';
7
- import { SourceWorkflowMessageEvent } from '@jpmorganchase/mosaic-types';
8
-
9
- import { useEditorUser, usePageState } from '../../store';
10
- import transformers from '../../transformers';
11
- import { PersistStatus } from './PersistStatus';
12
- import { Dialog } from '../Dialog';
13
- import style from './index.css';
14
- import useWorkflowFeed from '../../hooks/useWorkflowFeed';
15
-
16
- interface InfoProps {
17
- isRaising: boolean;
18
- prHref: string | null;
19
- error: string | null;
20
- }
21
-
22
- const Info: FC<InfoProps> = ({ isRaising, prHref, error }) =>
23
- !isRaising && !prHref && !error ? (
24
- <>
25
- <P2>
26
- The content of this page resides in a Git repository and to update it requires a Pull
27
- Request which will be reviewed by the content owners.
28
- </P2>
29
- <br />
30
- <P2>
31
- Should you decide to stop editing before creating the Pull Request then all changes will be
32
- lost.
33
- </P2>
34
- </>
35
- ) : null;
36
-
37
- interface PersistDialogProps {
38
- meta: any;
39
- persistUrl?: string;
40
- }
41
-
42
- export const PersistDialog = ({ meta, persistUrl }: PersistDialogProps) => {
43
- const { pageState, setPageState } = usePageState();
44
- const { user } = useEditorUser();
45
- const [editor] = useLexicalComposerContext();
46
- const [isRaising, setIsRaising] = useState(false);
47
- const [prHref, setPrHref] = useState<string | null>(null);
48
- const [error, setError] = useState<string | null>(null);
49
- const [progress, setProgress] = useState<SourceWorkflowMessageEvent[]>([]);
50
-
51
- const open = pageState === 'SAVING';
52
- const state = prHref !== null ? 'success' : 'info';
53
-
54
- const handleOpenChange = (newOpen: boolean) => {
55
- setIsRaising(newOpen);
56
- if (!newOpen) {
57
- setPageState('EDIT');
58
- setPrHref(null);
59
- setProgress([]);
60
- }
61
- };
62
-
63
- const handleClose = () => {
64
- handleOpenChange(false);
65
- };
66
-
67
- const handleErrorMessage = (errorMessage: string) => {
68
- setError(errorMessage ? errorMessage : 'Sorry - an unexpected error has occurred');
69
- setPrHref(null);
70
- setProgress([]);
71
- setIsRaising(false);
72
- };
73
-
74
- const handleCompleteMessage = message => {
75
- setPrHref(message.message?.links?.self[0]?.href);
76
- setIsRaising(false);
77
- };
78
-
79
- const handleSuccessMessage = message => {
80
- setProgress(prevState => [...prevState, message]);
81
- };
82
-
83
- const { sendWorkflowProgressMessage } = useWorkflowFeed(
84
- open,
85
- handleErrorMessage,
86
- handleSuccessMessage,
87
- handleCompleteMessage
88
- );
89
-
90
- const handleRaisePr = () => {
91
- setIsRaising(true);
92
- setPrHref(null);
93
- setError(null);
94
-
95
- try {
96
- editor.update(() => {
97
- const markdown = $convertToMarkdownString(transformers);
98
- if (markdown && user && persistUrl) {
99
- const { sid, displayName, email } = user;
100
-
101
- sendWorkflowProgressMessage(
102
- JSON.stringify({
103
- user: { sid, name: displayName, email },
104
- route: meta.route,
105
- markdown,
106
- name: 'save'
107
- }),
108
- md5(`${sid.toLowerCase()} - save`)
109
- );
110
- }
111
- });
112
- } catch (e) {
113
- setError('Sorry - an unexpected error has occurred');
114
- setPrHref(null);
115
- setIsRaising(false);
116
- setProgress([]);
117
- }
118
- };
119
-
120
- return (
121
- <Dialog onOpenChange={handleOpenChange} open={open} status={error ? 'error' : state}>
122
- <DialogTitle className={style.title}>
123
- {!prHref ? 'Save Changes' : 'Pull Request Created Successfully'}
124
- </DialogTitle>
125
- <DialogContent>
126
- {(isRaising || error) && !prHref && <PersistStatus error={error} progress={progress} />}
127
- <Info isRaising={isRaising} prHref={prHref} error={error} />
128
- {!isRaising && prHref && (
129
- <Link href={prHref} target="_blank">
130
- A Pull Request for your changes has been created
131
- </Link>
132
- )}
133
- </DialogContent>
134
- <DialogActions>
135
- <ButtonBar>
136
- <Button disabled={isRaising} onClick={handleClose}>
137
- {!prHref ? 'Cancel' : 'Done'}
138
- </Button>
139
- <Button
140
- disabled={persistUrl === undefined || isRaising || prHref !== null}
141
- onClick={handleRaisePr}
142
- variant="cta"
143
- >
144
- Raise Pull Request
145
- </Button>
146
- </ButtonBar>
147
- </DialogActions>
148
- </Dialog>
149
- );
150
- };
@@ -1,12 +0,0 @@
1
- import { style } from '@vanilla-extract/css';
2
- import { backgroundColor, shadow } from '@jpmorganchase/mosaic-theme';
3
-
4
- export const POPPER_Z_INDEX = 10;
5
-
6
- export default {
7
- root: style([
8
- style({ zIndex: POPPER_Z_INDEX }),
9
- backgroundColor({ variant: 'regular' }),
10
- shadow({ variant: 'elevation3' })
11
- ])
12
- };
@@ -1,36 +0,0 @@
1
- import React, { forwardRef, HTMLAttributes, ReactNode } from 'react';
2
- import { Portal, useWindow } from '@salt-ds/lab';
3
- import { themeClassName } from '@jpmorganchase/mosaic-theme';
4
- import classnames from 'clsx';
5
-
6
- import styles from './Popper.css';
7
-
8
- interface PopperProps extends HTMLAttributes<HTMLDivElement> {
9
- /** Floating contents */
10
- children?: ReactNode;
11
- /** Class name */
12
- className?: string;
13
- /** Flag indicating whether the floating content is visible */
14
- open?: boolean;
15
- }
16
-
17
- export const Popper = forwardRef<HTMLDivElement, PopperProps>(function Popper(props, forwardedRef) {
18
- const { children, className, ...rest } = props;
19
- const Window = useWindow();
20
-
21
- if (!rest.open) {
22
- return null;
23
- }
24
-
25
- return (
26
- <Portal>
27
- <Window
28
- className={classnames(className, themeClassName, styles.root)}
29
- ref={forwardedRef}
30
- {...rest}
31
- >
32
- {children}
33
- </Window>
34
- </Portal>
35
- );
36
- });
@@ -1,23 +0,0 @@
1
- import React, { useState } from 'react';
2
- import { Button, Icon } from '@jpmorganchase/mosaic-components';
3
- import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
4
-
5
- import { usePageState } from '../store';
6
-
7
- export const SaveButton = () => {
8
- const { setPageState } = usePageState();
9
- const [isDisabled, setIsDisabled] = useState(true);
10
-
11
- const onChange = () => {
12
- setIsDisabled(false);
13
- };
14
-
15
- return (
16
- <>
17
- <OnChangePlugin onChange={onChange} ignoreSelectionChange />
18
- <Button disabled={isDisabled} variant="cta" onClick={() => setPageState('SAVING')}>
19
- <Icon name="save" /> &nbsp; Save
20
- </Button>
21
- </>
22
- );
23
- };
@@ -1,10 +0,0 @@
1
- import { style } from '@vanilla-extract/css';
2
- import { vars } from '@jpmorganchase/mosaic-theme';
3
-
4
- export default {
5
- root: style({
6
- padding: vars.space.horizontal.x3,
7
- maxHeight: '100vh',
8
- overflow: 'scroll'
9
- })
10
- };
@@ -1,20 +0,0 @@
1
- import React, { Ref, forwardRef } from 'react';
2
- import classnames from 'clsx';
3
-
4
- import styles from './ScrollableSection.css';
5
-
6
- interface ScrollableSectionProps {
7
- className?: string;
8
- children: React.ReactNode;
9
- }
10
-
11
- export const ScrollableSection = forwardRef(function ScrollableSection(
12
- { className, children }: ScrollableSectionProps,
13
- ref: Ref<HTMLDivElement>
14
- ) {
15
- return (
16
- <section ref={ref} className={classnames(styles.root, className)}>
17
- {children}
18
- </section>
19
- );
20
- });
@@ -1,16 +0,0 @@
1
- import React from 'react';
2
- import { Banner, BannerContent } from '@salt-ds/core';
3
-
4
- import { usePageState } from '../store';
5
-
6
- const StatusBanner = () => {
7
- const { pageState, errorMessage } = usePageState();
8
- const isError = pageState === 'ERROR';
9
- return isError ? (
10
- <Banner status="error">
11
- <BannerContent role="status">{errorMessage}</BannerContent>
12
- </Banner>
13
- ) : null;
14
- };
15
-
16
- export default StatusBanner;
@@ -1,134 +0,0 @@
1
- import React from 'react';
2
- import { Dropdown, SelectionChangeHandler } from '@salt-ds/lab';
3
- import { $createCodeNode } from '@lexical/code';
4
- import { INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND } from '@lexical/list';
5
- import { $createHeadingNode, $createQuoteNode, HeadingTagType } from '@lexical/rich-text';
6
- import { $wrapNodes } from '@lexical/selection';
7
- import { $createParagraphNode, $getSelection, $isRangeSelection, LexicalEditor } from 'lexical';
8
-
9
- interface BlockSourceType {
10
- name: string;
11
- type: string;
12
- }
13
-
14
- const itemToString = (item?: BlockSourceType | null) => (item ? item.name : '');
15
-
16
- const headings = [
17
- { name: 'Heading 1', type: 'h1' },
18
- { name: 'Heading 2', type: 'h2' },
19
- { name: 'Heading 3', type: 'h3' },
20
- { name: 'Heading 4', type: 'h4' },
21
- { name: 'Heading 5', type: 'h5' },
22
- { name: 'Heading 6', type: 'h6' }
23
- ];
24
-
25
- const source = [
26
- { name: 'Bulleted List', type: 'bullet' },
27
- { name: 'Code Block', type: 'code' },
28
- ...headings,
29
- { name: 'Numbered List', type: 'number' },
30
- { name: 'Paragraph', type: 'paragraph' },
31
- { name: 'Quote', type: 'quote' }
32
- ];
33
-
34
- export function InsertBlockDropdown({
35
- editor,
36
- type: blockSourceType
37
- }: {
38
- editor: LexicalEditor;
39
- type: string;
40
- }): JSX.Element {
41
- const formatParagraph = (item: BlockSourceType) => {
42
- if (item.type === 'paragraph') {
43
- editor.update(() => {
44
- const selection = $getSelection();
45
-
46
- if ($isRangeSelection(selection)) {
47
- $wrapNodes(selection, () => $createParagraphNode());
48
- }
49
- });
50
- }
51
- };
52
-
53
- const formatHeading = (item: BlockSourceType) => {
54
- if (headings.findIndex(heading => heading.type === item.type) >= 0) {
55
- editor.update(() => {
56
- const selection = $getSelection();
57
-
58
- if ($isRangeSelection(selection)) {
59
- $wrapNodes(selection, () => $createHeadingNode(item.type as HeadingTagType));
60
- }
61
- });
62
- }
63
- };
64
-
65
- const formatBulletList = (item: BlockSourceType) => {
66
- if (item.type === 'bullet') {
67
- editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined);
68
- }
69
- };
70
-
71
- const formatNumberedList = (item: BlockSourceType) => {
72
- if (item.type === 'number') {
73
- editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, undefined);
74
- }
75
- };
76
-
77
- const formatQuote = (item: BlockSourceType) => {
78
- if (item.type === 'quote') {
79
- editor.update(() => {
80
- const selection = $getSelection();
81
-
82
- if ($isRangeSelection(selection)) {
83
- $wrapNodes(selection, () => $createQuoteNode());
84
- }
85
- });
86
- }
87
- };
88
-
89
- const formatCode = (item: BlockSourceType) => {
90
- if (item.type === 'code') {
91
- editor.update(() => {
92
- const selection = $getSelection();
93
-
94
- if ($isRangeSelection(selection)) {
95
- if (selection.isCollapsed()) {
96
- $wrapNodes(selection, () => $createCodeNode());
97
- } else {
98
- const textContent = selection.getTextContent();
99
- const codeNode = $createCodeNode();
100
- selection.removeText();
101
- selection.insertNodes([codeNode]);
102
- selection.insertRawText(textContent);
103
- }
104
- }
105
- });
106
- }
107
- };
108
-
109
- const handleSelect: SelectionChangeHandler<BlockSourceType, 'default'> = (_event, item) => {
110
- if (!item) {
111
- return;
112
- }
113
- formatParagraph(item);
114
- formatHeading(item);
115
- formatBulletList(item);
116
- formatNumberedList(item);
117
- formatQuote(item);
118
- formatCode(item);
119
- };
120
-
121
- const selectedBlockSourceIndex = source.findIndex(item => item.type === blockSourceType);
122
- return (
123
- <Dropdown
124
- ListProps={{
125
- width: 200
126
- }}
127
- defaultSelected={source[selectedBlockSourceIndex]}
128
- itemToString={itemToString}
129
- onSelectionChange={handleSelect}
130
- source={source}
131
- width={132}
132
- />
133
- );
134
- }
@@ -1,18 +0,0 @@
1
- import React from 'react';
2
- import { Icon } from '@jpmorganchase/mosaic-components';
3
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
4
- import { INSERT_HORIZONTAL_RULE_COMMAND } from '@lexical/react/LexicalHorizontalRuleNode';
5
- import { ToolbarButton } from './ToolbarButton';
6
-
7
- export const InsertHorizontalRule = () => {
8
- const [editor] = useLexicalComposerContext();
9
-
10
- const handleClick = () => {
11
- editor.dispatchCommand(INSERT_HORIZONTAL_RULE_COMMAND, undefined);
12
- };
13
- return (
14
- <ToolbarButton onClick={handleClick} label="Insert Divider">
15
- <Icon name="minimize" />
16
- </ToolbarButton>
17
- );
18
- };
@@ -1,7 +0,0 @@
1
- import { style } from '@vanilla-extract/css';
2
-
3
- export default {
4
- fullWidth: style({
5
- width: '100%'
6
- })
7
- };
@@ -1,130 +0,0 @@
1
- import React, { useState } from 'react';
2
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
3
- import { Button, Icon } from '@jpmorganchase/mosaic-components';
4
- import { string, object } from 'yup';
5
- import { Input, FormField, FormFieldLabel, FormFieldHelperText } from '@salt-ds/core';
6
- import { ButtonBar, DialogTitle, DialogContent, DialogActions } from '@salt-ds/lab';
7
-
8
- import { ToolbarButton } from './ToolbarButton';
9
- import { Dialog } from '../Dialog';
10
- import {
11
- INSERT_MARKDOWN_IMAGE_COMMAND,
12
- InsertImagePayload
13
- } from '../../plugins/MarkdownImagePlugin';
14
- import styles from './InsertImage.css';
15
-
16
- const validationSchema = object({
17
- alt: string()
18
- .required('Alternative Information is a required field')
19
- .max(100, 'Alternative Information must be fewer than 100 characters'),
20
- url: string().required('Url is required').url('Must be a valid Url')
21
- });
22
-
23
- const initialState = {
24
- url: 'https://'
25
- };
26
-
27
- type FormValueState =
28
- | {
29
- alt?: string;
30
- url?: string;
31
- }
32
- | undefined;
33
-
34
- type FormErrorState =
35
- | {
36
- alt?: string;
37
- url?: string;
38
- }
39
- | undefined;
40
-
41
- export const InsertImage = () => {
42
- const [editor] = useLexicalComposerContext();
43
- const [isOpen, setIsOpen] = useState(false);
44
- const [values, setValues] = useState<FormValueState>(initialState);
45
- const [errors, setErrors] = useState<FormErrorState>();
46
-
47
- const handleOpenChange = (open: boolean) => {
48
- setIsOpen(open);
49
- if (!open) {
50
- setValues(initialState);
51
- }
52
- };
53
-
54
- const handleOpen = () => setIsOpen(true);
55
-
56
- const handleClose = () => {
57
- handleOpenChange(false);
58
- };
59
-
60
- const processErrors = validationErrors => {
61
- const newErrors = validationErrors.inner.reduce(
62
- (acc, { path, message }) => ({
63
- ...acc,
64
- [path]: message
65
- }),
66
- {}
67
- );
68
- setErrors(newErrors);
69
- };
70
-
71
- const handleChange = event => {
72
- const { name, value } = event.target;
73
- const newValues = { ...values, [name]: value };
74
- validationSchema.validateAt(name, newValues, { abortEarly: false }).then(() => {
75
- setErrors({ ...errors, [name]: undefined });
76
- }, processErrors);
77
- setValues(newValues);
78
- };
79
-
80
- const handleSubmit = async event => {
81
- event.preventDefault();
82
- validationSchema.validate(values, { abortEarly: false }).then(() => {
83
- const payload: InsertImagePayload = {
84
- alt: values && values.alt !== undefined ? values.alt : null,
85
- url: values && values.url !== undefined ? values.url : null
86
- };
87
- editor.dispatchCommand(INSERT_MARKDOWN_IMAGE_COMMAND, payload);
88
- handleClose();
89
- }, processErrors);
90
- };
91
-
92
- return (
93
- <>
94
- <ToolbarButton active={isOpen} onClick={handleOpen} label="Insert Image">
95
- <Icon name="addDocument" />
96
- </ToolbarButton>
97
-
98
- <Dialog onOpenChange={handleOpenChange} open={isOpen}>
99
- <form onSubmit={handleSubmit} noValidate>
100
- <DialogTitle>Insert Image</DialogTitle>
101
- <DialogContent>
102
- <div className={styles.fullWidth}>
103
- <FormField validationStatus={errors?.url ? 'error' : undefined}>
104
- <FormFieldLabel>Url for image</FormFieldLabel>
105
- <Input value={values?.url} inputProps={{ name: 'url' }} onChange={handleChange} />
106
- <FormFieldHelperText>{errors?.url}</FormFieldHelperText>
107
- </FormField>
108
- <FormField validationStatus={errors?.alt ? 'error' : undefined}>
109
- <FormFieldLabel>Alternative Information (alt)</FormFieldLabel>
110
- <Input value={values?.alt} inputProps={{ name: 'alt' }} onChange={handleChange} />
111
- <FormFieldHelperText>
112
- {errors?.alt ||
113
- 'Provides alternative information for the image if for some reason it cannot be viewed'}
114
- </FormFieldHelperText>
115
- </FormField>
116
- </div>
117
- </DialogContent>
118
- <DialogActions>
119
- <ButtonBar>
120
- <Button onClick={handleClose}>Cancel</Button>
121
- <Button variant="cta" type="submit">
122
- Insert
123
- </Button>
124
- </ButtonBar>
125
- </DialogActions>
126
- </form>
127
- </Dialog>
128
- </>
129
- );
130
- };
@@ -1,7 +0,0 @@
1
- import { style } from '@vanilla-extract/css';
2
-
3
- export default {
4
- fullWidth: style({
5
- width: '100%'
6
- })
7
- };