UNPKG

@microsoft/sp-webpart-base

Version:

SharePoint Framework support for building web parts

115 lines 4.69 kB
import { __extends } from "tslib"; import { BaseComponentContext } from '@microsoft/sp-component-base'; import { Validate } from '@microsoft/sp-core-library'; import PropertyPaneAccessor from './context/PropertyPaneAccessor'; /** * Web part context object. This object contains the contextual services available to a web part. e.g. * a contextual instance to the http client. * * This base is to be extended by UI-specific WebPart's base. * * @public */ var BaseWebPartContext = /** @class */ (function (_super) { __extends(BaseWebPartContext, _super); /** @internal */ function BaseWebPartContext(parameters) { var _this = _super.call(this, parameters) || this; Validate.isNotNullOrUndefined(parameters, 'webpart context'); Validate.isNotNullOrUndefined(parameters.instanceId, 'webpart context instanceId'); Validate.isNotNullOrUndefined(parameters.webPartTag, 'webpart context webPartTag'); Validate.isNotNullOrUndefined(parameters.host, 'webpart context host'); Validate.isNotNullOrUndefined(parameters.isPropertyPaneRenderedByWebPart, 'webpart context isPropertyPaneRenderedByWebPart'); Validate.isNotNullOrUndefined(parameters.isPropertyPaneOpen, 'webpart context isPropertyPaneOpen'); Validate.isNotNullOrUndefined(parameters.requestPropertyPaneAction, 'webpart context requestPropertyPaneAction'); Validate.isNotNullOrUndefined(parameters.formFactor, 'webpart context form factor'); _this._webPartTag = parameters.webPartTag; _this._host = parameters.host; _this._requestPropertyPaneAction = parameters.requestPropertyPaneAction; _this._isPropertyPaneRenderedByWebPart = parameters.isPropertyPaneRenderedByWebPart; _this._isPropertyPaneOpen = parameters.isPropertyPaneOpen; _this._isContentPanelOpen = parameters.isContentPanelOpen; _this._privateDataUpdatedEvent = parameters._dataUpdatedEvent; _this._formFactor = parameters.formFactor; _this._propertyPaneAccessor = new PropertyPaneAccessor(function () { _this._requestPropertyPaneAction(_this.instanceId, 'Open', true); }, function () { _this._requestPropertyPaneAction(_this.instanceId, 'Close', true); }, function () { _this._requestPropertyPaneAction(_this.instanceId, 'Refresh', true); }, function (context) { _this._requestPropertyPaneAction(_this.instanceId, 'OpenDetails', true, context); }, function () { return _this._isPropertyPaneRenderedByWebPart(); }, function (instanceId) { return _this._isPropertyPaneOpen(instanceId); }, function () { return _this._isContentPanelOpen(); }); return _this; } Object.defineProperty(BaseWebPartContext.prototype, "webPartTag", { /** * Web part tag to be used for logging and telemetry. */ get: function () { return this._webPartTag; }, enumerable: false, configurable: true }); Object.defineProperty(BaseWebPartContext.prototype, "propertyPane", { /** * Accessor for common web part property pane operations. */ get: function () { return this._propertyPaneAccessor; }, enumerable: false, configurable: true }); Object.defineProperty(BaseWebPartContext.prototype, "formFactor", { /** * Form factor of the web part. * * @remarks * Web parts may behave differently based on its form factor. * E.g. a web part rendering as full size may want to set up different margins that when rendering in a canvas. * * @beta */ get: function () { return this._formFactor; }, enumerable: false, configurable: true }); Object.defineProperty(BaseWebPartContext.prototype, "host", { /** * Web part host. * * @internal */ get: function () { return this._host; }, enumerable: false, configurable: true }); Object.defineProperty(BaseWebPartContext.prototype, "_dataUpdatedEvent", { /** * Web part properties updated event. * * @eventproperty * @internal */ get: function () { return this._privateDataUpdatedEvent; }, enumerable: false, configurable: true }); return BaseWebPartContext; }(BaseComponentContext)); export default BaseWebPartContext; //# sourceMappingURL=BaseWebPartContext.js.map