@servicetitan/docs-uikit 22.20.0 → 23.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,8 +2,21 @@
2
2
  title: ESLint & Stylelint configurations
3
3
  ---
4
4
 
5
+ import Admonition from '@theme/Admonition';
6
+ import { VersionHistory, Changes } from '@site/src/components/version-history';
7
+
5
8
  `@servicetitan/eslint-config` and `@servicetitan/stylelint-config` packages contain core lint rule sets which should be used in ServiceTitan web projects.
6
9
 
10
+ <VersionHistory>
11
+ <Changes forVersion="23.0.0">
12
+ <Admonition type="caution">
13
+ Upgrades <code>@typescript-eslint/eslint-plugin</code> from version v5.x to v6. Because
14
+ every new major version of <code>typescript-eslint</code> includes improvements and
15
+ changes to existing rules, expect to see new lint errors in your project.
16
+ </Admonition>
17
+ </Changes>
18
+ </VersionHistory>
19
+
7
20
  ## Usage
8
21
 
9
22
  ### ESLint
@@ -4,6 +4,28 @@ title: React IoC
4
4
 
5
5
  `@servicetitan/react-ioc` is an implementation of [InversifyJS](https://github.com/inversify/InversifyJS) for react applications, it uses Context API of React 16 to manage containers.
6
6
 
7
+ import Admonition from '@theme/Admonition';
8
+ import { VersionHistory, Changes } from '@site/src/components/version-history';
9
+
10
+ <VersionHistory>
11
+ <Changes forVersion="v23.0.0">
12
+ <Admonition type="caution" title="Breaking changes">
13
+ <p>
14
+ Changed second argument of <code>provide</code> method to an object with
15
+ <code>loadingFallback</code> and <code>errorFallback</code> properties.
16
+ </p>
17
+ <p>
18
+ Renamed <code>fallback</code> property of the <code>Provider</code> component to{' '}
19
+ <code>loadingFallback</code> and added <code>errorFallback</code> property.
20
+ </p>
21
+ <p>
22
+ Removed ability to use <code>useValue</code> with <code>instances</code>.
23
+ </p>
24
+ </Admonition>
25
+ See <a href="https://github.com/servicetitan/uikit/releases/tag/v23.0.0">Release Notes</a>
26
+ </Changes>
27
+ </VersionHistory>
28
+
7
29
  ## Features
8
30
 
9
31
  - Supports hierarchical Dependency Injection
@@ -159,3 +181,45 @@ const App = provide({ singletons: [{ provide: LOGGER_TOKEN, useClass: Logger }]
159
181
  </ErrorBoundary>
160
182
  ));
161
183
  ```
184
+
185
+ #### Reusing a service
186
+
187
+ You can use the inherit option to reuse existing services that are already provided. In this case, service is only created if it is not already provided in a parent container.
188
+
189
+ ```tsx
190
+ class SomeStore {}
191
+
192
+ class SomeOtherStore {}
193
+
194
+ const App = provide({
195
+ singletons: [
196
+ { provide: SomeStore, useClass: SomeOtherStore, inherit: true },
197
+ { provide: SomeOtherStore, inherit: true },
198
+ ],
199
+ })(() => <div />);
200
+ ```
201
+
202
+ #### Service initialization
203
+
204
+ If a service inherits from Store, react-ioc calls the optional `initialize` method before rendering content and calls `dispose` after unbind. Also, you can pass a loading fallback that will be rendered during initialization.
205
+
206
+ ```tsx
207
+ import { Spinner } from '@servicetitan/design-system';
208
+ import { Store } from '@servicetitan/react-ioc';
209
+
210
+ class SomeStore extends Store {
211
+ constructor() {
212
+ super();
213
+ }
214
+
215
+ async initialize() {
216
+ // do some initialization
217
+ }
218
+
219
+ dispose() {
220
+ // implement disposal
221
+ }
222
+ }
223
+
224
+ const App = provide({ singletons: [SomeStore] }, { loadingFallback: <Spinner /> })(() => <div />);
225
+ ```
package/docs/startup.mdx CHANGED
@@ -5,7 +5,18 @@ title: Startup
5
5
  import Admonition from '@theme/Admonition';
6
6
  import { VersionHistory, Changes } from '@site/src/components/version-history';
7
7
 
8
+ [@servicetitan/startup](https://github.com/servicetitan/uikit/tree/master/packages/startup) is a command-line interface (CLI) to create multi-package Lerna projects with the support of TypeScript Project References and React. It offers a modern build setup with no configuration.
9
+
8
10
  <VersionHistory>
11
+ <Changes forVersion="23.0.0">
12
+ <Admonition type="caution">
13
+ Upgraded <code>Jest</code> from version v27.x to v29.
14
+ The largest breaking change is that v29 changed the default snapshot format.
15
+ To update old snapshots, run <code>npm run test -- --updateSnapshot</code>.
16
+ <br/>
17
+ See <a href="https://jest-archive-august-2023.netlify.app/docs/28.x/upgrading-to-jest28">Upgrading from v27 to v28</a> and <a href="https://jestjs.io/docs/upgrading-to-jest29">Upgrading from v28 to v29</a> for a list changes.
18
+ </Admonition>
19
+ </Changes>
9
20
  <Changes forVersion="22.20.0">
10
21
  Added <code>--experimental-bundlers</code> option to <code>build</code> command
11
22
  </Changes>
@@ -20,13 +31,13 @@ import { VersionHistory, Changes } from '@site/src/components/version-history';
20
31
  </Changes>
21
32
  <Changes forVersion="v22.16.0">
22
33
  <Admonition type="warning" title="Deprecated">
23
- This version contains a critical bug that was introduced in v22.15.0 and fixed in v22.17.0. Update to v22.17.0 or later as soon an possible.
34
+ This version contains a critical bug that was introduced in v22.15.0 and fixed in v22.17.0. Update to v22.17.0 or later as soon as possible.
24
35
  </Admonition>
25
36
  Added @servicetitan/testing-library to the <code>startup init</code> template
26
37
  </Changes>
27
38
  <Changes forVersion="v22.15.0">
28
39
  <Admonition type="warning" title="Deprecated">
29
- This version contains a critical bug that was introduced in v22.15.0 and fixed in v22.17.0. Update to v22.17.0 or later as soon an possible.
40
+ This version contains a critical bug that was introduced in v22.15.0 and fixed in v22.17.0. Update to v22.17.0 or later as soon as possible.
30
41
  </Admonition>
31
42
  Runs all commands with 8GB of memory by default.
32
43
  </Changes>
@@ -75,8 +86,6 @@ import { VersionHistory, Changes } from '@site/src/components/version-history';
75
86
 
76
87
  </VersionHistory>
77
88
 
78
- [@servicetitan/startup](https://github.com/servicetitan/uikit/tree/master/packages/startup) is a command-line interface (CLI) to create multi-package Lerna projects with the support of TypeScript Project References and React. It offers a modern build setup with no configuration.
79
-
80
89
  ## Why use this package?
81
90
 
82
91
  #### Less to learn
@@ -0,0 +1,230 @@
1
+ ---
2
+ title: Web Components
3
+ ---
4
+
5
+ import Admonition from '@theme/Admonition';
6
+ import { VersionHistory, Changes } from '@site/src/components/version-history';
7
+
8
+ <VersionHistory>
9
+ <Changes forVersion="v22.21.1">
10
+ Fixed a bug where the `Loader` component would error if an MFE's metadata.json contains a dependency of `web-components` with a version that is a semver range.
11
+ </Changes>
12
+ <Changes forVersion="v22.21.0">
13
+ <Admonition type="warning" title="Deprecated">
14
+ This version contains a critical bug that was introduced in v22.21.0 and fixed in v22.21.1. Update to v22.21.1 or later as soon as possible.
15
+ </Admonition>
16
+ Provided a more guaranteed check for an MFE's ability to re-render when passed MFE data changes.
17
+ Added context for MFEMetadata, which includes the shadowDom and portalShadowDom.
18
+ </Changes>
19
+ <Changes forVersion="v22.16.0">
20
+ Fixed Loader memory leaks.
21
+ </Changes>
22
+ <Changes forVersion="v22.12.0">
23
+ Support updating props passed to MFE via Loader.
24
+ Added context for accessing MFEData.
25
+ </Changes>
26
+ <Changes forVersion="v22.7.0">
27
+ Fixed disposing MFE when parent element has moved in DOM.
28
+ </Changes>
29
+ <Changes forVersion="v22.1.0">
30
+ Added EventBus support for sending payload with events.
31
+ </Changes>
32
+ </VersionHistory>
33
+
34
+ `@servicetitan/web-components` is used to build, register, and load Microfrontends (MFEs) into host applications.
35
+
36
+ ### Loader
37
+
38
+ The `Loader` component is used to load an MFE into a host application. See [Microfrontends (MFEs)](/docs/frontend/micro-frontends) for more information about how MFEs are injected.
39
+
40
+ #### Usage
41
+
42
+ ```tsx
43
+ ...
44
+
45
+ import { Loader } from '@servicetitan/web-components';
46
+
47
+ ...
48
+
49
+ export const Foo: React.FC = () => {
50
+ ...
51
+ return (
52
+ ...
53
+ <Loader src="https://unpkg.servicetitan.com/{package_name}@{semver_range}" />
54
+ ...
55
+ );
56
+ };
57
+ ```
58
+
59
+ #### Props
60
+
61
+ | Name | Description |
62
+ | :---------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------- |
63
+ | `src` | path to an MFE root folder |
64
+ | `fallbackSrc` | optional alternative path to an MFE root folder (if request for src returns error) |
65
+ | `data` | additional data passed to an MFE as an object, where values are serializable, and preferably memoized ([see below](#passing-data-from-host-to-mfe)) |
66
+ | `basename` | prefix for all MFE URLs, you should inject it by the `BASENAME_TOKEN` and pass to the appropriate router property |
67
+ | `loadingFallback` | optional JSX element to render when the MFE is loading |
68
+ | `errorFallback` | optional JSX element to render when the MFE fails to load |
69
+ | `className` | additional CSS classes for the MFE web component element |
70
+
71
+ #### Passing data from Host to MFE
72
+
73
+ You can pass data from your host application to the MFE using the `data` prop of the `<Loader>` component. The data should be an object where keys are string and the values are any serializable data.
74
+
75
+ We recommend memoizing your data before passing it to the `<Loader>` component in order to avoid potential performance issues with re-rendering and re-serializing that data.
76
+
77
+ As a reminder, it should be clearly discouraged (or sometimes prohibited) to share data between the host and MFEs. MFEs should load the data they need instead of relying on the host to pass it, when possible.
78
+
79
+ :::note
80
+ Before version v22.12.0 of `@servicetitan/web-components` package, the `data` prop only supported data of type `Record<string string>`
81
+ :::
82
+
83
+ ```tsx title="Host Application"
84
+ import { useMemo } from 'react';
85
+ import { Loader } from '@servicetitan/web-components';
86
+ ...
87
+ export const HostApp = () => {
88
+ ...
89
+ const data = useMemo(() => {
90
+ foo: ['one', 'two', 'three'],
91
+ bar: dependency,
92
+ }, [dependency]);
93
+ return (
94
+ ...
95
+ <Loader
96
+ src="https://unpkg.servicetitan.com/{package_name}@{semver_range}"
97
+ data={data}
98
+ />
99
+ ...
100
+ );
101
+ };
102
+ ```
103
+
104
+ Data can be accessed within the MFE using props.
105
+
106
+ ```tsx title="MFE Application"
107
+ interface MFEAppData {
108
+ foo: string[];
109
+ }
110
+
111
+ export const MFEApp = (props: MFEAppData) => {
112
+ const { foo } = props;
113
+ };
114
+ ```
115
+
116
+ Data must be serializable, due to the nature of how it is passed through a web component to reach your MFE component. This means that you cannot pass functions or other non-serializable data types.
117
+
118
+ ```tsx title="Host Application"
119
+ ...
120
+ <Loader data={{ date: new Date("2020-05-12T23:50:21.817Z") }} />
121
+ ```
122
+
123
+ ```tsx title="MFE Application"
124
+ ...
125
+ export const MFEApp = (props: MyType) => {
126
+ props.date; // '2020-05-12T23:50:21.817Z'
127
+ };
128
+ // RESULTS IN A STRING, NOT A DATE OBJECT
129
+ ```
130
+
131
+ As of version v22.12.0 of `@servicetitan/web-components`, if data passed into the `data` prop of `<Loader>` changes during runtime, the data will re-render within your MFE component where appropriate. Previous versions would re-mounting the entire MFE application when data changed.
132
+
133
+ ### useMFEDataContext
134
+
135
+ Data can be also be accessed within the MFE using the `useMFEDataContext` hook. You must provide the type of the data you expect to recieve.
136
+
137
+ ```tsx
138
+ import { useMFEDataContext } from '@servicetitan/web-components';
139
+ ...
140
+ interface MFEAppData {
141
+ bar: string;
142
+ }
143
+
144
+ export const MFEApp = () => {
145
+ const { bar } = useMFEDataContext<MFEAppData>();
146
+ };
147
+ ```
148
+
149
+ ### useMFEMetadataContext
150
+
151
+ Some metadata is also provided to MFEs, and is accessible through the `useMFEMetadataContext` hook.
152
+
153
+ ```tsx
154
+ import { useMFEMetadataContext } from '@servicetitan/web-components';
155
+ ...
156
+ export const MFEApp = () => {
157
+ const { shadowRoot, portalShadowRoot } = useMFEMetadataContext();
158
+ };
159
+ ```
160
+
161
+ The following metadata about an MFE is available from `useMFEMetadataContext` hook.
162
+
163
+ | Name | Type | Description |
164
+ | :----------------- | :--------- | :------------------------------------------------------------------------------------------------------------------------------ |
165
+ | `shadowRoot` | ShadowRoot | ShadowRoot root node of which the MFE is rendered within |
166
+ | `portalShadowRoot` | ShadowRoot | ShadowRoot root node of the "portal" tied to the MFE, which is used to render elements in a div directly under the body element |
167
+
168
+ ### EVENT_BUS_TOKEN - Emitting Events to MFEs
169
+
170
+ Sometimes you may need to send events from the host to the MFE or the other way around, the EventBus ([mitt](https://github.com/developit/mitt) is used under the hood) should cover these needs. Starting <code>v22.1.0</code> you can also send payload.
171
+
172
+ #### Subscription
173
+
174
+ ```tsx title="MFE"
175
+ ...
176
+
177
+ import { useOptionalDependencies } from '@servicetitan/react-ioc';
178
+ import { EVENT_BUS_TOKEN } from '@servicetitan/web-components';
179
+
180
+ ...
181
+
182
+ export const Foo: FC = () => {
183
+ const [eventBus] = useOptionalDependencies(EVENT_BUS_TOKEN);
184
+
185
+ useEffect(() => {
186
+ const myCustomEventHandler = () => {
187
+ console.log('`my-custom-event` has been fired!');
188
+ };
189
+ eventBus?.on('my-custom-event', myCustomEventHandler);
190
+
191
+ return () => {
192
+ eventBus?.off('my-custom-event', myCustomEventHandler);
193
+ };
194
+ }, []);
195
+
196
+ ...
197
+ };
198
+ ```
199
+
200
+ #### Emitting
201
+
202
+ ```tsx title="host"
203
+ ...
204
+
205
+ import { Loader, LoaderRef } from '@servicetitan/web-components';
206
+
207
+ ...
208
+
209
+ export const Bar: FC = () => {
210
+ const ref = useRef<LoaderRef>(null);
211
+
212
+ useEffect(() => {
213
+ const id = setInterval(() => {
214
+ ref.current?.emit('my-custom-event');
215
+ }, 1000);
216
+
217
+ return () => {
218
+ clearInterval(id);
219
+ };
220
+ }, []);
221
+
222
+ ...
223
+
224
+ return (
225
+ ...
226
+ <Loader ref={ref} src="https://unpkg.servicetitan.com/@servicetitan/examples" />
227
+ ...
228
+ );
229
+ };
230
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/docs-uikit",
3
- "version": "22.20.0",
3
+ "version": "23.0.0",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,5 +16,5 @@
16
16
  "cli": {
17
17
  "webpack": false
18
18
  },
19
- "gitHead": "ec4a9c96e9927170b725720de33e97efed24c724"
19
+ "gitHead": "45876ed36415ad78d3ec4ef3783d6df1430504d3"
20
20
  }