UNPKG

17.1 kBTypeScriptView Raw
1import { IFile } from "../files/types.js";
2import { IItem } from "../items/types.js";
3import { _SPQueryable, SPInit } from "../spqueryable.js";
4import { IWeb } from "../webs/types.js";
5import "../files/web.js";
6import "../comments/item.js";
7/**
8 * Page promotion state
9 */
10export declare const enum PromotedState {
11 /**
12 * Regular client side page
13 */
14 NotPromoted = 0,
15 /**
16 * Page that will be promoted as news article after publishing
17 */
18 PromoteOnPublish = 1,
19 /**
20 * Page that is promoted as news article
21 */
22 Promoted = 2
23}
24/**
25 * Type describing the available page layout types for client side "modern" pages
26 */
27export declare type ClientsidePageLayoutType = "Article" | "Home" | "SingleWebPartAppPage" | "RepostPage";
28/**
29 * Column size factor. Max value is 12 (= one column), other options are 8,6,4 or 0
30 */
31export declare type CanvasColumnFactor = 0 | 2 | 4 | 6 | 8 | 12;
32/**
33 * Represents the data and methods associated with client side "modern" pages
34 */
35export declare class _ClientsidePage extends _SPQueryable {
36 protected json?: Partial<IPageData>;
37 sections: CanvasSection[];
38 commentsDisabled: boolean;
39 private _pageSettings;
40 private _layoutPart;
41 private _bannerImageDirty;
42 private _bannerImageThumbnailUrlDirty;
43 /**
44 * PLEASE DON'T USE THIS CONSTRUCTOR DIRECTLY, thank you 🐇
45 */
46 constructor(base: SPInit, path?: string, json?: Partial<IPageData>, noInit?: boolean, sections?: CanvasSection[], commentsDisabled?: boolean);
47 private static getDefaultLayoutPart;
48 get pageLayout(): ClientsidePageLayoutType;
49 set pageLayout(value: ClientsidePageLayoutType);
50 get bannerImageUrl(): string;
51 set bannerImageUrl(value: string);
52 get thumbnailUrl(): string;
53 set thumbnailUrl(value: string);
54 get topicHeader(): string;
55 set topicHeader(value: string);
56 get title(): string;
57 set title(value: string);
58 get reservedHeight(): number;
59 set reservedHeight(value: number);
60 get description(): string;
61 set description(value: string);
62 get layoutType(): LayoutType;
63 set layoutType(value: LayoutType);
64 get headerTextAlignment(): TextAlignment;
65 set headerTextAlignment(value: TextAlignment);
66 get showTopicHeader(): boolean;
67 set showTopicHeader(value: boolean);
68 get showPublishDate(): boolean;
69 set showPublishDate(value: boolean);
70 get hasVerticalSection(): boolean;
71 get authorByLine(): string | null;
72 get verticalSection(): CanvasSection | null;
73 /**
74 * Add a section to this page
75 */
76 addSection(): CanvasSection;
77 /**
78 * Add a section to this page
79 */
80 addVerticalSection(): CanvasSection;
81 /**
82 * Loads this instance from the appropriate JSON data
83 *
84 * @param pageData JSON data to load (replaces any existing data)
85 */
86 fromJSON(pageData: Partial<IPageData>): this;
87 /**
88 * Loads this page's content from the server
89 */
90 load(): Promise<IClientsidePage>;
91 /**
92 * Persists the content changes (sections, columns, and controls) [does not work with batching]
93 *
94 * @param publish If true the page is published, if false the changes are persisted to SharePoint but not published [Default: true]
95 */
96 save(publish?: boolean): Promise<boolean>;
97 /**
98 * Discards the checkout of this page
99 */
100 discardPageCheckout(): Promise<void>;
101 /**
102 * Promotes this page as a news item
103 */
104 promoteToNews(): Promise<boolean>;
105 /**
106 * Finds a control by the specified instance id
107 *
108 * @param id Instance id of the control to find
109 */
110 findControlById<T extends ColumnControl<any> = ColumnControl<any>>(id: string): T;
111 /**
112 * Finds a control within this page's control tree using the supplied predicate
113 *
114 * @param predicate Takes a control and returns true or false, if true that control is returned by findControl
115 */
116 findControl<T extends ColumnControl<any> = ColumnControl<any>>(predicate: (c: ColumnControl<any>) => boolean): T;
117 /**
118 * Creates a new page with all of the content copied from this page
119 *
120 * @param web The web where we will create the copy
121 * @param pageName The file name of the new page
122 * @param title The title of the new page
123 * @param publish If true the page will be published (Default: true)
124 */
125 copy(web: IWeb, pageName: string, title: string, publish?: boolean, promotedState?: PromotedState): Promise<IClientsidePage>;
126 /**
127 * Copies the content from this page to the supplied page instance NOTE: fully overwriting any previous content!!
128 *
129 * @param page Page whose content we replace with this page's content
130 * @param publish If true the page will be published after the copy, if false it will be saved but left unpublished (Default: true)
131 */
132 copyTo(page: IClientsidePage, publish?: boolean): Promise<IClientsidePage>;
133 /**
134 * Sets the modern page banner image
135 *
136 * @param url Url of the image to display
137 * @param altText Alt text to describe the image
138 * @param bannerProps Additional properties to control display of the banner
139 */
140 setBannerImage(url: string, props?: IBannerImageProps): void;
141 /**
142 * Sets the banner image url from an external source. You must call save to persist the changes
143 *
144 * @param url absolute url of the external file
145 * @param props optional set of properties to control display of the banner image
146 */
147 setBannerImageFromExternalUrl(url: string, props?: IBannerImageProps): Promise<void>;
148 /**
149 * Sets the authors for this page from the supplied list of user integer ids
150 *
151 * @param authorId The integer id of the user to set as the author
152 */
153 setAuthorById(authorId: number): Promise<void>;
154 /**
155 * Sets the authors for this page from the supplied list of user integer ids
156 *
157 * @param authorLoginName The login name of the user (ex: i:0#.f|membership|name@tenant.com)
158 */
159 setAuthorByLoginName(authorLoginName: string): Promise<void>;
160 /**
161 * Gets the list item associated with this clientside page
162 *
163 * @param selects Specific set of fields to include when getting the item
164 */
165 getItem<T>(...selects: string[]): Promise<IItem & T>;
166 /**
167 * Recycle this page
168 */
169 recycle(): Promise<void>;
170 /**
171 * Delete this page
172 */
173 delete(): Promise<void>;
174 /**
175 * Schedules a page for publishing
176 *
177 * @param publishDate Date to publish the item
178 * @returns Version which was scheduled to be published
179 */
180 schedulePublish(publishDate: Date): Promise<string>;
181 /**
182 * Saves a copy of this page as a template in this library's Templates folder
183 *
184 * @param publish If true the template is published, false the template is not published (default: true)
185 * @returns IClientsidePage instance representing the new template page
186 */
187 saveAsTemplate(publish?: boolean): Promise<IClientsidePage>;
188 /**
189 * Share this Page's Preview content by Email
190 *
191 * @param emails Set of emails to which the preview is shared
192 * @param message The message to include
193 * @returns void
194 */
195 share(emails: string[], message: string): Promise<void>;
196 protected getCanvasContent1(): string;
197 protected getLayoutWebpartsContent(): string;
198 protected setControls(controls: IClientsideControlBaseData[]): void;
199 protected getControls(): IClientsideControlBaseData[];
200 private getEmphasisObj;
201 private promoteNewsImpl;
202 /**
203 * Merges the control into the tree of sections and columns for this page
204 *
205 * @param control The control to merge
206 */
207 private mergePartToTree;
208 /**
209 * Merges the supplied column into the tree
210 *
211 * @param column Column to merge
212 * @param position The position data for the column
213 */
214 private mergeColumnToTree;
215 /**
216 * Handle the logic to get or create a section based on the supplied order and layoutIndex
217 *
218 * @param order Section order
219 * @param layoutIndex Layout Index (1 === normal, 2 === vertical section)
220 * @param emphasis The section emphasis
221 */
222 private getOrCreateSection;
223 /**
224 * Based on issue #1690 we need to take special case actions to ensure some things
225 * can be saved properly without breaking existing pages.
226 *
227 * @param control The control we are ensuring is "ready" to be saved
228 */
229 private specialSaveHandling;
230}
231export interface IClientsidePage extends _ClientsidePage {
232}
233/**
234 * Loads a client side page from the supplied IFile instance
235 *
236 * @param file Source IFile instance
237 */
238export declare const ClientsidePageFromFile: (file: IFile) => Promise<IClientsidePage>;
239/**
240 * Creates a new client side page
241 *
242 * @param web The web or list
243 * @param pageName The name of the page (filename)
244 * @param title The page's title
245 * @param PageLayoutType Layout to use when creating the page
246 */
247export declare const CreateClientsidePage: (web: IWeb, pageName: string, title: string, PageLayoutType?: ClientsidePageLayoutType, promotedState?: PromotedState) => Promise<IClientsidePage>;
248export declare class CanvasSection {
249 protected page: IClientsidePage;
250 columns: CanvasColumn[];
251 private _emphasis;
252 /**
253 * Used to track this object inside the collection at runtime
254 */
255 private _memId;
256 private _order;
257 private _layoutIndex;
258 constructor(page: IClientsidePage, order: number, layoutIndex: number, columns?: CanvasColumn[], _emphasis?: 0 | 1 | 2 | 3);
259 get order(): number;
260 set order(value: number);
261 get layoutIndex(): number;
262 set layoutIndex(value: number);
263 /**
264 * Default column (this.columns[0]) for this section
265 */
266 get defaultColumn(): CanvasColumn;
267 /**
268 * Adds a new column to this section
269 */
270 addColumn(factor: CanvasColumnFactor, layoutIndex?: number): CanvasColumn;
271 /**
272 * Adds a control to the default column for this section
273 *
274 * @param control Control to add to the default column
275 */
276 addControl(control: ColumnControl<any>): this;
277 get emphasis(): 0 | 1 | 2 | 3;
278 set emphasis(value: 0 | 1 | 2 | 3);
279 /**
280 * Removes this section and all contained columns and controls from the collection
281 */
282 remove(): void;
283}
284export declare class CanvasColumn {
285 protected json: IClientsidePageColumnData;
286 controls: ColumnControl<any>[];
287 static Default: IClientsidePageColumnData;
288 private _section;
289 private _memId;
290 constructor(json?: IClientsidePageColumnData, controls?: ColumnControl<any>[]);
291 get data(): IClientsidePageColumnData;
292 get section(): CanvasSection;
293 set section(section: CanvasSection);
294 get order(): number;
295 set order(value: number);
296 get factor(): CanvasColumnFactor;
297 set factor(value: CanvasColumnFactor);
298 addControl(control: ColumnControl<any>): this;
299 getControl<T extends ColumnControl<any>>(index: number): T;
300 remove(): void;
301}
302export declare abstract class ColumnControl<T extends ICanvasControlBaseData> {
303 protected json: T;
304 private _column;
305 constructor(json: T);
306 abstract get order(): number;
307 abstract set order(value: number);
308 get id(): string;
309 get data(): T;
310 get column(): CanvasColumn | null;
311 set column(value: CanvasColumn);
312 remove(): void;
313 protected setData(data: T): void;
314 protected abstract onColumnChange(col: CanvasColumn): void;
315}
316export declare class ClientsideText extends ColumnControl<IClientsideTextData> {
317 static Default: IClientsideTextData;
318 constructor(text: string, json?: IClientsideTextData);
319 get text(): string;
320 set text(value: string);
321 get order(): number;
322 set order(value: number);
323 protected onColumnChange(col: CanvasColumn): void;
324}
325export declare class ClientsideWebpart extends ColumnControl<IClientsideWebPartData> {
326 static Default: IClientsideWebPartData;
327 constructor(json?: IClientsideWebPartData);
328 static fromComponentDef(definition: IClientsidePageComponent): ClientsideWebpart;
329 get title(): string;
330 set title(value: string);
331 get description(): string;
332 set description(value: string);
333 get order(): number;
334 set order(value: number);
335 get height(): number;
336 set height(value: number);
337 get width(): number;
338 set width(value: number);
339 get dataVersion(): string;
340 set dataVersion(value: string);
341 setProperties<T = any>(properties: T): this;
342 getProperties<T = any>(): T;
343 setServerProcessedContent<T = any>(properties: T): this;
344 getServerProcessedContent<T = any>(): T;
345 protected onColumnChange(col: CanvasColumn): void;
346 protected import(component: IClientsidePageComponent): void;
347}
348export interface IPageData {
349 readonly "odata.metadata": string;
350 readonly "odata.type": "SP.Publishing.SitePage";
351 readonly "odata.id": string;
352 readonly "odata.editLink": string;
353 AbsoluteUrl: string;
354 AuthorByline: string[] | null;
355 BannerImageUrl: string;
356 BannerThumbnailUrl: string;
357 ContentTypeId: null | string;
358 Description: string;
359 DoesUserHaveEditPermission: boolean;
360 FileName: string;
361 readonly FirstPublished: string;
362 readonly Id: number;
363 IsPageCheckedOutToCurrentUser: boolean;
364 IsWebWelcomePage: boolean;
365 readonly Modified: string;
366 PageLayoutType: ClientsidePageLayoutType;
367 Path: {
368 DecodedUrl: string;
369 };
370 PromotedState: number;
371 Title: string;
372 TopicHeader: null | string;
373 readonly UniqueId: string;
374 Url: string;
375 readonly Version: string;
376 readonly VersionInfo: {
377 readonly LastVersionCreated: string;
378 readonly LastVersionCreatedBy: string;
379 };
380 AlternativeUrlMap: string;
381 CanvasContent1: string;
382 LayoutWebpartsContent: string;
383}
384/**
385 * Client side webpart object (retrieved via the _api/web/GetClientSideWebParts REST call)
386 */
387export interface IClientsidePageComponent {
388 /**
389 * Component type for client side webpart object
390 */
391 ComponentType: number;
392 /**
393 * Id for client side webpart object
394 */
395 Id: string;
396 /**
397 * Manifest for client side webpart object
398 */
399 Manifest: string;
400 /**
401 * Manifest type for client side webpart object
402 */
403 ManifestType: number;
404 /**
405 * Name for client side webpart object
406 */
407 Name: string;
408 /**
409 * Status for client side webpart object
410 */
411 Status: number;
412}
413export interface IClientsideControlBaseData {
414 controlType: number;
415}
416export interface ICanvasControlBaseData extends IClientsideControlBaseData {
417 id: string;
418 emphasis: IClientControlEmphasis;
419 displayMode: number;
420}
421export interface IClientsidePageSettingsSlice extends IClientsideControlBaseData {
422 htmlAttributes?: string[];
423 pageSettingsSlice: {
424 "isDefaultDescription": boolean;
425 "isDefaultThumbnail": boolean;
426 };
427}
428export interface IClientsidePageColumnData extends IClientsideControlBaseData {
429 controlType: 0;
430 displayMode: number;
431 emphasis: IClientControlEmphasis;
432 position: IPosition;
433}
434interface IPosition {
435 zoneIndex: number;
436 sectionIndex: number;
437 controlIndex?: number;
438 sectionFactor?: CanvasColumnFactor;
439 layoutIndex: number;
440}
441export interface IClientsideTextData extends ICanvasControlBaseData {
442 controlType: 4;
443 position: IPosition;
444 anchorComponentId: string;
445 editorType: "CKEditor";
446 addedFromPersistedData: boolean;
447 innerHTML: string;
448}
449export interface IClientsideWebPartData<PropertiesType = any> extends ICanvasControlBaseData {
450 controlType: 3;
451 position: IPosition;
452 webPartId: string;
453 reservedHeight: number;
454 reservedWidth: number;
455 addedFromPersistedData: boolean;
456 webPartData: {
457 id: string;
458 instanceId: string;
459 title: string;
460 description: string;
461 serverProcessedContent?: {
462 htmlStrings?: Record<string, string>;
463 searchablePlainTexts?: Record<string, string>;
464 imageSources?: Record<string, string>;
465 links?: Record<string, string>;
466 };
467 dataVersion: string;
468 properties: PropertiesType;
469 };
470}
471export interface IClientControlEmphasis {
472 zoneEmphasis?: 0 | 1 | 2 | 3;
473}
474export declare type LayoutType = "FullWidthImage" | "NoImage" | "ColorBlock" | "CutInShape";
475export declare type TextAlignment = "Left" | "Center";
476export interface IBannerImageProps {
477 altText?: string;
478 imageSourceType?: number;
479 translateX?: number;
480 translateY?: number;
481}
482export interface IRepostPage {
483 Description?: string;
484 IsBannerImageUrlExternal?: boolean;
485 OriginalSourceListId?: string;
486 ShouldSaveAsDraft?: boolean;
487 OriginalSourceSiteId?: string;
488 BannerImageUrl?: string;
489 Title?: string;
490 OriginalSourceItemId?: string;
491 OriginalSourceUrl?: string;
492 OriginalSourceWebId?: string;
493}
494export {};
495//# sourceMappingURL=types.d.ts.map
\No newline at end of file