MCPcopy
hub / github.com/marktext/marktext / ParagraphFrontButton

Class ParagraphFrontButton

packages/muya/src/ui/paragraphFrontButton/index.ts:51–451  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51export class ParagraphFrontButton {
52 public name: string = 'mu-front-button';
53 public resizeObserver: ResizeObserver | null = null;
54 private _options: IBaseOptions;
55 private _block: Parent | null = null;
56 private _oldVNode: VNode | null = null;
57 private _status: boolean = false;
58 private _floatBox: HTMLDivElement = document.createElement('div');
59 private _container: HTMLDivElement = document.createElement('div');
60 private _iconWrapper: HTMLDivElement = document.createElement('div');
61 private _cleanup: (() => void) | null = null;
62 private _dragTimer: ReturnType<typeof setTimeout> | null = null;
63 private _dragInfo: {
64 block: Parent;
65 target?: Parent | null;
66 position?: 'down' | 'up' | null;
67 } | null = null;
68
69 private _ghost: HTMLDivElement | null = null;
70 private _shadow: HTMLDivElement | null = null;
71 private _disableListen: boolean = false;
72 private _dragEvents: string[] = [];
73
74 constructor(public muya: Muya, options = {}) {
75 this._options = Object.assign({}, defaultOptions(), options);
76 this.init();
77 this.listen();
78 }
79
80 init() {
81 const { _floatBox: floatBox, _container: container, _iconWrapper: iconWrapper } = this;
82 // Use to remember which float container is shown.
83 container.classList.add(this.name);
84 container.appendChild(iconWrapper);
85 floatBox.classList.add('mu-front-button-wrapper');
86 floatBox.appendChild(container);
87 document.body.appendChild(floatBox);
88
89 // Since the size of the container is not fixed and changes according to the change of content,
90 // the floatBox needs to set the size according to the container size
91 const resizeObserver = (this.resizeObserver = new ResizeObserver(() => {
92 // Use requestAnimationFrame to avoid "ResizeObserver loop completed" warning
93 requestAnimationFrame(() => {
94 const { offsetWidth, offsetHeight } = container;
95
96 Object.assign(floatBox.style, {
97 width: `${offsetWidth}px`,
98 height: `${offsetHeight}px`,
99 });
100
101 // Position will be updated by autoUpdate
102 });
103 }));
104
105 resizeObserver.observe(container);
106 }
107
108 listen() {

Callers

nothing calls this directly

Calls 15

moveShadowMethod · 0.95
createStyledGhostMethod · 0.95
destroyShadowMethod · 0.95
createStyledShadowMethod · 0.95
hideMethod · 0.95
isMouseEventFunction · 0.90
verticalPositionInRectFunction · 0.90
throttleFunction · 0.90
startDragMethod · 0.80
insertIntoMethod · 0.80
isInBlockMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected