@coze-editor/react-hooks 0.1.0-alpha.09ffeb
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 -0
- package/dist/esm/index.js +567 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +78 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +605 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
createPortalConnector: () => createPortalConnector,
|
|
33
|
+
useChangeListener: () => useChangeListener,
|
|
34
|
+
useCompartment: () => useCompartment,
|
|
35
|
+
useDocumentListener: () => useDocumentListener,
|
|
36
|
+
useDocumentSelector: () => useDocumentSelector,
|
|
37
|
+
useEditorEvent: () => useEditorEvent,
|
|
38
|
+
useFocused: () => useFocused,
|
|
39
|
+
useHTMLElement: () => useHTMLElement,
|
|
40
|
+
useHistoryState: () => useHistoryState,
|
|
41
|
+
useInjectorEffect: () => useInjectorEffect,
|
|
42
|
+
useLatest: () => useLatest,
|
|
43
|
+
useMouseSelectionPopup: () => useMouseSelectionPopup,
|
|
44
|
+
usePortalConnector: () => usePortalConnector,
|
|
45
|
+
useRangesManager: () => useRangesManager,
|
|
46
|
+
useStateField: () => useStateField
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(index_exports);
|
|
49
|
+
|
|
50
|
+
// src/hooks/use-state-field.ts
|
|
51
|
+
var import_react = require("react");
|
|
52
|
+
var import_react2 = require("@coze-editor/react");
|
|
53
|
+
var import_state = require("@codemirror/state");
|
|
54
|
+
function useStateField(create, update) {
|
|
55
|
+
const editor = (0, import_react2.useEditor)();
|
|
56
|
+
const [effect] = (0, import_react.useState)(() => import_state.StateEffect.define());
|
|
57
|
+
const updateRef = (0, import_react.useRef)();
|
|
58
|
+
updateRef.current = update;
|
|
59
|
+
const [field3] = (0, import_react.useState)(
|
|
60
|
+
() => import_state.StateField.define({
|
|
61
|
+
create(state) {
|
|
62
|
+
return create(state);
|
|
63
|
+
},
|
|
64
|
+
update(value, tr) {
|
|
65
|
+
if (typeof updateRef.current === "function") {
|
|
66
|
+
value = updateRef.current(value, tr);
|
|
67
|
+
}
|
|
68
|
+
for (const trEffect of tr.effects) {
|
|
69
|
+
if (trEffect.is(effect)) {
|
|
70
|
+
return trEffect.value;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
);
|
|
77
|
+
(0, import_react.useEffect)(() => {
|
|
78
|
+
if (!editor) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
editor.$view.dispatch({
|
|
82
|
+
effects: effect.of(create(editor.$view.state))
|
|
83
|
+
});
|
|
84
|
+
}, [editor, effect, create]);
|
|
85
|
+
return field3;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// src/hooks/use-ranges-manager.ts
|
|
89
|
+
var import_react3 = require("react");
|
|
90
|
+
var import_react4 = require("@coze-editor/react");
|
|
91
|
+
var import_view = require("@codemirror/view");
|
|
92
|
+
var import_state2 = require("@codemirror/state");
|
|
93
|
+
var import_commands = require("@codemirror/commands");
|
|
94
|
+
var IDValue = class extends import_view.Decoration {
|
|
95
|
+
id;
|
|
96
|
+
constructor(spec) {
|
|
97
|
+
const { start, end } = getInclusive(spec);
|
|
98
|
+
super(
|
|
99
|
+
start ? -1 /* InlineIncStart */ : 5e8 /* NonIncStart */,
|
|
100
|
+
end ? 1 /* InlineIncEnd */ : -6e8 /* NonIncEnd */,
|
|
101
|
+
null,
|
|
102
|
+
spec
|
|
103
|
+
);
|
|
104
|
+
this.id = spec.id ?? "";
|
|
105
|
+
}
|
|
106
|
+
eq(other) {
|
|
107
|
+
return this.id === other.id;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
function getInclusive(spec, block = false) {
|
|
111
|
+
let { inclusiveStart: start, inclusiveEnd: end } = spec;
|
|
112
|
+
if (start == null) {
|
|
113
|
+
start = spec.inclusive;
|
|
114
|
+
}
|
|
115
|
+
if (end == null) {
|
|
116
|
+
end = spec.inclusive;
|
|
117
|
+
}
|
|
118
|
+
return { start: start ?? block, end: end ?? block };
|
|
119
|
+
}
|
|
120
|
+
var addEffect = import_state2.StateEffect.define({
|
|
121
|
+
map: (specs, change) => specs.map(({ from, to, ...rest }) => ({
|
|
122
|
+
from: change.mapPos(from),
|
|
123
|
+
to: change.mapPos(to),
|
|
124
|
+
...rest
|
|
125
|
+
}))
|
|
126
|
+
});
|
|
127
|
+
var removeEffect = import_state2.StateEffect.define();
|
|
128
|
+
var recoverEffect = import_state2.StateEffect.define();
|
|
129
|
+
var facet = import_state2.Facet.define();
|
|
130
|
+
function toRangeSet(specs) {
|
|
131
|
+
specs.sort((a, b) => a.from - b.from);
|
|
132
|
+
const builder = new import_state2.RangeSetBuilder();
|
|
133
|
+
for (const spec of specs) {
|
|
134
|
+
builder.add(
|
|
135
|
+
spec.from,
|
|
136
|
+
spec.to,
|
|
137
|
+
new IDValue({
|
|
138
|
+
id: spec.id
|
|
139
|
+
})
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return builder.finish();
|
|
143
|
+
}
|
|
144
|
+
function toSpecs(ranges) {
|
|
145
|
+
const specs = [];
|
|
146
|
+
const cursor = ranges.iter();
|
|
147
|
+
while (cursor.value) {
|
|
148
|
+
specs.push({
|
|
149
|
+
from: cursor.from,
|
|
150
|
+
to: cursor.to,
|
|
151
|
+
id: cursor.value.id
|
|
152
|
+
});
|
|
153
|
+
cursor.next();
|
|
154
|
+
}
|
|
155
|
+
return specs;
|
|
156
|
+
}
|
|
157
|
+
function useRangesManager() {
|
|
158
|
+
const injector = (0, import_react4.useInjector)();
|
|
159
|
+
const editor = (0, import_react4.useEditor)();
|
|
160
|
+
const watchersRef = (0, import_react3.useRef)([]);
|
|
161
|
+
const viewRef = (0, import_react3.useRef)(null);
|
|
162
|
+
viewRef.current = editor == null ? void 0 : editor.$view;
|
|
163
|
+
const rangesStashRef = (0, import_react3.useRef)([]);
|
|
164
|
+
(0, import_react3.useEffect)(() => {
|
|
165
|
+
if (!editor) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const field3 = import_state2.StateField.define({
|
|
169
|
+
create() {
|
|
170
|
+
if (rangesStashRef.current) {
|
|
171
|
+
return toRangeSet(rangesStashRef.current);
|
|
172
|
+
}
|
|
173
|
+
return import_state2.RangeSet.empty;
|
|
174
|
+
},
|
|
175
|
+
update(set, tr) {
|
|
176
|
+
set = set.map(tr.changes);
|
|
177
|
+
for (const effect of tr.effects) {
|
|
178
|
+
if (effect.is(addEffect)) {
|
|
179
|
+
const specs = effect.value ?? [];
|
|
180
|
+
set = set.update({
|
|
181
|
+
add: specs.map(
|
|
182
|
+
(spec) => new IDValue({ id: spec.id }).range(spec.from, spec.to)
|
|
183
|
+
)
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
if (effect.is(removeEffect)) {
|
|
187
|
+
const ids = effect.value;
|
|
188
|
+
set = set.update({
|
|
189
|
+
filter(from, to, value) {
|
|
190
|
+
return !ids.includes(value.id);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if (effect.is(recoverEffect)) {
|
|
195
|
+
const specs = effect.value ?? [];
|
|
196
|
+
const ids = specs.map((spec) => spec.id);
|
|
197
|
+
set = set.update({
|
|
198
|
+
filter(from, to, value) {
|
|
199
|
+
return !ids.includes(value.id);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
set = set.update({
|
|
203
|
+
add: specs.map(
|
|
204
|
+
(spec) => new IDValue({ id: spec.id }).range(spec.from, spec.to)
|
|
205
|
+
)
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return set;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
const invertable = import_commands.invertedEffects.of((tr) => {
|
|
213
|
+
const effects = [];
|
|
214
|
+
const ranges = tr.startState.field(field3);
|
|
215
|
+
tr.changes.iterChangedRanges((from, to) => {
|
|
216
|
+
ranges.between(from, to, (rangeFrom, rangeTo, value) => {
|
|
217
|
+
const f = Math.max(from, rangeFrom);
|
|
218
|
+
const t = Math.min(to, rangeTo);
|
|
219
|
+
if (f < t) {
|
|
220
|
+
effects.push(
|
|
221
|
+
recoverEffect.of([
|
|
222
|
+
{ from: rangeFrom, to: rangeTo, id: value.id }
|
|
223
|
+
])
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
return effects;
|
|
229
|
+
});
|
|
230
|
+
let isFirstTime = true;
|
|
231
|
+
return injector.inject([
|
|
232
|
+
field3,
|
|
233
|
+
invertable,
|
|
234
|
+
facet.compute([field3], (state) => {
|
|
235
|
+
if (isFirstTime) {
|
|
236
|
+
isFirstTime = false;
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const set = state.field(field3);
|
|
240
|
+
if (Array.isArray(watchersRef.current) && watchersRef.current.length > 0) {
|
|
241
|
+
const specs = toSpecs(set);
|
|
242
|
+
for (const watcher of watchersRef.current) {
|
|
243
|
+
watcher(specs);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
]);
|
|
248
|
+
}, [editor]);
|
|
249
|
+
return {
|
|
250
|
+
add(specs) {
|
|
251
|
+
if (!viewRef.current) {
|
|
252
|
+
rangesStashRef.current.push(...specs);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
viewRef.current.dispatch({
|
|
256
|
+
effects: addEffect.of(specs)
|
|
257
|
+
});
|
|
258
|
+
},
|
|
259
|
+
remove(ids) {
|
|
260
|
+
if (!viewRef.current) {
|
|
261
|
+
rangesStashRef.current = rangesStashRef.current.filter(
|
|
262
|
+
(item) => !ids.includes(item.id)
|
|
263
|
+
);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
viewRef.current.dispatch({
|
|
267
|
+
effects: removeEffect.of(ids)
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
watch(watcher) {
|
|
271
|
+
watchersRef.current.push(watcher);
|
|
272
|
+
return () => {
|
|
273
|
+
watchersRef.current = watchersRef.current.filter((w) => w !== watcher);
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// src/hooks/use-focused.ts
|
|
280
|
+
var import_react5 = require("react");
|
|
281
|
+
var import_react6 = require("@coze-editor/react");
|
|
282
|
+
var import_view2 = require("@codemirror/view");
|
|
283
|
+
function useFocused() {
|
|
284
|
+
const injector = (0, import_react6.useInjector)();
|
|
285
|
+
const [focused, setFocused] = (0, import_react5.useState)(false);
|
|
286
|
+
const focusedRef = (0, import_react5.useRef)(focused);
|
|
287
|
+
(0, import_react5.useLayoutEffect)(
|
|
288
|
+
() => injector.inject(
|
|
289
|
+
[
|
|
290
|
+
import_view2.EditorView.updateListener.of((update) => {
|
|
291
|
+
if (focusedRef.current !== update.view.hasFocus) {
|
|
292
|
+
setFocused(update.view.hasFocus);
|
|
293
|
+
focusedRef.current = update.view.hasFocus;
|
|
294
|
+
}
|
|
295
|
+
})
|
|
296
|
+
],
|
|
297
|
+
import_react6.InjectPosition.Tail
|
|
298
|
+
),
|
|
299
|
+
[injector, setFocused]
|
|
300
|
+
);
|
|
301
|
+
return focused;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// src/hooks/use-injector-effect.ts
|
|
305
|
+
var import_react7 = require("react");
|
|
306
|
+
var import_react8 = require("@coze-editor/react");
|
|
307
|
+
function useInjectorEffect(handler, deps = []) {
|
|
308
|
+
const injector = (0, import_react8.useInjector)();
|
|
309
|
+
(0, import_react7.useLayoutEffect)(() => handler(injector), [injector, ...deps]);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// src/hooks/use-html-element.ts
|
|
313
|
+
var import_react9 = require("react");
|
|
314
|
+
function useHTMLElement(defaultTagName = "div") {
|
|
315
|
+
const [element] = (0, import_react9.useState)(() => document.createElement(defaultTagName));
|
|
316
|
+
return element;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// src/hooks/use-compartment.ts
|
|
320
|
+
var import_react10 = require("react");
|
|
321
|
+
var import_state3 = require("@codemirror/state");
|
|
322
|
+
function useCompartment() {
|
|
323
|
+
const [compartment] = (0, import_react10.useState)(() => new import_state3.Compartment());
|
|
324
|
+
return compartment;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// src/hooks/use-latest.ts
|
|
328
|
+
var import_react11 = require("react");
|
|
329
|
+
function useLatest(value) {
|
|
330
|
+
const ref = (0, import_react11.useRef)(value);
|
|
331
|
+
ref.current = value;
|
|
332
|
+
return ref;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// src/hooks/use-change-listener.tsx
|
|
336
|
+
var import_view3 = require("@codemirror/view");
|
|
337
|
+
function useChangeListener(listener) {
|
|
338
|
+
const listenerRef = useLatest(listener);
|
|
339
|
+
useInjectorEffect(
|
|
340
|
+
(injector) => injector.inject([
|
|
341
|
+
import_view3.EditorView.updateListener.of((update) => {
|
|
342
|
+
if (update.docChanged && typeof listenerRef.current === "function") {
|
|
343
|
+
update.changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
|
|
344
|
+
listenerRef.current({
|
|
345
|
+
change: [fromA, toA, fromB, toB, inserted],
|
|
346
|
+
view: update.view
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
})
|
|
351
|
+
]),
|
|
352
|
+
[]
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// src/hooks/use-document-selector.ts
|
|
357
|
+
var import_react12 = require("react");
|
|
358
|
+
var import_state4 = require("@codemirror/state");
|
|
359
|
+
var field = import_state4.StateField.define({
|
|
360
|
+
create(state) {
|
|
361
|
+
return state.doc;
|
|
362
|
+
},
|
|
363
|
+
update(value, tr) {
|
|
364
|
+
if (tr.docChanged) {
|
|
365
|
+
value = tr.state.doc;
|
|
366
|
+
}
|
|
367
|
+
return value;
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
var facet2 = import_state4.Facet.define();
|
|
371
|
+
function useDocumentSelector(selector, defaultValue) {
|
|
372
|
+
const [state, setState] = (0, import_react12.useState)(defaultValue);
|
|
373
|
+
const stateRef = useLatest(state);
|
|
374
|
+
const setStateRef = useLatest(setState);
|
|
375
|
+
const selectorRef = useLatest(selector);
|
|
376
|
+
useInjectorEffect(
|
|
377
|
+
(injector) => injector.inject([
|
|
378
|
+
field,
|
|
379
|
+
facet2.compute([field], (state2) => {
|
|
380
|
+
const derived = selectorRef.current(state2.field(field));
|
|
381
|
+
if (stateRef.current !== derived) {
|
|
382
|
+
setStateRef.current(derived);
|
|
383
|
+
}
|
|
384
|
+
})
|
|
385
|
+
]),
|
|
386
|
+
[]
|
|
387
|
+
);
|
|
388
|
+
return state;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// src/hooks/use-document-listener.ts
|
|
392
|
+
var import_state5 = require("@codemirror/state");
|
|
393
|
+
var field2 = import_state5.StateField.define({
|
|
394
|
+
create(state) {
|
|
395
|
+
return state.doc;
|
|
396
|
+
},
|
|
397
|
+
update(value, tr) {
|
|
398
|
+
if (tr.docChanged) {
|
|
399
|
+
value = tr.state.doc;
|
|
400
|
+
}
|
|
401
|
+
return value;
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
var facet3 = import_state5.Facet.define();
|
|
405
|
+
function useDocumentListener(listener) {
|
|
406
|
+
const listenerRef = useLatest(listener);
|
|
407
|
+
useInjectorEffect(
|
|
408
|
+
(injector) => injector.inject([
|
|
409
|
+
field2,
|
|
410
|
+
facet3.compute([field2], (state) => {
|
|
411
|
+
listenerRef.current(state.field(field2));
|
|
412
|
+
})
|
|
413
|
+
]),
|
|
414
|
+
[]
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// src/hooks/use-portal-connector.tsx
|
|
419
|
+
var import_react_dom = require("react-dom");
|
|
420
|
+
var import_react13 = __toESM(require("react"));
|
|
421
|
+
function flush(fn, options) {
|
|
422
|
+
if (options.sync) {
|
|
423
|
+
queueMicrotask(() => {
|
|
424
|
+
(0, import_react_dom.flushSync)(fn);
|
|
425
|
+
});
|
|
426
|
+
} else {
|
|
427
|
+
fn();
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
function createPortalConnector(options) {
|
|
431
|
+
let add = (id, portal) => {
|
|
432
|
+
};
|
|
433
|
+
let remove = (id) => {
|
|
434
|
+
};
|
|
435
|
+
function connect(id, portal) {
|
|
436
|
+
add(id, portal);
|
|
437
|
+
}
|
|
438
|
+
function disconnect(id) {
|
|
439
|
+
remove(id);
|
|
440
|
+
}
|
|
441
|
+
function Portal() {
|
|
442
|
+
const [items, setItems] = (0, import_react13.useState)([]);
|
|
443
|
+
const addItem = (0, import_react13.useCallback)((id, portal) => {
|
|
444
|
+
flush(
|
|
445
|
+
() => {
|
|
446
|
+
setItems((prevItems) => {
|
|
447
|
+
const nextItems = [...prevItems];
|
|
448
|
+
const index = nextItems.findIndex((item) => item.id === id);
|
|
449
|
+
if (index > -1) {
|
|
450
|
+
nextItems[index] = { id, portal };
|
|
451
|
+
} else {
|
|
452
|
+
nextItems.push({ id, portal });
|
|
453
|
+
}
|
|
454
|
+
return nextItems;
|
|
455
|
+
});
|
|
456
|
+
},
|
|
457
|
+
{ sync: (options == null ? void 0 : options.sync) ?? false }
|
|
458
|
+
);
|
|
459
|
+
}, []);
|
|
460
|
+
const removeItem = (0, import_react13.useCallback)((id) => {
|
|
461
|
+
flush(
|
|
462
|
+
() => {
|
|
463
|
+
setItems((oldItems) => oldItems.filter((item) => item.id !== id));
|
|
464
|
+
},
|
|
465
|
+
{ sync: (options == null ? void 0 : options.sync) ?? false }
|
|
466
|
+
);
|
|
467
|
+
}, []);
|
|
468
|
+
add = addItem;
|
|
469
|
+
remove = removeItem;
|
|
470
|
+
return /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, items.map((item) => item.portal));
|
|
471
|
+
}
|
|
472
|
+
return {
|
|
473
|
+
connect,
|
|
474
|
+
disconnect,
|
|
475
|
+
Portal
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
function usePortalConnector(options) {
|
|
479
|
+
const [connector] = (0, import_react13.useState)(() => createPortalConnector(options));
|
|
480
|
+
return connector;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// src/hooks/use-editor-event.ts
|
|
484
|
+
var import_react14 = require("react");
|
|
485
|
+
function useEditorEvent(editor, eventName, handler) {
|
|
486
|
+
(0, import_react14.useEffect)(() => {
|
|
487
|
+
if (!editor) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
editor.$on(eventName, handler);
|
|
491
|
+
return () => {
|
|
492
|
+
editor.$off(eventName, handler);
|
|
493
|
+
};
|
|
494
|
+
}, [editor, eventName, handler]);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// src/hooks/use-history-state.ts
|
|
498
|
+
var import_react15 = require("react");
|
|
499
|
+
var import_state6 = require("@codemirror/state");
|
|
500
|
+
var import_commands2 = require("@codemirror/commands");
|
|
501
|
+
var facet4 = import_state6.Facet.define();
|
|
502
|
+
function useHistoryState() {
|
|
503
|
+
const [canUndo, setCanUndo] = (0, import_react15.useState)(false);
|
|
504
|
+
const [canRedo, setCanRedo] = (0, import_react15.useState)(false);
|
|
505
|
+
const setCanUndoRef = useLatest(setCanUndo);
|
|
506
|
+
const setCanRedoRef = useLatest(setCanRedo);
|
|
507
|
+
useInjectorEffect(
|
|
508
|
+
(injector) => injector.inject([
|
|
509
|
+
facet4.compute([import_commands2.historyField], (state) => {
|
|
510
|
+
setCanUndoRef.current(() => (0, import_commands2.undoDepth)(state) > 0);
|
|
511
|
+
setCanRedoRef.current(() => (0, import_commands2.redoDepth)(state) > 0);
|
|
512
|
+
})
|
|
513
|
+
])
|
|
514
|
+
);
|
|
515
|
+
return {
|
|
516
|
+
canUndo,
|
|
517
|
+
canRedo
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// src/hooks/use-mouse-selection-popup.ts
|
|
522
|
+
var import_react16 = require("react");
|
|
523
|
+
var import_react17 = require("@coze-editor/react");
|
|
524
|
+
function useMouseSelectionPopup() {
|
|
525
|
+
const editor = (0, import_react17.useEditor)();
|
|
526
|
+
const [visible, setVisible] = (0, import_react16.useState)(false);
|
|
527
|
+
const [selection, setSelection] = (0, import_react16.useState)(null);
|
|
528
|
+
(0, import_react16.useEffect)(() => {
|
|
529
|
+
if (!editor) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
function handleMousedown() {
|
|
533
|
+
setVisible(false);
|
|
534
|
+
}
|
|
535
|
+
function handleMouseup() {
|
|
536
|
+
setTimeout(() => {
|
|
537
|
+
const cmSelection = editor.$view.state.selection.main;
|
|
538
|
+
if (!cmSelection) {
|
|
539
|
+
setVisible(false);
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
const isRange = cmSelection.from !== cmSelection.to;
|
|
543
|
+
if (!isRange) {
|
|
544
|
+
setVisible(false);
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
setSelection({
|
|
548
|
+
from: cmSelection.from,
|
|
549
|
+
to: cmSelection.to,
|
|
550
|
+
anchor: cmSelection.anchor,
|
|
551
|
+
head: cmSelection.head
|
|
552
|
+
});
|
|
553
|
+
setTimeout(() => {
|
|
554
|
+
setVisible(true);
|
|
555
|
+
}, 50);
|
|
556
|
+
}, 50);
|
|
557
|
+
}
|
|
558
|
+
function handleSelectionChange() {
|
|
559
|
+
setVisible(false);
|
|
560
|
+
}
|
|
561
|
+
function handleBlur() {
|
|
562
|
+
setVisible(false);
|
|
563
|
+
}
|
|
564
|
+
editor.$on("mousedown", handleMousedown);
|
|
565
|
+
editor.$on("mouseup", handleMouseup);
|
|
566
|
+
editor.$on("selectionChange", handleSelectionChange);
|
|
567
|
+
editor.$on("blur", handleBlur);
|
|
568
|
+
return () => {
|
|
569
|
+
editor.$off("mousedown", handleMousedown);
|
|
570
|
+
editor.$off("mouseup", handleMouseup);
|
|
571
|
+
editor.$off("selectionChange", handleSelectionChange);
|
|
572
|
+
editor.$off("blur", handleBlur);
|
|
573
|
+
};
|
|
574
|
+
}, [editor]);
|
|
575
|
+
const anchor = (selection == null ? void 0 : selection.anchor) ?? -1;
|
|
576
|
+
const head = (selection == null ? void 0 : selection.head) ?? -1;
|
|
577
|
+
const from = (selection == null ? void 0 : selection.from) ?? -1;
|
|
578
|
+
const to = (selection == null ? void 0 : selection.to) ?? -1;
|
|
579
|
+
return {
|
|
580
|
+
anchor,
|
|
581
|
+
head,
|
|
582
|
+
from,
|
|
583
|
+
to,
|
|
584
|
+
visible
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
588
|
+
0 && (module.exports = {
|
|
589
|
+
createPortalConnector,
|
|
590
|
+
useChangeListener,
|
|
591
|
+
useCompartment,
|
|
592
|
+
useDocumentListener,
|
|
593
|
+
useDocumentSelector,
|
|
594
|
+
useEditorEvent,
|
|
595
|
+
useFocused,
|
|
596
|
+
useHTMLElement,
|
|
597
|
+
useHistoryState,
|
|
598
|
+
useInjectorEffect,
|
|
599
|
+
useLatest,
|
|
600
|
+
useMouseSelectionPopup,
|
|
601
|
+
usePortalConnector,
|
|
602
|
+
useRangesManager,
|
|
603
|
+
useStateField
|
|
604
|
+
});
|
|
605
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/hooks/use-state-field.ts","../src/hooks/use-ranges-manager.ts","../src/hooks/use-focused.ts","../src/hooks/use-injector-effect.ts","../src/hooks/use-html-element.ts","../src/hooks/use-compartment.ts","../src/hooks/use-latest.ts","../src/hooks/use-change-listener.tsx","../src/hooks/use-document-selector.ts","../src/hooks/use-document-listener.ts","../src/hooks/use-portal-connector.tsx","../src/hooks/use-editor-event.ts","../src/hooks/use-history-state.ts","../src/hooks/use-mouse-selection-popup.ts"],"sourcesContent":["// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nexport {\n useRangesManager,\n useFocused,\n useChangeListener,\n useDocumentSelector,\n useDocumentListener,\n useLatest,\n usePortalConnector,\n createPortalConnector,\n useEditorEvent,\n // TODO: 考虑私有至使用的地方\n useHTMLElement,\n useInjectorEffect,\n useStateField,\n useCompartment,\n useHistoryState,\n useMouseSelectionPopup,\n} from './hooks';\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { useEffect, useRef, useState } from 'react';\n\nimport { type BuiltinEditorAPI, useEditor } from '@coze-editor/react';\nimport {\n type EditorState,\n StateEffect,\n StateField,\n type Transaction,\n} from '@codemirror/state';\n\nfunction useStateField<T = unknown>(\n create: (state: EditorState) => T,\n update?: (value: T, tr: Transaction) => T,\n) {\n const editor = useEditor<BuiltinEditorAPI>();\n\n const [effect] = useState(() => StateEffect.define<T>());\n\n const updateRef = useRef<((value: T, tr: Transaction) => T) | undefined>();\n updateRef.current = update;\n\n const [field] = useState<StateField<T>>(() =>\n StateField.define({\n create(state) {\n return create(state);\n },\n update(value, tr) {\n if (typeof updateRef.current === 'function') {\n value = updateRef.current(value, tr);\n }\n\n for (const trEffect of tr.effects) {\n if (trEffect.is(effect)) {\n return trEffect.value;\n }\n }\n\n return value;\n },\n }),\n );\n\n useEffect(() => {\n if (!editor) {\n return;\n }\n\n editor.$view.dispatch({\n effects: effect.of(create(editor.$view.state)),\n });\n }, [editor, effect, create]);\n\n return field;\n}\n\nexport { useStateField };\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { useEffect, useRef } from 'react';\n\nimport {\n type BuiltinEditorAPI,\n useEditor,\n useInjector,\n} from '@coze-editor/react';\nimport { Decoration, type EditorView } from '@codemirror/view';\nimport {\n Facet,\n RangeSet,\n RangeSetBuilder,\n StateEffect,\n StateField,\n} from '@codemirror/state';\nimport { invertedEffects } from '@codemirror/commands';\n\ninterface IDValueSpec {\n /// Whether the mark covers its start and end position or not. This\n /// influences whether content inserted at those positions becomes\n /// part of the mark. Defaults to false.\n inclusive?: boolean;\n /// Specify whether the start position of the marked range should be\n /// inclusive. Overrides `inclusive`, when both are present.\n inclusiveStart?: boolean;\n /// Whether the end should be inclusive.\n inclusiveEnd?: boolean;\n id?: string;\n [other: string]: any;\n}\n\nconst enum Side {\n NonIncEnd = -6e8, // (end of non-inclusive range)\n GapStart = -5e8,\n BlockBefore = -4e8, // + widget side option (block widget before)\n BlockIncStart = -3e8, // (start of inclusive block range)\n Line = -2e8, // (line widget)\n InlineBefore = -1e8, // + widget side (inline widget before)\n InlineIncStart = -1, // (start of inclusive inline range)\n InlineIncEnd = 1, // (end of inclusive inline range)\n InlineAfter = 1e8, // + widget side (inline widget after)\n BlockIncEnd = 2e8, // (end of inclusive block range)\n BlockAfter = 3e8, // + widget side (block widget after)\n GapEnd = 4e8,\n NonIncStart = 5e8, // (start of non-inclusive range)\n}\n\nclass IDValue extends Decoration {\n public id: string;\n\n constructor(spec: IDValueSpec) {\n const { start, end } = getInclusive(spec);\n\n super(\n start ? Side.InlineIncStart : Side.NonIncStart,\n end ? Side.InlineIncEnd : Side.NonIncEnd,\n null,\n spec,\n );\n\n this.id = spec.id ?? '';\n }\n\n eq(other: Decoration): boolean {\n return this.id === (other as IDValue).id;\n }\n}\n\nfunction getInclusive(\n spec: {\n inclusive?: boolean;\n inclusiveStart?: boolean;\n inclusiveEnd?: boolean;\n },\n block = false,\n): { start: boolean; end: boolean } {\n let { inclusiveStart: start, inclusiveEnd: end } = spec;\n if (start == null) {\n start = spec.inclusive;\n }\n if (end == null) {\n end = spec.inclusive;\n }\n return { start: start ?? block, end: end ?? block };\n}\n\nconst addEffect = StateEffect.define<IDRangeSpec[]>({\n map: (specs, change) =>\n specs.map(({ from, to, ...rest }) => ({\n from: change.mapPos(from),\n to: change.mapPos(to),\n ...rest,\n })),\n});\nconst removeEffect = StateEffect.define<string[]>();\nconst recoverEffect = StateEffect.define<IDRangeSpec[]>();\n\nconst facet = Facet.define();\n\ninterface IDRangeSpec {\n from: number;\n to: number;\n id: string;\n}\n\nfunction toRangeSet(specs: IDRangeSpec[]) {\n specs.sort((a, b) => a.from - b.from);\n\n const builder = new RangeSetBuilder<Decoration>();\n for (const spec of specs) {\n builder.add(\n spec.from,\n spec.to,\n new IDValue({\n id: spec.id,\n }),\n );\n }\n return builder.finish();\n}\n\nfunction toSpecs(ranges: RangeSet<IDValue>): IDRangeSpec[] {\n const specs: IDRangeSpec[] = [];\n const cursor = ranges.iter();\n\n while (cursor.value) {\n specs.push({\n from: cursor.from,\n to: cursor.to,\n id: cursor.value.id,\n });\n cursor.next();\n }\n\n return specs;\n}\n\ntype Watcher = (specs: IDRangeSpec[]) => void;\n\nfunction useRangesManager() {\n const injector = useInjector();\n const editor = useEditor<BuiltinEditorAPI>();\n\n const watchersRef = useRef<Watcher[]>([]);\n\n const viewRef = useRef<EditorView | null>(null);\n viewRef.current = editor?.$view;\n const rangesStashRef = useRef<IDRangeSpec[]>([]);\n\n useEffect(() => {\n if (!editor) {\n return;\n }\n\n const field = StateField.define<RangeSet<IDValue>>({\n create() {\n if (rangesStashRef.current) {\n return toRangeSet(rangesStashRef.current);\n }\n return RangeSet.empty;\n },\n update(set, tr) {\n set = set.map(tr.changes);\n\n for (const effect of tr.effects) {\n if (effect.is(addEffect)) {\n const specs = effect.value ?? [];\n set = set.update({\n add: specs.map(spec =>\n new IDValue({ id: spec.id }).range(spec.from, spec.to),\n ),\n });\n }\n\n if (effect.is(removeEffect)) {\n const ids = effect.value;\n set = set.update({\n filter(from, to, value) {\n return !ids.includes(value.id);\n },\n });\n }\n\n if (effect.is(recoverEffect)) {\n const specs = effect.value ?? [];\n const ids = specs.map(spec => spec.id);\n set = set.update({\n filter(from, to, value) {\n return !ids.includes(value.id);\n },\n });\n set = set.update({\n add: specs.map(spec =>\n new IDValue({ id: spec.id }).range(spec.from, spec.to),\n ),\n });\n }\n }\n\n return set;\n },\n });\n\n const invertable = invertedEffects.of(tr => {\n const effects: StateEffect<unknown>[] = [];\n\n const ranges = tr.startState.field(field);\n // const length = tr.startState.doc.length\n\n // make effect undoable(save effects of this tr in undo/redo stack)\n // for (const effect of tr.effects) {\n // if (effect.is(addEffect)) {\n // const specs = effect.value ?? []\n // effects.push(\n // removeEffect.of(\n // specs.map(spec => spec.id)\n // )\n // )\n // }\n\n // if (effect.is(removeEffect)) {\n // const ids = effect.value\n // const specs = []\n // ranges.between(0, length, (from, to, value) => {\n // if (ids.includes(value.id)) {\n // specs.push({\n // from,\n // to,\n // id: value.id\n // })\n // }\n // })\n\n // effects.push(\n // addEffect.of(\n // specs\n // )\n // )\n // }\n // }\n\n tr.changes.iterChangedRanges((from, to) => {\n ranges.between(from, to, (rangeFrom, rangeTo, value) => {\n const f = Math.max(from, rangeFrom);\n const t = Math.min(to, rangeTo);\n\n // has overlapped parts\n if (f < t) {\n effects.push(\n recoverEffect.of([\n { from: rangeFrom, to: rangeTo, id: value.id },\n ]),\n );\n }\n });\n });\n\n return effects;\n });\n\n let isFirstTime = true;\n\n return injector.inject([\n field,\n invertable,\n facet.compute([field], state => {\n if (isFirstTime) {\n isFirstTime = false;\n return;\n }\n\n const set = state.field(field);\n if (\n Array.isArray(watchersRef.current) &&\n watchersRef.current.length > 0\n ) {\n const specs = toSpecs(set);\n for (const watcher of watchersRef.current) {\n watcher(specs);\n }\n }\n }),\n ]);\n }, [editor]);\n\n return {\n add(specs: IDRangeSpec[]) {\n if (!viewRef.current) {\n rangesStashRef.current.push(...specs);\n return;\n }\n\n viewRef.current.dispatch({\n effects: addEffect.of(specs),\n });\n },\n remove(ids: string[]) {\n if (!viewRef.current) {\n rangesStashRef.current = rangesStashRef.current.filter(\n item => !ids.includes(item.id),\n );\n return;\n }\n\n viewRef.current.dispatch({\n effects: removeEffect.of(ids),\n });\n },\n watch(watcher: Watcher) {\n watchersRef.current.push(watcher);\n return () => {\n watchersRef.current = watchersRef.current.filter(w => w !== watcher);\n };\n },\n };\n}\n\nexport { useRangesManager };\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { useLayoutEffect, useRef, useState } from 'react';\n\nimport { useInjector, InjectPosition } from '@coze-editor/react';\nimport { EditorView } from '@codemirror/view';\n\nfunction useFocused() {\n const injector = useInjector();\n const [focused, setFocused] = useState(false);\n\n const focusedRef = useRef(focused);\n\n useLayoutEffect(\n () =>\n injector.inject(\n [\n EditorView.updateListener.of(update => {\n if (focusedRef.current !== update.view.hasFocus) {\n setFocused(update.view.hasFocus);\n focusedRef.current = update.view.hasFocus;\n }\n }),\n ],\n InjectPosition.Tail,\n ),\n [injector, setFocused],\n );\n\n return focused;\n}\n\nexport { useFocused };\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { useLayoutEffect } from 'react';\n\nimport { type Injector, useInjector } from '@coze-editor/react';\n\ntype InjectorHandler = (\n injector: Injector,\n) => ReturnType<typeof injector.inject> | undefined;\n\nfunction useInjectorEffect(handler: InjectorHandler, deps: any[] = []) {\n const injector = useInjector();\n\n useLayoutEffect(() => handler(injector), [injector, ...deps]);\n}\n\nexport { useInjectorEffect };\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { useState } from 'react';\n\nfunction useHTMLElement(defaultTagName = 'div') {\n const [element] = useState(() => document.createElement(defaultTagName));\n\n return element;\n}\n\nexport { useHTMLElement };\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { useState } from 'react';\n\nimport { Compartment } from '@codemirror/state';\n\nfunction useCompartment() {\n const [compartment] = useState(() => new Compartment());\n return compartment;\n}\n\nexport { useCompartment };\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { useRef } from 'react';\n\nfunction useLatest<T>(value: T) {\n const ref = useRef<T>(value);\n ref.current = value;\n return ref;\n}\n\nexport { useLatest };\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { EditorView } from '@codemirror/view';\nimport { type Text } from '@codemirror/state';\n\nimport { useInjectorEffect, useLatest } from '../hooks';\n\ntype ChangeListener = (event: {\n change: [number, number, number, number, Text];\n view: EditorView;\n}) => void;\n\nfunction useChangeListener(listener: ChangeListener) {\n const listenerRef = useLatest(listener);\n\n useInjectorEffect(\n injector =>\n injector.inject([\n EditorView.updateListener.of(update => {\n if (update.docChanged && typeof listenerRef.current === 'function') {\n update.changes.iterChanges((fromA, toA, fromB, toB, inserted) => {\n listenerRef.current({\n change: [fromA, toA, fromB, toB, inserted],\n view: update.view,\n });\n });\n }\n }),\n ]),\n [],\n );\n}\n\nexport { useChangeListener };\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { useState } from 'react';\n\nimport { Facet, StateField, type Text } from '@codemirror/state';\n\nimport { useLatest } from './use-latest';\nimport { useInjectorEffect } from './use-injector-effect';\n\nconst field = StateField.define({\n create(state) {\n return state.doc;\n },\n update(value, tr) {\n if (tr.docChanged) {\n value = tr.state.doc;\n }\n\n return value;\n },\n});\n\nconst facet = Facet.define();\n\ntype DocumentSelector<T> = (doc: Text) => T;\n\nfunction useDocumentSelector<T>(\n selector: DocumentSelector<T>,\n defaultValue: T,\n): T {\n const [state, setState] = useState<T>(defaultValue);\n const stateRef = useLatest(state);\n const setStateRef = useLatest(setState);\n const selectorRef = useLatest(selector);\n\n useInjectorEffect(\n injector =>\n injector.inject([\n field,\n facet.compute([field], state => {\n const derived = selectorRef.current(state.field(field));\n if (stateRef.current !== derived) {\n setStateRef.current(derived);\n }\n }),\n ]),\n [],\n );\n\n return state;\n}\n\nexport { useDocumentSelector };\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { Facet, StateField, type Text } from '@codemirror/state';\n\nimport { useLatest } from './use-latest';\nimport { useInjectorEffect } from './use-injector-effect';\n\nconst field = StateField.define({\n create(state) {\n return state.doc;\n },\n update(value, tr) {\n if (tr.docChanged) {\n value = tr.state.doc;\n }\n\n return value;\n },\n});\n\nconst facet = Facet.define();\n\ntype DocumentListener = (doc: Text) => void;\n\nfunction useDocumentListener(listener: DocumentListener): void {\n const listenerRef = useLatest(listener);\n\n useInjectorEffect(\n injector =>\n injector.inject([\n field,\n facet.compute([field], state => {\n listenerRef.current(state.field(field));\n }),\n ]),\n [],\n );\n}\n\nexport { useDocumentListener };\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { flushSync } from 'react-dom';\nimport React, { useState, useCallback } from 'react';\nimport type { ReactPortal } from 'react';\n\ninterface PortalItem {\n id: string;\n portal: ReactPortal;\n}\n\nfunction flush(fn: () => void, options: { sync: boolean }) {\n if (options.sync) {\n queueMicrotask(() => {\n flushSync(fn);\n });\n } else {\n fn();\n }\n}\n\nfunction createPortalConnector(options?: { sync?: boolean }) {\n let add = (id: string, portal: ReactPortal) => {};\n\n let remove = (id: string) => {};\n\n function connect(id: string, portal: ReactPortal) {\n add(id, portal);\n }\n\n function disconnect(id: string) {\n remove(id);\n }\n\n function Portal() {\n const [items, setItems] = useState<PortalItem[]>([]);\n\n const addItem = useCallback((id: string, portal: ReactPortal) => {\n flush(\n () => {\n setItems(prevItems => {\n const nextItems = [...prevItems];\n const index = nextItems.findIndex(item => item.id === id);\n if (index > -1) {\n nextItems[index] = { id, portal };\n } else {\n nextItems.push({ id, portal });\n }\n return nextItems;\n });\n },\n { sync: options?.sync ?? false },\n );\n }, []);\n\n const removeItem = useCallback((id: string) => {\n flush(\n () => {\n setItems(oldItems => oldItems.filter(item => item.id !== id));\n },\n { sync: options?.sync ?? false },\n );\n }, []);\n\n add = addItem;\n remove = removeItem;\n\n return <>{items.map(item => item.portal)}</>;\n }\n\n return {\n connect,\n disconnect,\n Portal,\n };\n}\n\nfunction usePortalConnector(options?: { sync?: boolean }) {\n const [connector] = useState(() => createPortalConnector(options));\n return connector;\n}\n\nexport { createPortalConnector, usePortalConnector };\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\n// WHY use-editor-event: avoid conflicts with React hook: useEvent\n\nimport { useEffect } from 'react';\n\ninterface EditorAPILike {\n __private_eventmap: Record<string, any>;\n}\n\nfunction useEditorEvent<\n T extends EditorAPILike,\n K extends keyof T['__private_eventmap'],\n>(editor: T, eventName: K, handler: T['__private_eventmap'][K]): void {\n useEffect(() => {\n if (!editor) {\n return;\n }\n\n (editor as any).$on(eventName, handler);\n\n return () => {\n (editor as any).$off(eventName, handler);\n };\n }, [editor, eventName, handler]);\n}\n\nexport { useEditorEvent };\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { useState } from 'react';\n\nimport { Facet } from '@codemirror/state';\nimport { historyField, redoDepth, undoDepth } from '@codemirror/commands';\n\nimport { useLatest } from './use-latest';\nimport { useInjectorEffect } from './use-injector-effect';\n\nconst facet = Facet.define();\n\nfunction useHistoryState() {\n const [canUndo, setCanUndo] = useState(false);\n const [canRedo, setCanRedo] = useState(false);\n\n const setCanUndoRef = useLatest(setCanUndo);\n const setCanRedoRef = useLatest(setCanRedo);\n\n useInjectorEffect(injector =>\n injector.inject([\n facet.compute([historyField], state => {\n setCanUndoRef.current(() => undoDepth(state) > 0);\n\n setCanRedoRef.current(() => redoDepth(state) > 0);\n }),\n ]),\n );\n\n return {\n canUndo,\n canRedo,\n };\n}\n\nexport { useHistoryState };\n","// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { useEffect, useState } from 'react';\n\nimport { type BuiltinEditorAPI, useEditor } from '@coze-editor/react';\n\nfunction useMouseSelectionPopup() {\n const editor = useEditor<BuiltinEditorAPI>();\n const [visible, setVisible] = useState(false);\n const [selection, setSelection] = useState<{\n from: number;\n to: number;\n anchor: number;\n head: number;\n } | null>(null);\n\n useEffect(() => {\n if (!editor) {\n return;\n }\n\n function handleMousedown() {\n setVisible(false);\n }\n\n function handleMouseup() {\n // mouseup 触发时机过早,此时 getSelection 获取到的信息还是上一次的 selection\n setTimeout(() => {\n const cmSelection = editor.$view.state.selection.main;\n\n if (!cmSelection) {\n setVisible(false);\n return;\n }\n\n const isRange = cmSelection.from !== cmSelection.to;\n\n if (!isRange) {\n setVisible(false);\n return;\n }\n\n setSelection({\n from: cmSelection.from,\n to: cmSelection.to,\n anchor: cmSelection.anchor,\n head: cmSelection.head,\n });\n\n // make showing up smooth\n setTimeout(() => {\n setVisible(true);\n }, 50);\n }, 50);\n }\n\n // 发生内容变更时,隐藏 popover\n function handleSelectionChange() {\n setVisible(false);\n }\n\n // 失焦时,隐藏 popover\n function handleBlur() {\n setVisible(false);\n }\n\n editor.$on('mousedown', handleMousedown);\n editor.$on('mouseup', handleMouseup);\n editor.$on('selectionChange', handleSelectionChange);\n editor.$on('blur', handleBlur);\n\n return () => {\n editor.$off('mousedown', handleMousedown);\n editor.$off('mouseup', handleMouseup);\n editor.$off('selectionChange', handleSelectionChange);\n editor.$off('blur', handleBlur);\n };\n }, [editor]);\n\n const anchor = selection?.anchor ?? -1;\n const head = selection?.head ?? -1;\n const from = selection?.from ?? -1;\n const to = selection?.to ?? -1;\n\n return {\n anchor,\n head,\n from,\n to,\n visible,\n };\n}\n\nexport { useMouseSelectionPopup };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,mBAA4C;AAE5C,IAAAA,gBAAiD;AACjD,mBAKO;AAEP,SAAS,cACP,QACA,QACA;AACA,QAAM,aAAS,yBAA4B;AAE3C,QAAM,CAAC,MAAM,QAAI,uBAAS,MAAM,yBAAY,OAAU,CAAC;AAEvD,QAAM,gBAAY,qBAAuD;AACzE,YAAU,UAAU;AAEpB,QAAM,CAACC,MAAK,QAAI;AAAA,IAAwB,MACtC,wBAAW,OAAO;AAAA,MAChB,OAAO,OAAO;AACZ,eAAO,OAAO,KAAK;AAAA,MACrB;AAAA,MACA,OAAO,OAAO,IAAI;AAChB,YAAI,OAA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AAW,MAAM;AACf,qBAAW,IAAI;AAAA,QACjB,GAAG,EAAE;AAAA,MACP,GAAG,EAAE;AAAA,IACP;AAGA,aAAS,wBAAwB;AAC/B,iBAAW,KAAK;AAAA,IAClB;AAGA,aAAS,aAAa;AACpB,iBAAW,KAAK;AAAA,IAClB;AAEA,WAAO,IAAI,aAAa,eAAe;AACvC,WAAO,IAAI,WAAW,aAAa;AACnC,WAAO,IAAI,mBAAmB,qBAAqB;AACnD,WAAO,IAAI,QAAQ,UAAU;AAE7B,WAAO,MAAM;AACX,aAAO,KAAK,aAAa,eAAe;AACxC,aAAO,KAAK,WAAW,aAAa;AACpC,aAAO,KAAK,mBAAmB,qBAAqB;AACpD,aAAO,KAAK,QAAQ,UAAU;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,UAAS,uCAAW,WAAU;AACpC,QAAM,QAAO,uCAAW,SAAQ;AAChC,QAAM,QAAO,uCAAW,SAAQ;AAChC,QAAM,MAAK,uCAAW,OAAM;AAE5B,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["import_react","field","import_react","import_state","field","import_react","import_view","import_react","import_react","import_react","import_state","import_react","import_view","import_react","import_state","facet","state","import_state","field","facet","import_react","React","import_react","import_react","import_state","import_commands","facet","import_react"]}
|