Sync snapshot (2026-09-09) (#271)
- **New app: GenOffice HTML.** Open, edit and generate .html pages: a source pane with a sandboxed live preview, click-to-select elements with a floating toolbar and style panel, device-size preview, image tools and a present mode. AI generates whole pages from a brief with style directions and offers page-wide Restyle, Theme and Summarize. Export to Word runs locally through the built-in html2docx converter (native, editable OOXML; no print-to-PDF detour). - **AI:** separate BYOK providers for web search, image generation and image/video analysis; new Codex App Server provider; Ask AI quotes the selected text and keeps it highlighted while it runs; custom AI panel text size; blocked requests retry through the Chromium network stack. - **App:** global AutoSave setting shared by every editor; AI panel text size and chat spellcheck toggles (genoffice#249); Czech (cs) UI locale (genoffice#259); Save As defaults to the document's folder; PDF export no longer aborts on CJK file paths on Windows. - **Docs:** Export as HTML; comments and replies edit in place from the comments pane; the caret can leave a trailing table (genoffice#266); spellcheck re-marks text as soon as it is re-enabled; AI edits are character-precise on partial selections; zoom keeps the scroll position; pasting a cell from Sheets takes the destination font. - **Sheets:** Find no longer freezes on wide or streamed grids; Replace searches as you type; cached values of external-workbook formulas are kept instead of #ERROR! (genoffice#235); "number stored as text" is a warning, not an error (genoffice#236); paste repeats into the target range like Excel; filter criteria survive save/reopen; saves retry when Windows locks the file; many Excel-fidelity fixes for column widths, row heights, charts, slicers, number formats and CJK fonts. - **Slides:** PDF export works for large presentations (genoffice#264); EMF/WMF picture fonts and East Asian theme fonts resolve correctly; decks with missing layouts or embedded styles still open; outline-only pie slices render. - **PDF:** highlight and underline geometry aligns with the text; Shift+arrows extend the selection instead of paging. - **Markdown:** Find and replace (Ctrl+F / Ctrl+H) (genoffice#253); mermaid code blocks render as diagrams (genoffice#263); better print quality. - Thanks to community contributors @GoodScholar, @aniruddhaadak80 and @Sun8854, and to @hanyscz, @qgzln, @zyp997, @bisslot, @krakotay and @Ben03151 for the reports. Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
This commit is contained in:
co-authored by
GenOffice
parent
fa58fff047
commit
d24c964a3e
@@ -16,7 +16,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.9.3",
|
||||
"vitest": "^4.1.0"
|
||||
"vitest": "^4.1.11"
|
||||
},
|
||||
"dependencies": {
|
||||
"parse5": "^8.0.1"
|
||||
|
||||
@@ -43,7 +43,7 @@ const EN: Labels = {
|
||||
}
|
||||
|
||||
// Shared table, same rationale as context-menu.ts: one copy instead of
|
||||
// 15 keys × 19 languages per app dictionary.
|
||||
// 15 keys × 20 languages per app dictionary.
|
||||
const LABELS: Record<string, Labels> = {
|
||||
zh: {
|
||||
window: '窗口',
|
||||
@@ -267,6 +267,23 @@ const LABELS: Record<string, Labels> = {
|
||||
zoomOut: 'Pomniejsz',
|
||||
fullscreen: 'Pełny ekran',
|
||||
},
|
||||
cs: {
|
||||
window: 'Okno',
|
||||
minimize: 'Minimalizovat',
|
||||
closeWindow: 'Zavřít okno',
|
||||
edit: 'Úpravy',
|
||||
undo: 'Zpět',
|
||||
redo: 'Znovu',
|
||||
delete: 'Odstranit',
|
||||
view: 'Zobrazení',
|
||||
reload: 'Znovu načíst',
|
||||
forceReload: 'Vynutit znovunačtení',
|
||||
toggleDevTools: 'Nástroje pro vývojáře',
|
||||
actualSize: 'Skutečná velikost',
|
||||
zoomIn: 'Přiblížit',
|
||||
zoomOut: 'Oddálit',
|
||||
fullscreen: 'Celá obrazovka',
|
||||
},
|
||||
nl: {
|
||||
window: 'Venster',
|
||||
minimize: 'Minimaliseren',
|
||||
|
||||
@@ -13,7 +13,7 @@ export interface ContextMenuLabels {
|
||||
|
||||
const EN: ContextMenuLabels = { cut: 'Cut', copy: 'Copy', paste: 'Paste', selectAll: 'Select All' }
|
||||
|
||||
// One shared table instead of 4 keys × 19 languages duplicated into every
|
||||
// One shared table instead of 4 keys × 20 languages duplicated into every
|
||||
// app's main-process dictionary; strings match the docs Edit menu.
|
||||
const LABELS: Record<string, ContextMenuLabels> = {
|
||||
zh: { cut: '剪切', copy: '复制', paste: '粘贴', selectAll: '全选' },
|
||||
@@ -30,6 +30,7 @@ const LABELS: Record<string, ContextMenuLabels> = {
|
||||
pt: { cut: 'Recortar', copy: 'Copiar', paste: 'Colar', selectAll: 'Selecionar Tudo' },
|
||||
it: { cut: 'Taglia', copy: 'Copia', paste: 'Incolla', selectAll: 'Seleziona tutto' },
|
||||
pl: { cut: 'Wytnij', copy: 'Kopiuj', paste: 'Wklej', selectAll: 'Zaznacz wszystko' },
|
||||
cs: { cut: 'Vyjmout', copy: 'Kopírovat', paste: 'Vložit', selectAll: 'Vybrat vše' },
|
||||
nl: { cut: 'Knippen', copy: 'Kopiëren', paste: 'Plakken', selectAll: 'Alles selecteren' },
|
||||
ms: { cut: 'Potong', copy: 'Salin', paste: 'Tampal', selectAll: 'Pilih Semua' },
|
||||
he: { cut: 'גזור', copy: 'העתק', paste: 'הדבק', selectAll: 'בחר הכול' },
|
||||
|
||||
@@ -58,6 +58,20 @@ export async function showOpenDialogWithMemory(
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Save As suggestion for a document that was opened from `sourcePath`: the
|
||||
* same folder with the suggested name (Word parity — Save As starts where the
|
||||
* document lives, not in the last-used or default folder). Falls back to the
|
||||
* bare name, which `withRememberedDirectory` then anchors, when the document
|
||||
* has never been on disk.
|
||||
*/
|
||||
export function saveAsSuggestion(
|
||||
sourcePath: string | null | undefined,
|
||||
defaultName: string,
|
||||
): string {
|
||||
return sourcePath ? join(dirname(sourcePath), defaultName) : defaultName
|
||||
}
|
||||
|
||||
export async function showSaveDialogWithMemory(
|
||||
dialog: Dialog,
|
||||
parent: BrowserWindow | null | undefined,
|
||||
|
||||
@@ -16,7 +16,7 @@ export const DROP_OPEN_CHANNEL = 'app:open-dropped-files'
|
||||
|
||||
/** Extensions routed by apps/shell routeDocumentPath — keep in sync there and
|
||||
* with OPEN_DIALOG_EXTENSIONS / OPEN_LOCAL_EXTENSIONS on the home screen. */
|
||||
export const OPENABLE_DOC_RE = /\.(docx|xlsx|xlsm|xls|csv|pptx|pdf|md|markdown)$/i
|
||||
export const OPENABLE_DOC_RE = /\.(docx|xlsx|xlsm|xls|csv|pptx|pdf|md|markdown|html|htm)$/i
|
||||
|
||||
/** Recognized-but-unsupported formats: kept in the sent payload so the shell
|
||||
* can show its "not supported" dialog instead of dropping them silently.
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/// Local store for AI-generated images that arrive as bytes (BYOK image
|
||||
/// providers answer with base64, unlike the Genspark CDN URLs the insert
|
||||
/// pipelines were built around). The bytes are written to a fixed temp
|
||||
/// directory and handed back as a file:// URL, which is the only file:// shape
|
||||
/// fetchRemoteImage accepts — anything outside this directory stays refused.
|
||||
|
||||
import { randomUUID } from 'node:crypto'
|
||||
import { mkdirSync, readFileSync, readdirSync, statSync, unlinkSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { basename, join, resolve, sep } from 'node:path'
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||||
|
||||
export const GENERATED_IMAGE_DIR = join(tmpdir(), 'genoffice-ai-images')
|
||||
|
||||
const MIME_BY_EXT: Record<string, string> = {
|
||||
png: 'image/png',
|
||||
jpg: 'image/jpeg',
|
||||
gif: 'image/gif',
|
||||
webp: 'image/webp',
|
||||
}
|
||||
const EXT_BY_MIME: Record<string, string> = {
|
||||
'image/png': 'png',
|
||||
'image/jpeg': 'jpg',
|
||||
'image/jpg': 'jpg',
|
||||
'image/gif': 'gif',
|
||||
'image/webp': 'webp',
|
||||
}
|
||||
const FILE_NAME_RE =
|
||||
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.(png|jpg|gif|webp)$/
|
||||
|
||||
const MAX_AGE_MS = 24 * 60 * 60 * 1000
|
||||
|
||||
/** Best-effort sweep of yesterday's images; the directory is a cache, not a document store */
|
||||
function pruneOld(now = Date.now()): void {
|
||||
let names: string[]
|
||||
try {
|
||||
names = readdirSync(GENERATED_IMAGE_DIR)
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
for (const name of names) {
|
||||
if (!FILE_NAME_RE.test(name)) continue
|
||||
const path = join(GENERATED_IMAGE_DIR, name)
|
||||
try {
|
||||
if (now - statSync(path).mtimeMs > MAX_AGE_MS) unlinkSync(path)
|
||||
} catch {
|
||||
/* another process may have removed it */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function storeGeneratedImage(bytes: Uint8Array, mime: string): string {
|
||||
const ext = EXT_BY_MIME[mime.toLowerCase()] ?? 'png'
|
||||
mkdirSync(GENERATED_IMAGE_DIR, { recursive: true })
|
||||
pruneOld()
|
||||
const path = join(GENERATED_IMAGE_DIR, `${randomUUID()}.${ext}`)
|
||||
writeFileSync(path, bytes)
|
||||
return pathToFileURL(path).toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a file:// URL back only when it names an image this store wrote:
|
||||
* inside GENERATED_IMAGE_DIR, uuid-named, image extension. Returns null for
|
||||
* every other URL so a prompt-injected file:///etc/passwd never gets read.
|
||||
*/
|
||||
export function readGeneratedImage(rawUrl: string): { bytes: Buffer; mime: string } | null {
|
||||
let path: string
|
||||
try {
|
||||
const url = new URL(rawUrl)
|
||||
if (url.protocol !== 'file:') return null
|
||||
path = resolve(fileURLToPath(url))
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
const dir = resolve(GENERATED_IMAGE_DIR)
|
||||
if (!path.startsWith(dir + sep)) return null
|
||||
const name = basename(path)
|
||||
if (!FILE_NAME_RE.test(name) || path !== join(dir, name)) return null
|
||||
try {
|
||||
const bytes = readFileSync(path)
|
||||
return { bytes, mime: MIME_BY_EXT[name.slice(name.lastIndexOf('.') + 1)] ?? 'image/png' }
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,11 @@ export {
|
||||
type AppMenuLabels,
|
||||
} from './app-menu'
|
||||
export { GITHUB_REPO_URL } from './github-menu'
|
||||
export { showOpenDialogWithMemory, showSaveDialogWithMemory } from './dialog-memory'
|
||||
export {
|
||||
saveAsSuggestion,
|
||||
showOpenDialogWithMemory,
|
||||
showSaveDialogWithMemory,
|
||||
} from './dialog-memory'
|
||||
export {
|
||||
DEFAULT_SAVE_DIR_KEY,
|
||||
configuredDefaultSaveDir,
|
||||
@@ -40,6 +44,7 @@ export {
|
||||
type FetchWithSsrfGuardOptions,
|
||||
} from './safe-remote-url'
|
||||
export { fetchRemoteImage, remoteImageHeaders } from './remote-image'
|
||||
export { GENERATED_IMAGE_DIR, readGeneratedImage, storeGeneratedImage } from './generated-images'
|
||||
export {
|
||||
buildPrintableHtml,
|
||||
printHtmlToPdf,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
/// requests; browser-like headers plus a Referer on genspark hosts and a couple
|
||||
/// of retries turn most of those transient failures into successful inserts.
|
||||
|
||||
import { readGeneratedImage } from './generated-images'
|
||||
import { fetchWithSsrfGuard, type FetchWithSsrfGuardOptions } from './safe-remote-url'
|
||||
|
||||
const RETRY_DELAYS_MS: readonly number[] = [500, 1500]
|
||||
@@ -39,6 +40,15 @@ export async function fetchRemoteImage(
|
||||
} = {},
|
||||
): Promise<Response | null> {
|
||||
const { retryDelaysMs = RETRY_DELAYS_MS, ...guardOptions } = options
|
||||
// BYOK-generated images live in the local store; only its own files resolve
|
||||
if (rawUrl.startsWith('file:')) {
|
||||
const local = readGeneratedImage(rawUrl)
|
||||
if (!local) return null
|
||||
return new Response(new Uint8Array(local.bytes), {
|
||||
status: 200,
|
||||
headers: { 'content-type': local.mime, 'content-length': String(local.bytes.byteLength) },
|
||||
})
|
||||
}
|
||||
const headers = remoteImageHeaders(rawUrl)
|
||||
for (let attempt = 0; ; attempt++) {
|
||||
let resp: Response | null = null
|
||||
|
||||
@@ -33,6 +33,7 @@ const LANGS = [
|
||||
'pt',
|
||||
'it',
|
||||
'pl',
|
||||
'cs',
|
||||
'nl',
|
||||
'ms',
|
||||
'he',
|
||||
@@ -50,7 +51,7 @@ beforeEach(() => {
|
||||
})
|
||||
|
||||
describe('appMenuLabels', () => {
|
||||
it('covers all 19 languages with every key non-empty', () => {
|
||||
it('covers all 20 languages with every key non-empty', () => {
|
||||
const keys = Object.keys(en) as (keyof AppMenuLabels)[]
|
||||
for (const lang of LANGS) {
|
||||
const labels = appMenuLabels(lang)
|
||||
|
||||
@@ -2,7 +2,7 @@ import { join } from 'node:path'
|
||||
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { showOpenDialogWithMemory, showSaveDialogWithMemory } from '../src/index'
|
||||
import { saveAsSuggestion, showOpenDialogWithMemory, showSaveDialogWithMemory } from '../src/index'
|
||||
|
||||
import type { Dialog } from 'electron'
|
||||
|
||||
@@ -115,3 +115,33 @@ describe('showSaveDialogWithMemory', () => {
|
||||
expect(dialog.showSaveDialog).toHaveBeenCalledWith({ defaultPath: '/docs/tab.pdf' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('saveAsSuggestion', () => {
|
||||
it('suggests the source document folder with the new name (Word parity)', () => {
|
||||
expect(saveAsSuggestion(join('/work', 'report.docx'), 'report.docx')).toBe(
|
||||
join('/work', 'report.docx'),
|
||||
)
|
||||
expect(saveAsSuggestion(join('/work', 'report.docx'), 'copy.docx')).toBe(
|
||||
join('/work', 'copy.docx'),
|
||||
)
|
||||
})
|
||||
|
||||
it('falls back to the bare name for a document that was never on disk', () => {
|
||||
expect(saveAsSuggestion(null, 'Untitled.docx')).toBe('Untitled.docx')
|
||||
expect(saveAsSuggestion(undefined, 'Untitled.docx')).toBe('Untitled.docx')
|
||||
expect(saveAsSuggestion('', 'Untitled.pptx')).toBe('Untitled.pptx')
|
||||
})
|
||||
|
||||
it('beats the remembered directory when threaded through the save dialog', async () => {
|
||||
const dialog = fakeDialog({ showSaveDialog: pickedSave(join('/elsewhere', 'x.docx')) })
|
||||
// a pick in /elsewhere seeds the remembered directory…
|
||||
await showSaveDialogWithMemory(dialog, undefined, { defaultPath: 'x.docx' })
|
||||
// …but Save As of a document living in /work still opens in /work
|
||||
await showSaveDialogWithMemory(dialog, undefined, {
|
||||
defaultPath: saveAsSuggestion(join('/work', 'report.docx'), 'report.docx'),
|
||||
})
|
||||
expect(dialog.showSaveDialog).toHaveBeenLastCalledWith({
|
||||
defaultPath: join('/work', 'report.docx'),
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { writeFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
GENERATED_IMAGE_DIR,
|
||||
readGeneratedImage,
|
||||
storeGeneratedImage,
|
||||
} from '../src/generated-images'
|
||||
import { fetchRemoteImage } from '../src/remote-image'
|
||||
|
||||
const PNG = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 1, 2, 3])
|
||||
|
||||
describe('generated image store', () => {
|
||||
it('round-trips bytes through a file URL inside the store directory', async () => {
|
||||
const url = storeGeneratedImage(PNG, 'image/png')
|
||||
expect(url.startsWith('file://')).toBe(true)
|
||||
expect(url).toMatch(/\.png$/)
|
||||
const back = readGeneratedImage(url)
|
||||
expect(back?.mime).toBe('image/png')
|
||||
expect(Array.from(back!.bytes)).toEqual(Array.from(PNG))
|
||||
const resp = await fetchRemoteImage(url)
|
||||
expect(resp?.ok).toBe(true)
|
||||
expect(resp?.headers.get('content-type')).toBe('image/png')
|
||||
expect(new Uint8Array(await resp!.arrayBuffer())).toEqual(PNG)
|
||||
})
|
||||
|
||||
it('refuses file URLs outside the store, foreign names inside it, and traversal', async () => {
|
||||
expect(readGeneratedImage('file:///etc/passwd')).toBeNull()
|
||||
const stray = join(GENERATED_IMAGE_DIR, 'notes.txt')
|
||||
writeFileSync(stray, 'x')
|
||||
expect(readGeneratedImage(pathToFileURL(stray).toString())).toBeNull()
|
||||
expect(
|
||||
readGeneratedImage(
|
||||
pathToFileURL(join(GENERATED_IMAGE_DIR, '..', 'genoffice-ai-images', 'x.png')).toString(),
|
||||
),
|
||||
).toBeNull()
|
||||
expect(readGeneratedImage('https://example.com/a.png')).toBeNull()
|
||||
expect(await fetchRemoteImage('file:///etc/hosts')).toBeNull()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user