mirror of
https://github.com/maputnik/editor.git
synced 2026-06-09 00:37:26 +00:00
change "download" to "save"
This commit is contained in:
@@ -2,7 +2,16 @@ import React from 'react'
|
|||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
import {detect} from 'detect-browser';
|
import {detect} from 'detect-browser';
|
||||||
|
|
||||||
import {MdFileDownload, MdOpenInBrowser, MdSettings, MdLayers, MdHelpOutline, MdFindInPage, MdLanguage} from 'react-icons/md'
|
import {
|
||||||
|
MdFileDownload,
|
||||||
|
MdOpenInBrowser,
|
||||||
|
MdSettings,
|
||||||
|
MdLayers,
|
||||||
|
MdHelpOutline,
|
||||||
|
MdFindInPage,
|
||||||
|
MdLanguage,
|
||||||
|
MdSave
|
||||||
|
} from 'react-icons/md'
|
||||||
import pkgJson from '../../package.json'
|
import pkgJson from '../../package.json'
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
import maputnikLogo from 'maputnik-design/logos/logo-color.svg?inline'
|
import maputnikLogo from 'maputnik-design/logos/logo-color.svg?inline'
|
||||||
@@ -216,8 +225,8 @@ class AppToolbarInternal extends React.Component<AppToolbarInternalProps> {
|
|||||||
<IconText>{t("Open")}</IconText>
|
<IconText>{t("Open")}</IconText>
|
||||||
</ToolbarAction>
|
</ToolbarAction>
|
||||||
<ToolbarAction wdKey="nav:export" onClick={this.props.onToggleModal.bind(this, 'export')}>
|
<ToolbarAction wdKey="nav:export" onClick={this.props.onToggleModal.bind(this, 'export')}>
|
||||||
<MdFileDownload />
|
<MdSave />
|
||||||
<IconText>{t("Export")}</IconText>
|
<IconText>{t("Save")}</IconText>
|
||||||
</ToolbarAction>
|
</ToolbarAction>
|
||||||
<ToolbarAction wdKey="nav:sources" onClick={this.props.onToggleModal.bind(this, 'sources')}>
|
<ToolbarAction wdKey="nav:sources" onClick={this.props.onToggleModal.bind(this, 'sources')}>
|
||||||
<MdLayers />
|
<MdLayers />
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {saveAs} from 'file-saver'
|
|||||||
import {version} from 'maplibre-gl/package.json'
|
import {version} from 'maplibre-gl/package.json'
|
||||||
import {format} from '@maplibre/maplibre-gl-style-spec'
|
import {format} from '@maplibre/maplibre-gl-style-spec'
|
||||||
import type {StyleSpecification} from 'maplibre-gl'
|
import type {StyleSpecification} from 'maplibre-gl'
|
||||||
import {MdFileDownload} from 'react-icons/md'
|
import {MdSave} from 'react-icons/md'
|
||||||
import { WithTranslation, withTranslation } from 'react-i18next';
|
import { WithTranslation, withTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import FieldString from './FieldString'
|
import FieldString from './FieldString'
|
||||||
@@ -81,11 +81,30 @@ class ModalExportInternal extends React.Component<ModalExportInternalProps> {
|
|||||||
saveAs(blob, exportName + ".html");
|
saveAs(blob, exportName + ".html");
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadStyle() {
|
async saveStyle() {
|
||||||
|
const fileHandle = null;
|
||||||
const tokenStyle = this.tokenizedStyle();
|
const tokenStyle = this.tokenizedStyle();
|
||||||
const blob = new Blob([tokenStyle], {type: "application/json;charset=utf-8"});
|
|
||||||
const exportName = this.exportName();
|
if (fileHandle != null) {
|
||||||
saveAs(blob, exportName + ".json");
|
const writable = await fileHandle.createWritable();
|
||||||
|
await writable.write(tokenStyle);
|
||||||
|
writable.flush();
|
||||||
|
await writable.close();
|
||||||
|
} else {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async saveStyleAs() {
|
||||||
|
const fileHandle = null;
|
||||||
|
const tokenStyle = this.tokenizedStyle();
|
||||||
|
|
||||||
|
const root = await navigator.storage.getDirectory();
|
||||||
|
const draftHandle = await root.getFileHandle(this.exportName(), { create: true });
|
||||||
|
const accessHandle = await draftHandle.createSyncAccessHandle();
|
||||||
|
|
||||||
|
accessHandle.write(tokenStyle);
|
||||||
|
accessHandle.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
changeMetadataProperty(property: string, value: any) {
|
changeMetadataProperty(property: string, value: any) {
|
||||||
@@ -107,14 +126,14 @@ class ModalExportInternal extends React.Component<ModalExportInternalProps> {
|
|||||||
data-wd-key="modal:export"
|
data-wd-key="modal:export"
|
||||||
isOpen={this.props.isOpen}
|
isOpen={this.props.isOpen}
|
||||||
onOpenToggle={this.props.onOpenToggle}
|
onOpenToggle={this.props.onOpenToggle}
|
||||||
title={t('Export Style')}
|
title={t('Save Style')}
|
||||||
className="maputnik-export-modal"
|
className="maputnik-export-modal"
|
||||||
>
|
>
|
||||||
|
|
||||||
<section className="maputnik-modal-section">
|
<section className="maputnik-modal-section">
|
||||||
<h1>{t("Download Style")}</h1>
|
<h1>{t("Save Style")}</h1>
|
||||||
<p>
|
<p>
|
||||||
{t("Download a JSON style to your computer.")}
|
{t("Save the JSON style to your computer.")}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
@@ -140,16 +159,22 @@ class ModalExportInternal extends React.Component<ModalExportInternalProps> {
|
|||||||
|
|
||||||
<div className="maputnik-modal-export-buttons">
|
<div className="maputnik-modal-export-buttons">
|
||||||
<InputButton
|
<InputButton
|
||||||
onClick={this.downloadStyle.bind(this)}
|
onClick={this.saveStyle.bind(this)}
|
||||||
>
|
>
|
||||||
<MdFileDownload />
|
<MdSave />
|
||||||
{t("Download Style")}
|
{t("Save Style")}
|
||||||
|
</InputButton>
|
||||||
|
<InputButton
|
||||||
|
onClick={this.saveStyleAs.bind(this)}
|
||||||
|
>
|
||||||
|
<MdSave />
|
||||||
|
{t("Save Style as")}
|
||||||
</InputButton>
|
</InputButton>
|
||||||
|
|
||||||
<InputButton
|
<InputButton
|
||||||
onClick={this.downloadHtml.bind(this)}
|
onClick={this.downloadHtml.bind(this)}
|
||||||
>
|
>
|
||||||
<MdFileDownload />
|
<MdSave />
|
||||||
{t("Download HTML")}
|
{t("Download HTML")}
|
||||||
</InputButton>
|
</InputButton>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user