Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable live code inclusion for consuming applications #2642

Merged
merged 19 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
24e7d04
feat: enable tree shaking
gavinbarron Jul 26, 2023
5d7b755
attempting to move to functional registration for components
gavinbarron Jul 27, 2023
9dc0e37
moved to generating a single file per react wrpper component and a ba…
gavinbarron Jul 28, 2023
7ab67b3
fixing incorrect register functions
gavinbarron Jul 28, 2023
f5f4684
merge from main
gavinbarron Jul 28, 2023
7032797
clean up yarn lock
gavinbarron Jul 28, 2023
e919630
adding register calls to tests
gavinbarron Jul 29, 2023
c907641
fixing component registration and mock set up to fix tests
gavinbarron Jul 29, 2023
ac41815
removing unused customElement imports
gavinbarron Oct 5, 2023
5c50d22
fixing render problem when given and surname are null on personType o…
gavinbarron Oct 5, 2023
f29541b
move mgt-components to module type es2020 for dynamic imports
gavinbarron Oct 5, 2023
624e690
refactored to only lazy load the person-card code when opening the fl…
gavinbarron Oct 6, 2023
7418447
merge from origin/main
gavinbarron Oct 9, 2023
b153db3
update list of components registered by registerMgtComponents
gavinbarron Oct 10, 2023
20bb265
move sample app to use lazy + Suspense to chunk up component usage
gavinbarron Oct 10, 2023
2ac9e84
Merge remote-tracking branch 'origin/main' into next/enable-tree-shaking
gavinbarron Oct 10, 2023
5d2ae00
Merge remote-tracking branch 'origin/main' into next/enable-tree-shaking
gavinbarron Oct 20, 2023
d405e0b
adding documentation for tree shaking support
gavinbarron Oct 20, 2023
31b876c
making registration of custom elements for providers use a register f…
gavinbarron Oct 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions cem-plugins/mgt-tag-plugin.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { resolveModuleOrPackageSpecifier } from '@custom-elements-manifest/analyzer/src/utils/index.js';
export default function mgtTagPlugin() {
function isCustomRegistration(node) {
// this would be better if we tested arg[0] for a string literal
return node?.expression?.getText() === 'registerComponent' && node.arguments.length >= 2;
}
// Write a custom plugin
return {
// Make sure to always give your plugins a name, this helps when debugging
name: 'mgt-tag-plugin',
// Runs for all modules in a project, before continuing to the analyzePhase
collectPhase({ ts, node, context }) {},
// Runs for each module
analyzePhase({ ts: TS, node, moduleDoc, context }) {
if (isCustomRegistration(node)) {
//do things...
if (context.dev) console.log(node);

var elementClass = node.arguments[1].text;
var elementTag = node.arguments[0].text;
const definitionDoc = {
kind: 'custom-element-definition',
name: elementTag,
declaration: {
name: elementClass,
...resolveModuleOrPackageSpecifier(moduleDoc, context, elementClass)
}
};
moduleDoc.exports = [...(moduleDoc.exports || []), definitionDoc];
}
},
// Runs for each module, after analyzing, all information about your module should now be available
moduleLinkPhase({ moduleDoc, context }) {},
// Runs after modules have been parsed and after post-processing
packageLinkPhase({ customElementsManifest, context }) {}
};
}
5 changes: 5 additions & 0 deletions custom-elements-manifest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import mgtTagPlugin from './cem-plugins/mgt-tag-plugin.mjs';

export default {
plugins: [mgtTagPlugin()]
};
8 changes: 6 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"packages": ["packages/*", "packages/providers/*", "samples/react-contoso"],
"packages": [
"packages/*",
"packages/providers/*",
"samples/*"
],
"npmClient": "yarn",
"version": "independent"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"packages": [
"packages/*",
"packages/providers/*",
"samples/react-contoso"
"samples/*"
],
"nohoist": [
"**/@microsoft/sp-office-ui-fabric-core**",
Expand All @@ -16,7 +16,7 @@
},
"scripts": {
"init": "yarn && yarn build",
"analyze": "custom-elements-manifest analyze --litelement --globs \"./packages/*/src/**/*.ts\"",
"analyze": "custom-elements-manifest analyze --globs \"./packages/*/src/**/*.ts\"",
musale marked this conversation as resolved.
Show resolved Hide resolved
"build": "npm run prettier:check && npm run clean && lerna run build --scope @microsoft/*",
"build:compile": "npm run prettier:check && npm run clean && lerna run build:compile --scope @microsoft/*",
"build:mgt": "cd ./packages/mgt && npm run build",
Expand Down
6 changes: 5 additions & 1 deletion packages/mgt-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
"sass": "gulp sass --cwd .",
"sass:watch": "gulp watchSass --cwd ."
},
"sideEffects": [
"./dist/es6/index.js",
"./src/index.ts"
],
"dependencies": {
"@microsoft/mgt-element": "*",
"@microsoft/microsoft-graph-client": "3.0.2",
Expand All @@ -46,4 +50,4 @@
"publishConfig": {
"directory": "dist"
}
}
}
4 changes: 4 additions & 0 deletions packages/mgt-components/src/components/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import './mgt-messages/mgt-messages';
import './mgt-organization/mgt-organization';
import './mgt-profile/mgt-profile';
import './mgt-theme-toggle/mgt-theme-toggle';
import './sub-components/mgt-spinner/mgt-spinner';

export * from './mgt-agenda/mgt-agenda';
export * from './mgt-file/mgt-file';
Expand All @@ -47,3 +48,6 @@ export * from './mgt-messages/mgt-messages';
export * from './mgt-organization/mgt-organization';
export * from './mgt-profile/mgt-profile';
export * from './mgt-theme-toggle/mgt-theme-toggle';
export * from './sub-components/mgt-spinner/mgt-spinner';
// include preview components here for ease of import into mgt-react
export * from './preview';
16 changes: 12 additions & 4 deletions packages/mgt-components/src/components/mgt-agenda/mgt-agenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
import { html, TemplateResult } from 'lit';
import { property } from 'lit/decorators.js';
import { Providers, ProviderState, MgtTemplatedComponent, mgtHtml, customElement } from '@microsoft/mgt-element';
import { Providers, ProviderState, MgtTemplatedComponent, mgtHtml } from '@microsoft/mgt-element';
import '../../styles/style-helper';
import '../mgt-person/mgt-person';
import { styles } from './mgt-agenda-css';
import { getEventsPageIterator, getEventsQueryPageIterator } from './mgt-agenda.graph';
import { SvgIcon, getSvg } from '../../utils/SvgHelper';
import { MgtPeople } from '../mgt-people/mgt-people';
import { MgtPeople, registerMgtPeopleComponent } from '../mgt-people/mgt-people';
import { registerFluentComponents } from '../../utils/FluentComponents';
import { fluentCard } from '@fluentui/web-components';
import { classMap } from 'lit/directives/class-map.js';
registerFluentComponents(fluentCard);
import { registerComponent } from '../registerComponent';

/**
* Web Component which represents events in a user or group calendar.
Expand All @@ -45,7 +45,15 @@ registerFluentComponents(fluentCard);
* @cssprop --event-location-color - {Color} Event location color
* @cssprop --event-attendees-color - {Color} Event attendees color
*/
@customElement('agenda')

export const registerMgtAgendaComponent = () => {
registerFluentComponents(fluentCard);
// register dependent components
registerMgtPeopleComponent();
// register self
registerComponent('agenda', MgtAgenda);
};

export class MgtAgenda extends MgtTemplatedComponent {
/**
* Array of styles to apply to the element. The styles should be defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

import { User } from '@microsoft/microsoft-graph-types';
import { html, TemplateResult } from 'lit';
import { TeamsHelper, customElement } from '@microsoft/mgt-element';
import { TeamsHelper } from '@microsoft/mgt-element';
import { classMap } from 'lit/directives/class-map.js';

import { getEmailFromGraphEntity } from '../../graph/graph.people';
import { BasePersonCardSection } from '../BasePersonCardSection';
import { styles } from './mgt-contact-css';
import { getSvg, SvgIcon } from '../../utils/SvgHelper';
import { strings } from './strings';
import { registerComponent } from '../registerComponent';

/**
* Represents a contact part and its metadata
Expand All @@ -31,15 +32,17 @@ interface IContactPart {

type Protocol = 'mailto:' | 'tel:';

export const registerMgtContactComponent = () => {
registerComponent('contact', MgtContact);
};

/**
* The contact details subsection of the person card
*
* @export
* @class MgtContact
* @extends {MgtTemplatedComponent}
*/
@customElement('contact')
// @customElement('mgt-contact')
export class MgtContact extends BasePersonCardSection {
/**
* Array of styles to apply to the element. The styles should be defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
GraphPageIterator,
Providers,
ProviderState,
customElement,
mgtHtml,
MgtTemplatedComponent
} from '@microsoft/mgt-element';
Expand Down Expand Up @@ -42,14 +41,21 @@ import { getSvg, SvgIcon } from '../../utils/SvgHelper';
import { OfficeGraphInsightString, ViewType } from '../../graph/types';
import { styles } from './mgt-file-list-css';
import { strings } from './strings';
import { MgtFile } from '../mgt-file/mgt-file';
import { MgtFileUploadConfig } from './mgt-file-upload/mgt-file-upload';
import { MgtFile, registerMgtFileComponent } from '../mgt-file/mgt-file';
import { MgtFileUploadConfig, registerMgtFileUploadComponent } from './mgt-file-upload/mgt-file-upload';

import { fluentProgressRing } from '@fluentui/web-components';
import { registerFluentComponents } from '../../utils/FluentComponents';
import { CardSection } from '../BasePersonCardSection';
import { registerComponent } from '../registerComponent';

registerFluentComponents(fluentProgressRing);
export const registerMgtFileListComponent = () => {
registerFluentComponents(fluentProgressRing);

registerMgtFileComponent();
registerMgtFileUploadComponent();
registerComponent('file-list', MgtFileList);
};

/**
* The File List component displays a list of multiple folders and files by
Expand Down Expand Up @@ -77,8 +83,6 @@ registerFluentComponents(fluentProgressRing);
* @cssprop --show-more-button-border-bottom-left-radius - {String} the "show more" button bottom left border radius. Default value is 8px;
* @cssprop --progress-ring-size -{String} Progress ring height and width. Default value is 24px.
*/

@customElement('file-list')
export class MgtFileList extends MgtTemplatedComponent implements CardSection {
@state() private _isCompact = false;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import { getSvg, SvgIcon } from '../../../utils/SvgHelper';
import { formatBytes } from '../../../utils/Utils';
import { styles } from './mgt-file-upload-css';
import { strings } from './strings';

registerFluentComponents(fluentProgress, fluentButton, fluentCheckbox, fluentDialog);
import { registerComponent } from '../../registerComponent';
import { registerMgtFileComponent } from '../../mgt-file/mgt-file';

/**
* Simple union type for file system entry and directory entry types
Expand Down Expand Up @@ -236,6 +236,13 @@ interface FileWithPath extends File {
fullPath: string;
}

export const registerMgtFileUploadComponent = () => {
registerFluentComponents(fluentProgress, fluentButton, fluentCheckbox, fluentDialog);

registerMgtFileComponent();
registerComponent('file-upload', MgtFileUpload);
};

/**
* A component to upload files to OneDrive or SharePoint Sites
*
Expand Down Expand Up @@ -264,8 +271,6 @@ interface FileWithPath extends File {
* @cssprop --file-upload-dialog-height - {String} the height of the file upload dialog box. Default value is auto.
* @cssprop --file-upload-dialog-padding - {String} the padding of the file upload dialog box. Default value is 24px;
*/

@customElement('file-upload')
export class MgtFileUpload extends MgtBaseComponent {
/**
* Array of styles to apply to the element. The styles should be defined
Expand Down
5 changes: 3 additions & 2 deletions packages/mgt-components/src/components/mgt-file/mgt-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import { OfficeGraphInsightString, ViewType } from '../../graph/types';
import { getFileTypeIconUriByExtension } from '../../styles/fluent-icons';
import { getSvg, SvgIcon } from '../../utils/SvgHelper';
import { strings } from './strings';
import { registerComponent } from '../registerComponent';

export const registerMgtFileComponent = () => registerComponent('file', MgtFile);

/**
* The File component is used to represent an individual file/folder from OneDrive or SharePoint by displaying information such as the file/folder name, an icon indicating the file type, and other properties such as the author, last modified date, or other details selected by the developer.
Expand Down Expand Up @@ -62,8 +65,6 @@ import { strings } from './strings';
* @cssprop --file-line3-color - {Color} the third line text color.
* @cssprop --file-line3-text-transform - {String} the third line text text transform. Default value is 400.
*/

@customElement('file')
export class MgtFile extends MgtTemplatedComponent {
/**
* Array of styles to apply to the element. The styles should be defined
Expand Down
12 changes: 8 additions & 4 deletions packages/mgt-components/src/components/mgt-get/mgt-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ import {
Providers,
ProviderState,
customElement,
CollectionResponse
CollectionResponse,
IGraph
} from '@microsoft/mgt-element';

import { getPhotoForResource } from '../../graph/graph.photos';
import { getDocumentThumbnail } from '../../graph/graph.files';
import { schemas } from '../../graph/cacheStores';
import { CacheResponse } from '../CacheResponse';
import { Entity } from '@microsoft/microsoft-graph-types';
import { GraphRequest } from '@microsoft/microsoft-graph-client';
import { registerComponent } from '../registerComponent';

/**
* Simple holder type for an image
Expand Down Expand Up @@ -79,6 +82,8 @@ export type DataChangedDetail = {
error?: object;
};

export const registerMgtGetComponent = () => registerComponent('get', MgtGet);

/**
* Custom element for making Microsoft Graph get queries
*
Expand All @@ -88,7 +93,6 @@ export type DataChangedDetail = {
* @class mgt-get
* @extends {MgtTemplatedComponent}
*/
@customElement('get')
export class MgtGet extends MgtTemplatedComponent {
/**
* The resource to get
Expand Down Expand Up @@ -355,8 +359,8 @@ export class MgtGet extends MgtTemplatedComponent {
isDeltaLink = new URL(uri, 'https://graph.microsoft.com').pathname.endsWith('delta');
}

const graph = provider.graph.forComponent(this);
let request = graph.api(uri).version(this.version);
const graph: IGraph = provider.graph.forComponent(this);
let request: GraphRequest = graph.api(uri).version(this.version);

if (this.scopes?.length) {
request = request.middlewareOptions(prepScopes(...this.scopes));
Expand Down
24 changes: 12 additions & 12 deletions packages/mgt-components/src/components/mgt-login/mgt-login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,12 @@ import { CSSResult, html, TemplateResult } from 'lit';
import { property, state } from 'lit/decorators.js';
import { classMap } from 'lit/directives/class-map.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import {
Providers,
ProviderState,
MgtTemplatedComponent,
IProviderAccount,
mgtHtml,
customElement
} from '@microsoft/mgt-element';
import { Providers, ProviderState, MgtTemplatedComponent, IProviderAccount, mgtHtml } from '@microsoft/mgt-element';

import { AvatarSize, IDynamicPerson, ViewType } from '../../graph/types';
import { MgtFlyout } from '../sub-components/mgt-flyout/mgt-flyout';
import { MgtFlyout, registerMgtFlyoutComponent } from '../sub-components/mgt-flyout/mgt-flyout';
import { getUserWithPhoto } from '../../graph/graph.userWithPhoto';
import { MgtPerson } from '../mgt-person/mgt-person';
import { MgtPerson, registerMgtPersonComponent } from '../mgt-person/mgt-person';
import { PersonViewType } from '../mgt-person/mgt-person-types';

import { getSvg, SvgIcon } from '../../utils/SvgHelper';
Expand All @@ -33,7 +26,7 @@ import '../../styles/style-helper';

import { fluentListbox, fluentProgressRing, fluentButton, fluentCard } from '@fluentui/web-components';
import { registerFluentComponents } from '../../utils/FluentComponents';
registerFluentComponents(fluentListbox, fluentProgressRing, fluentButton, fluentCard);
import { registerComponent } from '../registerComponent';

/**
* loginViewType describes the enum strings that can be passed in to determine
Expand All @@ -46,6 +39,14 @@ type PersonViewConfig = {
avatarSize: AvatarSize;
};

export const registerMgtLoginComponent = () => {
registerFluentComponents(fluentListbox, fluentProgressRing, fluentButton, fluentCard);

registerMgtFlyoutComponent();
registerMgtPersonComponent();
registerComponent('login', MgtLogin);
};

/**
* Web component button and flyout control to facilitate Microsoft identity platform authentication
*
Expand Down Expand Up @@ -82,7 +83,6 @@ type PersonViewConfig = {
* @cssprop --login-account-item-hover-bg-color - {Color} the background color of the account item on hover.
* @cssprop --login-flyout-command-text-color - {Color} the color for the text of the flyout command button.
*/
@customElement('login')
export class MgtLogin extends MgtTemplatedComponent {
/**
* Array of styles to apply to the element. The styles should be defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { getSvg, SvgIcon } from '../../utils/SvgHelper';
import { getRelativeDisplayDate } from '../../utils/Utils';
import { styles } from './mgt-messages-css';
import { strings } from './strings';
import { customElement } from '@microsoft/mgt-element';
import { registerComponent } from '../registerComponent';

export const registerMgtMessagesComponent = () => registerComponent('messages', MgtMessages);

/**
* The email messages subsection of the person card
Expand All @@ -22,7 +24,6 @@ import { customElement } from '@microsoft/mgt-element';
* @class MgtMessages
* @extends {MgtTemplatedComponent}
*/
@customElement('messages')
export class MgtMessages extends BasePersonCardSection {
/**
* Array of styles to apply to the element. The styles should be defined
Expand Down
Loading
Loading