1 | import { _Web } from "../webs/types.js";
|
2 | import { CreateClientsidePage, ClientsidePageFromFile, ClientsideWebpart, } from "./types.js";
|
3 | import { SPCollection, SPInstance } from "../spqueryable.js";
|
4 | import { spPost } from "../operations.js";
|
5 | import { body } from "@pnp/queryable";
|
6 | import { 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 |
|
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 |
|
\ | No newline at end of file |