diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index e6d67ea..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitignore b/.gitignore index c999f35..267a6d6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ node_modules dist out *.log* -.DS_Store \ No newline at end of file +*.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index 29dac18..79e7cdf 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,12 @@ After running the app, you can create a new document in which you must follow th Open search document bar Yes + + esc + esc + Close current presentation + Yes + diff --git a/build/.DS_Store b/build/.DS_Store deleted file mode 100644 index 1a73b06..0000000 Binary files a/build/.DS_Store and /dev/null differ diff --git a/package.json b/package.json index 4e68bca..ef293fb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "slidefy", "productName": "Slidefy", - "version": "1.0.0", + "version": "1.0.1", "description": "A slideshow focused on reading markdown files.", "main": "./out/main/index.js", "author": "frankrocha.dev", diff --git a/resources/.DS_Store b/resources/.DS_Store deleted file mode 100644 index 5008ddf..0000000 Binary files a/resources/.DS_Store and /dev/null differ diff --git a/src/.DS_Store b/src/.DS_Store deleted file mode 100644 index d4acb6f..0000000 Binary files a/src/.DS_Store and /dev/null differ diff --git a/src/main/index.ts b/src/main/index.ts index 59a42b9..a6e019d 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -11,8 +11,8 @@ import './store' function createWindow(): void { // Create the browser window. const mainWindow = new BrowserWindow({ - width: 900, - height: 670, + width: 1024, + height: 900, center: true, show: false, autoHideMenuBar: true, diff --git a/src/main/shortcuts.ts b/src/main/shortcuts.ts index 386a0a7..bb3e58d 100644 --- a/src/main/shortcuts.ts +++ b/src/main/shortcuts.ts @@ -5,6 +5,9 @@ export function createShortcuts(window: BrowserWindow) { globalShortcut.register('CommandOrControl+N', () => { window.webContents.send('new-document') }) + globalShortcut.register('Escape', () => { + window.webContents.send('close-document') + }) }) app.on('browser-window-blur', () => { diff --git a/src/main/store.ts b/src/main/store.ts index 289eac5..9a7b032 100644 --- a/src/main/store.ts +++ b/src/main/store.ts @@ -1,12 +1,27 @@ import Store from 'electron-store' import { Document } from '@shared/types/ipc' +import { randomUUID } from 'node:crypto' interface StoreType { + isFirstOpening: boolean documents: Record } export const store = new Store({ defaults: { + isFirstOpening: false, documents: {}, }, }) + +if (store.get('isFirstOpening')) { + const id = randomUUID() + store.set(`documents.${id}`, { + id, + title: 'Presentation Example', + content: ` +

<!— This is a comment! It is not displayed. It also serves to configure the slides —>

Hello Slidefy

Making your presentations easier


Code Block

You can use blocks of code easily

const productName = "Slidefy";

<!— .slide: transition=”convex" background=”aquamarine" —>

Custom Slide

You can customize the transition effect and background of each slide, using a markdown comment with the tags below:

.slide: transition="fast" backgroundColor="aquamarine"

Images and gifs

Use images or gifs via web image url:

teste

+ `, + }) + store.set('isFirstOpening', false) +} diff --git a/src/preload/index.ts b/src/preload/index.ts index 53b0497..e746a2a 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -39,6 +39,13 @@ const api = { ipcRenderer.off('new-document', callback) } }, + closeDocument(callback: () => void) { + ipcRenderer.on('close-document', callback) + + return () => { + ipcRenderer.off('close-document', callback) + } + }, } // Use `contextBridge` APIs to expose Electron APIs to diff --git a/src/renderer/.DS_Store b/src/renderer/.DS_Store deleted file mode 100644 index c34a670..0000000 Binary files a/src/renderer/.DS_Store and /dev/null differ diff --git a/src/renderer/src/.DS_Store b/src/renderer/src/.DS_Store deleted file mode 100644 index 467bf10..0000000 Binary files a/src/renderer/src/.DS_Store and /dev/null differ diff --git a/src/renderer/src/components/Editor/index.tsx b/src/renderer/src/components/Editor/index.tsx index 2024f2a..add985e 100644 --- a/src/renderer/src/components/Editor/index.tsx +++ b/src/renderer/src/components/Editor/index.tsx @@ -40,6 +40,7 @@ export function Editor({ content, onContentUpdated }: EditorProps) { const title = parsedContent?.title ?? 'Untitled' const content = parsedContent?.content ?? '' + setDocument({ title }) return { title, content } } diff --git a/src/renderer/src/components/Header/index.tsx b/src/renderer/src/components/Header/index.tsx index 11c170f..6606d87 100644 --- a/src/renderer/src/components/Header/index.tsx +++ b/src/renderer/src/components/Header/index.tsx @@ -12,7 +12,7 @@ import * as Breadcrumbs from './Breadcrumbs' import { useLocation, useNavigate, useParams } from 'react-router-dom' import { useMutation, useQueryClient } from '@tanstack/react-query' import { Document } from '@shared/types/ipc' -import { useContext } from 'react' +import { useContext, useEffect } from 'react' import { AppContext } from '../../contexts/AppContext' import { ConfirmModal } from '../ConfirmModal' @@ -64,6 +64,18 @@ export function Header({ isSidebarOpen }: HeaderProps) { return false } + useEffect(() => { + function closeCurrentDocument() { + sendToDocument() + } + + const unsubscribe = window.api.closeDocument(closeCurrentDocument) + + return () => { + unsubscribe() + } + }, [sendToDocument]) + return isSidebarOpen ? ( diff --git a/src/renderer/src/modules/reveal/Deck.tsx b/src/renderer/src/modules/reveal/Deck.tsx index 96da063..b15e644 100644 --- a/src/renderer/src/modules/reveal/Deck.tsx +++ b/src/renderer/src/modules/reveal/Deck.tsx @@ -5,7 +5,7 @@ import Highlight from 'reveal.js/plugin/highlight/highlight' const Deck = ({ children }) => { useEffect(() => { const deck = new Reveal() - deck.initialize({ plugins: [Highlight] }) + deck.initialize({ plugins: [Highlight], overview: false }) }) return ( diff --git a/src/renderer/src/modules/reveal/index.tsx b/src/renderer/src/modules/reveal/index.tsx index 06b88f7..330bfc8 100644 --- a/src/renderer/src/modules/reveal/index.tsx +++ b/src/renderer/src/modules/reveal/index.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'react' +import { useEffect, useState, useRef } from 'react' import './styles/reveal.css' import './styles/black.css' import './styles/dracula.css' @@ -7,8 +7,9 @@ import Slide from './Slide' export function SlideShow({ markdownData }) { const [slides, setSlides] = useState([]) + const dataFetchedRef = useRef(false) - const decode = (str) => { + const decode = (str: string) => { const txt = document.createElement('textarea') txt.innerHTML = str @@ -16,19 +17,34 @@ export function SlideShow({ markdownData }) { return txt.value } - const getSectionConfigs = (section, index) => { + const getSections = (section: string, index: number) => { + let slideConfigs = {} const decodedSection = decode(section) + slideConfigs = getSectionConfig(decodedSection) + + const sectionWithoutComments = removeSectionComments(decodedSection) + + setSlides((oldArray) => [ + ...oldArray, + + {sectionWithoutComments} + , + ]) + } + + const getSectionConfig = (decodedSection: string) => { + const configs = {} + const regexGetCommentConfigs = /(

.+?)—><\/p>)/ const slideConfig = decodedSection.match(regexGetCommentConfigs)?.groups - if (slideConfig && slideConfig?.configs.includes('.slide')) { + + if (slideConfig?.configs.includes('.slide')) { const slideConfigProrpeties = slideConfig?.configs .replace(' .slide:', '') .trim() const splitedProperties = slideConfigProrpeties?.split(' ') - const slideProperties = {} - let sectionWithoutConfig = '' if (splitedProperties.length > 0) { splitedProperties.forEach((p) => { @@ -36,35 +52,40 @@ export function SlideShow({ markdownData }) { const key = keyValue[0].replace(/[”"'“]/gi, '') const value = keyValue[1].replace(/[”"'“]/gi, '') - slideProperties[key] = value + configs[key] = value }) - - sectionWithoutConfig = decodedSection.replace( - /(

<\/p>)/, - '', - ) } - - return ( - - {sectionWithoutConfig} - - ) } - return {section} + return configs + } + + const removeSectionComments = (decodedSection: string) => { + const sectionWithoutConfig = decodedSection.replace( + /(

<\/p>)/i, + '', + ) + + return sectionWithoutConfig } useEffect(() => { - const splitedSections = markdownData.content?.split('


') + if (dataFetchedRef.current) return + dataFetchedRef.current = true + + const createSlides = () => { + const splitedSections = markdownData.content?.split('
') + + splitedSections?.forEach((item, index) => { + getSections(item, index) + }) + } - splitedSections?.forEach((item, index) => { - setSlides((oldArray) => [...oldArray, getSectionConfigs(item, index)]) - }) - }, [markdownData.content]) + createSlides() + }) return (
- {slides} + {slides && {slides}}
) } diff --git a/src/renderer/src/pages/Presentation.tsx b/src/renderer/src/pages/Presentation.tsx index af3e4c7..abb9853 100644 --- a/src/renderer/src/pages/Presentation.tsx +++ b/src/renderer/src/pages/Presentation.tsx @@ -3,12 +3,15 @@ import { useQuery } from '@tanstack/react-query' import { useState } from 'react' import { SlideShow } from '../modules/reveal' +interface IMarkdownData { + id: string + content: string + title: string +} + export function Presentation() { const { id } = useParams<{ id: string }>() - const [markdownData, setMarkdownData] = useState( - {} as { id: string; content: string; title: string }, - ) - + const [markdownData, setMarkdownData] = useState(null) useQuery( ['document', id], async () => { @@ -21,7 +24,7 @@ export function Presentation() { return (
- + {markdownData && }
) } diff --git a/src/renderer/src/pages/document.tsx b/src/renderer/src/pages/document.tsx index a00954f..5e3f17f 100644 --- a/src/renderer/src/pages/document.tsx +++ b/src/renderer/src/pages/document.tsx @@ -39,7 +39,7 @@ export function Document() { const initialContent = useMemo(() => { if (data) { - return `

${data.title}

${data.content ?? '

'}` + return `

${data.title}

${data.content ?? ''}` } return '' }, [data]) diff --git a/src/shared/constants/ipc.ts b/src/shared/constants/ipc.ts index e3a8668..1666b22 100644 --- a/src/shared/constants/ipc.ts +++ b/src/shared/constants/ipc.ts @@ -5,5 +5,6 @@ export const IPC = { CREATE: 'documents: create', SAVE: 'documents: save', DELETE: 'documents: delete', + CLOSE: 'documents: close', }, }