Skip to content

Commit fa763c1

Browse files
d13nzaytsev
andcommitted
Converts the graph view to web-components
Co-authored-by: Nikolai Zaytsev <[email protected]>
1 parent aafd25a commit fa763c1

File tree

29 files changed

+7237
-374
lines changed

29 files changed

+7237
-374
lines changed

ThirdPartyNotices.txt

Lines changed: 149 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,23 @@ This project incorporates components from the projects listed below.
1717
12. @opentelemetry/resources version 1.30.1 (https://github.com/open-telemetry/opentelemetry-js)
1818
13. @opentelemetry/sdk-trace-base version 1.30.1 (https://github.com/open-telemetry/opentelemetry-js)
1919
14. @opentelemetry/semantic-conventions version 1.30.0 (https://github.com/open-telemetry/opentelemetry-js)
20-
15. @shoelace-style/shoelace version 2.20.0 (https://github.com/shoelace-style/shoelace)
21-
16. @vscode/codicons version 0.0.36 (https://github.com/microsoft/vscode-codicons)
22-
17. billboard.js version 3.14.3 (https://github.com/naver/billboard.js)
23-
18. https-proxy-agent version 5.0.1 (https://github.com/TooTallNate/node-https-proxy-agent)
24-
19. iconv-lite version 0.6.3 (https://github.com/ashtuchkin/iconv-lite)
25-
20. lit version 3.2.1 (https://github.com/lit/lit)
26-
21. marked version 15.0.7 (https://github.com/markedjs/marked)
27-
22. microsoft/vscode (https://github.com/microsoft/vscode)
28-
23. node-fetch version 2.7.0 (https://github.com/bitinn/node-fetch)
29-
24. os-browserify version 0.3.0 (https://github.com/CoderPuppy/os-browserify)
30-
25. path-browserify version 1.0.1 (https://github.com/browserify/path-browserify)
31-
26. react-dom version 16.8.4 (https://github.com/facebook/react)
32-
27. react version 16.8.4 (https://github.com/facebook/react)
33-
28. signal-utils version 0.21.1 (https://github.com/proposal-signals/signal-utils)
34-
29. slug version 10.0.0 (https://github.com/Trott/slug)
35-
30. sortablejs version 1.15.0 (https://github.com/SortableJS/Sortable)
20+
15. @r2wc/react-to-web-component version 2.0.4 (https://github.com/bitovi/react-to-web-component)
21+
16. @shoelace-style/shoelace version 2.20.0 (https://github.com/shoelace-style/shoelace)
22+
17. @vscode/codicons version 0.0.36 (https://github.com/microsoft/vscode-codicons)
23+
18. billboard.js version 3.14.3 (https://github.com/naver/billboard.js)
24+
19. https-proxy-agent version 5.0.1 (https://github.com/TooTallNate/node-https-proxy-agent)
25+
20. iconv-lite version 0.6.3 (https://github.com/ashtuchkin/iconv-lite)
26+
21. lit version 3.2.1 (https://github.com/lit/lit)
27+
22. marked version 15.0.7 (https://github.com/markedjs/marked)
28+
23. microsoft/vscode (https://github.com/microsoft/vscode)
29+
24. node-fetch version 2.7.0 (https://github.com/bitinn/node-fetch)
30+
25. os-browserify version 0.3.0 (https://github.com/CoderPuppy/os-browserify)
31+
26. path-browserify version 1.0.1 (https://github.com/browserify/path-browserify)
32+
27. react-dom version 19.0.0 (https://github.com/facebook/react)
33+
28. react version 19.0.0 (https://github.com/facebook/react)
34+
29. signal-utils version 0.21.1 (https://github.com/proposal-signals/signal-utils)
35+
30. slug version 10.0.0 (https://github.com/Trott/slug)
36+
31. sortablejs version 1.15.0 (https://github.com/SortableJS/Sortable)
3637

3738
%% @gk-nzaytsev/fast-string-truncated-width NOTICES AND INFORMATION BEGIN HERE
3839
=========================================
@@ -1324,6 +1325,136 @@ END OF @opentelemetry/sdk-trace-base NOTICES AND INFORMATION
13241325
=========================================
13251326
END OF @opentelemetry/semantic-conventions NOTICES AND INFORMATION
13261327

1328+
%% @r2wc/react-to-web-component NOTICES AND INFORMATION BEGIN HERE
1329+
=========================================
1330+
# React to Web Component
1331+
1332+
`@r2wc/react-to-web-component` converts [React](https://reactjs.org/) components to [custom elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements)! It lets you share React components as native elements that **don't** require being mounted through React. The custom element acts as a wrapper for the underlying React component. Use these custom elements with any project that uses HTML even in any framework (vue, svelte, angular, ember, canjs) the same way you would use standard HTML elements.
1333+
1334+
> Note: The latest version of this package only works with the React 18. If you are using React 16 or 17, please use version 1.
1335+
1336+
`@r2wc/react-to-web-component`:
1337+
1338+
- Works in all modern browsers. (Edge needs a [customElements polyfill](https://github.com/webcomponents/polyfills/tree/master/packages/custom-elements)).
1339+
- Is `1.26KB` minified and gzipped.
1340+
1341+
## Setup
1342+
1343+
To install from npm:
1344+
1345+
```
1346+
npm install @r2wc/react-to-web-component
1347+
```
1348+
1349+
## Need help or have questions?
1350+
1351+
This project is supported by [Bitovi, a React consultancy](https://www.bitovi.com/frontend-javascript-consulting/react-consulting). You can get help or ask questions on our:
1352+
1353+
- [Discord Community](https://discord.gg/J7ejFsZnJ4)
1354+
- [Twitter](https://twitter.com/bitovi)
1355+
1356+
Or, you can hire us for training, consulting, or development. [Set up a free consultation.](https://www.bitovi.com/frontend-javascript-consulting/react-consulting)
1357+
1358+
## Basic Use
1359+
1360+
For basic usage, we will use this simple React component:
1361+
1362+
```js
1363+
const Greeting = () => {
1364+
return <h1>Hello, World!</h1>
1365+
}
1366+
```
1367+
1368+
With our React component complete, all we have to do is call `r2wc` and [customElements.define](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define) to create and define our custom element:
1369+
1370+
```js
1371+
import r2wc from "@r2wc/react-to-web-component"
1372+
1373+
const WebGreeting = r2wc(Greeting)
1374+
1375+
customElements.define("web-greeting", WebGreeting)
1376+
```
1377+
1378+
Now we can use `<web-greeting>` like any other HTML element!
1379+
1380+
```html
1381+
<body>
1382+
<h1>Greeting Demo</h1>
1383+
1384+
<web-greeting></web-greeting>
1385+
</body>
1386+
```
1387+
1388+
In the above case, the web-greeting custom element is not making use of the `name` property from our `Greeting` component.
1389+
1390+
## Working with Attributes
1391+
1392+
By default, custom elements created by `r2wc` only pass properties to the underlying React component. To make attributes work, you must specify your component's props.
1393+
1394+
```js
1395+
const Greeting = ({ name }) => {
1396+
return <h1>Hello, {name}!</h1>
1397+
}
1398+
1399+
const WebGreeting = r2wc(Greeting, {
1400+
props: {
1401+
name: "string",
1402+
},
1403+
})
1404+
```
1405+
1406+
Now `r2wc` will know to look for `name` attributes
1407+
as follows:
1408+
1409+
```html
1410+
<body>
1411+
<h1>Greeting Demo</h1>
1412+
1413+
<web-greeting name="Justin"></web-greeting>
1414+
</body>
1415+
```
1416+
1417+
For projects needing more advanced usage of the web components, see our [programatic usage and declarative demos](docs/programatic-usage.md).
1418+
1419+
We also have a [complete example using a third party library](docs/complete-example.md).
1420+
1421+
## Examples
1422+
1423+
- [Hello World](https://codesandbox.io/s/hello-world-md5oih) - The quintessential software demo!
1424+
- [All the Props](https://codesandbox.io/s/all-the-props-n8z5hv) - A demo of all the prop transform types that R2WC supports.
1425+
- [Header Example](https://codesandbox.io/s/example-header-blog-7k313l) - An example reusable Header component.
1426+
- [MUI Button](https://codesandbox.io/s/example-mui-button-qwidh9) - An example application using an MUI button with theme customization.
1427+
- [Checklist Demo](https://codesandbox.io/s/example-checklist-blog-y3nqwx) - An example Checklist application.
1428+
1429+
## Blog Posts
1430+
1431+
R2WC with Vite [View Post](https://www.bitovi.com/blog/react-everywhere-with-vite-and-react-to-webcomponent)
1432+
1433+
R2WC with Create React App (CRA) [View Post](https://www.bitovi.com/blog/how-to-create-a-web-component-with-create-react-app)
1434+
1435+
## How it works
1436+
1437+
Check out our [full API documentation](https://github.com/bitovi/react-to-web-component/blob/main/docs/api.md).
1438+
1439+
Under the hood, `r2wc` creates a `CustomElementConstructor` with custom getters/setters and life cycle methods that keep track of the props that you have defined. When a property is set, its custom setter:
1440+
1441+
- re-renders the React component inside the custom element.
1442+
- creates an enumerable getter / setter on the instance to save the set value and avoid hitting the proxy in the future.
1443+
1444+
Also:
1445+
1446+
- Enumerable properties and values on the custom element are used as the `props` passed to the React component.
1447+
- The React component is not rendered until the custom element is inserted into the page.
1448+
1449+
# We want to hear from you.
1450+
1451+
Come chat with us about open source in our Bitovi community [Discord](https://discord.gg/J7ejFsZnJ4).
1452+
1453+
See what we're up to by following us on [Twitter](https://twitter.com/bitovi).
1454+
1455+
=========================================
1456+
END OF @r2wc/react-to-web-component NOTICES AND INFORMATION
1457+
13271458
%% @shoelace-style/shoelace NOTICES AND INFORMATION BEGIN HERE
13281459
=========================================
13291460
Copyright (c) 2020 A Beautiful Site, LLC
@@ -2129,7 +2260,7 @@ END OF path-browserify NOTICES AND INFORMATION
21292260
=========================================
21302261
MIT License
21312262

2132-
Copyright (c) Facebook, Inc. and its affiliates.
2263+
Copyright (c) Meta Platforms, Inc. and affiliates.
21332264

21342265
Permission is hereby granted, free of charge, to any person obtaining a copy
21352266
of this software and associated documentation files (the "Software"), to deal
@@ -2156,7 +2287,7 @@ END OF react-dom NOTICES AND INFORMATION
21562287
=========================================
21572288
MIT License
21582289

2159-
Copyright (c) Facebook, Inc. and its affiliates.
2290+
Copyright (c) Meta Platforms, Inc. and affiliates.
21602291

21612292
Permission is hereby granted, free of charge, to any person obtaining a copy
21622293
of this software and associated documentation files (the "Software"), to deal

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20311,7 +20311,7 @@
2031120311
"vscode:prepublish": "pnpm run bundle"
2031220312
},
2031320313
"dependencies": {
20314-
"@gitkraken/gitkraken-components": "10.7.0",
20314+
"@gitkraken/gitkraken-components": "11.0.0-vnext.3",
2031520315
"@gitkraken/provider-apis": "0.26.2",
2031620316
"@gitkraken/shared-web-components": "0.1.1-rc.15",
2031720317
"@gk-nzaytsev/fast-string-truncated-width": "1.1.0",
@@ -20328,6 +20328,7 @@
2032820328
"@opentelemetry/resources": "1.30.1",
2032920329
"@opentelemetry/sdk-trace-base": "1.30.1",
2033020330
"@opentelemetry/semantic-conventions": "1.30.0",
20331+
"@r2wc/react-to-web-component": "^2.0.4",
2033120332
"@shoelace-style/shoelace": "2.20.0",
2033220333
"@vscode/codicons": "0.0.36",
2033320334
"billboard.js": "3.14.3",
@@ -20338,8 +20339,8 @@
2033820339
"node-fetch": "2.7.0",
2033920340
"os-browserify": "0.3.0",
2034020341
"path-browserify": "1.0.1",
20341-
"react": "16.8.4",
20342-
"react-dom": "16.8.4",
20342+
"react": "19.0.0",
20343+
"react-dom": "19.0.0",
2034320344
"signal-utils": "0.21.1",
2034420345
"slug": "10.0.0",
2034520346
"sortablejs": "1.15.0"
@@ -20352,8 +20353,8 @@
2035220353
"@twbs/fantasticon": "3.0.0",
2035320354
"@types/mocha": "10.0.10",
2035420355
"@types/node": "20.14.15",
20355-
"@types/react": "17.0.83",
20356-
"@types/react-dom": "17.0.25",
20356+
"@types/react": "19.0.6",
20357+
"@types/react-dom": "19.0.3",
2035720358
"@types/sinon": "17.0.4",
2035820359
"@types/slug": "5.0.9",
2035920360
"@types/sortablejs": "1.15.8",

0 commit comments

Comments
 (0)