chore: Move to prettier standard double quotes (#1309)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
// @flow
|
||||
import pkg from 'rich-markdown-editor/package.json';
|
||||
import { map, trim } from 'lodash';
|
||||
import invariant from 'invariant';
|
||||
import stores from 'stores';
|
||||
import download from './download';
|
||||
import pkg from "rich-markdown-editor/package.json";
|
||||
import { map, trim } from "lodash";
|
||||
import invariant from "invariant";
|
||||
import stores from "stores";
|
||||
import download from "./download";
|
||||
import {
|
||||
AuthorizationError,
|
||||
NetworkError,
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
OfflineError,
|
||||
RequestError,
|
||||
UpdateRequiredError,
|
||||
} from './errors';
|
||||
} from "./errors";
|
||||
|
||||
type Options = {
|
||||
baseUrl?: string,
|
||||
@@ -22,8 +22,8 @@ class ApiClient {
|
||||
userAgent: string;
|
||||
|
||||
constructor(options: Options = {}) {
|
||||
this.baseUrl = options.baseUrl || '/api';
|
||||
this.userAgent = 'OutlineFrontend';
|
||||
this.baseUrl = options.baseUrl || "/api";
|
||||
this.userAgent = "OutlineFrontend";
|
||||
}
|
||||
|
||||
fetch = async (
|
||||
@@ -35,27 +35,27 @@ class ApiClient {
|
||||
let body;
|
||||
let modifiedPath;
|
||||
|
||||
if (method === 'GET') {
|
||||
if (method === "GET") {
|
||||
if (data) {
|
||||
modifiedPath = `${path}?${data && this.constructQueryString(data)}`;
|
||||
} else {
|
||||
modifiedPath = path;
|
||||
}
|
||||
} else if (method === 'POST' || method === 'PUT') {
|
||||
} else if (method === "POST" || method === "PUT") {
|
||||
body = data ? JSON.stringify(data) : undefined;
|
||||
}
|
||||
|
||||
// Construct headers
|
||||
const headers = new Headers({
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
'cache-control': 'no-cache',
|
||||
'x-editor-version': pkg.version,
|
||||
pragma: 'no-cache',
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"cache-control": "no-cache",
|
||||
"x-editor-version": pkg.version,
|
||||
pragma: "no-cache",
|
||||
});
|
||||
if (stores.auth.authenticated) {
|
||||
invariant(stores.auth.token, 'JWT token not set properly');
|
||||
headers.set('Authorization', `Bearer ${stores.auth.token}`);
|
||||
invariant(stores.auth.token, "JWT token not set properly");
|
||||
headers.set("Authorization", `Bearer ${stores.auth.token}`);
|
||||
}
|
||||
|
||||
let response;
|
||||
@@ -64,15 +64,15 @@ class ApiClient {
|
||||
method,
|
||||
body,
|
||||
headers,
|
||||
redirect: 'follow',
|
||||
credentials: 'omit',
|
||||
cache: 'no-cache',
|
||||
redirect: "follow",
|
||||
credentials: "omit",
|
||||
cache: "no-cache",
|
||||
});
|
||||
} catch (err) {
|
||||
if (window.navigator.onLine) {
|
||||
throw new NetworkError('A network error occurred, try again?');
|
||||
throw new NetworkError("A network error occurred, try again?");
|
||||
} else {
|
||||
throw new OfflineError('No internet connection available');
|
||||
throw new OfflineError("No internet connection available");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,8 +81,8 @@ class ApiClient {
|
||||
if (options.download && success) {
|
||||
const blob = await response.blob();
|
||||
const fileName = (
|
||||
response.headers.get('content-disposition') || ''
|
||||
).split('filename=')[1];
|
||||
response.headers.get("content-disposition") || ""
|
||||
).split("filename=")[1];
|
||||
|
||||
download(blob, trim(fileName, '"'));
|
||||
return;
|
||||
@@ -103,14 +103,14 @@ class ApiClient {
|
||||
|
||||
try {
|
||||
const parsed = await response.json();
|
||||
error.message = parsed.message || '';
|
||||
error.message = parsed.message || "";
|
||||
error.error = parsed.error;
|
||||
error.data = parsed.data;
|
||||
} catch (_err) {
|
||||
// we're trying to parse an error so JSON may not be valid
|
||||
}
|
||||
|
||||
if (response.status === 400 && error.error === 'editor_update_required') {
|
||||
if (response.status === 400 && error.error === "editor_update_required") {
|
||||
window.location.reload(true);
|
||||
throw new UpdateRequiredError(error.message);
|
||||
}
|
||||
@@ -127,11 +127,11 @@ class ApiClient {
|
||||
};
|
||||
|
||||
get = (path: string, data: ?Object, options?: Object) => {
|
||||
return this.fetch(path, 'GET', data, options);
|
||||
return this.fetch(path, "GET", data, options);
|
||||
};
|
||||
|
||||
post = (path: string, data: ?Object, options?: Object) => {
|
||||
return this.fetch(path, 'POST', data, options);
|
||||
return this.fetch(path, "POST", data, options);
|
||||
};
|
||||
|
||||
// Helpers
|
||||
@@ -139,7 +139,7 @@ class ApiClient {
|
||||
return map(
|
||||
data,
|
||||
(v, k) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`
|
||||
).join('&');
|
||||
).join("&");
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -14,22 +14,22 @@ export default function download(
|
||||
strMimeType?: string
|
||||
) {
|
||||
var self = window, // this script is only for browsers anyway...
|
||||
u = 'application/octet-stream', // this default mime also triggers iframe downloads
|
||||
u = "application/octet-stream", // this default mime also triggers iframe downloads
|
||||
m = strMimeType || u,
|
||||
x = data,
|
||||
D = document,
|
||||
a = D.createElement('a'),
|
||||
a = D.createElement("a"),
|
||||
z = function(a, o) {
|
||||
return String(a);
|
||||
},
|
||||
B = self.Blob || self.MozBlob || self.WebKitBlob || z,
|
||||
BB = self.MSBlobBuilder || self.WebKitBlobBuilder || self.BlobBuilder,
|
||||
fn = strFileName || 'download',
|
||||
fn = strFileName || "download",
|
||||
blob,
|
||||
b,
|
||||
fr;
|
||||
|
||||
if (String(this) === 'true') {
|
||||
if (String(this) === "true") {
|
||||
//reverse arguments, allowing download.bind(true, "text/xml", "export.xml") to act as a callback
|
||||
x = [x, m];
|
||||
m = x[0];
|
||||
@@ -56,12 +56,12 @@ export default function download(
|
||||
}
|
||||
|
||||
function d2b(u) {
|
||||
if (typeof u !== 'string') {
|
||||
throw Error('Attempted to pass non-string to d2b');
|
||||
if (typeof u !== "string") {
|
||||
throw Error("Attempted to pass non-string to d2b");
|
||||
}
|
||||
var p = u.split(/[:;,]/),
|
||||
t = p[1],
|
||||
dec = p[2] === 'base64' ? atob : decodeURIComponent,
|
||||
dec = p[2] === "base64" ? atob : decodeURIComponent,
|
||||
bin = dec(p.pop()),
|
||||
mx = bin.length,
|
||||
i = 0,
|
||||
@@ -73,14 +73,14 @@ export default function download(
|
||||
}
|
||||
|
||||
function saver(url, winMode) {
|
||||
if (typeof url !== 'string') {
|
||||
throw Error('Attempted to pass non-string url to saver');
|
||||
if (typeof url !== "string") {
|
||||
throw Error("Attempted to pass non-string url to saver");
|
||||
}
|
||||
|
||||
if ('download' in a) {
|
||||
if ("download" in a) {
|
||||
a.href = url;
|
||||
a.setAttribute('download', fn);
|
||||
a.innerHTML = 'downloading…';
|
||||
a.setAttribute("download", fn);
|
||||
a.innerHTML = "downloading…";
|
||||
D.body && D.body.appendChild(a);
|
||||
setTimeout(function() {
|
||||
a.click();
|
||||
@@ -95,11 +95,11 @@ export default function download(
|
||||
}
|
||||
|
||||
//do iframe dataURL download (old ch+FF):
|
||||
var f = D.createElement('iframe');
|
||||
var f = D.createElement("iframe");
|
||||
D.body && D.body.appendChild(f);
|
||||
if (!winMode) {
|
||||
// force a mime that will download:
|
||||
url = 'data:' + url.replace(/^data:([\w\/\-\+]+)/, u);
|
||||
url = "data:" + url.replace(/^data:([\w\/\-\+]+)/, u);
|
||||
}
|
||||
|
||||
f.src = url;
|
||||
@@ -121,14 +121,14 @@ export default function download(
|
||||
// handle non-Blob()+non-URL browsers:
|
||||
if (
|
||||
blob &&
|
||||
(typeof blob === 'string' || blob.constructor === z) &&
|
||||
typeof m === 'string'
|
||||
(typeof blob === "string" || blob.constructor === z) &&
|
||||
typeof m === "string"
|
||||
) {
|
||||
try {
|
||||
return saver('data:' + m + ';base64,' + self.btoa(blob));
|
||||
return saver("data:" + m + ";base64," + self.btoa(blob));
|
||||
} catch (y) {
|
||||
// $FlowIssue
|
||||
return saver('data:' + m + ',' + encodeURIComponent(blob));
|
||||
return saver("data:" + m + "," + encodeURIComponent(blob));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export function toCodePoint(unicodeSurrogates: string, sep: ?string) {
|
||||
r.push(c.toString(16));
|
||||
}
|
||||
}
|
||||
return r.join(sep || '-');
|
||||
return r.join(sep || "-");
|
||||
}
|
||||
|
||||
export function emojiToUrl(text: string) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// @flow
|
||||
import ExtendableError from 'es6-error';
|
||||
import ExtendableError from "es6-error";
|
||||
|
||||
export class AuthorizationError extends ExtendableError {}
|
||||
export class NetworkError extends ExtendableError {}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @flow
|
||||
import Document from 'models/Document';
|
||||
import DocumentsStore from 'stores/DocumentsStore';
|
||||
import parseTitle from 'shared/utils/parseTitle';
|
||||
import Document from "models/Document";
|
||||
import DocumentsStore from "stores/DocumentsStore";
|
||||
import parseTitle from "shared/utils/parseTitle";
|
||||
|
||||
type Options = {
|
||||
file: File,
|
||||
@@ -25,14 +25,14 @@ const importFile = async ({
|
||||
|
||||
// If the first line of the imported file looks like a markdown heading
|
||||
// then we can use this as the document title
|
||||
if (text.trim().startsWith('# ')) {
|
||||
if (text.trim().startsWith("# ")) {
|
||||
const result = parseTitle(text);
|
||||
title = result.title;
|
||||
text = text.replace(`# ${title}\n`, '');
|
||||
text = text.replace(`# ${title}\n`, "");
|
||||
|
||||
// otherwise, just use the filename without the extension as our best guess
|
||||
} else {
|
||||
title = file.name.replace(/\.[^/.]+$/, '');
|
||||
title = file.name.replace(/\.[^/.]+$/, "");
|
||||
}
|
||||
|
||||
let document = new Document(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// @flow
|
||||
import { parseDomain } from '../../shared/utils/domains';
|
||||
import { parseDomain } from "../../shared/utils/domains";
|
||||
|
||||
export default function isInternalUrl(href: string) {
|
||||
if (href[0] === '/') return true;
|
||||
if (href[0] === "/") return true;
|
||||
|
||||
const outline = parseDomain(window.location.href);
|
||||
const parsed = parseDomain(href);
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
// @flow
|
||||
|
||||
export const meta = window.navigator.platform === 'MacIntel' ? '⌘' : 'Ctrl';
|
||||
export const meta = window.navigator.platform === "MacIntel" ? "⌘" : "Ctrl";
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
// @flow
|
||||
import Document from 'models/Document';
|
||||
import Document from "models/Document";
|
||||
|
||||
export function homeUrl(): string {
|
||||
return '/home';
|
||||
return "/home";
|
||||
}
|
||||
|
||||
export function starredUrl(): string {
|
||||
return '/starred';
|
||||
return "/starred";
|
||||
}
|
||||
|
||||
export function newCollectionUrl(): string {
|
||||
return '/collections/new';
|
||||
return "/collections/new";
|
||||
}
|
||||
|
||||
export function collectionUrl(collectionId: string, section: ?string): string {
|
||||
@@ -43,10 +43,10 @@ export function documentHistoryUrl(doc: Document, revisionId?: string): string {
|
||||
*/
|
||||
export function updateDocumentUrl(oldUrl: string, newUrl: string): string {
|
||||
// Update url to match the current one
|
||||
const urlParts = oldUrl.trim().split('/');
|
||||
const urlParts = oldUrl.trim().split("/");
|
||||
const actions = urlParts.slice(3);
|
||||
if (actions[0]) {
|
||||
return [newUrl, actions].join('/');
|
||||
return [newUrl, actions].join("/");
|
||||
}
|
||||
return newUrl;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ export function newDocumentUrl(
|
||||
}
|
||||
|
||||
export function searchUrl(query?: string, collectionId?: string): string {
|
||||
let route = '/search';
|
||||
let route = "/search";
|
||||
if (query) route += `/${encodeURIComponent(query)}`;
|
||||
|
||||
if (collectionId) {
|
||||
@@ -75,10 +75,10 @@ export function searchUrl(query?: string, collectionId?: string): string {
|
||||
}
|
||||
|
||||
export function notFoundUrl(): string {
|
||||
return '/404';
|
||||
return "/404";
|
||||
}
|
||||
|
||||
export const matchDocumentSlug =
|
||||
':documentSlug([0-9a-zA-Z-_~]*-[a-zA-z0-9]{10,15})';
|
||||
":documentSlug([0-9a-zA-Z-_~]*-[a-zA-z0-9]{10,15})";
|
||||
|
||||
export const matchDocumentEdit = `/doc/${matchDocumentSlug}/edit`;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// @flow
|
||||
import { client } from './ApiClient';
|
||||
import invariant from 'invariant';
|
||||
import { client } from "./ApiClient";
|
||||
import invariant from "invariant";
|
||||
|
||||
type Options = {
|
||||
name?: string,
|
||||
@@ -10,10 +10,10 @@ type Options = {
|
||||
|
||||
export const uploadFile = async (
|
||||
file: File | Blob,
|
||||
options?: Options = { name: '' }
|
||||
options?: Options = { name: "" }
|
||||
) => {
|
||||
const name = file instanceof File ? file.name : options.name;
|
||||
const response = await client.post('/attachments.create', {
|
||||
const response = await client.post("/attachments.create", {
|
||||
public: options.public,
|
||||
documentId: options.documentId,
|
||||
contentType: file.type,
|
||||
@@ -21,7 +21,7 @@ export const uploadFile = async (
|
||||
name,
|
||||
});
|
||||
|
||||
invariant(response, 'Response should be available');
|
||||
invariant(response, "Response should be available");
|
||||
|
||||
const data = response.data;
|
||||
const attachment = data.attachment;
|
||||
@@ -34,13 +34,13 @@ export const uploadFile = async (
|
||||
// $FlowFixMe
|
||||
if (file.blob) {
|
||||
// $FlowFixMe
|
||||
formData.append('file', file.file);
|
||||
formData.append("file", file.file);
|
||||
} else {
|
||||
formData.append('file', file);
|
||||
formData.append("file", file);
|
||||
}
|
||||
|
||||
await fetch(data.uploadUrl, {
|
||||
method: 'post',
|
||||
method: "post",
|
||||
body: formData,
|
||||
});
|
||||
|
||||
@@ -48,11 +48,11 @@ export const uploadFile = async (
|
||||
};
|
||||
|
||||
export const dataUrlToBlob = (dataURL: string) => {
|
||||
var blobBin = atob(dataURL.split(',')[1]);
|
||||
var blobBin = atob(dataURL.split(",")[1]);
|
||||
var array = [];
|
||||
for (var i = 0; i < blobBin.length; i++) {
|
||||
array.push(blobBin.charCodeAt(i));
|
||||
}
|
||||
const file = new Blob([new Uint8Array(array)], { type: 'image/png' });
|
||||
const file = new Blob([new Uint8Array(array)], { type: "image/png" });
|
||||
return file;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user