Skip to content

Commit

Permalink
add minitrix
Browse files Browse the repository at this point in the history
  • Loading branch information
bastihilger committed Feb 11, 2022
1 parent 1b182bb commit 6737d82
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@
"i": "^0.3.6",
"lodash": "^4.17.21",
"npm": "^7.17.0",
"portal-vue": "^2.1.7",
"pretty": "^2.0.0",
"vue": "^2.6.14",
"vue-codemirror": "^4.0.6",
"vue-template-compiler": "^2.6.14",
"vue-trix": "^1.2.0",
"yarn": "^1.22.11"
}
}
2 changes: 1 addition & 1 deletion resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export default {
mounted() {
this.placeholder = this.field.placeholder ? this.field.placeholder
: (this.field.extraAttributes ? this.field.extraAttributes.placeholder : '');
: (this.field.extraAttributes ? this.field.extraAttributes.placeholder : '');
if (this.field.imageSettings && this.field.imageSettings.path) {
this.imagePath = this.field.imageSettings.path;
Expand Down
190 changes: 190 additions & 0 deletions resources/js/components/SmallEditor.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
<template>
<div>
<div
class="
nova-tiptap-editor
mt-4
form-input-bordered w-full
pt-2 pb-2
"
>
<div
class="
w-full
bg-40 rounded-lg
mb-4
"
>
<template>
<div class="p-1">
<div
v-for="button in buttons"
:key="'button-'+button"
class="inline-block"
>
<template v-if="button == 'heading'">
<heading-buttons
:headingLevels="[2, 3, 4]"
mode="editor"
:editor="editor"
>
</heading-buttons>
</template>

<template v-else-if="button == 'link'">
<link-button
:editor="editor"
:button="button"
:field="field"
mode="editor"
:fileDisk="fileDisk"
:filePath="filePath"
>
</link-button>
</template>

<template v-else>
<normal-button
:editor="editor"
:button="button"
mode="editor"
>
</normal-button>
</template>
</div>
</div>
</template>
</div>

<editor-content :editor="editor" />
</div>
</div>
</template>

<script>
import { Editor, EditorContent } from '@tiptap/vue-2';
import Text from '@tiptap/extension-text';
import Bold from '@tiptap/extension-bold';
import BulletList from '@tiptap/extension-bullet-list';
import Highlight from '@tiptap/extension-highlight';
import HorizontalRule from '@tiptap/extension-horizontal-rule';
import Italic from '@tiptap/extension-italic';
import Link from '@tiptap/extension-link';
import ListItem from '@tiptap/extension-list-item';
import OrderedList from '@tiptap/extension-ordered-list';
import Strike from '@tiptap/extension-strike';
import Subscript from '@tiptap/extension-subscript';
import Superscript from '@tiptap/extension-superscript';
import Underline from '@tiptap/extension-underline';
import Heading from '@tiptap/extension-heading';
import Document from '@tiptap/extension-document';
import Paragraph from '@tiptap/extension-paragraph';
import HardBreak from '@tiptap/extension-hard-break';
import Dropcursor from '@tiptap/extension-dropcursor';
import LinkButton from './buttons/LinkButton';
import NormalButton from './buttons/NormalButton';
import HeadingButtons from './buttons/HeadingButtons';
import BaseButton from './buttons/BaseButton.vue';
import Gapcursor from '@tiptap/extension-gapcursor';
export default {
props: [
'value',
'imageDisk',
'imagePath',
'fileDisk',
'filePath',
],
components: {
EditorContent,
LinkButton,
NormalButton,
HeadingButtons,
BaseButton
},
data () {
return {
editor: null,
localValue: '<p>Fooo</p>',
buttons: [
'heading',
'italic',
'bold',
'link',
'bulletList',
],
}
},
computed: {
field: function () {
return {
attribute: _.uniqueId('small_editor_'),
}
}
},
methods: {
updateValue: function (value) {
this.$emit('input', value);
}
},
mounted() {
let extensions = [
Document,
Bold,
Italic,
Highlight,
Link.extend({
addAttributes() {
return {
...this.parent?.(),
'tt-mode': {
default: 'url',
},
class: String,
rel: String,
title: String,
download: String,
}
}
}),
Strike,
Underline,
Subscript,
Superscript,
Heading.configure({
levels: [2, 3, 4],
}),
BulletList,
HorizontalRule,
ListItem,
OrderedList,
HardBreak,
Paragraph,
Text,
Gapcursor,
Dropcursor,
];
const context = this;
this.editor = new Editor({
extensions: extensions,
content: this.value,
onCreate() {
},
onUpdate() {
context.updateValue(this.getHTML())
//context.debouncer = _.debounce(callback => callback(), context.updateValue(this.getHTML()))
},
});
}
}
</script>
22 changes: 22 additions & 0 deletions resources/js/components/SmallTrixEditor.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<template>
<div>

</div>
</template>

<script>
export default {
props: [
'value',
],
data () {
return {
localValue: '<p>Fooo</p>',
}
}
}
</script>
32 changes: 30 additions & 2 deletions resources/js/components/content-blocks/GalleryContentBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,19 @@
v-model="slides[slideIndex].embedCode"
/>
</div>

<div class="col-span-2">
<label class="block text-sm mb-1 ml-1 capitalize" v-text="__('text')" />

<trix-editor
ref="textEditor"
@keydown.stop
@trix-change="updateSlideText(slideIndex)"
@trix-initialize="initSlideText(slideIndex)"
:value="slides[slideIndex].text"
class="bg-white"
/>
</div>
</div>
</div>

Expand Down Expand Up @@ -431,7 +444,11 @@ export default {
'3:4',
'2:1',
'8:5',
]
],
imageDisk: '',
imagePath: '',
fileDisk: '',
filePath: '',
}
},
Expand All @@ -445,6 +462,13 @@ export default {
},
methods: {
initSlideText(index) {
this.$refs.textEditor[index].editor.insertHTML(this.slides[index].text)
//this.$refs.theEditor.editor.insertHTML(this.value)
},
updateSlideText(index) {
this.slides[index].text = this.$refs.textEditor[index].value
},
addSlide() {
let key = String(_.random(0, 999))+String(Date.now());
let fileInputKey = String(_.random(0, 999))+String(Date.now());
Expand All @@ -459,6 +483,7 @@ export default {
link: '',
linkTarget: '',
embedCode: '',
text: '',
uploading: false,
uploadProgress: 0,
});
Expand Down Expand Up @@ -596,7 +621,10 @@ export default {
},
mounted() {
this.imageDisk = parseInt(this.node.attrs.imageDisk) != 0 ? this.node.attrs.imageDisk : '';
this.imagePath = parseInt(this.node.attrs.imagePath) != 0 ? this.node.attrs.imagePath : '';
this.fileDisk = parseInt(this.node.attrs.fileDisk) != 0 ? this.node.attrs.fileDisk : '';
this.filePath = parseInt(this.node.attrs.filePath) != 0 ? this.node.attrs.filePath : '';
}
}
</script>
2 changes: 2 additions & 0 deletions resources/js/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ window._ = require('lodash');
window.axios = require('axios');

Nova.booting((Vue, router) => {


Vue.component('detail-tiptap', require('./components/DetailField.vue').default);
Vue.component('form-tiptap', require('./components/FormField.vue').default);
})
Expand Down
15 changes: 11 additions & 4 deletions src/TiptapContentBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function ($matches) {
$content = preg_replace_callback(
'/<gallery-content-block slides="(.*?)" slidecount="(.*?)" maxcolumns="(.*?)" mode="(.*?)" formatmode="(.*?)" format="(.*?)" key="(.*?)" imagedisk="(.*?)" imagepath="(.*?)"><\/gallery-content-block>/is',
function ($matches) {
$slides = json_decode(html_entity_decode($matches[1]));
$slides = json_decode(html_entity_decode($matches[1])) ?: [];
$mode = $matches[4];
$maxcolumns = $matches[3];
$formatmode = $matches[5];
Expand All @@ -44,6 +44,11 @@ function ($matches) {
$embedCode = $slide->embedCode;
}

$text = '';
if (@$slide->text && trim(strip_tags($slide->text))) {
$text = $slide->text;
}

$html .= '<div class="ttcp-grid-slide ttcp-grid-formatmode-'.$formatmode.'" ratio="'.$ratio.'">';
$html .= '<div class="ttcp-grid-image-wrapper">';
if (@$slide->link && ! $embedCode) {
Expand All @@ -54,10 +59,12 @@ function ($matches) {
$html .= '>';
}

if (! $embedCode) {
$html .= '<img class="ttcp-grid-image" src="'.$slide->src.'" />';
} else {
if ($embedCode) {
$html .= $embedCode;
} elseif ($text) {
$html .= $text;
} else {
$html .= '<img class="ttcp-grid-image" src="'.$slide->src.'" />';
}

if (@$slide->link && ! $embedCode) {
Expand Down

0 comments on commit 6737d82

Please sign in to comment.