@tarviks/lexical-rich-editor 1.0.5 → 1.0.6
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/README.md +198 -198
- package/dist/index.js +45 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,198 +1,198 @@
|
|
|
1
|
-
# lexical-rich-editor
|
|
2
|
-
|
|
3
|
-
A production-ready, feature-rich **rich text editor** built on Meta's [Lexical](https://lexical.dev) framework with a Fluent UI toolbar. Supports AI autocomplete, spell/grammar check, tables, images, YouTube embeds, code blocks, and more.
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
yarn add lexical-rich-editor
|
|
9
|
-
# or
|
|
10
|
-
npm install lexical-rich-editor
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
### Peer dependencies
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
yarn add lexical \
|
|
17
|
-
@lexical/react @lexical/code @lexical/link @lexical/list \
|
|
18
|
-
@lexical/rich-text @lexical/table @lexical/utils @lexical/selection @lexical/html \
|
|
19
|
-
@fluentui/react @fluentui/react-components @fluentui/react-icons \
|
|
20
|
-
react react-dom
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Quick start
|
|
24
|
-
|
|
25
|
-
```tsx
|
|
26
|
-
import { useRef, useState } from 'react';
|
|
27
|
-
import {
|
|
28
|
-
ContentEditorComponent,
|
|
29
|
-
ContentEditorLevel,
|
|
30
|
-
ContentEditorRef,
|
|
31
|
-
} from 'lexical-rich-editor';
|
|
32
|
-
|
|
33
|
-
function MyEditor() {
|
|
34
|
-
const [value, setValue] = useState('');
|
|
35
|
-
const editorRef = useRef<ContentEditorRef>(null);
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<div style={{ height: 400 }}>
|
|
39
|
-
<ContentEditorComponent
|
|
40
|
-
ref={editorRef}
|
|
41
|
-
namespace="my-editor"
|
|
42
|
-
value={value}
|
|
43
|
-
onChange={setValue}
|
|
44
|
-
level={ContentEditorLevel.Pro}
|
|
45
|
-
placeholder="Start typing…"
|
|
46
|
-
showFloatingToolbar
|
|
47
|
-
/>
|
|
48
|
-
</div>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## Editor levels
|
|
54
|
-
|
|
55
|
-
| Level | Toolbar features |
|
|
56
|
-
|---|---|
|
|
57
|
-
| `ContentEditorLevel.None` | No toolbar — plain editable area |
|
|
58
|
-
| `ContentEditorLevel.Basic` | Bold, italic, underline, lists, links |
|
|
59
|
-
| `ContentEditorLevel.Standard` | Basic + tables |
|
|
60
|
-
| `ContentEditorLevel.Pro` | Full — images, YouTube, fonts, colors, code, page breaks |
|
|
61
|
-
|
|
62
|
-
## AI Autocomplete
|
|
63
|
-
|
|
64
|
-
Pass any async function that returns suggestions — the editor handles debounce, ghost text, and cancellation:
|
|
65
|
-
|
|
66
|
-
```tsx
|
|
67
|
-
<ContentEditorComponent
|
|
68
|
-
suggestFn={async (text, cursorIndex) => {
|
|
69
|
-
const res = await fetch('/api/suggest', {
|
|
70
|
-
method: 'POST',
|
|
71
|
-
body: JSON.stringify({ text, cursorIndex }),
|
|
72
|
-
});
|
|
73
|
-
return res.json();
|
|
74
|
-
// Supported shapes: string[] | { generated_text: string } | { suggestions: string[] }
|
|
75
|
-
}}
|
|
76
|
-
onSuggestionAccept={({ suggestionText, triggerText, method }) => {
|
|
77
|
-
// method: 'tab' | 'enter' | 'click'
|
|
78
|
-
sendRewardSignal({ suggestionText, triggerText });
|
|
79
|
-
}}
|
|
80
|
-
suggestIdleMs={300} // debounce delay (default 300ms)
|
|
81
|
-
/>
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
## Spell & Grammar check
|
|
85
|
-
|
|
86
|
-
```tsx
|
|
87
|
-
<ContentEditorComponent
|
|
88
|
-
spellCheckFn={async (text) => {
|
|
89
|
-
const res = await fetch('/api/spellcheck', {
|
|
90
|
-
method: 'POST',
|
|
91
|
-
body: JSON.stringify({ text }),
|
|
92
|
-
});
|
|
93
|
-
return res.json();
|
|
94
|
-
// Supported shapes:
|
|
95
|
-
// { misspelled_words: string[], suggestions: Record<string, string[]>, grammar_correction?: string }
|
|
96
|
-
// { misspelled: string[], suggestions: Record<string, string[]>, improved_text?: string }
|
|
97
|
-
// SpellCheckIssue[]
|
|
98
|
-
}}
|
|
99
|
-
onSpellCheckAccept={({ original, replacement, type }) => {
|
|
100
|
-
// type: 'spelling' | 'grammar' | 'style'
|
|
101
|
-
}}
|
|
102
|
-
spellCheckIdleMs={1200} // debounce delay (default 1200ms)
|
|
103
|
-
spellCheckEnabled={true}
|
|
104
|
-
/>
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
## Ref API
|
|
108
|
-
|
|
109
|
-
```tsx
|
|
110
|
-
const editorRef = useRef<ContentEditorRef>(null);
|
|
111
|
-
|
|
112
|
-
// Get current HTML string
|
|
113
|
-
const html = editorRef.current?.getValue();
|
|
114
|
-
|
|
115
|
-
// Set content from HTML
|
|
116
|
-
editorRef.current?.setValue('<p>Hello <strong>world</strong></p>');
|
|
117
|
-
|
|
118
|
-
// Clear the editor
|
|
119
|
-
editorRef.current?.clear();
|
|
120
|
-
|
|
121
|
-
// Focus / blur
|
|
122
|
-
editorRef.current?.focus();
|
|
123
|
-
editorRef.current?.blur();
|
|
124
|
-
|
|
125
|
-
// Check state
|
|
126
|
-
const empty = editorRef.current?.isEmpty();
|
|
127
|
-
const focused = editorRef.current?.isFocused();
|
|
128
|
-
|
|
129
|
-
// Insert / update a named block (e.g. email signature)
|
|
130
|
-
editorRef.current?.upsertBlock({
|
|
131
|
-
kind: 'signature',
|
|
132
|
-
html: '<p>Best regards,<br/>John Doe</p>',
|
|
133
|
-
position: 'end',
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
// Remove a block
|
|
137
|
-
editorRef.current?.removeBlock('signature');
|
|
138
|
-
|
|
139
|
-
// Check if a block exists
|
|
140
|
-
const has = editorRef.current?.hasBlock('signature');
|
|
141
|
-
|
|
142
|
-
// Raw Lexical editor (advanced)
|
|
143
|
-
const lexicalEditor = editorRef.current?.getEditor();
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
## Props
|
|
147
|
-
|
|
148
|
-
| Prop | Type | Default | Description |
|
|
149
|
-
|---|---|---|---|
|
|
150
|
-
| `value` | `string` | required | Controlled HTML value |
|
|
151
|
-
| `onChange` | `(html: string) => void` | required | Change handler |
|
|
152
|
-
| `namespace` | `string` | `undefined` | Lexical namespace |
|
|
153
|
-
| `level` | `ContentEditorLevel` | `Basic` | Toolbar feature level |
|
|
154
|
-
| `readOnly` | `boolean` | `false` | Non-interactive mode |
|
|
155
|
-
| `placeholder` | `string` | `undefined` | Placeholder text |
|
|
156
|
-
| `width` | `string` | `'100%'` | Container width |
|
|
157
|
-
| `height` | `string` | `'100%'` | Container height |
|
|
158
|
-
| `margin` | `string\|number` | `'5px auto'` | Container margin |
|
|
159
|
-
| `autoFocus` | `boolean` | `false` | Focus on mount |
|
|
160
|
-
| `showFloatingToolbar` | `boolean` | `false` | Floating format bar on selection |
|
|
161
|
-
| `wordLimit` | `number` | `undefined` | Max word count (shows counter) |
|
|
162
|
-
| `onWordLimitExceeded` | `fn` | `undefined` | Fires when limit is crossed |
|
|
163
|
-
| `suggestFn` | `async fn` | `undefined` | Simple autocomplete API |
|
|
164
|
-
| `useQuery` | `fn` | `undefined` | Advanced autocomplete with cancellation |
|
|
165
|
-
| `suggestIdleMs` | `number` | `300` | Autocomplete debounce (ms) |
|
|
166
|
-
| `spellCheckFn` | `async fn` | `undefined` | Simple spell check API |
|
|
167
|
-
| `useSpellCheck` | `fn` | `undefined` | Advanced spell check with cancellation |
|
|
168
|
-
| `spellCheckIdleMs` | `number` | `1200` | Spell check debounce (ms) |
|
|
169
|
-
| `spellCheckEnabled` | `boolean` | `true` | Toggle spell check without unmounting |
|
|
170
|
-
| `onSuggestionAccept` | `fn` | `undefined` | Fires on autocomplete accept |
|
|
171
|
-
| `onSuggestionShown` | `fn` | `undefined` | Fires when suggestion is shown |
|
|
172
|
-
| `onSpellCheckAccept` | `fn` | `undefined` | Fires on spell check accept |
|
|
173
|
-
| `onFocus` | `fn` | `undefined` | Focus event |
|
|
174
|
-
| `onBlur` | `fn` | `undefined` | Blur event |
|
|
175
|
-
|
|
176
|
-
## Development
|
|
177
|
-
|
|
178
|
-
```bash
|
|
179
|
-
# Clone
|
|
180
|
-
git clone https://github.com/capsitech/lexical-rich-editor
|
|
181
|
-
|
|
182
|
-
# Install root deps (for building)
|
|
183
|
-
yarn install
|
|
184
|
-
|
|
185
|
-
# Run example app
|
|
186
|
-
cd example && yarn install && yarn dev
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
## Build & publish
|
|
190
|
-
|
|
191
|
-
```bash
|
|
192
|
-
yarn build # outputs to dist/
|
|
193
|
-
npm publish # publishes to npm
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
## License
|
|
197
|
-
|
|
198
|
-
MIT
|
|
1
|
+
# lexical-rich-editor
|
|
2
|
+
|
|
3
|
+
A production-ready, feature-rich **rich text editor** built on Meta's [Lexical](https://lexical.dev) framework with a Fluent UI toolbar. Supports AI autocomplete, spell/grammar check, tables, images, YouTube embeds, code blocks, and more.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
yarn add @tarviks/lexical-rich-editor
|
|
9
|
+
# or
|
|
10
|
+
npm install @tarviks/lexical-rich-editor
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Peer dependencies
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add lexical \
|
|
17
|
+
@lexical/react @lexical/code @lexical/link @lexical/list \
|
|
18
|
+
@lexical/rich-text @lexical/table @lexical/utils @lexical/selection @lexical/html \
|
|
19
|
+
@fluentui/react @fluentui/react-components @fluentui/react-icons \
|
|
20
|
+
react react-dom
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick start
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { useRef, useState } from 'react';
|
|
27
|
+
import {
|
|
28
|
+
ContentEditorComponent,
|
|
29
|
+
ContentEditorLevel,
|
|
30
|
+
ContentEditorRef,
|
|
31
|
+
} from '@tarviks/lexical-rich-editor';
|
|
32
|
+
|
|
33
|
+
function MyEditor() {
|
|
34
|
+
const [value, setValue] = useState('');
|
|
35
|
+
const editorRef = useRef<ContentEditorRef>(null);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div style={{ height: 400 }}>
|
|
39
|
+
<ContentEditorComponent
|
|
40
|
+
ref={editorRef}
|
|
41
|
+
namespace="my-editor"
|
|
42
|
+
value={value}
|
|
43
|
+
onChange={setValue}
|
|
44
|
+
level={ContentEditorLevel.Pro}
|
|
45
|
+
placeholder="Start typing…"
|
|
46
|
+
showFloatingToolbar
|
|
47
|
+
/>
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Editor levels
|
|
54
|
+
|
|
55
|
+
| Level | Toolbar features |
|
|
56
|
+
|---|---|
|
|
57
|
+
| `ContentEditorLevel.None` | No toolbar — plain editable area |
|
|
58
|
+
| `ContentEditorLevel.Basic` | Bold, italic, underline, lists, links |
|
|
59
|
+
| `ContentEditorLevel.Standard` | Basic + tables |
|
|
60
|
+
| `ContentEditorLevel.Pro` | Full — images, YouTube, fonts, colors, code, page breaks |
|
|
61
|
+
|
|
62
|
+
## AI Autocomplete
|
|
63
|
+
|
|
64
|
+
Pass any async function that returns suggestions — the editor handles debounce, ghost text, and cancellation:
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
<ContentEditorComponent
|
|
68
|
+
suggestFn={async (text, cursorIndex) => {
|
|
69
|
+
const res = await fetch('/api/suggest', {
|
|
70
|
+
method: 'POST',
|
|
71
|
+
body: JSON.stringify({ text, cursorIndex }),
|
|
72
|
+
});
|
|
73
|
+
return res.json();
|
|
74
|
+
// Supported shapes: string[] | { generated_text: string } | { suggestions: string[] }
|
|
75
|
+
}}
|
|
76
|
+
onSuggestionAccept={({ suggestionText, triggerText, method }) => {
|
|
77
|
+
// method: 'tab' | 'enter' | 'click'
|
|
78
|
+
sendRewardSignal({ suggestionText, triggerText });
|
|
79
|
+
}}
|
|
80
|
+
suggestIdleMs={300} // debounce delay (default 300ms)
|
|
81
|
+
/>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Spell & Grammar check
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
<ContentEditorComponent
|
|
88
|
+
spellCheckFn={async (text) => {
|
|
89
|
+
const res = await fetch('/api/spellcheck', {
|
|
90
|
+
method: 'POST',
|
|
91
|
+
body: JSON.stringify({ text }),
|
|
92
|
+
});
|
|
93
|
+
return res.json();
|
|
94
|
+
// Supported shapes:
|
|
95
|
+
// { misspelled_words: string[], suggestions: Record<string, string[]>, grammar_correction?: string }
|
|
96
|
+
// { misspelled: string[], suggestions: Record<string, string[]>, improved_text?: string }
|
|
97
|
+
// SpellCheckIssue[]
|
|
98
|
+
}}
|
|
99
|
+
onSpellCheckAccept={({ original, replacement, type }) => {
|
|
100
|
+
// type: 'spelling' | 'grammar' | 'style'
|
|
101
|
+
}}
|
|
102
|
+
spellCheckIdleMs={1200} // debounce delay (default 1200ms)
|
|
103
|
+
spellCheckEnabled={true}
|
|
104
|
+
/>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Ref API
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
const editorRef = useRef<ContentEditorRef>(null);
|
|
111
|
+
|
|
112
|
+
// Get current HTML string
|
|
113
|
+
const html = editorRef.current?.getValue();
|
|
114
|
+
|
|
115
|
+
// Set content from HTML
|
|
116
|
+
editorRef.current?.setValue('<p>Hello <strong>world</strong></p>');
|
|
117
|
+
|
|
118
|
+
// Clear the editor
|
|
119
|
+
editorRef.current?.clear();
|
|
120
|
+
|
|
121
|
+
// Focus / blur
|
|
122
|
+
editorRef.current?.focus();
|
|
123
|
+
editorRef.current?.blur();
|
|
124
|
+
|
|
125
|
+
// Check state
|
|
126
|
+
const empty = editorRef.current?.isEmpty();
|
|
127
|
+
const focused = editorRef.current?.isFocused();
|
|
128
|
+
|
|
129
|
+
// Insert / update a named block (e.g. email signature)
|
|
130
|
+
editorRef.current?.upsertBlock({
|
|
131
|
+
kind: 'signature',
|
|
132
|
+
html: '<p>Best regards,<br/>John Doe</p>',
|
|
133
|
+
position: 'end',
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Remove a block
|
|
137
|
+
editorRef.current?.removeBlock('signature');
|
|
138
|
+
|
|
139
|
+
// Check if a block exists
|
|
140
|
+
const has = editorRef.current?.hasBlock('signature');
|
|
141
|
+
|
|
142
|
+
// Raw Lexical editor (advanced)
|
|
143
|
+
const lexicalEditor = editorRef.current?.getEditor();
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Props
|
|
147
|
+
|
|
148
|
+
| Prop | Type | Default | Description |
|
|
149
|
+
|---|---|---|---|
|
|
150
|
+
| `value` | `string` | required | Controlled HTML value |
|
|
151
|
+
| `onChange` | `(html: string) => void` | required | Change handler |
|
|
152
|
+
| `namespace` | `string` | `undefined` | Lexical namespace |
|
|
153
|
+
| `level` | `ContentEditorLevel` | `Basic` | Toolbar feature level |
|
|
154
|
+
| `readOnly` | `boolean` | `false` | Non-interactive mode |
|
|
155
|
+
| `placeholder` | `string` | `undefined` | Placeholder text |
|
|
156
|
+
| `width` | `string` | `'100%'` | Container width |
|
|
157
|
+
| `height` | `string` | `'100%'` | Container height |
|
|
158
|
+
| `margin` | `string\|number` | `'5px auto'` | Container margin |
|
|
159
|
+
| `autoFocus` | `boolean` | `false` | Focus on mount |
|
|
160
|
+
| `showFloatingToolbar` | `boolean` | `false` | Floating format bar on selection |
|
|
161
|
+
| `wordLimit` | `number` | `undefined` | Max word count (shows counter) |
|
|
162
|
+
| `onWordLimitExceeded` | `fn` | `undefined` | Fires when limit is crossed |
|
|
163
|
+
| `suggestFn` | `async fn` | `undefined` | Simple autocomplete API |
|
|
164
|
+
| `useQuery` | `fn` | `undefined` | Advanced autocomplete with cancellation |
|
|
165
|
+
| `suggestIdleMs` | `number` | `300` | Autocomplete debounce (ms) |
|
|
166
|
+
| `spellCheckFn` | `async fn` | `undefined` | Simple spell check API |
|
|
167
|
+
| `useSpellCheck` | `fn` | `undefined` | Advanced spell check with cancellation |
|
|
168
|
+
| `spellCheckIdleMs` | `number` | `1200` | Spell check debounce (ms) |
|
|
169
|
+
| `spellCheckEnabled` | `boolean` | `true` | Toggle spell check without unmounting |
|
|
170
|
+
| `onSuggestionAccept` | `fn` | `undefined` | Fires on autocomplete accept |
|
|
171
|
+
| `onSuggestionShown` | `fn` | `undefined` | Fires when suggestion is shown |
|
|
172
|
+
| `onSpellCheckAccept` | `fn` | `undefined` | Fires on spell check accept |
|
|
173
|
+
| `onFocus` | `fn` | `undefined` | Focus event |
|
|
174
|
+
| `onBlur` | `fn` | `undefined` | Blur event |
|
|
175
|
+
|
|
176
|
+
## Development
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
# Clone
|
|
180
|
+
git clone https://github.com/capsitech/lexical-rich-editor
|
|
181
|
+
|
|
182
|
+
# Install root deps (for building)
|
|
183
|
+
yarn install
|
|
184
|
+
|
|
185
|
+
# Run example app
|
|
186
|
+
cd example && yarn install && yarn dev
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Build & publish
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
yarn build # outputs to dist/
|
|
193
|
+
npm publish # publishes to npm
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
MIT
|
package/dist/index.js
CHANGED
|
@@ -5106,11 +5106,12 @@ var hsvToRgb = (h, s, v) => {
|
|
|
5106
5106
|
b: Math.round((bb + m) * 255)
|
|
5107
5107
|
};
|
|
5108
5108
|
};
|
|
5109
|
-
function useDrag(onMove, onEnd) {
|
|
5109
|
+
function useDrag(onMove, onEnd, interactingRef) {
|
|
5110
5110
|
const draggingRef = React6__namespace.useRef(false);
|
|
5111
5111
|
const start = React6__namespace.useCallback(
|
|
5112
5112
|
(e) => {
|
|
5113
5113
|
draggingRef.current = true;
|
|
5114
|
+
if (interactingRef) interactingRef.current = true;
|
|
5114
5115
|
onMove(e.clientX, e.clientY);
|
|
5115
5116
|
const move = (ev) => {
|
|
5116
5117
|
if (!draggingRef.current) return;
|
|
@@ -5120,17 +5121,55 @@ function useDrag(onMove, onEnd) {
|
|
|
5120
5121
|
draggingRef.current = false;
|
|
5121
5122
|
window.removeEventListener("mousemove", move);
|
|
5122
5123
|
window.removeEventListener("mouseup", up);
|
|
5124
|
+
if (interactingRef) {
|
|
5125
|
+
const clearFlag = () => {
|
|
5126
|
+
interactingRef.current = false;
|
|
5127
|
+
};
|
|
5128
|
+
window.addEventListener("click", clearFlag, { once: true });
|
|
5129
|
+
setTimeout(() => {
|
|
5130
|
+
window.removeEventListener("click", clearFlag);
|
|
5131
|
+
interactingRef.current = false;
|
|
5132
|
+
}, 0);
|
|
5133
|
+
}
|
|
5123
5134
|
};
|
|
5124
5135
|
window.addEventListener("mousemove", move);
|
|
5125
5136
|
window.addEventListener("mouseup", up);
|
|
5126
5137
|
},
|
|
5127
|
-
[onMove, onEnd]
|
|
5138
|
+
[onMove, onEnd, interactingRef]
|
|
5128
5139
|
);
|
|
5129
5140
|
return start;
|
|
5130
5141
|
}
|
|
5131
5142
|
var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
5132
5143
|
const [open, setOpen] = React6__namespace.useState(false);
|
|
5133
5144
|
const btnRef = React6__namespace.useRef(null);
|
|
5145
|
+
const interactingRef = React6__namespace.useRef(false);
|
|
5146
|
+
const handleDismiss = React6__namespace.useCallback(() => setOpen(false), []);
|
|
5147
|
+
const preventDismissOnEvent = React6__namespace.useCallback(
|
|
5148
|
+
(ev) => {
|
|
5149
|
+
if (interactingRef.current) return true;
|
|
5150
|
+
return ev.type !== "click";
|
|
5151
|
+
},
|
|
5152
|
+
[]
|
|
5153
|
+
);
|
|
5154
|
+
const [, forceReposition] = React6__namespace.useState(0);
|
|
5155
|
+
React6__namespace.useEffect(() => {
|
|
5156
|
+
if (!open) return;
|
|
5157
|
+
let rafId = null;
|
|
5158
|
+
const reposition = () => {
|
|
5159
|
+
if (rafId != null) return;
|
|
5160
|
+
rafId = requestAnimationFrame(() => {
|
|
5161
|
+
rafId = null;
|
|
5162
|
+
forceReposition((n) => n + 1);
|
|
5163
|
+
});
|
|
5164
|
+
};
|
|
5165
|
+
window.addEventListener("scroll", reposition, true);
|
|
5166
|
+
window.addEventListener("resize", reposition);
|
|
5167
|
+
return () => {
|
|
5168
|
+
if (rafId != null) cancelAnimationFrame(rafId);
|
|
5169
|
+
window.removeEventListener("scroll", reposition, true);
|
|
5170
|
+
window.removeEventListener("resize", reposition);
|
|
5171
|
+
};
|
|
5172
|
+
}, [open]);
|
|
5134
5173
|
const [hex, setHex] = React6__namespace.useState(normalizeHex(value || "#000000"));
|
|
5135
5174
|
const { r, g, b } = React6__namespace.useMemo(() => hexToRgb(hex), [hex]);
|
|
5136
5175
|
const hsv = React6__namespace.useMemo(() => rgbToHsv(r, g, b), [r, g, b]);
|
|
@@ -5171,7 +5210,7 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5171
5210
|
},
|
|
5172
5211
|
[h, commitHsv]
|
|
5173
5212
|
);
|
|
5174
|
-
const startSV = useDrag(onSVMove);
|
|
5213
|
+
const startSV = useDrag(onSVMove, void 0, interactingRef);
|
|
5175
5214
|
const hueRef = React6__namespace.useRef(null);
|
|
5176
5215
|
const onHueMove = React6__namespace.useCallback(
|
|
5177
5216
|
(clientX) => {
|
|
@@ -5184,7 +5223,7 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5184
5223
|
},
|
|
5185
5224
|
[s, v, commitHsv]
|
|
5186
5225
|
);
|
|
5187
|
-
const startHue = useDrag((x) => onHueMove(x));
|
|
5226
|
+
const startHue = useDrag((x) => onHueMove(x), void 0, interactingRef);
|
|
5188
5227
|
const svThumb = React6__namespace.useMemo(() => ({ left: `${s * 100}%`, top: `${(1 - v) * 100}%` }), [s, v]);
|
|
5189
5228
|
const hueThumb = React6__namespace.useMemo(() => ({ left: `${h / 360 * 100}%` }), [h]);
|
|
5190
5229
|
const hueColor = React6__namespace.useMemo(() => {
|
|
@@ -5233,10 +5272,11 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon }) => {
|
|
|
5233
5272
|
react.Callout,
|
|
5234
5273
|
{
|
|
5235
5274
|
target: btnRef,
|
|
5236
|
-
onDismiss:
|
|
5275
|
+
onDismiss: handleDismiss,
|
|
5237
5276
|
setInitialFocus: true,
|
|
5238
5277
|
directionalHint: 4,
|
|
5239
5278
|
className: "aoColorCallout",
|
|
5279
|
+
preventDismissOnEvent,
|
|
5240
5280
|
children: /* @__PURE__ */ jsxRuntime.jsxs(react.Stack, { tokens: { childrenGap: 10 }, styles: { root: { padding: 12, width: 320 } }, children: [
|
|
5241
5281
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "aoLexRow", children: [
|
|
5242
5282
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "aoLexSwatch", style: { background: hex } }),
|