Initial commit
This commit is contained in:
1
lib/extensions/megaMenu/MegaMenu.module.css
Normal file
1
lib/extensions/megaMenu/MegaMenu.module.css
Normal file
File diff suppressed because one or more lines are too long
5
lib/extensions/megaMenu/MegaMenu.module.scss.d.ts
vendored
Normal file
5
lib/extensions/megaMenu/MegaMenu.module.scss.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
declare const styles: {
|
||||
mmSlideIn: string;
|
||||
mmFadeIn: string;
|
||||
};
|
||||
export default styles;
|
||||
10
lib/extensions/megaMenu/MegaMenu.module.scss.js
Normal file
10
lib/extensions/megaMenu/MegaMenu.module.scss.js
Normal file
@@ -0,0 +1,10 @@
|
||||
/* tslint:disable */
|
||||
require('./MegaMenu.module.css');
|
||||
var styles = {
|
||||
mmSlideIn: 'mmSlideIn_09a8e1a7',
|
||||
mmFadeIn: 'mmFadeIn_09a8e1a7',
|
||||
};
|
||||
export default styles;
|
||||
/* tslint:enable */
|
||||
|
||||
//# sourceMappingURL=MegaMenu.module.scss.js.map
|
||||
1
lib/extensions/megaMenu/MegaMenu.module.scss.js.map
Normal file
1
lib/extensions/megaMenu/MegaMenu.module.scss.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["extensions/megaMenu/MegaMenu.module.scss.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,OAAO,CAAC,uBAAuB,CAAC,CAAC;AACjC,IAAM,MAAM,GAAG;IACb,SAAS,EAAE,oBAAoB;IAC/B,QAAQ,EAAE,mBAAmB;CAC9B,CAAC;AAEF,eAAe,MAAM,CAAC;AACtB,mBAAmB","file":"extensions/megaMenu/MegaMenu.module.scss.js","sourcesContent":["/* tslint:disable */\r\nrequire('./MegaMenu.module.css');\r\nconst styles = {\r\n mmSlideIn: 'mmSlideIn_09a8e1a7',\r\n mmFadeIn: 'mmFadeIn_09a8e1a7',\r\n};\r\n\r\nexport default styles;\r\n/* tslint:enable */"],"sourceRoot":"..\\..\\..\\src"}
|
||||
27
lib/extensions/megaMenu/MegaMenuApplicationCustomizer.d.ts
vendored
Normal file
27
lib/extensions/megaMenu/MegaMenuApplicationCustomizer.d.ts
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import { BaseApplicationCustomizer } from '@microsoft/sp-application-base';
|
||||
import './MegaMenu.module.scss';
|
||||
export declare const UserCustomActionMegaMenuId: string;
|
||||
/**
|
||||
* Properties for the MegaMenu Application Customizer
|
||||
*/
|
||||
export interface IMegaMenuApplicationCustomizerProperties {
|
||||
/**
|
||||
* The name of the termset to load menu items from
|
||||
*/
|
||||
termSetName: string;
|
||||
/**
|
||||
* Optional URL to an external CSS file
|
||||
*/
|
||||
cssUrl?: string;
|
||||
}
|
||||
/** A Custom Action which can be run during execution of a Client Side Application */
|
||||
export default class MegaMenuApplicationCustomizer extends BaseApplicationCustomizer<IMegaMenuApplicationCustomizerProperties> {
|
||||
private _topPlaceholder;
|
||||
onInit(): Promise<void>;
|
||||
private _renderPlaceHolders();
|
||||
private _updateCallback;
|
||||
private _renderMegaMenu(termSetName);
|
||||
private _getOrCreateContainer(id, placeholder);
|
||||
private _loadExternalCss(cssUrl);
|
||||
private _onDispose();
|
||||
}
|
||||
188
lib/extensions/megaMenu/MegaMenuApplicationCustomizer.js
Normal file
188
lib/extensions/megaMenu/MegaMenuApplicationCustomizer.js
Normal file
@@ -0,0 +1,188 @@
|
||||
// tslint:disable:max-line-length
|
||||
// tslint:disable:match-default-export-name
|
||||
// tslint:disable:typedef
|
||||
// tslint:disable:variable-name
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [0, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
import { override } from '@microsoft/decorators';
|
||||
import { Log } from '@microsoft/sp-core-library';
|
||||
import { BaseApplicationCustomizer, PlaceholderName } from '@microsoft/sp-application-base';
|
||||
import * as strings from 'MegaMenuApplicationCustomizerStrings';
|
||||
import { TaxonomyNavigationService } from '../../services/TaxonomyNavigationService';
|
||||
import { MegaMenuRenderer } from './MegaMenuRenderer';
|
||||
// Import SCSS module
|
||||
import './MegaMenu.module.scss';
|
||||
var LOG_SOURCE = 'MegaMenuApplicationCustomizer';
|
||||
export var UserCustomActionMegaMenuId = 'abc3361f-bb2d-491f-aba3-cd51c19a299b';
|
||||
/** A Custom Action which can be run during execution of a Client Side Application */
|
||||
var MegaMenuApplicationCustomizer = (function (_super) {
|
||||
__extends(MegaMenuApplicationCustomizer, _super);
|
||||
function MegaMenuApplicationCustomizer() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this._updateCallback = function (data) {
|
||||
_this._loadExternalCss(data.cssUrl);
|
||||
_this._renderMegaMenu(data.termSetName);
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
MegaMenuApplicationCustomizer.prototype.onInit = function () {
|
||||
Log.info(LOG_SOURCE, "Initialized " + strings.Title);
|
||||
// Load external CSS if provided
|
||||
if (this.properties.cssUrl) {
|
||||
this._loadExternalCss(this.properties.cssUrl);
|
||||
}
|
||||
// Wait for the page to be ready
|
||||
this.context.placeholderProvider.changedEvent.add(this, this._renderPlaceHolders);
|
||||
// Initial render
|
||||
this._renderPlaceHolders();
|
||||
return Promise.resolve();
|
||||
};
|
||||
MegaMenuApplicationCustomizer.prototype._renderPlaceHolders = function () {
|
||||
console.log('Available placeholders: ', this.context.placeholderProvider.placeholderNames.map(function (name) { return PlaceholderName[name]; }).join(', '));
|
||||
// Handling the top placeholder
|
||||
if (!this._topPlaceholder) {
|
||||
this._topPlaceholder = this.context.placeholderProvider.tryCreateContent(PlaceholderName.Top, { onDispose: this._onDispose });
|
||||
// The extension should not assume that the expected placeholder is available.
|
||||
if (!this._topPlaceholder) {
|
||||
console.error('The expected placeholder (Top) was not found.');
|
||||
return;
|
||||
}
|
||||
if (!this.properties.termSetName) {
|
||||
console.error('TermSetName property is required but not provided.');
|
||||
1;
|
||||
return;
|
||||
}
|
||||
this._renderMegaMenu(this.properties.termSetName);
|
||||
}
|
||||
};
|
||||
MegaMenuApplicationCustomizer.prototype._renderMegaMenu = function (termSetName) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var taxonomyService, menuItems, renderer, container, error_1;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
if (!this._topPlaceholder) {
|
||||
return [2 /*return*/];
|
||||
}
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
_a.trys.push([1, 3, , 4]);
|
||||
taxonomyService = new TaxonomyNavigationService(this.context, termSetName);
|
||||
return [4 /*yield*/, taxonomyService.getMenuItems()];
|
||||
case 2:
|
||||
menuItems = _a.sent();
|
||||
renderer = new MegaMenuRenderer(this.context, menuItems, this._updateCallback);
|
||||
container = this._getOrCreateContainer('CustomHeader', this._topPlaceholder);
|
||||
if (container) {
|
||||
renderer.render(container);
|
||||
}
|
||||
else {
|
||||
renderer.render(this._topPlaceholder.domElement);
|
||||
}
|
||||
Log.info(LOG_SOURCE, "MegaMenu rendered successfully with " + menuItems.length + " top-level items");
|
||||
return [3 /*break*/, 4];
|
||||
case 3:
|
||||
error_1 = _a.sent();
|
||||
console.error('Error rendering MegaMenu:', error_1);
|
||||
return [3 /*break*/, 4];
|
||||
case 4: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MegaMenuApplicationCustomizer.prototype._getOrCreateContainer = function (id, placeholder) {
|
||||
var container = document.getElementById(id);
|
||||
if (container) {
|
||||
var div = document.createElement('div');
|
||||
container.appendChild(div);
|
||||
return div;
|
||||
}
|
||||
else {
|
||||
return placeholder.domElement;
|
||||
}
|
||||
};
|
||||
MegaMenuApplicationCustomizer.prototype._loadExternalCss = function (cssUrl) {
|
||||
var externalCssLinkId = 'mega-menu-additional-css-34FAB720';
|
||||
var link = document.getElementById(externalCssLinkId);
|
||||
if (cssUrl && cssUrl.trim() !== '') {
|
||||
// update previous link, if present
|
||||
if (!link) {
|
||||
var head = document.getElementsByTagName('head')[0];
|
||||
link = document.createElement('link');
|
||||
link.rel = 'stylesheet';
|
||||
link.type = 'text/css';
|
||||
link.id = externalCssLinkId;
|
||||
link.onload = function () {
|
||||
Log.info(LOG_SOURCE, "External CSS loaded successfully from: " + cssUrl);
|
||||
};
|
||||
link.onerror = function () {
|
||||
console.warn("Failed to load external CSS from: " + cssUrl);
|
||||
};
|
||||
head.appendChild(link);
|
||||
}
|
||||
link.href = cssUrl;
|
||||
}
|
||||
else if (link) {
|
||||
link.remove();
|
||||
}
|
||||
};
|
||||
MegaMenuApplicationCustomizer.prototype._onDispose = function () {
|
||||
console.log('[MegaMenuApplicationCustomizer._onDispose] Disposed custom top placeholder.');
|
||||
};
|
||||
__decorate([
|
||||
override
|
||||
], MegaMenuApplicationCustomizer.prototype, "onInit", null);
|
||||
return MegaMenuApplicationCustomizer;
|
||||
}(BaseApplicationCustomizer));
|
||||
export default MegaMenuApplicationCustomizer;
|
||||
|
||||
//# sourceMappingURL=MegaMenuApplicationCustomizer.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-extension-manifest.schema.json",
|
||||
|
||||
"id": "abc3361f-bb2d-491f-aba3-cd51c19a299b",
|
||||
"alias": "MegaMenuApplicationCustomizer",
|
||||
"componentType": "Extension",
|
||||
"extensionType": "ApplicationCustomizer",
|
||||
|
||||
// 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
|
||||
}
|
||||
28
lib/extensions/megaMenu/MegaMenuRenderer.d.ts
vendored
Normal file
28
lib/extensions/megaMenu/MegaMenuRenderer.d.ts
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import { ApplicationCustomizerContext } from '@microsoft/sp-application-base';
|
||||
import { IMenuItem } from '../../services/IMenuItem';
|
||||
import { IMegaMenuApplicationCustomizerProperties } from './MegaMenuApplicationCustomizer';
|
||||
export declare class MegaMenuRenderer {
|
||||
private context;
|
||||
private menuItems;
|
||||
private updateCallback;
|
||||
private _settingsPanel?;
|
||||
constructor(context: ApplicationCustomizerContext, menuItems: IMenuItem[], updateCallback: (data: IMegaMenuApplicationCustomizerProperties) => void);
|
||||
render(container: HTMLElement): void;
|
||||
private createSettingsItem();
|
||||
private openSettings();
|
||||
private createTopLevelItem(item);
|
||||
private createTopLevelElement(item);
|
||||
private createMegaMenu(parentItem);
|
||||
private createCategorySection(item);
|
||||
private attachEventListeners();
|
||||
private attachKeyboardNavigation(heading, megaMenu);
|
||||
private attachMouseEvents(heading, megaMenu);
|
||||
private attachFocusManagement(heading, megaMenu);
|
||||
private attachGlobalKeyboardNavigation();
|
||||
private openMegaMenu(trigger, menu);
|
||||
private closeMegaMenu(trigger, menu);
|
||||
private toggleMegaMenu(trigger, menu);
|
||||
private closeAllMegaMenus();
|
||||
private focusFirstLink(megaMenu);
|
||||
private createScreenReaderAnnouncer();
|
||||
}
|
||||
372
lib/extensions/megaMenu/MegaMenuRenderer.js
Normal file
372
lib/extensions/megaMenu/MegaMenuRenderer.js
Normal file
@@ -0,0 +1,372 @@
|
||||
// tslint:disable:max-line-length
|
||||
// tslint:disable:match-default-export-name
|
||||
// tslint:disable:typedef
|
||||
// tslint:disable:variable-name
|
||||
import { SPPermission } from '@microsoft/sp-page-context';
|
||||
import { MegaMenuSettingsPanel } from './MegaMenuSettings';
|
||||
var MegaMenuRenderer = (function () {
|
||||
function MegaMenuRenderer(context, menuItems, updateCallback) {
|
||||
this.context = context;
|
||||
this.menuItems = menuItems;
|
||||
this.updateCallback = updateCallback;
|
||||
}
|
||||
MegaMenuRenderer.prototype.render = function (container) {
|
||||
var _this = this;
|
||||
// Clear any existing content
|
||||
container.innerHTML = '';
|
||||
container.id = 'CustomNavigation';
|
||||
// Create the main nav element
|
||||
var nav = document.createElement('nav');
|
||||
nav.id = 'Mega-Menu';
|
||||
nav.className = 'mega-menu-main';
|
||||
nav.setAttribute('role', 'navigation');
|
||||
nav.setAttribute('aria-label', 'Hauptnavigation');
|
||||
// Create the top-level menubar
|
||||
var topLevelUl = document.createElement('ul');
|
||||
topLevelUl.setAttribute('role', 'menubar');
|
||||
// Process each top-level menu item
|
||||
this.menuItems.forEach(function (topLevelItem) {
|
||||
var topLevelLi = _this.createTopLevelItem(topLevelItem);
|
||||
topLevelUl.appendChild(topLevelLi);
|
||||
});
|
||||
// Only if current user has ManageWeb permissions in this website can they access the settings
|
||||
if (this.context.pageContext.web.permissions.hasPermission(SPPermission.manageWeb)) {
|
||||
topLevelUl.appendChild(this.createSettingsItem());
|
||||
}
|
||||
nav.appendChild(topLevelUl);
|
||||
container.appendChild(nav);
|
||||
// Attach accessibility event listeners after rendering
|
||||
this.attachEventListeners();
|
||||
this.createScreenReaderAnnouncer();
|
||||
};
|
||||
MegaMenuRenderer.prototype.createSettingsItem = function () {
|
||||
var _this = this;
|
||||
var li = document.createElement('li');
|
||||
li.setAttribute('role', 'none');
|
||||
// Verwenden eines Links-ähnlichen Buttons damit Styling identisch zu Top-Level Items ist
|
||||
var btn = document.createElement('button');
|
||||
btn.type = 'button';
|
||||
btn.className = 'menu-item-link menu-item-settings'; // reuse same base styles
|
||||
btn.setAttribute('role', 'menuitem');
|
||||
btn.setAttribute('tabindex', '0');
|
||||
btn.setAttribute('aria-haspopup', 'false');
|
||||
btn.setAttribute('aria-label', 'Einstellungen');
|
||||
btn.title = 'Einstellungen';
|
||||
// Nur EIN Icon: Wenn Fabric Icons geladen sind, zeigt ms-Icon das Symbol. Fallback via aria-label für Screenreader
|
||||
var icon = document.createElement('span');
|
||||
icon.className = 'ms-Icon ms-Icon--Settings menu-item-settings__icon';
|
||||
icon.setAttribute('aria-hidden', 'true');
|
||||
btn.appendChild(icon);
|
||||
btn.addEventListener('click', function () { return _this.openSettings(); });
|
||||
btn.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
_this.openSettings();
|
||||
}
|
||||
});
|
||||
li.appendChild(btn);
|
||||
return li;
|
||||
};
|
||||
MegaMenuRenderer.prototype.openSettings = function () {
|
||||
if (!this._settingsPanel) {
|
||||
this._settingsPanel = new MegaMenuSettingsPanel(this.context, this.updateCallback);
|
||||
}
|
||||
this._settingsPanel.open();
|
||||
};
|
||||
// Panel logic moved to MegaMenuSettingsPanel
|
||||
MegaMenuRenderer.prototype.createTopLevelItem = function (item) {
|
||||
var li = document.createElement('li');
|
||||
li.setAttribute('role', 'none');
|
||||
// Create the top-level element (link or span)
|
||||
var topElement = this.createTopLevelElement(item);
|
||||
li.appendChild(topElement);
|
||||
// If the item has children, create the mega menu
|
||||
if (item.hasChildren() && item.items && item.items.length > 0) {
|
||||
var megaMenu = this.createMegaMenu(item);
|
||||
li.appendChild(megaMenu);
|
||||
}
|
||||
return li;
|
||||
};
|
||||
MegaMenuRenderer.prototype.createTopLevelElement = function (item) {
|
||||
var element;
|
||||
if (item.url) {
|
||||
// Create as link
|
||||
element = document.createElement('a');
|
||||
element.href = item.url;
|
||||
element.className = 'menu-item-link';
|
||||
}
|
||||
else {
|
||||
// Create as span (no link)
|
||||
element = document.createElement('span');
|
||||
element.className = 'menu-item-text';
|
||||
element.setAttribute('tabindex', '0');
|
||||
}
|
||||
element.setAttribute('role', 'menuitem');
|
||||
element.setAttribute('aria-haspopup', 'true');
|
||||
element.setAttribute('aria-expanded', 'false');
|
||||
element.textContent = item.label;
|
||||
if (item.hoverText) {
|
||||
element.title = item.hoverText;
|
||||
}
|
||||
return element;
|
||||
};
|
||||
MegaMenuRenderer.prototype.createMegaMenu = function (parentItem) {
|
||||
var _this = this;
|
||||
var megaMenuDiv = document.createElement('div');
|
||||
megaMenuDiv.className = 'mega-menu';
|
||||
megaMenuDiv.setAttribute('role', 'menu');
|
||||
megaMenuDiv.setAttribute('aria-label', parentItem.label + " Unterkategorien");
|
||||
var gridDiv = document.createElement('div');
|
||||
gridDiv.className = 'mega-menu-grid';
|
||||
// Process second-level items (categories)
|
||||
if (parentItem.items) {
|
||||
parentItem.items.forEach(function (secondLevelItem) {
|
||||
var categoryDiv = _this.createCategorySection(secondLevelItem);
|
||||
gridDiv.appendChild(categoryDiv);
|
||||
});
|
||||
}
|
||||
megaMenuDiv.appendChild(gridDiv);
|
||||
return megaMenuDiv;
|
||||
};
|
||||
MegaMenuRenderer.prototype.createCategorySection = function (item) {
|
||||
var categoryDiv = document.createElement('div');
|
||||
categoryDiv.className = 'mega-menu-category';
|
||||
// Create the category header (h3)
|
||||
var h3 = document.createElement('h3');
|
||||
if (item.url) {
|
||||
// Category header as link
|
||||
var link = document.createElement('a');
|
||||
link.href = item.url;
|
||||
link.textContent = item.label;
|
||||
if (item.hoverText) {
|
||||
link.title = item.hoverText;
|
||||
}
|
||||
h3.appendChild(link);
|
||||
}
|
||||
else {
|
||||
// Category header as span (no link)
|
||||
var span = document.createElement('span');
|
||||
span.textContent = item.label;
|
||||
if (item.hoverText) {
|
||||
span.title = item.hoverText;
|
||||
}
|
||||
h3.appendChild(span);
|
||||
}
|
||||
categoryDiv.appendChild(h3);
|
||||
// Create the third-level items list if they exist
|
||||
if (item.hasChildren() && item.items && item.items.length > 0) {
|
||||
var ul_1 = document.createElement('ul');
|
||||
item.items.forEach(function (thirdLevelItem) {
|
||||
var li = document.createElement('li');
|
||||
var link = document.createElement('a');
|
||||
link.href = thirdLevelItem.url || '#';
|
||||
link.textContent = thirdLevelItem.label;
|
||||
if (thirdLevelItem.hoverText) {
|
||||
link.title = thirdLevelItem.hoverText;
|
||||
}
|
||||
li.appendChild(link);
|
||||
ul_1.appendChild(li);
|
||||
});
|
||||
categoryDiv.appendChild(ul_1);
|
||||
}
|
||||
return categoryDiv;
|
||||
};
|
||||
MegaMenuRenderer.prototype.attachEventListeners = function () {
|
||||
var headings = document.querySelectorAll('#Mega-Menu > ul > li > a, #Mega-Menu > ul > li > span[role="menuitem"]');
|
||||
for (var i = 0; i < headings.length; i++) {
|
||||
var heading = headings[i];
|
||||
var megaMenu = heading.nextElementSibling;
|
||||
if (megaMenu && megaMenu.classList.contains('mega-menu')) {
|
||||
this.attachKeyboardNavigation(heading, megaMenu);
|
||||
this.attachMouseEvents(heading, megaMenu);
|
||||
this.attachFocusManagement(heading, megaMenu);
|
||||
}
|
||||
}
|
||||
// Global keyboard navigation
|
||||
this.attachGlobalKeyboardNavigation();
|
||||
};
|
||||
MegaMenuRenderer.prototype.attachKeyboardNavigation = function (heading, megaMenu) {
|
||||
var _this = this;
|
||||
heading.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Enter') {
|
||||
// Enter: Navigation (nur bei Links ohne Mega-Menu-Override)
|
||||
if (heading.tagName === 'A') {
|
||||
// Lasse normale Link-Navigation zu (KEIN preventDefault!)
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// Bei span: Toggle Menu
|
||||
e.preventDefault();
|
||||
_this.toggleMegaMenu(heading, megaMenu);
|
||||
}
|
||||
}
|
||||
else if (e.key === ' ') {
|
||||
// Space: Toggle Dropdown (immer)
|
||||
e.preventDefault();
|
||||
_this.toggleMegaMenu(heading, megaMenu);
|
||||
}
|
||||
else if (e.key === 'ArrowDown') {
|
||||
// Pfeil runter: Menü öffnen + erster Link
|
||||
e.preventDefault();
|
||||
_this.openMegaMenu(heading, megaMenu);
|
||||
_this.focusFirstLink(megaMenu);
|
||||
}
|
||||
else if (e.key === 'ArrowUp') {
|
||||
// Pfeil hoch: Menü schließen
|
||||
e.preventDefault();
|
||||
_this.closeMegaMenu(heading, megaMenu);
|
||||
}
|
||||
else if (e.key === 'Escape') {
|
||||
// Escape: Menü schließen
|
||||
e.preventDefault();
|
||||
_this.closeMegaMenu(heading, megaMenu);
|
||||
heading.focus();
|
||||
}
|
||||
});
|
||||
// Click Event für Top-Level Links - NORMALE Navigation erlauben
|
||||
if (heading.tagName === 'A') {
|
||||
heading.addEventListener('click', function (e) {
|
||||
// Links sollen normal navigieren, nicht das Mega-Menu toglen
|
||||
// Wenn der User das Menu öffnen will, soll er Space oder Pfeil↓ nutzen
|
||||
console.log('Link geklickt:', heading.href);
|
||||
// KEIN preventDefault() - normale Link-Navigation
|
||||
});
|
||||
}
|
||||
// Focus Management - KEIN automatisches Öffnen oder Schließen
|
||||
heading.addEventListener('focus', function () {
|
||||
console.log('Focus auf:', heading.textContent);
|
||||
// Einfach nur fokussiert - keine automatischen Aktionen!
|
||||
});
|
||||
};
|
||||
MegaMenuRenderer.prototype.attachMouseEvents = function (heading, megaMenu) {
|
||||
var _this = this;
|
||||
var parentLi = heading.parentElement;
|
||||
parentLi.addEventListener('mouseenter', function () {
|
||||
_this.openMegaMenu(heading, megaMenu);
|
||||
});
|
||||
parentLi.addEventListener('mouseleave', function () {
|
||||
_this.closeMegaMenu(heading, megaMenu);
|
||||
});
|
||||
};
|
||||
MegaMenuRenderer.prototype.attachFocusManagement = function (heading, megaMenu) {
|
||||
var _this = this;
|
||||
// Focus-Verlust-Behandlung - vereinfacht
|
||||
megaMenu.addEventListener('focusout', function (e) {
|
||||
// Kurz warten, um zu prüfen ob Focus innerhalb des Mega-Menus bleibt
|
||||
setTimeout(function () {
|
||||
var focusedElement = document.activeElement;
|
||||
var isInsideThisMenu = megaMenu.contains(focusedElement);
|
||||
var isOnThisTrigger = focusedElement === heading;
|
||||
var isInAnyMegaMenu = focusedElement.closest('.mega-menu');
|
||||
var isOnAnyTopLevel = focusedElement.closest('#Mega-Menu > ul > li > a, #Mega-Menu > ul > li > span');
|
||||
// Nur schließen wenn Focus komplett außerhalb der Navigation ist
|
||||
if (!isInsideThisMenu && !isOnThisTrigger && !isInAnyMegaMenu && !isOnAnyTopLevel) {
|
||||
console.log('Schließe Menu wegen Focus-Verlust');
|
||||
_this.closeMegaMenu(heading, megaMenu);
|
||||
}
|
||||
}, 150);
|
||||
});
|
||||
};
|
||||
MegaMenuRenderer.prototype.attachGlobalKeyboardNavigation = function () {
|
||||
var _this = this;
|
||||
document.addEventListener('keydown', function (e) {
|
||||
var activeElement = document.activeElement;
|
||||
if (e.key === 'Escape') {
|
||||
var openMenu = document.querySelector('.mega-menu[aria-expanded="true"]');
|
||||
if (openMenu) {
|
||||
var triggerLink = openMenu.previousElementSibling;
|
||||
_this.closeMegaMenu(triggerLink, openMenu);
|
||||
triggerLink.focus();
|
||||
}
|
||||
}
|
||||
// Tab-Navigation: Nur bei spezifischen Übergängen eingreifen
|
||||
if (e.key === 'Tab') {
|
||||
// Von Top-Level zum ersten Link im offenen Menu
|
||||
if (!e.shiftKey) {
|
||||
var currentTopLevel = activeElement.closest('#Mega-Menu > ul > li > a, #Mega-Menu > ul > li > span');
|
||||
if (currentTopLevel) {
|
||||
var parentLi = currentTopLevel.closest('li');
|
||||
var megaMenu = parentLi.querySelector('.mega-menu.js-open');
|
||||
if (megaMenu) {
|
||||
// Nur eingreifen wenn wir vom Trigger weg-tabben
|
||||
e.preventDefault();
|
||||
var firstLink = megaMenu.querySelector('a');
|
||||
if (firstLink) {
|
||||
firstLink.focus();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Shift+Tab: Vom ersten Link im Menu zurück zum Trigger
|
||||
if (e.shiftKey) {
|
||||
var megaMenu = activeElement.closest('.mega-menu');
|
||||
if (megaMenu && megaMenu.classList.contains('js-open')) {
|
||||
var allLinksInMenu = megaMenu.querySelectorAll('a');
|
||||
var firstLinkInMenu = allLinksInMenu[0];
|
||||
// Nur eingreifen wenn wir beim ersten Link sind
|
||||
if (activeElement === firstLinkInMenu) {
|
||||
e.preventDefault();
|
||||
var triggerElement = megaMenu.previousElementSibling;
|
||||
triggerElement.focus();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Ansonsten: Normale Tab-Navigation nicht unterbrechen!
|
||||
}
|
||||
});
|
||||
};
|
||||
MegaMenuRenderer.prototype.openMegaMenu = function (trigger, menu) {
|
||||
trigger.setAttribute('aria-expanded', 'true');
|
||||
menu.setAttribute('aria-expanded', 'true');
|
||||
menu.classList.add('js-open');
|
||||
console.log('Menu geöffnet:', trigger.textContent);
|
||||
};
|
||||
MegaMenuRenderer.prototype.closeMegaMenu = function (trigger, menu) {
|
||||
trigger.setAttribute('aria-expanded', 'false');
|
||||
menu.setAttribute('aria-expanded', 'false');
|
||||
menu.classList.remove('js-open');
|
||||
console.log('Menu geschlossen:', trigger.textContent);
|
||||
};
|
||||
MegaMenuRenderer.prototype.toggleMegaMenu = function (trigger, menu) {
|
||||
var isOpen = trigger.getAttribute('aria-expanded') === 'true';
|
||||
if (isOpen) {
|
||||
this.closeMegaMenu(trigger, menu);
|
||||
}
|
||||
else {
|
||||
this.closeAllMegaMenus();
|
||||
this.openMegaMenu(trigger, menu);
|
||||
}
|
||||
};
|
||||
MegaMenuRenderer.prototype.closeAllMegaMenus = function () {
|
||||
var allTriggers = document.querySelectorAll('#Mega-Menu > ul > li > a[aria-expanded="true"], #Mega-Menu > ul > li > span[aria-expanded="true"]');
|
||||
for (var i = 0; i < allTriggers.length; i++) {
|
||||
var trigger = allTriggers[i];
|
||||
var menu = trigger.nextElementSibling;
|
||||
if (menu) {
|
||||
this.closeMegaMenu(trigger, menu);
|
||||
}
|
||||
}
|
||||
};
|
||||
// removed unused closeOtherMegaMenus (was previously declared but not used)
|
||||
MegaMenuRenderer.prototype.focusFirstLink = function (megaMenu) {
|
||||
var firstLink = megaMenu.querySelector('a');
|
||||
if (firstLink) {
|
||||
firstLink.focus();
|
||||
}
|
||||
};
|
||||
MegaMenuRenderer.prototype.createScreenReaderAnnouncer = function () {
|
||||
// Screenreader-Ankündigungen
|
||||
var srAnnouncer = document.createElement('div');
|
||||
srAnnouncer.setAttribute('aria-live', 'polite');
|
||||
srAnnouncer.setAttribute('aria-atomic', 'true');
|
||||
srAnnouncer.className = 'sr-only';
|
||||
document.body.appendChild(srAnnouncer);
|
||||
console.log('Screenreader-Ankündigungen sind jetzt bereit');
|
||||
};
|
||||
return MegaMenuRenderer;
|
||||
}());
|
||||
export { MegaMenuRenderer };
|
||||
|
||||
//# sourceMappingURL=MegaMenuRenderer.js.map
|
||||
1
lib/extensions/megaMenu/MegaMenuRenderer.js.map
Normal file
1
lib/extensions/megaMenu/MegaMenuRenderer.js.map
Normal file
File diff suppressed because one or more lines are too long
25
lib/extensions/megaMenu/MegaMenuSettings.d.ts
vendored
Normal file
25
lib/extensions/megaMenu/MegaMenuSettings.d.ts
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { ApplicationCustomizerContext } from '@microsoft/sp-application-base';
|
||||
import { IMegaMenuApplicationCustomizerProperties } from './MegaMenuApplicationCustomizer';
|
||||
export declare class MegaMenuSettingsPanel {
|
||||
private context;
|
||||
private dataUpdated;
|
||||
private _service;
|
||||
private _ucaId;
|
||||
private _panelElement;
|
||||
private _overlayElement;
|
||||
constructor(context: ApplicationCustomizerContext, dataUpdated: (data: IMegaMenuApplicationCustomizerProperties) => void);
|
||||
open(): Promise<void>;
|
||||
close(): void;
|
||||
private readApplicationCustomizerProps();
|
||||
private saveApplicationCustomizerProps(componentProps);
|
||||
private _createPanel(props);
|
||||
private _getMarkup(termSet, cssUrl);
|
||||
private _save();
|
||||
/**
|
||||
* Hält den Fokus innerhalb des Settings-Panels gefangen (Focus Trapping).
|
||||
* Wichtig für Accessibility: Verhindert, dass Tab-Navigation aus dem modalen Dialog herausführt.
|
||||
* Bei Tab am letzten Element → springt zum ersten, bei Shift+Tab am ersten → springt zum letzten.
|
||||
*/
|
||||
private _trapFocus(e);
|
||||
private _escape(value);
|
||||
}
|
||||
223
lib/extensions/megaMenu/MegaMenuSettings.js
Normal file
223
lib/extensions/megaMenu/MegaMenuSettings.js
Normal file
@@ -0,0 +1,223 @@
|
||||
// tslint:disable:max-line-length export-name
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [0, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
import { UserCustomActionMegaMenuId } from './MegaMenuApplicationCustomizer';
|
||||
import { UserCustomActionService } from '../../services/UserCustomActionService/UserCustomActionService';
|
||||
import { UserCustomActionScope } from '../../services/UserCustomActionService/UserCustomActionScope';
|
||||
var MegaMenuSettingsPanel = (function () {
|
||||
function MegaMenuSettingsPanel(context, dataUpdated) {
|
||||
this.context = context;
|
||||
this.dataUpdated = dataUpdated;
|
||||
this._panelElement = undefined;
|
||||
this._overlayElement = undefined;
|
||||
this._service = new UserCustomActionService(this.context);
|
||||
}
|
||||
MegaMenuSettingsPanel.prototype.open = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var currentProps;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
if (this._panelElement) {
|
||||
return [2 /*return*/];
|
||||
}
|
||||
return [4 /*yield*/, this.readApplicationCustomizerProps()];
|
||||
case 1:
|
||||
currentProps = _a.sent();
|
||||
this._createPanel(currentProps);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MegaMenuSettingsPanel.prototype.close = function () {
|
||||
if (this._panelElement) {
|
||||
this._panelElement.remove();
|
||||
this._panelElement = undefined;
|
||||
}
|
||||
if (this._overlayElement) {
|
||||
this._overlayElement.remove();
|
||||
this._overlayElement = undefined;
|
||||
}
|
||||
// Fokus entfernen (kein sichtbarer Fokus-Rahmen nach Dialog-Schließung)
|
||||
document.body.focus();
|
||||
document.body.blur();
|
||||
};
|
||||
MegaMenuSettingsPanel.prototype.readApplicationCustomizerProps = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var ucas, candidates, uca;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this._service.getUserCustomActions(UserCustomActionScope.Site)];
|
||||
case 1:
|
||||
ucas = _a.sent();
|
||||
candidates = ucas.filter(function (uca) { return uca.ClientSideComponentId === UserCustomActionMegaMenuId; });
|
||||
if (candidates.length) {
|
||||
uca = candidates[0];
|
||||
this._ucaId = uca.Id;
|
||||
return [2 /*return*/, JSON.parse(uca.ClientSideComponentProperties)];
|
||||
}
|
||||
else {
|
||||
console.error('UserCustomAction für das Megamenü nicht gefunden. Alles ist sinnlos.');
|
||||
return [2 /*return*/, {
|
||||
termSetName: '',
|
||||
cssUrl: ''
|
||||
}];
|
||||
}
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MegaMenuSettingsPanel.prototype.saveApplicationCustomizerProps = function (componentProps) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var newUserCustomActionsProperty, e_1;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
_a.trys.push([0, 2, , 3]);
|
||||
newUserCustomActionsProperty = {
|
||||
ClientSideComponentProperties: JSON.stringify(componentProps)
|
||||
};
|
||||
return [4 /*yield*/, this._service.updateUserCustomAction(UserCustomActionScope.Site, this._ucaId, newUserCustomActionsProperty)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
this.dataUpdated(componentProps);
|
||||
return [3 /*break*/, 3];
|
||||
case 2:
|
||||
e_1 = _a.sent();
|
||||
console.error(e_1);
|
||||
return [3 /*break*/, 3];
|
||||
case 3: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MegaMenuSettingsPanel.prototype._createPanel = function (props) {
|
||||
var _this = this;
|
||||
var overlay = document.createElement('div');
|
||||
overlay.className = 'mm-settings-overlay';
|
||||
overlay.tabIndex = -1;
|
||||
overlay.onclick = function () { return _this.close(); };
|
||||
this._overlayElement = overlay;
|
||||
var panel = document.createElement('div');
|
||||
panel.className = 'mm-settings-panel';
|
||||
panel.setAttribute('role', 'dialog');
|
||||
panel.setAttribute('aria-modal', 'true');
|
||||
panel.setAttribute('aria-label', 'MegaMenu Einstellungen');
|
||||
panel.innerHTML = this._getMarkup(props.termSetName, props.cssUrl);
|
||||
this._panelElement = panel;
|
||||
document.body.appendChild(overlay);
|
||||
document.body.appendChild(panel);
|
||||
var closeBtn = panel.querySelector('.mm-settings-close');
|
||||
var cancelBtn = panel.querySelector('.mm-settings-cancel');
|
||||
var saveBtn = panel.querySelector('.mm-settings-save');
|
||||
var firstInput = panel.querySelector('#mm-setting-termset');
|
||||
if (closeBtn) {
|
||||
closeBtn.onclick = function () { return _this.close(); };
|
||||
}
|
||||
if (cancelBtn) {
|
||||
cancelBtn.onclick = function () { return _this.close(); };
|
||||
}
|
||||
if (saveBtn) {
|
||||
saveBtn.onclick = function () { return _this._save(); };
|
||||
}
|
||||
panel.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Escape') {
|
||||
e.preventDefault();
|
||||
_this.close();
|
||||
}
|
||||
else if (e.key === 'Tab') {
|
||||
_this._trapFocus(e);
|
||||
}
|
||||
});
|
||||
setTimeout(function () { if (firstInput) {
|
||||
firstInput.focus();
|
||||
} }, 0);
|
||||
};
|
||||
MegaMenuSettingsPanel.prototype._getMarkup = function (termSet, cssUrl) {
|
||||
return "<div class='mm-settings-header'>\n <h2 class='mm-settings-title'>Einstellungen</h2>\n <button type='button' class='mm-settings-close' aria-label='Schlie\u00DFen'>\u00D7</button>\n </div>\n <div class='mm-settings-body'>\n <div class='mm-settings-field'>\n <label for='mm-setting-termset'>Name des Navigations-Termsets</label>\n <input id='mm-setting-termset' type='text' value='" + this._escape(termSet) + "' />\n </div>\n <div class='mm-settings-field'>\n <label for='mm-setting-css'>Pfad zu zus\u00E4tzlicher CSS-Datei</label>\n <input id='mm-setting-css' type='text' value='" + this._escape(cssUrl) + "' />\n </div>\n </div>\n <div class='mm-settings-footer'>\n <button type='button' class='mm-settings-save ms-Button ms-Button--primary'><span>Speichern</span></button>\n <button type='button' class='mm-settings-cancel ms-Button'><span>Abbrechen</span></button>\n </div>";
|
||||
};
|
||||
MegaMenuSettingsPanel.prototype._save = function () {
|
||||
if (!this._panelElement) {
|
||||
return;
|
||||
}
|
||||
var termSetInput = this._panelElement.querySelector('#mm-setting-termset');
|
||||
var cssInput = this._panelElement.querySelector('#mm-setting-css');
|
||||
this.saveApplicationCustomizerProps({
|
||||
termSetName: termSetInput && termSetInput.value ? termSetInput.value : '',
|
||||
cssUrl: cssInput && cssInput.value ? cssInput.value : ''
|
||||
});
|
||||
this.close();
|
||||
};
|
||||
/**
|
||||
* Hält den Fokus innerhalb des Settings-Panels gefangen (Focus Trapping).
|
||||
* Wichtig für Accessibility: Verhindert, dass Tab-Navigation aus dem modalen Dialog herausführt.
|
||||
* Bei Tab am letzten Element → springt zum ersten, bei Shift+Tab am ersten → springt zum letzten.
|
||||
*/
|
||||
MegaMenuSettingsPanel.prototype._trapFocus = function (e) {
|
||||
if (!this._panelElement) {
|
||||
return;
|
||||
}
|
||||
var focusable = this._panelElement.querySelectorAll('button, input');
|
||||
if (!focusable || focusable.length === 0) {
|
||||
return;
|
||||
}
|
||||
var first = focusable[0];
|
||||
var last = focusable[focusable.length - 1];
|
||||
var active = document.activeElement;
|
||||
if (e.shiftKey && active === first) {
|
||||
e.preventDefault();
|
||||
last.focus();
|
||||
}
|
||||
else if (!e.shiftKey && active === last) {
|
||||
e.preventDefault();
|
||||
first.focus();
|
||||
}
|
||||
};
|
||||
MegaMenuSettingsPanel.prototype._escape = function (value) {
|
||||
if (value) {
|
||||
return value.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
return MegaMenuSettingsPanel;
|
||||
}());
|
||||
export { MegaMenuSettingsPanel };
|
||||
|
||||
//# sourceMappingURL=MegaMenuSettings.js.map
|
||||
1
lib/extensions/megaMenu/MegaMenuSettings.js.map
Normal file
1
lib/extensions/megaMenu/MegaMenuSettings.js.map
Normal file
File diff suppressed because one or more lines are too long
5
lib/extensions/megaMenu/loc/en-us.js
Normal file
5
lib/extensions/megaMenu/loc/en-us.js
Normal file
@@ -0,0 +1,5 @@
|
||||
define([], function() {
|
||||
return {
|
||||
"Title": "MegaMenuApplicationCustomizer"
|
||||
}
|
||||
});
|
||||
4
lib/index.d.ts
vendored
Normal file
4
lib/index.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export { TaxonomyNavigationService } from './services/TaxonomyNavigationService';
|
||||
export { MegaMenuRenderer } from './extensions/megaMenu/MegaMenuRenderer';
|
||||
export { UserCustomActionService } from './services/UserCustomActionService/UserCustomActionService';
|
||||
export { UserCustomActionScope } from './services/UserCustomActionService/UserCustomActionScope';
|
||||
17
lib/index.js
Normal file
17
lib/index.js
Normal file
@@ -0,0 +1,17 @@
|
||||
// tslint:disable:max-line-length no-any
|
||||
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
||||
// Export services for classic SharePoint usage
|
||||
export { TaxonomyNavigationService } from './services/TaxonomyNavigationService';
|
||||
export { MegaMenuRenderer } from './extensions/megaMenu/MegaMenuRenderer';
|
||||
export { UserCustomActionService } from './services/UserCustomActionService/UserCustomActionService';
|
||||
export { UserCustomActionScope } from './services/UserCustomActionService/UserCustomActionScope';
|
||||
if (typeof window !== 'undefined') {
|
||||
window.__megaMenuServices = {
|
||||
TaxonomyNavigationService: require('./services/TaxonomyNavigationService').TaxonomyNavigationService,
|
||||
MegaMenuRenderer: require('./extensions/megaMenu/MegaMenuRenderer').MegaMenuRenderer,
|
||||
UserCustomActionService: require('./services/UserCustomActionService/UserCustomActionService').UserCustomActionService,
|
||||
UserCustomActionScope: require('./services/UserCustomActionService/UserCustomActionScope').UserCustomActionScope
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
lib/index.js.map
Normal file
1
lib/index.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,wFAAwF;AAExF,+CAA+C;AAC/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,4DAA4D,CAAC;AACrG,OAAO,EAAE,qBAAqB,EAAE,MAAM,0DAA0D,CAAC;AAKjG,EAAE,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC;IAChC,MAAM,CAAC,kBAAkB,GAAG;QACxB,yBAAyB,EAAE,OAAO,CAAC,sCAAsC,CAAC,CAAC,yBAAyB;QACpG,gBAAgB,EAAE,OAAO,CAAC,wCAAwC,CAAC,CAAC,gBAAgB;QACpF,uBAAuB,EAAE,OAAO,CAAC,4DAA4D,CAAC,CAAC,uBAAuB;QACtH,qBAAqB,EAAE,OAAO,CAAC,0DAA0D,CAAC,CAAC,qBAAqB;KACnH,CAAC;AACN,CAAC","file":"index.js","sourcesContent":["// tslint:disable:max-line-length no-any\r\n// A file is required to be in the root of the /src directory by the TypeScript compiler\r\n\r\n// Export services for classic SharePoint usage\r\nexport { TaxonomyNavigationService } from './services/TaxonomyNavigationService';\r\nexport { MegaMenuRenderer } from './extensions/megaMenu/MegaMenuRenderer';\r\nexport { UserCustomActionService } from './services/UserCustomActionService/UserCustomActionService';\r\nexport { UserCustomActionScope } from './services/UserCustomActionService/UserCustomActionScope';\r\n\r\n// Expose services globally for classic JavaScript consumption\r\ndeclare var window: any;\r\n\r\nif (typeof window !== 'undefined') {\r\n window.__megaMenuServices = {\r\n TaxonomyNavigationService: require('./services/TaxonomyNavigationService').TaxonomyNavigationService,\r\n MegaMenuRenderer: require('./extensions/megaMenu/MegaMenuRenderer').MegaMenuRenderer,\r\n UserCustomActionService: require('./services/UserCustomActionService/UserCustomActionService').UserCustomActionService,\r\n UserCustomActionScope: require('./services/UserCustomActionService/UserCustomActionScope').UserCustomActionScope\r\n };\r\n}\r\n"],"sourceRoot":"..\\src"}
|
||||
10
lib/services/IMenuItem.d.ts
vendored
Normal file
10
lib/services/IMenuItem.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
export interface IMenuItem {
|
||||
id: string;
|
||||
label: string;
|
||||
icon?: string;
|
||||
hoverText: string;
|
||||
url?: string;
|
||||
pathDepth: number;
|
||||
items?: IMenuItem[];
|
||||
hasChildren: () => boolean;
|
||||
}
|
||||
3
lib/services/IMenuItem.js
Normal file
3
lib/services/IMenuItem.js
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=IMenuItem.js.map
|
||||
1
lib/services/IMenuItem.js.map
Normal file
1
lib/services/IMenuItem.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"services/IMenuItem.js","sourcesContent":[],"sourceRoot":"..\\..\\src"}
|
||||
9
lib/services/IPickerTerm.d.ts
vendored
Normal file
9
lib/services/IPickerTerm.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export interface IPickerTerm {
|
||||
name: string;
|
||||
key: string;
|
||||
path: string;
|
||||
termSet: string;
|
||||
termSetName?: string;
|
||||
}
|
||||
export interface IPickerTerms extends Array<IPickerTerm> {
|
||||
}
|
||||
3
lib/services/IPickerTerm.js
Normal file
3
lib/services/IPickerTerm.js
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=IPickerTerm.js.map
|
||||
1
lib/services/IPickerTerm.js.map
Normal file
1
lib/services/IPickerTerm.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"services/IPickerTerm.js","sourcesContent":[],"sourceRoot":"..\\..\\src"}
|
||||
84
lib/services/ISPTermStorePickerService.d.ts
vendored
Normal file
84
lib/services/ISPTermStorePickerService.d.ts
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Interfaces for Term store, groups and term sets
|
||||
* This code is a copy from the library @pnp/sp-dev-fx-controls-react
|
||||
*/
|
||||
export interface ITermStore {
|
||||
_ObjectType_: string;
|
||||
_ObjectIdentity_: string;
|
||||
Id: string;
|
||||
Name: string;
|
||||
Groups: IGroups;
|
||||
}
|
||||
export interface IGroups {
|
||||
_ObjectType_: string;
|
||||
_Child_Items_: IGroup[];
|
||||
}
|
||||
export interface IGroup {
|
||||
_ObjectType_: string;
|
||||
_ObjectIdentity_: string;
|
||||
TermSets: ITermSets;
|
||||
Id: string;
|
||||
Name: string;
|
||||
IsSystemGroup: boolean;
|
||||
}
|
||||
export interface ITermSets {
|
||||
_ObjectType_: string;
|
||||
_Child_Items_: ITermSet[];
|
||||
}
|
||||
export interface ITermSet {
|
||||
_ObjectType_: string;
|
||||
_ObjectIdentity_: string;
|
||||
Id: string;
|
||||
CustomSortOrder?: string;
|
||||
Name: string;
|
||||
Description: string;
|
||||
Names: ITermSetNames;
|
||||
Terms?: ITerm[];
|
||||
}
|
||||
export interface ITermSetMinimal {
|
||||
_ObjectType_?: string;
|
||||
_ObjectIdentity_?: string;
|
||||
Id: string;
|
||||
Name: string;
|
||||
}
|
||||
export interface ITermSetNames {
|
||||
[locale: string]: string;
|
||||
}
|
||||
/**
|
||||
* Interfaces for the terms
|
||||
*/
|
||||
export interface ITerms {
|
||||
_ObjectType_: string;
|
||||
_Child_Items_: ITerm[];
|
||||
}
|
||||
/**
|
||||
* Term
|
||||
*/
|
||||
export interface ITerm {
|
||||
_ObjectType_: string;
|
||||
_ObjectIdentity_: string;
|
||||
Id: string;
|
||||
Name: string;
|
||||
Description: string;
|
||||
IsDeprecated: boolean;
|
||||
IsAvailableForTagging: boolean;
|
||||
IsRoot: boolean;
|
||||
PathOfTerm: string;
|
||||
TermSet: ITermSetMinimal;
|
||||
CustomSortOrderIndex?: number;
|
||||
PathDepth?: number;
|
||||
ParentId?: string;
|
||||
TermsCount?: number;
|
||||
LocalCustomProperties?: {
|
||||
[property: string]: any;
|
||||
};
|
||||
}
|
||||
export interface ISuggestTerm {
|
||||
Id: string;
|
||||
DefaultLabel: string;
|
||||
Description: string;
|
||||
IsKeyword: boolean;
|
||||
IsSynonym: boolean;
|
||||
Paths: Array<string>;
|
||||
Synonyms: string;
|
||||
}
|
||||
3
lib/services/ISPTermStorePickerService.js
Normal file
3
lib/services/ISPTermStorePickerService.js
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=ISPTermStorePickerService.js.map
|
||||
1
lib/services/ISPTermStorePickerService.js.map
Normal file
1
lib/services/ISPTermStorePickerService.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"services/ISPTermStorePickerService.js","sourcesContent":[],"sourceRoot":"..\\..\\src"}
|
||||
7
lib/services/ISPTermStorePickerServiceProps.d.ts
vendored
Normal file
7
lib/services/ISPTermStorePickerServiceProps.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export interface ISPTermStorePickerServiceProps {
|
||||
termsetNameOrID: string;
|
||||
useSessionStorage: boolean;
|
||||
hideDeprecatedTags: boolean;
|
||||
hideTagsNotAvailableForTagging: boolean;
|
||||
anchorId: string;
|
||||
}
|
||||
3
lib/services/ISPTermStorePickerServiceProps.js
Normal file
3
lib/services/ISPTermStorePickerServiceProps.js
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=ISPTermStorePickerServiceProps.js.map
|
||||
1
lib/services/ISPTermStorePickerServiceProps.js.map
Normal file
1
lib/services/ISPTermStorePickerServiceProps.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"services/ISPTermStorePickerServiceProps.js","sourcesContent":[],"sourceRoot":"..\\..\\src"}
|
||||
4
lib/services/ITaxonomyNavigationService.d.ts
vendored
Normal file
4
lib/services/ITaxonomyNavigationService.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { IMenuItem } from './IMenuItem';
|
||||
export interface ITaxonomyNavigationService {
|
||||
getMenuItems(): Promise<IMenuItem[]>;
|
||||
}
|
||||
3
lib/services/ITaxonomyNavigationService.js
Normal file
3
lib/services/ITaxonomyNavigationService.js
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=ITaxonomyNavigationService.js.map
|
||||
1
lib/services/ITaxonomyNavigationService.js.map
Normal file
1
lib/services/ITaxonomyNavigationService.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"services/ITaxonomyNavigationService.js","sourcesContent":[],"sourceRoot":"..\\..\\src"}
|
||||
4
lib/services/ItemDictionary.d.ts
vendored
Normal file
4
lib/services/ItemDictionary.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export declare class ItemDictionary<T> {
|
||||
Get(key: string): T;
|
||||
Add(key: string, value: T): void;
|
||||
}
|
||||
14
lib/services/ItemDictionary.js
Normal file
14
lib/services/ItemDictionary.js
Normal file
@@ -0,0 +1,14 @@
|
||||
var ItemDictionary = (function () {
|
||||
function ItemDictionary() {
|
||||
}
|
||||
ItemDictionary.prototype.Get = function (key) {
|
||||
return this[key];
|
||||
};
|
||||
ItemDictionary.prototype.Add = function (key, value) {
|
||||
this[key] = value;
|
||||
};
|
||||
return ItemDictionary;
|
||||
}());
|
||||
export { ItemDictionary };
|
||||
|
||||
//# sourceMappingURL=ItemDictionary.js.map
|
||||
1
lib/services/ItemDictionary.js.map
Normal file
1
lib/services/ItemDictionary.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["services/ItemDictionary.ts"],"names":[],"mappings":"AAAA;IAAA;IAQA,CAAC;IAPU,4BAAG,GAAV,UAAW,GAAW;QAClB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IAEM,4BAAG,GAAV,UAAW,GAAW,EAAE,KAAQ;QAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC;IACL,qBAAC;AAAD,CARA,AAQC,IAAA","file":"services/ItemDictionary.js","sourcesContent":["export class ItemDictionary<T> {\r\n public Get(key: string): T {\r\n return this[key];\r\n }\r\n\r\n public Add(key: string, value: T): void {\r\n this[key] = value;\r\n }\r\n}\r\n"],"sourceRoot":"..\\..\\src"}
|
||||
14
lib/services/MenuItem.d.ts
vendored
Normal file
14
lib/services/MenuItem.d.ts
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { IMenuItem } from './IMenuItem';
|
||||
import { ITerm } from './ISPTermStorePickerService';
|
||||
export declare class MenuItem implements IMenuItem {
|
||||
level: number;
|
||||
id: string;
|
||||
label: string;
|
||||
hoverText: string;
|
||||
pathDepth: number;
|
||||
url?: string;
|
||||
items?: IMenuItem[];
|
||||
constructor(term: ITerm, level: number, siteCollectionUrl?: string);
|
||||
hasChildren(): boolean;
|
||||
command(): void;
|
||||
}
|
||||
29
lib/services/MenuItem.js
Normal file
29
lib/services/MenuItem.js
Normal file
@@ -0,0 +1,29 @@
|
||||
// tslint:disable:no-any no-string-literal max-line-length
|
||||
var MenuItem = (function () {
|
||||
function MenuItem(term, level, siteCollectionUrl) {
|
||||
this.level = level;
|
||||
this.id = term.Id;
|
||||
this.label = term.Name;
|
||||
this.hoverText = term.LocalCustomProperties['_Sys_Nav_HoverText'];
|
||||
this.pathDepth = term.PathDepth;
|
||||
var rawUrl = term.LocalCustomProperties['_Sys_Nav_SimpleLinkUrl'] || term.LocalCustomProperties['_Sys_Nav_TargetUrl'];
|
||||
if (rawUrl) {
|
||||
this.url = siteCollectionUrl && rawUrl.indexOf('~sitecollection') === 0
|
||||
? siteCollectionUrl + rawUrl.substring('~sitecollection'.length)
|
||||
: rawUrl;
|
||||
}
|
||||
this.items = [];
|
||||
}
|
||||
MenuItem.prototype.hasChildren = function () {
|
||||
return this.items && this.items.length > 0;
|
||||
};
|
||||
MenuItem.prototype.command = function () {
|
||||
if (this.url) {
|
||||
window.location.href = this.url;
|
||||
}
|
||||
};
|
||||
return MenuItem;
|
||||
}());
|
||||
export { MenuItem };
|
||||
|
||||
//# sourceMappingURL=MenuItem.js.map
|
||||
1
lib/services/MenuItem.js.map
Normal file
1
lib/services/MenuItem.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["services/MenuItem.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAK1D;IAQI,kBAAY,IAAW,EAAS,KAAa,EAAE,iBAA0B;QAAzC,UAAK,GAAL,KAAK,CAAQ;QACzC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,qBAAqB,CAAC,oBAAoB,CAAC,CAAC;QAClE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAM,MAAM,GAAW,IAAI,CAAC,qBAAqB,CAAC,wBAAwB,CAAC,IAAI,IAAI,CAAC,qBAAqB,CAAC,oBAAoB,CAAC,CAAC;QAChI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;YACT,IAAI,CAAC,GAAG,GAAG,iBAAiB,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC;kBACjE,iBAAiB,GAAG,MAAM,CAAC,SAAS,CAAC,iBAAiB,CAAC,MAAM,CAAC;kBAC9D,MAAM,CAAC;QACjB,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IACpB,CAAC;IAEM,8BAAW,GAAlB;QACI,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/C,CAAC;IAEM,0BAAO,GAAd;QACI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YACV,MAAc,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC;QAC7C,CAAC;IACL,CAAC;IACL,eAAC;AAAD,CA/BA,AA+BC,IAAA","file":"services/MenuItem.js","sourcesContent":["// tslint:disable:no-any no-string-literal max-line-length\r\n\r\nimport { IMenuItem } from './IMenuItem';\r\nimport { ITerm } from './ISPTermStorePickerService';\r\n\r\nexport class MenuItem implements IMenuItem {\r\n public id: string;\r\n public label: string;\r\n public hoverText: string;\r\n public pathDepth: number;\r\n public url?: string;\r\n public items?: IMenuItem[];\r\n\r\n constructor(term: ITerm, public level: number, siteCollectionUrl?: string) {\r\n this.id = term.Id;\r\n this.label = term.Name;\r\n this.hoverText = term.LocalCustomProperties['_Sys_Nav_HoverText'];\r\n this.pathDepth = term.PathDepth;\r\n const rawUrl: string = term.LocalCustomProperties['_Sys_Nav_SimpleLinkUrl'] || term.LocalCustomProperties['_Sys_Nav_TargetUrl'];\r\n if (rawUrl) {\r\n this.url = siteCollectionUrl && rawUrl.indexOf('~sitecollection') === 0\r\n ? siteCollectionUrl + rawUrl.substring('~sitecollection'.length)\r\n : rawUrl;\r\n }\r\n this.items = [];\r\n }\r\n\r\n public hasChildren(): boolean {\r\n return this.items && this.items.length > 0;\r\n }\r\n\r\n public command(): void {\r\n if (this.url) {\r\n (window as any).location.href = this.url;\r\n }\r\n }\r\n}\r\n"],"sourceRoot":"..\\..\\src"}
|
||||
5
lib/services/MockTaxonomyNavigationService.d.ts
vendored
Normal file
5
lib/services/MockTaxonomyNavigationService.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { IMenuItem } from './IMenuItem';
|
||||
import { ITaxonomyNavigationService } from './ITaxonomyNavigationService';
|
||||
export default class MockTaxonomyNavigationService implements ITaxonomyNavigationService {
|
||||
getMenuItems(): Promise<IMenuItem[]>;
|
||||
}
|
||||
109
lib/services/MockTaxonomyNavigationService.js
Normal file
109
lib/services/MockTaxonomyNavigationService.js
Normal file
@@ -0,0 +1,109 @@
|
||||
import * as uuid from 'uuid';
|
||||
var MockTaxonomyNavigationService = (function () {
|
||||
function MockTaxonomyNavigationService() {
|
||||
}
|
||||
MockTaxonomyNavigationService.prototype.getMenuItems = function () {
|
||||
return new Promise(function (resolve) {
|
||||
resolve([
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Menu Item 1',
|
||||
url: 'https://www.bing.com',
|
||||
hoverText: 'Hover me!',
|
||||
pathDepth: 1,
|
||||
hasChildren: function () { return true; },
|
||||
items: [
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Submenu Item 1',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 2,
|
||||
hasChildren: function () { return false; }
|
||||
},
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Submenu Item 2',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 2,
|
||||
hasChildren: function () { return false; }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Menu Item 2',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 1,
|
||||
hasChildren: function () { return false; }
|
||||
},
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Menu Item 3',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 1,
|
||||
hasChildren: function () { return true; },
|
||||
items: [
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Submenu Item 1',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 2,
|
||||
hasChildren: function () { return false; }
|
||||
},
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Submenu Item 2',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 2,
|
||||
hasChildren: function () { return true; },
|
||||
items: [
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Submenu Item 1',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 3,
|
||||
hasChildren: function () { return false; }
|
||||
},
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Submenu Item 2',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 3,
|
||||
hasChildren: function () { return false; }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Submenu Item 3',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 2,
|
||||
hasChildren: function () { return false; }
|
||||
},
|
||||
{
|
||||
id: uuid.v4(),
|
||||
label: 'Submenu Item 4',
|
||||
hoverText: 'Huch!',
|
||||
url: 'https://www.bing.com',
|
||||
pathDepth: 2,
|
||||
hasChildren: function () { return false; }
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
||||
});
|
||||
};
|
||||
return MockTaxonomyNavigationService;
|
||||
}());
|
||||
export default MockTaxonomyNavigationService;
|
||||
|
||||
//# sourceMappingURL=MockTaxonomyNavigationService.js.map
|
||||
1
lib/services/MockTaxonomyNavigationService.js.map
Normal file
1
lib/services/MockTaxonomyNavigationService.js.map
Normal file
File diff suppressed because one or more lines are too long
76
lib/services/SPTermStorePickerService.d.ts
vendored
Normal file
76
lib/services/SPTermStorePickerService.d.ts
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
import { ITermStore, ITermSet } from './ISPTermStorePickerService';
|
||||
import { ISPTermStorePickerServiceProps } from './ISPTermStorePickerServiceProps';
|
||||
import { IPickerTerm } from './IPickerTerm';
|
||||
import { ApplicationCustomizerContext } from '@microsoft/sp-application-base';
|
||||
/**
|
||||
* Service implementation to manage term stores in SharePoint
|
||||
*/
|
||||
export default class SPTermStorePickerService {
|
||||
private props;
|
||||
private context;
|
||||
private clientServiceUrl;
|
||||
private suggestionServiceUrl;
|
||||
/**
|
||||
* Service constructor
|
||||
*/
|
||||
constructor(props: ISPTermStorePickerServiceProps, context: ApplicationCustomizerContext);
|
||||
getTermLabels(termId: string): Promise<string[]>;
|
||||
/**
|
||||
* Gets the collection of term stores in the current SharePoint env
|
||||
*/
|
||||
getTermStores(): Promise<ITermStore[]>;
|
||||
/**
|
||||
* Gets the current term set
|
||||
*/
|
||||
getTermSet(): Promise<ITermSet>;
|
||||
/**
|
||||
* Retrieve all terms for the given term set
|
||||
* @param termset
|
||||
*/
|
||||
getAllTerms(termset: string, hideDeprecatedTags?: boolean, hideTagsNotAvailableForTagging?: boolean, useSessionStorage?: boolean): Promise<ITermSet>;
|
||||
/**
|
||||
* Retrieve all terms that starts with the searchText
|
||||
* @param searchText
|
||||
*/
|
||||
searchTermsByName(searchText: string): Promise<IPickerTerm[]>;
|
||||
searchTermsByTermId(searchText: string, termId: string): Promise<IPickerTerm[]>;
|
||||
/**
|
||||
* Retrieve all terms for the given term set and anchorId
|
||||
*/
|
||||
getAllTermsByAnchorId(termsetNameOrID: string, anchorId: string, hideDeprecatedTags?: boolean, hideTagsNotAvailableForTagging?: boolean, useSessionStorage?: boolean): Promise<IPickerTerm[]>;
|
||||
/**
|
||||
* Clean the Guid from the Web Service response
|
||||
* @param guid
|
||||
*/
|
||||
cleanGuid(guid: string): string;
|
||||
/**
|
||||
* Get the term set ID by its name
|
||||
* @param termstore
|
||||
* @param termset
|
||||
*/
|
||||
private getTermSetId(termstore, termsetName);
|
||||
private getTermsById(termId, useSessionStorage?);
|
||||
private searchTermsBySearchText(terms, searchText);
|
||||
/**
|
||||
* Searches terms for the given term set
|
||||
* @param searchText
|
||||
* @param termsetId
|
||||
*/
|
||||
private searchTermsByTermSet(searchText);
|
||||
private isGuid(strGuid);
|
||||
/**
|
||||
* Sorting terms based on their path and depth
|
||||
*
|
||||
* @param terms
|
||||
*/
|
||||
private sortTerms(terms);
|
||||
/**
|
||||
* Sort the terms by their path
|
||||
*
|
||||
* @param a term 2
|
||||
* @param b term 2
|
||||
*/
|
||||
private sortTermByPath(a, b);
|
||||
private convertTermToPickerTerm(term);
|
||||
private convertSuggestTermToPickerTerm(term);
|
||||
}
|
||||
574
lib/services/SPTermStorePickerService.js
Normal file
574
lib/services/SPTermStorePickerService.js
Normal file
@@ -0,0 +1,574 @@
|
||||
/* tslint:disable:no-null-keyword max-line-length typedef no-any no-string-literal variable-name */
|
||||
/**
|
||||
* This code is a copy from the library @pnp/sp-dev-fx-controls-react
|
||||
*/
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [0, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
import { SPHttpClient } from '@microsoft/sp-http';
|
||||
import { findIndex } from '@microsoft/sp-lodash-subset';
|
||||
var EmptyGuid = '00000000-0000-0000-0000-000000000000';
|
||||
/**
|
||||
* Service implementation to manage term stores in SharePoint
|
||||
*/
|
||||
var SPTermStorePickerService = (function () {
|
||||
/**
|
||||
* Service constructor
|
||||
*/
|
||||
function SPTermStorePickerService(props, context) {
|
||||
this.props = props;
|
||||
this.context = context;
|
||||
this.clientServiceUrl = this.context.pageContext.web.absoluteUrl + '/_vti_bin/client.svc/ProcessQuery';
|
||||
this.suggestionServiceUrl = this.context.pageContext.web.absoluteUrl + '/_vti_bin/TaxonomyInternalService.json/GetSuggestions';
|
||||
}
|
||||
SPTermStorePickerService.prototype.getTermLabels = function (termId) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var result, data, reqHeaders, httpPostOptions, callResult, jsonResult, node, error_1;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
result = null;
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
_a.trys.push([1, 4, , 5]);
|
||||
data = "<Request AddExpandoFieldTypeSuffix=\"true\" SchemaVersion=\"15.0.0.0\" LibraryVersion=\"16.0.0.0\" ApplicationName=\".NET Library\" xmlns=\"http://schemas.microsoft.com/sharepoint/clientquery/2009\"><Actions><ObjectPath Id=\"8\" ObjectPathId=\"7\" /><ObjectIdentityQuery Id=\"9\" ObjectPathId=\"7\" /><ObjectPath Id=\"11\" ObjectPathId=\"10\" /><ObjectIdentityQuery Id=\"12\" ObjectPathId=\"10\" /><ObjectPath Id=\"14\" ObjectPathId=\"13\" /><ObjectIdentityQuery Id=\"15\" ObjectPathId=\"13\" /><Query Id=\"16\" ObjectPathId=\"13\"><Query SelectAllProperties=\"false\"><Properties><Property Name=\"Labels\" SelectAll=\"true\"><Query SelectAllProperties=\"false\"><Properties /></Query></Property></Properties></Query></Query></Actions><ObjectPaths><StaticMethod Id=\"7\" Name=\"GetTaxonomySession\" TypeId=\"{981cbc68-9edc-4f8d-872f-71146fcbb84f}\" /><Method Id=\"10\" ParentId=\"7\" Name=\"GetDefaultKeywordsTermStore\" /><Method Id=\"13\" ParentId=\"10\" Name=\"GetTerm\"><Parameters><Parameter Type=\"Guid\">" + termId + "</Parameter></Parameters></Method></ObjectPaths></Request>";
|
||||
reqHeaders = new Headers();
|
||||
reqHeaders.append('accept', 'application/json');
|
||||
reqHeaders.append('content-type', 'application/xml');
|
||||
httpPostOptions = {
|
||||
headers: reqHeaders,
|
||||
body: data
|
||||
};
|
||||
return [4 /*yield*/, this.context.spHttpClient.post(this.clientServiceUrl, SPHttpClient.configurations.v1, httpPostOptions)];
|
||||
case 2:
|
||||
callResult = _a.sent();
|
||||
return [4 /*yield*/, callResult.json()];
|
||||
case 3:
|
||||
jsonResult = _a.sent();
|
||||
node = jsonResult.find(function (x) { return x._ObjectType_ === 'SP.Taxonomy.Term'; });
|
||||
if (node && node.Labels && node.Labels._Child_Items_) {
|
||||
result = node.Labels._Child_Items_.map(function (termLabel) { return termLabel.Value; });
|
||||
}
|
||||
return [3 /*break*/, 5];
|
||||
case 4:
|
||||
error_1 = _a.sent();
|
||||
result = null;
|
||||
console.log(error_1.message);
|
||||
return [3 /*break*/, 5];
|
||||
case 5: return [2 /*return*/, result];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Gets the collection of term stores in the current SharePoint env
|
||||
*/
|
||||
SPTermStorePickerService.prototype.getTermStores = function () {
|
||||
var _this = this;
|
||||
// Retrieve the term store name, groups, and term sets
|
||||
var data = '<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName=".NET Library" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="2" ObjectPathId="1" /><ObjectIdentityQuery Id="3" ObjectPathId="1" /><ObjectPath Id="5" ObjectPathId="4" /><ObjectIdentityQuery Id="6" ObjectPathId="4" /><Query Id="7" ObjectPathId="4"><Query SelectAllProperties="false"><Properties><Property Name="Id" ScalarProperty="true" /><Property Name="Name" ScalarProperty="true" /><Property Name="Groups"><Query SelectAllProperties="false"><Properties /></Query><ChildItemQuery SelectAllProperties="false"><Properties><Property Name="Name" ScalarProperty="true" /><Property Name="Id" ScalarProperty="true" /><Property Name="IsSystemGroup" ScalarProperty="true" /><Property Name="TermSets"><Query SelectAllProperties="false"><Properties /></Query><ChildItemQuery SelectAllProperties="false"><Properties><Property Name="Name" ScalarProperty="true" /><Property Name="Id" ScalarProperty="true" /><Property Name="Description" ScalarProperty="true" /><Property Name="Names" ScalarProperty="true" /></Properties></ChildItemQuery></Property></Properties></ChildItemQuery></Property></Properties></Query></Query></Actions><ObjectPaths><StaticMethod Id="1" Name="GetTaxonomySession" TypeId="{981cbc68-9edc-4f8d-872f-71146fcbb84f}" /><Method Id="4" ParentId="1" Name="GetDefaultSiteCollectionTermStore" /></ObjectPaths></Request>';
|
||||
var reqHeaders = new Headers();
|
||||
reqHeaders.append('accept', 'application/json');
|
||||
reqHeaders.append('content-type', 'application/xml');
|
||||
var httpPostOptions = {
|
||||
headers: reqHeaders,
|
||||
body: data
|
||||
};
|
||||
return this.context.spHttpClient.post(this.clientServiceUrl, SPHttpClient.configurations.v1, httpPostOptions).then(function (serviceResponse) {
|
||||
return serviceResponse.json().then(function (serviceJSONResponse) {
|
||||
// Construct results
|
||||
var termStoreResult = serviceJSONResponse.filter(function (r) { return r['_ObjectType_'] === 'SP.Taxonomy.TermStore'; });
|
||||
// Check if term store was retrieved
|
||||
if (termStoreResult.length > 0) {
|
||||
// Check if the termstore needs to be filtered or limited
|
||||
if (_this.props.termsetNameOrID) {
|
||||
return termStoreResult.map(function (termstore) {
|
||||
var termGroups = termstore.Groups._Child_Items_;
|
||||
// Check if the groups have to be limited to a specific term set
|
||||
if (_this.props.termsetNameOrID) {
|
||||
var termsetNameOrId_1 = _this.props.termsetNameOrID;
|
||||
termGroups = termGroups.map(function (group) {
|
||||
group.TermSets._Child_Items_ = group.TermSets._Child_Items_.filter(function (termSet) { return termSet.Name === termsetNameOrId_1 || _this.cleanGuid(termSet.Id).toLowerCase() === _this.cleanGuid(termsetNameOrId_1).toLowerCase(); });
|
||||
return group;
|
||||
});
|
||||
}
|
||||
// Filter out all systen groups
|
||||
termGroups = termGroups.filter(function (group) { return !group.IsSystemGroup; });
|
||||
// Filter out empty groups
|
||||
termGroups = termGroups.filter(function (group) { return group.TermSets._Child_Items_.length > 0; });
|
||||
// Map the new groups
|
||||
termstore.Groups._Child_Items_ = termGroups;
|
||||
return termstore;
|
||||
});
|
||||
}
|
||||
// Return the term store results
|
||||
return termStoreResult;
|
||||
}
|
||||
return [];
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Gets the current term set
|
||||
*/
|
||||
SPTermStorePickerService.prototype.getTermSet = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var termStore;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.getTermStores()];
|
||||
case 1:
|
||||
termStore = _a.sent();
|
||||
return [2 /*return*/, this.getTermSetId(termStore, this.props.termsetNameOrID)];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Retrieve all terms for the given term set
|
||||
* @param termset
|
||||
*/
|
||||
SPTermStorePickerService.prototype.getAllTerms = function (termset, hideDeprecatedTags, hideTagsNotAvailableForTagging, useSessionStorage) {
|
||||
if (useSessionStorage === void 0) { useSessionStorage = true; }
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var _this = this;
|
||||
var termsetId, termStore, crntTermSet, childTerms, data, reqHeaders, httpPostOptions;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
termsetId = termset;
|
||||
if (!!this.isGuid(termset)) return [3 /*break*/, 2];
|
||||
return [4 /*yield*/, this.getTermStores()];
|
||||
case 1:
|
||||
termStore = _a.sent();
|
||||
crntTermSet = this.getTermSetId(termStore, termset);
|
||||
if (crntTermSet) {
|
||||
termsetId = this.cleanGuid(crntTermSet.Id);
|
||||
}
|
||||
else {
|
||||
return [2 /*return*/, null];
|
||||
}
|
||||
_a.label = 2;
|
||||
case 2:
|
||||
childTerms = this.getTermsById(termsetId, useSessionStorage);
|
||||
if (childTerms) {
|
||||
return [2 /*return*/, childTerms];
|
||||
}
|
||||
data = "<Request xmlns=\"http://schemas.microsoft.com/sharepoint/clientquery/2009\" SchemaVersion=\"15.0.0.0\" LibraryVersion=\"16.0.0.0\" ApplicationName=\"Javascript Library\"><Actions><ObjectPath Id=\"1\" ObjectPathId=\"0\" /><ObjectIdentityQuery Id=\"2\" ObjectPathId=\"0\" /><ObjectPath Id=\"4\" ObjectPathId=\"3\" /><ObjectIdentityQuery Id=\"5\" ObjectPathId=\"3\" /><ObjectPath Id=\"7\" ObjectPathId=\"6\" /><ObjectIdentityQuery Id=\"8\" ObjectPathId=\"6\" /><ObjectPath Id=\"10\" ObjectPathId=\"9\" /><Query Id=\"11\" ObjectPathId=\"6\"><Query SelectAllProperties=\"true\"><Properties /></Query></Query><Query Id=\"12\" ObjectPathId=\"9\"><Query SelectAllProperties=\"false\"><Properties /></Query><ChildItemQuery SelectAllProperties=\"false\"><Properties><Property Name=\"IsRoot\" SelectAll=\"true\" /><Property Name=\"Labels\" SelectAll=\"true\" /><Property Name=\"TermsCount\" SelectAll=\"true\" /><Property Name=\"CustomSortOrder\" SelectAll=\"true\" /><Property Name=\"Id\" SelectAll=\"true\" /><Property Name=\"Name\" SelectAll=\"true\" /><Property Name=\"PathOfTerm\" SelectAll=\"true\" /><Property Name=\"Parent\" SelectAll=\"true\" /><Property Name=\"LocalCustomProperties\" SelectAll=\"true\" /><Property Name=\"IsDeprecated\" ScalarProperty=\"true\" /><Property Name=\"IsAvailableForTagging\" ScalarProperty=\"true\" /></Properties></ChildItemQuery></Query></Actions><ObjectPaths><StaticMethod Id=\"0\" Name=\"GetTaxonomySession\" TypeId=\"{981cbc68-9edc-4f8d-872f-71146fcbb84f}\" /><Method Id=\"3\" ParentId=\"0\" Name=\"GetDefaultKeywordsTermStore\" /><Method Id=\"6\" ParentId=\"3\" Name=\"GetTermSet\"><Parameters><Parameter Type=\"Guid\">" + termsetId + "</Parameter></Parameters></Method><Method Id=\"9\" ParentId=\"6\" Name=\"GetAllTerms\" /></ObjectPaths></Request>";
|
||||
reqHeaders = new Headers();
|
||||
reqHeaders.append('accept', 'application/json');
|
||||
reqHeaders.append('content-type', 'application/xml');
|
||||
httpPostOptions = {
|
||||
headers: reqHeaders,
|
||||
body: data
|
||||
};
|
||||
return [2 /*return*/, this.context.spHttpClient.post(this.clientServiceUrl, SPHttpClient.configurations.v1, httpPostOptions).then(function (serviceResponse) {
|
||||
return serviceResponse.json().then(function (serviceJSONResponse) {
|
||||
var termStoreResultTermSets = serviceJSONResponse.filter(function (r) { return r['_ObjectType_'] === 'SP.Taxonomy.TermSet'; });
|
||||
if (termStoreResultTermSets.length > 0) {
|
||||
var termStoreResultTermSet_1 = termStoreResultTermSets[0];
|
||||
termStoreResultTermSet_1.Terms = [];
|
||||
// Retrieve the term collection results
|
||||
var termStoreResultTerms = serviceJSONResponse.filter(function (r) { return r['_ObjectType_'] === 'SP.Taxonomy.TermCollection'; });
|
||||
if (termStoreResultTerms.length > 0) {
|
||||
// Retrieve all terms
|
||||
var terms = termStoreResultTerms[0]._Child_Items_;
|
||||
if (hideDeprecatedTags === true) {
|
||||
terms = terms.filter(function (d) { return d.IsDeprecated === false; });
|
||||
}
|
||||
if (hideTagsNotAvailableForTagging === true) {
|
||||
terms = terms.filter(function (d) { return d.IsAvailableForTagging === true; });
|
||||
}
|
||||
// Clean the term ID and specify the path depth
|
||||
terms = terms.map(function (term) {
|
||||
if (term.IsRoot) {
|
||||
term.CustomSortOrderIndex = (termStoreResultTermSet_1.CustomSortOrder) ? termStoreResultTermSet_1.CustomSortOrder.split(':').indexOf(_this.cleanGuid(term.Id)) : -1;
|
||||
}
|
||||
else {
|
||||
term.CustomSortOrderIndex = (term['Parent'].CustomSortOrder) ? term['Parent'].CustomSortOrder.split(':').indexOf(_this.cleanGuid(term.Id)) : -1;
|
||||
}
|
||||
term.Id = _this.cleanGuid(term.Id);
|
||||
term['PathDepth'] = term.PathOfTerm.split(';').length;
|
||||
term.TermSet = { Id: _this.cleanGuid(termStoreResultTermSet_1.Id), Name: termStoreResultTermSet_1.Name };
|
||||
if (term['Parent']) {
|
||||
term.ParentId = _this.cleanGuid(term['Parent'].Id);
|
||||
}
|
||||
return term;
|
||||
});
|
||||
// Check if the term set was not empty
|
||||
if (terms.length > 0) {
|
||||
// Sort the terms by PathOfTerm and their depth
|
||||
terms = _this.sortTerms(terms);
|
||||
termStoreResultTermSet_1.Terms = terms;
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (useSessionStorage && window.sessionStorage) {
|
||||
window.sessionStorage.setItem(termsetId, JSON.stringify(termStoreResultTermSet_1));
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
// Do nothing, sometimes "storage quota exceeded" error if too many items
|
||||
}
|
||||
return termStoreResultTermSet_1;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
})];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Retrieve all terms that starts with the searchText
|
||||
* @param searchText
|
||||
*/
|
||||
SPTermStorePickerService.prototype.searchTermsByName = function (searchText) {
|
||||
return this.searchTermsByTermSet(searchText);
|
||||
};
|
||||
SPTermStorePickerService.prototype.searchTermsByTermId = function (searchText, termId) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var useSessionStorage, childTerms, _a, termsetNameOrID, hideDeprecatedTags, hideTagsNotAvailableForTagging, terms;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
useSessionStorage = this.props.useSessionStorage;
|
||||
childTerms = this.getTermsById(termId, useSessionStorage);
|
||||
if (!childTerms) return [3 /*break*/, 1];
|
||||
return [2 /*return*/, this.searchTermsBySearchText(childTerms, searchText)];
|
||||
case 1:
|
||||
_a = this.props, termsetNameOrID = _a.termsetNameOrID, hideDeprecatedTags = _a.hideDeprecatedTags, hideTagsNotAvailableForTagging = _a.hideTagsNotAvailableForTagging;
|
||||
return [4 /*yield*/, this.getAllTermsByAnchorId(termsetNameOrID, termId, hideDeprecatedTags, hideTagsNotAvailableForTagging, useSessionStorage)];
|
||||
case 2:
|
||||
terms = _b.sent();
|
||||
if (terms) {
|
||||
return [2 /*return*/, this.searchTermsBySearchText(terms, searchText)];
|
||||
}
|
||||
_b.label = 3;
|
||||
case 3: return [2 /*return*/, null];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Retrieve all terms for the given term set and anchorId
|
||||
*/
|
||||
SPTermStorePickerService.prototype.getAllTermsByAnchorId = function (termsetNameOrID, anchorId, hideDeprecatedTags, hideTagsNotAvailableForTagging, useSessionStorage) {
|
||||
if (useSessionStorage === void 0) { useSessionStorage = true; }
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var _this = this;
|
||||
var returnTerms, childTerms, termSet, terms, anchorTerm_1, anchorTermPath_1, anchorTerms;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
returnTerms = [];
|
||||
childTerms = this.getTermsById(anchorId, useSessionStorage);
|
||||
if (childTerms) {
|
||||
return [2 /*return*/, childTerms];
|
||||
}
|
||||
return [4 /*yield*/, this.getAllTerms(termsetNameOrID, hideDeprecatedTags, hideTagsNotAvailableForTagging)];
|
||||
case 1:
|
||||
termSet = _a.sent();
|
||||
terms = termSet.Terms;
|
||||
if (anchorId) {
|
||||
anchorTerm_1 = terms.filter(function (t) { return t.Id.toLowerCase() === anchorId.toLowerCase(); }).shift();
|
||||
if (anchorTerm_1) {
|
||||
anchorTermPath_1 = anchorTerm_1.PathOfTerm + ";";
|
||||
anchorTerms = terms.filter(function (t) { return t.PathOfTerm.substring(0, anchorTermPath_1.length) === anchorTermPath_1 && t.Id !== anchorTerm_1.Id; });
|
||||
anchorTerms.forEach(function (term) {
|
||||
returnTerms.push(_this.convertTermToPickerTerm(term));
|
||||
});
|
||||
try {
|
||||
if (useSessionStorage && window.sessionStorage) {
|
||||
window.sessionStorage.setItem(anchorId, JSON.stringify(returnTerms));
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
terms.forEach(function (term) {
|
||||
returnTerms.push(_this.convertTermToPickerTerm(term));
|
||||
});
|
||||
}
|
||||
return [2 /*return*/, returnTerms];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Clean the Guid from the Web Service response
|
||||
* @param guid
|
||||
*/
|
||||
SPTermStorePickerService.prototype.cleanGuid = function (guid) {
|
||||
if (guid !== undefined) {
|
||||
return guid.replace('/Guid(', '').replace('/', '').replace(')', '');
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Get the term set ID by its name
|
||||
* @param termstore
|
||||
* @param termset
|
||||
*/
|
||||
SPTermStorePickerService.prototype.getTermSetId = function (termstore, termsetName) {
|
||||
if (termstore && termstore.length > 0 && termsetName) {
|
||||
// Get the first term store
|
||||
var ts = termstore[0];
|
||||
// Check if the term store contains groups
|
||||
if (ts.Groups && ts.Groups._Child_Items_) {
|
||||
for (var _i = 0, _a = ts.Groups._Child_Items_; _i < _a.length; _i++) {
|
||||
var group = _a[_i];
|
||||
// Check if the group contains term sets
|
||||
if (group.TermSets && group.TermSets._Child_Items_) {
|
||||
for (var _b = 0, _c = group.TermSets._Child_Items_; _b < _c.length; _b++) {
|
||||
var termSet = _c[_b];
|
||||
// Check if the term set is found
|
||||
if (termSet.Name === termsetName) {
|
||||
return termSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
SPTermStorePickerService.prototype.getTermsById = function (termId, useSessionStorage) {
|
||||
if (useSessionStorage === void 0) { useSessionStorage = true; }
|
||||
try {
|
||||
if (useSessionStorage && window.sessionStorage) {
|
||||
var terms = window.sessionStorage.getItem(termId);
|
||||
if (terms) {
|
||||
return JSON.parse(terms);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
SPTermStorePickerService.prototype.searchTermsBySearchText = function (terms, searchText) {
|
||||
if (terms) {
|
||||
return terms.filter(function (t) { return t.name.toLowerCase().indexOf(searchText.toLowerCase()) > -1; });
|
||||
}
|
||||
else {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Searches terms for the given term set
|
||||
* @param searchText
|
||||
* @param termsetId
|
||||
*/
|
||||
SPTermStorePickerService.prototype.searchTermsByTermSet = function (searchText) {
|
||||
var _this = this;
|
||||
return new Promise(function (resolve) {
|
||||
_this.getTermStores().then(function (termStore) {
|
||||
var termSetId = _this.props.termsetNameOrID;
|
||||
if (!_this.isGuid(termSetId)) {
|
||||
// Get the ID of the provided term set name
|
||||
var crntTermSet = _this.getTermSetId(termStore, termSetId);
|
||||
if (crntTermSet) {
|
||||
termSetId = _this.cleanGuid(crntTermSet.Id);
|
||||
}
|
||||
else {
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (termStore === undefined || termStore.length === 0) {
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
var loc = _this.context.pageContext.cultureInfo.currentUICultureName === 'de-de' ? 1031 : 1033;
|
||||
var data = {
|
||||
start: searchText,
|
||||
lcid: loc !== 0 ? loc : _this.context.pageContext.web.language,
|
||||
sspList: _this.cleanGuid(termStore[0].Id),
|
||||
termSetList: termSetId,
|
||||
anchorId: _this.props.anchorId ? _this.props.anchorId : EmptyGuid,
|
||||
isSpanTermStores: false,
|
||||
isSpanTermSets: false,
|
||||
isIncludeUnavailable: _this.props.hideTagsNotAvailableForTagging === true,
|
||||
isIncludeDeprecated: _this.props.hideDeprecatedTags === true,
|
||||
isAddTerms: false,
|
||||
isIncludePathData: false,
|
||||
excludeKeyword: false,
|
||||
excludedTermset: EmptyGuid
|
||||
};
|
||||
var reqHeaders = new Headers();
|
||||
reqHeaders.append('accept', 'application/json');
|
||||
reqHeaders.append('content-type', 'application/json');
|
||||
var httpPostOptions = {
|
||||
headers: reqHeaders,
|
||||
body: JSON.stringify(data)
|
||||
};
|
||||
return _this.context.spHttpClient.post(_this.suggestionServiceUrl, SPHttpClient.configurations.v1, httpPostOptions).then(function (serviceResponse) {
|
||||
return serviceResponse.json().then(function (serviceJSONResponse) {
|
||||
var groups = serviceJSONResponse.d.Groups;
|
||||
if (groups && groups.length > 0) {
|
||||
// Retrieve the term collection results
|
||||
var terms = groups[0].Suggestions;
|
||||
if (terms.length > 0) {
|
||||
// Retrieve all terms
|
||||
var returnTerms = terms.map(function (term) { return _this.convertSuggestTermToPickerTerm(term); });
|
||||
resolve(returnTerms);
|
||||
return;
|
||||
}
|
||||
}
|
||||
resolve([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
SPTermStorePickerService.prototype.isGuid = function (strGuid) {
|
||||
return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(strGuid);
|
||||
};
|
||||
/**
|
||||
* Sorting terms based on their path and depth
|
||||
*
|
||||
* @param terms
|
||||
*/
|
||||
SPTermStorePickerService.prototype.sortTerms = function (terms) {
|
||||
// Start sorting by depth
|
||||
var newTermsOrder = [];
|
||||
var itemsToSort = true;
|
||||
var pathLevel = 1;
|
||||
while (itemsToSort) {
|
||||
// Get terms for the current level
|
||||
var crntTerms = terms.filter(function (term) { return term.PathDepth === pathLevel; });
|
||||
if (crntTerms && crntTerms.length > 0) {
|
||||
crntTerms = crntTerms.sort(this.sortTermByPath);
|
||||
if (pathLevel !== 1) {
|
||||
crntTerms = crntTerms.reverse();
|
||||
var _loop_1 = function (crntTerm) {
|
||||
var pathElms = crntTerm.PathOfTerm.split(';');
|
||||
// Last item is not needed for parent path
|
||||
pathElms.pop();
|
||||
// Find the parent item and add the new item
|
||||
var idx = findIndex(newTermsOrder, function (term) { return term.PathOfTerm === pathElms.join(';'); });
|
||||
if (idx !== -1) {
|
||||
newTermsOrder.splice(idx + 1, 0, crntTerm);
|
||||
}
|
||||
else {
|
||||
// Push the item at the end if the parent couldn't be found
|
||||
newTermsOrder.push(crntTerm);
|
||||
}
|
||||
};
|
||||
for (var _i = 0, crntTerms_1 = crntTerms; _i < crntTerms_1.length; _i++) {
|
||||
var crntTerm = crntTerms_1[_i];
|
||||
_loop_1(crntTerm);
|
||||
}
|
||||
}
|
||||
else {
|
||||
newTermsOrder = crntTerms;
|
||||
}
|
||||
++pathLevel;
|
||||
}
|
||||
else {
|
||||
itemsToSort = false;
|
||||
}
|
||||
}
|
||||
return newTermsOrder;
|
||||
};
|
||||
/**
|
||||
* Sort the terms by their path
|
||||
*
|
||||
* @param a term 2
|
||||
* @param b term 2
|
||||
*/
|
||||
SPTermStorePickerService.prototype.sortTermByPath = function (a, b) {
|
||||
if (a.CustomSortOrderIndex === -1) {
|
||||
if (a.PathOfTerm.toLowerCase() < b.PathOfTerm.toLowerCase()) {
|
||||
return -1;
|
||||
}
|
||||
if (a.PathOfTerm.toLowerCase() > b.PathOfTerm.toLowerCase()) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
if (a.CustomSortOrderIndex < b.CustomSortOrderIndex) {
|
||||
return -1;
|
||||
}
|
||||
if (a.CustomSortOrderIndex > b.CustomSortOrderIndex) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
SPTermStorePickerService.prototype.convertTermToPickerTerm = function (term) {
|
||||
return {
|
||||
key: this.cleanGuid(term.Id),
|
||||
name: term.Name,
|
||||
path: term.PathOfTerm,
|
||||
termSet: this.cleanGuid(term.TermSet.Id),
|
||||
termSetName: term.TermSet.Name
|
||||
};
|
||||
};
|
||||
SPTermStorePickerService.prototype.convertSuggestTermToPickerTerm = function (term) {
|
||||
var path = '';
|
||||
var termSetName = '';
|
||||
if (term.Paths && term.Paths.length > 0) {
|
||||
var fullPath = term.Paths[0].replace(/^\[/, '').replace(/\]$/, '');
|
||||
var fullPathParts = fullPath.split(':');
|
||||
path = fullPathParts.join(';') + ';' + term.DefaultLabel;
|
||||
termSetName = fullPathParts[0];
|
||||
}
|
||||
return {
|
||||
key: this.cleanGuid(term.Id),
|
||||
name: term.DefaultLabel,
|
||||
path: path,
|
||||
termSet: EmptyGuid,
|
||||
termSetName: termSetName
|
||||
};
|
||||
};
|
||||
return SPTermStorePickerService;
|
||||
}());
|
||||
export default SPTermStorePickerService;
|
||||
|
||||
//# sourceMappingURL=SPTermStorePickerService.js.map
|
||||
1
lib/services/SPTermStorePickerService.js.map
Normal file
1
lib/services/SPTermStorePickerService.js.map
Normal file
File diff suppressed because one or more lines are too long
11
lib/services/TaxonomyNavigationService.d.ts
vendored
Normal file
11
lib/services/TaxonomyNavigationService.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { ITaxonomyNavigationService } from './ITaxonomyNavigationService';
|
||||
import { IMenuItem } from './IMenuItem';
|
||||
import { ApplicationCustomizerContext } from '@microsoft/sp-application-base';
|
||||
export declare class TaxonomyNavigationService implements ITaxonomyNavigationService {
|
||||
private context;
|
||||
private termSetName;
|
||||
private _taxonomyPickerService;
|
||||
private _noTerm;
|
||||
constructor(context: ApplicationCustomizerContext, termSetName: string);
|
||||
getMenuItems(): Promise<IMenuItem[]>;
|
||||
}
|
||||
120
lib/services/TaxonomyNavigationService.js
Normal file
120
lib/services/TaxonomyNavigationService.js
Normal file
@@ -0,0 +1,120 @@
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [0, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
import { sp } from '@pnp/sp';
|
||||
import { MenuItem } from './MenuItem';
|
||||
import SPTermStorePickerService from './SPTermStorePickerService';
|
||||
import { ItemDictionary } from './ItemDictionary';
|
||||
var TaxonomyNavigationService = (function () {
|
||||
function TaxonomyNavigationService(context /*, private lcid: number*/, termSetName) {
|
||||
this.context = context; /*, private lcid: number*/
|
||||
this.termSetName = termSetName;
|
||||
this._noTerm = {
|
||||
_ObjectType_: '',
|
||||
_ObjectIdentity_: '',
|
||||
CustomSortOrderIndex: 0,
|
||||
Description: '',
|
||||
Id: '',
|
||||
IsAvailableForTagging: false,
|
||||
IsDeprecated: false,
|
||||
IsRoot: true,
|
||||
LocalCustomProperties: {
|
||||
_Sys_Nav_HoverText: 'Es wurden keine Terms gefunden. Bitte überprüfen Sie Ihre Einstellungen.',
|
||||
_Sys_Nav_ExcludedProviders: undefined,
|
||||
_Sys_Nav_SimpleLinkUrl: undefined
|
||||
},
|
||||
Name: 'Es wurden keine Terms gefunden. Bitte überprüfen Sie Ihre Einstellungen.',
|
||||
PathOfTerm: '',
|
||||
TermSet: undefined
|
||||
};
|
||||
sp.setup({
|
||||
spfxContext: context
|
||||
});
|
||||
this._taxonomyPickerService = new SPTermStorePickerService({
|
||||
anchorId: '',
|
||||
termsetNameOrID: termSetName,
|
||||
useSessionStorage: true,
|
||||
hideDeprecatedTags: true,
|
||||
hideTagsNotAvailableForTagging: false
|
||||
}, this.context);
|
||||
}
|
||||
// Implement the methods from ITaxonomyNavigationService interface here
|
||||
TaxonomyNavigationService.prototype.getMenuItems = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var _this = this;
|
||||
var siteCollectionUrl, termset, itemsDict, menuItems;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
siteCollectionUrl = this.context.pageContext.site.absoluteUrl;
|
||||
return [4 /*yield*/, this._taxonomyPickerService.getAllTerms(this.termSetName)];
|
||||
case 1:
|
||||
termset = _a.sent();
|
||||
itemsDict = new ItemDictionary();
|
||||
menuItems = [];
|
||||
if (!termset || !termset.Terms) {
|
||||
console.warn('No terms found in the term set');
|
||||
return [2 /*return*/, [new MenuItem(this._noTerm, 0, siteCollectionUrl)]];
|
||||
}
|
||||
termset.Terms.forEach(function (term) { return __awaiter(_this, void 0, void 0, function () {
|
||||
var menuItem, parentItem;
|
||||
return __generator(this, function (_a) {
|
||||
menuItem = new MenuItem(term, 0, siteCollectionUrl);
|
||||
itemsDict.Add(term.Id, menuItem);
|
||||
if (menuItem.pathDepth === 1) {
|
||||
menuItems.push(menuItem);
|
||||
}
|
||||
else {
|
||||
parentItem = itemsDict.Get(term.ParentId);
|
||||
if (parentItem) {
|
||||
parentItem.items.push(menuItem);
|
||||
}
|
||||
else {
|
||||
console.warn("Item without parent: " + term.PathOfTerm);
|
||||
}
|
||||
}
|
||||
return [2 /*return*/];
|
||||
});
|
||||
}); });
|
||||
return [2 /*return*/, menuItems];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
return TaxonomyNavigationService;
|
||||
}());
|
||||
export { TaxonomyNavigationService };
|
||||
|
||||
//# sourceMappingURL=TaxonomyNavigationService.js.map
|
||||
1
lib/services/TaxonomyNavigationService.js.map
Normal file
1
lib/services/TaxonomyNavigationService.js.map
Normal file
File diff suppressed because one or more lines are too long
20
lib/services/UserCustomActionService/IUserCustomActionProps.d.ts
vendored
Normal file
20
lib/services/UserCustomActionService/IUserCustomActionProps.d.ts
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
export interface IUserCustomActionProps {
|
||||
Id?: string;
|
||||
Title: string;
|
||||
Name?: string;
|
||||
Description?: string;
|
||||
Location: string;
|
||||
ScriptSrc?: string;
|
||||
ScriptBlock?: string;
|
||||
Url?: string;
|
||||
Sequence?: number;
|
||||
Group?: string;
|
||||
ImageUrl?: string;
|
||||
CommandUIExtension?: string;
|
||||
RegistrationType?: number;
|
||||
RegistrationId?: string;
|
||||
Rights?: {};
|
||||
Scope?: number;
|
||||
ClientSideComponentId?: string;
|
||||
ClientSideComponentProperties?: string;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=IUserCustomActionProps.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"services/UserCustomActionService/IUserCustomActionProps.js","sourcesContent":[],"sourceRoot":"..\\..\\..\\src"}
|
||||
10
lib/services/UserCustomActionService/IUserCustomActionService.d.ts
vendored
Normal file
10
lib/services/UserCustomActionService/IUserCustomActionService.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { UserCustomActionScope } from './UserCustomActionScope';
|
||||
import { IUserCustomActionProps } from './IUserCustomActionProps';
|
||||
import { UserCustomActionAddResult, UserCustomActionUpdateResult } from '@pnp/sp';
|
||||
export interface IUserCustomActionService {
|
||||
getUserCustomActions(scope: UserCustomActionScope, listId?: string): Promise<IUserCustomActionProps[]>;
|
||||
getUserCustomActionById(scope: UserCustomActionScope, id: string, listId?: string): Promise<IUserCustomActionProps>;
|
||||
addUserCustomAction(scope: UserCustomActionScope, customAction: IUserCustomActionProps, listId?: string): Promise<UserCustomActionAddResult>;
|
||||
updateUserCustomAction(scope: UserCustomActionScope, id: string, props: {}, listId?: string): Promise<UserCustomActionUpdateResult>;
|
||||
deleteUserCustomAction(scope: UserCustomActionScope, customAction: IUserCustomActionProps, listId?: string): Promise<void>;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//# sourceMappingURL=IUserCustomActionService.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"services/UserCustomActionService/IUserCustomActionService.js","sourcesContent":[],"sourceRoot":"..\\..\\..\\src"}
|
||||
5
lib/services/UserCustomActionService/UserCustomActionScope.d.ts
vendored
Normal file
5
lib/services/UserCustomActionService/UserCustomActionScope.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare enum UserCustomActionScope {
|
||||
Web = "web",
|
||||
Site = "site",
|
||||
List = "list",
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
export var UserCustomActionScope;
|
||||
(function (UserCustomActionScope) {
|
||||
UserCustomActionScope["Web"] = "web";
|
||||
UserCustomActionScope["Site"] = "site";
|
||||
UserCustomActionScope["List"] = "list";
|
||||
})(UserCustomActionScope = UserCustomActionScope || (UserCustomActionScope = {}));
|
||||
|
||||
//# sourceMappingURL=UserCustomActionScope.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["services/UserCustomActionService/UserCustomActionScope.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC7B,oCAAW,CAAA;IACX,sCAAa,CAAA;IACb,sCAAa,CAAA;AACjB,CAAC,EAJW,qBAAqB,GAArB,qBAAqB,KAArB,qBAAqB,QAIhC","file":"services/UserCustomActionService/UserCustomActionScope.js","sourcesContent":["export enum UserCustomActionScope {\r\n Web = 'web',\r\n Site = 'site',\r\n List = 'list'\r\n}\r\n"],"sourceRoot":"..\\..\\..\\src"}
|
||||
13
lib/services/UserCustomActionService/UserCustomActionService.d.ts
vendored
Normal file
13
lib/services/UserCustomActionService/UserCustomActionService.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { UserCustomActionAddResult, UserCustomActionUpdateResult } from '@pnp/sp/src/usercustomactions';
|
||||
import { IUserCustomActionService } from './IUserCustomActionService';
|
||||
import { UserCustomActionScope } from './UserCustomActionScope';
|
||||
import { IUserCustomActionProps } from './IUserCustomActionProps';
|
||||
import { ApplicationCustomizerContext } from '@microsoft/sp-application-base';
|
||||
export declare class UserCustomActionService implements IUserCustomActionService {
|
||||
constructor(context: ApplicationCustomizerContext);
|
||||
getUserCustomActions(scope: UserCustomActionScope, listId?: string): Promise<IUserCustomActionProps[]>;
|
||||
getUserCustomActionById(scope: UserCustomActionScope, id: string, listId?: string): Promise<IUserCustomActionProps>;
|
||||
addUserCustomAction(scope: UserCustomActionScope, customAction: IUserCustomActionProps, listId?: string): Promise<UserCustomActionAddResult>;
|
||||
updateUserCustomAction(scope: UserCustomActionScope, id: string, props: {}, listId?: string): Promise<UserCustomActionUpdateResult>;
|
||||
deleteUserCustomAction(scope: UserCustomActionScope, customAction: IUserCustomActionProps, listId?: string): Promise<void>;
|
||||
}
|
||||
210
lib/services/UserCustomActionService/UserCustomActionService.js
Normal file
210
lib/services/UserCustomActionService/UserCustomActionService.js
Normal file
@@ -0,0 +1,210 @@
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [0, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
import { sp } from '@pnp/sp';
|
||||
import { UserCustomActionScope } from './UserCustomActionScope';
|
||||
var UserCustomActionService = (function () {
|
||||
function UserCustomActionService(context) {
|
||||
sp.setup({
|
||||
spfxContext: context
|
||||
});
|
||||
}
|
||||
UserCustomActionService.prototype.getUserCustomActions = function (scope, listId) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var actions, _a, error_1;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
_b.trys.push([0, 9, , 10]);
|
||||
actions = void 0;
|
||||
_a = scope;
|
||||
switch (_a) {
|
||||
case UserCustomActionScope.Web: return [3 /*break*/, 1];
|
||||
case UserCustomActionScope.Site: return [3 /*break*/, 3];
|
||||
case UserCustomActionScope.List: return [3 /*break*/, 5];
|
||||
}
|
||||
return [3 /*break*/, 7];
|
||||
case 1: return [4 /*yield*/, sp.web.userCustomActions.get()];
|
||||
case 2:
|
||||
actions = _b.sent();
|
||||
return [3 /*break*/, 8];
|
||||
case 3: return [4 /*yield*/, sp.site.userCustomActions.get()];
|
||||
case 4:
|
||||
actions = _b.sent();
|
||||
return [3 /*break*/, 8];
|
||||
case 5:
|
||||
if (!listId) {
|
||||
throw new Error('List ID is required for List scope');
|
||||
}
|
||||
return [4 /*yield*/, sp.web.lists.getById(listId).userCustomActions.get()];
|
||||
case 6:
|
||||
actions = _b.sent();
|
||||
return [3 /*break*/, 8];
|
||||
case 7: throw new Error('Invalid scope');
|
||||
case 8: return [2 /*return*/, actions];
|
||||
case 9:
|
||||
error_1 = _b.sent();
|
||||
console.error('Error getting user custom actions: ', error_1);
|
||||
throw error_1;
|
||||
case 10: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
UserCustomActionService.prototype.getUserCustomActionById = function (scope, id, listId) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
try {
|
||||
switch (scope) {
|
||||
case UserCustomActionScope.Web:
|
||||
return [2 /*return*/, sp.web.userCustomActions.getById(id)];
|
||||
case UserCustomActionScope.Site:
|
||||
return [2 /*return*/, sp.site.userCustomActions.getById(id)];
|
||||
case UserCustomActionScope.List:
|
||||
if (!listId) {
|
||||
throw new Error('List ID is required for List scope');
|
||||
}
|
||||
return [2 /*return*/, sp.web.lists.getById(listId).userCustomActions.getById(id)];
|
||||
default:
|
||||
throw new Error('Invalid scope');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Error getting user custom action by ID: ', error);
|
||||
throw error;
|
||||
}
|
||||
return [2 /*return*/];
|
||||
});
|
||||
});
|
||||
};
|
||||
UserCustomActionService.prototype.addUserCustomAction = function (scope, customAction, listId) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
try {
|
||||
switch (scope) {
|
||||
case UserCustomActionScope.Web:
|
||||
return [2 /*return*/, sp.web.userCustomActions.add(customAction)];
|
||||
case UserCustomActionScope.Site:
|
||||
return [2 /*return*/, sp.site.userCustomActions.add(customAction)];
|
||||
case UserCustomActionScope.List:
|
||||
if (!listId) {
|
||||
throw new Error('List ID is required for List scope');
|
||||
}
|
||||
return [2 /*return*/, sp.web.lists.getById(listId).userCustomActions.add(customAction)];
|
||||
default:
|
||||
throw new Error('Invalid scope');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Error adding user custom action: ', error);
|
||||
throw error;
|
||||
}
|
||||
return [2 /*return*/];
|
||||
});
|
||||
});
|
||||
};
|
||||
UserCustomActionService.prototype.updateUserCustomAction = function (scope, id, props, listId) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var result, _a, error_2;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
_b.trys.push([0, 9, , 10]);
|
||||
result = void 0;
|
||||
_a = scope;
|
||||
switch (_a) {
|
||||
case UserCustomActionScope.Web: return [3 /*break*/, 1];
|
||||
case UserCustomActionScope.Site: return [3 /*break*/, 3];
|
||||
case UserCustomActionScope.List: return [3 /*break*/, 5];
|
||||
}
|
||||
return [3 /*break*/, 7];
|
||||
case 1: return [4 /*yield*/, sp.web.userCustomActions.getById(id).update(props)];
|
||||
case 2:
|
||||
result = _b.sent();
|
||||
return [3 /*break*/, 8];
|
||||
case 3: return [4 /*yield*/, sp.site.userCustomActions.getById(id).update(props)];
|
||||
case 4:
|
||||
result = _b.sent();
|
||||
return [3 /*break*/, 8];
|
||||
case 5:
|
||||
if (!listId) {
|
||||
throw new Error('List ID is required for List scope');
|
||||
}
|
||||
return [4 /*yield*/, sp.web.lists.getById(listId).userCustomActions.getById(id).update(props)];
|
||||
case 6:
|
||||
result = _b.sent();
|
||||
return [3 /*break*/, 8];
|
||||
case 7: throw new Error('Invalid scope');
|
||||
case 8: return [2 /*return*/, result];
|
||||
case 9:
|
||||
error_2 = _b.sent();
|
||||
console.error('Error updating user custom action: ', error_2);
|
||||
throw error_2;
|
||||
case 10: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
UserCustomActionService.prototype.deleteUserCustomAction = function (scope, customAction, listId) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
try {
|
||||
switch (scope) {
|
||||
case UserCustomActionScope.Web:
|
||||
return [2 /*return*/, sp.web.userCustomActions.getById(customAction.Id).delete()];
|
||||
case UserCustomActionScope.Site:
|
||||
return [2 /*return*/, sp.site.userCustomActions.getById(customAction.Id).delete()];
|
||||
case UserCustomActionScope.List:
|
||||
if (!listId) {
|
||||
throw new Error('List ID is required for List scope');
|
||||
}
|
||||
return [2 /*return*/, sp.web.lists.getById(listId).userCustomActions.getById(customAction.Id).delete()];
|
||||
default:
|
||||
throw new Error('Invalid scope');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Error deleting user custom action: ', error);
|
||||
throw error;
|
||||
}
|
||||
return [2 /*return*/];
|
||||
});
|
||||
});
|
||||
};
|
||||
return UserCustomActionService;
|
||||
}());
|
||||
export { UserCustomActionService };
|
||||
|
||||
//# sourceMappingURL=UserCustomActionService.js.map
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user