add excalidraw_embed into base repo (#2040)

Co-authored-by: Lipis <lipiridis@gmail.com>
This commit is contained in:
David Luzar 2020-08-20 16:45:20 +02:00 committed by GitHub
parent 80cbe13167
commit ab7073abdb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 6710 additions and 77 deletions

2
src/excalidraw-embed/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
node_modules
dist

View file

@ -0,0 +1,71 @@
import React, { useEffect } from "react";
import { InitializeApp } from "../components/InitializeApp";
import App from "../components/App";
import "../css/app.scss";
import "../css/styles.scss";
import { ExcalidrawProps } from "../types";
import { IsMobileProvider } from "../is-mobile";
const Excalidraw = React.memo(
(props: ExcalidrawProps) => {
const {
width,
height,
onChange,
initialData,
user,
onUsernameChange,
} = props;
useEffect(() => {
// Block pinch-zooming on iOS outside of the content area
const handleTouchMove = (event: TouchEvent) => {
// @ts-ignore
if (typeof event.scale === "number" && event.scale !== 1) {
event.preventDefault();
}
};
document.addEventListener("touchmove", handleTouchMove, {
passive: false,
});
return () => {
document.removeEventListener("touchmove", handleTouchMove);
};
}, []);
return (
<InitializeApp>
<IsMobileProvider>
<App
width={width}
height={height}
onChange={onChange}
initialData={initialData}
user={user}
onUsernameChange={onUsernameChange}
/>
</IsMobileProvider>
</InitializeApp>
);
},
(prevProps: ExcalidrawProps, nextProps: ExcalidrawProps) => {
const { initialData: prevInitialData, user: prevUser, ...prev } = prevProps;
const { initialData: nextInitialData, user: nextUser, ...next } = nextProps;
const prevKeys = Object.keys(prevProps) as (keyof typeof prev)[];
const nextKeys = Object.keys(nextProps) as (keyof typeof next)[];
return (
prevUser?.name === nextUser?.name &&
prevKeys.length === nextKeys.length &&
prevKeys.every((key) => prev[key] === next[key])
);
},
);
export default Excalidraw;

6384
src/excalidraw-embed/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,66 @@
{
"name": "@excalidraw/excalidraw",
"version": "0.7.0",
"main": "dist/excalidraw.min.js",
"files": [
"dist/*"
],
"description": "Excalidraw as a React component",
"license": "MIT",
"keywords": [
"excalidraw",
"excalidraw-embed",
"react",
"npm",
"npm excalidraw"
],
"browserslist": {
"production": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all",
"not safari < 12",
"not kaios <= 2.5",
"not edge < 79",
"not chrome < 70",
"not and_uc < 13",
"not samsung < 10"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"peerDependencies": {
"react": "16.13.1",
"react-dom": "16.13.1"
},
"devDependencies": {
"@babel/core": "7.9.0",
"@babel/plugin-transform-arrow-functions": "7.8.3",
"@babel/plugin-transform-async-to-generator": "7.8.3",
"@babel/plugin-transform-typescript": "7.9.4",
"@babel/preset-env": "7.9.5",
"@babel/preset-react": "7.9.4",
"@babel/preset-typescript": "7.9.0",
"babel-loader": "8.1.0",
"babel-plugin-transform-class-properties": "6.24.1",
"cross-env": "7.0.2",
"css-loader": "3.5.2",
"file-loader": "6.0.0",
"mini-css-extract-plugin": "0.8.0",
"sass-loader": "8.0.2",
"terser-webpack-plugin": "2.3.5",
"ts-loader": "7.0.0",
"webpack": "4.42.0",
"webpack-cli": "3.3.11"
},
"bugs": "https://github.com/excalidraw/excalidraw/issues",
"repository": "https://github.com/excalidraw/excalidraw",
"scripts": {
"build:umd": "cross-env NODE_ENV=production webpack --config webpack.prod.config.js",
"pack": "npm run build:umd && npm pack"
}
}

View file

@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"resolveJsonModule": true,
"jsx": "react"
}
}

View file

@ -0,0 +1,99 @@
const path = require("path");
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
mode: "production",
entry: {
"excalidraw.min": "./index.tsx",
},
output: {
path: path.resolve(__dirname, "dist"),
library: "Excalidraw",
libraryTarget: "umd",
filename: "[name].js",
},
resolve: {
extensions: [".js", ".ts", ".tsx", ".css", ".scss"],
},
module: {
rules: [
{
test: /\.(sa|sc|c)ss$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{ loader: "css-loader" },
"sass-loader",
],
},
{
test: /\.(ts|tsx|js|jsx|mjs)$/,
exclude: /node_modules\/(?!(roughjs|socket.io-client|browser-nativefs)\/).*/,
use: [
{
loader: "ts-loader",
options: {
transpileOnly: true,
configFile: path.resolve(__dirname, "tsconfig.prod.json"),
},
},
{
loader: "babel-loader",
options: {
presets: [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript",
],
plugins: [
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-transform-arrow-functions",
"transform-class-properties",
"@babel/plugin-transform-async-to-generator",
],
},
},
],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]",
},
},
],
},
],
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
test: /\.js($|\?)/i,
}),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
],
},
plugins: [new MiniCssExtractPlugin({ filename: "[name].css" })],
externals: {
react: {
root: "React",
commonjs2: "react",
commonjs: "react",
amd: "react",
},
"react-dom": {
root: "ReactDOM",
commonjs2: "react-dom",
commonjs: "react-dom",
amd: "react-dom",
},
},
};