UNPKG

@pnp/sp

Version:

pnp - provides a fluent api for working with SharePoint REST

147 lines 4.75 kB
import { __decorate } from "tslib"; import { _SPCollection, spInvokableFactory, deleteable, _SPInstance, _SPQueryable, } from "../spqueryable.js"; import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; import { spPost, spPostMerge } from "../operations.js"; import { extractWebUrl } from "../index.js"; import { combine } from "@pnp/core"; /** * Represents a collection of navigation nodes * */ export class _NavigationNodes extends _SPCollection { /** * Gets a navigation node by id * * @param id The id of the node */ getById(id) { return NavigationNode(this).concat(`(${id})`); } /** * Adds a new node to the collection * * @param title Display name of the node * @param url The url of the node * @param visible If true the node is visible, otherwise it is hidden (default: true) */ async add(title, url, visible = true) { const postBody = body({ IsVisible: visible, Title: title, Url: url, }); const data = await spPost(NavigationNodes(this, null), postBody); return { data, node: this.getById(data.Id), }; } /** * Moves a node to be after another node in the navigation * * @param nodeId Id of the node to move * @param previousNodeId Id of the node after which we move the node specified by nodeId */ moveAfter(nodeId, previousNodeId) { const postBody = body({ nodeId: nodeId, previousNodeId: previousNodeId, }); return spPost(NavigationNodes(this, "MoveAfter"), postBody); } } export const NavigationNodes = spInvokableFactory(_NavigationNodes); /** * Represents an instance of a navigation node * */ export class _NavigationNode extends _SPInstance { constructor() { super(...arguments); this.delete = deleteable(); } /** * Represents the child nodes of this node */ get children() { return NavigationNodes(this, "children"); } /** * Updates this node * * @param properties Properties used to update this node */ async update(properties) { const data = await spPostMerge(this, body(properties)); return { data, node: this, }; } } export const NavigationNode = spInvokableFactory(_NavigationNode); /** * Exposes the navigation components * */ let _Navigation = class _Navigation extends _SPQueryable { /** * Gets the quicklaunch navigation nodes for the current context * */ get quicklaunch() { return NavigationNodes(this, "quicklaunch"); } /** * Gets the top bar navigation nodes for the current context * */ get topNavigationBar() { return NavigationNodes(this, "topnavigationbar"); } }; _Navigation = __decorate([ defaultPath("navigation") ], _Navigation); export { _Navigation }; export const Navigation = spInvokableFactory(_Navigation); /** * Represents the top level navigation service */ export class _NavigationService extends _SPQueryable { constructor(base = null, path) { super(base, path); this._url = combine(extractWebUrl(this._url), "_api/navigation", path); } /** * The MenuState service operation returns a Menu-State (dump) of a SiteMapProvider on a site. * * @param menuNodeKey MenuNode.Key of the start node within the SiteMapProvider If no key is provided the SiteMapProvider.RootNode will be the root of the menu state. * @param depth Depth of the dump. If no value is provided a dump with the depth of 10 is returned * @param mapProviderName The name identifying the SiteMapProvider to be used * @param customProperties comma seperated list of custom properties to be returned. */ getMenuState(menuNodeKey = null, depth = 10, mapProviderName = null, customProperties = null) { return spPost(NavigationService(this, "MenuState"), body({ customProperties, depth, mapProviderName, menuNodeKey, })); } /** * Tries to get a SiteMapNode.Key for a given URL within a site collection. * * @param currentUrl A url representing the SiteMapNode * @param mapProviderName The name identifying the SiteMapProvider to be used */ getMenuNodeKey(currentUrl, mapProviderName = null) { return spPost(NavigationService(this, "MenuNodeKey"), body({ currentUrl, mapProviderName, })); } } export const NavigationService = (base, path) => new _NavigationService(base, path); //# sourceMappingURL=types.js.map