@pnp/sp 2.7.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/LICENSE +25 -25
  2. package/appcatalog/index.d.ts +8 -8
  3. package/appcatalog/index.js +30 -30
  4. package/appcatalog/types.d.ts +81 -81
  5. package/appcatalog/types.js +177 -177
  6. package/appcatalog/web.d.ts +16 -16
  7. package/appcatalog/web.js +6 -6
  8. package/attachments/index.d.ts +2 -2
  9. package/attachments/index.js +2 -2
  10. package/attachments/item.d.ts +12 -12
  11. package/attachments/item.js +4 -4
  12. package/attachments/types.d.ts +92 -92
  13. package/attachments/types.js +240 -240
  14. package/batch.d.ts +17 -17
  15. package/batch.js +223 -223
  16. package/batch.js.map +1 -1
  17. package/clientside-pages/funcs.d.ts +22 -22
  18. package/clientside-pages/funcs.js +25 -25
  19. package/clientside-pages/index.d.ts +2 -2
  20. package/clientside-pages/index.js +2 -2
  21. package/clientside-pages/types.d.ts +496 -494
  22. package/clientside-pages/types.d.ts.map +1 -1
  23. package/clientside-pages/types.js +1496 -1485
  24. package/clientside-pages/types.js.map +1 -1
  25. package/clientside-pages/web.d.ts +41 -41
  26. package/clientside-pages/web.js +57 -57
  27. package/column-defaults/folder.d.ts +27 -27
  28. package/column-defaults/folder.js +82 -82
  29. package/column-defaults/index.d.ts +3 -3
  30. package/column-defaults/index.js +2 -2
  31. package/column-defaults/list.d.ts +19 -19
  32. package/column-defaults/list.js +198 -198
  33. package/column-defaults/types.d.ts +21 -21
  34. package/column-defaults/types.js +1 -1
  35. package/comments/clientside-page.d.ts +57 -57
  36. package/comments/clientside-page.d.ts.map +1 -1
  37. package/comments/clientside-page.js +136 -136
  38. package/comments/index.d.ts +2 -2
  39. package/comments/index.js +2 -2
  40. package/comments/item.d.ts +29 -29
  41. package/comments/item.js +47 -47
  42. package/comments/types.d.ts +107 -107
  43. package/comments/types.d.ts.map +1 -1
  44. package/comments/types.js +145 -145
  45. package/comments/types.js.map +1 -1
  46. package/content-types/index.d.ts +4 -4
  47. package/content-types/index.js +4 -4
  48. package/content-types/item.d.ts +12 -12
  49. package/content-types/item.js +4 -4
  50. package/content-types/list.d.ts +12 -12
  51. package/content-types/list.js +4 -4
  52. package/content-types/types.d.ts +107 -107
  53. package/content-types/types.js +166 -166
  54. package/content-types/web.d.ts +12 -12
  55. package/content-types/web.js +4 -4
  56. package/decorators.d.ts +11 -11
  57. package/decorators.js +28 -28
  58. package/features/index.d.ts +3 -3
  59. package/features/index.js +3 -3
  60. package/features/site.d.ts +12 -12
  61. package/features/site.js +4 -4
  62. package/features/types.d.ts +47 -47
  63. package/features/types.js +109 -109
  64. package/features/web.d.ts +12 -12
  65. package/features/web.js +4 -4
  66. package/fields/index.d.ts +4 -4
  67. package/fields/index.js +4 -4
  68. package/fields/list.d.ts +12 -12
  69. package/fields/list.js +4 -4
  70. package/fields/types.d.ts +368 -361
  71. package/fields/types.d.ts.map +1 -1
  72. package/fields/types.js +624 -609
  73. package/fields/types.js.map +1 -1
  74. package/fields/web.d.ts +17 -17
  75. package/fields/web.js +5 -5
  76. package/files/folder.d.ts +12 -12
  77. package/files/folder.js +4 -4
  78. package/files/index.d.ts +4 -4
  79. package/files/index.js +4 -4
  80. package/files/item.d.ts +12 -12
  81. package/files/item.js +4 -4
  82. package/files/types.d.ts +421 -421
  83. package/files/types.js +853 -853
  84. package/files/types.js.map +1 -1
  85. package/files/web.d.ts +35 -35
  86. package/files/web.js +15 -15
  87. package/folders/index.d.ts +4 -4
  88. package/folders/index.js +4 -4
  89. package/folders/item.d.ts +9 -9
  90. package/folders/item.js +4 -4
  91. package/folders/list.d.ts +12 -12
  92. package/folders/list.js +4 -4
  93. package/folders/types.d.ts +207 -207
  94. package/folders/types.js +433 -433
  95. package/folders/types.js.map +1 -1
  96. package/folders/web.d.ts +39 -39
  97. package/folders/web.js +15 -15
  98. package/forms/index.d.ts +2 -2
  99. package/forms/index.js +2 -2
  100. package/forms/list.d.ts +9 -9
  101. package/forms/list.js +4 -4
  102. package/forms/types.d.ts +35 -35
  103. package/forms/types.js +41 -41
  104. package/hubsites/index.d.ts +12 -12
  105. package/hubsites/index.js +15 -15
  106. package/hubsites/site.d.ts +26 -26
  107. package/hubsites/site.js +39 -39
  108. package/hubsites/types.d.ts +55 -55
  109. package/hubsites/types.js +53 -53
  110. package/hubsites/web.d.ts +21 -21
  111. package/hubsites/web.js +23 -23
  112. package/index.d.ts +14 -14
  113. package/index.js +13 -13
  114. package/items/index.d.ts +2 -2
  115. package/items/index.js +2 -2
  116. package/items/list.d.ts +9 -9
  117. package/items/list.js +4 -4
  118. package/items/types.d.ts +226 -219
  119. package/items/types.d.ts.map +1 -1
  120. package/items/types.js +549 -511
  121. package/items/types.js.map +1 -1
  122. package/lists/index.d.ts +2 -2
  123. package/lists/index.js +2 -2
  124. package/lists/types.d.ts +495 -495
  125. package/lists/types.js +522 -522
  126. package/lists/types.js.map +1 -1
  127. package/lists/web.d.ts +43 -43
  128. package/lists/web.js +27 -27
  129. package/navigation/index.d.ts +8 -8
  130. package/navigation/index.js +14 -14
  131. package/navigation/types.d.ts +154 -154
  132. package/navigation/types.js +219 -219
  133. package/navigation/web.d.ts +13 -13
  134. package/navigation/web.js +4 -4
  135. package/odata.d.ts +5 -5
  136. package/odata.js +90 -90
  137. package/odata.js.map +1 -1
  138. package/operations.d.ts +9 -9
  139. package/operations.js +63 -63
  140. package/package.json +4 -4
  141. package/presets/all.d.ts +72 -72
  142. package/presets/all.js +72 -72
  143. package/presets/core.d.ts +11 -11
  144. package/presets/core.js +11 -11
  145. package/profiles/index.d.ts +7 -7
  146. package/profiles/index.js +13 -13
  147. package/profiles/types.d.ts +357 -357
  148. package/profiles/types.js +454 -454
  149. package/readme.md +21 -21
  150. package/regional-settings/content-type.d.ts +7 -7
  151. package/regional-settings/content-type.js +4 -4
  152. package/regional-settings/field.d.ts +7 -7
  153. package/regional-settings/field.js +4 -4
  154. package/regional-settings/funcs.d.ts +2 -2
  155. package/regional-settings/funcs.js +8 -8
  156. package/regional-settings/index.d.ts +6 -6
  157. package/regional-settings/index.js +6 -6
  158. package/regional-settings/list.d.ts +7 -7
  159. package/regional-settings/list.js +4 -4
  160. package/regional-settings/types.d.ts +111 -111
  161. package/regional-settings/types.js +159 -159
  162. package/regional-settings/user-custom-actions.d.ts +7 -7
  163. package/regional-settings/user-custom-actions.js +4 -4
  164. package/regional-settings/web.d.ts +12 -12
  165. package/regional-settings/web.js +7 -7
  166. package/related-items/index.d.ts +1 -1
  167. package/related-items/index.js +1 -1
  168. package/related-items/types.d.ts +76 -76
  169. package/related-items/types.js +103 -103
  170. package/related-items/web.d.ts +12 -12
  171. package/related-items/web.js +9 -9
  172. package/rest.d.ts +44 -44
  173. package/rest.js +72 -72
  174. package/search/index.d.ts +30 -30
  175. package/search/index.js +25 -25
  176. package/search/query.d.ts +62 -62
  177. package/search/query.js +302 -302
  178. package/search/suggest.d.ts +76 -76
  179. package/search/suggest.js +66 -66
  180. package/search/types.d.ts +426 -426
  181. package/search/types.js +57 -57
  182. package/security/funcs.d.ts +43 -43
  183. package/security/funcs.js +142 -142
  184. package/security/index.d.ts +4 -4
  185. package/security/index.js +4 -4
  186. package/security/item.d.ts +7 -7
  187. package/security/item.js +14 -14
  188. package/security/list.d.ts +7 -7
  189. package/security/list.js +14 -14
  190. package/security/types.d.ts +318 -318
  191. package/security/types.js +399 -399
  192. package/security/web.d.ts +9 -9
  193. package/security/web.js +15 -15
  194. package/sharepointqueryable.d.ts +135 -135
  195. package/sharepointqueryable.js +265 -265
  196. package/sharing/file.d.ts +18 -18
  197. package/sharing/file.d.ts.map +1 -1
  198. package/sharing/file.js +116 -15
  199. package/sharing/file.js.map +1 -1
  200. package/sharing/folder.d.ts +9 -9
  201. package/sharing/folder.js +136 -136
  202. package/sharing/funcs.d.ts +62 -62
  203. package/sharing/funcs.js +239 -239
  204. package/sharing/funcs.js.map +1 -1
  205. package/sharing/index.d.ts +5 -5
  206. package/sharing/index.js +5 -5
  207. package/sharing/item.d.ts +16 -16
  208. package/sharing/item.js +15 -15
  209. package/sharing/types.d.ts +583 -583
  210. package/sharing/types.js +113 -113
  211. package/sharing/web.d.ts +19 -19
  212. package/sharing/web.js +76 -76
  213. package/site-designs/index.d.ts +8 -8
  214. package/site-designs/index.js +14 -14
  215. package/site-designs/types.d.ts +319 -319
  216. package/site-designs/types.js +203 -203
  217. package/site-designs/web.d.ts +25 -25
  218. package/site-designs/web.js +11 -11
  219. package/site-groups/index.d.ts +2 -2
  220. package/site-groups/index.js +2 -2
  221. package/site-groups/types.d.ts +89 -89
  222. package/site-groups/types.js +125 -125
  223. package/site-groups/web.d.ts +40 -40
  224. package/site-groups/web.js +30 -30
  225. package/site-scripts/index.d.ts +9 -9
  226. package/site-scripts/index.js +15 -15
  227. package/site-scripts/list.d.ts +12 -12
  228. package/site-scripts/list.js +24 -24
  229. package/site-scripts/types.d.ts +183 -183
  230. package/site-scripts/types.js +141 -141
  231. package/site-scripts/web.d.ts +13 -13
  232. package/site-scripts/web.js +5 -5
  233. package/site-users/index.d.ts +2 -2
  234. package/site-users/index.js +2 -2
  235. package/site-users/types.d.ts +138 -138
  236. package/site-users/types.js +122 -122
  237. package/site-users/web.d.ts +31 -31
  238. package/site-users/web.js +27 -27
  239. package/sites/index.d.ts +7 -7
  240. package/sites/index.js +13 -13
  241. package/sites/types.d.ts +147 -147
  242. package/sites/types.js +321 -321
  243. package/social/index.d.ts +10 -10
  244. package/social/index.js +13 -13
  245. package/social/types.d.ts +309 -309
  246. package/social/types.js +322 -322
  247. package/sphttpclient.d.ts +18 -18
  248. package/sphttpclient.js +189 -189
  249. package/splibconfig.d.ts +22 -22
  250. package/splibconfig.js +13 -13
  251. package/sputilities/index.d.ts +7 -7
  252. package/sputilities/index.js +13 -13
  253. package/sputilities/types.d.ts +130 -130
  254. package/sputilities/types.js +118 -118
  255. package/subscriptions/index.d.ts +2 -2
  256. package/subscriptions/index.js +2 -2
  257. package/subscriptions/list.d.ts +13 -13
  258. package/subscriptions/list.js +4 -4
  259. package/subscriptions/types.d.ts +54 -54
  260. package/subscriptions/types.js +111 -111
  261. package/taxonomy/index.d.ts +7 -7
  262. package/taxonomy/index.js +13 -13
  263. package/taxonomy/types.d.ts +200 -200
  264. package/taxonomy/types.js +347 -347
  265. package/taxonomy/types.js.map +1 -1
  266. package/telemetry.d.ts +12 -12
  267. package/telemetry.js +48 -48
  268. package/types.d.ts +218 -218
  269. package/types.js +79 -79
  270. package/user-custom-actions/index.d.ts +4 -4
  271. package/user-custom-actions/index.js +4 -4
  272. package/user-custom-actions/list.d.ts +12 -12
  273. package/user-custom-actions/list.js +4 -4
  274. package/user-custom-actions/site.d.ts +12 -12
  275. package/user-custom-actions/site.js +4 -4
  276. package/user-custom-actions/types.d.ts +82 -82
  277. package/user-custom-actions/types.js +93 -93
  278. package/user-custom-actions/web.d.ts +15 -15
  279. package/user-custom-actions/web.js +4 -4
  280. package/utils/escapeQueryStrValue.d.ts +1 -1
  281. package/utils/escapeQueryStrValue.js +19 -19
  282. package/utils/extractweburl.d.ts +1 -1
  283. package/utils/extractweburl.js +15 -15
  284. package/utils/file-names.d.ts +17 -17
  285. package/utils/file-names.js +38 -38
  286. package/utils/metadata.d.ts +5 -5
  287. package/utils/metadata.js +5 -5
  288. package/utils/objectToSPKeyValueCollection.d.ts +20 -20
  289. package/utils/objectToSPKeyValueCollection.js +16 -16
  290. package/utils/toResourcePath.d.ts +7 -7
  291. package/utils/toResourcePath.js +6 -6
  292. package/utils/toabsoluteurl.d.ts +7 -7
  293. package/utils/toabsoluteurl.js +61 -61
  294. package/views/index.d.ts +2 -2
  295. package/views/index.js +2 -2
  296. package/views/list.d.ts +23 -23
  297. package/views/list.js +8 -8
  298. package/views/types.d.ts +140 -140
  299. package/views/types.js +184 -184
  300. package/webparts/file.d.ts +15 -15
  301. package/webparts/file.js +6 -6
  302. package/webparts/index.d.ts +2 -2
  303. package/webparts/index.js +2 -2
  304. package/webparts/types.d.ts +83 -83
  305. package/webparts/types.js +117 -117
  306. package/webs/index.d.ts +16 -16
  307. package/webs/index.js +16 -16
  308. package/webs/types.d.ts +210 -210
  309. package/webs/types.js +295 -295
@@ -1,1486 +1,1497 @@
1
- import { __awaiter, __decorate, __extends, __generator, __read, __spreadArray } from "tslib";
2
- import { invokableFactory, body, headers } from "@pnp/odata";
3
- import { assign, getGUID, hOP, stringIsNullOrEmpty, objectDefinedNotNull, combine, isUrlAbsolute, isArray } from "@pnp/common";
4
- import { Item } from "../items/types.js";
5
- import { SharePointQueryable, _SharePointQueryable, SharePointQueryableCollection } from "../sharepointqueryable.js";
6
- import { metadata } from "../utils/metadata.js";
7
- import { List } from "../lists/types.js";
8
- import { odataUrlFrom } from "../odata.js";
9
- import { Web } from "../webs/types.js";
10
- import { extractWebUrl } from "../utils/extractweburl.js";
11
- import { Site } from "../sites/types.js";
12
- import { spPost } from "../operations.js";
13
- import { getNextOrder, reindex } from "./funcs.js";
14
- import "../files/web.js";
15
- import "../comments/item.js";
16
- import { tag } from "../telemetry.js";
17
- /**
18
- * Page promotion state
19
- */
20
- export var PromotedState;
21
- (function (PromotedState) {
22
- /**
23
- * Regular client side page
24
- */
25
- PromotedState[PromotedState["NotPromoted"] = 0] = "NotPromoted";
26
- /**
27
- * Page that will be promoted as news article after publishing
28
- */
29
- PromotedState[PromotedState["PromoteOnPublish"] = 1] = "PromoteOnPublish";
30
- /**
31
- * Page that is promoted as news article
32
- */
33
- PromotedState[PromotedState["Promoted"] = 2] = "Promoted";
34
- })(PromotedState || (PromotedState = {}));
35
- function initFrom(o, url) {
36
- return ClientsidePage(extractWebUrl(o.toUrl()), url).configureFrom(o);
37
- }
38
- /**
39
- * Represents the data and methods associated with client side "modern" pages
40
- */
41
- var _ClientsidePage = /** @class */ (function (_super) {
42
- __extends(_ClientsidePage, _super);
43
- /**
44
- * PLEASE DON'T USE THIS CONSTRUCTOR DIRECTLY, thank you 🐇
45
- */
46
- function _ClientsidePage(baseUrl, path, json, noInit, sections, commentsDisabled) {
47
- if (noInit === void 0) { noInit = false; }
48
- if (sections === void 0) { sections = []; }
49
- if (commentsDisabled === void 0) { commentsDisabled = false; }
50
- var _this = _super.call(this, baseUrl, path) || this;
51
- _this.json = json;
52
- _this.sections = sections;
53
- _this.commentsDisabled = commentsDisabled;
54
- _this._bannerImageDirty = false;
55
- _this._bannerImageThumbnailUrlDirty = false;
56
- // ensure we have a good url to build on for the pages api
57
- if (typeof baseUrl === "string") {
58
- _this.data.parentUrl = "";
59
- _this.data.url = combine(extractWebUrl(baseUrl), path);
60
- }
61
- else {
62
- _this.assign(initFrom(baseUrl, null), path);
63
- }
64
- // set a default page settings slice
65
- _this._pageSettings = { controlType: 0, pageSettingsSlice: { isDefaultDescription: true, isDefaultThumbnail: true } };
66
- // set a default layout part
67
- _this._layoutPart = _ClientsidePage.getDefaultLayoutPart();
68
- if (typeof json !== "undefined" && !noInit) {
69
- _this.fromJSON(json);
70
- }
71
- return _this;
72
- }
73
- _ClientsidePage.getDefaultLayoutPart = function () {
74
- return {
75
- dataVersion: "1.4",
76
- description: "Title Region Description",
77
- id: "cbe7b0a9-3504-44dd-a3a3-0e5cacd07788",
78
- instanceId: "cbe7b0a9-3504-44dd-a3a3-0e5cacd07788",
79
- properties: {
80
- authorByline: [],
81
- authors: [],
82
- layoutType: "FullWidthImage",
83
- showPublishDate: false,
84
- showTopicHeader: false,
85
- textAlignment: "Left",
86
- title: "",
87
- topicHeader: "",
88
- },
89
- reservedHeight: 280,
90
- serverProcessedContent: { htmlStrings: {}, searchablePlainTexts: {}, imageSources: {}, links: {} },
91
- title: "Title area",
92
- };
93
- };
94
- Object.defineProperty(_ClientsidePage.prototype, "pageLayout", {
95
- get: function () {
96
- return this.json.PageLayoutType;
97
- },
98
- set: function (value) {
99
- this.json.PageLayoutType = value;
100
- },
101
- enumerable: false,
102
- configurable: true
103
- });
104
- Object.defineProperty(_ClientsidePage.prototype, "bannerImageUrl", {
105
- get: function () {
106
- return this.json.BannerImageUrl;
107
- },
108
- set: function (value) {
109
- this.setBannerImage(value);
110
- },
111
- enumerable: false,
112
- configurable: true
113
- });
114
- Object.defineProperty(_ClientsidePage.prototype, "thumbnailUrl", {
115
- get: function () {
116
- return this._pageSettings.pageSettingsSlice.isDefaultThumbnail ? this.json.BannerImageUrl : this.json.BannerThumbnailUrl;
117
- },
118
- set: function (value) {
119
- this.json.BannerThumbnailUrl = value;
120
- this._bannerImageThumbnailUrlDirty = true;
121
- this._pageSettings.pageSettingsSlice.isDefaultThumbnail = false;
122
- },
123
- enumerable: false,
124
- configurable: true
125
- });
126
- Object.defineProperty(_ClientsidePage.prototype, "topicHeader", {
127
- get: function () {
128
- return objectDefinedNotNull(this.json.TopicHeader) ? this.json.TopicHeader : "";
129
- },
130
- set: function (value) {
131
- this.json.TopicHeader = value;
132
- this._layoutPart.properties.topicHeader = value;
133
- if (stringIsNullOrEmpty(value)) {
134
- this.showTopicHeader = false;
135
- }
136
- },
137
- enumerable: false,
138
- configurable: true
139
- });
140
- Object.defineProperty(_ClientsidePage.prototype, "title", {
141
- get: function () {
142
- return this._layoutPart.properties.title;
143
- },
144
- set: function (value) {
145
- this.json.Title = value;
146
- this._layoutPart.properties.title = value;
147
- },
148
- enumerable: false,
149
- configurable: true
150
- });
151
- Object.defineProperty(_ClientsidePage.prototype, "reservedHeight", {
152
- get: function () {
153
- return this._layoutPart.reservedHeight;
154
- },
155
- set: function (value) {
156
- this._layoutPart.reservedHeight = value;
157
- },
158
- enumerable: false,
159
- configurable: true
160
- });
161
- Object.defineProperty(_ClientsidePage.prototype, "description", {
162
- get: function () {
163
- return this.json.Description;
164
- },
165
- set: function (value) {
166
- if (!stringIsNullOrEmpty(value) && value.length > 255) {
167
- throw Error("Modern Page description is limited to 255 chars.");
168
- }
169
- this.json.Description = value;
170
- if (!hOP(this._pageSettings, "htmlAttributes")) {
171
- this._pageSettings.htmlAttributes = [];
172
- }
173
- if (this._pageSettings.htmlAttributes.indexOf("modifiedDescription") < 0) {
174
- this._pageSettings.htmlAttributes.push("modifiedDescription");
175
- }
176
- this._pageSettings.pageSettingsSlice.isDefaultDescription = false;
177
- },
178
- enumerable: false,
179
- configurable: true
180
- });
181
- Object.defineProperty(_ClientsidePage.prototype, "layoutType", {
182
- get: function () {
183
- return this._layoutPart.properties.layoutType;
184
- },
185
- set: function (value) {
186
- this._layoutPart.properties.layoutType = value;
187
- },
188
- enumerable: false,
189
- configurable: true
190
- });
191
- Object.defineProperty(_ClientsidePage.prototype, "headerTextAlignment", {
192
- get: function () {
193
- return this._layoutPart.properties.textAlignment;
194
- },
195
- set: function (value) {
196
- this._layoutPart.properties.textAlignment = value;
197
- },
198
- enumerable: false,
199
- configurable: true
200
- });
201
- Object.defineProperty(_ClientsidePage.prototype, "showTopicHeader", {
202
- get: function () {
203
- return this._layoutPart.properties.showTopicHeader;
204
- },
205
- set: function (value) {
206
- this._layoutPart.properties.showTopicHeader = value;
207
- },
208
- enumerable: false,
209
- configurable: true
210
- });
211
- Object.defineProperty(_ClientsidePage.prototype, "showPublishDate", {
212
- get: function () {
213
- return this._layoutPart.properties.showPublishDate;
214
- },
215
- set: function (value) {
216
- this._layoutPart.properties.showPublishDate = value;
217
- },
218
- enumerable: false,
219
- configurable: true
220
- });
221
- Object.defineProperty(_ClientsidePage.prototype, "hasVerticalSection", {
222
- get: function () {
223
- return this.sections.findIndex(function (s) { return s.layoutIndex === 2; }) > -1;
224
- },
225
- enumerable: false,
226
- configurable: true
227
- });
228
- Object.defineProperty(_ClientsidePage.prototype, "authorByLine", {
229
- get: function () {
230
- if (isArray(this._layoutPart.properties.authorByline) && this._layoutPart.properties.authorByline.length > 0) {
231
- return this._layoutPart.properties.authorByline[0];
232
- }
233
- return null;
234
- },
235
- enumerable: false,
236
- configurable: true
237
- });
238
- Object.defineProperty(_ClientsidePage.prototype, "verticalSection", {
239
- get: function () {
240
- if (this.hasVerticalSection) {
241
- return this.addVerticalSection();
242
- }
243
- return null;
244
- },
245
- enumerable: false,
246
- configurable: true
247
- });
248
- /**
249
- * Add a section to this page
250
- */
251
- _ClientsidePage.prototype.addSection = function () {
252
- var section = new CanvasSection(this, getNextOrder(this.sections), 1);
253
- this.sections.push(section);
254
- return section;
255
- };
256
- /**
257
- * Add a section to this page
258
- */
259
- _ClientsidePage.prototype.addVerticalSection = function () {
260
- // we can only have one vertical section so we find it if it exists
261
- var sectionIndex = this.sections.findIndex(function (s) { return s.layoutIndex === 2; });
262
- if (sectionIndex > -1) {
263
- return this.sections[sectionIndex];
264
- }
265
- var section = new CanvasSection(this, getNextOrder(this.sections), 2);
266
- this.sections.push(section);
267
- return section;
268
- };
269
- /**
270
- * Loads this instance from the appropriate JSON data
271
- *
272
- * @param pageData JSON data to load (replaces any existing data)
273
- */
274
- _ClientsidePage.prototype.fromJSON = function (pageData) {
275
- this.json = pageData;
276
- var canvasControls = JSON.parse(pageData.CanvasContent1);
277
- var layouts = JSON.parse(pageData.LayoutWebpartsContent);
278
- if (layouts && layouts.length > 0) {
279
- this._layoutPart = layouts[0];
280
- }
281
- this.setControls(canvasControls);
282
- return this;
283
- };
284
- /**
285
- * Loads this page's content from the server
286
- */
287
- _ClientsidePage.prototype.load = function () {
288
- return __awaiter(this, void 0, void 0, function () {
289
- var item, pageData;
290
- return __generator(this, function (_a) {
291
- switch (_a.label) {
292
- case 0: return [4 /*yield*/, this.getItem("Id", "CommentsDisabled")];
293
- case 1:
294
- item = _a.sent();
295
- return [4 /*yield*/, SharePointQueryable(this, "_api/sitepages/pages(" + item.Id + ")")()];
296
- case 2:
297
- pageData = _a.sent();
298
- this.commentsDisabled = item.CommentsDisabled;
299
- return [2 /*return*/, this.fromJSON(pageData)];
300
- }
301
- });
302
- });
303
- };
304
- /**
305
- * Persists the content changes (sections, columns, and controls) [does not work with batching]
306
- *
307
- * @param publish If true the page is published, if false the changes are persisted to SharePoint but not published [Default: true]
308
- */
309
- _ClientsidePage.prototype.save = function (publish) {
310
- if (publish === void 0) { publish = true; }
311
- return __awaiter(this, void 0, void 0, function () {
312
- var serverRelativePath, imgInfo_1, webUrl_1, web, batch, f, saveBody, bannerImageUrlValue, updater, r;
313
- return __generator(this, function (_a) {
314
- switch (_a.label) {
315
- case 0:
316
- if (this.json.Id === null) {
317
- throw Error("The id for this page is null. If you want to create a new page, please use ClientSidePage.Create");
318
- }
319
- if (!this._bannerImageDirty) return [3 /*break*/, 2];
320
- serverRelativePath = this.bannerImageUrl;
321
- web = Web(extractWebUrl(this.toUrl())).configureFrom(this);
322
- batch = web.createBatch();
323
- web.getFileByServerRelativePath(serverRelativePath.replace(/%20/ig, " "))
324
- .select("ListId", "WebId", "UniqueId", "Name", "SiteId").inBatch(batch)().then(function (r1) { return imgInfo_1 = r1; });
325
- web.select("Url").inBatch(batch)().then(function (r2) { return webUrl_1 = r2.Url; });
326
- // we know the .then calls above will run before execute resolves, ensuring the vars are set
327
- return [4 /*yield*/, batch.execute()];
328
- case 1:
329
- // we know the .then calls above will run before execute resolves, ensuring the vars are set
330
- _a.sent();
331
- f = SharePointQueryable(webUrl_1, "_layouts/15/getpreview.ashx");
332
- f.query.set("guidSite", "" + imgInfo_1.SiteId);
333
- f.query.set("guidWeb", "" + imgInfo_1.WebId);
334
- f.query.set("guidFile", "" + imgInfo_1.UniqueId);
335
- this.bannerImageUrl = f.toUrlAndQuery();
336
- if (!objectDefinedNotNull(this._layoutPart.serverProcessedContent)) {
337
- this._layoutPart.serverProcessedContent = {};
338
- }
339
- this._layoutPart.serverProcessedContent.imageSources = { imageSource: serverRelativePath };
340
- if (!objectDefinedNotNull(this._layoutPart.serverProcessedContent.customMetadata)) {
341
- this._layoutPart.serverProcessedContent.customMetadata = {};
342
- }
343
- this._layoutPart.serverProcessedContent.customMetadata.imageSource = {
344
- listId: imgInfo_1.ListId,
345
- siteId: imgInfo_1.SiteId,
346
- uniqueId: imgInfo_1.UniqueId,
347
- webId: imgInfo_1.WebId,
348
- };
349
- this._layoutPart.properties.webId = imgInfo_1.WebId;
350
- this._layoutPart.properties.siteId = imgInfo_1.SiteId;
351
- this._layoutPart.properties.listId = imgInfo_1.ListId;
352
- this._layoutPart.properties.uniqueId = imgInfo_1.UniqueId;
353
- _a.label = 2;
354
- case 2:
355
- if (!!this.json.IsPageCheckedOutToCurrentUser) return [3 /*break*/, 4];
356
- return [4 /*yield*/, spPost(initFrom(this, "_api/sitepages/pages(" + this.json.Id + ")/checkoutpage"))];
357
- case 3:
358
- _a.sent();
359
- _a.label = 4;
360
- case 4:
361
- saveBody = Object.assign(metadata("SP.Publishing.SitePage"), {
362
- AuthorByline: this.json.AuthorByline || [],
363
- CanvasContent1: this.getCanvasContent1(),
364
- Description: this.description,
365
- LayoutWebpartsContent: this.getLayoutWebpartsContent(),
366
- Title: this.title,
367
- TopicHeader: this.topicHeader,
368
- });
369
- if (this._bannerImageDirty || this._bannerImageThumbnailUrlDirty) {
370
- bannerImageUrlValue = this._bannerImageThumbnailUrlDirty ? this.thumbnailUrl : this.bannerImageUrl;
371
- saveBody = assign(saveBody, {
372
- BannerImageUrl: bannerImageUrlValue,
373
- });
374
- }
375
- updater = initFrom(this, "_api/sitepages/pages(" + this.json.Id + ")/savepage");
376
- return [4 /*yield*/, spPost(updater, headers({ "if-match": "*" }, body(saveBody)))];
377
- case 5:
378
- _a.sent();
379
- r = true;
380
- if (!publish) return [3 /*break*/, 7];
381
- return [4 /*yield*/, spPost(initFrom(this, "_api/sitepages/pages(" + this.json.Id + ")/publish"))];
382
- case 6:
383
- r = _a.sent();
384
- if (r) {
385
- this.json.IsPageCheckedOutToCurrentUser = false;
386
- }
387
- _a.label = 7;
388
- case 7:
389
- this._bannerImageDirty = false;
390
- this._bannerImageThumbnailUrlDirty = false;
391
- // we need to ensure we reload from the latest data to ensure all urls are updated and current in the object (expecially for new pages)
392
- return [4 /*yield*/, this.load()];
393
- case 8:
394
- // we need to ensure we reload from the latest data to ensure all urls are updated and current in the object (expecially for new pages)
395
- _a.sent();
396
- return [2 /*return*/, r];
397
- }
398
- });
399
- });
400
- };
401
- /**
402
- * Discards the checkout of this page
403
- */
404
- _ClientsidePage.prototype.discardPageCheckout = function () {
405
- return __awaiter(this, void 0, void 0, function () {
406
- var d;
407
- return __generator(this, function (_a) {
408
- switch (_a.label) {
409
- case 0:
410
- if (this.json.Id === null) {
411
- throw Error("The id for this page is null. If you want to create a new page, please use ClientSidePage.Create");
412
- }
413
- return [4 /*yield*/, spPost(initFrom(this, "_api/sitepages/pages(" + this.json.Id + ")/discardPage"), body(metadata("SP.Publishing.SitePage")))];
414
- case 1:
415
- d = _a.sent();
416
- this.fromJSON(d);
417
- return [2 /*return*/];
418
- }
419
- });
420
- });
421
- };
422
- /**
423
- * Promotes this page as a news item
424
- */
425
- _ClientsidePage.prototype.promoteToNews = function () {
426
- return __awaiter(this, void 0, void 0, function () {
427
- return __generator(this, function (_a) {
428
- return [2 /*return*/, this.promoteNewsImpl("promoteToNews")];
429
- });
430
- });
431
- };
432
- // API is currently broken on server side
433
- // public async demoteFromNews(): Promise<boolean> {
434
- // return this.promoteNewsImpl("demoteFromNews");
435
- // }
436
- /**
437
- * Finds a control by the specified instance id
438
- *
439
- * @param id Instance id of the control to find
440
- */
441
- _ClientsidePage.prototype.findControlById = function (id) {
442
- return this.findControl(function (c) { return c.id === id; });
443
- };
444
- /**
445
- * Finds a control within this page's control tree using the supplied predicate
446
- *
447
- * @param predicate Takes a control and returns true or false, if true that control is returned by findControl
448
- */
449
- _ClientsidePage.prototype.findControl = function (predicate) {
450
- // check all sections
451
- for (var i = 0; i < this.sections.length; i++) {
452
- // check all columns
453
- for (var j = 0; j < this.sections[i].columns.length; j++) {
454
- // check all controls
455
- for (var k = 0; k < this.sections[i].columns[j].controls.length; k++) {
456
- // check to see if the predicate likes this control
457
- if (predicate(this.sections[i].columns[j].controls[k])) {
458
- return this.sections[i].columns[j].controls[k];
459
- }
460
- }
461
- }
462
- }
463
- // we found nothing so give nothing back
464
- return null;
465
- };
466
- /**
467
- * Creates a new page with all of the content copied from this page
468
- *
469
- * @param web The web where we will create the copy
470
- * @param pageName The file name of the new page
471
- * @param title The title of the new page
472
- * @param publish If true the page will be published (Default: true)
473
- */
474
- _ClientsidePage.prototype.copy = function (web, pageName, title, publish, promotedState) {
475
- if (publish === void 0) { publish = true; }
476
- return __awaiter(this, void 0, void 0, function () {
477
- var page;
478
- return __generator(this, function (_a) {
479
- switch (_a.label) {
480
- case 0: return [4 /*yield*/, CreateClientsidePage(web, pageName, title, this.pageLayout, promotedState)];
481
- case 1:
482
- page = _a.sent();
483
- return [2 /*return*/, this.copyTo(page, publish)];
484
- }
485
- });
486
- });
487
- };
488
- /**
489
- * Copies the content from this page to the supplied page instance NOTE: fully overwriting any previous content!!
490
- *
491
- * @param page Page whose content we replace with this page's content
492
- * @param publish If true the page will be published after the copy, if false it will be saved but left unpublished (Default: true)
493
- */
494
- _ClientsidePage.prototype.copyTo = function (page, publish) {
495
- if (publish === void 0) { publish = true; }
496
- return __awaiter(this, void 0, void 0, function () {
497
- var url, makeGuid, guidSite, guidWeb, guidFile, site, id, openWeb, file, props;
498
- return __generator(this, function (_a) {
499
- switch (_a.label) {
500
- case 0:
501
- // we know the method is on the class - but it is protected so not part of the interface
502
- page.setControls(this.getControls());
503
- if (!!stringIsNullOrEmpty(this.json.BannerImageUrl)) return [3 /*break*/, 4];
504
- url = new URL(this.json.BannerImageUrl);
505
- makeGuid = function (s) { return s.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/g, "$1-$2-$3-$4-$5"); };
506
- if (!(url.searchParams.has("guidSite") && url.searchParams.has("guidWeb") && url.searchParams.has("guidFile"))) return [3 /*break*/, 4];
507
- guidSite = makeGuid(url.searchParams.get("guidSite"));
508
- guidWeb = makeGuid(url.searchParams.get("guidWeb"));
509
- guidFile = makeGuid(url.searchParams.get("guidFile"));
510
- site = Site(extractWebUrl(this.toUrl()));
511
- return [4 /*yield*/, site.select("Id")()];
512
- case 1:
513
- id = _a.sent();
514
- if (!(id.Id === guidSite)) return [3 /*break*/, 4];
515
- return [4 /*yield*/, site.openWebById(guidWeb)];
516
- case 2:
517
- openWeb = _a.sent();
518
- return [4 /*yield*/, openWeb.web.getFileById(guidFile).select("ServerRelativeUrl")()];
519
- case 3:
520
- file = _a.sent();
521
- props = {};
522
- if (this._layoutPart.properties) {
523
- if (hOP(this._layoutPart.properties, "translateX")) {
524
- props.translateX = this._layoutPart.properties.translateX;
525
- }
526
- if (hOP(this._layoutPart.properties, "translateY")) {
527
- props.translateY = this._layoutPart.properties.translateY;
528
- }
529
- if (hOP(this._layoutPart.properties, "imageSourceType")) {
530
- props.imageSourceType = this._layoutPart.properties.imageSourceType;
531
- }
532
- if (hOP(this._layoutPart.properties, "altText")) {
533
- props.altText = this._layoutPart.properties.altText;
534
- }
535
- }
536
- page.setBannerImage(file.ServerRelativeUrl, props);
537
- _a.label = 4;
538
- case 4: return [4 /*yield*/, page.save(publish)];
539
- case 5:
540
- _a.sent();
541
- return [2 /*return*/, page];
542
- }
543
- });
544
- });
545
- };
546
- /**
547
- * Sets the modern page banner image
548
- *
549
- * @param url Url of the image to display
550
- * @param altText Alt text to describe the image
551
- * @param bannerProps Additional properties to control display of the banner
552
- */
553
- _ClientsidePage.prototype.setBannerImage = function (url, props) {
554
- if (isUrlAbsolute(url)) {
555
- // do our best to make this a server relative url by removing the x.sharepoint.com part
556
- url = url.replace(/^https?:\/\/[a-z0-9.]*?\.[a-z]{2,3}\//i, "/");
557
- }
558
- this.json.BannerImageUrl = url;
559
- this._bannerImageDirty = true;
560
- /*
561
- setting the banner image resets the thumbnail image (matching UI functionality)
562
- but if the thumbnail is dirty they are likely trying to set them both to
563
- different values, so we allow that here.
564
- Also allows the banner image to be updated safely with the calculated one in save()
565
- */
566
- if (!this._bannerImageThumbnailUrlDirty) {
567
- this.thumbnailUrl = url;
568
- this._pageSettings.pageSettingsSlice.isDefaultThumbnail = true;
569
- }
570
- // this seems to always be true, so default
571
- this._layoutPart.properties.imageSourceType = 2;
572
- if (objectDefinedNotNull(props)) {
573
- if (hOP(props, "translateX")) {
574
- this._layoutPart.properties.translateX = props.translateX;
575
- }
576
- if (hOP(props, "translateY")) {
577
- this._layoutPart.properties.translateY = props.translateY;
578
- }
579
- if (hOP(props, "imageSourceType")) {
580
- this._layoutPart.properties.imageSourceType = props.imageSourceType;
581
- }
582
- if (hOP(props, "altText")) {
583
- this._layoutPart.properties.altText = props.altText;
584
- }
585
- }
586
- };
587
- /**
588
- * Sets the banner image url from an external source. You must call save to persist the changes
589
- *
590
- * @param url absolute url of the external file
591
- * @param props optional set of properties to control display of the banner image
592
- */
593
- _ClientsidePage.prototype.setBannerImageFromExternalUrl = function (url, props) {
594
- return __awaiter(this, void 0, void 0, function () {
595
- var fileUrl, pageName, filename, request, result;
596
- return __generator(this, function (_a) {
597
- switch (_a.label) {
598
- case 0:
599
- fileUrl = new URL(url);
600
- pageName = this.json.FileName.replace(/\.[^/.]+$/, "");
601
- filename = fileUrl.pathname.split(/[\\/]/i).pop();
602
- request = initFrom(this, "_api/sitepages/AddImageFromExternalUrl");
603
- request.query.set("imageFileName", "'" + encodeURIComponent(filename) + "'");
604
- request.query.set("pageName", "'" + encodeURIComponent(pageName) + "'");
605
- request.query.set("externalUrl", "'" + encodeURIComponent(url) + "'");
606
- request.select("ServerRelativeUrl");
607
- return [4 /*yield*/, spPost(request)];
608
- case 1:
609
- result = _a.sent();
610
- // set with the newly created relative url
611
- this.setBannerImage(result.ServerRelativeUrl, props);
612
- return [2 /*return*/];
613
- }
614
- });
615
- });
616
- };
617
- /**
618
- * Sets the authors for this page from the supplied list of user integer ids
619
- *
620
- * @param authorId The integer id of the user to set as the author
621
- */
622
- _ClientsidePage.prototype.setAuthorById = function (authorId) {
623
- return __awaiter(this, void 0, void 0, function () {
624
- var userLoginData;
625
- return __generator(this, function (_a) {
626
- switch (_a.label) {
627
- case 0: return [4 /*yield*/, SharePointQueryableCollection(extractWebUrl(this.toUrl()), "/_api/web/siteusers")
628
- .configureFrom(this)
629
- .filter("Id eq " + authorId)
630
- .select("LoginName")()];
631
- case 1:
632
- userLoginData = _a.sent();
633
- if (userLoginData.length < 1) {
634
- throw Error("Could not find user with id " + authorId + ".");
635
- }
636
- return [2 /*return*/, this.setAuthorByLoginName(userLoginData[0].LoginName)];
637
- }
638
- });
639
- });
640
- };
641
- /**
642
- * Sets the authors for this page from the supplied list of user integer ids
643
- *
644
- * @param authorLoginName The login name of the user (ex: i:0#.f|membership|name@tenant.com)
645
- */
646
- _ClientsidePage.prototype.setAuthorByLoginName = function (authorLoginName) {
647
- return __awaiter(this, void 0, void 0, function () {
648
- var userLoginData;
649
- return __generator(this, function (_a) {
650
- switch (_a.label) {
651
- case 0: return [4 /*yield*/, SharePointQueryableCollection(extractWebUrl(this.toUrl()), "/_api/web/siteusers")
652
- .configureFrom(this)
653
- .filter("LoginName eq '" + authorLoginName + "'")
654
- .select("UserPrincipalName", "Title")()];
655
- case 1:
656
- userLoginData = _a.sent();
657
- if (userLoginData.length < 1) {
658
- throw Error("Could not find user with login name '" + authorLoginName + "'.");
659
- }
660
- this.json.AuthorByline = [userLoginData[0].UserPrincipalName];
661
- this._layoutPart.properties.authorByline = [userLoginData[0].UserPrincipalName];
662
- this._layoutPart.properties.authors = [{
663
- id: authorLoginName,
664
- name: userLoginData[0].Title,
665
- role: "",
666
- upn: userLoginData[0].UserPrincipalName,
667
- }];
668
- return [2 /*return*/];
669
- }
670
- });
671
- });
672
- };
673
- /**
674
- * Gets the list item associated with this clientside page
675
- *
676
- * @param selects Specific set of fields to include when getting the item
677
- */
678
- _ClientsidePage.prototype.getItem = function () {
679
- var selects = [];
680
- for (var _i = 0; _i < arguments.length; _i++) {
681
- selects[_i] = arguments[_i];
682
- }
683
- return __awaiter(this, void 0, void 0, function () {
684
- var initer, listData, item, itemData;
685
- return __generator(this, function (_a) {
686
- switch (_a.label) {
687
- case 0:
688
- initer = initFrom(this, "/_api/lists/EnsureClientRenderedSitePagesLibrary").select("EnableModeration", "EnableMinorVersions", "Id");
689
- return [4 /*yield*/, spPost(initer)];
690
- case 1:
691
- listData = _a.sent();
692
- item = (List(listData["odata.id"])).configureFrom(this).items.getById(this.json.Id);
693
- return [4 /*yield*/, item.select.apply(item, __spreadArray([], __read(selects)))()];
694
- case 2:
695
- itemData = _a.sent();
696
- return [2 /*return*/, assign((Item(odataUrlFrom(itemData))).configureFrom(this), itemData)];
697
- }
698
- });
699
- });
700
- };
701
- /**
702
- * Recycle this page
703
- */
704
- _ClientsidePage.prototype.recycle = function () {
705
- return __awaiter(this, void 0, void 0, function () {
706
- var item;
707
- return __generator(this, function (_a) {
708
- switch (_a.label) {
709
- case 0: return [4 /*yield*/, this.getItem()];
710
- case 1:
711
- item = _a.sent();
712
- return [4 /*yield*/, item.recycle()];
713
- case 2:
714
- _a.sent();
715
- return [2 /*return*/];
716
- }
717
- });
718
- });
719
- };
720
- /**
721
- * Delete this page
722
- */
723
- _ClientsidePage.prototype.delete = function () {
724
- return __awaiter(this, void 0, void 0, function () {
725
- var item;
726
- return __generator(this, function (_a) {
727
- switch (_a.label) {
728
- case 0: return [4 /*yield*/, this.getItem()];
729
- case 1:
730
- item = _a.sent();
731
- return [4 /*yield*/, item.delete()];
732
- case 2:
733
- _a.sent();
734
- return [2 /*return*/];
735
- }
736
- });
737
- });
738
- };
739
- // not yet active in service
740
- // /**
741
- // * Schedules a page for publishing
742
- // *
743
- // * @param publishDate Date to publish the item
744
- // * @returns Publish work item details
745
- // */
746
- // public async schedulePublish(publishDate: Date): Promise<string> {
747
- // let r: string;
748
- // // currently the server throws an exception, but then the page is published as expected
749
- // // so we just ignore that error for now, YMMV
750
- // try {
751
- // r = await spPost(initFrom(this, `_api/sitepages/pages(${this.json.Id})/SchedulePublish`), body({
752
- // sitePage: { PublishStartDate: publishDate },
753
- // }));
754
- // } catch {
755
- // r = "";
756
- // }
757
- // return r;
758
- // }
759
- /**
760
- * Saves a copy of this page as a template in this library's Templates folder
761
- *
762
- * @param publish If true the template is published, false the template is not published (default: true)
763
- * @returns IClientsidePage instance representing the new template page
764
- */
765
- _ClientsidePage.prototype.saveAsTemplate = function (publish) {
766
- if (publish === void 0) { publish = true; }
767
- return __awaiter(this, void 0, void 0, function () {
768
- var data, page;
769
- return __generator(this, function (_a) {
770
- switch (_a.label) {
771
- case 0: return [4 /*yield*/, spPost(initFrom(this, "_api/sitepages/pages(" + this.json.Id + ")/SavePageAsTemplate"))];
772
- case 1:
773
- data = _a.sent();
774
- page = ClientsidePage(this, null, data);
775
- page.title = this.title;
776
- return [4 /*yield*/, page.save(publish)];
777
- case 2:
778
- _a.sent();
779
- return [2 /*return*/, page];
780
- }
781
- });
782
- });
783
- };
784
- /**
785
- * Share this Page's Preview content by Email
786
- *
787
- * @param emails Set of emails to which the preview is shared
788
- * @param message The message to include
789
- * @returns void
790
- */
791
- _ClientsidePage.prototype.share = function (emails, message) {
792
- return spPost(initFrom(this, "_api/SP.Publishing.RichSharing/SharePageByEmail"), body({
793
- recipientEmails: emails,
794
- message: message,
795
- url: this.json.AbsoluteUrl,
796
- }));
797
- };
798
- /**
799
- * Extends this queryable from the provided parent
800
- *
801
- * @param parent Parent queryable from which we will derive a base url
802
- * @param path Additional path
803
- */
804
- _ClientsidePage.prototype.assign = function (parent, path) {
805
- this.data.parentUrl = parent.data.url;
806
- this.data.url = combine(this.data.parentUrl, path || "");
807
- this.configureFrom(parent);
808
- };
809
- _ClientsidePage.prototype.getCanvasContent1 = function () {
810
- return JSON.stringify(this.getControls());
811
- };
812
- _ClientsidePage.prototype.getLayoutWebpartsContent = function () {
813
- if (this._layoutPart) {
814
- return JSON.stringify([this._layoutPart]);
815
- }
816
- else {
817
- return JSON.stringify(null);
818
- }
819
- };
820
- _ClientsidePage.prototype.setControls = function (controls) {
821
- // reset the sections
822
- this.sections = [];
823
- if (controls && controls.length) {
824
- for (var i = 0; i < controls.length; i++) {
825
- // if no control type is present this is a column which we give type 0 to let us process it
826
- var controlType = hOP(controls[i], "controlType") ? controls[i].controlType : 0;
827
- switch (controlType) {
828
- case 0:
829
- // empty canvas column or page settings
830
- if (hOP(controls[i], "pageSettingsSlice")) {
831
- this._pageSettings = controls[i];
832
- }
833
- else {
834
- // we have an empty column
835
- this.mergeColumnToTree(new CanvasColumn(controls[i]));
836
- }
837
- break;
838
- case 3: {
839
- var part = new ClientsideWebpart(controls[i]);
840
- this.mergePartToTree(part, part.data.position);
841
- break;
842
- }
843
- case 4: {
844
- var textData = controls[i];
845
- var text = new ClientsideText(textData.innerHTML, textData);
846
- this.mergePartToTree(text, text.data.position);
847
- break;
848
- }
849
- }
850
- }
851
- reindex(this.sections);
852
- }
853
- };
854
- _ClientsidePage.prototype.getControls = function () {
855
- var _this = this;
856
- // reindex things
857
- reindex(this.sections);
858
- // rollup the control changes
859
- var canvasData = [];
860
- this.sections.forEach(function (section) {
861
- section.columns.forEach(function (column) {
862
- if (column.controls.length < 1) {
863
- // empty column
864
- canvasData.push({
865
- displayMode: column.data.displayMode,
866
- emphasis: _this.getEmphasisObj(section.emphasis),
867
- position: column.data.position,
868
- });
869
- }
870
- else {
871
- column.controls.forEach(function (control) {
872
- control.data.emphasis = _this.getEmphasisObj(section.emphasis);
873
- canvasData.push(_this.specialSaveHandling(control).data);
874
- });
875
- }
876
- });
877
- });
878
- canvasData.push(this._pageSettings);
879
- return canvasData;
880
- };
881
- _ClientsidePage.prototype.getEmphasisObj = function (value) {
882
- if (value < 1 || value > 3) {
883
- return {};
884
- }
885
- return { zoneEmphasis: value };
886
- };
887
- _ClientsidePage.prototype.promoteNewsImpl = function (method) {
888
- return __awaiter(this, void 0, void 0, function () {
889
- var lastPubData;
890
- return __generator(this, function (_a) {
891
- switch (_a.label) {
892
- case 0:
893
- if (this.json.Id === null) {
894
- throw Error("The id for this page is null.");
895
- }
896
- if (!stringIsNullOrEmpty(this.json.VersionInfo.LastVersionCreatedBy)) return [3 /*break*/, 2];
897
- lastPubData = new Date(this.json.VersionInfo.LastVersionCreated);
898
- if (!(lastPubData.getFullYear() < 2000)) return [3 /*break*/, 2];
899
- return [4 /*yield*/, this.save(true)];
900
- case 1:
901
- _a.sent();
902
- _a.label = 2;
903
- case 2: return [4 /*yield*/, spPost(initFrom(this, "_api/sitepages/pages(" + this.json.Id + ")/" + method), body(metadata("SP.Publishing.SitePage")))];
904
- case 3: return [2 /*return*/, _a.sent()];
905
- }
906
- });
907
- });
908
- };
909
- /**
910
- * Merges the control into the tree of sections and columns for this page
911
- *
912
- * @param control The control to merge
913
- */
914
- _ClientsidePage.prototype.mergePartToTree = function (control, positionData) {
915
- var _a, _b, _c;
916
- var column = null;
917
- var sectionFactor = 12;
918
- var sectionIndex = 0;
919
- var zoneIndex = 0;
920
- var layoutIndex = 1;
921
- // handle case where we don't have position data (shouldn't happen?)
922
- if (positionData) {
923
- if (hOP(positionData, "zoneIndex")) {
924
- zoneIndex = positionData.zoneIndex;
925
- }
926
- if (hOP(positionData, "sectionIndex")) {
927
- sectionIndex = positionData.sectionIndex;
928
- }
929
- if (hOP(positionData, "sectionFactor")) {
930
- sectionFactor = positionData.sectionFactor;
931
- }
932
- if (hOP(positionData, "layoutIndex")) {
933
- layoutIndex = positionData.layoutIndex;
934
- }
935
- }
936
- var zoneEmphasis = (_c = (_b = (_a = control.data) === null || _a === void 0 ? void 0 : _a.emphasis) === null || _b === void 0 ? void 0 : _b.zoneEmphasis) !== null && _c !== void 0 ? _c : 0;
937
- var section = this.getOrCreateSection(zoneIndex, layoutIndex, zoneEmphasis);
938
- var columns = section.columns.filter(function (c) { return c.order === sectionIndex; });
939
- if (columns.length < 1) {
940
- column = section.addColumn(sectionFactor, layoutIndex);
941
- }
942
- else {
943
- column = columns[0];
944
- }
945
- control.column = column;
946
- column.addControl(control);
947
- };
948
- /**
949
- * Merges the supplied column into the tree
950
- *
951
- * @param column Column to merge
952
- * @param position The position data for the column
953
- */
954
- _ClientsidePage.prototype.mergeColumnToTree = function (column) {
955
- var _a, _b;
956
- var order = hOP(column.data, "position") && hOP(column.data.position, "zoneIndex") ? column.data.position.zoneIndex : 0;
957
- var layoutIndex = hOP(column.data, "position") && hOP(column.data.position, "layoutIndex") ? column.data.position.layoutIndex : 1;
958
- var section = this.getOrCreateSection(order, layoutIndex, ((_b = (_a = column.data) === null || _a === void 0 ? void 0 : _a.emphasis) === null || _b === void 0 ? void 0 : _b.zoneEmphasis) || 0);
959
- column.section = section;
960
- section.columns.push(column);
961
- };
962
- /**
963
- * Handle the logic to get or create a section based on the supplied order and layoutIndex
964
- *
965
- * @param order Section order
966
- * @param layoutIndex Layout Index (1 === normal, 2 === vertical section)
967
- * @param emphasis The section emphasis
968
- */
969
- _ClientsidePage.prototype.getOrCreateSection = function (order, layoutIndex, emphasis) {
970
- var section = null;
971
- var sections = this.sections.filter(function (s) { return s.order === order && s.layoutIndex === layoutIndex; });
972
- if (sections.length < 1) {
973
- section = layoutIndex === 2 ? this.addVerticalSection() : this.addSection();
974
- section.order = order;
975
- section.emphasis = emphasis;
976
- }
977
- else {
978
- section = sections[0];
979
- }
980
- return section;
981
- };
982
- /**
983
- * Based on issue #1690 we need to take special case actions to ensure some things
984
- * can be saved properly without breaking existing pages.
985
- *
986
- * @param control The control we are ensuring is "ready" to be saved
987
- */
988
- _ClientsidePage.prototype.specialSaveHandling = function (control) {
989
- var _a, _b, _c;
990
- // this is to handle the special case in issue #1690
991
- // must ensure that searchablePlainTexts values have < replaced with &lt; in links web part
992
- if (control.data.controlType === 3 && control.data.webPartId === "c70391ea-0b10-4ee9-b2b4-006d3fcad0cd") {
993
- var texts = ((_c = (_b = (_a = control.data) === null || _a === void 0 ? void 0 : _a.webPartData) === null || _b === void 0 ? void 0 : _b.serverProcessedContent) === null || _c === void 0 ? void 0 : _c.searchablePlainTexts) || null;
994
- if (objectDefinedNotNull(texts)) {
995
- var keys = Object.getOwnPropertyNames(texts);
996
- for (var i = 0; i < keys.length; i++) {
997
- texts[keys[i]] = texts[keys[i]].replace(/</ig, "&lt;");
998
- control.data.webPartData.serverProcessedContent.searchablePlainTexts = texts;
999
- }
1000
- }
1001
- }
1002
- return control;
1003
- };
1004
- __decorate([
1005
- tag("csp.load")
1006
- ], _ClientsidePage.prototype, "load", null);
1007
- __decorate([
1008
- tag("csp.save")
1009
- ], _ClientsidePage.prototype, "save", null);
1010
- __decorate([
1011
- tag("csp.discardPageCheckout")
1012
- ], _ClientsidePage.prototype, "discardPageCheckout", null);
1013
- __decorate([
1014
- tag("csp.promoteToNews")
1015
- ], _ClientsidePage.prototype, "promoteToNews", null);
1016
- __decorate([
1017
- tag("csp.copy")
1018
- ], _ClientsidePage.prototype, "copy", null);
1019
- __decorate([
1020
- tag("csp.copyTo")
1021
- ], _ClientsidePage.prototype, "copyTo", null);
1022
- __decorate([
1023
- tag("csp.getItem")
1024
- ], _ClientsidePage.prototype, "getItem", null);
1025
- return _ClientsidePage;
1026
- }(_SharePointQueryable));
1027
- export { _ClientsidePage };
1028
- /**
1029
- * Invokable factory for IClientSidePage instances
1030
- */
1031
- var ClientsidePage = function (baseUrl, path, json, noInit, sections, commentsDisabled) {
1032
- if (noInit === void 0) { noInit = false; }
1033
- if (sections === void 0) { sections = []; }
1034
- if (commentsDisabled === void 0) { commentsDisabled = false; }
1035
- return invokableFactory(_ClientsidePage)(baseUrl, path, json, noInit, sections, commentsDisabled);
1036
- };
1037
- /**
1038
- * Loads a client side page from the supplied IFile instance
1039
- *
1040
- * @param file Source IFile instance
1041
- */
1042
- export var ClientsidePageFromFile = function (file) { return __awaiter(void 0, void 0, void 0, function () {
1043
- var item, page;
1044
- return __generator(this, function (_a) {
1045
- switch (_a.label) {
1046
- case 0: return [4 /*yield*/, file.getItem()];
1047
- case 1:
1048
- item = _a.sent();
1049
- page = ClientsidePage(extractWebUrl(file.toUrl()), "", { Id: item.Id }, true);
1050
- return [2 /*return*/, page.configureFrom(file).load()];
1051
- }
1052
- });
1053
- }); };
1054
- /**
1055
- * Creates a new client side page
1056
- *
1057
- * @param web The web or list
1058
- * @param pageName The name of the page (filename)
1059
- * @param title The page's title
1060
- * @param PageLayoutType Layout to use when creating the page
1061
- */
1062
- export var CreateClientsidePage = function (web, pageName, title, PageLayoutType, promotedState) {
1063
- if (PageLayoutType === void 0) { PageLayoutType = "Article"; }
1064
- if (promotedState === void 0) { promotedState = 0; }
1065
- return __awaiter(void 0, void 0, void 0, function () {
1066
- var pageInitData, newPage;
1067
- return __generator(this, function (_a) {
1068
- switch (_a.label) {
1069
- case 0:
1070
- // patched because previously we used the full page name with the .aspx at the end
1071
- // this allows folk's existing code to work after the re-write to the new API
1072
- pageName = pageName.replace(/\.aspx$/i, "");
1073
- return [4 /*yield*/, spPost(initFrom(web, "_api/sitepages/pages"), body(Object.assign(metadata("SP.Publishing.SitePage"), {
1074
- PageLayoutType: PageLayoutType,
1075
- PromotedState: promotedState,
1076
- })))];
1077
- case 1:
1078
- pageInitData = _a.sent();
1079
- newPage = ClientsidePage(web, "", pageInitData);
1080
- newPage.title = pageName;
1081
- return [4 /*yield*/, newPage.save(false)];
1082
- case 2:
1083
- _a.sent();
1084
- newPage.title = title;
1085
- return [2 /*return*/, newPage];
1086
- }
1087
- });
1088
- });
1089
- };
1090
- var CanvasSection = /** @class */ (function () {
1091
- function CanvasSection(page, order, layoutIndex, columns, _emphasis) {
1092
- if (columns === void 0) { columns = []; }
1093
- if (_emphasis === void 0) { _emphasis = 0; }
1094
- this.page = page;
1095
- this.columns = columns;
1096
- this._emphasis = _emphasis;
1097
- this._memId = getGUID();
1098
- this._order = order;
1099
- this._layoutIndex = layoutIndex;
1100
- }
1101
- Object.defineProperty(CanvasSection.prototype, "order", {
1102
- get: function () {
1103
- return this._order;
1104
- },
1105
- set: function (value) {
1106
- this._order = value;
1107
- for (var i = 0; i < this.columns.length; i++) {
1108
- this.columns[i].data.position.zoneIndex = value;
1109
- }
1110
- },
1111
- enumerable: false,
1112
- configurable: true
1113
- });
1114
- Object.defineProperty(CanvasSection.prototype, "layoutIndex", {
1115
- get: function () {
1116
- return this._layoutIndex;
1117
- },
1118
- set: function (value) {
1119
- this._layoutIndex = value;
1120
- for (var i = 0; i < this.columns.length; i++) {
1121
- this.columns[i].data.position.layoutIndex = value;
1122
- }
1123
- },
1124
- enumerable: false,
1125
- configurable: true
1126
- });
1127
- Object.defineProperty(CanvasSection.prototype, "defaultColumn", {
1128
- /**
1129
- * Default column (this.columns[0]) for this section
1130
- */
1131
- get: function () {
1132
- if (this.columns.length < 1) {
1133
- this.addColumn(12);
1134
- }
1135
- return this.columns[0];
1136
- },
1137
- enumerable: false,
1138
- configurable: true
1139
- });
1140
- /**
1141
- * Adds a new column to this section
1142
- */
1143
- CanvasSection.prototype.addColumn = function (factor, layoutIndex) {
1144
- if (layoutIndex === void 0) { layoutIndex = this.layoutIndex; }
1145
- var column = new CanvasColumn();
1146
- column.section = this;
1147
- column.data.position.zoneIndex = this.order;
1148
- column.data.position.layoutIndex = layoutIndex;
1149
- column.data.position.sectionFactor = factor;
1150
- column.order = getNextOrder(this.columns);
1151
- this.columns.push(column);
1152
- return column;
1153
- };
1154
- /**
1155
- * Adds a control to the default column for this section
1156
- *
1157
- * @param control Control to add to the default column
1158
- */
1159
- CanvasSection.prototype.addControl = function (control) {
1160
- this.defaultColumn.addControl(control);
1161
- return this;
1162
- };
1163
- Object.defineProperty(CanvasSection.prototype, "emphasis", {
1164
- get: function () {
1165
- return this._emphasis;
1166
- },
1167
- set: function (value) {
1168
- this._emphasis = value;
1169
- },
1170
- enumerable: false,
1171
- configurable: true
1172
- });
1173
- /**
1174
- * Removes this section and all contained columns and controls from the collection
1175
- */
1176
- CanvasSection.prototype.remove = function () {
1177
- var _this = this;
1178
- this.page.sections = this.page.sections.filter(function (section) { return section._memId !== _this._memId; });
1179
- reindex(this.page.sections);
1180
- };
1181
- return CanvasSection;
1182
- }());
1183
- export { CanvasSection };
1184
- var CanvasColumn = /** @class */ (function () {
1185
- function CanvasColumn(json, controls) {
1186
- if (json === void 0) { json = JSON.parse(JSON.stringify(CanvasColumn.Default)); }
1187
- if (controls === void 0) { controls = []; }
1188
- this.json = json;
1189
- this.controls = controls;
1190
- this._section = null;
1191
- this._memId = getGUID();
1192
- }
1193
- Object.defineProperty(CanvasColumn.prototype, "data", {
1194
- get: function () {
1195
- return this.json;
1196
- },
1197
- enumerable: false,
1198
- configurable: true
1199
- });
1200
- Object.defineProperty(CanvasColumn.prototype, "section", {
1201
- get: function () {
1202
- return this._section;
1203
- },
1204
- set: function (section) {
1205
- this._section = section;
1206
- },
1207
- enumerable: false,
1208
- configurable: true
1209
- });
1210
- Object.defineProperty(CanvasColumn.prototype, "order", {
1211
- get: function () {
1212
- return this.data.position.sectionIndex;
1213
- },
1214
- set: function (value) {
1215
- this.data.position.sectionIndex = value;
1216
- for (var i = 0; i < this.controls.length; i++) {
1217
- this.controls[i].data.position.zoneIndex = this.data.position.zoneIndex;
1218
- this.controls[i].data.position.layoutIndex = this.data.position.layoutIndex;
1219
- this.controls[i].data.position.sectionIndex = value;
1220
- }
1221
- },
1222
- enumerable: false,
1223
- configurable: true
1224
- });
1225
- Object.defineProperty(CanvasColumn.prototype, "factor", {
1226
- get: function () {
1227
- return this.data.position.sectionFactor;
1228
- },
1229
- set: function (value) {
1230
- this.data.position.sectionFactor = value;
1231
- },
1232
- enumerable: false,
1233
- configurable: true
1234
- });
1235
- CanvasColumn.prototype.addControl = function (control) {
1236
- control.column = this;
1237
- this.controls.push(control);
1238
- return this;
1239
- };
1240
- CanvasColumn.prototype.getControl = function (index) {
1241
- return this.controls[index];
1242
- };
1243
- CanvasColumn.prototype.remove = function () {
1244
- var _this = this;
1245
- this.section.columns = this.section.columns.filter(function (column) { return column._memId !== _this._memId; });
1246
- reindex(this.section.columns);
1247
- };
1248
- CanvasColumn.Default = {
1249
- controlType: 0,
1250
- displayMode: 2,
1251
- emphasis: {},
1252
- position: {
1253
- layoutIndex: 1,
1254
- sectionFactor: 12,
1255
- sectionIndex: 1,
1256
- zoneIndex: 1,
1257
- },
1258
- };
1259
- return CanvasColumn;
1260
- }());
1261
- export { CanvasColumn };
1262
- var ColumnControl = /** @class */ (function () {
1263
- function ColumnControl(json) {
1264
- this.json = json;
1265
- }
1266
- Object.defineProperty(ColumnControl.prototype, "id", {
1267
- get: function () {
1268
- return this.json.id;
1269
- },
1270
- enumerable: false,
1271
- configurable: true
1272
- });
1273
- Object.defineProperty(ColumnControl.prototype, "data", {
1274
- get: function () {
1275
- return this.json;
1276
- },
1277
- enumerable: false,
1278
- configurable: true
1279
- });
1280
- Object.defineProperty(ColumnControl.prototype, "column", {
1281
- get: function () {
1282
- return this._column;
1283
- },
1284
- set: function (value) {
1285
- this._column = value;
1286
- this.onColumnChange(this._column);
1287
- },
1288
- enumerable: false,
1289
- configurable: true
1290
- });
1291
- ColumnControl.prototype.remove = function () {
1292
- var _this = this;
1293
- this.column.controls = this.column.controls.filter(function (control) { return control.id !== _this.id; });
1294
- reindex(this.column.controls);
1295
- };
1296
- ColumnControl.prototype.setData = function (data) {
1297
- this.json = data;
1298
- };
1299
- return ColumnControl;
1300
- }());
1301
- export { ColumnControl };
1302
- var ClientsideText = /** @class */ (function (_super) {
1303
- __extends(ClientsideText, _super);
1304
- function ClientsideText(text, json) {
1305
- if (json === void 0) { json = JSON.parse(JSON.stringify(ClientsideText.Default)); }
1306
- var _this = this;
1307
- if (stringIsNullOrEmpty(json.id)) {
1308
- json.id = getGUID();
1309
- json.anchorComponentId = json.id;
1310
- }
1311
- _this = _super.call(this, json) || this;
1312
- _this.text = text;
1313
- return _this;
1314
- }
1315
- Object.defineProperty(ClientsideText.prototype, "text", {
1316
- get: function () {
1317
- return this.data.innerHTML;
1318
- },
1319
- set: function (value) {
1320
- this.data.innerHTML = value;
1321
- },
1322
- enumerable: false,
1323
- configurable: true
1324
- });
1325
- Object.defineProperty(ClientsideText.prototype, "order", {
1326
- get: function () {
1327
- return this.data.position.controlIndex;
1328
- },
1329
- set: function (value) {
1330
- this.data.position.controlIndex = value;
1331
- },
1332
- enumerable: false,
1333
- configurable: true
1334
- });
1335
- ClientsideText.prototype.onColumnChange = function (col) {
1336
- this.data.position.sectionFactor = col.factor;
1337
- this.data.position.controlIndex = getNextOrder(col.controls);
1338
- this.data.position.zoneIndex = col.data.position.zoneIndex;
1339
- this.data.position.sectionIndex = col.order;
1340
- this.data.position.layoutIndex = col.data.position.layoutIndex;
1341
- };
1342
- ClientsideText.Default = {
1343
- addedFromPersistedData: false,
1344
- anchorComponentId: "",
1345
- controlType: 4,
1346
- displayMode: 2,
1347
- editorType: "CKEditor",
1348
- emphasis: {},
1349
- id: "",
1350
- innerHTML: "",
1351
- position: {
1352
- controlIndex: 1,
1353
- layoutIndex: 1,
1354
- sectionFactor: 12,
1355
- sectionIndex: 1,
1356
- zoneIndex: 1,
1357
- },
1358
- };
1359
- return ClientsideText;
1360
- }(ColumnControl));
1361
- export { ClientsideText };
1362
- var ClientsideWebpart = /** @class */ (function (_super) {
1363
- __extends(ClientsideWebpart, _super);
1364
- function ClientsideWebpart(json) {
1365
- if (json === void 0) { json = JSON.parse(JSON.stringify(ClientsideWebpart.Default)); }
1366
- return _super.call(this, json) || this;
1367
- }
1368
- ClientsideWebpart.fromComponentDef = function (definition) {
1369
- var part = new ClientsideWebpart();
1370
- part.import(definition);
1371
- return part;
1372
- };
1373
- Object.defineProperty(ClientsideWebpart.prototype, "title", {
1374
- get: function () {
1375
- return this.data.webPartData.title;
1376
- },
1377
- set: function (value) {
1378
- this.data.webPartData.title = value;
1379
- },
1380
- enumerable: false,
1381
- configurable: true
1382
- });
1383
- Object.defineProperty(ClientsideWebpart.prototype, "description", {
1384
- get: function () {
1385
- return this.data.webPartData.description;
1386
- },
1387
- set: function (value) {
1388
- this.data.webPartData.description = value;
1389
- },
1390
- enumerable: false,
1391
- configurable: true
1392
- });
1393
- Object.defineProperty(ClientsideWebpart.prototype, "order", {
1394
- get: function () {
1395
- return this.data.position.controlIndex;
1396
- },
1397
- set: function (value) {
1398
- this.data.position.controlIndex = value;
1399
- },
1400
- enumerable: false,
1401
- configurable: true
1402
- });
1403
- Object.defineProperty(ClientsideWebpart.prototype, "height", {
1404
- get: function () {
1405
- return this.data.reservedHeight;
1406
- },
1407
- set: function (value) {
1408
- this.data.reservedHeight = value;
1409
- },
1410
- enumerable: false,
1411
- configurable: true
1412
- });
1413
- Object.defineProperty(ClientsideWebpart.prototype, "width", {
1414
- get: function () {
1415
- return this.data.reservedWidth;
1416
- },
1417
- set: function (value) {
1418
- this.data.reservedWidth = value;
1419
- },
1420
- enumerable: false,
1421
- configurable: true
1422
- });
1423
- Object.defineProperty(ClientsideWebpart.prototype, "dataVersion", {
1424
- get: function () {
1425
- return this.data.webPartData.dataVersion;
1426
- },
1427
- set: function (value) {
1428
- this.data.webPartData.dataVersion = value;
1429
- },
1430
- enumerable: false,
1431
- configurable: true
1432
- });
1433
- ClientsideWebpart.prototype.setProperties = function (properties) {
1434
- this.data.webPartData.properties = assign(this.data.webPartData.properties, properties);
1435
- return this;
1436
- };
1437
- ClientsideWebpart.prototype.getProperties = function () {
1438
- return this.data.webPartData.properties;
1439
- };
1440
- ClientsideWebpart.prototype.onColumnChange = function (col) {
1441
- this.data.position.sectionFactor = col.factor;
1442
- this.data.position.controlIndex = getNextOrder(col.controls);
1443
- this.data.position.zoneIndex = col.data.position.zoneIndex;
1444
- this.data.position.sectionIndex = col.data.position.sectionIndex;
1445
- this.data.position.layoutIndex = col.data.position.layoutIndex;
1446
- };
1447
- ClientsideWebpart.prototype.import = function (component) {
1448
- var id = getGUID();
1449
- var componendId = component.Id.replace(/^\{|\}$/g, "").toLowerCase();
1450
- var manifest = JSON.parse(component.Manifest);
1451
- var preconfiguredEntries = manifest.preconfiguredEntries[0];
1452
- this.setData(Object.assign({}, this.data, {
1453
- id: id,
1454
- webPartData: {
1455
- dataVersion: "1.0",
1456
- description: preconfiguredEntries.description.default,
1457
- id: componendId,
1458
- instanceId: id,
1459
- properties: preconfiguredEntries.properties,
1460
- title: preconfiguredEntries.title.default,
1461
- },
1462
- webPartId: componendId,
1463
- }));
1464
- };
1465
- ClientsideWebpart.Default = {
1466
- addedFromPersistedData: false,
1467
- controlType: 3,
1468
- displayMode: 2,
1469
- emphasis: {},
1470
- id: null,
1471
- position: {
1472
- controlIndex: 1,
1473
- layoutIndex: 1,
1474
- sectionFactor: 12,
1475
- sectionIndex: 1,
1476
- zoneIndex: 1,
1477
- },
1478
- reservedHeight: 500,
1479
- reservedWidth: 500,
1480
- webPartData: null,
1481
- webPartId: null,
1482
- };
1483
- return ClientsideWebpart;
1484
- }(ColumnControl));
1485
- export { ClientsideWebpart };
1
+ import { __awaiter, __decorate, __extends, __generator, __read, __spreadArray } from "tslib";
2
+ import { invokableFactory, body, headers } from "@pnp/odata";
3
+ import { assign, getGUID, hOP, stringIsNullOrEmpty, objectDefinedNotNull, combine, isUrlAbsolute, isArray } from "@pnp/common";
4
+ import { Item } from "../items/types.js";
5
+ import { SharePointQueryable, _SharePointQueryable, SharePointQueryableCollection } from "../sharepointqueryable.js";
6
+ import { metadata } from "../utils/metadata.js";
7
+ import { List } from "../lists/types.js";
8
+ import { odataUrlFrom } from "../odata.js";
9
+ import { Web } from "../webs/types.js";
10
+ import { extractWebUrl } from "../utils/extractweburl.js";
11
+ import { Site } from "../sites/types.js";
12
+ import { spPost } from "../operations.js";
13
+ import { getNextOrder, reindex } from "./funcs.js";
14
+ import "../files/web.js";
15
+ import "../comments/item.js";
16
+ import { tag } from "../telemetry.js";
17
+ /**
18
+ * Page promotion state
19
+ */
20
+ export var PromotedState;
21
+ (function (PromotedState) {
22
+ /**
23
+ * Regular client side page
24
+ */
25
+ PromotedState[PromotedState["NotPromoted"] = 0] = "NotPromoted";
26
+ /**
27
+ * Page that will be promoted as news article after publishing
28
+ */
29
+ PromotedState[PromotedState["PromoteOnPublish"] = 1] = "PromoteOnPublish";
30
+ /**
31
+ * Page that is promoted as news article
32
+ */
33
+ PromotedState[PromotedState["Promoted"] = 2] = "Promoted";
34
+ })(PromotedState || (PromotedState = {}));
35
+ function initFrom(o, url) {
36
+ return ClientsidePage(extractWebUrl(o.toUrl()), url).configureFrom(o);
37
+ }
38
+ /**
39
+ * Represents the data and methods associated with client side "modern" pages
40
+ */
41
+ var _ClientsidePage = /** @class */ (function (_super) {
42
+ __extends(_ClientsidePage, _super);
43
+ /**
44
+ * PLEASE DON'T USE THIS CONSTRUCTOR DIRECTLY, thank you 🐇
45
+ */
46
+ function _ClientsidePage(baseUrl, path, json, noInit, sections, commentsDisabled) {
47
+ if (noInit === void 0) { noInit = false; }
48
+ if (sections === void 0) { sections = []; }
49
+ if (commentsDisabled === void 0) { commentsDisabled = false; }
50
+ var _this = _super.call(this, baseUrl, path) || this;
51
+ _this.json = json;
52
+ _this.sections = sections;
53
+ _this.commentsDisabled = commentsDisabled;
54
+ _this._bannerImageDirty = false;
55
+ _this._bannerImageThumbnailUrlDirty = false;
56
+ // ensure we have a good url to build on for the pages api
57
+ if (typeof baseUrl === "string") {
58
+ _this.data.parentUrl = "";
59
+ _this.data.url = combine(extractWebUrl(baseUrl), path);
60
+ }
61
+ else {
62
+ _this.assign(initFrom(baseUrl, null), path);
63
+ }
64
+ // set a default page settings slice
65
+ _this._pageSettings = { controlType: 0, pageSettingsSlice: { isDefaultDescription: true, isDefaultThumbnail: true } };
66
+ // set a default layout part
67
+ _this._layoutPart = _ClientsidePage.getDefaultLayoutPart();
68
+ if (typeof json !== "undefined" && !noInit) {
69
+ _this.fromJSON(json);
70
+ }
71
+ return _this;
72
+ }
73
+ _ClientsidePage.getDefaultLayoutPart = function () {
74
+ return {
75
+ dataVersion: "1.4",
76
+ description: "Title Region Description",
77
+ id: "cbe7b0a9-3504-44dd-a3a3-0e5cacd07788",
78
+ instanceId: "cbe7b0a9-3504-44dd-a3a3-0e5cacd07788",
79
+ properties: {
80
+ authorByline: [],
81
+ authors: [],
82
+ layoutType: "FullWidthImage",
83
+ showPublishDate: false,
84
+ showTopicHeader: false,
85
+ textAlignment: "Left",
86
+ title: "",
87
+ topicHeader: "",
88
+ },
89
+ reservedHeight: 280,
90
+ serverProcessedContent: { htmlStrings: {}, searchablePlainTexts: {}, imageSources: {}, links: {} },
91
+ title: "Title area",
92
+ };
93
+ };
94
+ Object.defineProperty(_ClientsidePage.prototype, "pageLayout", {
95
+ get: function () {
96
+ return this.json.PageLayoutType;
97
+ },
98
+ set: function (value) {
99
+ this.json.PageLayoutType = value;
100
+ },
101
+ enumerable: false,
102
+ configurable: true
103
+ });
104
+ Object.defineProperty(_ClientsidePage.prototype, "bannerImageUrl", {
105
+ get: function () {
106
+ return this.json.BannerImageUrl;
107
+ },
108
+ set: function (value) {
109
+ this.setBannerImage(value);
110
+ },
111
+ enumerable: false,
112
+ configurable: true
113
+ });
114
+ Object.defineProperty(_ClientsidePage.prototype, "thumbnailUrl", {
115
+ get: function () {
116
+ return this._pageSettings.pageSettingsSlice.isDefaultThumbnail ? this.json.BannerImageUrl : this.json.BannerThumbnailUrl;
117
+ },
118
+ set: function (value) {
119
+ this.json.BannerThumbnailUrl = value;
120
+ this._bannerImageThumbnailUrlDirty = true;
121
+ this._pageSettings.pageSettingsSlice.isDefaultThumbnail = false;
122
+ },
123
+ enumerable: false,
124
+ configurable: true
125
+ });
126
+ Object.defineProperty(_ClientsidePage.prototype, "topicHeader", {
127
+ get: function () {
128
+ return objectDefinedNotNull(this.json.TopicHeader) ? this.json.TopicHeader : "";
129
+ },
130
+ set: function (value) {
131
+ this.json.TopicHeader = value;
132
+ this._layoutPart.properties.topicHeader = value;
133
+ if (stringIsNullOrEmpty(value)) {
134
+ this.showTopicHeader = false;
135
+ }
136
+ },
137
+ enumerable: false,
138
+ configurable: true
139
+ });
140
+ Object.defineProperty(_ClientsidePage.prototype, "title", {
141
+ get: function () {
142
+ return this._layoutPart.properties.title;
143
+ },
144
+ set: function (value) {
145
+ this.json.Title = value;
146
+ this._layoutPart.properties.title = value;
147
+ },
148
+ enumerable: false,
149
+ configurable: true
150
+ });
151
+ Object.defineProperty(_ClientsidePage.prototype, "reservedHeight", {
152
+ get: function () {
153
+ return this._layoutPart.reservedHeight;
154
+ },
155
+ set: function (value) {
156
+ this._layoutPart.reservedHeight = value;
157
+ },
158
+ enumerable: false,
159
+ configurable: true
160
+ });
161
+ Object.defineProperty(_ClientsidePage.prototype, "description", {
162
+ get: function () {
163
+ return this.json.Description;
164
+ },
165
+ set: function (value) {
166
+ if (!stringIsNullOrEmpty(value) && value.length > 255) {
167
+ throw Error("Modern Page description is limited to 255 chars.");
168
+ }
169
+ this.json.Description = value;
170
+ if (!hOP(this._pageSettings, "htmlAttributes")) {
171
+ this._pageSettings.htmlAttributes = [];
172
+ }
173
+ if (this._pageSettings.htmlAttributes.indexOf("modifiedDescription") < 0) {
174
+ this._pageSettings.htmlAttributes.push("modifiedDescription");
175
+ }
176
+ this._pageSettings.pageSettingsSlice.isDefaultDescription = false;
177
+ },
178
+ enumerable: false,
179
+ configurable: true
180
+ });
181
+ Object.defineProperty(_ClientsidePage.prototype, "layoutType", {
182
+ get: function () {
183
+ return this._layoutPart.properties.layoutType;
184
+ },
185
+ set: function (value) {
186
+ this._layoutPart.properties.layoutType = value;
187
+ },
188
+ enumerable: false,
189
+ configurable: true
190
+ });
191
+ Object.defineProperty(_ClientsidePage.prototype, "headerTextAlignment", {
192
+ get: function () {
193
+ return this._layoutPart.properties.textAlignment;
194
+ },
195
+ set: function (value) {
196
+ this._layoutPart.properties.textAlignment = value;
197
+ },
198
+ enumerable: false,
199
+ configurable: true
200
+ });
201
+ Object.defineProperty(_ClientsidePage.prototype, "showTopicHeader", {
202
+ get: function () {
203
+ return this._layoutPart.properties.showTopicHeader;
204
+ },
205
+ set: function (value) {
206
+ this._layoutPart.properties.showTopicHeader = value;
207
+ },
208
+ enumerable: false,
209
+ configurable: true
210
+ });
211
+ Object.defineProperty(_ClientsidePage.prototype, "showPublishDate", {
212
+ get: function () {
213
+ return this._layoutPart.properties.showPublishDate;
214
+ },
215
+ set: function (value) {
216
+ this._layoutPart.properties.showPublishDate = value;
217
+ },
218
+ enumerable: false,
219
+ configurable: true
220
+ });
221
+ Object.defineProperty(_ClientsidePage.prototype, "hasVerticalSection", {
222
+ get: function () {
223
+ return this.sections.findIndex(function (s) { return s.layoutIndex === 2; }) > -1;
224
+ },
225
+ enumerable: false,
226
+ configurable: true
227
+ });
228
+ Object.defineProperty(_ClientsidePage.prototype, "authorByLine", {
229
+ get: function () {
230
+ if (isArray(this._layoutPart.properties.authorByline) && this._layoutPart.properties.authorByline.length > 0) {
231
+ return this._layoutPart.properties.authorByline[0];
232
+ }
233
+ return null;
234
+ },
235
+ enumerable: false,
236
+ configurable: true
237
+ });
238
+ Object.defineProperty(_ClientsidePage.prototype, "verticalSection", {
239
+ get: function () {
240
+ if (this.hasVerticalSection) {
241
+ return this.addVerticalSection();
242
+ }
243
+ return null;
244
+ },
245
+ enumerable: false,
246
+ configurable: true
247
+ });
248
+ /**
249
+ * Add a section to this page
250
+ */
251
+ _ClientsidePage.prototype.addSection = function () {
252
+ var section = new CanvasSection(this, getNextOrder(this.sections), 1);
253
+ this.sections.push(section);
254
+ return section;
255
+ };
256
+ /**
257
+ * Add a section to this page
258
+ */
259
+ _ClientsidePage.prototype.addVerticalSection = function () {
260
+ // we can only have one vertical section so we find it if it exists
261
+ var sectionIndex = this.sections.findIndex(function (s) { return s.layoutIndex === 2; });
262
+ if (sectionIndex > -1) {
263
+ return this.sections[sectionIndex];
264
+ }
265
+ var section = new CanvasSection(this, getNextOrder(this.sections), 2);
266
+ this.sections.push(section);
267
+ return section;
268
+ };
269
+ /**
270
+ * Loads this instance from the appropriate JSON data
271
+ *
272
+ * @param pageData JSON data to load (replaces any existing data)
273
+ */
274
+ _ClientsidePage.prototype.fromJSON = function (pageData) {
275
+ this.json = pageData;
276
+ var canvasControls = JSON.parse(pageData.CanvasContent1);
277
+ var layouts = JSON.parse(pageData.LayoutWebpartsContent);
278
+ if (layouts && layouts.length > 0) {
279
+ this._layoutPart = layouts[0];
280
+ }
281
+ this.setControls(canvasControls);
282
+ return this;
283
+ };
284
+ /**
285
+ * Loads this page's content from the server
286
+ */
287
+ _ClientsidePage.prototype.load = function () {
288
+ return __awaiter(this, void 0, void 0, function () {
289
+ var item, pageData;
290
+ return __generator(this, function (_a) {
291
+ switch (_a.label) {
292
+ case 0: return [4 /*yield*/, this.getItem("Id", "CommentsDisabled")];
293
+ case 1:
294
+ item = _a.sent();
295
+ return [4 /*yield*/, SharePointQueryable(this, "_api/sitepages/pages(" + item.Id + ")")()];
296
+ case 2:
297
+ pageData = _a.sent();
298
+ this.commentsDisabled = item.CommentsDisabled;
299
+ return [2 /*return*/, this.fromJSON(pageData)];
300
+ }
301
+ });
302
+ });
303
+ };
304
+ /**
305
+ * Persists the content changes (sections, columns, and controls) [does not work with batching]
306
+ *
307
+ * @param publish If true the page is published, if false the changes are persisted to SharePoint but not published [Default: true]
308
+ */
309
+ _ClientsidePage.prototype.save = function (publish) {
310
+ if (publish === void 0) { publish = true; }
311
+ return __awaiter(this, void 0, void 0, function () {
312
+ var previewPartialUrl, serverRelativePath, imgInfo_1, webUrl_1, web, batch, f, saveBody, bannerImageUrlValue, updater, r;
313
+ return __generator(this, function (_a) {
314
+ switch (_a.label) {
315
+ case 0:
316
+ if (this.json.Id === null) {
317
+ throw Error("The id for this page is null. If you want to create a new page, please use ClientSidePage.Create");
318
+ }
319
+ previewPartialUrl = "_layouts/15/getpreview.ashx";
320
+ if (!(this._bannerImageDirty && !this.bannerImageUrl.includes(previewPartialUrl))) return [3 /*break*/, 2];
321
+ serverRelativePath = this.bannerImageUrl;
322
+ web = Web(extractWebUrl(this.toUrl())).configureFrom(this);
323
+ batch = web.createBatch();
324
+ web.getFileByServerRelativePath(serverRelativePath.replace(/%20/ig, " "))
325
+ .select("ListId", "WebId", "UniqueId", "Name", "SiteId").inBatch(batch)().then(function (r1) { return imgInfo_1 = r1; });
326
+ web.select("Url").inBatch(batch)().then(function (r2) { return webUrl_1 = r2.Url; });
327
+ // we know the .then calls above will run before execute resolves, ensuring the vars are set
328
+ return [4 /*yield*/, batch.execute()];
329
+ case 1:
330
+ // we know the .then calls above will run before execute resolves, ensuring the vars are set
331
+ _a.sent();
332
+ f = SharePointQueryable(webUrl_1, previewPartialUrl);
333
+ f.query.set("guidSite", "" + imgInfo_1.SiteId);
334
+ f.query.set("guidWeb", "" + imgInfo_1.WebId);
335
+ f.query.set("guidFile", "" + imgInfo_1.UniqueId);
336
+ this.bannerImageUrl = f.toUrlAndQuery();
337
+ if (!objectDefinedNotNull(this._layoutPart.serverProcessedContent)) {
338
+ this._layoutPart.serverProcessedContent = {};
339
+ }
340
+ this._layoutPart.serverProcessedContent.imageSources = { imageSource: serverRelativePath };
341
+ if (!objectDefinedNotNull(this._layoutPart.serverProcessedContent.customMetadata)) {
342
+ this._layoutPart.serverProcessedContent.customMetadata = {};
343
+ }
344
+ this._layoutPart.serverProcessedContent.customMetadata.imageSource = {
345
+ listId: imgInfo_1.ListId,
346
+ siteId: imgInfo_1.SiteId,
347
+ uniqueId: imgInfo_1.UniqueId,
348
+ webId: imgInfo_1.WebId,
349
+ };
350
+ this._layoutPart.properties.webId = imgInfo_1.WebId;
351
+ this._layoutPart.properties.siteId = imgInfo_1.SiteId;
352
+ this._layoutPart.properties.listId = imgInfo_1.ListId;
353
+ this._layoutPart.properties.uniqueId = imgInfo_1.UniqueId;
354
+ _a.label = 2;
355
+ case 2:
356
+ if (!!this.json.IsPageCheckedOutToCurrentUser) return [3 /*break*/, 4];
357
+ return [4 /*yield*/, spPost(initFrom(this, "_api/sitepages/pages(" + this.json.Id + ")/checkoutpage"))];
358
+ case 3:
359
+ _a.sent();
360
+ _a.label = 4;
361
+ case 4:
362
+ saveBody = Object.assign(metadata("SP.Publishing.SitePage"), {
363
+ AuthorByline: this.json.AuthorByline || [],
364
+ CanvasContent1: this.getCanvasContent1(),
365
+ Description: this.description,
366
+ LayoutWebpartsContent: this.getLayoutWebpartsContent(),
367
+ Title: this.title,
368
+ TopicHeader: this.topicHeader,
369
+ BannerImageUrl: this.bannerImageUrl,
370
+ });
371
+ if (this._bannerImageDirty || this._bannerImageThumbnailUrlDirty) {
372
+ bannerImageUrlValue = this._bannerImageThumbnailUrlDirty ? this.thumbnailUrl : this.bannerImageUrl;
373
+ saveBody = assign(saveBody, {
374
+ BannerImageUrl: bannerImageUrlValue,
375
+ });
376
+ }
377
+ updater = initFrom(this, "_api/sitepages/pages(" + this.json.Id + ")/savepage");
378
+ return [4 /*yield*/, spPost(updater, headers({ "if-match": "*" }, body(saveBody)))];
379
+ case 5:
380
+ _a.sent();
381
+ r = true;
382
+ if (!publish) return [3 /*break*/, 7];
383
+ return [4 /*yield*/, spPost(initFrom(this, "_api/sitepages/pages(" + this.json.Id + ")/publish"))];
384
+ case 6:
385
+ r = _a.sent();
386
+ if (r) {
387
+ this.json.IsPageCheckedOutToCurrentUser = false;
388
+ }
389
+ _a.label = 7;
390
+ case 7:
391
+ this._bannerImageDirty = false;
392
+ this._bannerImageThumbnailUrlDirty = false;
393
+ // we need to ensure we reload from the latest data to ensure all urls are updated and current in the object (expecially for new pages)
394
+ return [4 /*yield*/, this.load()];
395
+ case 8:
396
+ // we need to ensure we reload from the latest data to ensure all urls are updated and current in the object (expecially for new pages)
397
+ _a.sent();
398
+ return [2 /*return*/, r];
399
+ }
400
+ });
401
+ });
402
+ };
403
+ /**
404
+ * Discards the checkout of this page
405
+ */
406
+ _ClientsidePage.prototype.discardPageCheckout = function () {
407
+ return __awaiter(this, void 0, void 0, function () {
408
+ var d;
409
+ return __generator(this, function (_a) {
410
+ switch (_a.label) {
411
+ case 0:
412
+ if (this.json.Id === null) {
413
+ throw Error("The id for this page is null. If you want to create a new page, please use ClientSidePage.Create");
414
+ }
415
+ return [4 /*yield*/, spPost(initFrom(this, "_api/sitepages/pages(" + this.json.Id + ")/discardPage"), body(metadata("SP.Publishing.SitePage")))];
416
+ case 1:
417
+ d = _a.sent();
418
+ this.fromJSON(d);
419
+ return [2 /*return*/];
420
+ }
421
+ });
422
+ });
423
+ };
424
+ /**
425
+ * Promotes this page as a news item
426
+ */
427
+ _ClientsidePage.prototype.promoteToNews = function () {
428
+ return __awaiter(this, void 0, void 0, function () {
429
+ return __generator(this, function (_a) {
430
+ return [2 /*return*/, this.promoteNewsImpl("promoteToNews")];
431
+ });
432
+ });
433
+ };
434
+ // API is currently broken on server side
435
+ // public async demoteFromNews(): Promise<boolean> {
436
+ // return this.promoteNewsImpl("demoteFromNews");
437
+ // }
438
+ /**
439
+ * Finds a control by the specified instance id
440
+ *
441
+ * @param id Instance id of the control to find
442
+ */
443
+ _ClientsidePage.prototype.findControlById = function (id) {
444
+ return this.findControl(function (c) { return c.id === id; });
445
+ };
446
+ /**
447
+ * Finds a control within this page's control tree using the supplied predicate
448
+ *
449
+ * @param predicate Takes a control and returns true or false, if true that control is returned by findControl
450
+ */
451
+ _ClientsidePage.prototype.findControl = function (predicate) {
452
+ // check all sections
453
+ for (var i = 0; i < this.sections.length; i++) {
454
+ // check all columns
455
+ for (var j = 0; j < this.sections[i].columns.length; j++) {
456
+ // check all controls
457
+ for (var k = 0; k < this.sections[i].columns[j].controls.length; k++) {
458
+ // check to see if the predicate likes this control
459
+ if (predicate(this.sections[i].columns[j].controls[k])) {
460
+ return this.sections[i].columns[j].controls[k];
461
+ }
462
+ }
463
+ }
464
+ }
465
+ // we found nothing so give nothing back
466
+ return null;
467
+ };
468
+ /**
469
+ * Creates a new page with all of the content copied from this page
470
+ *
471
+ * @param web The web where we will create the copy
472
+ * @param pageName The file name of the new page
473
+ * @param title The title of the new page
474
+ * @param publish If true the page will be published (Default: true)
475
+ */
476
+ _ClientsidePage.prototype.copy = function (web, pageName, title, publish, promotedState) {
477
+ if (publish === void 0) { publish = true; }
478
+ return __awaiter(this, void 0, void 0, function () {
479
+ var page;
480
+ return __generator(this, function (_a) {
481
+ switch (_a.label) {
482
+ case 0: return [4 /*yield*/, CreateClientsidePage(web, pageName, title, this.pageLayout, promotedState)];
483
+ case 1:
484
+ page = _a.sent();
485
+ return [2 /*return*/, this.copyTo(page, publish)];
486
+ }
487
+ });
488
+ });
489
+ };
490
+ /**
491
+ * Copies the content from this page to the supplied page instance NOTE: fully overwriting any previous content!!
492
+ *
493
+ * @param page Page whose content we replace with this page's content
494
+ * @param publish If true the page will be published after the copy, if false it will be saved but left unpublished (Default: true)
495
+ */
496
+ _ClientsidePage.prototype.copyTo = function (page, publish) {
497
+ if (publish === void 0) { publish = true; }
498
+ return __awaiter(this, void 0, void 0, function () {
499
+ var url, makeGuid, guidSite, guidWeb, guidFile, site, id, openWeb, file, props;
500
+ return __generator(this, function (_a) {
501
+ switch (_a.label) {
502
+ case 0:
503
+ // we know the method is on the class - but it is protected so not part of the interface
504
+ page.setControls(this.getControls());
505
+ if (!!stringIsNullOrEmpty(this.json.BannerImageUrl)) return [3 /*break*/, 4];
506
+ url = new URL(this.json.BannerImageUrl);
507
+ makeGuid = function (s) { return s.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/g, "$1-$2-$3-$4-$5"); };
508
+ if (!(url.searchParams.has("guidSite") && url.searchParams.has("guidWeb") && url.searchParams.has("guidFile"))) return [3 /*break*/, 4];
509
+ guidSite = makeGuid(url.searchParams.get("guidSite"));
510
+ guidWeb = makeGuid(url.searchParams.get("guidWeb"));
511
+ guidFile = makeGuid(url.searchParams.get("guidFile"));
512
+ site = Site(extractWebUrl(this.toUrl()));
513
+ return [4 /*yield*/, site.select("Id")()];
514
+ case 1:
515
+ id = _a.sent();
516
+ if (!(id.Id === guidSite)) return [3 /*break*/, 4];
517
+ return [4 /*yield*/, site.openWebById(guidWeb)];
518
+ case 2:
519
+ openWeb = _a.sent();
520
+ return [4 /*yield*/, openWeb.web.getFileById(guidFile).select("ServerRelativeUrl")()];
521
+ case 3:
522
+ file = _a.sent();
523
+ props = {};
524
+ if (this._layoutPart.properties) {
525
+ if (hOP(this._layoutPart.properties, "translateX")) {
526
+ props.translateX = this._layoutPart.properties.translateX;
527
+ }
528
+ if (hOP(this._layoutPart.properties, "translateY")) {
529
+ props.translateY = this._layoutPart.properties.translateY;
530
+ }
531
+ if (hOP(this._layoutPart.properties, "imageSourceType")) {
532
+ props.imageSourceType = this._layoutPart.properties.imageSourceType;
533
+ }
534
+ if (hOP(this._layoutPart.properties, "altText")) {
535
+ props.altText = this._layoutPart.properties.altText;
536
+ }
537
+ }
538
+ page.setBannerImage(file.ServerRelativeUrl, props);
539
+ _a.label = 4;
540
+ case 4: return [4 /*yield*/, page.save(publish)];
541
+ case 5:
542
+ _a.sent();
543
+ return [2 /*return*/, page];
544
+ }
545
+ });
546
+ });
547
+ };
548
+ /**
549
+ * Sets the modern page banner image
550
+ *
551
+ * @param url Url of the image to display
552
+ * @param altText Alt text to describe the image
553
+ * @param bannerProps Additional properties to control display of the banner
554
+ */
555
+ _ClientsidePage.prototype.setBannerImage = function (url, props) {
556
+ if (isUrlAbsolute(url)) {
557
+ // do our best to make this a server relative url by removing the x.sharepoint.com part
558
+ url = url.replace(/^https?:\/\/[a-z0-9.]*?\.[a-z]{2,3}\//i, "/");
559
+ }
560
+ this.json.BannerImageUrl = url;
561
+ // update serverProcessedContent (page behavior change 2021-Oct-13)
562
+ this._layoutPart.serverProcessedContent = { imageSources: { imageSource: url }, };
563
+ this._bannerImageDirty = true;
564
+ /*
565
+ setting the banner image resets the thumbnail image (matching UI functionality)
566
+ but if the thumbnail is dirty they are likely trying to set them both to
567
+ different values, so we allow that here.
568
+ Also allows the banner image to be updated safely with the calculated one in save()
569
+ */
570
+ if (!this._bannerImageThumbnailUrlDirty) {
571
+ this.thumbnailUrl = url;
572
+ this._pageSettings.pageSettingsSlice.isDefaultThumbnail = true;
573
+ }
574
+ // this seems to always be true, so default
575
+ this._layoutPart.properties.imageSourceType = 2;
576
+ if (objectDefinedNotNull(props)) {
577
+ if (hOP(props, "translateX")) {
578
+ this._layoutPart.properties.translateX = props.translateX;
579
+ }
580
+ if (hOP(props, "translateY")) {
581
+ this._layoutPart.properties.translateY = props.translateY;
582
+ }
583
+ if (hOP(props, "imageSourceType")) {
584
+ this._layoutPart.properties.imageSourceType = props.imageSourceType;
585
+ }
586
+ if (hOP(props, "altText")) {
587
+ this._layoutPart.properties.altText = props.altText;
588
+ }
589
+ }
590
+ };
591
+ /**
592
+ * Sets the banner image url from an external source. You must call save to persist the changes
593
+ *
594
+ * @param url absolute url of the external file
595
+ * @param props optional set of properties to control display of the banner image
596
+ */
597
+ _ClientsidePage.prototype.setBannerImageFromExternalUrl = function (url, props) {
598
+ return __awaiter(this, void 0, void 0, function () {
599
+ var fileUrl, pageName, filename, request, result;
600
+ return __generator(this, function (_a) {
601
+ switch (_a.label) {
602
+ case 0:
603
+ fileUrl = new URL(url);
604
+ pageName = this.json.FileName.replace(/\.[^/.]+$/, "");
605
+ filename = fileUrl.pathname.split(/[\\/]/i).pop();
606
+ request = initFrom(this, "_api/sitepages/AddImageFromExternalUrl");
607
+ request.query.set("imageFileName", "'" + encodeURIComponent(filename) + "'");
608
+ request.query.set("pageName", "'" + encodeURIComponent(pageName) + "'");
609
+ request.query.set("externalUrl", "'" + encodeURIComponent(url) + "'");
610
+ request.select("ServerRelativeUrl");
611
+ return [4 /*yield*/, spPost(request)];
612
+ case 1:
613
+ result = _a.sent();
614
+ // set with the newly created relative url
615
+ this.setBannerImage(result.ServerRelativeUrl, props);
616
+ return [2 /*return*/];
617
+ }
618
+ });
619
+ });
620
+ };
621
+ /**
622
+ * Sets the authors for this page from the supplied list of user integer ids
623
+ *
624
+ * @param authorId The integer id of the user to set as the author
625
+ */
626
+ _ClientsidePage.prototype.setAuthorById = function (authorId) {
627
+ return __awaiter(this, void 0, void 0, function () {
628
+ var userLoginData;
629
+ return __generator(this, function (_a) {
630
+ switch (_a.label) {
631
+ case 0: return [4 /*yield*/, SharePointQueryableCollection(extractWebUrl(this.toUrl()), "/_api/web/siteusers")
632
+ .configureFrom(this)
633
+ .filter("Id eq " + authorId)
634
+ .select("LoginName")()];
635
+ case 1:
636
+ userLoginData = _a.sent();
637
+ if (userLoginData.length < 1) {
638
+ throw Error("Could not find user with id " + authorId + ".");
639
+ }
640
+ return [2 /*return*/, this.setAuthorByLoginName(userLoginData[0].LoginName)];
641
+ }
642
+ });
643
+ });
644
+ };
645
+ /**
646
+ * Sets the authors for this page from the supplied list of user integer ids
647
+ *
648
+ * @param authorLoginName The login name of the user (ex: i:0#.f|membership|name@tenant.com)
649
+ */
650
+ _ClientsidePage.prototype.setAuthorByLoginName = function (authorLoginName) {
651
+ return __awaiter(this, void 0, void 0, function () {
652
+ var userLoginData;
653
+ return __generator(this, function (_a) {
654
+ switch (_a.label) {
655
+ case 0: return [4 /*yield*/, SharePointQueryableCollection(extractWebUrl(this.toUrl()), "/_api/web/siteusers")
656
+ .configureFrom(this)
657
+ .filter("LoginName eq '" + authorLoginName + "'")
658
+ .select("UserPrincipalName", "Title")()];
659
+ case 1:
660
+ userLoginData = _a.sent();
661
+ if (userLoginData.length < 1) {
662
+ throw Error("Could not find user with login name '" + authorLoginName + "'.");
663
+ }
664
+ this.json.AuthorByline = [userLoginData[0].UserPrincipalName];
665
+ this._layoutPart.properties.authorByline = [userLoginData[0].UserPrincipalName];
666
+ this._layoutPart.properties.authors = [{
667
+ id: authorLoginName,
668
+ name: userLoginData[0].Title,
669
+ role: "",
670
+ upn: userLoginData[0].UserPrincipalName,
671
+ }];
672
+ return [2 /*return*/];
673
+ }
674
+ });
675
+ });
676
+ };
677
+ /**
678
+ * Gets the list item associated with this clientside page
679
+ *
680
+ * @param selects Specific set of fields to include when getting the item
681
+ */
682
+ _ClientsidePage.prototype.getItem = function () {
683
+ var selects = [];
684
+ for (var _i = 0; _i < arguments.length; _i++) {
685
+ selects[_i] = arguments[_i];
686
+ }
687
+ return __awaiter(this, void 0, void 0, function () {
688
+ var initer, listData, item, itemData;
689
+ return __generator(this, function (_a) {
690
+ switch (_a.label) {
691
+ case 0:
692
+ initer = initFrom(this, "/_api/lists/EnsureClientRenderedSitePagesLibrary").select("EnableModeration", "EnableMinorVersions", "Id");
693
+ return [4 /*yield*/, spPost(initer)];
694
+ case 1:
695
+ listData = _a.sent();
696
+ item = (List(listData["odata.id"])).configureFrom(this).items.getById(this.json.Id);
697
+ return [4 /*yield*/, item.select.apply(item, __spreadArray([], __read(selects), false))()];
698
+ case 2:
699
+ itemData = _a.sent();
700
+ return [2 /*return*/, assign((Item(odataUrlFrom(itemData))).configureFrom(this), itemData)];
701
+ }
702
+ });
703
+ });
704
+ };
705
+ /**
706
+ * Recycle this page
707
+ */
708
+ _ClientsidePage.prototype.recycle = function () {
709
+ return __awaiter(this, void 0, void 0, function () {
710
+ var item;
711
+ return __generator(this, function (_a) {
712
+ switch (_a.label) {
713
+ case 0: return [4 /*yield*/, this.getItem()];
714
+ case 1:
715
+ item = _a.sent();
716
+ return [4 /*yield*/, item.recycle()];
717
+ case 2:
718
+ _a.sent();
719
+ return [2 /*return*/];
720
+ }
721
+ });
722
+ });
723
+ };
724
+ /**
725
+ * Delete this page
726
+ */
727
+ _ClientsidePage.prototype.delete = function () {
728
+ return __awaiter(this, void 0, void 0, function () {
729
+ var item;
730
+ return __generator(this, function (_a) {
731
+ switch (_a.label) {
732
+ case 0: return [4 /*yield*/, this.getItem()];
733
+ case 1:
734
+ item = _a.sent();
735
+ return [4 /*yield*/, item.delete()];
736
+ case 2:
737
+ _a.sent();
738
+ return [2 /*return*/];
739
+ }
740
+ });
741
+ });
742
+ };
743
+ // not yet active in service
744
+ // /**
745
+ // * Schedules a page for publishing
746
+ // *
747
+ // * @param publishDate Date to publish the item
748
+ // * @returns Publish work item details
749
+ // */
750
+ // public async schedulePublish(publishDate: Date): Promise<string> {
751
+ // let r: string;
752
+ // // currently the server throws an exception, but then the page is published as expected
753
+ // // so we just ignore that error for now, YMMV
754
+ // try {
755
+ // r = await spPost(initFrom(this, `_api/sitepages/pages(${this.json.Id})/SchedulePublish`), body({
756
+ // sitePage: { PublishStartDate: publishDate },
757
+ // }));
758
+ // } catch {
759
+ // r = "";
760
+ // }
761
+ // return r;
762
+ // }
763
+ /**
764
+ * Saves a copy of this page as a template in this library's Templates folder
765
+ *
766
+ * @param publish If true the template is published, false the template is not published (default: true)
767
+ * @returns IClientsidePage instance representing the new template page
768
+ */
769
+ _ClientsidePage.prototype.saveAsTemplate = function (publish) {
770
+ if (publish === void 0) { publish = true; }
771
+ return __awaiter(this, void 0, void 0, function () {
772
+ var data, page;
773
+ return __generator(this, function (_a) {
774
+ switch (_a.label) {
775
+ case 0: return [4 /*yield*/, spPost(initFrom(this, "_api/sitepages/pages(" + this.json.Id + ")/SavePageAsTemplate"))];
776
+ case 1:
777
+ data = _a.sent();
778
+ page = ClientsidePage(this, null, data);
779
+ page.title = this.title;
780
+ return [4 /*yield*/, page.save(publish)];
781
+ case 2:
782
+ _a.sent();
783
+ return [2 /*return*/, page];
784
+ }
785
+ });
786
+ });
787
+ };
788
+ /**
789
+ * Share this Page's Preview content by Email
790
+ *
791
+ * @param emails Set of emails to which the preview is shared
792
+ * @param message The message to include
793
+ * @returns void
794
+ */
795
+ _ClientsidePage.prototype.share = function (emails, message) {
796
+ return spPost(initFrom(this, "_api/SP.Publishing.RichSharing/SharePageByEmail"), body({
797
+ recipientEmails: emails,
798
+ message: message,
799
+ url: this.json.AbsoluteUrl,
800
+ }));
801
+ };
802
+ /**
803
+ * Extends this queryable from the provided parent
804
+ *
805
+ * @param parent Parent queryable from which we will derive a base url
806
+ * @param path Additional path
807
+ */
808
+ _ClientsidePage.prototype.assign = function (parent, path) {
809
+ this.data.parentUrl = parent.data.url;
810
+ this.data.url = combine(this.data.parentUrl, path || "");
811
+ this.configureFrom(parent);
812
+ };
813
+ _ClientsidePage.prototype.getCanvasContent1 = function () {
814
+ return JSON.stringify(this.getControls());
815
+ };
816
+ _ClientsidePage.prototype.getLayoutWebpartsContent = function () {
817
+ if (this._layoutPart) {
818
+ return JSON.stringify([this._layoutPart]);
819
+ }
820
+ else {
821
+ return JSON.stringify(null);
822
+ }
823
+ };
824
+ _ClientsidePage.prototype.setControls = function (controls) {
825
+ // reset the sections
826
+ this.sections = [];
827
+ if (controls && controls.length) {
828
+ for (var i = 0; i < controls.length; i++) {
829
+ // if no control type is present this is a column which we give type 0 to let us process it
830
+ var controlType = hOP(controls[i], "controlType") ? controls[i].controlType : 0;
831
+ switch (controlType) {
832
+ case 0:
833
+ // empty canvas column or page settings
834
+ if (hOP(controls[i], "pageSettingsSlice")) {
835
+ this._pageSettings = controls[i];
836
+ }
837
+ else {
838
+ // we have an empty column
839
+ this.mergeColumnToTree(new CanvasColumn(controls[i]));
840
+ }
841
+ break;
842
+ case 3: {
843
+ var part = new ClientsideWebpart(controls[i]);
844
+ this.mergePartToTree(part, part.data.position);
845
+ break;
846
+ }
847
+ case 4: {
848
+ var textData = controls[i];
849
+ var text = new ClientsideText(textData.innerHTML, textData);
850
+ this.mergePartToTree(text, text.data.position);
851
+ break;
852
+ }
853
+ }
854
+ }
855
+ reindex(this.sections);
856
+ }
857
+ };
858
+ _ClientsidePage.prototype.getControls = function () {
859
+ var _this = this;
860
+ // reindex things
861
+ reindex(this.sections);
862
+ // rollup the control changes
863
+ var canvasData = [];
864
+ this.sections.forEach(function (section) {
865
+ section.columns.forEach(function (column) {
866
+ if (column.controls.length < 1) {
867
+ // empty column
868
+ canvasData.push({
869
+ displayMode: column.data.displayMode,
870
+ emphasis: _this.getEmphasisObj(section.emphasis),
871
+ position: column.data.position,
872
+ });
873
+ }
874
+ else {
875
+ column.controls.forEach(function (control) {
876
+ control.data.emphasis = _this.getEmphasisObj(section.emphasis);
877
+ canvasData.push(_this.specialSaveHandling(control).data);
878
+ });
879
+ }
880
+ });
881
+ });
882
+ canvasData.push(this._pageSettings);
883
+ return canvasData;
884
+ };
885
+ _ClientsidePage.prototype.getEmphasisObj = function (value) {
886
+ if (value < 1 || value > 3) {
887
+ return {};
888
+ }
889
+ return { zoneEmphasis: value };
890
+ };
891
+ _ClientsidePage.prototype.promoteNewsImpl = function (method) {
892
+ return __awaiter(this, void 0, void 0, function () {
893
+ var lastPubData;
894
+ return __generator(this, function (_a) {
895
+ switch (_a.label) {
896
+ case 0:
897
+ if (this.json.Id === null) {
898
+ throw Error("The id for this page is null.");
899
+ }
900
+ if (!stringIsNullOrEmpty(this.json.VersionInfo.LastVersionCreatedBy)) return [3 /*break*/, 2];
901
+ lastPubData = new Date(this.json.VersionInfo.LastVersionCreated);
902
+ if (!(lastPubData.getFullYear() < 2000)) return [3 /*break*/, 2];
903
+ return [4 /*yield*/, this.save(true)];
904
+ case 1:
905
+ _a.sent();
906
+ _a.label = 2;
907
+ case 2: return [4 /*yield*/, spPost(initFrom(this, "_api/sitepages/pages(" + this.json.Id + ")/" + method), body(metadata("SP.Publishing.SitePage")))];
908
+ case 3: return [2 /*return*/, _a.sent()];
909
+ }
910
+ });
911
+ });
912
+ };
913
+ /**
914
+ * Merges the control into the tree of sections and columns for this page
915
+ *
916
+ * @param control The control to merge
917
+ */
918
+ _ClientsidePage.prototype.mergePartToTree = function (control, positionData) {
919
+ var _a, _b, _c;
920
+ var column = null;
921
+ var sectionFactor = 12;
922
+ var sectionIndex = 0;
923
+ var zoneIndex = 0;
924
+ var layoutIndex = 1;
925
+ // handle case where we don't have position data (shouldn't happen?)
926
+ if (positionData) {
927
+ if (hOP(positionData, "zoneIndex")) {
928
+ zoneIndex = positionData.zoneIndex;
929
+ }
930
+ if (hOP(positionData, "sectionIndex")) {
931
+ sectionIndex = positionData.sectionIndex;
932
+ }
933
+ if (hOP(positionData, "sectionFactor")) {
934
+ sectionFactor = positionData.sectionFactor;
935
+ }
936
+ if (hOP(positionData, "layoutIndex")) {
937
+ layoutIndex = positionData.layoutIndex;
938
+ }
939
+ }
940
+ var zoneEmphasis = (_c = (_b = (_a = control.data) === null || _a === void 0 ? void 0 : _a.emphasis) === null || _b === void 0 ? void 0 : _b.zoneEmphasis) !== null && _c !== void 0 ? _c : 0;
941
+ var section = this.getOrCreateSection(zoneIndex, layoutIndex, zoneEmphasis);
942
+ var columns = section.columns.filter(function (c) { return c.order === sectionIndex; });
943
+ if (columns.length < 1) {
944
+ column = section.addColumn(sectionFactor, layoutIndex);
945
+ }
946
+ else {
947
+ column = columns[0];
948
+ }
949
+ control.column = column;
950
+ column.addControl(control);
951
+ };
952
+ /**
953
+ * Merges the supplied column into the tree
954
+ *
955
+ * @param column Column to merge
956
+ * @param position The position data for the column
957
+ */
958
+ _ClientsidePage.prototype.mergeColumnToTree = function (column) {
959
+ var _a, _b;
960
+ var order = hOP(column.data, "position") && hOP(column.data.position, "zoneIndex") ? column.data.position.zoneIndex : 0;
961
+ var layoutIndex = hOP(column.data, "position") && hOP(column.data.position, "layoutIndex") ? column.data.position.layoutIndex : 1;
962
+ var section = this.getOrCreateSection(order, layoutIndex, ((_b = (_a = column.data) === null || _a === void 0 ? void 0 : _a.emphasis) === null || _b === void 0 ? void 0 : _b.zoneEmphasis) || 0);
963
+ column.section = section;
964
+ section.columns.push(column);
965
+ };
966
+ /**
967
+ * Handle the logic to get or create a section based on the supplied order and layoutIndex
968
+ *
969
+ * @param order Section order
970
+ * @param layoutIndex Layout Index (1 === normal, 2 === vertical section)
971
+ * @param emphasis The section emphasis
972
+ */
973
+ _ClientsidePage.prototype.getOrCreateSection = function (order, layoutIndex, emphasis) {
974
+ var section = null;
975
+ var sections = this.sections.filter(function (s) { return s.order === order && s.layoutIndex === layoutIndex; });
976
+ if (sections.length < 1) {
977
+ section = layoutIndex === 2 ? this.addVerticalSection() : this.addSection();
978
+ section.order = order;
979
+ section.emphasis = emphasis;
980
+ }
981
+ else {
982
+ section = sections[0];
983
+ }
984
+ return section;
985
+ };
986
+ /**
987
+ * Based on issue #1690 we need to take special case actions to ensure some things
988
+ * can be saved properly without breaking existing pages.
989
+ *
990
+ * @param control The control we are ensuring is "ready" to be saved
991
+ */
992
+ _ClientsidePage.prototype.specialSaveHandling = function (control) {
993
+ var _a, _b, _c;
994
+ // this is to handle the special case in issue #1690
995
+ // must ensure that searchablePlainTexts values have < replaced with &lt; in links web part
996
+ if (control.data.controlType === 3 && control.data.webPartId === "c70391ea-0b10-4ee9-b2b4-006d3fcad0cd") {
997
+ var texts = ((_c = (_b = (_a = control.data) === null || _a === void 0 ? void 0 : _a.webPartData) === null || _b === void 0 ? void 0 : _b.serverProcessedContent) === null || _c === void 0 ? void 0 : _c.searchablePlainTexts) || null;
998
+ if (objectDefinedNotNull(texts)) {
999
+ var keys = Object.getOwnPropertyNames(texts);
1000
+ for (var i = 0; i < keys.length; i++) {
1001
+ texts[keys[i]] = texts[keys[i]].replace(/</ig, "&lt;");
1002
+ control.data.webPartData.serverProcessedContent.searchablePlainTexts = texts;
1003
+ }
1004
+ }
1005
+ }
1006
+ return control;
1007
+ };
1008
+ __decorate([
1009
+ tag("csp.load")
1010
+ ], _ClientsidePage.prototype, "load", null);
1011
+ __decorate([
1012
+ tag("csp.save")
1013
+ ], _ClientsidePage.prototype, "save", null);
1014
+ __decorate([
1015
+ tag("csp.discardPageCheckout")
1016
+ ], _ClientsidePage.prototype, "discardPageCheckout", null);
1017
+ __decorate([
1018
+ tag("csp.promoteToNews")
1019
+ ], _ClientsidePage.prototype, "promoteToNews", null);
1020
+ __decorate([
1021
+ tag("csp.copy")
1022
+ ], _ClientsidePage.prototype, "copy", null);
1023
+ __decorate([
1024
+ tag("csp.copyTo")
1025
+ ], _ClientsidePage.prototype, "copyTo", null);
1026
+ __decorate([
1027
+ tag("csp.getItem")
1028
+ ], _ClientsidePage.prototype, "getItem", null);
1029
+ return _ClientsidePage;
1030
+ }(_SharePointQueryable));
1031
+ export { _ClientsidePage };
1032
+ /**
1033
+ * Invokable factory for IClientSidePage instances
1034
+ */
1035
+ var ClientsidePage = function (baseUrl, path, json, noInit, sections, commentsDisabled) {
1036
+ if (noInit === void 0) { noInit = false; }
1037
+ if (sections === void 0) { sections = []; }
1038
+ if (commentsDisabled === void 0) { commentsDisabled = false; }
1039
+ return invokableFactory(_ClientsidePage)(baseUrl, path, json, noInit, sections, commentsDisabled);
1040
+ };
1041
+ /**
1042
+ * Loads a client side page from the supplied IFile instance
1043
+ *
1044
+ * @param file Source IFile instance
1045
+ */
1046
+ export var ClientsidePageFromFile = function (file) { return __awaiter(void 0, void 0, void 0, function () {
1047
+ var item, page;
1048
+ return __generator(this, function (_a) {
1049
+ switch (_a.label) {
1050
+ case 0: return [4 /*yield*/, file.getItem()];
1051
+ case 1:
1052
+ item = _a.sent();
1053
+ page = ClientsidePage(extractWebUrl(file.toUrl()), "", { Id: item.Id }, true);
1054
+ return [2 /*return*/, page.configureFrom(file).load()];
1055
+ }
1056
+ });
1057
+ }); };
1058
+ /**
1059
+ * Creates a new client side page
1060
+ *
1061
+ * @param web The web or list
1062
+ * @param pageName The name of the page (filename)
1063
+ * @param title The page's title
1064
+ * @param PageLayoutType Layout to use when creating the page
1065
+ */
1066
+ export var CreateClientsidePage = function (web, pageName, title, PageLayoutType, promotedState) {
1067
+ if (PageLayoutType === void 0) { PageLayoutType = "Article"; }
1068
+ if (promotedState === void 0) { promotedState = 0; }
1069
+ return __awaiter(void 0, void 0, void 0, function () {
1070
+ var pageInitData, newPage;
1071
+ return __generator(this, function (_a) {
1072
+ switch (_a.label) {
1073
+ case 0:
1074
+ // patched because previously we used the full page name with the .aspx at the end
1075
+ // this allows folk's existing code to work after the re-write to the new API
1076
+ pageName = pageName.replace(/\.aspx$/i, "");
1077
+ return [4 /*yield*/, spPost(initFrom(web, "_api/sitepages/pages"), body(Object.assign(metadata("SP.Publishing.SitePage"), {
1078
+ PageLayoutType: PageLayoutType,
1079
+ PromotedState: promotedState,
1080
+ })))];
1081
+ case 1:
1082
+ pageInitData = _a.sent();
1083
+ newPage = ClientsidePage(web, "", pageInitData);
1084
+ newPage.title = pageName;
1085
+ return [4 /*yield*/, newPage.save(false)];
1086
+ case 2:
1087
+ _a.sent();
1088
+ newPage.title = title;
1089
+ return [2 /*return*/, newPage];
1090
+ }
1091
+ });
1092
+ });
1093
+ };
1094
+ var CanvasSection = /** @class */ (function () {
1095
+ function CanvasSection(page, order, layoutIndex, columns, _emphasis) {
1096
+ if (columns === void 0) { columns = []; }
1097
+ if (_emphasis === void 0) { _emphasis = 0; }
1098
+ this.page = page;
1099
+ this.columns = columns;
1100
+ this._emphasis = _emphasis;
1101
+ this._memId = getGUID();
1102
+ this._order = order;
1103
+ this._layoutIndex = layoutIndex;
1104
+ }
1105
+ Object.defineProperty(CanvasSection.prototype, "order", {
1106
+ get: function () {
1107
+ return this._order;
1108
+ },
1109
+ set: function (value) {
1110
+ this._order = value;
1111
+ for (var i = 0; i < this.columns.length; i++) {
1112
+ this.columns[i].data.position.zoneIndex = value;
1113
+ }
1114
+ },
1115
+ enumerable: false,
1116
+ configurable: true
1117
+ });
1118
+ Object.defineProperty(CanvasSection.prototype, "layoutIndex", {
1119
+ get: function () {
1120
+ return this._layoutIndex;
1121
+ },
1122
+ set: function (value) {
1123
+ this._layoutIndex = value;
1124
+ for (var i = 0; i < this.columns.length; i++) {
1125
+ this.columns[i].data.position.layoutIndex = value;
1126
+ }
1127
+ },
1128
+ enumerable: false,
1129
+ configurable: true
1130
+ });
1131
+ Object.defineProperty(CanvasSection.prototype, "defaultColumn", {
1132
+ /**
1133
+ * Default column (this.columns[0]) for this section
1134
+ */
1135
+ get: function () {
1136
+ if (this.columns.length < 1) {
1137
+ this.addColumn(12);
1138
+ }
1139
+ return this.columns[0];
1140
+ },
1141
+ enumerable: false,
1142
+ configurable: true
1143
+ });
1144
+ /**
1145
+ * Adds a new column to this section
1146
+ */
1147
+ CanvasSection.prototype.addColumn = function (factor, layoutIndex) {
1148
+ if (layoutIndex === void 0) { layoutIndex = this.layoutIndex; }
1149
+ var column = new CanvasColumn();
1150
+ column.section = this;
1151
+ column.data.position.zoneIndex = this.order;
1152
+ column.data.position.layoutIndex = layoutIndex;
1153
+ column.data.position.sectionFactor = factor;
1154
+ column.order = getNextOrder(this.columns);
1155
+ this.columns.push(column);
1156
+ return column;
1157
+ };
1158
+ /**
1159
+ * Adds a control to the default column for this section
1160
+ *
1161
+ * @param control Control to add to the default column
1162
+ */
1163
+ CanvasSection.prototype.addControl = function (control) {
1164
+ this.defaultColumn.addControl(control);
1165
+ return this;
1166
+ };
1167
+ Object.defineProperty(CanvasSection.prototype, "emphasis", {
1168
+ get: function () {
1169
+ return this._emphasis;
1170
+ },
1171
+ set: function (value) {
1172
+ this._emphasis = value;
1173
+ },
1174
+ enumerable: false,
1175
+ configurable: true
1176
+ });
1177
+ /**
1178
+ * Removes this section and all contained columns and controls from the collection
1179
+ */
1180
+ CanvasSection.prototype.remove = function () {
1181
+ var _this = this;
1182
+ this.page.sections = this.page.sections.filter(function (section) { return section._memId !== _this._memId; });
1183
+ reindex(this.page.sections);
1184
+ };
1185
+ return CanvasSection;
1186
+ }());
1187
+ export { CanvasSection };
1188
+ var CanvasColumn = /** @class */ (function () {
1189
+ function CanvasColumn(json, controls) {
1190
+ if (json === void 0) { json = JSON.parse(JSON.stringify(CanvasColumn.Default)); }
1191
+ if (controls === void 0) { controls = []; }
1192
+ this.json = json;
1193
+ this.controls = controls;
1194
+ this._section = null;
1195
+ this._memId = getGUID();
1196
+ }
1197
+ Object.defineProperty(CanvasColumn.prototype, "data", {
1198
+ get: function () {
1199
+ return this.json;
1200
+ },
1201
+ enumerable: false,
1202
+ configurable: true
1203
+ });
1204
+ Object.defineProperty(CanvasColumn.prototype, "section", {
1205
+ get: function () {
1206
+ return this._section;
1207
+ },
1208
+ set: function (section) {
1209
+ this._section = section;
1210
+ },
1211
+ enumerable: false,
1212
+ configurable: true
1213
+ });
1214
+ Object.defineProperty(CanvasColumn.prototype, "order", {
1215
+ get: function () {
1216
+ return this.data.position.sectionIndex;
1217
+ },
1218
+ set: function (value) {
1219
+ this.data.position.sectionIndex = value;
1220
+ for (var i = 0; i < this.controls.length; i++) {
1221
+ this.controls[i].data.position.zoneIndex = this.data.position.zoneIndex;
1222
+ this.controls[i].data.position.layoutIndex = this.data.position.layoutIndex;
1223
+ this.controls[i].data.position.sectionIndex = value;
1224
+ }
1225
+ },
1226
+ enumerable: false,
1227
+ configurable: true
1228
+ });
1229
+ Object.defineProperty(CanvasColumn.prototype, "factor", {
1230
+ get: function () {
1231
+ return this.data.position.sectionFactor;
1232
+ },
1233
+ set: function (value) {
1234
+ this.data.position.sectionFactor = value;
1235
+ },
1236
+ enumerable: false,
1237
+ configurable: true
1238
+ });
1239
+ CanvasColumn.prototype.addControl = function (control) {
1240
+ control.column = this;
1241
+ this.controls.push(control);
1242
+ return this;
1243
+ };
1244
+ CanvasColumn.prototype.getControl = function (index) {
1245
+ return this.controls[index];
1246
+ };
1247
+ CanvasColumn.prototype.remove = function () {
1248
+ var _this = this;
1249
+ this.section.columns = this.section.columns.filter(function (column) { return column._memId !== _this._memId; });
1250
+ reindex(this.section.columns);
1251
+ };
1252
+ CanvasColumn.Default = {
1253
+ controlType: 0,
1254
+ displayMode: 2,
1255
+ emphasis: {},
1256
+ position: {
1257
+ layoutIndex: 1,
1258
+ sectionFactor: 12,
1259
+ sectionIndex: 1,
1260
+ zoneIndex: 1,
1261
+ },
1262
+ };
1263
+ return CanvasColumn;
1264
+ }());
1265
+ export { CanvasColumn };
1266
+ var ColumnControl = /** @class */ (function () {
1267
+ function ColumnControl(json) {
1268
+ this.json = json;
1269
+ }
1270
+ Object.defineProperty(ColumnControl.prototype, "id", {
1271
+ get: function () {
1272
+ return this.json.id;
1273
+ },
1274
+ enumerable: false,
1275
+ configurable: true
1276
+ });
1277
+ Object.defineProperty(ColumnControl.prototype, "data", {
1278
+ get: function () {
1279
+ return this.json;
1280
+ },
1281
+ enumerable: false,
1282
+ configurable: true
1283
+ });
1284
+ Object.defineProperty(ColumnControl.prototype, "column", {
1285
+ get: function () {
1286
+ return this._column;
1287
+ },
1288
+ set: function (value) {
1289
+ this._column = value;
1290
+ this.onColumnChange(this._column);
1291
+ },
1292
+ enumerable: false,
1293
+ configurable: true
1294
+ });
1295
+ ColumnControl.prototype.remove = function () {
1296
+ var _this = this;
1297
+ this.column.controls = this.column.controls.filter(function (control) { return control.id !== _this.id; });
1298
+ reindex(this.column.controls);
1299
+ };
1300
+ ColumnControl.prototype.setData = function (data) {
1301
+ this.json = data;
1302
+ };
1303
+ return ColumnControl;
1304
+ }());
1305
+ export { ColumnControl };
1306
+ var ClientsideText = /** @class */ (function (_super) {
1307
+ __extends(ClientsideText, _super);
1308
+ function ClientsideText(text, json) {
1309
+ if (json === void 0) { json = JSON.parse(JSON.stringify(ClientsideText.Default)); }
1310
+ var _this = this;
1311
+ if (stringIsNullOrEmpty(json.id)) {
1312
+ json.id = getGUID();
1313
+ json.anchorComponentId = json.id;
1314
+ }
1315
+ _this = _super.call(this, json) || this;
1316
+ _this.text = text;
1317
+ return _this;
1318
+ }
1319
+ Object.defineProperty(ClientsideText.prototype, "text", {
1320
+ get: function () {
1321
+ return this.data.innerHTML;
1322
+ },
1323
+ set: function (value) {
1324
+ this.data.innerHTML = value;
1325
+ },
1326
+ enumerable: false,
1327
+ configurable: true
1328
+ });
1329
+ Object.defineProperty(ClientsideText.prototype, "order", {
1330
+ get: function () {
1331
+ return this.data.position.controlIndex;
1332
+ },
1333
+ set: function (value) {
1334
+ this.data.position.controlIndex = value;
1335
+ },
1336
+ enumerable: false,
1337
+ configurable: true
1338
+ });
1339
+ ClientsideText.prototype.onColumnChange = function (col) {
1340
+ this.data.position.sectionFactor = col.factor;
1341
+ this.data.position.controlIndex = getNextOrder(col.controls);
1342
+ this.data.position.zoneIndex = col.data.position.zoneIndex;
1343
+ this.data.position.sectionIndex = col.order;
1344
+ this.data.position.layoutIndex = col.data.position.layoutIndex;
1345
+ };
1346
+ ClientsideText.Default = {
1347
+ addedFromPersistedData: false,
1348
+ anchorComponentId: "",
1349
+ controlType: 4,
1350
+ displayMode: 2,
1351
+ editorType: "CKEditor",
1352
+ emphasis: {},
1353
+ id: "",
1354
+ innerHTML: "",
1355
+ position: {
1356
+ controlIndex: 1,
1357
+ layoutIndex: 1,
1358
+ sectionFactor: 12,
1359
+ sectionIndex: 1,
1360
+ zoneIndex: 1,
1361
+ },
1362
+ };
1363
+ return ClientsideText;
1364
+ }(ColumnControl));
1365
+ export { ClientsideText };
1366
+ var ClientsideWebpart = /** @class */ (function (_super) {
1367
+ __extends(ClientsideWebpart, _super);
1368
+ function ClientsideWebpart(json) {
1369
+ if (json === void 0) { json = JSON.parse(JSON.stringify(ClientsideWebpart.Default)); }
1370
+ return _super.call(this, json) || this;
1371
+ }
1372
+ ClientsideWebpart.fromComponentDef = function (definition) {
1373
+ var part = new ClientsideWebpart();
1374
+ part.import(definition);
1375
+ return part;
1376
+ };
1377
+ Object.defineProperty(ClientsideWebpart.prototype, "title", {
1378
+ get: function () {
1379
+ return this.data.webPartData.title;
1380
+ },
1381
+ set: function (value) {
1382
+ this.data.webPartData.title = value;
1383
+ },
1384
+ enumerable: false,
1385
+ configurable: true
1386
+ });
1387
+ Object.defineProperty(ClientsideWebpart.prototype, "description", {
1388
+ get: function () {
1389
+ return this.data.webPartData.description;
1390
+ },
1391
+ set: function (value) {
1392
+ this.data.webPartData.description = value;
1393
+ },
1394
+ enumerable: false,
1395
+ configurable: true
1396
+ });
1397
+ Object.defineProperty(ClientsideWebpart.prototype, "order", {
1398
+ get: function () {
1399
+ return this.data.position.controlIndex;
1400
+ },
1401
+ set: function (value) {
1402
+ this.data.position.controlIndex = value;
1403
+ },
1404
+ enumerable: false,
1405
+ configurable: true
1406
+ });
1407
+ Object.defineProperty(ClientsideWebpart.prototype, "height", {
1408
+ get: function () {
1409
+ return this.data.reservedHeight;
1410
+ },
1411
+ set: function (value) {
1412
+ this.data.reservedHeight = value;
1413
+ },
1414
+ enumerable: false,
1415
+ configurable: true
1416
+ });
1417
+ Object.defineProperty(ClientsideWebpart.prototype, "width", {
1418
+ get: function () {
1419
+ return this.data.reservedWidth;
1420
+ },
1421
+ set: function (value) {
1422
+ this.data.reservedWidth = value;
1423
+ },
1424
+ enumerable: false,
1425
+ configurable: true
1426
+ });
1427
+ Object.defineProperty(ClientsideWebpart.prototype, "dataVersion", {
1428
+ get: function () {
1429
+ return this.data.webPartData.dataVersion;
1430
+ },
1431
+ set: function (value) {
1432
+ this.data.webPartData.dataVersion = value;
1433
+ },
1434
+ enumerable: false,
1435
+ configurable: true
1436
+ });
1437
+ ClientsideWebpart.prototype.setProperties = function (properties) {
1438
+ this.data.webPartData.properties = assign(this.data.webPartData.properties, properties);
1439
+ return this;
1440
+ };
1441
+ ClientsideWebpart.prototype.setServerProcessedContent = function (properties) {
1442
+ this.data.webPartData.serverProcessedContent = assign(this.data.webPartData.serverProcessedContent || {}, properties);
1443
+ return this;
1444
+ };
1445
+ ClientsideWebpart.prototype.getProperties = function () {
1446
+ return this.data.webPartData.properties;
1447
+ };
1448
+ ClientsideWebpart.prototype.getServerProcessedContent = function () {
1449
+ return this.data.webPartData.serverProcessedContent;
1450
+ };
1451
+ ClientsideWebpart.prototype.onColumnChange = function (col) {
1452
+ this.data.position.sectionFactor = col.factor;
1453
+ this.data.position.controlIndex = getNextOrder(col.controls);
1454
+ this.data.position.zoneIndex = col.data.position.zoneIndex;
1455
+ this.data.position.sectionIndex = col.data.position.sectionIndex;
1456
+ this.data.position.layoutIndex = col.data.position.layoutIndex;
1457
+ };
1458
+ ClientsideWebpart.prototype.import = function (component) {
1459
+ var id = getGUID();
1460
+ var componendId = component.Id.replace(/^\{|\}$/g, "").toLowerCase();
1461
+ var manifest = JSON.parse(component.Manifest);
1462
+ var preconfiguredEntries = manifest.preconfiguredEntries[0];
1463
+ this.setData(Object.assign({}, this.data, {
1464
+ id: id,
1465
+ webPartData: {
1466
+ dataVersion: "1.0",
1467
+ description: preconfiguredEntries.description.default,
1468
+ id: componendId,
1469
+ instanceId: id,
1470
+ properties: preconfiguredEntries.properties,
1471
+ title: preconfiguredEntries.title.default,
1472
+ },
1473
+ webPartId: componendId,
1474
+ }));
1475
+ };
1476
+ ClientsideWebpart.Default = {
1477
+ addedFromPersistedData: false,
1478
+ controlType: 3,
1479
+ displayMode: 2,
1480
+ emphasis: {},
1481
+ id: null,
1482
+ position: {
1483
+ controlIndex: 1,
1484
+ layoutIndex: 1,
1485
+ sectionFactor: 12,
1486
+ sectionIndex: 1,
1487
+ zoneIndex: 1,
1488
+ },
1489
+ reservedHeight: 500,
1490
+ reservedWidth: 500,
1491
+ webPartData: null,
1492
+ webPartId: null,
1493
+ };
1494
+ return ClientsideWebpart;
1495
+ }(ColumnControl));
1496
+ export { ClientsideWebpart };
1486
1497
  //# sourceMappingURL=types.js.map