Skip to content

Commit 83f911b

Browse files
Migrate base component and provider structures to mgt-element package (#594)
* Migrated Providers and IProvider to mgt-element * Migrated baseComponent to mgt-element * Migrated template helper to mgt-element * Migrated templatedComponent to mgt-element * Updated tsconfigs to fix debugging * Migrated Providers and IProvider to mgt-element * Migrated baseComponent to mgt-element * Migrated template helper to mgt-element * Migrated templatedComponent to mgt-element * Updated tsconfigs to fix debugging * Merged react work with base-component work * Updated readme with samples guidance * Added preview doc for mgt-element * Fixed samples * Fixed storybook * Fixed typo and removed console log * Update generated react.ts Co-authored-by: Nikola Metulev <[email protected]>
1 parent 43fc64c commit 83f911b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+279
-259
lines changed

.storybook/addons/signInAddon/signInAddon.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import addons, { makeDecorator } from '@storybook/addons';
2-
import { Providers } from '../../../packages/mgt/dist/es6/Providers';
3-
import { ProviderState } from '../../../packages/mgt/dist/es6/providers/IProvider';
2+
import { Providers } from '../../../packages/mgt-element/dist/providers/Providers';
3+
import { ProviderState } from '../../../packages/mgt-element/dist/providers/IProvider';
44
import { MsalProvider } from '../../../packages/mgt/dist/es6/providers/MsalProvider';
55
import { MockProvider } from '../../../packages/mgt/dist/es6/mock/MockProvider';
66
import { CLIENTID, SETPROVIDER_EVENT, GETPROVIDER_EVENT } from '../../env';

.storybook/manager.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import { addons, types } from '@storybook/addons';
1010
import { STORIES_CONFIGURED, STORY_MISSING } from '@storybook/core-events';
1111
import { AddonPanel } from '@storybook/components';
1212
import { useParameter, useChannel } from '@storybook/api';
13-
import { Providers, MsalProvider, LoginType } from '../packages/mgt/dist/commonjs';
13+
import { MsalProvider } from '../packages/mgt/dist/commonjs';
14+
import { Providers, LoginType } from '../packages/mgt-element/dist';
1415
import { CLIENTID, GETPROVIDER_EVENT, SETPROVIDER_EVENT } from './env';
1516

1617
const PARAM_KEY = 'signInAddon';

docs/preview/mgt-element.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# @microsoft/mgt-element
2+
3+
Going forward in version 2, Microsoft Graph Toolkit will be broken up into multiple packages. This allows developers to take what they need from the toolkit and avoid any unnecessary parts.
4+
5+
`@microsft/mgt-element` is the first of these packages. It contains the low level interfaces and base classes that all MGT components and providers are built upon.
6+
7+
The most notable change for consuming apps is the relocation of the `Providers` class. Access to the global provider instance is managed through `Providers`, so any module references will need to import from `@microsoft/mgt-element` instead.
8+
9+
```ts
10+
<script type="module">
11+
import { MsalProvider } from '@microsoft/mgt';
12+
import { IGraph, IProvider, Providers } from '@microsoft/mgt-element'
13+
14+
const provider: IProvider = new MsalProvider({ clientId: '[CLIENT-ID]' });
15+
Providers.globalProvider = provider;
16+
17+
const graph: IGraph = provider.graph;
18+
const me: any = await graph.api('/me').get();
19+
</script>
20+
```

packages/mgt/src/components/baseComponent.ts renamed to packages/mgt-element/src/components/baseComponent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* -------------------------------------------------------------------------------------------
66
*/
77

8-
import { LitElement, property, PropertyValues } from 'lit-element';
9-
import { Providers } from '../Providers';
8+
import { LitElement, PropertyValues } from 'lit-element';
9+
import { Providers } from '../providers/Providers';
1010

1111
/**
1212
* Defines media query based on component width
@@ -64,7 +64,7 @@ export abstract class MgtBaseComponent extends LitElement {
6464
* Gets the ComponentMediaQuery of the component
6565
*
6666
* @readonly
67-
* @type {ComponentMediaQuery}
67+
* @type {MgtElement.ComponentMediaQuery}
6868
* @memberof MgtBaseComponent
6969
*/
7070
public get mediaQuery(): ComponentMediaQuery {

packages/mgt/src/components/templatedComponent.ts renamed to packages/mgt-element/src/components/templatedComponent.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
*/
77

88
import { html, PropertyValues } from 'lit-element';
9-
import { TemplateContext } from '../graph/types';
10-
import { equals } from '../utils/Utils';
9+
import { TemplateContext } from '../utils/TemplateContext';
10+
import { equals } from '../utils/equals';
1111
import { MgtBaseComponent } from './baseComponent';
12-
import { TemplateHelper } from './templateHelper';
12+
import { TemplateHelper } from '../utils/TemplateHelper';
1313

1414
/**
1515
* Lookup for rendered component templates and contexts by slot name.
@@ -39,7 +39,7 @@ export abstract class MgtTemplatedComponent extends MgtBaseComponent {
3939
/**
4040
* Collection of functions to be used in template binding
4141
*
42-
* @type {TemplateContext}
42+
* @type {MgtElement.TemplateContext}
4343
* @memberof MgtTemplatedComponent
4444
* @deprecated since 1.2 - use templateContext instead
4545
*/
@@ -49,7 +49,7 @@ export abstract class MgtTemplatedComponent extends MgtBaseComponent {
4949
* Additional data context to be used in template binding
5050
* Use this to add event listeners or value converters
5151
*
52-
* @type {TemplateContext}
52+
* @type {MgtElement.TemplateContext}
5353
* @memberof MgtTemplatedComponent
5454
*/
5555
public templateContext: TemplateContext;

packages/mgt-element/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@
77

88
export * from './IBatch';
99
export * from './IGraph';
10+
export * from './components/baseComponent';
11+
export * from './components/templatedComponent';
12+
export * from './providers/IProvider';
13+
export * from './providers/Providers';
14+
export * from './utils/EventDispatcher';
15+
export * from './utils/TemplateContext';
16+
export * from './utils/TemplateHelper';
17+
export * from './utils/equals';

packages/mgt/src/providers/IProvider.ts renamed to packages/mgt-element/src/providers/IProvider.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
import { AuthenticationProvider } from '@microsoft/microsoft-graph-client/lib/es/IAuthenticationProvider';
99
import { AuthenticationProviderOptions } from '@microsoft/microsoft-graph-client/lib/es/IAuthenticationProviderOptions';
10-
import { Graph } from '../Graph';
10+
import { IGraph } from '../IGraph';
1111
import { EventDispatcher, EventHandler } from '../utils/EventDispatcher';
12+
1213
/**
1314
* Provider Type to be extended for implmenting new providers
1415
*
@@ -24,7 +25,7 @@ export abstract class IProvider implements AuthenticationProvider {
2425
* @type {Graph}
2526
* @memberof IProvider
2627
*/
27-
public graph: Graph;
28+
public graph: IGraph;
2829
private _state: ProviderState;
2930
private _loginChangedDispatcher = new EventDispatcher<LoginChangedEvent>();
3031
/**

packages/mgt/src/Providers.ts renamed to packages/mgt-element/src/providers/Providers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
* -------------------------------------------------------------------------------------------
66
*/
77

8-
import { IProvider } from './providers/IProvider';
9-
import { EventDispatcher, EventHandler } from './utils/EventDispatcher';
8+
import { IProvider } from './IProvider';
9+
import { EventDispatcher, EventHandler } from '../utils/EventDispatcher';
10+
1011
/**
1112
* Provides implementation for acquiring the necessary access token for calling the Microsoft Graph APIs.
1213
*
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* -------------------------------------------------------------------------------------------
3+
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
4+
* See License in the project root for license information.
5+
* -------------------------------------------------------------------------------------------
6+
*/
7+
8+
/**
9+
* Template context object
10+
*/
11+
export interface TemplateContext {
12+
[prop: string]: any;
13+
}

0 commit comments

Comments
 (0)