Browse Source

feat: export types for package @excalidraw/excalidraw 🎉 (#3337)

* feat: export types for package @excalidraw/excalidraw

* update

* remove

* Add lib in tsconfig-types and Add global.d.ts, and errors down to 39 :)

* Add declaration for scss so typescript allows scss imports, errors down to 37 :)

* Add css.d.ts, errors down to 32 yay

* set target to es6, all errors resolved yay

* move types outside dist

* update docs

* fix
vanilla_orig
Aakansha Doshi 4 years ago
parent
commit
a6706cff20
No account linked to committer's email address

+ 1
- 0
.gitignore View File

@@ -20,3 +20,4 @@ package-lock.json
20 20
 static
21 21
 yarn-debug.log*
22 22
 yarn-error.log*
23
+src/packages/excalidraw/types

+ 2
- 0
src/global.d.ts View File

@@ -89,3 +89,5 @@ interface Blob {
89 89
   handle?: import("browser-fs-acces").FileSystemHandle;
90 90
   name?: string;
91 91
 }
92
+
93
+declare module "*.scss";

+ 1
- 0
src/packages/excalidraw/CHANGELOG.md View File

@@ -18,6 +18,7 @@ Please add the latest change on the top under the correct section.
18 18
 
19 19
 ### Features
20 20
 
21
+- Export types for the package so now it can be used with typescript[#3337](https://github.com/excalidraw/excalidraw/pull/3337). The types are available at `@excalidraw/excalirdraw/types`.
21 22
 - Add `renderCustomStats` prop to render extra stats on host, and expose `setToastMessage` API via refs which can be used to show toast with custom message [#3360](https://github.com/excalidraw/excalidraw/pull/3360).
22 23
 - Support passing a CSRF token when importing libraries to prevent prompting before installation. The token is passed from [https://libraries.excalidraw.com](https://libraries.excalidraw.com/) using the `token` URL key [#3329](https://github.com/excalidraw/excalidraw/pull/3329).
23 24
 - #### BREAKING CHANGE

+ 3
- 1
src/packages/excalidraw/README_NEXT.md View File

@@ -171,6 +171,8 @@ To view the full example visit :point_down:
171 171
 
172 172
 [![Edit excalidraw](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/excalidraw-ehlz3?fontsize=14&hidenavigation=1&theme=dark)
173 173
 
174
+</details>
175
+
174 176
 Since Excalidraw doesn't support server side rendering yet so you will have to make sure the component is rendered once host is mounted.
175 177
 
176 178
 ```js
@@ -184,7 +186,7 @@ export default function IndexPage() {
184 186
 }
185 187
 ```
186 188
 
187
-</details>
189
+The `types` are available at `@excalidraw/excalidraw/types`, you can view [example for typescript](https://codesandbox.io/s/excalidraw-types-9h2dm)
188 190
 
189 191
 #### In Browser
190 192
 

+ 6
- 2
src/packages/excalidraw/package.json View File

@@ -2,8 +2,10 @@
2 2
   "name": "@excalidraw/excalidraw",
3 3
   "version": "0.5.0",
4 4
   "main": "main.js",
5
+  "types": "types/packages/excalidraw/index.d.ts",
5 6
   "files": [
6
-    "dist/*"
7
+    "dist/*",
8
+    "types/*"
7 9
   ],
8 10
   "publishConfig": {
9 11
     "access": "public"
@@ -58,6 +60,7 @@
58 60
     "sass-loader": "11.0.1",
59 61
     "terser-webpack-plugin": "5.1.1",
60 62
     "ts-loader": "8.0.18",
63
+    "typescript": "4.2.3",
61 64
     "webpack": "5.28.0",
62 65
     "webpack-bundle-analyzer": "4.4.0",
63 66
     "webpack-cli": "4.6.0"
@@ -66,7 +69,8 @@
66 69
   "repository": "https://github.com/excalidraw/excalidraw",
67 70
   "homepage": "https://github.com/excalidraw/excalidraw/tree/master/src/packages/excalidraw",
68 71
   "scripts": {
69
-    "build:umd": "cross-env NODE_ENV=production webpack --config webpack.prod.config.js && cross-env NODE_ENV=development webpack --config webpack.dev.config.js",
72
+    "gen:types": "tsc --project ../../../tsconfig-types.json",
73
+    "build:umd": "cross-env NODE_ENV=production webpack --config webpack.prod.config.js && cross-env NODE_ENV=development webpack --config webpack.dev.config.js && yarn gen:types",
70 74
     "build:umd:withAnalyzer": "cross-env NODE_ENV=production ANALYZER=true webpack --config webpack.prod.config.js",
71 75
     "pack": "yarn build:umd && yarn pack"
72 76
   }

+ 5
- 0
src/packages/excalidraw/yarn.lock View File

@@ -2586,6 +2586,11 @@ tslib@^1.9.0:
2586 2586
   resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
2587 2587
   integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
2588 2588
 
2589
+typescript@4.2.3:
2590
+  version "4.2.3"
2591
+  resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.3.tgz#39062d8019912d43726298f09493d598048c1ce3"
2592
+  integrity sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==
2593
+
2589 2594
 unicode-canonical-property-names-ecmascript@^1.0.4:
2590 2595
   version "1.0.4"
2591 2596
   resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818"

+ 18
- 0
tsconfig-types.json View File

@@ -0,0 +1,18 @@
1
+{
2
+  "include": ["src/packages/excalidraw", "src/global.d.ts", "src/css.d.ts"],
3
+  "compilerOptions": {
4
+    "allowJs": true,
5
+    "declaration": true,
6
+    "emitDeclarationOnly": true,
7
+    "outDir": "src/packages/excalidraw/types",
8
+    "jsx": "react-jsx",
9
+    "target": "es6",
10
+    "lib": ["dom", "dom.iterable", "esnext"],
11
+    "module": "esnext",
12
+    "moduleResolution": "node",
13
+    "resolveJsonModule": true,
14
+    "skipLibCheck": true,
15
+    "allowSyntheticDefaultImports": true,
16
+    "strict": true
17
+  }
18
+}

Loading…
Cancel
Save