Skip to content

AI-native design editor. Open-source Figma alternative.

feat(storage): save the open document to storage from the File menu (#991)

Danila Poyarkovb670f1bf923b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1ad1c11bb..c63391157 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -38,6 +38,7 @@
### Added
+- Save the open document to cloud storage with **File → Save to storage…**. The tab stays bound to the stored copy, so Save and auto-save write to the bucket; before storage is configured, the command opens its settings. A new Cloud Storage guide covers connecting a bucket, CORS, syncing, and provider notes.
- Add a variant to a standalone component from the header's **Add variant** button, as in Figma (#847): it becomes a component set named after it, whose existing instances and properties carry over, with a `Property 1=Variant2` copy below. A set's variant properties are rows of its **Properties** list, each opening to rename it and add, rename, reorder, or remove its values; removing a value variants still use moves them to another value. Variants that share a combination of values are named in a notice that selects them.
- Create and edit a component's text, boolean, and instance swap properties from the properties panel, as in Figma (#847). A layer in a main component links its text content, visibility, or swapped component to a new or existing property from the Typography and Appearance sections and the instance header, and shows the linked property in place of the value. The component lists its properties, each opening to rename it, change its default, see and unlink the layers it drives, or delete it, and reorders them by dragging. Expose nested instances so their properties show, grouped under the instance's name, on instances of the component. Typing into text a property drives sets the property: its default in the main component, the instance's value in an instance.
- An icon picker searches Iconify's open-source sets from the toolbar, the Object menu, and the command palette, and inserts the chosen icon at the middle of the view. It starts with the icons already in the file and the ones picked lately, and a set button in the search field narrows it to one set. Placed icons keep their name, so the Design panel's Icon section can swap the glyph or change its color in one undo step, and design JSX and HTML exports write them as icons.
@@ -133,6 +134,7 @@
### Fixed
+- Show when the browser menubar has more menus than fit in the left panel. The clipped side fades out and a chevron scrolls to the hidden menus; before, Arrange and Text could be cut off with no sign the bar scrolls.
- List storage documents as soon as storage settings are saved. The home tab kept asking to configure storage until it next refreshed, which happened on window focus or up to a minute later.
- Keep a Figma file's exposed nested instances when it is saved from OpenPencil; their properties stopped showing on the outer component's instances in Figma.
- Offer only components that fit in an instance swap's list: one that would contain itself, such as the component the swapped layer sits in, is left out, and a variant is named with its set, as in `Badge / State=Info`.
diff --git a/desktop/generated/menu.json b/desktop/generated/menu.json
index 5ff702a31..542ea88d9 100644
--- a/desktop/generated/menu.json
+++ b/desktop/generated/menu.json
@@ -33,6 +33,10 @@
"label": "Save As…",
"accelerator": "CmdOrCtrl+Shift+S"
},
+ {
+ "id": "save-to-storage",
+ "label": "Save to Storage…"
+ },
{
"type": "separator"
},
diff --git a/packages/docs/.vitepress/labels.ts b/packages/docs/.vitepress/labels.ts
index 1aa81cfab..946693c99 100644
--- a/packages/docs/.vitepress/labels.ts
+++ b/packages/docs/.vitepress/labels.ts
@@ -17,6 +17,7 @@ export interface SidebarLabels {
components: string
variables: string
checkingDesigns: string
+ cloudStorage: string
overview: string
gettingStarted: string
features: string
@@ -168,6 +169,7 @@ export const EN: SidebarLabels = {
components: 'Components',
variables: 'Variables',
checkingDesigns: 'Checking Designs',
+ cloudStorage: 'Cloud Storage',
icons: 'Icons',
overview: 'Overview',
gettingStarted: 'Getting Started',
@@ -195,6 +197,7 @@ export const DE: SidebarLabels = {
components: 'Komponenten',
variables: 'Variablen',
checkingDesigns: 'Designs prüfen',
+ cloudStorage: 'Cloud-Speicher',
icons: 'Symbole',
overview: 'Überblick',
gettingStarted: 'Erste Schritte',
@@ -222,6 +225,7 @@ export const IT: SidebarLabels = {
components: 'Componenti',
variables: 'Variabili',
checkingDesigns: 'Verificare i design',
+ cloudStorage: 'Archiviazione cloud',
icons: 'Icone',
overview: 'Panoramica',
gettingStarted: 'Per iniziare',
@@ -249,6 +253,7 @@ export const FR: SidebarLabels = {
components: 'Composants',
variables: 'Variables',
checkingDesigns: 'Vérifier les designs',
+ cloudStorage: 'Stockage cloud',
icons: 'Icônes',
overview: 'Vue d’ensemble',
gettingStarted: 'Premiers pas',
@@ -276,6 +281,7 @@ export const ES: SidebarLabels = {
components: 'Componentes',
variables: 'Variables',
checkingDesigns: 'Revisar diseños',
+ cloudStorage: 'Almacenamiento en la nube',
icons: 'Iconos',
overview: 'Resumen',
gettingStarted: 'Primeros pasos',
@@ -303,6 +309,7 @@ export const PL: SidebarLabels = {
components: 'Komponenty',
variables: 'Zmienne',
checkingDesigns: 'Sprawdzanie projektów',
+ cloudStorage: 'Przechowywanie w chmurze',
icons: 'Ikony',
overview: 'Przegląd',
gettingStarted: 'Rozpoczęcie pracy',
@@ -330,6 +337,7 @@ export const RU: SidebarLabels = {
components: 'Компоненты',
variables: 'Переменные',
checkingDesigns: 'Проверка дизайна',
+ cloudStorage: 'Облачное хранилище',
icons: 'Иконки',
overview: 'Обзор',
gettingStarted: 'Начало работы',
diff --git a/packages/docs/.vitepress/sidebars.ts b/packages/docs/.vitepress/sidebars.ts
index f9bd4ff10..649fec5ab 100644
--- a/packages/docs/.vitepress/sidebars.ts
+++ b/packages/docs/.vitepress/sidebars.ts
@@ -40,6 +40,8 @@ export const userGuideSidebar = (
items: [
{ text: labels.layers, link: `${prefix}/user-guide/layers-and-pages` },
{ text: labels.exporting, link: `${prefix}/user-guide/exporting` },
+ // English only until translated; locales link to the canonical page.
+ { text: labels.cloudStorage, link: '/user-guide/cloud-storage' },
],
},
{
diff --git a/packages/docs/user-guide/cloud-storage.md b/packages/docs/user-guide/cloud-storage.md
new file mode 100644
index 000000000..ac31f5265
--- /dev/null
+++ b/packages/docs/user-guide/cloud-storage.md
@@ -0,0 +1,82 @@
+---
+title: Cloud Storage
+description: Keep documents and component libraries in your own S3-compatible bucket — AWS S3, Backblaze B2, Cloudflare R2, MinIO, and others.
+---
+
+# Cloud Storage
+
+OpenPencil can keep documents in a bucket you own on any S3-compatible service: AWS S3, Backblaze B2, Cloudflare R2, MinIO, and others. There is no OpenPencil server in between; the editor talks to your bucket directly with your own access keys.
+
+## Connect a Bucket
+
+Open **Settings → Cloud storage**, select **S3 storage**, and fill in:
+
+| Field | What to enter |
+| --------------------- | --------------------------------------------------------------------------------- |
+| **Endpoint** | The provider's S3 API URL, including any required path. See the examples below. |
+| **Bucket** | The bucket name. |
+| **Region** | Optional. Left empty, it is read from the endpoint, or `us-east-1` when it can't be. |
+| **Access key ID** | An access key with read, write, list, and delete access to the bucket. |
+| **Secret access key** | The key's secret. |
+
+Endpoint examples:
+
+- AWS S3: `https://s3.eu-west-1.amazonaws.com`
+- Backblaze B2: `https://s3.eu-central-003.backblazeb2.com`
+- Cloudflare R2: `https://<account-id>.r2.cloudflarestorage.com`
+- MinIO: `http://localhost:9000`, or wherever your server listens
+
+Select **Test connection** to check the endpoint, keys, and bucket before saving, then **Save**. OpenPencil addresses objects as `{endpoint}/{bucket}/{key}`, so the bucket name never goes into the endpoint.
+
+Access keys are kept in the system credential store in the desktop app. In the browser they are encrypted in browser storage, or kept only until you close the session when **Settings → General → Remember API keys on this device** is off.
+
+## Allow the Web App in CORS
+
+The browser can only reach a bucket that allows requests from the page's origin, so the web app needs a CORS rule on the bucket. The desktop app sends its requests natively and needs none.
+
+Add a rule like this one, with the origins you open OpenPencil from:
+
+```json
+[
+ {
+ "AllowedHeaders": ["*"],
+ "AllowedMethods": ["GET", "PUT", "POST", "DELETE", "HEAD"],
+ "AllowedOrigins": ["https://app.openpencil.dev"],
+ "ExposeHeaders": ["ETag", "Content-Range", "x-amz-request-id", "x-amz-id-2", "x-amz-version-id"],
+ "MaxAgeSeconds": 3600
+ }
+]
+```
+
+Set it in the AWS console under the bucket's **Permissions → Cross-origin resource sharing**, in the Cloudflare dashboard under the R2 bucket's **Settings → CORS policy**, or with your provider's CLI. When the rule is missing, **Test connection** says the browser could not reach the bucket from the current site.
+
+## Save a Document to Storage
+
+Open or create a document, then choose **File → Save to storage…**. The document is saved into the bucket and the tab stays bound to it: **Save** and auto-save now write to storage instead of a local file. A local `.fig` you had open keeps its last saved contents.
+
+To open stored documents, choose **File → Open storage workspace…**. The workspace lists every document in the bucket with a preview read from the document itself, so listing a large file downloads only its embedded thumbnail.
+
+## How Saving Works
+
+Saving writes the document on this device first and uploads it in the background, so editing never waits for the network. If an upload fails or you are offline, it is retried with increasing delays, and pending work resumes when you reconnect or change storage settings.
+
+Each document is uploaded whole. When two devices save the same document, the last upload wins.
+
+Documents you have opened stay cached on the device for faster reopening, up to 500 MB. Only copies that are fully uploaded are removed when the cache is full, and they are downloaded again the next time you open them.
+
+## Component Libraries
+
+The bucket can also hold component libraries. In **Assets → Manage libraries**, switch the source to **Storage** to publish and enable libraries there instead of on this device. Publishing uses conditional writes, so two people publishing the same library at once can't overwrite each other's revision. See [Components](./components#component-libraries) for publishing and updating libraries.
+
+## What's in the Bucket
+
+OpenPencil writes only under two prefixes and leaves everything else in the bucket alone:
+
+- `open_pencil_storage/canvases/` — each document as `<id>.fig`, with its name and modification time in `<id>.meta.json`.
+- `open-pencil/libraries/` — each library's `manifest.json` and its published revisions.
+
+## Provider Notes
+
+- **Cloudflare R2** needs the exact web app origin in its CORS rule; it does not accept wildcard origins such as `https://*.example.com`.
+- **MinIO** answers CORS requests from any origin unless you configure otherwise.
+- **`rclone serve s3`** works with two limits. It rejects CORS preflight requests, so the web app needs a reverse proxy in front of it that answers them; the desktop app does not. It also ignores conditional writes, so concurrent library publishes are not detected.
diff --git a/packages/docs/user-guide/index.md b/packages/docs/user-guide/index.md
index 5cda1bde5..845888808 100644
--- a/packages/docs/user-guide/index.md
+++ b/packages/docs/user-guide/index.md
@@ -29,6 +29,7 @@ Throughout this guide, keyboard shortcuts use Mac notation: <kbd>⌘</kbd> = <kb
- [Layers & Pages](./layers-and-pages) — the layers panel, pages, and properties panel
- [Context Menu](./context-menu) — right-click actions for clipboard, grouping, components, and more
- [Exporting](./exporting) — image export and .fig file operations
+- [Cloud Storage](./cloud-storage) — documents and libraries in your own S3-compatible bucket
## Advanced Features
diff --git a/packages/vue/src/i18n/locales/de/menu.json b/packages/vue/src/i18n/locales/de/menu.json
index b6eea4dfd..4bb44e08c 100644
--- a/packages/vue/src/i18n/locales/de/menu.json
+++ b/packages/vue/src/i18n/locales/de/menu.json
@@ -10,6 +10,7 @@
"openStorageWorkspace": "Speicher-Arbeitsbereich öffnen…",
"save": "Speichern",
"saveAs": "Speichern unter…",
+ "saveToStorage": "Im Speicher-Arbeitsbereich speichern…",
"exportSelection": "Auswahl exportieren…",
"autosave": "Automatisch in Datei speichern",
"copy": "Kopieren",
diff --git a/packages/vue/src/i18n/locales/es/menu.json b/packages/vue/src/i18n/locales/es/menu.json
index 0ed12e9ae..2402b5984 100644
--- a/packages/vue/src/i18n/locales/es/menu.json
+++ b/packages/vue/src/i18n/locales/es/menu.json
@@ -10,6 +10,7 @@
"openStorageWorkspace": "Abrir espacio de almacenamiento…",
"save": "Guardar",
"saveAs": "Guardar como…",
+ "saveToStorage": "Guardar en el espacio de almacenamiento…",
"exportSelection": "Exportar selección…",
"autosave": "Guardado automático en archivo",
"copy": "Copiar",
diff --git a/packages/vue/src/i18n/locales/fr/menu.json b/packages/vue/src/i18n/locales/fr/menu.json
index e065870ba..6c63aedb1 100644
--- a/packages/vue/src/i18n/locales/fr/menu.json
+++ b/packages/vue/src/i18n/locales/fr/menu.json
@@ -10,6 +10,7 @@
"openStorageWorkspace": "Ouvrir l’espace de stockage…",
"save": "Enregistrer",
"saveAs": "Enregistrer sous…",
+ "saveToStorage": "Enregistrer dans l’espace de stockage…",
"exportSelection": "Exporter la sélection…",
"autosave": "Enregistrement automatique",
"copy": "Copier",
diff --git a/packages/vue/src/i18n/locales/it/menu.json b/packages/vue/src/i18n/locales/it/menu.json
index dcdcd8c9c..8aae7660e 100644
--- a/packages/vue/src/i18n/locales/it/menu.json
+++ b/packages/vue/src/i18n/locales/it/menu.json
@@ -10,6 +10,7 @@
"openStorageWorkspace": "Apri area di archiviazione…",
"save": "Salva",
"saveAs": "Salva con nome…",
+ "saveToStorage": "Salva nell’area di archiviazione…",
"exportSelection": "Esporta selezione…",
"autosave": "Salvataggio automatico su file",
"copy": "Copia",
diff --git a/packages/vue/src/i18n/locales/ja/menu.json b/packages/vue/src/i18n/locales/ja/menu.json
index 7d1077670..41480837f 100644
--- a/packages/vue/src/i18n/locales/ja/menu.json
+++ b/packages/vue/src/i18n/locales/ja/menu.json
@@ -10,6 +10,7 @@
"openStorageWorkspace": "ストレージワークスペースを開く…",
"save": "保存",
"saveAs": "名前を付けて保存…",
+ "saveToStorage": "ストレージに保存…",
"exportSelection": "選択範囲をエクスポート…",
"autosave": "ファイルに自動保存",
"copy": "コピー",
diff --git a/packages/vue/src/i18n/locales/pl/menu.json b/packages/vue/src/i18n/locales/pl/menu.json
index 6a82f5712..3b63a2504 100644
--- a/packages/vue/src/i18n/locales/pl/menu.json
+++ b/packages/vue/src/i18n/locales/pl/menu.json
@@ -10,6 +10,7 @@
"openStorageWorkspace": "Otwórz obszar przechowywania…",
"save": "Zapisz",
"saveAs": "Zapisz jako…",
+ "saveToStorage": "Zapisz w obszarze przechowywania…",
"exportSelection": "Eksportuj zaznaczenie…",
"autosave": "Automatyczny zapis do pliku",
"copy": "Kopiuj",
diff --git a/packages/vue/src/i18n/locales/ru/menu.json b/packages/vue/src/i18n/locales/ru/menu.json
index 8f2b340de..29a7bb6d7 100644
--- a/packages/vue/src/i18n/locales/ru/menu.json
+++ b/packages/vue/src/i18n/locales/ru/menu.json
@@ -10,6 +10,7 @@
"openStorageWorkspace": "Открыть рабочее пространство хранилища…",
"save": "Сохранить",
"saveAs": "Сохранить как…",
+ "saveToStorage": "Сохранить в хранилище…",
"exportSelection": "Экспорт выделения…",
"autosave": "Автосохранение в файл",
"copy": "Копировать",
diff --git a/packages/vue/src/i18n/locales/zh-cn/menu.json b/packages/vue/src/i18n/locales/zh-cn/menu.json
index 8f23cc1eb..8cce8d5f3 100644
--- a/packages/vue/src/i18n/locales/zh-cn/menu.json
+++ b/packages/vue/src/i18n/locales/zh-cn/menu.json
@@ -10,6 +10,7 @@
"openStorageWorkspace": "打开存储工作区…",
"save": "保存",
"saveAs": "另存为…",
+ "saveToStorage": "保存到存储工作区…",
"exportSelection": "导出所选内容…",
"autosave": "自动保存到本地文件",
"copy": "复制",
diff --git a/packages/vue/src/i18n/messages/menu.ts b/packages/vue/src/i18n/messages/menu.ts
index 50db24fdd..0e9cd48fb 100644
--- a/packages/vue/src/i18n/messages/menu.ts
+++ b/packages/vue/src/i18n/messages/menu.ts
@@ -13,6 +13,7 @@ export const menuMessageDefaults = {
openStorageWorkspace: 'Open storage workspace…',
save: 'Save',
saveAs: 'Save as…',
+ saveToStorage: 'Save to storage…',
exportSelection: 'Export selection…',
exportSelectionAsPNG: 'Export selection as PNG',
exportSelectionAsSVG: 'Export selection as SVG',
diff --git a/src/app/document/io/create.ts b/src/app/document/io/create.ts
index a1e863d45..20a4b72e3 100644
--- a/src/app/document/io/create.ts
+++ b/src/app/document/io/create.ts
@@ -87,6 +87,7 @@ export function createDocumentIOActions(
setStorageDocumentSource: sourceActions.setStorageDocumentSource,
setPlannedFilePath: sourceActions.setPlannedFilePath,
saveFigFileToPath: sourceActions.saveFigFileToPath,
+ saveFigFileToStorage: sourceActions.saveFigFileToStorage,
startWatchingCurrentFile: sourceActions.startWatchingCurrentFile,
disposeDocumentIO: sourceActions.disposeDocumentIO,
openFigFile,
diff --git a/src/app/document/io/source.ts b/src/app/document/io/source.ts
index 508a61b0f..e799a7ddf 100644
--- a/src/app/document/io/source.ts
+++ b/src/app/document/io/source.ts
@@ -13,7 +13,8 @@ import { createDocumentSourceState } from '@/app/document/io/source-state'
import type { DocumentSourceAccess } from '@/app/document/io/types'
import { createDocumentRecovery } from '@/app/document/recovery'
import { recoveryEnabled } from '@/app/document/recovery/preferences'
-import type { StorageDocumentBinding } from '@/app/integrations/storage/types'
+import type { StorageDocumentBinding, StorageProviderID } from '@/app/integrations/storage/types'
+import { createCanvasId } from '@/app/storage/id'
type DocumentSourceState = EditorState & {
documentName: string
@@ -157,8 +158,15 @@ export function createDocumentSourceActions({
state.documentName = documentNameFromFigPath(downloadName)
}
- /** Save to a new path; when the write fails, the document keeps the source it had. */
- async function saveFigFileToPath(path: string): Promise<boolean> {
+ let retargeting = false
+
+ /**
+ * Save to a new target; when the write fails, the document keeps the source it had. A second
+ * retarget while one is in flight is refused, so a failure never restores another save's target.
+ */
+ async function saveToNewTarget(planTarget: () => void): Promise<boolean> {
+ if (retargeting) return false
+ retargeting = true
const previous = {
filePath: getFilePath(),
fileHandle: getFileHandle(),
@@ -174,16 +182,39 @@ export function createDocumentSourceActions({
state.documentName = previous.documentName
if (previous.filePath || previous.fileHandle) void startWatchingFile()
}
- setPlannedFilePath(path)
+ planTarget()
try {
const saved = await saveAndTrack(saveFigFile)
- if (saved) void startWatchingFile()
- else restore()
+ if (!saved) restore()
return saved
} catch (error) {
restore()
throw error
+ } finally {
+ retargeting = false
+ }
+ }
+
+ async function saveFigFileToPath(path: string): Promise<boolean> {
+ const saved = await saveToNewTarget(() => setPlannedFilePath(path))
+ if (saved) void startWatchingFile()
+ return saved
+ }
+
+ /** Upload the document to storage as a new stored document and keep editing it there. */
+ async function saveFigFileToStorage(providerId: StorageProviderID): Promise<boolean> {
+ const saved = await saveToNewTarget(() => {
+ stopWatchingFile()
+ setFileHandle(null)
+ setFilePath(null)
+ setDownloadName(`${state.documentName}.fig`)
+ setStorageBinding({ providerId, documentId: createCanvasId() })
+ })
+ if (saved) {
+ setSourceIdentity({ handle: null, path: null })
+ state.autosaveEnabled = true
}
+ return saved
}
function startWatchingCurrentFile() {
@@ -202,6 +233,7 @@ export function createDocumentSourceActions({
setStorageDocumentSource,
setPlannedFilePath,
saveFigFileToPath,
+ saveFigFileToStorage,
startWatchingCurrentFile,
disposeDocumentIO,
saveFigFile: () => saveAndTrack(saveFigFile),
diff --git a/src/app/editor/session/modules.ts b/src/app/editor/session/modules.ts
index 3c318ed1c..ec532c50e 100644
--- a/src/app/editor/session/modules.ts
+++ b/src/app/editor/session/modules.ts
@@ -94,6 +94,7 @@ export function createEditorStoreModules(
setStorageDocumentSource: documentIO.setStorageDocumentSource,
setPlannedFilePath: documentIO.setPlannedFilePath,
saveFigFileToPath: documentIO.saveFigFileToPath,
+ saveFigFileToStorage: documentIO.saveFigFileToStorage,
startWatchingCurrentFile: documentIO.startWatchingCurrentFile,
designCheck,
dispose: () => {
diff --git a/src/app/integrations/storage/index.ts b/src/app/integrations/storage/index.ts
index 681e475f6..0e9ee64e4 100644
--- a/src/app/integrations/storage/index.ts
+++ b/src/app/integrations/storage/index.ts
@@ -12,6 +12,7 @@ export type { S3StorageAdapter } from './s3/adapter'
export type { S3CompatibleConfig, S3ConnectionResult } from './s3/types'
export {
createActiveStorageAdapter,
+ isStorageConfigured,
storageCredentialRefs,
storageCredentialStatuses
} from './runtime'
diff --git a/src/app/integrations/storage/runtime.ts b/src/app/integrations/storage/runtime.ts
index 0d24ba200..9a5fc2455 100644
--- a/src/app/integrations/storage/runtime.ts
+++ b/src/app/integrations/storage/runtime.ts
@@ -2,7 +2,11 @@ import { appCredentialServices } from '@/app/settings/credentials/app'
import { credentialRef } from '@/app/settings/credentials/reference'
import type { CredentialRef, CredentialStatus } from '@/app/settings/credentials/types'
-import { activeStorageProviderID, readStoragePreferences } from './preferences'
+import {
+ activeStorageProviderID,
+ readStoragePreferences,
+ storagePreferencesComplete
+} from './preferences'
import { storageProviderRegistry } from './providers'
import type { StorageAdapter, StorageProviderID } from './types'
@@ -31,6 +35,15 @@ export async function storageCredentialStatuses(
return Object.fromEntries(entries)
}
+/** Required preferences are filled in and every required credential is saved. */
+export async function isStorageConfigured(providerID: StorageProviderID): Promise<boolean> {
+ if (!storagePreferencesComplete(providerID)) return false
+ const statuses = await storageCredentialStatuses(providerID)
+ return storageProviderRegistry
+ .get(providerID)
+ .credentialFields.every((field) => !field.required || statuses[field.id] === 'configured')
+}
+
export function createActiveStorageAdapter(
providerID: StorageProviderID = activeStorageProviderID.value,
profileID = 'default'
diff --git a/src/app/integrations/storage/s3/cors.ts b/src/app/integrations/storage/s3/cors.ts
index 38f21f982..dd0ed347c 100644
--- a/src/app/integrations/storage/s3/cors.ts
+++ b/src/app/integrations/storage/s3/cors.ts
@@ -52,6 +52,7 @@ ${originTags}
<AllowedMethod>HEAD</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
<ExposeHeader>ETag</ExposeHeader>
+ <ExposeHeader>Content-Range</ExposeHeader>
<ExposeHeader>x-amz-request-id</ExposeHeader>
<ExposeHeader>x-amz-id-2</ExposeHeader>
<ExposeHeader>x-amz-version-id</ExposeHeader>
@@ -69,7 +70,14 @@ export function buildCORSConfigurationJSON(origins: string[]): string {
AllowedHeaders: ['*'],
AllowedMethods: ['GET', 'PUT', 'POST', 'DELETE', 'HEAD'],
AllowedOrigins: origins,
- ExposeHeaders: ['ETag', 'x-amz-request-id', 'x-amz-id-2', 'x-amz-version-id'],
+ // Content-Range lets a 200 reply to a range read be checked against the request.
+ ExposeHeaders: [
+ 'ETag',
+ 'Content-Range',
+ 'x-amz-request-id',
+ 'x-amz-id-2',
+ 'x-amz-version-id'
+ ],
MaxAgeSeconds: 3600
}
],
diff --git a/src/app/shell/menu/app-menu.ts b/src/app/shell/menu/app-menu.ts
index 8b7fd40b2..1a71a8306 100644
--- a/src/app/shell/menu/app-menu.ts
+++ b/src/app/shell/menu/app-menu.ts
@@ -38,6 +38,7 @@ import { createSelectionMenuActions } from '@/app/shell/menu/selection-actions'
import { appMenuShortcutLabel } from '@/app/shell/menu/shortcut'
import { openFileDialog } from '@/app/shell/menu/use'
import { useAppTheme } from '@/app/shell/theme'
+import { saveDocumentToStorage } from '@/app/storage/workspace/save'
import { closeTab, activeTab } from '@/app/tabs'
export interface AppMenuGroup {
@@ -100,6 +101,7 @@ export function useAppMenu() {
'open-storage-workspace': 'openStorageWorkspace',
save: 'save',
'save-as': 'saveAs',
+ 'save-to-storage': 'saveToStorage',
'export-selection': 'exportSelection',
autosave: 'autosave',
close: 'closeTab',
@@ -164,6 +166,7 @@ export function useAppMenu() {
'open-storage-workspace': () => openStorageWorkspace(router),
save: () => void store.saveFigFile(),
'save-as': () => void store.saveFigFileAs(),
+ 'save-to-storage': () => void saveDocumentToStorage(store),
'export-selection': () => exportSelection('png'),
...createSelectionMenuActions(store),
close: () => {
diff --git a/src/app/shell/menu/editor.ts b/src/app/shell/menu/editor.ts
index 84ed8bb62..6890b2ca3 100644
--- a/src/app/shell/menu/editor.ts
+++ b/src/app/shell/menu/editor.ts
@@ -11,6 +11,7 @@ import { APP_MENU_SCHEMA, type AppMenuEntry } from '@/app/shell/menu/schema'
import { createSelectionMenuActions } from '@/app/shell/menu/selection-actions'
import { SHELL_MENU_IDS } from '@/app/shell/menu/shell'
import { useAppTheme } from '@/app/shell/theme'
+import { saveDocumentToStorage } from '@/app/storage/workspace/save'
import { createTab, closeTab, activeTab } from '@/app/tabs'
import { isTauri } from '@/app/tauri/env'
@@ -42,6 +43,7 @@ export function useEditorMenu() {
},
save: () => void store.saveFigFile(),
'save-as': () => void store.saveFigFileAs(),
+ 'save-to-storage': () => void saveDocumentToStorage(store),
'export-selection': () => {
if (store.state.selectedIds.size > 0) void store.exportSelection(1, 'png')
},
diff --git a/src/app/shell/menu/schema.ts b/src/app/shell/menu/schema.ts
index c3b80417e..8b522f7d0 100644
--- a/src/app/shell/menu/schema.ts
+++ b/src/app/shell/menu/schema.ts
@@ -73,6 +73,7 @@ export const APP_MENU_SCHEMA = [
{ type: 'separator' },
{ id: 'save', label: 'Save', shortcut: 'MOD+S' },
{ id: 'save-as', label: 'Save As…', shortcut: 'MOD+SHIFT+S' },
+ { id: 'save-to-storage', label: 'Save to Storage…' },
{ type: 'separator' },
{
id: 'export-selection',
diff --git a/src/app/storage/workspace/save.ts b/src/app/storage/workspace/save.ts
new file mode 100644
index 000000000..e799ab451
--- /dev/null
+++ b/src/app/storage/workspace/save.ts
@@ -0,0 +1,25 @@
+import { activeStorageProviderID, isStorageConfigured } from '@/app/integrations/storage'
+import type { StorageDocumentBinding, StorageProviderID } from '@/app/integrations/storage/types'
+import { rememberRecentStorageDocument } from '@/app/recent-files'
+import { openSettingsDialog } from '@/app/settings/dialog'
+
+type StorageSaveTarget = {
+ state: { documentName: string }
+ saveFigFileToStorage: (providerId: StorageProviderID) => Promise<boolean>
+ getStorageBinding: () => StorageDocumentBinding | null
+}
+
+/** Save the open document as a new stored document, or ask for storage settings first. */
+export async function saveDocumentToStorage(store: StorageSaveTarget): Promise<boolean> {
+ const providerId = activeStorageProviderID.value
+ if (!(await isStorageConfigured(providerId))) {
+ openSettingsDialog('storage')
+ return false
+ }
+ const saved = await store.saveFigFileToStorage(providerId)
+ const binding = store.getStorageBinding()
+ if (saved && binding) {
+ rememberRecentStorageDocument(providerId, binding.documentId, store.state.documentName)
+ }
+ return saved
+}
diff --git a/src/app/storage/workspace/source.ts b/src/app/storage/workspace/source.ts
index ab43cc272..b1c79db54 100644
--- a/src/app/storage/workspace/source.ts
+++ b/src/app/storage/workspace/source.ts
@@ -2,9 +2,7 @@ import type { StorageDocument } from '@/app/integrations/storage'
import {
activeStorageProviderID,
createActiveStorageAdapter,
- storageCredentialStatuses,
- storagePreferencesComplete,
- storageProviderRegistry
+ isStorageConfigured
} from '@/app/integrations/storage'
import { getLocalCanvasStore } from '@/app/storage/local-store'
import { reconcileStorageDocuments } from '@/app/storage/reconcile'
@@ -27,13 +25,7 @@ export function createStorageWorkspaceSource(
async refresh(): Promise<StorageDocument[] | null> {
const providerID = activeStorageProviderID.value
- const provider = storageProviderRegistry.get(providerID)
- const statuses = await storageCredentialStatuses(providerID)
- const configured =
- storagePreferencesComplete(providerID) &&
- provider.credentialFields.every(
- (field) => !field.required || statuses[field.id] === 'configured'
- )
+ const configured = await isStorageConfigured(providerID)
const localStore = getLocalCanvasStore()
const local = (await localStore.listMetas(true)).filter(
(metadata) => metadata.providerId === providerID
diff --git a/src/components/shell/AppMenu.vue b/src/components/shell/AppMenu.vue
index 3f0670a82..9f38a69b1 100644
--- a/src/components/shell/AppMenu.vue
+++ b/src/components/shell/AppMenu.vue
@@ -1,5 +1,5 @@
<script setup lang="ts">
-import { templateRef } from '@vueuse/core'
+import { templateRef, useResizeObserver, useScroll } from '@vueuse/core'
import {
MenubarCheckboxItem,
MenubarContent,
@@ -14,7 +14,7 @@ import {
MenubarSubTrigger,
MenubarTrigger
} from 'reka-ui'
-import { watch } from 'vue'
+import { computed, useTemplateRef, watch } from 'vue'
import IconChevronRight from '~icons/lucide/chevron-right'
import { vTestId, useI18n } from '@open-pencil/vue'
@@ -36,6 +36,7 @@ import {
updateMenuChecked
} from '@/app/shell/menu/entry'
import { appMenuShortcutLabel } from '@/app/shell/menu/shortcut'
+import { animationsEnabled } from '@/app/shell/motion'
import { resolvedAppTheme } from '@/app/shell/theme'
import BrandMark from '@/components/brand/BrandMark.vue'
import IconButton from '@/components/ui/button/IconButton.vue'
@@ -58,6 +59,27 @@ const { topMenus } = useAppMenu()
const menuCls = useMenuUI()
const mainMenuCls = useMenuUI({ content: 'min-w-52' })
const subMenuCls = useMenuUI({ content: 'min-w-44' })
+
+// A narrow panel clips the menubar; fade the clipped side and offer a chevron so it reads as scrollable.
+const menubar = useTemplateRef<HTMLElement>('menubar')
+const { arrivedState, measure } = useScroll(menubar)
+// Labels change width with the language, so watch the menus as well as the space they get.
+useResizeObserver(menubar, measure)
+useResizeObserver(() => {
+ const content = menubar.value?.firstElementChild
+ return content instanceof HTMLElement ? content : null
+}, measure)
+const overflowStart = computed(() => !arrivedState.left)
+const overflowEnd = computed(() => !arrivedState.right)
+
+function scrollMenubar() {
+ const element = menubar.value
+ if (!element) return
+ element.scrollBy({
+ left: overflowEnd.value ? element.clientWidth : -element.scrollWidth,
+ behavior: animationsEnabled.value ? 'smooth' : 'auto'
+ })
+}
</script>
<template>
@@ -101,81 +123,106 @@ const subMenuCls = useMenuUI({ content: 'min-w-44' })
</IconButton>
</div>
<div v-if="!IS_TAURI" class="flex items-center px-1 pb-1">
- <MenubarRoot class="scrollbar-none flex items-center gap-0.5 overflow-x-auto">
- <MenubarMenu v-for="menu in topMenus" :key="menu.label">
- <MenubarTrigger
- v-test-id="`menubar-${menu.label.toLowerCase()}`"
- class="flex cursor-pointer items-center rounded px-2 py-1 text-[11px] text-surface/80 transition-colors select-none hover:bg-hover hover:text-surface data-[state=open]:bg-hover data-[state=open]:text-surface"
- >
- {{ menu.label }}
- </MenubarTrigger>
+ <div
+ ref="menubar"
+ class="scrollbar-none min-w-0 flex-1 overflow-x-auto data-overflow-end:mask-r-from-[calc(100%-2rem)] data-overflow-start:mask-l-from-[calc(100%-2rem)]"
+ :data-overflow-start="overflowStart || undefined"
+ :data-overflow-end="overflowEnd || undefined"
+ >
+ <MenubarRoot class="flex w-max items-center gap-0.5">
+ <MenubarMenu v-for="menu in topMenus" :key="menu.label">
+ <MenubarTrigger
+ v-test-id="`menubar-${menu.label.toLowerCase()}`"
+ class="flex cursor-pointer items-center rounded px-2 py-1 text-[11px] text-surface/80 transition-colors select-none hover:bg-hover hover:text-surface data-[state=open]:bg-hover data-[state=open]:text-surface"
+ >
+ {{ menu.label }}
+ </MenubarTrigger>
- <MenubarPortal>
- <MenubarContent :side-offset="4" align="start" :class="mainMenuCls.content">
- <template v-for="(item, i) in menu.items" :key="i">
- <MenubarSeparator v-if="isMenuSeparator(item)" :class="menuCls.separator" />
- <MenubarSub v-else-if="hasMenuSubItems(item)">
- <MenubarSubTrigger :class="menuCls.item" :disabled="menuDisabled(item)">
+ <MenubarPortal>
+ <MenubarContent :side-offset="4" align="start" :class="mainMenuCls.content">
+ <template v-for="(item, i) in menu.items" :key="i">
+ <MenubarSeparator v-if="isMenuSeparator(item)" :class="menuCls.separator" />
+ <MenubarSub v-else-if="hasMenuSubItems(item)">
+ <MenubarSubTrigger :class="menuCls.item" :disabled="menuDisabled(item)">
+ <span class="flex-1">{{ menuLabel(item) }}</span>
+ <IconChevronRight class="size-3 text-muted" />
+ </MenubarSubTrigger>
+ <MenubarPortal>
+ <MenubarSubContent :side-offset="4" :class="subMenuCls.content">
+ <template v-for="(sub, j) in menuSubItems(item)" :key="j">
+ <MenubarSeparator
+ v-if="isMenuSeparator(sub)"
+ :class="menuCls.separator"
+ />
+ <MenubarCheckboxItem
+ v-else-if="isMenuCheckbox(sub)"
+ :model-value="menuChecked(sub)"
+ :class="menuCls.item"
+ @update:model-value="updateMenuChecked(sub, $event as boolean)"
+ >
+ <span class="flex-1">{{ menuLabel(sub) }}</span>
+ <MenubarItemIndicator class="text-surface">
+ <icon-lucide-check class="size-3.5" />
+ </MenubarItemIndicator>
+ </MenubarCheckboxItem>
+ <MenubarItem
+ v-else
+ :class="menuCls.item"
+ :disabled="menuDisabled(sub)"
+ @select="runMenuAction(sub)"
+ >
+ <span class="flex-1">{{ menuLabel(sub) }}</span>
+ <AppShortcutText v-if="menuShortcut(sub)">{{
+ menuShortcut(sub)
+ }}</AppShortcutText>
+ </MenubarItem>
+ </template>
+ </MenubarSubContent>
+ </MenubarPortal>
+ </MenubarSub>
+ <MenubarCheckboxItem
+ v-else-if="isMenuCheckbox(item)"
+ :model-value="menuChecked(item)"
+ :class="menuCls.item"
+ @update:model-value="updateMenuChecked(item, $event as boolean)"
+ >
<span class="flex-1">{{ menuLabel(item) }}</span>
- <IconChevronRight class="size-3 text-muted" />
- </MenubarSubTrigger>
- <MenubarPortal>
- <MenubarSubContent :side-offset="4" :class="subMenuCls.content">
- <template v-for="(sub, j) in menuSubItems(item)" :key="j">
- <MenubarSeparator v-if="isMenuSeparator(sub)" :class="menuCls.separator" />
- <MenubarCheckboxItem
- v-else-if="isMenuCheckbox(sub)"
- :model-value="menuChecked(sub)"
- :class="menuCls.item"
- @update:model-value="updateMenuChecked(sub, $event as boolean)"
- >
- <span class="flex-1">{{ menuLabel(sub) }}</span>
- <MenubarItemIndicator class="text-surface">
- <icon-lucide-check class="size-3.5" />
- </MenubarItemIndicator>
- </MenubarCheckboxItem>
- <MenubarItem
- v-else
- :class="menuCls.item"
- :disabled="menuDisabled(sub)"
- @select="runMenuAction(sub)"
- >
- <span class="flex-1">{{ menuLabel(sub) }}</span>
- <AppShortcutText v-if="menuShortcut(sub)">{{
- menuShortcut(sub)
- }}</AppShortcutText>
- </MenubarItem>
- </template>
- </MenubarSubContent>
- </MenubarPortal>
- </MenubarSub>
- <MenubarCheckboxItem
- v-else-if="isMenuCheckbox(item)"
- :model-value="menuChecked(item)"
- :class="menuCls.item"
- @update:model-value="updateMenuChecked(item, $event as boolean)"
- >
- <span class="flex-1">{{ menuLabel(item) }}</span>
- <MenubarItemIndicator class="text-surface">
- <icon-lucide-check class="size-3.5" />
- </MenubarItemIndicator>
- </MenubarCheckboxItem>
- <MenubarItem
- v-else
- :class="menuCls.item"
- :disabled="menuDisabled(item)"
- @select="runMenuAction(item)"
- >
- <span class="flex-1">{{ menuLabel(item) }}</span>
- <AppShortcutText v-if="menuShortcut(item)">{{
- menuShortcut(item)
- }}</AppShortcutText>
- </MenubarItem>
- </template>
- </MenubarContent>
- </MenubarPortal>
- </MenubarMenu>
- </MenubarRoot>
+ <MenubarItemIndicator class="text-surface">
+ <icon-lucide-check class="size-3.5" />
+ </MenubarItemIndicator>
+ </MenubarCheckboxItem>
+ <MenubarItem
+ v-else
+ :class="menuCls.item"
+ :disabled="menuDisabled(item)"
+ @select="runMenuAction(item)"
+ >
+ <span class="flex-1">{{ menuLabel(item) }}</span>
+ <AppShortcutText v-if="menuShortcut(item)">{{
+ menuShortcut(item)
+ }}</AppShortcutText>
+ </MenubarItem>
+ </template>
+ </MenubarContent>
+ </MenubarPortal>
+ </MenubarMenu>
+ </MenubarRoot>
+ </div>
+ <!-- Sits beside the hidden menus; it keeps its width when it switches sides, so the bar's overflow never flips back.
+ Pointer affordance only: arrow keys already move through the menus and scroll them into view. -->
+ <button
+ v-if="overflowStart || overflowEnd"
+ type="button"
+ tabindex="-1"
+ aria-hidden="true"
+ data-test-id="app-menubar-scroll"
+ class="flex h-6 w-5 shrink-0 cursor-pointer items-center justify-center rounded text-muted hover:bg-hover hover:text-surface data-start:order-first"
+ :data-start="!overflowEnd || undefined"
+ @click="scrollMenubar"
+ >
+ <icon-lucide-chevron-right v-if="overflowEnd" class="size-3.5" />
+ <icon-lucide-chevron-left v-else class="size-3.5" />
+ </button>
</div>
</div>
</template>
diff --git a/tests/e2e/storage/workspace.spec.ts b/tests/e2e/storage/workspace.spec.ts
index 386464f78..c7854b299 100644
--- a/tests/e2e/storage/workspace.spec.ts
+++ b/tests/e2e/storage/workspace.spec.ts
@@ -3,6 +3,7 @@ import { readFileSync } from 'node:fs'
import { expect, test } from '@playwright/test'
import { CanvasHelper } from '#tests/helpers/canvas'
+import { openAppMenu } from '#tests/helpers/menu'
test('configured storage lists previews through ranges before opening the document', async ({
page
@@ -124,3 +125,77 @@ test('storage workspace directs unconfigured users to Settings', async ({ page }
await page.getByTestId('settings-section-storage').click()
await expect(page.getByTestId('settings-storage-panel')).toBeVisible()
})
+
+test('Save to storage uploads the open document and lists it in the workspace', async ({
+ page
+}) => {
+ const objects = new Map<string, Buffer>()
+ await page.route('https://s3.example.com/**', async (route) => {
+ const request = route.request()
+ const url = new URL(request.url())
+ const key = decodeURIComponent(url.pathname.replace(/^\/designs\/?/, ''))
+ const prefix = url.searchParams.get('prefix')
+ if (url.searchParams.get('list-type') === '2' && prefix !== null) {
+ const contents = [...objects]
+ .filter(([name]) => name.startsWith(prefix))
+ .map(
+ ([name, body]) =>
+ `<Contents><Key>${name}</Key><LastModified>2026-01-02T03:04:05.000Z</LastModified><Size>${body.byteLength}</Size></Contents>`
+ )
+ await route.fulfill({
+ contentType: 'application/xml',
+ body: `<ListBucketResult><IsTruncated>false</IsTruncated>${contents.join('')}</ListBucketResult>`
+ })
+ return
+ }
+ if (request.method() === 'PUT') {
+ objects.set(key, request.postDataBuffer() ?? Buffer.alloc(0))
+ await route.fulfill({ status: 200, headers: { ETag: '"etag"' } })
+ return
+ }
+ const body = objects.get(key)
+ if (!body) {
+ await route.fulfill({ status: 404 })
+ return
+ }
+ await route.fulfill({
+ status: 200,
+ headers: { 'Content-Length': String(body.byteLength) },
+ body: request.method() === 'HEAD' ? undefined : body
+ })
+ })
+
+ await page.goto('/?test')
+ const canvas = new CanvasHelper(page)
+ await canvas.waitForInit()
+
+ // Before storage is configured, the command opens storage settings.
+ let file = await openAppMenu(page, 'File')
+ await file.getByRole('menuitem', { name: 'Save to storage…' }).click()
+ const panel = page.getByTestId('settings-storage-panel')
+ await expect(panel).toBeVisible()
+ await panel.getByRole('button', { name: /S3 storage/ }).click()
+ await panel.getByLabel('Endpoint').fill('https://s3.example.com')
+ await panel.getByLabel('Bucket').fill('designs')
+ await panel.getByLabel('Access key ID').fill('access-key')
+ await panel.getByLabel('Secret access key').fill('secret-key')
+ await page.getByRole('button', { name: 'Save', exact: true }).click()
+ await page.getByTestId('app-settings-done').click()
+
+ file = await openAppMenu(page, 'File')
+ await file.getByRole('menuitem', { name: 'Save to storage…' }).click()
+ await expect
+ .poll(() => [...objects.keys()].filter((key) => key.includes('/canvases/')).sort())
+ .toEqual([
+ expect.stringMatching(/^open_pencil_storage\/canvases\/[^/]+\.fig$/),
+ expect.stringMatching(/^open_pencil_storage\/canvases\/[^/]+\.meta\.json$/)
+ ])
+ const uploaded = [...objects].find(([key]) => key.endsWith('.fig'))?.[1]
+ // An exported .fig is a zip archive holding the document and its thumbnail.
+ expect(uploaded?.subarray(0, 4)).toEqual(Buffer.from([0x50, 0x4b, 0x03, 0x04]))
+
+ file = await openAppMenu(page, 'File')
+ await file.getByRole('menuitem', { name: 'Open storage workspace…' }).click()
+ await expect(page.getByTestId('recent-files-home')).toBeVisible()
+ await expect(page.getByRole('button', { name: /^Untitled/ }).first()).toBeVisible()
+})
diff --git a/tests/engine/app/integrations/storage/cors.test.ts b/tests/engine/app/integrations/storage/cors.test.ts
index 12e78f2b1..12333fe49 100644
--- a/tests/engine/app/integrations/storage/cors.test.ts
+++ b/tests/engine/app/integrations/storage/cors.test.ts
@@ -21,6 +21,7 @@ describe('cloud S3 CORS helpers', () => {
expect(xml).toContain('<AllowedMethod>DELETE</AllowedMethod>')
expect(xml).toContain('<AllowedHeader>*</AllowedHeader>')
expect(xml).toContain('<ExposeHeader>ETag</ExposeHeader>')
+ expect(xml).toContain('<ExposeHeader>Content-Range</ExposeHeader>')
})
test('escapes XML special characters in origins', () => {
@@ -37,7 +38,8 @@ describe('cloud S3 CORS helpers', () => {
v.object({
AllowedOrigins: v.array(v.string()),
AllowedMethods: v.array(v.string()),
- AllowedHeaders: v.array(v.string())
+ AllowedHeaders: v.array(v.string()),
+ ExposeHeaders: v.array(v.string())
})
)
),
@@ -45,6 +47,7 @@ describe('cloud S3 CORS helpers', () => {
)
expect(json).toHaveLength(1)
expect(json[0]?.AllowedOrigins).toContain('https://app.openpencil.dev')
+ expect(json[0]?.ExposeHeaders).toEqual(expect.arrayContaining(['ETag', 'Content-Range']))
expect(json[0]?.AllowedMethods).toEqual(
expect.arrayContaining(['GET', 'PUT', 'POST', 'DELETE', 'HEAD'])
)