quill-toolbar-tip 0.1.0 → 1.0.0-beta.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.
- package/LICENSE +21 -21
- package/README.md +29 -14
- package/dist/index.d.ts +47 -32
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +3 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/toolbar-tip.umd.js +3 -0
- package/package.json +61 -55
- package/src/constants/tip-text.ts +66 -50
- package/src/index.ts +31 -21
- package/src/supports/index.ts +1 -0
- package/src/supports/quill-i18n.ts +56 -0
- package/src/utils/components.ts +15 -15
- package/src/utils/handler-utils.ts +2 -2
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 zzxming
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 zzxming
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Quill Toolbar Tip
|
|
2
2
|
|
|
3
|
-
[online demo](https://
|
|
3
|
+
[online demo](https://opentiny.github.io/quill-toolbar-tip/)
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
|
-
```
|
|
7
|
+
```sh
|
|
8
8
|
npm install quill-toolbar-tip
|
|
9
9
|
```
|
|
10
10
|
|
|
@@ -38,7 +38,7 @@ const quill = new Quill('#editor', {
|
|
|
38
38
|
});
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
Or you can add the text in `tipTextMap` to display in the tooltip. The keys
|
|
41
|
+
Or you can add the text in `tipTextMap` to display in the tooltip. The keys match the toolbar format name.
|
|
42
42
|
|
|
43
43
|
```ts
|
|
44
44
|
import QuillToolbarTip from 'quill-toolbar-tip';
|
|
@@ -79,29 +79,44 @@ const quill = new Quill('#editor', {
|
|
|
79
79
|
});
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
## Configuration Structure
|
|
83
|
+
|
|
84
|
+
For toolbar formats with multiple values (like pickers and dropdowns), you can use the `values` object to map each value to its tooltip text:
|
|
83
85
|
|
|
84
86
|
```ts
|
|
85
87
|
const QuillToolbarTipOption = {
|
|
86
88
|
tipTextMap: {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
list: {
|
|
90
|
+
values: {
|
|
91
|
+
ordered: 'Ordered List',
|
|
92
|
+
bullet: 'Unordered List',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
align: {
|
|
96
|
+
values: {
|
|
97
|
+
'': 'Left aligned',
|
|
98
|
+
'center': 'Center aligned',
|
|
99
|
+
'right': 'Right aligned',
|
|
100
|
+
'justify': 'Justify aligned',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
89
103
|
}
|
|
90
104
|
};
|
|
91
105
|
```
|
|
92
106
|
|
|
93
|
-
You
|
|
107
|
+
You can also use the `onShow` function to dynamically calculate the tooltip text. When both `values` and `onShow` are provided, `onShow` takes priority:
|
|
94
108
|
|
|
95
109
|
```ts
|
|
96
110
|
const QuillToolbarTipOption = {
|
|
97
111
|
tipTextMap: {
|
|
98
112
|
script: {
|
|
113
|
+
values: {
|
|
114
|
+
sub: 'Subscript',
|
|
115
|
+
super: 'Superscript',
|
|
116
|
+
},
|
|
117
|
+
// onShow takes priority over values
|
|
99
118
|
onShow(target, value) {
|
|
100
|
-
|
|
101
|
-
sub: 'Subscript',
|
|
102
|
-
super: 'Superscript',
|
|
103
|
-
};
|
|
104
|
-
return text[value] || null;
|
|
119
|
+
return `Script: ${value}`;
|
|
105
120
|
},
|
|
106
121
|
},
|
|
107
122
|
}
|
|
@@ -115,7 +130,7 @@ const QuillToolbarTipOption = {
|
|
|
115
130
|
| defaultTooltipOptions | `Partial<TooltipOptions>` | Default tooltip options. |
|
|
116
131
|
| tipTextMap | `Record<string, Partial<TooltipItem> \| string>` | Tooltip text map. You can also set a object that will be use in the tooltip. The configuration of tooltip options is shown below |
|
|
117
132
|
|
|
118
|
-
###
|
|
133
|
+
### Tooltip Options
|
|
119
134
|
|
|
120
135
|
| Option | Description |
|
|
121
136
|
| ------------ | ------------------------------------------------------------------------------------------ |
|
package/dist/index.d.ts
CHANGED
|
@@ -1,45 +1,60 @@
|
|
|
1
|
-
import Quill from
|
|
2
|
-
import Toolbar from
|
|
1
|
+
import Quill from "quill";
|
|
2
|
+
import Toolbar from "quill/modules/toolbar";
|
|
3
3
|
|
|
4
|
+
//#region src/utils/components.d.ts
|
|
4
5
|
type Placement = 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'right' | 'right-start' | 'right-end' | 'left' | 'left-start' | 'left-end';
|
|
5
6
|
interface TooltipOptions {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
direction: Placement;
|
|
8
|
+
msg: string;
|
|
9
|
+
delay: number;
|
|
10
|
+
content: HTMLElement;
|
|
11
|
+
className: string | string[];
|
|
12
|
+
tipHoverable: boolean;
|
|
13
|
+
onShow: (target: HTMLElement) => string | HTMLElement | undefined | null;
|
|
14
|
+
appendTo: HTMLElement;
|
|
14
15
|
}
|
|
15
16
|
interface TooltipInstance {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
instance: HTMLElement;
|
|
18
|
+
destroy: () => void;
|
|
19
|
+
hide: () => void;
|
|
20
|
+
show: () => void;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/constants/tip-text.d.ts
|
|
22
24
|
declare const defaultToolbarTip: Record<string, QuillToolbarTipOptions['tipTextMap']>;
|
|
23
|
-
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/supports/quill-i18n.d.ts
|
|
27
|
+
declare function createI18nToolbarTipMap(options?: {
|
|
28
|
+
prefix?: string;
|
|
29
|
+
formats?: {
|
|
30
|
+
simple?: string[];
|
|
31
|
+
withValues?: Record<string, string[]>;
|
|
32
|
+
};
|
|
33
|
+
i18nModuleName?: string;
|
|
34
|
+
}): Record<string, string | Partial<TooltipItem>>;
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/index.d.ts
|
|
24
37
|
interface TooltipItem extends Omit<TooltipOptions, 'onShow'> {
|
|
25
|
-
|
|
38
|
+
values?: Record<string, string>;
|
|
39
|
+
onShow?: (this: Quill, target: HTMLElement, value: string, toolControl: HTMLButtonElement | HTMLSelectElement) => ReturnType<TooltipOptions['onShow']>;
|
|
26
40
|
}
|
|
27
41
|
interface QuillToolbarTipOptions {
|
|
28
|
-
|
|
29
|
-
|
|
42
|
+
tipTextMap: Record<string, Partial<TooltipItem> | string>;
|
|
43
|
+
defaultTooltipOptions: Partial<TooltipOptions>;
|
|
30
44
|
}
|
|
31
45
|
declare class QuillToolbarTip {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
quill: Quill;
|
|
47
|
+
static moduleName: string;
|
|
48
|
+
options: QuillToolbarTipOptions;
|
|
49
|
+
toolbar: Toolbar;
|
|
50
|
+
toolbarTips: [string, TooltipInstance][];
|
|
51
|
+
constructor(quill: Quill, options: Partial<QuillToolbarTipOptions>);
|
|
52
|
+
resolveOptions(options: Partial<QuillToolbarTipOptions>): QuillToolbarTipOptions;
|
|
53
|
+
createToolbarTip(): void;
|
|
54
|
+
getControlLabel([_, target]: [string, HTMLButtonElement | HTMLSelectElement]): HTMLElement | null;
|
|
55
|
+
destroyAllTips(): void;
|
|
56
|
+
hideAllTips(): void;
|
|
43
57
|
}
|
|
44
|
-
|
|
45
|
-
export { QuillToolbarTip,
|
|
58
|
+
//#endregion
|
|
59
|
+
export { QuillToolbarTip, QuillToolbarTip as default, QuillToolbarTipOptions, TooltipItem, createI18nToolbarTipMap, defaultToolbarTip };
|
|
60
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
const t={"en-US":{...["background","blockquote","bold","clean","code","color","formula","italic","image","strike","table","underline","video","link"].reduce(((t,e)=>(t[e]=e[0].toUpperCase()+e.slice(1),t)),{}),...["list","align","script","indent","header"].reduce(((t,e)=>{const n={"list:ordered":"Ordered List","list:bullet":"Unordered List","list:check":"Todo List","align:left":"Left aligned","align:center":"Center aligned","align:right":"Right aligned","align:justify":"Justify aligned","script:super":"Superscript","script:sub":"Subscript","indent:-1":"Minus Indent","indent:+1":"Add Indent",text:"Text","header:1":"Heading 1","header:2":"Heading 2","header:3":"Heading 3","header:4":"Heading 4","header:5":"Heading 5","header:6":"Heading 6"};return t[e]={onShow:(t,o)=>("align"!==e||o||(o="left"),"header"!==e||o?n[`${e}:${o}`]:n.text)},t}),{}),"code-block":"Code Block",size:"Font Size",font:"Font Style",direction:{onShow:t=>t.classList.contains("ql-active")?"Text Direction Right To Left":"Text Direction Left To Right"}}},e={msg:"",delay:150,direction:"top",className:[]},n=Math.min,o=Math.max,i=Math.round,r=Math.floor,l=t=>({x:t,y:t}),s={left:"right",right:"left",bottom:"top",top:"bottom"},c={start:"end",end:"start"};function a(t,e,i){return o(t,n(e,i))}function f(t,e){return"function"==typeof t?t(e):t}function u(t){return t.split("-")[0]}function d(t){return t.split("-")[1]}function h(t){return"x"===t?"y":"x"}function p(t){return"y"===t?"height":"width"}function m(t){return["top","bottom"].includes(u(t))?"y":"x"}function g(t){return h(m(t))}function y(t){return t.replace(/start|end/g,(t=>c[t]))}function x(t){return t.replace(/left|right|bottom|top/g,(t=>s[t]))}function v(t){const{x:e,y:n,width:o,height:i}=t;return{width:o,height:i,top:n,left:e,right:e+o,bottom:n+i,x:e,y:n}}function w(t,e,n){let{reference:o,floating:i}=t;const r=m(e),l=g(e),s=p(l),c=u(e),a="y"===r,f=o.x+o.width/2-i.width/2,h=o.y+o.height/2-i.height/2,y=o[s]/2-i[s]/2;let x;switch(c){case"top":x={x:f,y:o.y-i.height};break;case"bottom":x={x:f,y:o.y+o.height};break;case"right":x={x:o.x+o.width,y:h};break;case"left":x={x:o.x-i.width,y:h};break;default:x={x:o.x,y:o.y}}switch(d(e)){case"start":x[l]-=y*(n&&a?-1:1);break;case"end":x[l]+=y*(n&&a?-1:1)}return x}async function b(t,e){var n;void 0===e&&(e={});const{x:o,y:i,platform:r,rects:l,elements:s,strategy:c}=t,{boundary:a="clippingAncestors",rootBoundary:u="viewport",elementContext:d="floating",altBoundary:h=!1,padding:p=0}=f(e,t),m=function(t){return"number"!=typeof t?function(t){return{top:0,right:0,bottom:0,left:0,...t}}(t):{top:t,right:t,bottom:t,left:t}}(p),g=s[h?"floating"===d?"reference":"floating":d],y=v(await r.getClippingRect({element:null==(n=await(null==r.isElement?void 0:r.isElement(g)))||n?g:g.contextElement||await(null==r.getDocumentElement?void 0:r.getDocumentElement(s.floating)),boundary:a,rootBoundary:u,strategy:c})),x="floating"===d?{x:o,y:i,width:l.floating.width,height:l.floating.height}:l.reference,w=await(null==r.getOffsetParent?void 0:r.getOffsetParent(s.floating)),b=await(null==r.isElement?void 0:r.isElement(w))&&await(null==r.getScale?void 0:r.getScale(w))||{x:1,y:1},T=v(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:s,rect:x,offsetParent:w,strategy:c}):x);return{top:(y.top-T.top+m.top)/b.y,bottom:(T.bottom-y.bottom+m.bottom)/b.y,left:(y.left-T.left+m.left)/b.x,right:(T.right-y.right+m.right)/b.x}}function T(){return"undefined"!=typeof window}function L(t){return E(t)?(t.nodeName||"").toLowerCase():"#document"}function R(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function A(t){var e;return null==(e=(E(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function E(t){return!!T()&&(t instanceof Node||t instanceof R(t).Node)}function S(t){return!!T()&&(t instanceof Element||t instanceof R(t).Element)}function C(t){return!!T()&&(t instanceof HTMLElement||t instanceof R(t).HTMLElement)}function O(t){return!(!T()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof R(t).ShadowRoot)}function k(t){const{overflow:e,overflowX:n,overflowY:o,display:i}=q(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&!["inline","contents"].includes(i)}function D(t){return["table","td","th"].includes(L(t))}function H(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function F(t){const e=P(),n=S(t)?q(t):t;return"none"!==n.transform||"none"!==n.perspective||!!n.containerType&&"normal"!==n.containerType||!e&&!!n.backdropFilter&&"none"!==n.backdropFilter||!e&&!!n.filter&&"none"!==n.filter||["transform","perspective","filter"].some((t=>(n.willChange||"").includes(t)))||["paint","layout","strict","content"].some((t=>(n.contain||"").includes(t)))}function P(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function M(t){return["html","body","#document"].includes(L(t))}function q(t){return R(t).getComputedStyle(t)}function B(t){return S(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function N(t){if("html"===L(t))return t;const e=t.assignedSlot||t.parentNode||O(t)&&t.host||A(t);return O(e)?e.host:e}function W(t){const e=N(t);return M(e)?t.ownerDocument?t.ownerDocument.body:t.body:C(e)&&k(e)?e:W(e)}function V(t,e,n){var o;void 0===e&&(e=[]),void 0===n&&(n=!0);const i=W(t),r=i===(null==(o=t.ownerDocument)?void 0:o.body),l=R(i);if(r){const t=z(l);return e.concat(l,l.visualViewport||[],k(i)?i:[],t&&n?V(t):[])}return e.concat(i,V(i,[],n))}function z(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function $(t){const e=q(t);let n=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const r=C(t),l=r?t.offsetWidth:n,s=r?t.offsetHeight:o,c=i(n)!==l||i(o)!==s;return c&&(n=l,o=s),{width:n,height:o,$:c}}function j(t){return S(t)?t:t.contextElement}function I(t){const e=j(t);if(!C(e))return l(1);const n=e.getBoundingClientRect(),{width:o,height:r,$:s}=$(e);let c=(s?i(n.width):n.width)/o,a=(s?i(n.height):n.height)/r;return c&&Number.isFinite(c)||(c=1),a&&Number.isFinite(a)||(a=1),{x:c,y:a}}const _=l(0);function U(t){const e=R(t);return P()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:_}function X(t,e,n,o){void 0===e&&(e=!1),void 0===n&&(n=!1);const i=t.getBoundingClientRect(),r=j(t);let s=l(1);e&&(o?S(o)&&(s=I(o)):s=I(t));const c=function(t,e,n){return void 0===e&&(e=!1),!(!n||e&&n!==R(t))&&e}(r,n,o)?U(r):l(0);let a=(i.left+c.x)/s.x,f=(i.top+c.y)/s.y,u=i.width/s.x,d=i.height/s.y;if(r){const t=R(r),e=o&&S(o)?R(o):o;let n=t,i=z(n);for(;i&&o&&e!==n;){const t=I(i),e=i.getBoundingClientRect(),o=q(i),r=e.left+(i.clientLeft+parseFloat(o.paddingLeft))*t.x,l=e.top+(i.clientTop+parseFloat(o.paddingTop))*t.y;a*=t.x,f*=t.y,u*=t.x,d*=t.y,a+=r,f+=l,n=R(i),i=z(n)}}return v({width:u,height:d,x:a,y:f})}function Y(t,e){const n=B(t).scrollLeft;return e?e.left+n:X(A(t)).left+n}function J(t,e,n){void 0===n&&(n=!1);const o=t.getBoundingClientRect();return{x:o.left+e.scrollLeft-(n?0:Y(t,o)),y:o.top+e.scrollTop}}function G(t,e,n){let i;if("viewport"===e)i=function(t,e){const n=R(t),o=A(t),i=n.visualViewport;let r=o.clientWidth,l=o.clientHeight,s=0,c=0;if(i){r=i.width,l=i.height;const t=P();(!t||t&&"fixed"===e)&&(s=i.offsetLeft,c=i.offsetTop)}return{width:r,height:l,x:s,y:c}}(t,n);else if("document"===e)i=function(t){const e=A(t),n=B(t),i=t.ownerDocument.body,r=o(e.scrollWidth,e.clientWidth,i.scrollWidth,i.clientWidth),l=o(e.scrollHeight,e.clientHeight,i.scrollHeight,i.clientHeight);let s=-n.scrollLeft+Y(t);const c=-n.scrollTop;return"rtl"===q(i).direction&&(s+=o(e.clientWidth,i.clientWidth)-r),{width:r,height:l,x:s,y:c}}(A(t));else if(S(e))i=function(t,e){const n=X(t,!0,"fixed"===e),o=n.top+t.clientTop,i=n.left+t.clientLeft,r=C(t)?I(t):l(1);return{width:t.clientWidth*r.x,height:t.clientHeight*r.y,x:i*r.x,y:o*r.y}}(e,n);else{const n=U(t);i={x:e.x-n.x,y:e.y-n.y,width:e.width,height:e.height}}return v(i)}function K(t,e){const n=N(t);return!(n===e||!S(n)||M(n))&&("fixed"===q(n).position||K(n,e))}function Q(t,e,n){const o=C(e),i=A(e),r="fixed"===n,s=X(t,!0,r,e);let c={scrollLeft:0,scrollTop:0};const a=l(0);if(o||!o&&!r)if(("body"!==L(e)||k(i))&&(c=B(e)),o){const t=X(e,!0,r,e);a.x=t.x+e.clientLeft,a.y=t.y+e.clientTop}else i&&(a.x=Y(i));const f=!i||o||r?l(0):J(i,c);return{x:s.left+c.scrollLeft-a.x-f.x,y:s.top+c.scrollTop-a.y-f.y,width:s.width,height:s.height}}function Z(t){return"static"===q(t).position}function tt(t,e){if(!C(t)||"fixed"===q(t).position)return null;if(e)return e(t);let n=t.offsetParent;return A(t)===n&&(n=n.ownerDocument.body),n}function et(t,e){const n=R(t);if(H(t))return n;if(!C(t)){let e=N(t);for(;e&&!M(e);){if(S(e)&&!Z(e))return e;e=N(e)}return n}let o=tt(t,e);for(;o&&D(o)&&Z(o);)o=tt(o,e);return o&&M(o)&&Z(o)&&!F(o)?n:o||function(t){let e=N(t);for(;C(e)&&!M(e);){if(F(e))return e;if(H(e))return null;e=N(e)}return null}(t)||n}const nt={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:n,offsetParent:o,strategy:i}=t;const r="fixed"===i,s=A(o),c=!!e&&H(e.floating);if(o===s||c&&r)return n;let a={scrollLeft:0,scrollTop:0},f=l(1);const u=l(0),d=C(o);if((d||!d&&!r)&&(("body"!==L(o)||k(s))&&(a=B(o)),C(o))){const t=X(o);f=I(o),u.x=t.x+o.clientLeft,u.y=t.y+o.clientTop}const h=!s||d||r?l(0):J(s,a,!0);return{width:n.width*f.x,height:n.height*f.y,x:n.x*f.x-a.scrollLeft*f.x+u.x+h.x,y:n.y*f.y-a.scrollTop*f.y+u.y+h.y}},getDocumentElement:A,getClippingRect:function(t){let{element:e,boundary:i,rootBoundary:r,strategy:l}=t;const s=[..."clippingAncestors"===i?H(e)?[]:function(t,e){const n=e.get(t);if(n)return n;let o=V(t,[],!1).filter((t=>S(t)&&"body"!==L(t))),i=null;const r="fixed"===q(t).position;let l=r?N(t):t;for(;S(l)&&!M(l);){const e=q(l),n=F(l);n||"fixed"!==e.position||(i=null),(r?!n&&!i:!n&&"static"===e.position&&i&&["absolute","fixed"].includes(i.position)||k(l)&&!n&&K(t,l))?o=o.filter((t=>t!==l)):i=e,l=N(l)}return e.set(t,o),o}(e,this._c):[].concat(i),r],c=s[0],a=s.reduce(((t,i)=>{const r=G(e,i,l);return t.top=o(r.top,t.top),t.right=n(r.right,t.right),t.bottom=n(r.bottom,t.bottom),t.left=o(r.left,t.left),t}),G(e,c,l));return{width:a.right-a.left,height:a.bottom-a.top,x:a.left,y:a.top}},getOffsetParent:et,getElementRects:async function(t){const e=this.getOffsetParent||et,n=this.getDimensions,o=await n(t.floating);return{reference:Q(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}},getClientRects:function(t){return Array.from(t.getClientRects())},getDimensions:function(t){const{width:e,height:n}=$(t);return{width:e,height:n}},getScale:I,isElement:S,isRTL:function(t){return"rtl"===q(t).direction}};function ot(t,e,i,l){void 0===l&&(l={});const{ancestorScroll:s=!0,ancestorResize:c=!0,elementResize:a="function"==typeof ResizeObserver,layoutShift:f="function"==typeof IntersectionObserver,animationFrame:u=!1}=l,d=j(t),h=s||c?[...d?V(d):[],...V(e)]:[];h.forEach((t=>{s&&t.addEventListener("scroll",i,{passive:!0}),c&&t.addEventListener("resize",i)}));const p=d&&f?function(t,e){let i,l=null;const s=A(t);function c(){var t;clearTimeout(i),null==(t=l)||t.disconnect(),l=null}return function a(f,u){void 0===f&&(f=!1),void 0===u&&(u=1),c();const{left:d,top:h,width:p,height:m}=t.getBoundingClientRect();if(f||e(),!p||!m)return;const g={rootMargin:-r(h)+"px "+-r(s.clientWidth-(d+p))+"px "+-r(s.clientHeight-(h+m))+"px "+-r(d)+"px",threshold:o(0,n(1,u))||1};let y=!0;function x(t){const e=t[0].intersectionRatio;if(e!==u){if(!y)return a();e?a(!1,e):i=setTimeout((()=>{a(!1,1e-7)}),1e3)}y=!1}try{l=new IntersectionObserver(x,{...g,root:s.ownerDocument})}catch(t){l=new IntersectionObserver(x,g)}l.observe(t)}(!0),c}(d,i):null;let m,g=-1,y=null;a&&(y=new ResizeObserver((t=>{let[n]=t;n&&n.target===d&&y&&(y.unobserve(e),cancelAnimationFrame(g),g=requestAnimationFrame((()=>{var t;null==(t=y)||t.observe(e)}))),i()})),d&&!u&&y.observe(d),y.observe(e));let x=u?X(t):null;return u&&function e(){const n=X(t);!x||n.x===x.x&&n.y===x.y&&n.width===x.width&&n.height===x.height||i();x=n,m=requestAnimationFrame(e)}(),i(),()=>{var t;h.forEach((t=>{s&&t.removeEventListener("scroll",i),c&&t.removeEventListener("resize",i)})),null==p||p(),null==(t=y)||t.disconnect(),y=null,u&&cancelAnimationFrame(m)}}const it=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var n,o;const{x:i,y:r,placement:l,middlewareData:s}=e,c=await async function(t,e){const{placement:n,platform:o,elements:i}=t,r=await(null==o.isRTL?void 0:o.isRTL(i.floating)),l=u(n),s=d(n),c="y"===m(n),a=["left","top"].includes(l)?-1:1,h=r&&c?-1:1,p=f(e,t);let{mainAxis:g,crossAxis:y,alignmentAxis:x}="number"==typeof p?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return s&&"number"==typeof x&&(y="end"===s?-1*x:x),c?{x:y*h,y:g*a}:{x:g*a,y:y*h}}(e,t);return l===(null==(n=s.offset)?void 0:n.placement)&&null!=(o=s.arrow)&&o.alignmentOffset?{}:{x:i+c.x,y:r+c.y,data:{...c,placement:l}}}}},rt=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:o,placement:i}=e,{mainAxis:r=!0,crossAxis:l=!1,limiter:s={fn:t=>{let{x:e,y:n}=t;return{x:e,y:n}}},...c}=f(t,e),d={x:n,y:o},p=await b(e,c),g=m(u(i)),y=h(g);let x=d[y],v=d[g];if(r){const t="y"===y?"bottom":"right";x=a(x+p["y"===y?"top":"left"],x,x-p[t])}if(l){const t="y"===g?"bottom":"right";v=a(v+p["y"===g?"top":"left"],v,v-p[t])}const w=s.fn({...e,[y]:x,[g]:v});return{...w,data:{x:w.x-n,y:w.y-o,enabled:{[y]:r,[g]:l}}}}}},lt=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var n,o;const{placement:i,middlewareData:r,rects:l,initialPlacement:s,platform:c,elements:a}=e,{mainAxis:h=!0,crossAxis:v=!0,fallbackPlacements:w,fallbackStrategy:T="bestFit",fallbackAxisSideDirection:L="none",flipAlignment:R=!0,...A}=f(t,e);if(null!=(n=r.arrow)&&n.alignmentOffset)return{};const E=u(i),S=m(s),C=u(s)===s,O=await(null==c.isRTL?void 0:c.isRTL(a.floating)),k=w||(C||!R?[x(s)]:function(t){const e=x(t);return[y(t),e,y(e)]}(s)),D="none"!==L;!w&&D&&k.push(...function(t,e,n,o){const i=d(t);let r=function(t,e,n){const o=["left","right"],i=["right","left"],r=["top","bottom"],l=["bottom","top"];switch(t){case"top":case"bottom":return n?e?i:o:e?o:i;case"left":case"right":return e?r:l;default:return[]}}(u(t),"start"===n,o);return i&&(r=r.map((t=>t+"-"+i)),e&&(r=r.concat(r.map(y)))),r}(s,R,L,O));const H=[s,...k],F=await b(e,A),P=[];let M=(null==(o=r.flip)?void 0:o.overflows)||[];if(h&&P.push(F[E]),v){const t=function(t,e,n){void 0===n&&(n=!1);const o=d(t),i=g(t),r=p(i);let l="x"===i?o===(n?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[r]>e.floating[r]&&(l=x(l)),[l,x(l)]}(i,l,O);P.push(F[t[0]],F[t[1]])}if(M=[...M,{placement:i,overflows:P}],!P.every((t=>t<=0))){var q,B;const t=((null==(q=r.flip)?void 0:q.index)||0)+1,e=H[t];if(e)return{data:{index:t,overflows:M},reset:{placement:e}};let n=null==(B=M.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:B.placement;if(!n)switch(T){case"bestFit":{var N;const t=null==(N=M.filter((t=>{if(D){const e=m(t.placement);return e===S||"y"===e}return!0})).map((t=>[t.placement,t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)])).sort(((t,e)=>t[1]-e[1]))[0])?void 0:N[0];t&&(n=t);break}case"initialPlacement":n=s}if(i!==n)return{reset:{placement:n}}}return{}}}},st=function(t){return void 0===t&&(t={}),{options:t,fn(e){const{x:n,y:o,placement:i,rects:r,middlewareData:l}=e,{offset:s=0,mainAxis:c=!0,crossAxis:a=!0}=f(t,e),d={x:n,y:o},p=m(i),g=h(p);let y=d[g],x=d[p];const v=f(s,e),w="number"==typeof v?{mainAxis:v,crossAxis:0}:{mainAxis:0,crossAxis:0,...v};if(c){const t="y"===g?"height":"width",e=r.reference[g]-r.floating[t]+w.mainAxis,n=r.reference[g]+r.reference[t]-w.mainAxis;y<e?y=e:y>n&&(y=n)}if(a){var b,T;const t="y"===g?"width":"height",e=["top","left"].includes(u(i)),n=r.reference[p]-r.floating[t]+(e&&(null==(b=l.offset)?void 0:b[p])||0)+(e?0:w.crossAxis),o=r.reference[p]+r.reference[t]+(e?0:(null==(T=l.offset)?void 0:T[p])||0)-(e?w.crossAxis:0);x<n?x=n:x>o&&(x=o)}return{[g]:y,[p]:x}}}},ct=(t,e,n)=>{const o=new Map,i={platform:nt,...n},r={...i.platform,_c:o};return(async(t,e,n)=>{const{placement:o="bottom",strategy:i="absolute",middleware:r=[],platform:l}=n,s=r.filter(Boolean),c=await(null==l.isRTL?void 0:l.isRTL(e));let a=await l.getElementRects({reference:t,floating:e,strategy:i}),{x:f,y:u}=w(a,o,c),d=o,h={},p=0;for(let n=0;n<s.length;n++){const{name:r,fn:m}=s[n],{x:g,y:y,data:x,reset:v}=await m({x:f,y:u,initialPlacement:o,placement:d,strategy:i,middlewareData:h,rects:a,platform:l,elements:{reference:t,floating:e}});f=null!=g?g:f,u=null!=y?y:u,h={...h,[r]:{...h[r],...x}},v&&p<=50&&(p++,"object"==typeof v&&(v.placement&&(d=v.placement),v.rects&&(a=!0===v.rects?await l.getElementRects({reference:t,floating:e,strategy:i}):v.rects),({x:f,y:u}=w(a,d,c))),n=-1)}return{x:f,y:u,placement:d,strategy:i,middlewareData:h}})(t,e,{...i,platform:r})},at=t=>void 0===t,ft=t=>"string"==typeof t;let ut;const dt=(t,n={})=>{let{msg:o="",delay:i=150,content:r,direction:l="top",className:s=[],tipHoverable:c=!0,onShow:a,appendTo:f=document.body}=Object.assign({},e,n);var u;if(ft(s)&&(u=s.split(" "),s=Array.isArray(u)?u||[]:[u]),o||r||a){const d=document.createElement("div");d.classList.add("toolbar-tip__tooltip","hidden","transparent",...s);const h=t=>{d.innerHTML="";for(const e of t.split("\n")){const t=document.createElement("div");t.textContent=e,d.appendChild(t)}},p=()=>{if(r&&d.appendChild(r),o&&h(o),a){const e=a(t);if(ft(e))h(e);else{if(!e)return!1;d.appendChild(e)}}return Boolean(r||o||a)};let m,g;const y=()=>{ct(t,d,{placement:l,middleware:[lt(),rt({limiter:st()}),it(8)]}).then((({x:t,y:e})=>{Object.assign(d.style,{left:`${t}px`,top:`${e}px`})}))},x=()=>{d.classList.add("hidden"),d.remove(),g&&g()};function v(){m&&clearTimeout(m),m=setTimeout((()=>{p()&&(ut||(ut=document.createElement("div"),f.appendChild(ut)),ut.appendChild(d),d.removeEventListener("transitionend",x),d.classList.remove("hidden"),g=ot(t,d,y),d.classList.remove("transparent"))}),i)}function w(){m&&clearTimeout(m),m=setTimeout((()=>{d.classList.add("transparent"),((t,e,n,o)=>{t.addEventListener("transitionend",n,o),setTimeout((()=>{n()}),e)})(d,150,x,{once:!0})}),i)}const b=[t];c&&b.push(d);for(const L of b)L.addEventListener("mouseenter",v),L.addEventListener("mouseleave",w);const T=()=>{for(const t of b)t.removeEventListener("mouseenter",v),t.removeEventListener("mouseleave",w);g&&g(),d.remove(),ut&&ut.children.length<=0&&(ut.remove(),ut=void 0)};return{instance:d,destroy:T,show:v,hide:w}}return null};class ht{quill;static moduleName="toolbar-tip";options;toolbar;toolbarTips=[];constructor(t,e){if(this.quill=t,!e.tipTextMap)throw new Error("Please provide the tip text");if(this.options=this.resolveOptions(e),this.toolbar=this.quill.getModule("toolbar"),!this.toolbar)throw new Error("Please provide the toolbar");!this.toolbar||this.toolbar.controls.length<=0?console.warn("Toolbar is not available or has no controls"):this.createToolbarTip()}resolveOptions(t){return{defaultTooltipOptions:Object.assign({},e,t.defaultTooltipOptions),tipTextMap:t.tipTextMap||{}}}createToolbarTip(){for(const t of this.toolbar.controls){const e=t;let[n,o]=e;const i=this.options.tipTextMap[n];o.value&&(n=`${n}:${o.value}`);let r=this.options.tipTextMap[n];ft(r)&&(r={msg:r});const l=this.getControlLabel(e);if(!l||at(r)&&at(i))continue;const s=dt(l,{...this.options.defaultTooltipOptions,...r,onShow:t=>{let e=o.value;i&&!ft(i)&&i.onShow&&(e=i.onShow.call(this.quill,t,o.value));let n=null;return r&&(n=r.onShow?r.onShow.call(this.quill,t,o.value):r.content||r.msg),n||e},appendTo:this.quill.container});s&&this.toolbarTips.push([n,s])}}getControlLabel([t,e]){return"button"===e.tagName.toLowerCase()?e:e.previousElementSibling.querySelector(".ql-picker-label")}destroyAllTips(){const t=this.toolbarTips;if(0!==t.length)for(const[,e]of t)e.destroy()}hideAllTips(){const t=this.toolbarTips;if(0!==t.length)for(const[,e]of t)e.hide()}}export{ht as QuillToolbarTip,ht as default,t as defaultToolbarTip};
|
|
2
|
-
|
|
1
|
+
import{autoUpdate as e,computePosition as t,flip as n,limitShift as r,offset as i,shift as a}from"@floating-ui/dom";const o={"en-US":{blockquote:`Blockquote`,bold:`Bold`,clean:`Clean`,code:`Code`,"code-block":`Code Block`,formula:`Formula`,italic:`Italic`,image:`Image`,strike:`Strike`,table:`Table`,underline:`Underline`,video:`Video`,link:`Link`,list:{values:{ordered:`Ordered List`,bullet:`Unordered List`,check:`Todo List`}},align:{values:{"":`Left aligned`,center:`Center aligned`,right:`Right aligned`,justify:`Justify aligned`}},script:{values:{super:`Superscript`,sub:`Subscript`}},indent:{values:{"-1":`Minus Indent`,"+1":`Add Indent`}},header:{values:{"":`Normal text`,1:`Heading 1`,2:`Heading 2`,3:`Heading 3`,4:`Heading 4`,5:`Heading 5`,6:`Heading 6`}},size:`Font Size`,font:`Font Style`,direction:{onShow(e){return e.classList.contains(`ql-active`)?`Text Direction Right To Left`:`Text Direction Left To Right`}},color:{onShow(e,t){return t||`Color`}},background:{onShow(e,t){return t||`Background`}}}},s={msg:``,delay:150,direction:`top`,className:[]};function c(e,t,n,r,i){return i&&clearTimeout(i),e.addEventListener(`transitionend`,n,r),setTimeout(()=>{n()},t)}const l=e=>e===void 0,u=e=>typeof e==`string`,d=e=>Array.isArray(e)?e||[]:[e];let f;function p(o,l={}){let{msg:p=``,delay:m=150,content:h,direction:g=`top`,className:_=[],tipHoverable:v=!0,onShow:y,appendTo:b=document.body}=Object.assign({},s,l);if(u(_)&&(_=d(_.split(` `))),p||h||y){let s=document.createElement(`div`);s.classList.add(`toolbar-tip__tooltip`,`hidden`,`transparent`,..._);let l=e=>{s.innerHTML=``;for(let t of e.split(`
|
|
2
|
+
`)){let e=document.createElement(`div`);e.textContent=t,s.appendChild(e)}},d=()=>{if(h&&s.appendChild(h),p&&l(p),y){let e=y(o);if(u(e))l(e);else if(e)s.appendChild(e);else return!1}return!!(h||p||y)},x,S,C=()=>{t(o,s,{placement:g,middleware:[n(),a({limiter:r()}),i(8)]}).then(({x:e,y:t})=>{Object.assign(s.style,{left:`${e}px`,top:`${t}px`})})},w=()=>{s.classList.add(`hidden`),s.remove(),S&&S()};function T(){x&&clearTimeout(x),x=setTimeout(()=>{d()&&(f||(f=document.createElement(`div`),b.appendChild(f)),f.appendChild(s),s.removeEventListener(`transitionend`,w),s.classList.remove(`hidden`),S=e(o,s,C),s.classList.remove(`transparent`))},m)}function E(){x&&clearTimeout(x),x=setTimeout(()=>{s.classList.add(`transparent`),c(s,150,w,{once:!0})},m)}let D=[o];v&&D.push(s);for(let e of D)e.addEventListener(`mouseenter`,T),e.addEventListener(`mouseleave`,E);return{instance:s,destroy:()=>{for(let e of D)e.removeEventListener(`mouseenter`,T),e.removeEventListener(`mouseleave`,E);S&&S(),s.remove(),f&&f.children.length<=0&&(f.remove(),f=void 0)},show:T,hide:E}}return null}function m(e={}){let{prefix:t=`toolbar`,i18nModuleName:n=`i18n`}=e,r=e.formats||{simple:[`bold`,`italic`,`underline`,`strike`,`color`,`background`,`blockquote`,`code-block`,`code`,`link`,`image`,`video`,`formula`,`clean`],withValues:{list:[`ordered`,`bullet`,`check`],script:[`sub`,`super`],indent:[`-1`,`+1`],header:[``,`1`,`2`,`3`,`4`,`5`,`6`],align:[``,`center`,`right`,`justify`],size:[`small`,``,`large`,`huge`],font:[``,`serif`,`monospace`],direction:[``,`rtl`]}},i={};for(let e of r.simple||[])i[e]={onShow(){let r=this.getModule?.(n);if(r)return r.t(`${t}.${e}`,{})}};for(let[e]of Object.entries(r.withValues||{}))i[e]={onShow(r,i){let a=this.getModule?.(n);if(a)return a.t(`${t}.${e}.${i}`,{})}};return i}var h=class{static moduleName=`toolbar-tip`;options;toolbar;toolbarTips=[];constructor(e,t){if(this.quill=e,!t.tipTextMap)throw Error(`Please provide the tip text`);if(this.options=this.resolveOptions(t),this.toolbar=this.quill.getModule(`toolbar`),!this.toolbar)throw Error(`Please provide the toolbar`);!this.toolbar||this.toolbar.controls.length<=0?console.warn(`Toolbar is not available or has no controls`):this.createToolbarTip()}resolveOptions(e){return{defaultTooltipOptions:Object.assign({},s,e.defaultTooltipOptions),tipTextMap:e.tipTextMap||{}}}createToolbarTip(){for(let e of this.toolbar.controls){let t=e,[n,r]=t,i=this.options.tipTextMap[n];if(l(i))continue;u(i)&&(i={msg:i});let a=this.getControlLabel(t);if(!a)continue;let o=p(a,{...this.options.defaultTooltipOptions,...i,onShow:e=>{let t=r.value||``;return i.onShow?i.onShow.call(this.quill,e,t,r):i.values&&t in i.values?i.values[t]:i.content||i.msg||null},appendTo:this.quill.container});o&&this.toolbarTips.push([n,o])}}getControlLabel([e,t]){return t.tagName.toLowerCase()===`button`?t:t.previousElementSibling.querySelector(`.ql-picker-label`)}destroyAllTips(){let e=this.toolbarTips;if(e.length!==0){for(let[,t]of e)t.destroy();this.toolbarTips=[]}}hideAllTips(){let e=this.toolbarTips;if(e.length!==0)for(let[,t]of e)t.hide()}};export{h as QuillToolbarTip,h as default,m as createI18nToolbarTipMap,o as defaultToolbarTip};
|
|
3
|
+
//# sourceMappingURL=index.js.map
|