仲裁视频会议H5

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import Attributor from '../../attributor/attributor';
  2. import AttributorStore from '../../attributor/store';
  3. import { Blot, Parent, Formattable } from './blot';
  4. import ContainerBlot from './container';
  5. import ShadowBlot from './shadow';
  6. import * as Registry from '../../registry';
  7. class FormatBlot extends ContainerBlot implements Formattable {
  8. protected attributes: AttributorStore;
  9. static formats(domNode: HTMLElement): any {
  10. if (typeof this.tagName === 'string') {
  11. return true;
  12. } else if (Array.isArray(this.tagName)) {
  13. return domNode.tagName.toLowerCase();
  14. }
  15. return undefined;
  16. }
  17. constructor(domNode: Node) {
  18. super(domNode);
  19. this.attributes = new AttributorStore(this.domNode);
  20. }
  21. format(name: string, value: any): void {
  22. let format = Registry.query(name);
  23. if (format instanceof Attributor) {
  24. this.attributes.attribute(format, value);
  25. } else if (value) {
  26. if (format != null && (name !== this.statics.blotName || this.formats()[name] !== value)) {
  27. this.replaceWith(name, value);
  28. }
  29. }
  30. }
  31. formats(): { [index: string]: any } {
  32. let formats = this.attributes.values();
  33. let format = this.statics.formats(this.domNode);
  34. if (format != null) {
  35. formats[this.statics.blotName] = format;
  36. }
  37. return formats;
  38. }
  39. replaceWith(name: string | Blot, value?: any): Blot {
  40. let replacement = <FormatBlot>super.replaceWith(name, value);
  41. this.attributes.copy(replacement);
  42. return replacement;
  43. }
  44. update(mutations: MutationRecord[], context: { [key: string]: any }): void {
  45. super.update(mutations, context);
  46. if (
  47. mutations.some(mutation => {
  48. return mutation.target === this.domNode && mutation.type === 'attributes';
  49. })
  50. ) {
  51. this.attributes.build();
  52. }
  53. }
  54. wrap(name: string | Parent, value?: any): Parent {
  55. let wrapper = super.wrap(name, value);
  56. if (wrapper instanceof FormatBlot && wrapper.statics.scope === this.statics.scope) {
  57. this.attributes.move(wrapper);
  58. }
  59. return wrapper;
  60. }
  61. }
  62. export default FormatBlot;