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

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,8 +4,8 @@
4
4
  data-myft-ui="saved"
5
5
  action="/myft/save/{{contentId}}"
6
6
  data-js-action="/__myft/api/core/saved/content/{{contentId}}?method=put"
7
- {{#if @root.flags.manageArticleLists}}data-myft-ui-save-new="manageArticleLists"{{/if}}
8
- {{#if @root.flags.manageArticleLists}}data-myft-ui-save-new-config="{{#if @root.flags.myftListPublicPrivateToggle}}showPublicToggle{{/if}}"{{/if}}>
7
+ {{#if flags.manageArticleLists}}data-myft-ui-save-new="manageArticleLists"{{/if}}
8
+ {{#if flags.manageArticleLists}}data-myft-ui-save-new-config="{{#if flags.myftListPublicPrivateToggle}}showPublicToggle{{/if}}"{{/if}}>
9
9
  {{> n-myft-ui/components/csrf-token/input}}
10
10
  <div
11
11
  class="n-myft-ui__announcement o-normalise-visually-hidden"
package/myft/main.scss CHANGED
@@ -239,13 +239,12 @@ $spacing-unit: 20px;
239
239
  color: oColorsByName('black-80');
240
240
 
241
241
  padding-left: 0;
242
- margin-left: -8px;
243
242
 
244
243
  &:hover {
245
244
  text-decoration: underline;
246
245
  }
247
246
 
248
- &::before {
247
+ &-collapsed::before {
249
248
  content: '';
250
249
  @include oIconsContent(
251
250
  'plus',
@@ -255,6 +254,7 @@ $spacing-unit: 20px;
255
254
  );
256
255
  vertical-align: middle;
257
256
  margin-top: -2px;
257
+ margin-left: -8px;
258
258
  }
259
259
  }
260
260
 
@@ -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();
273
+ }
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);
258
280
  }
259
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) {
@@ -275,7 +297,7 @@ function ContentElement (hasDescription, onClick) {
275
297
 
276
298
  const content = `
277
299
  <div class="myft-ui-create-list-variant-footer">
278
- <button class="myft-ui-create-list-variant-add" data-trackable="add-to-new-list" text="add to new list">Add to a new list</button>
300
+ <button class="myft-ui-create-list-variant-add myft-ui-create-list-variant-add-collapsed" data-trackable="add-to-new-list" text="add to new list">Add to a new list</button>
279
301
  ${hasDescription ? `
280
302
  ${description}
281
303
  ` : ''}
@@ -299,7 +321,13 @@ function ContentElement (hasDescription, onClick) {
299
321
  }
300
322
 
301
323
  function restoreFormHandler () {
302
- return contentElement.addEventListener('click', onClick, { once: true });
324
+ contentElement.querySelector('.myft-ui-create-list-variant-add').classList.add('myft-ui-create-list-variant-add-collapsed');
325
+ return contentElement.addEventListener('click', clickHandler, { once: true });
326
+ }
327
+
328
+ function clickHandler (event) {
329
+ contentElement.querySelector('.myft-ui-create-list-variant-add').classList.remove('myft-ui-create-list-variant-add-collapsed');
330
+ onClick(event);
303
331
  }
304
332
 
305
333
  return [contentElement, removeDescription, attachDescription, restoreFormHandler];
@@ -332,9 +360,21 @@ function ListsElement (lists, addToList, removeFromList) {
332
360
 
333
361
  const listsElementContainer = listsElement.querySelector('.myft-ui-create-list-variant-lists-container');
334
362
 
335
- lists.map(list => listsElementContainer.insertAdjacentElement('beforeend', listCheckboxElement(list)));
363
+ function refresh () {
364
+ listsElementContainer.replaceChildren(...lists.map(list => listCheckboxElement(list)));
365
+ }
366
+
367
+ function hide () {
368
+ listsElement.style.display = 'none';
369
+ }
370
+
371
+ function show () {
372
+ listsElement.style.display = 'flex';
373
+ }
374
+
375
+ refresh();
336
376
 
337
- return listsElement;
377
+ return [listsElement, refresh, hide, show];
338
378
  }
339
379
 
340
380
  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.5",
4
4
  "description": "Client side component for interaction with myft",
5
5
  "main": "server.js",
6
6
  "scripts": {