@mediafly/js-ui 53.1.0-1 → 53.1.1-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.
- package/CHANGELOG.md +4 -0
- package/lib/src/components/rich-text/rich-text.component.d.ts +1 -7
- package/lib/src/components/rich-text/rich-text.component.js +3 -29
- package/lib/src/components/rich-text/rich-text.component.js.map +1 -1
- package/lib/src/components/rich-text/rich-text.service.d.ts +23 -4
- package/lib/src/components/rich-text/rich-text.service.js +74 -15
- package/lib/src/components/rich-text/rich-text.service.js.map +1 -1
- package/lib/tsconfig.deploy.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/rich-text/rich-text.component.less +2 -2
- package/src/components/rich-text/rich-text.component.ts +3 -33
- package/src/components/rich-text/rich-text.service.ts +81 -13
- package/src/index.spec.js +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -354,8 +354,8 @@ export default class RichTextService {
|
|
|
354
354
|
|
|
355
355
|
/**
|
|
356
356
|
* Quill only styles the text runs inside a list item, so a bullet or number would take the container's style,
|
|
357
|
-
* not its text's. Put the
|
|
358
|
-
* The item's em-based indent then also scales with its own marker.
|
|
357
|
+
* not its text's. Put the item's marker style (see `getListItemMarkerStyle`) on the <li> itself, so its marker
|
|
358
|
+
* inherits it. The item's em-based indent then also scales with its own marker.
|
|
359
359
|
* These styles are derived from the text, so `removeListMarkerStyles` can drop them again before editing.
|
|
360
360
|
*/
|
|
361
361
|
addListMarkerStyles(html: string): string {
|
|
@@ -415,11 +415,59 @@ export default class RichTextService {
|
|
|
415
415
|
}
|
|
416
416
|
|
|
417
417
|
/**
|
|
418
|
-
*
|
|
419
|
-
*
|
|
418
|
+
* In the editor, put each list item's marker style on its <li> as CSS variables (see rich-text.component.less).
|
|
419
|
+
* Quill has no attributors for these, so they never become part of the content, its history, or a text-change.
|
|
420
|
+
* Values are only written when they change, to avoid needless mutations for Quill to process.
|
|
421
|
+
*/
|
|
422
|
+
syncListMarkerVariables(root: Element): void {
|
|
423
|
+
|
|
424
|
+
root.querySelectorAll<HTMLElement>('li').forEach((item) => {
|
|
425
|
+
const style = this.getListItemMarkerStyle(item)
|
|
426
|
+
|
|
427
|
+
// A list that doesn't have any text yet keeps the styles Quill copied when it split the line.
|
|
428
|
+
if (!style) {
|
|
429
|
+
return
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
for (const property of LIST_MARKER_PROPERTIES) {
|
|
433
|
+
const name = `${LIST_MARKER_VARIABLE_PREFIX}${property}`
|
|
434
|
+
const value = style[property] ?? ''
|
|
435
|
+
if (item.style.getPropertyValue(name) === value) {
|
|
436
|
+
continue
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (value) {
|
|
440
|
+
item.style.setProperty(name, value)
|
|
441
|
+
} else {
|
|
442
|
+
item.style.removeProperty(name)
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
})
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* The style a list item's bullet or number should copy: the inline styles of the item's first character.
|
|
450
|
+
* Any text in the item with no inline style of its own inherits these from the <li> too.
|
|
451
|
+
* An item with no text yet copies the nearest earlier item in its list, as the editor does when a new item is
|
|
452
|
+
* started. Undefined when no item that far has any text.
|
|
420
453
|
*/
|
|
421
454
|
getListItemMarkerStyle(item: Element): ListMarkerStyle | undefined {
|
|
422
455
|
|
|
456
|
+
let current: Element | null = item
|
|
457
|
+
while (current) {
|
|
458
|
+
const style = current.tagName === 'LI' ? this.getOwnListItemMarkerStyle(current) : undefined
|
|
459
|
+
if (style) {
|
|
460
|
+
return style
|
|
461
|
+
}
|
|
462
|
+
current = current.previousElementSibling
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
return undefined
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/** The marker style from the item's own first character, or undefined if it has no text. */
|
|
469
|
+
private getOwnListItemMarkerStyle(item: Element): ListMarkerStyle | undefined {
|
|
470
|
+
|
|
423
471
|
const firstText = this.findFirstText(item)
|
|
424
472
|
if (!firstText) {
|
|
425
473
|
return undefined
|
|
@@ -427,28 +475,29 @@ export default class RichTextService {
|
|
|
427
475
|
|
|
428
476
|
const style: ListMarkerStyle = {}
|
|
429
477
|
for (const property of LIST_MARKER_PROPERTIES) {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
style[property] = value
|
|
434
|
-
break
|
|
435
|
-
}
|
|
478
|
+
const value = this.getInlineStyle(firstText, item, property)
|
|
479
|
+
if (value) {
|
|
480
|
+
style[property] = value
|
|
436
481
|
}
|
|
437
482
|
}
|
|
438
483
|
|
|
439
484
|
return style
|
|
440
485
|
}
|
|
441
486
|
|
|
487
|
+
/**
|
|
488
|
+
* The item's own first text, skipping Quill's marker element, nested lists, and whitespace between tags.
|
|
489
|
+
* (`trim` also removes the zero width no-break spaces in Quill's cursor.)
|
|
490
|
+
*/
|
|
442
491
|
private findFirstText(item: Element): Text | undefined {
|
|
443
492
|
|
|
444
493
|
const walker = item.ownerDocument.createTreeWalker(item, NodeFilter.SHOW_TEXT)
|
|
445
494
|
|
|
446
495
|
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
447
|
-
|
|
448
|
-
if (
|
|
496
|
+
const parent = node.parentElement
|
|
497
|
+
if (!parent || parent.closest('.ql-ui') || parent.closest('li') !== item) {
|
|
449
498
|
continue
|
|
450
499
|
}
|
|
451
|
-
if (node.textContent?.
|
|
500
|
+
if (node.textContent?.trim()) {
|
|
452
501
|
return node as Text
|
|
453
502
|
}
|
|
454
503
|
}
|
|
@@ -456,6 +505,25 @@ export default class RichTextService {
|
|
|
456
505
|
return undefined
|
|
457
506
|
}
|
|
458
507
|
|
|
508
|
+
/**
|
|
509
|
+
* The nearest inline value of a style around some text, not counting the list item itself.
|
|
510
|
+
* Quill's bold format (Ctrl+B) is a <strong> with no inline font-weight, so that counts as 700.
|
|
511
|
+
*/
|
|
512
|
+
private getInlineStyle(text: Text, item: Element, property: string): string | undefined {
|
|
513
|
+
|
|
514
|
+
for (let element = text.parentElement; element && element !== item; element = element.parentElement) {
|
|
515
|
+
const value = element.style?.getPropertyValue(property)
|
|
516
|
+
if (value) {
|
|
517
|
+
return value
|
|
518
|
+
}
|
|
519
|
+
if (property === 'font-weight' && (element.tagName === 'STRONG' || element.tagName === 'B')) {
|
|
520
|
+
return '700'
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
return undefined
|
|
525
|
+
}
|
|
526
|
+
|
|
459
527
|
private clearListMarkerStyles(item: HTMLElement): void {
|
|
460
528
|
|
|
461
529
|
for (const property of Array.from(item.style)) {
|
package/src/index.spec.js
CHANGED
|
@@ -29,6 +29,7 @@ import './components/on-media-error/tests/on-media-error.spec'
|
|
|
29
29
|
import './components/paging/tests/paging-factory.spec'
|
|
30
30
|
import './components/progress-bar/tests/progress-bar.spec'
|
|
31
31
|
import './components/progress-circle/tests/progress-circle.spec'
|
|
32
|
+
import './components/rich-text/tests/rich-text.list-markers.quill.spec'
|
|
32
33
|
import './components/rich-text/tests/rich-text.service.list-markers.spec'
|
|
33
34
|
import './components/rich-text/tests/rich-text.service.spec'
|
|
34
35
|
import './components/response-handlers/tests/error-response.service.spec'
|