mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-25 16:20:49 +02:00
Slate base64 serializer and SSR (#1208)
* provide polyfill for btoa and atob * add fallback for Buffer.from * fix listing issues * remove window usage for URIComponent * remove monkeyPatching and add window check * fix linter warnings * update to use isomorphic-base64
This commit is contained in:
committed by
Ian Storm Taylor
parent
a0a03ba276
commit
33bfeb8cda
@@ -15,6 +15,9 @@
|
||||
"slate": "^0.27.4",
|
||||
"uglify-js": "^2.7.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"isomorphic-base64": "^1.0.2"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "babel --out-dir ./lib ./src",
|
||||
"build:max": "mkdir -p ./dist && NODE_ENV=production browserify ./src/index.js --transform babelify --transform envify --transform [ browserify-global-shim --global ] --standalone SlateBase64Serializer > ./dist/slate-base64-serializer.js",
|
||||
|
@@ -1,5 +1,6 @@
|
||||
|
||||
import { State } from 'slate'
|
||||
import { atob, btoa } from 'isomorphic-base64'
|
||||
|
||||
/**
|
||||
* Encode a JSON `object` as base-64 `string`.
|
||||
@@ -10,7 +11,7 @@ import { State } from 'slate'
|
||||
|
||||
function encode(object) {
|
||||
const string = JSON.stringify(object)
|
||||
const encoded = window.btoa(window.encodeURIComponent(string))
|
||||
const encoded = btoa(encodeURIComponent(string))
|
||||
return encoded
|
||||
}
|
||||
|
||||
@@ -22,7 +23,7 @@ function encode(object) {
|
||||
*/
|
||||
|
||||
function decode(string) {
|
||||
const decoded = window.decodeURIComponent(window.atob(string))
|
||||
const decoded = decodeURIComponent(atob(string))
|
||||
const object = JSON.parse(decoded)
|
||||
return object
|
||||
}
|
||||
|
Reference in New Issue
Block a user