@mediafly/js-ui 53.1.0-0 → 53.1.0-1

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.
@@ -19,22 +19,16 @@ export const LIST_MARKER_PROPERTIES = ['color', 'font-family', 'font-size', 'fon
19
19
  /** In the editor, marker styles go on the <li> as CSS variables, because Quill would read real ones as content formats. */
20
20
  export const LIST_MARKER_VARIABLE_PREFIX = '--mfly-list-marker-'
21
21
 
22
- /** Quill's list item indent: 1.5em, plus 3em for each `ql-indent-N` level. */
23
- const LIST_ITEM_INDENT_EMS = 1.5
24
- const LIST_INDENT_LEVEL_EMS = 3
22
+ /**
23
+ * Styles removed from list items before editing. As well as the marker styles, this includes the shared `padding-left`
24
+ * that js-ui 53.1.0-0 saved, which would otherwise override the em-based indent.
25
+ */
26
+ const LIST_ITEM_STYLES_TO_CLEAR = [...LIST_MARKER_PROPERTIES, 'padding-left']
25
27
 
26
28
  const LIST_ITEM_TAG_REGEX = /<li[\s>]/i
27
29
 
28
30
  export type ListMarkerStyle = Partial<Record<typeof LIST_MARKER_PROPERTIES[number], string>>
29
31
 
30
- export interface ListItemMarker {
31
- item: HTMLElement
32
- /** Undefined when the item has no text yet */
33
- style?: ListMarkerStyle
34
- /** Undefined when no item in the list has a font size in px */
35
- paddingLeft?: string
36
- }
37
-
38
32
  @Injectable('richTextService')
39
33
  export default class RichTextService {
40
34
 
@@ -360,8 +354,8 @@ export default class RichTextService {
360
354
 
361
355
  /**
362
356
  * Quill only styles the text runs inside a list item, so a bullet or number would take the container's style,
363
- * not its text's. Put the style of each item's first character on the <li> itself, so its marker inherits it,
364
- * and give every item in a list the same indent, with room for the list's largest marker.
357
+ * not its text's. Put the style of each item's first character on the <li> itself, so its marker inherits it.
358
+ * The item's em-based indent then also scales with its own marker.
365
359
  * These styles are derived from the text, so `removeListMarkerStyles` can drop them again before editing.
366
360
  */
367
361
  addListMarkerStyles(html: string): string {
@@ -373,23 +367,19 @@ export default class RichTextService {
373
367
  const template = document.createElement('template')
374
368
  template.innerHTML = html
375
369
 
376
- template.content.querySelectorAll('ol, ul').forEach((list) => {
377
- for (const { item, style, paddingLeft } of this.getListMarkerStyles(list)) {
378
- this.clearListMarkerStyles(item)
370
+ template.content.querySelectorAll('li').forEach((item) => {
371
+ const style = this.getListItemMarkerStyle(item)
372
+ this.clearListMarkerStyles(item)
379
373
 
380
- for (const property of LIST_MARKER_PROPERTIES) {
381
- const value = style?.[property]
382
- if (value) {
383
- item.style.setProperty(property, value)
384
- }
385
- }
386
- if (paddingLeft) {
387
- item.style.setProperty('padding-left', paddingLeft)
374
+ for (const property of LIST_MARKER_PROPERTIES) {
375
+ const value = style?.[property]
376
+ if (value) {
377
+ item.style.setProperty(property, value)
388
378
  }
379
+ }
389
380
 
390
- if (!item.getAttribute('style')) {
391
- item.removeAttribute('style')
392
- }
381
+ if (!item.getAttribute('style')) {
382
+ item.removeAttribute('style')
393
383
  }
394
384
  })
395
385
 
@@ -424,35 +414,6 @@ export default class RichTextService {
424
414
  })
425
415
  }
426
416
 
427
- /**
428
- * For each item in a list (<ol> or <ul>), work out the style its marker should copy, and its indent.
429
- * Every item gets the same indent, sized for the largest marker in the list.
430
- */
431
- getListMarkerStyles(list: Element): ListItemMarker[] {
432
-
433
- const markers: ListItemMarker[] = Array.from(list.children)
434
- .filter((child): child is HTMLElement => child.tagName === 'LI')
435
- .map((item) => ({ item, style: this.getListItemMarkerStyle(item) }))
436
-
437
- const sizes = markers
438
- .map(({ style }) => parseFloat(style?.['font-size']?.match(/^\s*([\d.]+)px\s*$/)?.[1] ?? ''))
439
- .filter((size) => size > 0)
440
-
441
- if (sizes.length === 0) {
442
- return markers
443
- }
444
-
445
- const largestSize = Math.max(...sizes)
446
-
447
- for (const marker of markers) {
448
- const indentLevel = Number(marker.item.className.match(/(?:^|\s)ql-indent-(\d+)(?:\s|$)/)?.[1] ?? 0)
449
- const paddingLeft = (LIST_ITEM_INDENT_EMS + (LIST_INDENT_LEVEL_EMS * indentLevel)) * largestSize
450
- marker.paddingLeft = `${Math.round(paddingLeft * 100) / 100}px`
451
- }
452
-
453
- return markers
454
- }
455
-
456
417
  /**
457
418
  * The styles of a list item's first character, which its bullet or number should copy.
458
419
  * Undefined when the item has no text yet.
@@ -502,7 +463,7 @@ export default class RichTextService {
502
463
  item.style.removeProperty(property)
503
464
  }
504
465
  }
505
- for (const property of [...LIST_MARKER_PROPERTIES, 'padding-left']) {
466
+ for (const property of LIST_ITEM_STYLES_TO_CLEAR) {
506
467
  item.style.removeProperty(property)
507
468
  }
508
469
  }