@financial-times/n-myft-ui 28.2.2 → 28.2.3

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.
@@ -16,8 +16,7 @@ export default async function openSaveArticleToListVariant (contentId, options =
16
16
 
17
17
  function createList (newList, cb) {
18
18
  if(!newList || !newList.name) {
19
- if (!lists.length) attachDescription();
20
- return restoreFormHandler();
19
+ return restoreContent();
21
20
  }
22
21
 
23
22
  myFtClient.add('user', null, 'created', 'list', uuid(), { name: newList.name, token: csrfToken })
@@ -25,18 +24,13 @@ export default async function openSaveArticleToListVariant (contentId, options =
25
24
  myFtClient.add('list', detail.subject, 'contained', 'content', contentId, { token: csrfToken }).then((data) => {
26
25
  const createdList = { name: newList.name, uuid: data.actorId, checked: true, isShareable: !!newList.isShareable };
27
26
  lists.unshift(createdList);
28
- const listElement = ListsElement(lists, addToList, removeFromList);
29
- const overlayContent = document.querySelector('.o-overlay__content');
30
- overlayContent.insertAdjacentElement('afterbegin', listElement);
31
27
  const announceListContainer = document.querySelector('.myft-ui-create-list-variant-announcement');
32
28
  announceListContainer.textContent = `${newList.name} created`;
33
- restoreFormHandler();
34
29
  cb(contentId, createdList);
35
30
  });
36
31
  })
37
32
  .catch(() => {
38
- if (!lists.length) attachDescription();
39
- return restoreFormHandler();
33
+ return restoreContent();
40
34
  });
41
35
  }
42
36
 
@@ -62,6 +56,13 @@ export default async function openSaveArticleToListVariant (contentId, options =
62
56
  });
63
57
  }
64
58
 
59
+ function restoreContent () {
60
+ if (!lists.length) attachDescription();
61
+ refreshListElement();
62
+ showListElement();
63
+ return restoreFormHandler();
64
+ }
65
+
65
66
  if (!haveLoadedLists) {
66
67
  lists = await getLists(contentId);
67
68
  haveLoadedLists = true;
@@ -75,6 +76,7 @@ export default async function openSaveArticleToListVariant (contentId, options =
75
76
 
76
77
  const headingElement = HeadingElement();
77
78
  let [contentElement, removeDescription, attachDescription, restoreFormHandler] = ContentElement(!lists.length, openFormHandler);
79
+ const [listElement, refreshListElement, hideListElement, showListElement] = ListsElement(lists, addToList, removeFromList);
78
80
 
79
81
  createListOverlay = new Overlay(name, {
80
82
  html: contentElement,
@@ -95,8 +97,20 @@ export default async function openSaveArticleToListVariant (contentId, options =
95
97
  }
96
98
  }
97
99
 
100
+ function onFormCancel () {
101
+ showListElement();
102
+ restoreFormHandler();
103
+ }
104
+
105
+ function onFormListCreated () {
106
+ refreshListElement();
107
+ showListElement();
108
+ restoreFormHandler();
109
+ }
110
+
98
111
  function openFormHandler () {
99
- const formElement = FormElement(createList, showPublicToggle, restoreFormHandler, attachDescription);
112
+ hideListElement();
113
+ const formElement = FormElement(createList, showPublicToggle, attachDescription, onFormListCreated, onFormCancel);
100
114
  const overlayContent = document.querySelector('.o-overlay__content');
101
115
  removeDescription();
102
116
  overlayContent.insertAdjacentElement('beforeend', formElement);
@@ -110,7 +124,6 @@ export default async function openSaveArticleToListVariant (contentId, options =
110
124
 
111
125
  createListOverlay.wrapper.addEventListener('oOverlay.ready', (data) => {
112
126
  if (lists.length) {
113
- const listElement = ListsElement(lists, addToList, removeFromList);
114
127
  const overlayContent = document.querySelector('.o-overlay__content');
115
128
  overlayContent.insertAdjacentElement('afterbegin', listElement);
116
129
  }
@@ -183,7 +196,7 @@ function getResizeHandler (target) {
183
196
  };
184
197
  }
185
198
 
186
- function FormElement (createList, showPublicToggle, restoreFormHandler, attachDescription) {
199
+ function FormElement (createList, showPublicToggle, attachDescription, onListCreated, onCancel) {
187
200
  const formString = `
188
201
  <form class="myft-ui-create-list-variant-form">
189
202
  <label class="myft-ui-create-list-variant-form-name o-forms-field">
@@ -245,6 +258,8 @@ function FormElement (createList, showPublicToggle, restoreFormHandler, attachDe
245
258
  createListOverlay.close();
246
259
  showMessageOverlay();
247
260
  }
261
+
262
+ onListCreated();
248
263
  }));
249
264
  formElement.remove();
250
265
  }
@@ -254,20 +269,27 @@ function FormElement (createList, showPublicToggle, restoreFormHandler, attachDe
254
269
  event.stopPropagation();
255
270
  formElement.remove();
256
271
  if (!lists.length) attachDescription();
257
- restoreFormHandler();
272
+ onCancel();
258
273
  }
259
274
 
275
+ formElement.querySelector('button[type="submit"]').addEventListener('click', handleSubmit);
276
+ formElement.querySelector('button[type="button"]').addEventListener('click', handleCancelClick);
277
+
278
+ if (showPublicToggle) {
279
+ addPublicToggleListener(formElement);
280
+ }
281
+
282
+ return formElement;
283
+ }
284
+
285
+ function addPublicToggleListener (formElement) {
260
286
  function onPublicToggleClick (event) {
261
287
  event.target.setAttribute('data-trackable', event.target.checked ? 'private-link' : 'public-link');
262
288
  event.target.setAttribute('text', event.target.checked ? 'private' : 'public');
263
289
  triggerPublicToggleEvent(event.target.checked);
264
290
  }
265
291
 
266
- formElement.querySelector('button[type="submit"]').addEventListener('click', handleSubmit);
267
- formElement.querySelector('button[type="button"]').addEventListener('click', handleCancelClick);
268
292
  formElement.querySelector('input[name="is-shareable"]').addEventListener('click', onPublicToggleClick);
269
-
270
- return formElement;
271
293
  }
272
294
 
273
295
  function ContentElement (hasDescription, onClick) {
@@ -332,9 +354,21 @@ function ListsElement (lists, addToList, removeFromList) {
332
354
 
333
355
  const listsElementContainer = listsElement.querySelector('.myft-ui-create-list-variant-lists-container');
334
356
 
335
- lists.map(list => listsElementContainer.insertAdjacentElement('beforeend', listCheckboxElement(list)));
357
+ function refresh () {
358
+ listsElementContainer.replaceChildren(...lists.map(list => listCheckboxElement(list)));
359
+ }
360
+
361
+ function hide () {
362
+ listsElement.style.display = 'none';
363
+ }
364
+
365
+ function show () {
366
+ listsElement.style.display = 'flex';
367
+ }
368
+
369
+ refresh();
336
370
 
337
- return listsElement;
371
+ return [listsElement, refresh, hide, show];
338
372
  }
339
373
 
340
374
  function ListCheckboxElement (addToList, removeFromList) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/n-myft-ui",
3
- "version": "28.2.2",
3
+ "version": "28.2.3",
4
4
  "description": "Client side component for interaction with myft",
5
5
  "main": "server.js",
6
6
  "scripts": {