docs: excalidraw package usage example tweaks (#2608)

Co-authored-by: Aakansha Doshi <monstershome@gmail.com>
pull/2619/head
David Luzar 4 years ago committed by GitHub
parent 325d1bec91
commit 34dcf998bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,34 +1,34 @@
const { exec } = require("child_process"); const { exec } = require("child_process");
const changeLogCheck = () => { const normalizePath = (path) => path.replace(/\\+/g, "/").trim().toLowerCase();
exec(
"git diff origin/master --cached --name-only",
(error, stdout, stderr) => {
if (error || stderr) {
process.exit(1);
}
if (!stdout || stdout.includes("packages/excalidraw/CHANGELOG.md")) { const IGNORED_PATHS = [
process.exit(0); "src/excalidraw-app",
} "packages/utils",
"CHANGELOG.md",
"README.md",
].map(normalizePath);
const onlyNonSrcFilesUpdated = stdout.indexOf("src") < 0; exec("git diff origin/master --cached --name-only", (error, stdout, stderr) => {
if (onlyNonSrcFilesUpdated) { if (error || stderr) {
process.exit(0); process.exit(1);
} }
const changedFiles = stdout.trim().split("\n"); if (!stdout || stdout.includes("packages/excalidraw/CHANGELOG.md")) {
const filesToIgnoreRegex = /src\/excalidraw-app|packages\/utils/; process.exit(0);
}
const excalidrawPackageFiles = changedFiles.filter((file) => { const changedFiles = stdout.trim().split("\n").map(normalizePath);
return file.indexOf("src") >= 0 && !filesToIgnoreRegex.test(file);
});
if (excalidrawPackageFiles.length) { const excalidrawPackageFiles = changedFiles.filter((filename) => {
process.exit(1); return (
} filename.includes("src") &&
process.exit(0); !IGNORED_PATHS.find((ignoredPath) => filename.includes(ignoredPath))
}, );
); });
};
changeLogCheck(); if (excalidrawPackageFiles.length) {
process.exit(1);
}
process.exit(0);
});

@ -39,26 +39,19 @@ import "./styles.css";
export default function App() { export default function App() {
const excalidrawRef = createRef(); const excalidrawRef = createRef();
const onChange = (elements, state) => {
console.log(excalidrawRef.current);
console.log("Elements :", elements, "State : ", state);
};
const [dimensions, setDimensions] = useState({ const [dimensions, setDimensions] = useState({
width: window.innerWidth, width: window.innerWidth,
height: window.innerHeight, height: window.innerHeight,
}); });
const onResize = () => {
setDimensions({
width: window.innerWidth,
height: window.innerHeight,
});
};
useEffect(() => { useEffect(() => {
const onResize = () => {
setDimensions({
width: window.innerWidth,
height: window.innerHeight,
});
};
window.addEventListener("resize", onResize); window.addEventListener("resize", onResize);
return () => window.removeEventListener("resize", onResize); return () => window.removeEventListener("resize", onResize);
}, []); }, []);
@ -94,7 +87,6 @@ export default function App() {
excalidrawRef.current.updateScene(sceneData); excalidrawRef.current.updateScene(sceneData);
}; };
const { width, height } = dimensions;
return ( return (
<div className="App"> <div className="App">
<button className="update-scene" onClick={updateScene}> <button className="update-scene" onClick={updateScene}>
@ -111,12 +103,17 @@ export default function App() {
<div className="excalidraw-wrapper"> <div className="excalidraw-wrapper">
<Excalidraw <Excalidraw
ref={excalidrawRef} ref={excalidrawRef}
width={width} width={dimensions.width}
height={height} height={dimensions.height}
initialData={InitialData} initialData={InitialData}
onChange={onChange} onChange={(elements, state) => {
console.log("Latest elements:", elements, "Latest state:", state);
}}
user={{ name: "Excalidraw User" }} user={{ name: "Excalidraw User" }}
onPointerUpdate={(payload) => console.log(payload)} onPointerUpdate={(pointerData) => console.log(pointerData)}
onCollabButtonClick={() => {
window.alert("You clicked on collab button");
}}
/> />
</div> </div>
</div> </div>

Loading…
Cancel
Save