Skip to content

Commit

Permalink
Quotes for web (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
alunturner authored Jan 18, 2023
1 parent c364b6e commit c6ef4e5
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bindings/wysiwyg-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ impl ComposerModel {
ComposerUpdate::from(self.inner.underline())
}

pub fn quote(&mut self) -> ComposerUpdate {
ComposerUpdate::from(self.inner.quote())
}

pub fn inline_code(&mut self) -> ComposerUpdate {
ComposerUpdate::from(self.inner.inline_code())
}
Expand Down
5 changes: 5 additions & 0 deletions platforms/web/lib/composer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const mockComposerModel = {
inline_code: vi.fn(),
ordered_list: vi.fn(),
unordered_list: vi.fn(),
quote: vi.fn(),
enter: vi.fn(),
} as unknown as ComposerModel;

Expand Down Expand Up @@ -100,6 +101,10 @@ const testCases: testCase[] = [
eventType: 'insertLineBreak',
composerMethod: 'enter',
},
{
eventType: 'insertQuote',
composerMethod: 'quote',
},
];

describe('processInput', () => {
Expand Down
2 changes: 2 additions & 0 deletions platforms/web/lib/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export function processInput(
return action(composerModel.undo(), 'undo');
case 'insertCodeBlock':
return action(composerModel.code_block(), 'code_block');
case 'insertQuote':
return action(composerModel.quote(), 'quote');
case 'insertFromPaste':
// Paste is already handled by catching the 'paste' event, which
// results in a ClipboardEvent, handled above. Ideally, we would
Expand Down
1 change: 1 addition & 0 deletions platforms/web/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ export const ACTION_TYPES = [
'clear',
'link',
'codeBlock',
'quote',
] as const;
1 change: 1 addition & 0 deletions platforms/web/lib/useFormattingFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function useFormattingFunctions(
getLink: () =>
composerModel?.get_link_action()?.edit_link?.link || '',
codeBlock: () => sendEvent('insertCodeBlock'),
quote: () => sendEvent('insertQuote'),
};
}, [editorRef, composerModel]);

Expand Down
1 change: 1 addition & 0 deletions platforms/web/lib/useListeners/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('createDefaultActionStates', () => {
unorderedList: 'enabled',
link: 'enabled',
codeBlock: 'enabled',
quote: 'enabled',
});
});
});
Expand Down
7 changes: 7 additions & 0 deletions platforms/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import listUnorderedImage from './images/list_unordered.svg';
import listOrderedImage from './images/list_ordered.svg';
import inlineCodeImage from './images/inline_code.svg';
import codeBlockImage from './images/code_block.svg';
import quoteImage from './images/quote.svg';
import { Wysiwyg, WysiwygEvent } from '../lib/types';

type ButtonProps = {
Expand Down Expand Up @@ -142,6 +143,12 @@ function App() {
imagePath={listOrderedImage}
state={actionStates.orderedList}
/>
<Button
onClick={wysiwyg.quote}
alt="quote"
imagePath={quoteImage}
state={actionStates.quote}
/>
<Button
onClick={wysiwyg.inlineCode}
alt="inline code"
Expand Down
6 changes: 6 additions & 0 deletions platforms/web/src/images/quote.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c6ef4e5

Please sign in to comment.