@dxos/react-ui-editor 0.3.11-main.e8c477a → 0.3.11-main.f14932f
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/dist/lib/browser/index.mjs +34 -38
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +6 -2
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +6 -10
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +2 -2
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/yjs.stories.d.ts +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/package.json +22 -22
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +7 -4
- package/src/components/TextEditor/TextEditor.stories.tsx +3 -4
- package/src/components/TextEditor/TextEditor.tsx +51 -45
- package/src/hooks/useTextModel.ts +1 -1
- package/src/index.ts +1 -0
|
@@ -11,7 +11,7 @@ import { EditorView as EditorView12 } from "@codemirror/view";
|
|
|
11
11
|
import { useFocusableGroup } from "@fluentui/react-tabster";
|
|
12
12
|
import { vim } from "@replit/codemirror-vim";
|
|
13
13
|
import defaultsDeep2 from "lodash.defaultsdeep";
|
|
14
|
-
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useState } from "react";
|
|
14
|
+
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useState, useRef } from "react";
|
|
15
15
|
import { generateName } from "@dxos/display-name";
|
|
16
16
|
import { useThemeContext } from "@dxos/react-ui";
|
|
17
17
|
import { getColorForValue, inputSurface, mx as mx3 } from "@dxos/react-ui-theme";
|
|
@@ -2531,21 +2531,23 @@ var EditorModes = [
|
|
|
2531
2531
|
"default",
|
|
2532
2532
|
"vim"
|
|
2533
2533
|
];
|
|
2534
|
-
var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, comments: comments2, extensions = [], editorMode, slots = defaultSlots }, forwardedRef) => {
|
|
2535
|
-
const { themeMode } = useThemeContext();
|
|
2534
|
+
var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, focus, readonly, comments: comments2, extensions = [], editorMode, slots = defaultSlots }, forwardedRef) => {
|
|
2536
2535
|
const tabsterDOMAttribute = useFocusableGroup({
|
|
2537
2536
|
tabBehavior: "limited"
|
|
2538
2537
|
});
|
|
2539
|
-
const
|
|
2540
|
-
const
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2538
|
+
const { themeMode } = useThemeContext();
|
|
2539
|
+
const rootRef = useRef(null);
|
|
2540
|
+
const [view, setView] = useState(null);
|
|
2541
|
+
useImperativeHandle(forwardedRef, () => view, [
|
|
2542
|
+
view
|
|
2543
|
+
]);
|
|
2544
|
+
useEffect(() => {
|
|
2545
|
+
if (focus && view) {
|
|
2546
|
+
view.focus();
|
|
2547
|
+
}
|
|
2548
|
+
}, [
|
|
2549
|
+
focus,
|
|
2544
2550
|
view
|
|
2545
|
-
}), [
|
|
2546
|
-
view,
|
|
2547
|
-
state,
|
|
2548
|
-
root
|
|
2549
2551
|
]);
|
|
2550
2552
|
const { awareness: awareness2, peer } = model;
|
|
2551
2553
|
useEffect(() => {
|
|
@@ -2582,10 +2584,10 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, comments: co
|
|
|
2582
2584
|
comments2
|
|
2583
2585
|
]);
|
|
2584
2586
|
useEffect(() => {
|
|
2585
|
-
if (!
|
|
2587
|
+
if (!model || !rootRef.current) {
|
|
2586
2588
|
return;
|
|
2587
2589
|
}
|
|
2588
|
-
const
|
|
2590
|
+
const state = EditorState2.create({
|
|
2589
2591
|
doc: model.text(),
|
|
2590
2592
|
extensions: [
|
|
2591
2593
|
readonly && EditorState2.readOnly.of(readonly),
|
|
@@ -2603,19 +2605,17 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, comments: co
|
|
|
2603
2605
|
].filter(Boolean)
|
|
2604
2606
|
});
|
|
2605
2607
|
view?.destroy();
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
state: state2,
|
|
2610
|
-
parent: root
|
|
2611
|
-
})
|
|
2608
|
+
const newView = new EditorView12({
|
|
2609
|
+
parent: rootRef.current,
|
|
2610
|
+
state
|
|
2612
2611
|
});
|
|
2612
|
+
setView(newView);
|
|
2613
2613
|
return () => {
|
|
2614
|
-
|
|
2615
|
-
|
|
2614
|
+
newView?.destroy();
|
|
2615
|
+
setView(null);
|
|
2616
2616
|
};
|
|
2617
2617
|
}, [
|
|
2618
|
-
|
|
2618
|
+
rootRef,
|
|
2619
2619
|
model,
|
|
2620
2620
|
readonly,
|
|
2621
2621
|
editorMode,
|
|
@@ -2624,12 +2624,8 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, comments: co
|
|
|
2624
2624
|
const handleKeyUp = useCallback((event) => {
|
|
2625
2625
|
const { key, altKey, shiftKey, metaKey, ctrlKey } = event;
|
|
2626
2626
|
switch (key) {
|
|
2627
|
-
case "Enter": {
|
|
2628
|
-
view?.contentDOM.focus();
|
|
2629
|
-
break;
|
|
2630
|
-
}
|
|
2631
2627
|
case "Escape": {
|
|
2632
|
-
editorMode === "vim" && (altKey || shiftKey || metaKey || ctrlKey) &&
|
|
2628
|
+
editorMode === "vim" && (altKey || shiftKey || metaKey || ctrlKey) && rootRef.current?.focus();
|
|
2633
2629
|
break;
|
|
2634
2630
|
}
|
|
2635
2631
|
}
|
|
@@ -2639,16 +2635,16 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, comments: co
|
|
|
2639
2635
|
]);
|
|
2640
2636
|
return /* @__PURE__ */ React.createElement("div", {
|
|
2641
2637
|
key: model.id,
|
|
2642
|
-
ref:
|
|
2638
|
+
ref: rootRef,
|
|
2643
2639
|
tabIndex: 0,
|
|
2644
2640
|
...slots?.root,
|
|
2645
2641
|
...editorMode !== "vim" && tabsterDOMAttribute,
|
|
2646
2642
|
onKeyUp: handleKeyUp
|
|
2647
2643
|
});
|
|
2648
2644
|
});
|
|
2649
|
-
var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots
|
|
2645
|
+
var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots, ...props }, forwardedRef) => {
|
|
2650
2646
|
const { themeMode } = useThemeContext();
|
|
2651
|
-
const
|
|
2647
|
+
const updatedSlots = defaultsDeep2({}, slots, defaultTextSlots);
|
|
2652
2648
|
return /* @__PURE__ */ React.createElement(BaseTextEditor, {
|
|
2653
2649
|
ref: forwardedRef,
|
|
2654
2650
|
readonly,
|
|
@@ -2656,17 +2652,17 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots:
|
|
|
2656
2652
|
basicBundle({
|
|
2657
2653
|
readonly,
|
|
2658
2654
|
themeMode,
|
|
2659
|
-
placeholder:
|
|
2655
|
+
placeholder: updatedSlots?.editor?.placeholder
|
|
2660
2656
|
}),
|
|
2661
2657
|
...extensions
|
|
2662
2658
|
],
|
|
2663
|
-
slots,
|
|
2659
|
+
slots: updatedSlots,
|
|
2664
2660
|
...props
|
|
2665
2661
|
});
|
|
2666
2662
|
});
|
|
2667
|
-
var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots
|
|
2663
|
+
var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots, ...props }, forwardedRef) => {
|
|
2668
2664
|
const { themeMode } = useThemeContext();
|
|
2669
|
-
const
|
|
2665
|
+
const updatedSlots = defaultsDeep2({}, slots, defaultMarkdownSlots);
|
|
2670
2666
|
return /* @__PURE__ */ React.createElement(BaseTextEditor, {
|
|
2671
2667
|
ref: forwardedRef,
|
|
2672
2668
|
readonly,
|
|
@@ -2674,11 +2670,11 @@ var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], sl
|
|
|
2674
2670
|
markdownBundle({
|
|
2675
2671
|
readonly,
|
|
2676
2672
|
themeMode,
|
|
2677
|
-
placeholder:
|
|
2673
|
+
placeholder: updatedSlots?.editor?.placeholder
|
|
2678
2674
|
}),
|
|
2679
2675
|
...extensions
|
|
2680
2676
|
],
|
|
2681
|
-
slots,
|
|
2677
|
+
slots: updatedSlots,
|
|
2682
2678
|
...props
|
|
2683
2679
|
});
|
|
2684
2680
|
});
|
|
@@ -2984,7 +2980,7 @@ var modelState = StateField5.define({
|
|
|
2984
2980
|
});
|
|
2985
2981
|
var useTextModel = (props) => {
|
|
2986
2982
|
const { identity, space, text } = props;
|
|
2987
|
-
const [model, setModel] = useState2(
|
|
2983
|
+
const [model, setModel] = useState2();
|
|
2988
2984
|
useEffect2(() => setModel(createModel(props)), [
|
|
2989
2985
|
identity,
|
|
2990
2986
|
space,
|