UNPKG

4.75 kBJavaScriptView Raw
1import { __decorate } from "tslib";
2import { _SPCollection, spInvokableFactory, deleteable, _SPInstance, _SPQueryable, } from "../spqueryable.js";
3import { body } from "@pnp/queryable";
4import { defaultPath } from "../decorators.js";
5import { spPost, spPostMerge } from "../operations.js";
6import { extractWebUrl } from "../index.js";
7import { combine } from "@pnp/core";
8/**
9 * Represents a collection of navigation nodes
10 *
11 */
12export class _NavigationNodes extends _SPCollection {
13 /**
14 * Gets a navigation node by id
15 *
16 * @param id The id of the node
17 */
18 getById(id) {
19 return NavigationNode(this).concat(`(${id})`);
20 }
21 /**
22 * Adds a new node to the collection
23 *
24 * @param title Display name of the node
25 * @param url The url of the node
26 * @param visible If true the node is visible, otherwise it is hidden (default: true)
27 */
28 async add(title, url, visible = true) {
29 const postBody = body({
30 IsVisible: visible,
31 Title: title,
32 Url: url,
33 });
34 const data = await spPost(NavigationNodes(this, null), postBody);
35 return {
36 data,
37 node: this.getById(data.Id),
38 };
39 }
40 /**
41 * Moves a node to be after another node in the navigation
42 *
43 * @param nodeId Id of the node to move
44 * @param previousNodeId Id of the node after which we move the node specified by nodeId
45 */
46 moveAfter(nodeId, previousNodeId) {
47 const postBody = body({
48 nodeId: nodeId,
49 previousNodeId: previousNodeId,
50 });
51 return spPost(NavigationNodes(this, "MoveAfter"), postBody);
52 }
53}
54export const NavigationNodes = spInvokableFactory(_NavigationNodes);
55/**
56 * Represents an instance of a navigation node
57 *
58 */
59export class _NavigationNode extends _SPInstance {
60 constructor() {
61 super(...arguments);
62 this.delete = deleteable();
63 }
64 /**
65 * Represents the child nodes of this node
66 */
67 get children() {
68 return NavigationNodes(this, "children");
69 }
70 /**
71 * Updates this node
72 *
73 * @param properties Properties used to update this node
74 */
75 async update(properties) {
76 const data = await spPostMerge(this, body(properties));
77 return {
78 data,
79 node: this,
80 };
81 }
82}
83export const NavigationNode = spInvokableFactory(_NavigationNode);
84/**
85 * Exposes the navigation components
86 *
87 */
88let _Navigation = class _Navigation extends _SPQueryable {
89 /**
90 * Gets the quicklaunch navigation nodes for the current context
91 *
92 */
93 get quicklaunch() {
94 return NavigationNodes(this, "quicklaunch");
95 }
96 /**
97 * Gets the top bar navigation nodes for the current context
98 *
99 */
100 get topNavigationBar() {
101 return NavigationNodes(this, "topnavigationbar");
102 }
103};
104_Navigation = __decorate([
105 defaultPath("navigation")
106], _Navigation);
107export { _Navigation };
108export const Navigation = spInvokableFactory(_Navigation);
109/**
110 * Represents the top level navigation service
111 */
112export class _NavigationService extends _SPQueryable {
113 constructor(base = null, path) {
114 super(base, path);
115 this._url = combine(extractWebUrl(this._url), "_api/navigation", path);
116 }
117 /**
118 * The MenuState service operation returns a Menu-State (dump) of a SiteMapProvider on a site.
119 *
120 * @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.
121 * @param depth Depth of the dump. If no value is provided a dump with the depth of 10 is returned
122 * @param mapProviderName The name identifying the SiteMapProvider to be used
123 * @param customProperties comma seperated list of custom properties to be returned.
124 */
125 getMenuState(menuNodeKey = null, depth = 10, mapProviderName = null, customProperties = null) {
126 return spPost(NavigationService(this, "MenuState"), body({
127 customProperties,
128 depth,
129 mapProviderName,
130 menuNodeKey,
131 }));
132 }
133 /**
134 * Tries to get a SiteMapNode.Key for a given URL within a site collection.
135 *
136 * @param currentUrl A url representing the SiteMapNode
137 * @param mapProviderName The name identifying the SiteMapProvider to be used
138 */
139 getMenuNodeKey(currentUrl, mapProviderName = null) {
140 return spPost(NavigationService(this, "MenuNodeKey"), body({
141 currentUrl,
142 mapProviderName,
143 }));
144 }
145}
146export const NavigationService = (base, path) => new _NavigationService(base, path);
147//# sourceMappingURL=types.js.map
\No newline at end of file