UNPKG

1.62 kBJavaScriptView Raw
1import { _Web } from "../webs/types.js";
2import { CreateClientsidePage, ClientsidePageFromFile, ClientsideWebpart, } from "./types.js";
3import { SPCollection, SPInstance } from "../spqueryable.js";
4import { spPost } from "../operations.js";
5import { body } from "@pnp/queryable";
6import { extractWebUrl } from "@pnp/sp";
7_Web.prototype.getClientsideWebParts = function () {
8 return SPCollection(this, "GetClientSideWebParts")();
9};
10_Web.prototype.addClientsidePage =
11 function (pageName, title = pageName.replace(/\.[^/.]+$/, ""), layout, promotedState) {
12 return CreateClientsidePage(this, pageName, title, layout, promotedState);
13 };
14_Web.prototype.loadClientsidePage = function (path) {
15 return ClientsidePageFromFile(this.getFileByServerRelativePath(path));
16};
17_Web.prototype.addRepostPage = async function (details) {
18 const query = SPInstance([this, extractWebUrl(this.toUrl())], "_api/sitepages/pages/reposts");
19 const r = await spPost(query, body(details));
20 return r.AbsoluteUrl;
21};
22// eslint-disable-next-line max-len
23_Web.prototype.addFullPageApp = async function (pageName, title = pageName.replace(/\.[^/.]+$/, ""), componentId, promotedState) {
24 const parts = await this.getClientsideWebParts();
25 const test = new RegExp(`{?${componentId}}?`, "i");
26 const partDef = parts.find(p => test.test(p.Id));
27 const part = ClientsideWebpart.fromComponentDef(partDef);
28 const page = await this.addClientsidePage(pageName, title, "SingleWebPartAppPage", promotedState);
29 page.addSection().addColumn(12).addControl(part);
30 return page;
31};
32//# sourceMappingURL=web.js.map
\No newline at end of file