From ca36e312c46841d48b42075ee1e6978da98da848 Mon Sep 17 00:00:00 2001 From: rijkvanzanten Date: Thu, 14 Jan 2021 14:48:40 -0500 Subject: [PATCH 1/3] Start on new md interface --- app/src/interfaces/code/code.vue | 1 + .../markdown/composables/use-edit.ts | 46 +++ app/src/interfaces/markdown/index.ts | 15 - app/src/interfaces/markdown/markdown.story.ts | 51 --- app/src/interfaces/markdown/markdown.vue | 354 ++---------------- 5 files changed, 80 insertions(+), 387 deletions(-) create mode 100644 app/src/interfaces/markdown/composables/use-edit.ts delete mode 100644 app/src/interfaces/markdown/markdown.story.ts diff --git a/app/src/interfaces/code/code.vue b/app/src/interfaces/code/code.vue index 39c816d6a3..738d13f54d 100644 --- a/app/src/interfaces/code/code.vue +++ b/app/src/interfaces/code/code.vue @@ -300,6 +300,7 @@ export default defineComponent({ cursor: pointer; transition: color var(--fast) var(--transition-out); user-select: none; + &:hover { color: var(--primary-125); transition: none; diff --git a/app/src/interfaces/markdown/composables/use-edit.ts b/app/src/interfaces/markdown/composables/use-edit.ts new file mode 100644 index 0000000000..a30520e444 --- /dev/null +++ b/app/src/interfaces/markdown/composables/use-edit.ts @@ -0,0 +1,46 @@ +import { Ref } from '@vue/composition-api'; + +type Alteration = 'bold' | 'italic' | 'strikethrough'; + +type AlterationFunctions = Record string[]>; + +export function useEdit(codemirror: Ref) { + const alterations: AlterationFunctions = { + bold(selections) { + return selections.map((selection) => { + if (selection.startsWith('**') && selection.endsWith('**')) { + return selection.substring(2, selection.length - 2); + } else { + return `**${selection}**`; + } + }); + }, + italic(selections) { + return selections.map((selection) => { + if (selection.startsWith('*') && selection.endsWith('*')) { + return selection.substring(1, selection.length - 1); + } else { + return `*${selection}*`; + } + }); + }, + strikethrough(selections) { + return selections.map((selection) => { + if (selection.startsWith('~~') && selection.endsWith('~~')) { + return selection.substring(2, selection.length - 2); + } else { + return `~~${selection}~~`; + } + }); + } + } + + return { edit }; + + function edit(type: Alteration) { + if (codemirror.value) { + const selections = codemirror.value.getSelections(); + codemirror.value.replaceSelection(alterations[type](selections)); + } + } +} diff --git a/app/src/interfaces/markdown/index.ts b/app/src/interfaces/markdown/index.ts index 6ebe816cbc..6b8a69efa3 100644 --- a/app/src/interfaces/markdown/index.ts +++ b/app/src/interfaces/markdown/index.ts @@ -21,20 +21,5 @@ export default defineInterface(({ i18n }) => ({ }, }, }, - { - field: 'tabbed', - name: i18n.t('interfaces.markdown.tabbed'), - type: 'boolean', - meta: { - width: 'half', - interface: 'toggle', - options: { - label: i18n.t('interfaces.markdown.tabbed_label'), - }, - }, - schema: { - default_value: false, - }, - }, ], })); diff --git a/app/src/interfaces/markdown/markdown.story.ts b/app/src/interfaces/markdown/markdown.story.ts deleted file mode 100644 index 889813b0cf..0000000000 --- a/app/src/interfaces/markdown/markdown.story.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { withKnobs, boolean, text, optionsKnob } from '@storybook/addon-knobs'; -import { action } from '@storybook/addon-actions'; -import Vue from 'vue'; -import InterfaceMarkdown from './markdown.vue'; -import markdown from './readme.md'; -import withPadding from '../../../.storybook/decorators/with-padding'; -import { defineComponent, ref } from '@vue/composition-api'; -import RawValue from '../../../.storybook/raw-value.vue'; -import i18n from '@/lang'; - -Vue.component('interface-markdown', InterfaceMarkdown); - -export default { - title: 'Interfaces / Markdown', - decorators: [withKnobs, withPadding], - parameters: { - notes: markdown, - }, -}; - -export const basic = () => - defineComponent({ - components: { RawValue }, - i18n, - props: { - disabled: { - default: boolean('Disabled', false, 'Options'), - }, - placeholder: { - default: text('Placeholder', 'Enter a value...', 'Options'), - }, - tabbed: { - default: boolean('Tabbed', false, 'Options'), - }, - }, - setup() { - const value = ref(''); - const onInput = action('input'); - return { onInput, value }; - }, - template: ` -
- - {{ value }} -
- `, - }); diff --git a/app/src/interfaces/markdown/markdown.vue b/app/src/interfaces/markdown/markdown.vue index 464fea1d63..42e8ff58d9 100644 --- a/app/src/interfaces/markdown/markdown.vue +++ b/app/src/interfaces/markdown/markdown.vue @@ -1,33 +1,24 @@