@nesso-how/ui 1.0.0-beta.15 → 1.0.0-beta.17
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 +4 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +22 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,8 +52,10 @@ Your build must compile this CSS; it is not a precompiled stylesheet. Supply the
|
|
|
52
52
|
|
|
53
53
|
`BottomSheet` is a controlled, non-modal drawer with a title, close label, optional footer, and popup ref for measuring covered content. It supports swipe-down dismissal, safe-area padding, and reduced motion. Reading text can use `--nesso-reading-font-size` and `--nesso-reading-line-height`, which increase from 13/20px to 15/23px on narrow screens or coarse pointers.
|
|
54
54
|
|
|
55
|
-
`MarkdownInput`
|
|
55
|
+
`MarkdownInput` accepts Markdown through `value`/`onChange`, with live preview of emphasis, links, and lists. Syntax reappears around the selection. Cmd/Ctrl+B/I toggles formatting; Enter continues or exits lists, Tab/Shift+Tab changes nesting, and Shift+Enter inserts a line break. Optional `tasks` enables clickable task checkboxes; `placeholder` appears when empty.
|
|
56
56
|
|
|
57
|
-
`
|
|
57
|
+
Undo/redo is local by default. Use `history={false}` for host-owned history or `history="focus"` to reset local history on blur and external value changes. Exhausted local history never falls through. Menu commands can send `beforeinput` events (`historyUndo`/`historyRedo`) to the focused editor inside `[data-local-history]`.
|
|
58
|
+
|
|
59
|
+
Cmd/Ctrl-click calls `onOpenLink`; read-only fields use a regular click. The host validates and opens destinations.
|
|
58
60
|
|
|
59
61
|
The package also exports `useMediaQuery`, `contrastColor`, `presetColors`, and the `ActionIconName` and `ToastItem` types. See the [public exports](https://github.com/nesso-how/nesso/blob/main/packages/ui/src/index.ts) and component source files for prop definitions; published TypeScript declarations provide editor completion.
|
package/dist/index.d.ts
CHANGED
|
@@ -76,7 +76,7 @@ type MarkdownInputProps = Omit<ComponentProps<'div'>, 'onChange' | 'children' |
|
|
|
76
76
|
value: string;
|
|
77
77
|
onChange: (value: string) => void;
|
|
78
78
|
readOnly?: boolean;
|
|
79
|
-
history?: boolean;
|
|
79
|
+
history?: boolean | 'focus';
|
|
80
80
|
tasks?: boolean;
|
|
81
81
|
onOpenLink?: (url: string) => void;
|
|
82
82
|
placeholder?: string;
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { ArrowRight, BookOpen, Check, ChevronDown, ChevronLeft, ChevronRight, Ci
|
|
|
7
7
|
import { Input as Input$1 } from "@base-ui/react/input";
|
|
8
8
|
import { Annotation, Compartment, EditorSelection, EditorState, Facet, Transaction } from "@codemirror/state";
|
|
9
9
|
import { Decoration, EditorView, ViewPlugin, WidgetType, keymap, placeholder } from "@codemirror/view";
|
|
10
|
-
import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
|
|
10
|
+
import { defaultKeymap, history, historyKeymap, redo } from "@codemirror/commands";
|
|
11
11
|
import { TaskList, parser } from "@lezer/markdown";
|
|
12
12
|
import { Dialog, Dialog as Dialog$1 } from "@base-ui/react/dialog";
|
|
13
13
|
import { Drawer } from "@base-ui/react/drawer";
|
|
@@ -560,6 +560,10 @@ function toggleMarkdownFormat(state, marker) {
|
|
|
560
560
|
//#endregion
|
|
561
561
|
//#region src/markdown-input.tsx
|
|
562
562
|
const externalChange = Annotation.define();
|
|
563
|
+
const resetHistory = (view, compartment) => {
|
|
564
|
+
view.dispatch({ effects: compartment.reconfigure([]) });
|
|
565
|
+
view.dispatch({ effects: compartment.reconfigure(history()) });
|
|
566
|
+
};
|
|
563
567
|
const livePreview = ViewPlugin.define((view) => ({
|
|
564
568
|
decorations: markdownDecorations(view.state, view.hasFocus && !view.state.readOnly),
|
|
565
569
|
update(update) {
|
|
@@ -589,6 +593,7 @@ function MarkdownInput({ value, onChange, readOnly = false, history: history$1 =
|
|
|
589
593
|
onOpenLink
|
|
590
594
|
});
|
|
591
595
|
const [configuration] = useState(() => new Compartment());
|
|
596
|
+
const [historyState] = useState(() => new Compartment());
|
|
592
597
|
const [initialValue] = useState(value);
|
|
593
598
|
useLayoutEffect(() => {
|
|
594
599
|
callbacks.current = {
|
|
@@ -685,11 +690,19 @@ function MarkdownInput({ value, onChange, readOnly = false, history: history$1 =
|
|
|
685
690
|
"aria-readonly": String(readOnly),
|
|
686
691
|
spellcheck: "true"
|
|
687
692
|
}),
|
|
688
|
-
...history$1 ? [history(), keymap.of(historyKeymap
|
|
693
|
+
...history$1 ? [historyState.of(history()), keymap.of([...historyKeymap, {
|
|
694
|
+
key: "Mod-Shift-z",
|
|
695
|
+
run: redo,
|
|
696
|
+
preventDefault: true
|
|
697
|
+
}])] : [],
|
|
698
|
+
...history$1 === "focus" ? [EditorView.domEventHandlers({ blur(_event, view) {
|
|
699
|
+
resetHistory(view, historyState);
|
|
700
|
+
} })] : [],
|
|
689
701
|
...placeholder$1 ? [placeholder(placeholder$1)] : []
|
|
690
702
|
]) });
|
|
691
703
|
}, [
|
|
692
704
|
configuration,
|
|
705
|
+
historyState,
|
|
693
706
|
readOnly,
|
|
694
707
|
history$1,
|
|
695
708
|
tasks,
|
|
@@ -701,6 +714,7 @@ function MarkdownInput({ value, onChange, readOnly = false, history: history$1 =
|
|
|
701
714
|
useLayoutEffect(() => {
|
|
702
715
|
const view = editor.current;
|
|
703
716
|
if (!view || value === view.state.doc.toString()) return;
|
|
717
|
+
if (history$1 === "focus") resetHistory(view, historyState);
|
|
704
718
|
view.dispatch({
|
|
705
719
|
changes: {
|
|
706
720
|
from: 0,
|
|
@@ -709,10 +723,15 @@ function MarkdownInput({ value, onChange, readOnly = false, history: history$1 =
|
|
|
709
723
|
},
|
|
710
724
|
annotations: [externalChange.of(true), Transaction.addToHistory.of(false)]
|
|
711
725
|
});
|
|
712
|
-
}, [
|
|
726
|
+
}, [
|
|
727
|
+
value,
|
|
728
|
+
history$1,
|
|
729
|
+
historyState
|
|
730
|
+
]);
|
|
713
731
|
return /* @__PURE__ */ jsx("div", {
|
|
714
732
|
...props,
|
|
715
733
|
ref: container,
|
|
734
|
+
"data-local-history": history$1 ? "" : void 0,
|
|
716
735
|
className: cn("nesso-input nesso-markdown-input nesso-scroll min-h-24 w-full overflow-y-auto border border-input bg-background px-2.5 py-2 focus-within:border-muted-foreground", className)
|
|
717
736
|
});
|
|
718
737
|
}
|
package/package.json
CHANGED