diff --git a/docs/components/file-input.md b/docs/components/file-input.md index 946249377..b9f63c742 100644 --- a/docs/components/file-input.md +++ b/docs/components/file-input.md @@ -21,3 +21,25 @@ ``` + +## Long Style + + + + + +```vue + +``` \ No newline at end of file diff --git a/docs/components/markdown-editor.md b/docs/components/markdown-editor.md index a0f96cb88..df35be280 100644 --- a/docs/components/markdown-editor.md +++ b/docs/components/markdown-editor.md @@ -30,7 +30,7 @@ const description = ref(null) ## With options - + ```vue @@ -39,7 +39,7 @@ import { ref } from "vue"; const description = ref(null) - + ``` ## With image upload diff --git a/lib/assets/icons/scan-eye.svg b/lib/assets/icons/scan-eye.svg new file mode 100644 index 000000000..0230c4ed8 --- /dev/null +++ b/lib/assets/icons/scan-eye.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/lib/assets/styles/classes.scss b/lib/assets/styles/classes.scss index bbce8abf0..34fa61e00 100644 --- a/lib/assets/styles/classes.scss +++ b/lib/assets/styles/classes.scss @@ -883,7 +883,7 @@ a, a { cursor: pointer; - color: var(--color-blue); + color: var(--color-link); &:focus-visible, &:hover { diff --git a/lib/components/base/DropdownSelect.vue b/lib/components/base/DropdownSelect.vue index e77428cd5..609d5cdf1 100644 --- a/lib/components/base/DropdownSelect.vue +++ b/lib/components/base/DropdownSelect.vue @@ -191,6 +191,7 @@ const isChildOfDropdown = (element) => { diff --git a/lib/components/base/MarkdownEditor.vue b/lib/components/base/MarkdownEditor.vue index 3c8042427..f47331508 100644 --- a/lib/components/base/MarkdownEditor.vue +++ b/lib/components/base/MarkdownEditor.vue @@ -37,11 +37,13 @@ Preview -
+
+
+
Max length: - {{ props.maxLength ?? 'Unlimited' }} + + {{ props.maxLength ? `${currentValue?.length || 0}/${props.maxLength}` : 'Unlimited' }} + +
+
+
+
+
-
@@ -260,6 +276,7 @@ import { Heading3Icon, BoldIcon, ItalicIcon, + ScanEyeIcon, StrikethroughIcon, CodeIcon, ListBulletedIcon, @@ -294,14 +311,16 @@ const props = withDefaults( onImageUpload?: (file: File) => Promise placeholder?: string maxLength?: number + maxHeight?: number }>(), { modelValue: '', disabled: false, headingButtons: true, onImageUpload: undefined, - placeholder: undefined, + placeholder: 'Write something...', maxLength: undefined, + maxHeight: undefined, } ) @@ -320,13 +339,15 @@ onMounted(() => { const theme = EditorView.theme({ // in defualts.scss there's references to .cm-content and such to inherit global styles - '.cm-content, .cm-gutter': { + '.cm-content': { marginBlockEnd: '0.5rem', padding: '0.5rem', minHeight: '200px', caretColor: 'var(--color-contrast)', width: '100%', overflowX: 'scroll', + maxHeight: props.maxHeight ? `${props.maxHeight}px` : 'unset', + overflowY: 'scroll', }, '.cm-scroller': { height: '100%', @@ -359,19 +380,6 @@ onMounted(() => { return false } }, - beforeinput: (ev, view) => { - if (props.maxLength && view.state.doc.length > props.maxLength) { - ev.preventDefault() - // Calculate how many characters to remove from the end - const excessLength = view.state.doc.length - props.maxLength - // Dispatch transaction to remove excess characters - view.dispatch({ - changes: { from: view.state.doc.length - excessLength, to: view.state.doc.length }, - selection: { anchor: props.maxLength, head: props.maxLength }, // Place cursor at the end - }) - return true - } - }, blur: (_, view) => { if (props.maxLength && view.state.doc.length > props.maxLength) { // Calculate how many characters to remove from the end @@ -385,6 +393,13 @@ onMounted(() => { }, }) + const inputFilter = EditorState.changeFilter.of((transaction) => { + if (props.maxLength && transaction.newDoc.length > props.maxLength) { + return false + } + return true + }) + const editorState = EditorState.create({ doc: props.modelValue, extensions: [ @@ -399,6 +414,7 @@ onMounted(() => { }), keymap.of(historyKeymap), cm_placeholder(props.placeholder || ''), + inputFilter, ], }) @@ -468,6 +484,7 @@ const BUTTONS: ButtonGroupMap = { markdownCommands.toggleStrikethrough ), composeCommandButton('Code', CodeIcon, markdownCommands.toggleCodeBlock), + composeCommandButton('Spoiler', ScanEyeIcon, markdownCommands.toggleSpoiler), ], }, lists: { @@ -627,6 +644,38 @@ function openVideoModal() {