From b30324a06cbf4e330a1bf65cf597595bcbc0c507 Mon Sep 17 00:00:00 2001 From: rijkvanzanten Date: Fri, 15 Jan 2021 11:43:27 -0500 Subject: [PATCH] Add custom syntax block option to markdown And fix v-form overrides --- app/src/components/v-form/readme.md | 19 ++--- .../markdown/composables/use-edit.ts | 44 +++++++++- app/src/interfaces/markdown/index.ts | 80 ++++++++++++++++++- app/src/interfaces/markdown/markdown.vue | 32 +++++++- .../interfaces/repeater/repeater-row-form.vue | 4 +- app/src/lang/translations/en-US.yaml | 12 ++- .../field-detail/components/field.vue | 4 +- .../field-detail/components/schema.vue | 4 +- .../fields/components/field-select.vue | 2 +- .../modules/settings/routes/presets/item.vue | 4 +- .../modules/settings/routes/roles/add-new.vue | 11 +-- .../export-sidebar-detail.vue | 2 +- .../layout-sidebar-detail.vue | 2 +- .../components/users-invite/users-invite.vue | 2 +- 14 files changed, 180 insertions(+), 42 deletions(-) diff --git a/app/src/components/v-form/readme.md b/app/src/components/v-form/readme.md index 032d5089a5..13bee9d2c1 100644 --- a/app/src/components/v-form/readme.md +++ b/app/src/components/v-form/readme.md @@ -1,7 +1,9 @@ # Form + Renders a form using interfaces based on the passed collection name. ## Usage + ```html { newSelection: string; newCursor: Position; highlight?: { from: Position; to: Position } } >; -export function useEdit(codemirror: Ref) { +export type CustomSyntax = { + name: string; + icon: string; + prefix: string; + suffix: string; + box: 'inline' | 'block'; +}; + +export function useEdit(codemirror: Ref, customSyntaxBlocks: CustomSyntax[]) { const alterations: AlterationFunctions = { heading(selection, { cursorTo }, options) { const level = options?.level || 3; @@ -218,6 +227,37 @@ export function useEdit(codemirror: Ref) { return { newSelection: table, newCursor: cursors.cursorFrom }; }, + custom(selection, { cursorTo, cursorHead }, options) { + if (!options) return { newSelection: selection, newCursor: cursorHead }; + + if (options.box === 'block') { + // Multiline + let newSelection = selection; + let newCursor = cursorTo; + + if (selection.startsWith(options.prefix) && selection.endsWith(options.suffix)) { + newSelection = selection.substring(options.prefix.length, selection.length - options.suffix.length); + } else { + newSelection = `${options.prefix}\n${newSelection}\n${options.suffix}`; + newCursor.line = newCursor.line + 1; + } + + return { newSelection, newCursor }; + } else { + // Inline + let newSelection = selection; + let newCursor = cursorTo; + + if (selection.startsWith(options.prefix) && selection.endsWith(options.suffix)) { + newSelection = selection.substring(1, selection.length - 1); + } else { + newSelection = `${options.prefix}${selection}${options.suffix}`; + newCursor.ch = newCursor.ch + 1; + } + + return { newSelection, newCursor }; + } + }, }; return { edit }; diff --git a/app/src/interfaces/markdown/index.ts b/app/src/interfaces/markdown/index.ts index 6b8a69efa3..33a510e0b8 100644 --- a/app/src/interfaces/markdown/index.ts +++ b/app/src/interfaces/markdown/index.ts @@ -14,12 +14,88 @@ export default defineInterface(({ i18n }) => ({ name: i18n.t('placeholder'), type: 'string', meta: { - width: 'half', - interface: 'text-input', + width: 'full', + interface: 'textarea', options: { placeholder: i18n.t('enter_a_placeholder'), }, }, }, + { + field: 'customSyntax', + name: i18n.t('interfaces.markdown.customSyntax'), + label: i18n.t('interfaces.markdown.customSyntax_label'), + type: 'json', + meta: { + width: 'full', + interface: 'repeater', + options: { + addLabel: i18n.t('interfaces.markdown.customSyntax_add'), + template: '{{ name }}', + fields: [ + { + field: 'name', + type: 'string', + name: i18n.t('name'), + meta: { + interface: 'text-input', + width: 'half', + }, + }, + { + field: 'icon', + type: 'string', + name: i18n.t('icon'), + meta: { + interface: 'icon', + width: 'half', + }, + }, + { + field: 'prefix', + type: 'string', + name: i18n.t('prefix'), + meta: { + interface: 'text-input', + width: 'half', + }, + }, + { + field: 'suffix', + type: 'string', + name: i18n.t('suffix'), + meta: { + interface: 'text-input', + width: 'half', + }, + }, + { + field: 'box', + type: 'string', + name: i18n.t('interfaces.markdown.box'), + meta: { + interface: 'radio-buttons', + width: 'half', + options: { + choices: [ + { + text: i18n.t('inline'), + value: 'inline', + }, + { + text: i18n.t('block'), + value: 'block', + }, + ], + }, + }, + schema: { + default_value: 'inline', + }, + }, + ], + }, + }, + }, ], })); diff --git a/app/src/interfaces/markdown/markdown.vue b/app/src/interfaces/markdown/markdown.vue index 02dc6cfa4b..9d6c903c60 100644 --- a/app/src/interfaces/markdown/markdown.vue +++ b/app/src/interfaces/markdown/markdown.vue @@ -73,6 +73,17 @@ + + + +
@@ -88,14 +99,24 @@