Commit eadb913e authored by M. Esat Akpunar's avatar M. Esat Akpunar

Add initial implementation of template previewer application

- Created project structure for a Vue.js application with Vite.
- Added main application files including App.vue, main.js, and components.
- Implemented HTML and PDF preview functionality with Monaco Editor for template and data source input.
- Configured environment variables and added .env files for API base URL.
- Included necessary dependencies in package.json for Vue, Vite, and other libraries.
- Established a responsive layout with Tailwind CSS and custom styles.
- Added README and PRD documentation for project overview and requirements.
parents
# HTML ve PDF Önizleyici PRD
## Proje Amacı
Bu proje, kullanıcıların HTML template'lerini ve veri kaynaklarını girerek, sonuçları hem HTML hem de PDF formatında önizleyebilecekleri bir web uygulamasıdır.
## Kullanıcı Arayüzü Gereksinimleri
### Ana Sayfa Düzeni
- Sayfa dikey olarak iki ana bölüme ayrılacak:
1. Sol Panel
2. Sağ Panel
### Sol Panel Özellikleri
1. HTML Template Giriş Alanı
- Geniş bir metin editörü
- Syntax highlighting desteği
- Template değişkenlerini vurgulama
2. Data Source Giriş Alanı
- JSON formatında veri girişi
- Syntax highlighting desteği
- JSON validasyonu
3. Kontrol Butonları
- "Run" butonu
- Template ve veri kaynağını backend'e gönderme
### Sağ Panel Özellikleri
1. Sekmeli Görünüm
- HTML Önizleme sekmesi
- PDF Önizleme sekmesi
2. HTML Önizleme
- Template ve veri kaynağının birleştirilmiş sonucu
- Responsive görünüm
3. PDF Önizleme
- PDF dosyasının önizlemesi
- Zoom in/out özellikleri
## Teknik Gereksinimler
- Frontend Framework: Vue.js
- UI Kütüphanesi: Tailwind CSS
- Code Editor: Monaco Editor
- PDF Görüntüleyici: PDF.js
- Responsive tasarım
- Modern ve kullanıcı dostu arayüz
- Dark/Light mode desteği
- Error notification sistemi
- Detaylı hata yönetimi ve görüntüleme
## Backend Entegrasyonu
- API Endpoint: `/report/pdfTest`
- Request Format:
```json
{
"template": "HTML template string",
"dataSource": "JSON data string"
}
```
- Response Format:
```json
{
"htmlContent": "Rendered HTML string",
"pdfContent": "PDF byte array"
}
```
## Kullanıcı Deneyimi
- Yükleme durumları için loading göstergeleri
- Hata mesajları için toast bildirimleri
- Kullanıcı dostu hata yönetimi
- Responsive tasarım ile mobil uyumluluk
- Dark/Light mode geçiş özelliği
- Detaylı hata mesajları ve bildirimler
## Güvenlik Gereksinimleri
- XSS koruması
- Input validasyonu
- Rate limiting
- CORS politikaları
- Base64 to blob dönüşüm güvenliği
\ No newline at end of file
VITE_API_BASE_URL=https://mars.reybex.com/api
\ No newline at end of file
VITE_API_BASE_URL=https://mars.reybex.com/api
# Configuration Notes:
# VITE_API_BASE_URL: Base URL for the API
\ No newline at end of file
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
.DS_Store
dist
dist-ssr
coverage
*.local
/cypress/videos/
/cypress/screenshots/
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.tsbuildinfo
{
"recommendations": ["Vue.volar"]
}
# template-previewer
This template should help get you started developing with Vue 3 in Vite.
## Recommended IDE Setup
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
## Customize configuration
See [Vite Configuration Reference](https://vite.dev/config/).
## Project Setup
```sh
npm install
```
### Compile and Hot-Reload for Development
```sh
npm run dev
```
### Compile and Minify for Production
```sh
npm run build
```
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Template Previewer</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
{
"compilerOptions": {
"paths": {
"@/*": ["./src/*"]
}
},
"exclude": ["node_modules", "dist"]
}
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "template-previewer",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@monaco-editor/loader": "^1.3.2",
"@vueuse/core": "^10.3.0",
"autoprefixer": "^10.4.16",
"axios": "^1.6.2",
"monaco-editor": "^0.45.0",
"pdfjs-dist": "^3.11.174",
"postcss": "^8.4.31",
"primeicons": "^6.0.1",
"primevue": "^3.38.0",
"splitpanes": "^4.0.3",
"tailwindcss": "^3.3.5",
"toastify-js": "^1.12.0",
"vue": "^3.3.4",
"vue-router": "^4.2.4"
},
"devDependencies": {
"@types/node": "^20.8.9",
"@vitejs/plugin-vue": "^4.3.4",
"vite": "^4.4.11",
"vite-plugin-vue-devtools": "^7.0.0"
}
}
<script setup>
import { ref, watch } from 'vue'
import MonacoEditor from './components/MonacoEditor.vue'
import { Splitpanes, Pane } from 'splitpanes'
import 'splitpanes/dist/splitpanes.css'
const template = ref('')
const dataSource = ref('{}')
const activeTab = ref('html')
const renderedHtml = ref('')
const pdfUrl = ref('')
const isDarkMode = ref(false)
const errorMessage = ref('')
const showError = ref(false)
const tabs = [
{ id: 'html', label: 'HTML Preview' },
{ id: 'pdf', label: 'PDF Preview' }
]
const editorOptions = {
minimap: { enabled: false },
fontSize: 14,
lineNumbers: 'on',
roundedSelection: false,
scrollBeyondLastLine: false,
readOnly: false,
automaticLayout: true
}
const toggleTheme = () => {
isDarkMode.value = !isDarkMode.value
document.documentElement.setAttribute('data-theme', isDarkMode.value ? 'dark' : 'light')
}
// Utility function to render template with data
const renderTemplate = (template, data) => {
return template.replace(/\{\{([^}]+)\}\}/g, (match, key) => {
// Handle nested properties using dot notation
const value = key.split('.').reduce((obj, k) => obj?.[k], data)
return value !== undefined ? value : match
})
}
const runPreview = async () => {
try {
errorMessage.value = ''
showError.value = false
// Prepare request data with raw string values
const requestData = {
dataSource: dataSource.value,
template: template.value
}
// Make API request
const response = await previewAPI(requestData)
// Handle the response
if (response.htmlContent) {
renderedHtml.value = response.htmlContent
updateIframeContent(response.htmlContent)
}
if (response.pdfContent) {
// Convert byte array to blob
const pdfBlob = new Blob([new Uint8Array(response.pdfContent)], { type: 'application/pdf' })
pdfUrl.value = URL.createObjectURL(pdfBlob)
}
} catch (error) {
console.error('Error running preview:', error)
errorMessage.value = error.message
showError.value = true
// Clear the contents
renderedHtml.value = ''
updateIframeContent('')
// Clear PDF URL
if (pdfUrl.value) {
URL.revokeObjectURL(pdfUrl.value)
pdfUrl.value = ''
}
}
}
// Utility function to update iframe content
const updateIframeContent = (content) => {
const iframe = document.getElementById('preview-iframe')
if (iframe) {
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document
iframeDoc.open()
iframeDoc.write(content)
iframeDoc.close()
}
}
// Watch for tab changes
watch(activeTab, (newTab) => {
if (newTab === 'html' && renderedHtml.value) {
// Restore HTML content when switching back to HTML tab
updateIframeContent(renderedHtml.value)
}
})
// API endpoint constant
const API_ENDPOINT = '/report/pdfTest'
// API function
const previewAPI = async (requestData) => {
try {
const apiUrl = `${import.meta.env.VITE_API_BASE_URL}${API_ENDPOINT}`
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(requestData)
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
if (!data.htmlContent || !data.pdfContent) {
throw new Error('Invalid response format from server')
}
return {
htmlContent: data.htmlContent,
pdfContent: data.pdfContent
}
} catch (error) {
console.error('API Error:', error)
throw new Error(`API request failed: ${error.message}`)
}
}
// Utility function to convert base64 to blob
const base64ToBlob = (base64, type = '') => {
const binStr = atob(base64)
const len = binStr.length
const arr = new Uint8Array(len)
for (let i = 0; i < len; i++) {
arr[i] = binStr.charCodeAt(i)
}
return new Blob([arr], { type })
}
</script>
<template>
<div class="app-container" :class="{ 'dark-mode': isDarkMode }">
<!-- Error Notification -->
<div v-if="showError" class="error-notification">
<div class="error-content">
<span class="error-icon">⚠️</span>
<span class="error-text">{{ errorMessage }}</span>
<button class="error-close" @click="showError = false">×</button>
</div>
</div>
<div class="theme-toggle">
<button @click="toggleTheme" class="theme-button">
{{ isDarkMode ? '☀️' : '🌙' }}
</button>
</div>
<Splitpanes class="main-layout">
<!-- Sol Panel -->
<Pane min-size="20" size="50">
<div class="left-panel">
<div class="editor-section">
<h2>HTML Template</h2>
<div class="editor-container">
<MonacoEditor
v-model="template"
language="html"
:theme="isDarkMode ? 'vs-dark' : 'vs-light'"
:options="editorOptions"
/>
</div>
</div>
<div class="editor-section">
<h2>Data Source</h2>
<div class="editor-container">
<MonacoEditor
v-model="dataSource"
language="json"
:theme="isDarkMode ? 'vs-dark' : 'vs-light'"
:options="editorOptions"
/>
</div>
</div>
<div class="control-buttons">
<button @click="runPreview" class="run-button">Run</button>
</div>
</div>
</Pane>
<!-- Sağ Panel -->
<Pane min-size="20" size="50">
<div class="right-panel">
<div class="tabs">
<button
v-for="tab in tabs"
:key="tab.id"
:class="{ active: activeTab === tab.id }"
@click="activeTab = tab.id"
>
{{ tab.label }}
</button>
</div>
<div class="preview-container">
<div v-show="activeTab === 'html'" class="html-preview">
<iframe id="preview-iframe" frameborder="0" width="100%" height="100%"></iframe>
</div>
<div v-show="activeTab === 'pdf'" class="pdf-preview">
<iframe v-if="pdfUrl" :src="pdfUrl" frameborder="0"></iframe>
</div>
</div>
</div>
</Pane>
</Splitpanes>
</div>
</template>
<style>
/* Scrollbar gizleme ve düzenleme */
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: transparent;
}
::-webkit-scrollbar-thumb {
background: var(--border-color);
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: var(--accent-color);
}
/* Root stilleri */
:root {
--bg-primary: #ffffff;
--bg-secondary: #f5f5f5;
--text-primary: #333333;
--text-secondary: #666666;
--border-color: #dddddd;
--accent-color: #4CAF50;
--accent-hover: #45a049;
--editor-border: #e0e0e0;
}
[data-theme="dark"] {
--bg-primary: #1e1e1e;
--bg-secondary: #252525;
--text-primary: #ffffff;
--text-secondary: #cccccc;
--border-color: #333333;
--editor-border: #333333;
}
/* Reset margin ve padding */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: var(--bg-primary);
}
.app-container {
height: 100vh;
width: 100vw;
display: flex;
flex-direction: column;
overflow: hidden;
background-color: var(--bg-primary);
color: var(--text-primary);
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.main-layout {
flex: 1;
display: flex;
overflow: hidden;
background-color: var(--bg-primary);
height: 100%;
width: 100%;
}
.left-panel, .right-panel {
height: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
background-color: var(--bg-primary);
width: 100%;
}
/* Splitpanes custom styles */
.splitpanes {
background-color: var(--bg-primary) !important;
height: 100% !important;
width: 100% !important;
}
.splitpanes__pane {
background-color: var(--bg-primary) !important;
height: 100% !important;
}
.splitpanes__splitter {
background-color: var(--border-color) !important;
position: relative;
width: 6px !important;
margin: 0 -3px;
cursor: col-resize;
z-index: 10;
}
.splitpanes__splitter:hover {
background-color: var(--accent-color) !important;
}
.dark-mode .splitpanes__splitter {
background-color: var(--border-color) !important;
}
.dark-mode .splitpanes__splitter:hover {
background-color: var(--accent-color) !important;
}
.editor-section {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
padding: 1rem;
min-height: 0; /* Önemli: Flex child overflow için */
}
.editor-section h2 {
color: var(--text-primary);
margin-bottom: 0.5rem;
}
.editor-container {
flex: 1;
overflow: hidden;
border: 1px solid var(--editor-border);
border-radius: 4px;
min-height: 0; /* Önemli: Flex child overflow için */
}
.preview-container {
flex: 1;
overflow: hidden;
padding: 1rem;
min-height: 0; /* Önemli: Flex child overflow için */
}
.control-buttons {
padding: 1rem;
display: flex;
justify-content: flex-end;
}
.run-button {
padding: 0.5rem 1rem;
background-color: var(--accent-color);
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s;
font-size: 1rem;
font-weight: 500;
}
.run-button:hover {
background-color: var(--accent-hover);
}
.theme-toggle {
position: fixed;
top: 1rem;
right: 1rem;
z-index: 1000;
}
.theme-button {
padding: 0.5rem;
font-size: 1.2rem;
background: none;
border: 1px solid var(--border-color);
border-radius: 50%;
cursor: pointer;
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
transition: background-color 0.3s;
}
.theme-button:hover {
background-color: var(--bg-secondary);
}
.tabs {
display: flex;
border-bottom: 1px solid var(--border-color);
background-color: var(--bg-secondary);
}
.tabs button {
padding: 0.5rem 1rem;
border: none;
background: none;
cursor: pointer;
color: var(--text-secondary);
transition: color 0.3s;
}
.tabs button.active {
color: var(--accent-color);
border-bottom: 2px solid var(--accent-color);
}
.html-preview {
height: 100%;
border: 1px solid var(--border-color);
border-radius: 4px;
background-color: var(--bg-primary);
overflow: hidden;
}
.html-preview iframe {
border: none;
background-color: white;
}
.pdf-preview {
height: 100%;
}
.pdf-preview iframe {
width: 100%;
height: 100%;
border: 1px solid var(--border-color);
border-radius: 4px;
}
/* Responsive Design */
@media (max-width: 768px) {
.main-layout {
flex-direction: column;
height: auto;
}
.left-panel,
.right-panel {
width: 100%;
height: 50vh;
}
.left-panel {
border-right: none;
border-bottom: 1px solid var(--border-color);
}
.theme-toggle {
top: 0.5rem;
right: 0.5rem;
}
.editor-section {
min-height: 200px;
}
.preview-container {
height: calc(50vh - 41px);
}
}
@media (max-width: 480px) {
.left-panel,
.right-panel {
padding: 0.5rem;
}
.control-buttons {
padding: 0.5rem;
}
.tabs button {
padding: 0.5rem;
font-size: 0.9rem;
}
}
.error-notification {
position: fixed;
top: 1rem;
left: 50%;
transform: translateX(-50%);
z-index: 1001;
background-color: #ff5252;
color: white;
padding: 0.75rem 1rem;
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
max-width: 90%;
animation: slideDown 0.3s ease-out;
}
.error-content {
display: flex;
align-items: center;
gap: 0.5rem;
}
.error-icon {
font-size: 1.2rem;
}
.error-text {
flex: 1;
font-size: 0.9rem;
}
.error-close {
background: none;
border: none;
color: white;
font-size: 1.2rem;
cursor: pointer;
padding: 0 0.25rem;
opacity: 0.8;
transition: opacity 0.2s;
}
.error-close:hover {
opacity: 1;
}
@keyframes slideDown {
from {
transform: translate(-50%, -100%);
opacity: 0;
}
to {
transform: translate(-50%, 0);
opacity: 1;
}
}
/* Responsive adjustments for error notification */
@media (max-width: 768px) {
.error-notification {
width: 90%;
}
}
</style>
/* color palette from <https://github.com/vuejs/theme> */
:root {
--vt-c-white: #ffffff;
--vt-c-white-soft: #f8f8f8;
--vt-c-white-mute: #f2f2f2;
--vt-c-black: #181818;
--vt-c-black-soft: #222222;
--vt-c-black-mute: #282828;
--vt-c-indigo: #2c3e50;
--vt-c-divider-light-1: rgba(60, 60, 60, 0.29);
--vt-c-divider-light-2: rgba(60, 60, 60, 0.12);
--vt-c-divider-dark-1: rgba(84, 84, 84, 0.65);
--vt-c-divider-dark-2: rgba(84, 84, 84, 0.48);
--vt-c-text-light-1: var(--vt-c-indigo);
--vt-c-text-light-2: rgba(60, 60, 60, 0.66);
--vt-c-text-dark-1: var(--vt-c-white);
--vt-c-text-dark-2: rgba(235, 235, 235, 0.64);
}
/* semantic color variables for this project */
:root {
--color-background: var(--vt-c-white);
--color-background-soft: var(--vt-c-white-soft);
--color-background-mute: var(--vt-c-white-mute);
--color-border: var(--vt-c-divider-light-2);
--color-border-hover: var(--vt-c-divider-light-1);
--color-heading: var(--vt-c-text-light-1);
--color-text: var(--vt-c-text-light-1);
--section-gap: 160px;
}
@media (prefers-color-scheme: dark) {
:root {
--color-background: var(--vt-c-black);
--color-background-soft: var(--vt-c-black-soft);
--color-background-mute: var(--vt-c-black-mute);
--color-border: var(--vt-c-divider-dark-2);
--color-border-hover: var(--vt-c-divider-dark-1);
--color-heading: var(--vt-c-text-dark-1);
--color-text: var(--vt-c-text-dark-2);
}
}
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
font-weight: normal;
}
body {
min-height: 100vh;
color: var(--color-text);
background: var(--color-background);
transition:
color 0.5s,
background-color 0.5s;
line-height: 1.6;
font-family:
Inter,
-apple-system,
BlinkMacSystemFont,
'Segoe UI',
Roboto,
Oxygen,
Ubuntu,
Cantarell,
'Fira Sans',
'Droid Sans',
'Helvetica Neue',
sans-serif;
font-size: 15px;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 261.76 226.69"><path d="M161.096.001l-30.225 52.351L100.647.001H-.005l130.877 226.688L261.749.001z" fill="#41b883"/><path d="M161.096.001l-30.225 52.351L100.647.001H52.346l78.526 136.01L209.398.001z" fill="#34495e"/></svg>
@import './base.css';
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
#app {
width: 100%;
height: 100vh;
}
a,
.green {
text-decoration: none;
color: hsla(160, 100%, 37%, 1);
transition: 0.4s;
padding: 3px;
}
@media (hover: hover) {
a:hover {
background-color: hsla(160, 100%, 37%, 0.2);
}
}
@media (min-width: 1024px) {
body {
display: flex;
place-items: center;
}
#app {
display: grid;
grid-template-columns: 1fr 1fr;
padding: 0 2rem;
}
}
<template>
<div ref="editorContainer" class="monaco-editor"></div>
</template>
<script setup>
import { ref, onMounted, watch, onBeforeUnmount } from 'vue'
import * as monaco from 'monaco-editor'
import loader from '@monaco-editor/loader'
const props = defineProps({
modelValue: {
type: String,
default: ''
},
language: {
type: String,
default: 'javascript'
},
theme: {
type: String,
default: 'vs-dark'
},
options: {
type: Object,
default: () => ({})
}
})
const emit = defineEmits(['update:modelValue'])
const editorContainer = ref(null)
let editor = null
onMounted(async () => {
await loader.init()
editor = monaco.editor.create(editorContainer.value, {
value: props.modelValue,
language: props.language,
theme: props.theme,
automaticLayout: true,
...props.options
})
editor.onDidChangeModelContent(() => {
const value = editor.getValue()
emit('update:modelValue', value)
})
})
watch(() => props.modelValue, (newValue) => {
if (editor && newValue !== editor.getValue()) {
editor.setValue(newValue)
}
})
watch(() => props.language, (newValue) => {
if (editor) {
monaco.editor.setModelLanguage(editor.getModel(), newValue)
}
})
watch(() => props.theme, (newValue) => {
if (editor) {
monaco.editor.setTheme(newValue)
}
})
onBeforeUnmount(() => {
if (editor) {
editor.dispose()
}
})
</script>
<style scoped>
.monaco-editor {
width: 100%;
height: 100%;
}
</style>
\ No newline at end of file
import './assets/main.css'
import { createApp } from 'vue'
import App from './App.vue'
import PrimeVue from 'primevue/config'
import ToastService from 'primevue/toastservice'
import 'primevue/resources/themes/lara-light-blue/theme.css'
import 'primevue/resources/primevue.min.css'
import 'primeicons/primeicons.css'
import 'toastify-js/src/toastify.css'
const app = createApp(App)
app.use(PrimeVue)
app.use(ToastService)
app.mount('#app')
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
// https://vite.dev/config/
export default defineConfig({
plugins: [
vue(),
vueDevTools(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
},
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment