Skip to content

Commit

Permalink
Working on editor super excited about that
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Jul 18, 2024
1 parent 15adc0b commit 2f7cde1
Show file tree
Hide file tree
Showing 9 changed files with 5,610 additions and 773 deletions.
9 changes: 9 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,19 @@ public function boot(): void
return false;
});

Feature::define('editor', function (User $user) {
if (config('llmdriver.features.editor')) {
return true;
}

return false;
});

Feature::define('verification_prompt_tags', function (User $user) {
return false;
});


Feature::define('verification_prompt', function (User $user) {
return false;
});
Expand Down
1 change: 1 addition & 0 deletions config/llmdriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
'chatv2' => true,
'reference_collection' => env('FEATURE_REFERENCE_COLLECTION', false),
'date_range' => env('FEATURE_DATE_RANGE', true),
'editor' => env('FEATURE_EDITOR', false),
'all_tools' => env('FEATURE_ALL_TOOLS', false),
],
'sources' => [
Expand Down
6,094 changes: 5,332 additions & 762 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,35 @@
"vue": "^3.3.13"
},
"dependencies": {
"@codemirror/autocomplete": "^6.17.0",
"@editorjs/editorjs": "^2.30.2",
"@formkit/auto-animate": "^0.8.1",
"@headlessui/vue": "^1.7.19",
"@heroicons/vue": "^2.1.1",
"@kangc/v-md-editor": "^2.3.18",
"@tiptap/extension-bubble-menu": "^2.5.4",
"@tiptap/extension-color": "^2.5.1",
"@tiptap/extension-list-item": "^2.5.1",
"@tiptap/extension-text-style": "^2.5.1",
"@tiptap/pm": "^2.5.4",
"@tiptap/starter-kit": "^2.5.4",
"@tiptap/vue-3": "^2.5.4",
"@vitejs/plugin-basic-ssl": "^1.1.0",
"apexcharts": "^3.47.0",
"axios": "^1.6.4",
"easymde": "^2.18.0",
"laravel-echo": "^1.16.1",
"laravel-vite-plugin": "^1.0",
"md-editor-v3": "^4.17.3",
"puppeteer": "^22.7.1",
"pusher-js": "^8.4.0-rc2",
"theme-change": "^2.5.0",
"vue-apexcharts": "^1.6.2",
"vue-toastification": "^2.0.0-rc.5",
"vue-upload-component": "^3.1.15",
"vue3-apexcharts": "^1.5.2",
"vue3-dropzone": "^2.2.1"
"vue3-dropzone": "^2.2.1",
"vue3-easymde": "^1.0.1",
"vue3-markdown": "^1.1.9"
}
}
213 changes: 213 additions & 0 deletions resources/js/Components/Editor.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
<template>
<bubble-menu
:editor="editor"
:tippy-options="{ duration: 100 }"
v-if="editor">

<div class="control-group">
<div class="button-group">
<button type="button" @click="editor.chain().focus().toggleBold().run()" :disabled="!editor.can().chain().focus().toggleBold().run()" :class="{ 'is-active': editor.isActive('bold') }">
Bold
</button>
<button type="button" @click="editor.chain().focus().toggleItalic().run()" :disabled="!editor.can().chain().focus().toggleItalic().run()" :class="{ 'is-active': editor.isActive('italic') }">
Italic
</button>
<button type="button" @click="editor.chain().focus().toggleStrike().run()" :disabled="!editor.can().chain().focus().toggleStrike().run()" :class="{ 'is-active': editor.isActive('strike') }">
Strike
</button>
<button type="button" @click="editor.chain().focus().toggleCode().run()" :disabled="!editor.can().chain().focus().toggleCode().run()" :class="{ 'is-active': editor.isActive('code') }">
Code
</button>
<button type="button" @click="editor.chain().focus().setParagraph().run()" :class="{ 'is-active': editor.isActive('paragraph') }">
Paragraph
</button>
<button type="button" @click="editor.chain().focus().toggleHeading({ level: 1 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 1 }) }">
H1
</button>
<button type="button" @click="editor.chain().focus().toggleHeading({ level: 2 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 2 }) }">
H2
</button>
<button type="button" @click="editor.chain().focus().toggleHeading({ level: 3 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 3 }) }">
H3
</button>
<button type="button" @click="editor.chain().focus().toggleBulletList().run()" :class="{ 'is-active': editor.isActive('bulletList') }">
Bullet list
</button>
<button type="button" @click="editor.chain().focus().toggleOrderedList().run()" :class="{ 'is-active': editor.isActive('orderedList') }">
Ordered list
</button>
<button type="button" @click="editor.chain().focus().toggleCodeBlock().run()" :class="{ 'is-active': editor.isActive('codeBlock') }">
Code block
</button>
<button type="button" @click="editor.chain().focus().toggleBlockquote().run()" :class="{ 'is-active': editor.isActive('blockquote') }">
Blockquote
</button>
<button type="button" @click="editor.chain().focus().setHorizontalRule().run()">
Horizontal rule
</button>
<button type="button" @click="editor.chain().focus().setHardBreak().run()">
Hard break
</button>
<button type="button" @click="editor.chain().focus().undo().run()" :disabled="!editor.can().chain().focus().undo().run()">
Undo
</button>
<button type="button" @click="editor.chain().focus().redo().run()" :disabled="!editor.can().chain().focus().redo().run()">
Redo
</button>
</div>
</div>
</bubble-menu>


<editor-content
@input="$emit('update:modelValue', $event.target.getHTML())"
:editor="editor" />

<div>
</div>

</template>

<script setup>
import { BubbleMenu, Editor, EditorContent } from '@tiptap/vue-3'
import StarterKit from '@tiptap/starter-kit'
import {ref, watch, onMounted, onBeforeUnmount} from "vue";
const editor = ref(null);
const props = defineProps({
modelValue: {
type: String,
default: '',
},
});
onMounted(() => {
editor.value = new Editor({
content: '<p>Edit here using Markdown</p>',
extensions: [StarterKit],
})
})
onBeforeUnmount(() => {
editor.value.destroy()
})
</script>

<style scoped>
.tiptap :first-child {
margin-top: 0;
}
.tiptap ul,
.tiptap ol {
padding: 0 1rem;
margin: 1.25rem 1rem 1.25rem 0.4rem;
}
.tiptap ul li p,
.tiptap ol li p {
margin-top: 0.25em;
margin-bottom: 0.25em;
}
.tiptap h1,
.tiptap h2,
.tiptap h3,
.tiptap h4,
.tiptap h5,
.tiptap h6 {
line-height: 1.1;
margin-top: 2.5rem;
text-wrap: pretty;
}
.tiptap h1,
.tiptap h2 {
margin-top: 3.5rem;
margin-bottom: 1.5rem;
}
.tiptap h1 {
font-size: 1.4rem;
}
.tiptap h2 {
font-size: 1.2rem;
}
.tiptap h3 {
font-size: 1.1rem;
}
.tiptap h4,
.tiptap h5,
.tiptap h6 {
font-size: 1rem;
}
.tiptap code {
background-color: var(--purple-light);
border-radius: 0.4rem;
color: var(--black);
font-size: 0.85rem;
padding: 0.25em 0.3em;
}
.tiptap pre {
background: var(--black);
border-radius: 0.5rem;
color: var(--white);
font-family: 'JetBrainsMono', monospace;
margin: 1.5rem 0;
padding: 0.75rem 1rem;
}
.tiptap pre code {
background: none;
color: inherit;
font-size: 0.8rem;
padding: 0;
}
.tiptap blockquote {
border-left: 3px solid var(--gray-3);
margin: 1.5rem 0;
padding-left: 1rem;
}
.tiptap hr {
border: none;
border-top: 1px solid var(--gray-2);
margin: 2rem 0;
}
.bubble-menu {
background-color: var(--white);
border: 1px solid var(--gray-1);
border-radius: 0.7rem;
box-shadow: var(--shadow);
display: flex;
padding: 0.2rem;
}
.bubble-menu button {
background-color: unset;
}
.bubble-menu button:hover {
background-color: var(--gray-3);
}
.bubble-menu button.is-active {
background-color: var(--purple);
}
.bubble-menu button.is-active:hover {
background-color: var(--purple-contrast);
}
</style>
24 changes: 22 additions & 2 deletions resources/js/Pages/Collection/Components/ShowDocument.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@
</div>
<div class="relative mt-6 flex-1 px-4 sm:px-6" v-auto-animate>
<Tags :document="document"></Tags>
<div class="flex justify-end gap-2 items-center">
<div class="flex justify-end gap-2 items-center mt-2">
<UpdateSummary
@startingUpdate="startingUpdate"
@updateSummary="updateSummary"
:document="document"></UpdateSummary>
<button
v-if="false"
type="button" class="btn btn-ghost rounded-none" @click="toggleEdit">
edit</button>
</div>
<h2 class="font-bold">Summary:</h2>
<div v-if="updating" class="mt-10">
Expand All @@ -44,8 +48,15 @@
</div>
</div>
<div
v-if="!updating"
v-if="!updating && !showEdit"
class="prose mb-10 mt-5" v-html="documentToShow.summary_markdown"></div>
<div v-if="showEdit && !updating && false">
<MdEditor
theme="dark"
language="en"
:preview=false
v-model="documentToShow.summary" />
</div>
</div>
</div>
</DialogPanel>
Expand All @@ -60,6 +71,9 @@


<script setup>
import { MdEditor } from 'md-editor-v3';
import 'md-editor-v3/lib/style.css';
import { Dialog, DialogPanel, DialogTitle, TransitionChild, TransitionRoot } from '@headlessui/vue'
import { XMarkIcon } from '@heroicons/vue/24/outline'
import Tags from '@/Components/Tags.vue';
Expand All @@ -78,10 +92,16 @@ onMounted(() => {
documentToShow.value = props.document;
});
const showEdit = ref(false);
const emit = defineEmits(['closing']);
const updating = ref(false);
const toggleEdit = () => {
showEdit.value = !showEdit.value;
}
const startingUpdate = () => {
updating.value = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,35 @@
<InputError :message="modelValue.errors.name" class="mt-2" />
</div>
<div class="col-span-6 sm:col-span-6">
<InputLabel value="Content (Markdown is ideal)" />
<TextArea v-model="modelValue.content" type="text" class="mt-1 block w-full" rows="30"/>
<InputLabel value="Content" />

<Editor
v-if="usePage().props.features.editor"
v-model="modelValue.content" />

<TextArea v-else
v-model="modelValue.content" type="text"
class="w-full textarea textarea-secondary" rows="30"/>
<InputError :message="modelValue.errors.content" class="mt-2" />
</div>
</div>
</template>

<script setup>
import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import TextInput from '@/Components/TextInput.vue';
import TextArea from '@/Components/TextArea.vue';
import LlmType from './LlmType.vue';
import EmbeddingType from './EmbeddingType.vue';
import Editor from '@/Components/Editor.vue';
import {usePage} from "@inertiajs/vue3";
const props = defineProps({
modelValue: Object,
});
</script>
</script>
2 changes: 1 addition & 1 deletion resources/js/Pages/Collection/Components/UpdateSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const updateSummary = () => {
<button
:disabled="running"
type="button"
class="btn btn-primary rounded-none mt-2"
class="btn btn-primary rounded-none"
@click="updateSummary">
Generate Summary
</button>
Expand Down
1 change: 0 additions & 1 deletion resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import VueApexCharts from "vue3-apexcharts";
import Toast, { TYPE } from "vue-toastification";
import { autoAnimatePlugin } from '@formkit/auto-animate/vue'


import "vue-toastification/dist/index.css";
const appName = import.meta.env.VITE_APP_NAME || 'Template App';

Expand Down

0 comments on commit 2f7cde1

Please sign in to comment.