Added Angular Elements sample (#523)

This commit is contained in:
Waldek Mastykarz 2018-06-01 15:52:26 +02:00 committed by GitHub
parent e770ade42f
commit 4385260f73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 19346 additions and 0 deletions

View File

@ -0,0 +1,55 @@
# Angular Elements in SharePoint Framework
## Summary
Set of sample web parts illustrating how to use Angular Elements in the SharePoint Framework.
## Used SharePoint Framework Version
![drop](https://img.shields.io/badge/drop-1.4.1-green.svg)
## Applies to
* [SharePoint Framework](http://dev.office.com/sharepoint/docs/spfx/sharepoint-framework-overview)
* [Office 365 developer tenant](http://dev.office.com/sharepoint/docs/spfx/set-up-your-developer-tenant)
## Solution
Solution|Author(s)
--------|---------
angularelements-helloworld|Waldek Mastykarz (MVP, Rencore, @waldekm), Sébastien Levert (MVP, Valo, @sebastienlevert)
## Version history
Version|Date|Comments
-------|----|--------
1.0|June 1, 2018|Initial release
## Disclaimer
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
---
## Minimal Path to Awesome
* clone this repo
* in the command line run:
* `npm i`
* `gulp serve`
## Features
This sample contains a set of web parts that illustrate using Angular Elements in the SharePoint Framework.
This web part illustrates the following concepts on top of the SharePoint Framework:
* adding Angular Elements to a no-framework SharePoint Framework project
* bootstrapping Angular Elements inside a SharePoint Framework web part
* extending the building configuration to build Angular Elements
* checking if the particular web component has already been registered to avoid conflicts
* passing web part configuration to Angular Elements and reacting to configuration changes
* calling the SharePoint REST API from an Angular Element using the native Angular HttpClient
* calling the Microsoft Graph from an Angular Element using the SharePoint Framework MSGraphClient
* calling the SharePoint REST API from an Angular Element using PnPjs
* calling the Microsoft Graph from an Angular Element using PnPjs
<img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/angularelements-helloworld" />

View File

@ -0,0 +1,40 @@
{
"$schema": "https://dev.office.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"angular-web-parts": {
"components": [
{
"entrypoint": "./lib/webparts/helloAngular/HelloAngularWebPart.js",
"manifest": "./src/webparts/helloAngular/HelloAngularWebPart.manifest.json"
},
{
"entrypoint": "./lib/webparts/helloSharePoint/HelloSharePointWebPart.js",
"manifest": "./src/webparts/helloSharePoint/HelloSharePointWebPart.manifest.json"
},
{
"entrypoint": "./lib/webparts/helloGraph/HelloGraphWebPart.js",
"manifest": "./src/webparts/helloGraph/HelloGraphWebPart.manifest.json"
},
{
"entrypoint": "./lib/webparts/helloPnPjsSharePoint/HelloPnPjsSharePointWebPart.js",
"manifest": "./src/webparts/helloPnPjsSharePoint/HelloPnPjsSharePointWebPart.manifest.json"
},
{
"entrypoint": "./lib/webparts/helloPnPjsGraph/HelloPnPjsGraphWebPart.js",
"manifest": "./src/webparts/helloPnPjsGraph/HelloPnPjsGraphWebPart.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"HelloAngularWebPartStrings": "lib/webparts/helloAngular/loc/{locale}.js",
"HelloSharePointWebPartStrings": "lib/webparts/helloSharePoint/loc/{locale}.js",
"GraphHelloWorldWebPartStrings": "lib/webparts/graphHelloWorld/loc/{locale}.js",
"PnPSharePointHelloWorldWebPartStrings": "lib/webparts/pnPSharePointHelloWorld/loc/{locale}.js",
"HelloGraphWebPartStrings": "lib/webparts/helloGraph/loc/{locale}.js",
"HelloPnPjsSharePointWebPartStrings": "lib/webparts/helloPnPjsSharePoint/loc/{locale}.js",
"HelloPnPjsGraphWebPartStrings": "lib/webparts/helloPnPjsGraph/loc/{locale}.js"
}
}

View File

@ -0,0 +1,4 @@
{
"$schema": "https://dev.office.com/json-schemas/spfx-build/copy-assets.schema.json",
"deployCdnPath": "temp/deploy"
}

View File

@ -0,0 +1,7 @@
{
"$schema": "https://dev.office.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
"workingDir": "./temp/deploy/",
"account": "<!-- STORAGE ACCOUNT NAME -->",
"container": "angularelements-helloworld",
"accessKey": "<!-- ACCESS KEY -->"
}

View File

@ -0,0 +1,13 @@
{
"$schema": "https://dev.office.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "angularelements-helloworld-client-side-solution",
"id": "565c046f-46a4-42e5-a5e6-e9e4edfcf09d",
"version": "1.0.0.0",
"includeClientSideAssets": true,
"skipFeatureDeployment": true
},
"paths": {
"zippedPackage": "solution/angularelements-helloworld.sppkg"
}
}

View File

@ -0,0 +1,10 @@
{
"$schema": "https://dev.office.com/json-schemas/core-build/serve.schema.json",
"port": 4321,
"https": true,
"initialPage": "https://localhost:5432/workbench",
"api": {
"port": 5432,
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
}
}

View File

@ -0,0 +1,45 @@
{
"$schema": "https://dev.office.com/json-schemas/core-build/tslint.schema.json",
// Display errors as warnings
"displayAsWarning": true,
// The TSLint task may have been configured with several custom lint rules
// before this config file is read (for example lint rules from the tslint-microsoft-contrib
// project). If true, this flag will deactivate any of these rules.
"removeExistingRules": true,
// When true, the TSLint task is configured with some default TSLint "rules.":
"useDefaultConfigAsBase": false,
// Since removeExistingRules=true and useDefaultConfigAsBase=false, there will be no lint rules
// which are active, other than the list of rules below.
"lintConfig": {
// Opt-in to Lint rules which help to eliminate bugs in JavaScript
"rules": {
"class-name": false,
"export-name": false,
"forin": false,
"label-position": false,
"member-access": true,
"no-arg": false,
"no-console": false,
"no-construct": false,
"no-duplicate-case": true,
"no-duplicate-variable": true,
"no-eval": false,
"no-function-expression": true,
"no-internal-module": true,
"no-shadowed-variable": true,
"no-switch-case-fall-through": true,
"no-unnecessary-semicolons": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-with-statement": true,
"semicolon": true,
"trailing-comma": false,
"typedef": false,
"typedef-whitespace": false,
"use-named-parameter": true,
"valid-typeof": true,
"variable-name": false,
"whitespace": false
}
}
}

View File

@ -0,0 +1,4 @@
{
"$schema": "https://dev.office.com/json-schemas/spfx-build/write-manifests.schema.json",
"cdnBasePath": "<!-- PATH TO CDN -->"
}

View File

@ -0,0 +1,38 @@
'use strict';
const gulp = require('gulp');
const build = require('@microsoft/sp-build-web');
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
const webpack = require('webpack');
const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const bundleAnalyzer = require('webpack-bundle-analyzer');
build.configureWebpack.mergeConfig({
additionalConfiguration: (generatedConfiguration) => {
const lastDirName = path.basename(__dirname);
const dropPath = path.join(__dirname, 'temp', 'stats');
generatedConfiguration.plugins.push(new bundleAnalyzer.BundleAnalyzerPlugin({
openAnalyzer: false,
analyzerMode: 'static',
reportFilename: path.join(dropPath, `${lastDirName}.stats.html`),
generateStatsFile: true,
statsFilename: path.join(dropPath, `${lastDirName}.stats.json`),
logLevel: 'error'
}));
generatedConfiguration.plugins.push(new webpack.ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)fesm5/, path.join(__dirname, './client')));
for (let i = 0; i < generatedConfiguration.plugins.length; i++) {
const p = generatedConfiguration.plugins[i];
if (p.options && p.options.mangle) {
generatedConfiguration.plugins.splice(i, 1, new UglifyJSPlugin({ uglifyOptions: { mangle: true } }));
break;
}
}
return generatedConfiguration;
}
});
build.initialize(gulp);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,47 @@
{
"name": "angularelements-helloworld",
"version": "0.0.1",
"private": true,
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"build": "gulp bundle",
"clean": "gulp clean",
"test": "gulp test"
},
"dependencies": {
"@angular/common": "^6.0.3",
"@angular/compiler": "^6.0.3",
"@angular/core": "^6.0.3",
"@angular/elements": "^6.0.3",
"@angular/platform-browser": "^6.0.3",
"@angular/platform-browser-dynamic": "^6.0.3",
"@microsoft/generator-sharepoint": "^1.4.1",
"@microsoft/sp-core-library": "~1.4.1",
"@microsoft/sp-lodash-subset": "~1.4.1",
"@microsoft/sp-office-ui-fabric-core": "~1.4.1",
"@microsoft/sp-webpart-base": "~1.4.1",
"@pnp/common": "^1.1.0",
"@pnp/graph": "^1.1.0",
"@pnp/logging": "^1.1.0",
"@pnp/odata": "^1.1.0",
"@pnp/sp": "^1.1.0",
"@types/webpack-env": ">=1.12.1 <1.14.0",
"@webcomponents/custom-elements": "^1.1.1",
"core-js": "^2.5.7",
"rxjs": "^6.2.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@microsoft/sp-build-web": "~1.4.1",
"@microsoft/sp-module-interfaces": "~1.4.1",
"@microsoft/sp-webpart-workbench": "~1.4.1",
"@types/chai": ">=3.4.34 <3.6.0",
"@types/mocha": ">=2.2.33 <2.6.0",
"ajv": "~5.2.2",
"gulp": "~3.9.1",
"uglifyjs-webpack-plugin": "^1.2.5",
"webpack-bundle-analyzer": "^2.13.1"
}
}

View File

@ -0,0 +1,26 @@
{
"$schema": "https://dev.office.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "5488f211-1e21-42ae-85b1-da871d3e4dc4",
"alias": "HelloAngularWebPart",
"componentType": "WebPart",
// The "*" signifies that the version should be taken from the package.json
"version": "*",
"manifestVersion": 2,
// If true, the component can only be installed on sites where Custom Script is allowed.
// Components that allow authors to embed arbitrary script code should set this to true.
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
"requiresCustomScript": false,
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
"group": { "default": "Other" },
"title": { "default": "Hello Angular" },
"description": { "default": "Hello Angular description" },
"officeFabricIconFontName": "Page",
"properties": {
"description": "Hello Angular"
}
}]
}

View File

@ -0,0 +1,74 @@
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
.helloAngular {
.container {
max-width: 700px;
margin: 0px auto;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
}
.row {
@include ms-Grid-row;
@include ms-fontColor-white;
background-color: $ms-color-themeDark;
padding: 20px;
}
.column {
@include ms-Grid-col;
@include ms-lg10;
@include ms-xl8;
@include ms-xlPush2;
@include ms-lgPush1;
}
.title {
@include ms-font-xl;
@include ms-fontColor-white;
}
.subTitle {
@include ms-font-l;
@include ms-fontColor-white;
}
.description {
@include ms-font-l;
@include ms-fontColor-white;
}
.button {
// Our button
text-decoration: none;
height: 32px;
// Primary Button
min-width: 80px;
background-color: $ms-color-themePrimary;
border-color: $ms-color-themePrimary;
color: $ms-color-white;
// Basic Button
outline: transparent;
position: relative;
font-family: "Segoe UI WestEuropean","Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",sans-serif;
-webkit-font-smoothing: antialiased;
font-size: $ms-font-size-m;
font-weight: $ms-font-weight-regular;
border-width: 0;
text-align: center;
cursor: pointer;
display: inline-block;
padding: 0 16px;
.label {
font-weight: $ms-font-weight-semibold;
font-size: $ms-font-size-m;
height: 32px;
line-height: 32px;
margin: 0 4px;
vertical-align: top;
display: inline-block;
}
}
}

View File

@ -0,0 +1,57 @@
import { Version } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-webpart-base';
import { escape } from '@microsoft/sp-lodash-subset';
import styles from './HelloAngularWebPart.module.scss';
import * as strings from 'HelloAngularWebPartStrings';
import '@webcomponents/custom-elements/src/native-shim';
import 'core-js/es7/reflect';
import { AppModule } from './app/app.module';
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
export interface IHelloAngularWebPartProps {
description: string;
}
export default class HelloAngularWebPart extends BaseClientSideWebPart<IHelloAngularWebPartProps> {
public render(): void {
platformBrowserDynamic().bootstrapModule(AppModule, { ngZone: 'noop' }).then(() => {
this.domElement.innerHTML = `<hello-world message="${this.properties.description}"></hello-world>`;
});
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField('description', {
label: strings.DescriptionFieldLabel
})
]
}
]
}
]
};
}
}

View File

@ -0,0 +1,27 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule, Injector } from '@angular/core';
import { createCustomElement } from '@angular/elements';
import { HelloWorldComponent } from './helloWorld.component';
@NgModule({
imports: [
BrowserModule
],
declarations: [
HelloWorldComponent
],
entryComponents: [
HelloWorldComponent
]
})
export class AppModule {
constructor(private injector: Injector) {}
public ngDoBootstrap() {
if(!customElements.get("hello-world")) {
const AppElement = createCustomElement(HelloWorldComponent, { injector: this.injector });
customElements.define('hello-world', AppElement);
}
}
}

View File

@ -0,0 +1,14 @@
import { Component, OnInit, Input } from "@angular/core";
@Component({
selector: 'hello-world',
template: `
<div>{{ message }}</div>
`
})
export class HelloWorldComponent implements OnInit {
@Input()
public message: string;
public ngOnInit() { }
}

View File

@ -0,0 +1,7 @@
define([], function() {
return {
"PropertyPaneDescription": "Description",
"BasicGroupName": "Group Name",
"DescriptionFieldLabel": "Description Field"
}
});

View File

@ -0,0 +1,10 @@
declare interface IHelloAngularWebPartStrings {
PropertyPaneDescription: string;
BasicGroupName: string;
DescriptionFieldLabel: string;
}
declare module 'HelloAngularWebPartStrings' {
const strings: IHelloAngularWebPartStrings;
export = strings;
}

View File

@ -0,0 +1,26 @@
{
"$schema": "https://dev.office.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "893b2dc0-3a3b-4c81-a9fd-beb65e4636e9",
"alias": "HelloGraphWebPart",
"componentType": "WebPart",
// The "*" signifies that the version should be taken from the package.json
"version": "*",
"manifestVersion": 2,
// If true, the component can only be installed on sites where Custom Script is allowed.
// Components that allow authors to embed arbitrary script code should set this to true.
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
"requiresCustomScript": false,
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
"group": { "default": "Other" },
"title": { "default": "Hello Graph" },
"description": { "default": "Hello Graph description" },
"officeFabricIconFontName": "Page",
"properties": {
"description": "Hello Graph"
}
}]
}

View File

@ -0,0 +1,74 @@
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
.helloGraph {
.container {
max-width: 700px;
margin: 0px auto;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
}
.row {
@include ms-Grid-row;
@include ms-fontColor-white;
background-color: $ms-color-themeDark;
padding: 20px;
}
.column {
@include ms-Grid-col;
@include ms-lg10;
@include ms-xl8;
@include ms-xlPush2;
@include ms-lgPush1;
}
.title {
@include ms-font-xl;
@include ms-fontColor-white;
}
.subTitle {
@include ms-font-l;
@include ms-fontColor-white;
}
.description {
@include ms-font-l;
@include ms-fontColor-white;
}
.button {
// Our button
text-decoration: none;
height: 32px;
// Primary Button
min-width: 80px;
background-color: $ms-color-themePrimary;
border-color: $ms-color-themePrimary;
color: $ms-color-white;
// Basic Button
outline: transparent;
position: relative;
font-family: "Segoe UI WestEuropean","Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",sans-serif;
-webkit-font-smoothing: antialiased;
font-size: $ms-font-size-m;
font-weight: $ms-font-weight-regular;
border-width: 0;
text-align: center;
cursor: pointer;
display: inline-block;
padding: 0 16px;
.label {
font-weight: $ms-font-weight-semibold;
font-size: $ms-font-size-m;
height: 32px;
line-height: 32px;
margin: 0 4px;
vertical-align: top;
display: inline-block;
}
}
}

View File

@ -0,0 +1,64 @@
import { Version } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-webpart-base';
import { escape } from '@microsoft/sp-lodash-subset';
import styles from './HelloGraphWebPart.module.scss';
import * as strings from 'HelloGraphWebPartStrings';
import '@webcomponents/custom-elements/src/native-shim';
import 'core-js/es7/reflect';
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { MSGraphClient } from '@microsoft/sp-client-preview';
export interface IHelloGraphWebPartProps {
description: string;
}
export default class HelloGraphWebPart extends BaseClientSideWebPart<IHelloGraphWebPartProps> {
public render(): void {
if(!this.renderedOnce) {
let client : MSGraphClient = this.context.serviceScope.consume(MSGraphClient.serviceKey);
platformBrowserDynamic().bootstrapModule(AppModule, { ngZone: 'noop' })
.then(() => {
const ElementGraphHelloWorld = customElements.get("hello-graph");
const element = new ElementGraphHelloWorld();
element.client = client;
this.domElement.appendChild(element);
});
}
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField('description', {
label: strings.DescriptionFieldLabel
})
]
}
]
}
]
};
}
}

View File

@ -0,0 +1,24 @@
import { NgModule, Injector } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { createCustomElement, NgElementConfig } from "@angular/elements";
import { HelloGraphComponent } from "./helloGraph.component";
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
BrowserModule,
HttpClientModule
],
declarations: [HelloGraphComponent],
entryComponents: [HelloGraphComponent]
})
export class AppModule {
constructor(private injector: Injector) {}
public ngDoBootstrap() {
if(!customElements.get("hello-graph")) {
const AppElement = createCustomElement(HelloGraphComponent, { injector: this.injector });
customElements.define('hello-graph', AppElement);
}
}
}

View File

@ -0,0 +1,13 @@
import { MSGraphClient } from "@microsoft/sp-client-preview";
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, from } from 'rxjs';
@Injectable()
export class GraphService {
public getMe(client: MSGraphClient): Observable<{ displayName: string }> {
return from(
client.api("/me").get()
);
}
}

View File

@ -0,0 +1,30 @@
import { Component, OnInit, Input, ChangeDetectorRef } from "@angular/core";
import { GraphService } from "./graph.service";
import { MSGraphClient } from "@microsoft/sp-client-preview";
@Component({
selector: 'hello-graph',
providers: [GraphService],
template: `
<div>[Hello Graph] My name is: {{ displayName }}</div>
`
})
export class HelloGraphComponent implements OnInit {
@Input()
public client: MSGraphClient;
public displayName: string;
constructor(private graphService: GraphService, private cd: ChangeDetectorRef) {
}
public ngOnInit() {
this.displayName = '...';
this.graphService
.getMe(this.client)
.subscribe(data => {
this.displayName = data.displayName;
this.cd.detectChanges();
});
}
}

View File

@ -0,0 +1,7 @@
define([], function() {
return {
"PropertyPaneDescription": "Description",
"BasicGroupName": "Group Name",
"DescriptionFieldLabel": "Description Field"
}
});

View File

@ -0,0 +1,10 @@
declare interface IHelloGraphWebPartStrings {
PropertyPaneDescription: string;
BasicGroupName: string;
DescriptionFieldLabel: string;
}
declare module 'HelloGraphWebPartStrings' {
const strings: IHelloGraphWebPartStrings;
export = strings;
}

View File

@ -0,0 +1,26 @@
{
"$schema": "https://dev.office.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "a6239324-68c5-487c-9b14-f9b9693224da",
"alias": "HelloPnPjsGraphWebPart",
"componentType": "WebPart",
// The "*" signifies that the version should be taken from the package.json
"version": "*",
"manifestVersion": 2,
// If true, the component can only be installed on sites where Custom Script is allowed.
// Components that allow authors to embed arbitrary script code should set this to true.
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
"requiresCustomScript": false,
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
"group": { "default": "Other" },
"title": { "default": "Hello PnP JS Graph" },
"description": { "default": "Hello PnP JS Graph description" },
"officeFabricIconFontName": "Page",
"properties": {
"description": "Hello PnP JS Graph"
}
}]
}

View File

@ -0,0 +1,74 @@
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
.helloPnPjsGraph {
.container {
max-width: 700px;
margin: 0px auto;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
}
.row {
@include ms-Grid-row;
@include ms-fontColor-white;
background-color: $ms-color-themeDark;
padding: 20px;
}
.column {
@include ms-Grid-col;
@include ms-lg10;
@include ms-xl8;
@include ms-xlPush2;
@include ms-lgPush1;
}
.title {
@include ms-font-xl;
@include ms-fontColor-white;
}
.subTitle {
@include ms-font-l;
@include ms-fontColor-white;
}
.description {
@include ms-font-l;
@include ms-fontColor-white;
}
.button {
// Our button
text-decoration: none;
height: 32px;
// Primary Button
min-width: 80px;
background-color: $ms-color-themePrimary;
border-color: $ms-color-themePrimary;
color: $ms-color-white;
// Basic Button
outline: transparent;
position: relative;
font-family: "Segoe UI WestEuropean","Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",sans-serif;
-webkit-font-smoothing: antialiased;
font-size: $ms-font-size-m;
font-weight: $ms-font-weight-regular;
border-width: 0;
text-align: center;
cursor: pointer;
display: inline-block;
padding: 0 16px;
.label {
font-weight: $ms-font-weight-semibold;
font-size: $ms-font-size-m;
height: 32px;
line-height: 32px;
margin: 0 4px;
vertical-align: top;
display: inline-block;
}
}
}

View File

@ -0,0 +1,65 @@
import { Version } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-webpart-base';
import { escape } from '@microsoft/sp-lodash-subset';
import styles from './HelloPnPjsGraphWebPart.module.scss';
import * as strings from 'HelloPnPjsGraphWebPartStrings';
import '@webcomponents/custom-elements/src/native-shim';
import 'core-js/es7/reflect';
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { graph } from "@pnp/graph";
export interface IHelloPnPjsGraphWebPartProps {
description: string;
}
export default class HelloPnPjsGraphWebPart extends BaseClientSideWebPart<IHelloPnPjsGraphWebPartProps> {
public render(): void {
platformBrowserDynamic().bootstrapModule(AppModule, { ngZone: 'noop' }).then(() => {
this.domElement.innerHTML = `<hello-pnp-js-graph></hello-pnp-js-graph>`;
});
}
public onInit(): Promise<void> {
return super.onInit().then(_ => {
graph.setup({
spfxContext: this.context
});
});
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField('description', {
label: strings.DescriptionFieldLabel
})
]
}
]
}
]
};
}
}

View File

@ -0,0 +1,26 @@
import { NgModule, Injector } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { createCustomElement, NgElementConfig } from "@angular/elements";
import { HelloPnPJSGraphComponent } from "./helloPnPJSGraph.component";
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
BrowserModule,
HttpClientModule
],
declarations: [HelloPnPJSGraphComponent],
entryComponents: [HelloPnPJSGraphComponent]
})
export class AppModule {
constructor(private injector: Injector) {}
public ngDoBootstrap() {
const config: NgElementConfig = {injector: this.injector};
const ngElement = createCustomElement(HelloPnPJSGraphComponent, config);
if(!customElements.get("hello-pnp-js-graph")) {
customElements.define('hello-pnp-js-graph', ngElement);
}
}
}

View File

@ -0,0 +1,12 @@
import { Injectable } from '@angular/core';
import { Observable, from } from 'rxjs';
import { graph } from "@pnp/graph";
@Injectable()
export class GraphService {
public getMe(): Observable<{ displayName: string }> {
return from(
graph.me.get()
);
}
}

View File

@ -0,0 +1,27 @@
import { Component, OnInit, Input, ChangeDetectorRef } from "@angular/core";
import { GraphService } from "./graph.service";
@Component({
selector: 'hello-pnp-js-graph',
providers: [GraphService],
template: `
<div>[Hello PnP JS Graph] My name is: {{ displayName }}</div>
`
})
export class HelloPnPJSGraphComponent implements OnInit {
public displayName: string;
constructor(private graphService: GraphService, private cd: ChangeDetectorRef) {
}
public ngOnInit() {
this.displayName = '...';
this.graphService
.getMe()
.subscribe(data => {
this.displayName = data.displayName;
this.cd.detectChanges();
});
}
}

View File

@ -0,0 +1,7 @@
define([], function() {
return {
"PropertyPaneDescription": "Description",
"BasicGroupName": "Group Name",
"DescriptionFieldLabel": "Description Field"
}
});

View File

@ -0,0 +1,10 @@
declare interface IHelloPnPjsGraphWebPartStrings {
PropertyPaneDescription: string;
BasicGroupName: string;
DescriptionFieldLabel: string;
}
declare module 'HelloPnPjsGraphWebPartStrings' {
const strings: IHelloPnPjsGraphWebPartStrings;
export = strings;
}

View File

@ -0,0 +1,26 @@
{
"$schema": "https://dev.office.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "39ae6319-d894-4dba-9d17-3d323b51e92b",
"alias": "HelloPnPjsSharePointWebPart",
"componentType": "WebPart",
// The "*" signifies that the version should be taken from the package.json
"version": "*",
"manifestVersion": 2,
// If true, the component can only be installed on sites where Custom Script is allowed.
// Components that allow authors to embed arbitrary script code should set this to true.
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
"requiresCustomScript": false,
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
"group": { "default": "Other" },
"title": { "default": "HelloPnPJSSharePoint" },
"description": { "default": "HelloPnPJSSharePoint description" },
"officeFabricIconFontName": "Page",
"properties": {
"description": "HelloPnPJSSharePoint"
}
}]
}

View File

@ -0,0 +1,74 @@
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
.helloPnPjsSharePoint {
.container {
max-width: 700px;
margin: 0px auto;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
}
.row {
@include ms-Grid-row;
@include ms-fontColor-white;
background-color: $ms-color-themeDark;
padding: 20px;
}
.column {
@include ms-Grid-col;
@include ms-lg10;
@include ms-xl8;
@include ms-xlPush2;
@include ms-lgPush1;
}
.title {
@include ms-font-xl;
@include ms-fontColor-white;
}
.subTitle {
@include ms-font-l;
@include ms-fontColor-white;
}
.description {
@include ms-font-l;
@include ms-fontColor-white;
}
.button {
// Our button
text-decoration: none;
height: 32px;
// Primary Button
min-width: 80px;
background-color: $ms-color-themePrimary;
border-color: $ms-color-themePrimary;
color: $ms-color-white;
// Basic Button
outline: transparent;
position: relative;
font-family: "Segoe UI WestEuropean","Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",sans-serif;
-webkit-font-smoothing: antialiased;
font-size: $ms-font-size-m;
font-weight: $ms-font-weight-regular;
border-width: 0;
text-align: center;
cursor: pointer;
display: inline-block;
padding: 0 16px;
.label {
font-weight: $ms-font-weight-semibold;
font-size: $ms-font-size-m;
height: 32px;
line-height: 32px;
margin: 0 4px;
vertical-align: top;
display: inline-block;
}
}
}

View File

@ -0,0 +1,65 @@
import { Version } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-webpart-base';
import { escape } from '@microsoft/sp-lodash-subset';
import styles from './HelloPnPjsSharePointWebPart.module.scss';
import * as strings from 'HelloPnPjsSharePointWebPartStrings';
import '@webcomponents/custom-elements/src/native-shim';
import 'core-js/es7/reflect';
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { sp } from "@pnp/sp";
export interface IHelloPnPjsSharePointWebPartProps {
description: string;
}
export default class HelloPnPjsSharePointWebPart extends BaseClientSideWebPart<IHelloPnPjsSharePointWebPartProps> {
public render(): void {
platformBrowserDynamic().bootstrapModule(AppModule, { ngZone: 'noop' }).then(() => {
this.domElement.innerHTML = `<hello-pnp-js-sharepoint></hello-pnp-js-sharepoint>`;
});
}
public onInit(): Promise<void> {
return super.onInit().then(_ => {
sp.setup({
spfxContext: this.context
});
});
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField('description', {
label: strings.DescriptionFieldLabel
})
]
}
]
}
]
};
}
}

View File

@ -0,0 +1,27 @@
import { NgModule, Injector } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { createCustomElement, NgElementConfig } from "@angular/elements";
import { HelloPnPJSSharePointComponent } from "./helloPnPJSSharePoint.component";
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
BrowserModule,
HttpClientModule
],
declarations: [HelloPnPJSSharePointComponent],
entryComponents: [HelloPnPJSSharePointComponent]
})
export class AppModule {
constructor(private injector: Injector) {
}
public ngDoBootstrap() {
const config: NgElementConfig = {injector: this.injector};
const ngElement = createCustomElement(HelloPnPJSSharePointComponent, config);
if(!customElements.get("hello-pnp-js-sharepoint")) {
customElements.define('hello-pnp-js-sharepoint', ngElement);
}
}
}

View File

@ -0,0 +1,29 @@
import { Component, OnInit, Input, ChangeDetectorRef } from "@angular/core";
import { SharePointService } from "./sharePoint.service";
@Component({
selector: 'hello-pnp-js-sharepoint',
providers: [SharePointService],
template: `
<div>[Hello PnP JS SharePoint] Web title: {{ title }}</div>
`
})
export class HelloPnPJSSharePointComponent implements OnInit {
@Input()
public siteUrl: string;
public title: string;
constructor(private sharePointService: SharePointService, private cd: ChangeDetectorRef) {
}
public ngOnInit() {
this.title = '...';
this.sharePointService
.getSiteTitle()
.subscribe(data => {
this.title = data.Title;
this.cd.detectChanges();
});
}
}

View File

@ -0,0 +1,12 @@
import { Injectable } from '@angular/core';
import { Observable, from } from 'rxjs';
import { sp } from "@pnp/sp";
@Injectable()
export class SharePointService {
public getSiteTitle(): Observable<{ Title: string }> {
return from(
sp.web.get()
);
}
}

View File

@ -0,0 +1,7 @@
define([], function() {
return {
"PropertyPaneDescription": "Description",
"BasicGroupName": "Group Name",
"DescriptionFieldLabel": "Description Field"
}
});

View File

@ -0,0 +1,10 @@
declare interface IHelloPnPjsSharePointWebPartStrings {
PropertyPaneDescription: string;
BasicGroupName: string;
DescriptionFieldLabel: string;
}
declare module 'HelloPnPjsSharePointWebPartStrings' {
const strings: IHelloPnPjsSharePointWebPartStrings;
export = strings;
}

View File

@ -0,0 +1,26 @@
{
"$schema": "https://dev.office.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "10260958-8a90-4562-9927-63504d229b7f",
"alias": "HelloSharePointWebPart",
"componentType": "WebPart",
// The "*" signifies that the version should be taken from the package.json
"version": "*",
"manifestVersion": 2,
// If true, the component can only be installed on sites where Custom Script is allowed.
// Components that allow authors to embed arbitrary script code should set this to true.
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
"requiresCustomScript": false,
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
"group": { "default": "Other" },
"title": { "default": "Hello SharePoint" },
"description": { "default": "Hello SharePoint description" },
"officeFabricIconFontName": "Page",
"properties": {
"description": "Hello SharePoint"
}
}]
}

View File

@ -0,0 +1,74 @@
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
.helloSharePoint {
.container {
max-width: 700px;
margin: 0px auto;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
}
.row {
@include ms-Grid-row;
@include ms-fontColor-white;
background-color: $ms-color-themeDark;
padding: 20px;
}
.column {
@include ms-Grid-col;
@include ms-lg10;
@include ms-xl8;
@include ms-xlPush2;
@include ms-lgPush1;
}
.title {
@include ms-font-xl;
@include ms-fontColor-white;
}
.subTitle {
@include ms-font-l;
@include ms-fontColor-white;
}
.description {
@include ms-font-l;
@include ms-fontColor-white;
}
.button {
// Our button
text-decoration: none;
height: 32px;
// Primary Button
min-width: 80px;
background-color: $ms-color-themePrimary;
border-color: $ms-color-themePrimary;
color: $ms-color-white;
// Basic Button
outline: transparent;
position: relative;
font-family: "Segoe UI WestEuropean","Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",sans-serif;
-webkit-font-smoothing: antialiased;
font-size: $ms-font-size-m;
font-weight: $ms-font-weight-regular;
border-width: 0;
text-align: center;
cursor: pointer;
display: inline-block;
padding: 0 16px;
.label {
font-weight: $ms-font-weight-semibold;
font-size: $ms-font-size-m;
height: 32px;
line-height: 32px;
margin: 0 4px;
vertical-align: top;
display: inline-block;
}
}
}

View File

@ -0,0 +1,56 @@
import { Version } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-webpart-base';
import { escape } from '@microsoft/sp-lodash-subset';
import styles from './HelloSharePointWebPart.module.scss';
import * as strings from 'HelloSharePointWebPartStrings';
import '@webcomponents/custom-elements/src/native-shim';
import 'core-js/es7/reflect';
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
export interface IHelloSharePointWebPartProps {
description: string;
}
export default class HelloSharePointWebPart extends BaseClientSideWebPart<IHelloSharePointWebPartProps> {
public render(): void {
platformBrowserDynamic().bootstrapModule(AppModule, { ngZone: 'noop' }).then(() => {
this.domElement.innerHTML = `<hello-sharepoint site-url="${this.context.pageContext.web.absoluteUrl}"></hello-sharepoint>`;
});
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField('description', {
label: strings.DescriptionFieldLabel
})
]
}
]
}
]
};
}
}

View File

@ -0,0 +1,26 @@
import { NgModule, Injector } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { createCustomElement, NgElementConfig } from "@angular/elements";
import { HelloSharePointComponent } from "./helloSharePoint.component";
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
BrowserModule,
HttpClientModule
],
declarations: [HelloSharePointComponent],
entryComponents: [HelloSharePointComponent]
})
export class AppModule {
constructor(private injector: Injector) {}
public ngDoBootstrap() {
const config: NgElementConfig = {injector: this.injector};
const ngElement = createCustomElement(HelloSharePointComponent, config);
if(!customElements.get("hello-sharepoint")) {
customElements.define('hello-sharepoint', ngElement);
}
}
}

View File

@ -0,0 +1,29 @@
import { Component, OnInit, Input, ChangeDetectorRef } from "@angular/core";
import { SharePointService } from "./sharePoint.service";
@Component({
selector: 'hello-sharepoint',
providers: [SharePointService],
template: `
<div>[Hello SharePoint] Web title: {{ title }}</div>
`
})
export class HelloSharePointComponent implements OnInit {
@Input()
public siteUrl: string;
public title: string;
constructor(private sharePointService: SharePointService, private cd: ChangeDetectorRef) {
}
public ngOnInit() {
this.title = '...';
this.sharePointService
.getSiteTitle(this.siteUrl)
.subscribe(data => {
this.title = data.Title;
this.cd.detectChanges();
});
}
}

View File

@ -0,0 +1,16 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable()
export class SharePointService {
constructor(private http: HttpClient) { }
public getSiteTitle(siteUrl: string): Observable<{ Title: string }> {
return this.http.get<{ Title: string }>(`${siteUrl}/_api/web?$select=Title`, {
headers: new HttpHeaders({
accept: 'application/json;odata=nometadata'
})
});
}
}

View File

@ -0,0 +1,7 @@
define([], function() {
return {
"PropertyPaneDescription": "Description",
"BasicGroupName": "Group Name",
"DescriptionFieldLabel": "Description Field"
}
});

View File

@ -0,0 +1,10 @@
declare interface IHelloSharePointWebPartStrings {
PropertyPaneDescription: string;
BasicGroupName: string;
DescriptionFieldLabel: string;
}
declare module 'HelloSharePointWebPartStrings' {
const strings: IHelloSharePointWebPartStrings;
export = strings;
}

View File

@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "es5",
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"jsx": "react",
"declaration": true,
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"skipLibCheck": true,
"typeRoots": [
"./node_modules/@types",
"./node_modules/@microsoft"
],
"types": [
"es6-promise",
"webpack-env"
],
"lib": [
"es5",
"dom",
"es2015.collection"
]
}
}