-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add eslint + prettier * del yarn.lock - clashes with package-lock * WIP * add peer dependencies * useSiftView: hypothetically complete * useSiftController: WIP * update import use * return render * 1.0.0-beta.0 * lint config * different importing * fix imports * debug build * change rendering implementation * cleanup * rem useSiftController * beta.6 * rem cache * rebuild * cleanup unrequired files * separate react bundle. Update rollup to latest. Remove unrequired * eslint config * new build process * importing fix * simplify * 1.0.0-beta.11 * optional props * babel config * add supported engines for build * Update package.json
- Loading branch information
Showing
12 changed files
with
3,211 additions
and
6,477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"commonjs": true | ||
}, | ||
"extends": ["eslint:recommended", "plugin:react/recommended"], | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"plugins": ["react"], | ||
"rules": {} | ||
} |
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
{ | ||
"name": "@redsift/sift-sdk-web", | ||
"version": "0.16.8", | ||
"version": "1.0.0-beta.13", | ||
"description": "SDK for developing web-based Sifts.", | ||
"jsnext:main": "dist/sift-sdk-web.esm.js", | ||
"module": "dist/sift-sdk-web.esm.js", | ||
"main": "dist/sift-sdk-web.umd.js", | ||
"browser": "dist/sift-sdk-web.umd.js", | ||
"esnext": "src/index.js", | ||
"files": [ | ||
"dist", | ||
"react.js" | ||
], | ||
"scripts": { | ||
"build": "npm run clean && rollup-bundler", | ||
"build": "npm run clean && rollup --config", | ||
"clean": "rm -rf ./dist", | ||
"prepare": "npm run build", | ||
"pretest": "npm outdated || true", | ||
|
@@ -21,13 +23,42 @@ | |
], | ||
"author": "Martin Hecher <[email protected]>", | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=12.16.3", | ||
"npm": ">=6.13.4" | ||
}, | ||
"dependencies": { | ||
"@redsift/observable": "^1.2.0", | ||
"@redsift/rs-storage": "^1.3.1", | ||
"js-sha256": "^0.9.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/runtime": "^7.4.5", | ||
"@redsift/rollup-bundler": "^0.7.1" | ||
"@babel/core": "^7.9.6", | ||
"@babel/plugin-proposal-class-properties": "^7.8.3", | ||
"@babel/plugin-transform-runtime": "^7.9.6", | ||
"@babel/preset-env": "^7.9.6", | ||
"@rollup/plugin-babel": "^5.0.2", | ||
"@rollup/plugin-commonjs": "^12.0.0", | ||
"@rollup/plugin-node-resolve": "^8.0.0", | ||
"babel-eslint": "^10.1.0", | ||
"eslint": "^7.0.0", | ||
"eslint-plugin-react": "^7.20.0", | ||
"husky": ">=4", | ||
"lint-staged": ">=10", | ||
"prettier": "^2.0.5", | ||
"rollup": "^2.10.9" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.13.1", | ||
"react-dom": "^16.13.1" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.{js,jsx}": "eslint --cache --fix", | ||
"*.{js,jsx,css,md}": "prettier --write" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist/react.umd'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import resolve from '@rollup/plugin-node-resolve'; | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import { getBabelOutputPlugin } from '@rollup/plugin-babel'; | ||
import pkg from './package.json'; | ||
|
||
const babelConfig = { | ||
presets: [['@babel/preset-env']], | ||
plugins: [ | ||
'@babel/plugin-transform-runtime', | ||
'@babel/plugin-proposal-class-properties', | ||
], | ||
}; | ||
|
||
const babelConfigUmd = { | ||
presets: [['@babel/preset-env', { modules: 'umd' }]], | ||
plugins: babelConfig.plugins, | ||
}; | ||
|
||
export default [ | ||
{ | ||
input: './src/index.js', | ||
plugins: [resolve(), commonjs()], | ||
output: [ | ||
{ | ||
file: pkg.module, | ||
format: 'es', | ||
name: 'sift-sdk-web', | ||
plugins: [getBabelOutputPlugin(babelConfig)], | ||
}, | ||
{ | ||
file: pkg.browser, | ||
format: 'esm', | ||
name: 'sift-sdk-web', | ||
plugins: [getBabelOutputPlugin(babelConfigUmd)], | ||
}, | ||
], | ||
}, | ||
{ | ||
input: './src/react.js', | ||
plugins: [resolve(), commonjs()], | ||
output: [ | ||
{ | ||
file: 'dist/react.esm.js', | ||
format: 'es', | ||
name: 'sift-sdk-web/react', | ||
plugins: [getBabelOutputPlugin(babelConfig)], | ||
}, | ||
{ | ||
file: 'dist/react.umd.js', | ||
format: 'esm', | ||
name: 'sift-sdk-web/react', | ||
plugins: [getBabelOutputPlugin(babelConfigUmd)], | ||
}, | ||
], | ||
}, | ||
]; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import { useState, useEffect } from 'react'; | ||
import PluginManager from '../lib/plugin-manager'; | ||
import Observable from '@redsift/observable'; | ||
import sha256 from 'js-sha256'; | ||
|
||
const useSiftView = (props = {}) => { | ||
const { willPresentView } = props; | ||
const [resizeHandler] = useState(null); | ||
const [proxy] = useState(parent); | ||
const [controller] = useState(new Observable()); | ||
const [pluginManager] = useState(new PluginManager()); | ||
const [params, setParams] = useState(null); | ||
|
||
const notifyClient = (topic, value = {}) => { | ||
proxy.postMessage( | ||
{ method: 'notifyClient', params: { topic, value } }, | ||
'*' | ||
); | ||
}; | ||
|
||
const _initPlugins = ({ pluginConfigs }) => { | ||
pluginManager.init({ | ||
pluginConfigs, | ||
contextType: 'view', | ||
context: { notifyClient }, | ||
global: window, | ||
}); | ||
}; | ||
|
||
const _startPlugins = ({ pluginConfigs }) => { | ||
pluginManager.start({ | ||
pluginConfigs, | ||
contextType: 'view', | ||
context: { notifyClient }, | ||
global: window, | ||
}); | ||
}; | ||
|
||
const _stopPlugins = ({ pluginConfigs }) => { | ||
pluginManager.stop({ | ||
pluginConfigs, | ||
contextType: 'view', | ||
context: { notifyClient }, | ||
global: window, | ||
}); | ||
}; | ||
|
||
const _receivePluginMessages = ({ messages }) => { | ||
pluginManager.onMessages({ messages }); | ||
}; | ||
|
||
const getPlugin = ({ id }) => { | ||
return ( | ||
pluginManager | ||
.getActivePlugins() | ||
// NOTE: see https://stackoverflow.com/questions/28627908/call-static-methods-from-regular-es6-class-methods | ||
.find((plugin) => plugin.constructor.id() === id) | ||
); | ||
}; | ||
|
||
const publish = (topic, value) => { | ||
proxy.postMessage( | ||
{ method: 'notifyController', params: { topic, value } }, | ||
'*' | ||
); | ||
}; | ||
|
||
const showOAuthPopup = ({ provider, options = null }) => { | ||
let opt = options; | ||
// If an email is passed, hash it into a subject | ||
if (options && typeof options === 'object' && options.email) { | ||
const { email, ...others } = options; | ||
const subject = sha256(email).substr(0, 16); | ||
opt = { subject, ...others }; | ||
} | ||
notifyClient('showOAuthPopup', { provider, options: opt }); | ||
}; | ||
|
||
const removeOAuthIdentity = ({ provider, options = null }) => { | ||
notifyClient('showOAuthRemovePopup', { provider, options }); | ||
}; | ||
|
||
const signup = () => { | ||
notifyClient('signup'); | ||
}; | ||
|
||
const login = ({ redirectUri }) => { | ||
notifyClient('login', { redirectUri }); | ||
}; | ||
|
||
const logout = () => { | ||
notifyClient('logout'); | ||
}; | ||
|
||
const navigate = ({ href, openInNewTab = false }) => { | ||
notifyClient('navigate', { href, openInNewTab }); | ||
}; | ||
|
||
const setupSyncHistory = ({ history, initialPath }) => { | ||
const syncHistoryPlugin = getPlugin({ id: 'sync-history' }); | ||
if (syncHistoryPlugin) { | ||
syncHistoryPlugin.setup({ history, initialPath }); | ||
} else { | ||
console.log( | ||
'[SiftSdkWeb] ERROR: To use `syncHistory` please enable the plugin first!' | ||
); | ||
} | ||
}; | ||
|
||
const presentView = (props) => { | ||
setParams(props); | ||
}; | ||
|
||
const siftView = { | ||
resizeHandler, | ||
proxy, | ||
controller, | ||
pluginManager, | ||
_initPlugins, | ||
_startPlugins, | ||
_stopPlugins, | ||
_receivePluginMessages, | ||
getPlugin, | ||
publish, | ||
notifyClient, | ||
showOAuthPopup, | ||
removeOAuthIdentity, | ||
signup, | ||
login, | ||
logout, | ||
navigate, | ||
setupSyncHistory, | ||
presentView, | ||
willPresentView, | ||
}; | ||
|
||
useEffect(() => { | ||
const _registerMessageListeners = () => { | ||
window.addEventListener( | ||
'message', | ||
({ data: { method, params } }) => { | ||
if (method === 'notifyView') { | ||
controller.publish(params.topic, params.value); | ||
} else if (siftView[method]) { | ||
siftView[method](params); | ||
} else { | ||
console.warn(`[SiftView]: method not implemented: ${method}`); | ||
} | ||
}, | ||
false | ||
); | ||
}; | ||
_registerMessageListeners(); | ||
}, []); | ||
|
||
return [params, siftView]; | ||
}; | ||
|
||
export default useSiftView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import useSiftView from './core/useSiftView'; | ||
|
||
export { useSiftView }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.