@nesso-how/ui 1.0.0-beta.11 → 1.0.0-beta.12

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 CHANGED
@@ -52,7 +52,7 @@ 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` provides a live preview of bold, italic, links, and bullet or numbered lists in one field without a toolbar. Markdown delimiters reappear when the cursor or selection enters formatted text, including link destinations and list markers. Enter continues a list, incrementing the current number for numbered lists; Enter on an empty nested item returns to the parent level, and on an empty top-level item ends the list. Tab nests the current item under the previous one; Shift+Tab moves it up a level. Both move the item's continuation lines and children together, leaving unrelated text alone. At level boundaries they leave content and focus unchanged; outside lists they retain normal focus navigation. Shift+Enter inserts a plain line break. Existing items are not renumbered, and there are no checklists. It accepts the unchanged Markdown source through `value` and `onChange`, supports Cmd/Ctrl+B/I on selections, and preserves line breaks. Set `history={false}` when the host owns undo/redo and its shortcuts. Cmd/Ctrl-click requests `onOpenLink`; read-only fields request it on a regular click. The host is responsible for validating and opening destinations.
55
+ `MarkdownInput` provides a live preview of bold, italic, links, and bullet or numbered lists in one field without a toolbar. Markdown delimiters reappear when the cursor or selection enters formatted text, including link destinations and list markers. Enter continues a list, incrementing the current number for numbered lists; Enter on an empty nested item returns to the parent level, and on an empty top-level item ends the list. Tab nests the current item under the previous one; Shift+Tab moves it up a level. Both move the item's continuation lines and children together, leaving unrelated text alone. At level boundaries they leave content and focus unchanged; outside lists they retain normal focus navigation. Shift+Enter inserts a plain line break. Existing items are not renumbered. Set `tasks` to render `[ ]` and `[x]` list items as checkboxes that toggle on click; Enter continues them with an unchecked item. Without it, task syntax stays literal. It accepts the unchanged Markdown source through `value` and `onChange`, supports Cmd/Ctrl+B/I on selections, and preserves line breaks. Set `history={false}` when the host owns undo/redo and its shortcuts. Cmd/Ctrl-click requests `onOpenLink`; read-only fields request it on a regular click. The host is responsible for validating and opening destinations.
56
56
 
57
57
  `MarkdownInput` also accepts an optional `placeholder` shown only while the editor is empty.
58
58
 
package/dist/index.d.ts CHANGED
@@ -77,10 +77,11 @@ type MarkdownInputProps = Omit<ComponentProps<'div'>, 'onChange' | 'children' |
77
77
  onChange: (value: string) => void;
78
78
  readOnly?: boolean;
79
79
  history?: boolean;
80
+ tasks?: boolean;
80
81
  onOpenLink?: (url: string) => void;
81
82
  placeholder?: string;
82
83
  };
83
- export declare function MarkdownInput({ value, onChange, readOnly, history, onOpenLink, placeholder, className, id, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, ...props }: MarkdownInputProps): import("react").JSX.Element;
84
+ export declare function MarkdownInput({ value, onChange, readOnly, history, tasks, onOpenLink, placeholder, className, id, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, ...props }: MarkdownInputProps): import("react").JSX.Element;
84
85
  //#endregion
85
86
  //#region src/label.d.ts
86
87
  declare function Label({ className, ...props }: ComponentProps<'label'>): import("react").JSX.Element;
package/dist/index.js CHANGED
@@ -5,10 +5,10 @@ import { jsx, jsxs } from "react/jsx-runtime";
5
5
  import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
6
6
  import { ArrowRight, BookOpen, Check, ChevronDown, ChevronLeft, ChevronRight, CircleHelp, ClipboardPaste, Copy, Download, FileDown, FileUp, Folder, Glasses, Globe, Info, Layers, Minus, Pencil, Play, Plus, RefreshCw, Repeat, RotateCcw, Scissors, Search, Share2, Sparkles, TriangleAlert, Upload, X, Zap } from "lucide-react";
7
7
  import { Input as Input$1 } from "@base-ui/react/input";
8
- import { Annotation, Compartment, EditorSelection, EditorState, Transaction } from "@codemirror/state";
8
+ import { Annotation, Compartment, EditorSelection, EditorState, Facet, Transaction } from "@codemirror/state";
9
9
  import { Decoration, EditorView, ViewPlugin, WidgetType, keymap, placeholder } from "@codemirror/view";
10
10
  import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
11
- import { parser } from "@lezer/markdown";
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";
14
14
  import { Combobox } from "@base-ui/react/combobox";
@@ -287,25 +287,96 @@ function DirectoryField({ label, value, labels, disabled, changeDisabled, onOpen
287
287
  //#endregion
288
288
  //#region src/markdown.ts
289
289
  const listPrefix = /^(\s*)([-+*]|(\d{1,9})([.)]))([\t ]+|$)/;
290
+ const taskPrefix = /^\[[ xX]\]([\t ]+|$)/;
291
+ const taskParser = parser.configure(TaskList);
292
+ const markdownTasks = Facet.define({ combine: (values) => values.some(Boolean) });
293
+ const parse = (state) => (state.facet(markdownTasks) ? taskParser : parser).parse(state.doc.toString());
290
294
  var ListMarker = class extends WidgetType {
291
295
  label;
292
- constructor(label) {
296
+ checked;
297
+ constructor(label, checked = null) {
293
298
  super();
294
299
  this.label = label;
300
+ this.checked = checked;
295
301
  }
296
302
  eq(other) {
297
- return this.label === other.label;
303
+ return this.label === other.label && this.checked === other.checked;
298
304
  }
299
305
  toDOM(view) {
300
- const marker = view.dom.ownerDocument.createElement("span");
306
+ const document = view.dom.ownerDocument;
307
+ const marker = document.createElement("span");
301
308
  marker.className = "nesso-markdown-list-marker";
302
309
  marker.textContent = this.label;
310
+ if (this.label === "• ") {
311
+ const bullet = document.createElement("span");
312
+ bullet.className = "nesso-markdown-bullet";
313
+ bullet.textContent = "•";
314
+ marker.replaceChildren(bullet, document.createTextNode(" "));
315
+ }
316
+ if (this.checked !== null) {
317
+ const checkbox = document.createElement("input");
318
+ checkbox.type = "checkbox";
319
+ checkbox.className = "nesso-markdown-task";
320
+ checkbox.checked = this.checked;
321
+ checkbox.tabIndex = -1;
322
+ marker.append(checkbox);
323
+ }
303
324
  return marker;
304
325
  }
305
326
  ignoreEvent() {
306
327
  return false;
307
328
  }
308
329
  };
330
+ function markerWidth(item) {
331
+ const marker = item.getChild("ListMark");
332
+ const task = item.getChild("Task") ? 1.4 : 0;
333
+ return item.parent?.name === "BulletList" ? {
334
+ ch: 0,
335
+ em: task || 1
336
+ } : {
337
+ ch: marker.to - marker.from - 1,
338
+ em: .75 + task
339
+ };
340
+ }
341
+ function markerLabel(state, item, checked) {
342
+ if (item.parent?.name !== "BulletList") {
343
+ const marker = item.getChild("ListMark");
344
+ return `${state.sliceDoc(marker.from, marker.to)} `;
345
+ }
346
+ return checked === null ? "• " : "";
347
+ }
348
+ function listPadding(item) {
349
+ const padding = {
350
+ ch: 0,
351
+ em: 0
352
+ };
353
+ for (let node = item; node; node = node.parent) {
354
+ if (node.name !== "ListItem") continue;
355
+ const width = markerWidth(node);
356
+ padding.ch += width.ch;
357
+ padding.em += width.em;
358
+ }
359
+ return padding;
360
+ }
361
+ function listItemDecorations(state, item, active) {
362
+ const marker = item.getChild("ListMark");
363
+ const task = item.getChild("Task");
364
+ const taskMarker = task?.getChild("TaskMarker");
365
+ const checked = taskMarker ? state.sliceDoc(taskMarker.from + 1, taskMarker.from + 2) !== " " : null;
366
+ const line = state.doc.lineAt(marker.from);
367
+ const from = /^[\t ]*$/.test(state.sliceDoc(line.from, marker.from)) ? line.from : marker.from;
368
+ const start = taskMarker?.to ?? marker.to;
369
+ const end = start + state.sliceDoc(start, line.to).match(/^[\t ]*/)[0].length;
370
+ const label = markerLabel(state, item, checked);
371
+ const width = markerWidth(item);
372
+ const padding = listPadding(item);
373
+ const decorations = [Decoration.line({
374
+ class: "nesso-markdown-list-item",
375
+ attributes: { style: `--nesso-list-indent: calc(${width.ch}ch + ${width.em}em); --nesso-list-padding: calc(var(--nesso-list-inset) + ${padding.ch}ch + ${padding.em}em)` }
376
+ }).range(line.from), (active ? Decoration.mark({ class: "nesso-markdown-syntax nesso-markdown-list-marker" }) : Decoration.replace({ widget: new ListMarker(label, checked) })).range(from, end)];
377
+ if (checked && task && end < task.to) decorations.push(Decoration.mark({ class: "nesso-markdown-task-done" }).range(end, task.to));
378
+ return decorations;
379
+ }
309
380
  function markdownDecorations(state, focused) {
310
381
  const source = state.doc.toString();
311
382
  const decorations = [];
@@ -314,7 +385,7 @@ function markdownDecorations(state, focused) {
314
385
  const decoration = active ? Decoration.mark({ class: "nesso-markdown-syntax" }) : Decoration.replace({});
315
386
  decorations.push(decoration.range(from, to));
316
387
  };
317
- parser.parse(source).iterate({ enter(node) {
388
+ parse(state).iterate({ enter(node) {
318
389
  if ([
319
390
  "Image",
320
391
  "InlineCode",
@@ -323,17 +394,7 @@ function markdownDecorations(state, focused) {
323
394
  "HTMLBlock"
324
395
  ].includes(node.name)) return false;
325
396
  const active = focused && state.selection.ranges.some((range) => range.from <= node.to && range.to >= node.from);
326
- if (node.name === "ListItem") {
327
- const marker = node.node.getChild("ListMark");
328
- const line = state.doc.lineAt(marker.from);
329
- const end = marker.to + (source.slice(marker.to, line.to).match(/^[\t ]*/)?.[0].length ?? 0);
330
- const label = node.node.parent?.name === "BulletList" ? "•" : source.slice(marker.from, marker.to);
331
- const width = Math.max(3, end - marker.from);
332
- decorations.push(Decoration.line({
333
- class: "nesso-markdown-list-item",
334
- attributes: { style: `--nesso-list-indent: ${width}ch; --nesso-list-padding: ${marker.from - line.from + width}ch` }
335
- }).range(line.from), (active ? Decoration.mark({ class: "nesso-markdown-syntax nesso-markdown-list-marker" }) : Decoration.replace({ widget: new ListMarker(`${label} `) })).range(marker.from, end));
336
- }
397
+ if (node.name === "ListItem") decorations.push(...listItemDecorations(state, node.node, active));
337
398
  if (node.name === "StrongEmphasis" || node.name === "Emphasis") {
338
399
  const [open, close] = node.node.getChildren("EmphasisMark");
339
400
  decorations.push(Decoration.mark({ class: node.name === "StrongEmphasis" ? "nesso-markdown-bold" : "nesso-markdown-italic" }).range(open.to, close.from));
@@ -358,7 +419,7 @@ function markdownListItem(state) {
358
419
  if (state.readOnly || state.selection.ranges.length !== 1) return null;
359
420
  const { from, to } = state.selection.main;
360
421
  if (to > state.doc.lineAt(from).to) return null;
361
- let node = parser.parse(state.doc.toString()).resolveInner(from, -1);
422
+ let node = parse(state).resolveInner(from, -1);
362
423
  while (node.name !== "ListItem") {
363
424
  if ([
364
425
  "FencedCode",
@@ -426,12 +487,17 @@ function continueMarkdownList(state) {
426
487
  if (!item) return null;
427
488
  const { node, firstLine, prefix } = item;
428
489
  let { from, to } = state.selection.main;
429
- if (from < firstLine.from + prefix[0].length) return null;
430
- let insert = nextListPrefix(prefix);
431
- if (state.doc.lineAt(from).from === firstLine.from && !firstLine.text.slice(prefix[0].length).trim()) {
490
+ const task = state.facet(markdownTasks) ? firstLine.text.slice(prefix[0].length).match(taskPrefix)?.[0] ?? "" : "";
491
+ if (from < firstLine.from + prefix[0].length + task.length) return null;
492
+ const next = (prefix) => {
493
+ const marker = nextListPrefix(prefix);
494
+ return marker === null ? null : marker + (task && "[ ] ");
495
+ };
496
+ let insert = next(prefix);
497
+ if (state.doc.lineAt(from).from === firstLine.from && !firstLine.text.slice(prefix[0].length + task.length).trim()) {
432
498
  const parent = node.parent?.parent;
433
499
  const parentPrefix = parent?.name === "ListItem" ? state.doc.lineAt(parent.from).text.match(listPrefix) : null;
434
- insert = parentPrefix ? nextListPrefix(parentPrefix) : "";
500
+ insert = parentPrefix ? next(parentPrefix) : "";
435
501
  from = firstLine.from;
436
502
  to = firstLine.to;
437
503
  } else if (insert !== null) insert = `\n${insert}`;
@@ -446,12 +512,26 @@ function continueMarkdownList(state) {
446
512
  userEvent: "input"
447
513
  };
448
514
  }
515
+ function toggleMarkdownTask(state, position) {
516
+ if (state.readOnly || !state.facet(markdownTasks)) return null;
517
+ const marker = parse(state).resolveInner(position, 1).parent?.getChild("Task")?.getChild("TaskMarker");
518
+ if (!marker) return null;
519
+ const from = marker.from + 1;
520
+ return {
521
+ changes: {
522
+ from,
523
+ to: from + 1,
524
+ insert: state.sliceDoc(from, from + 1) === " " ? "x" : " "
525
+ },
526
+ userEvent: "input.toggle"
527
+ };
528
+ }
449
529
  function toggleMarkdownFormat(state, marker) {
450
530
  if (state.readOnly) return null;
451
531
  const { from, to } = state.selection.main;
452
532
  const selected = state.sliceDoc(from, to);
453
533
  let delimiters;
454
- parser.parse(state.doc.toString()).iterate({ enter(node) {
534
+ parse(state).iterate({ enter(node) {
455
535
  if (node.name !== (marker === "**" ? "StrongEmphasis" : "Emphasis")) return;
456
536
  const [open, close] = node.node.getChildren("EmphasisMark");
457
537
  if (from === node.from && to === node.to || from >= open.to && to <= close.from) delimiters = [open, close].map(({ from, to }) => ({
@@ -483,10 +563,25 @@ const externalChange = Annotation.define();
483
563
  const livePreview = ViewPlugin.define((view) => ({
484
564
  decorations: markdownDecorations(view.state, view.hasFocus && !view.state.readOnly),
485
565
  update(update) {
486
- if (update.docChanged || update.selectionSet || update.focusChanged || update.startState.readOnly !== update.state.readOnly) this.decorations = markdownDecorations(update.state, update.view.hasFocus && !update.state.readOnly);
566
+ if (update.docChanged || update.selectionSet || update.focusChanged || update.startState.readOnly !== update.state.readOnly || update.startState.facet(markdownTasks) !== update.state.facet(markdownTasks)) this.decorations = markdownDecorations(update.state, update.view.hasFocus && !update.state.readOnly);
487
567
  }
488
568
  }), { decorations: (plugin) => plugin.decorations });
489
- function MarkdownInput({ value, onChange, readOnly = false, history: history$1 = true, onOpenLink, placeholder: placeholder$1, className, id, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, ...props }) {
569
+ const taskCheckboxes = EditorView.domEventHandlers({
570
+ mousedown(event, view) {
571
+ const task = event.target.closest(".nesso-markdown-task");
572
+ if (!task) return false;
573
+ event.preventDefault();
574
+ const transaction = toggleMarkdownTask(view.state, view.posAtDOM(task));
575
+ if (transaction) view.dispatch(transaction);
576
+ return true;
577
+ },
578
+ click(event) {
579
+ if (!event.target.closest(".nesso-markdown-task")) return false;
580
+ event.preventDefault();
581
+ return true;
582
+ }
583
+ });
584
+ function MarkdownInput({ value, onChange, readOnly = false, history: history$1 = true, tasks, onOpenLink, placeholder: placeholder$1, className, id, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, ...props }) {
490
585
  const container = useRef(null);
491
586
  const editor = useRef(null);
492
587
  const callbacks = useRef({
@@ -517,10 +612,11 @@ function MarkdownInput({ value, onChange, readOnly = false, history: history$1 =
517
612
  ".cm-content, .cm-line": { padding: "0" },
518
613
  ".cm-line.nesso-markdown-list-item": {
519
614
  paddingInlineStart: "var(--nesso-list-padding)",
520
- textIndent: "calc(-1 * var(--nesso-list-padding))"
615
+ textIndent: "calc(-1 * var(--nesso-list-indent))"
521
616
  }
522
617
  }),
523
618
  livePreview,
619
+ taskCheckboxes,
524
620
  configuration.of([]),
525
621
  keymap.of([
526
622
  ...["Tab", "Shift-Tab"].map((key) => ({
@@ -580,6 +676,7 @@ function MarkdownInput({ value, onChange, readOnly = false, history: history$1 =
580
676
  editor.current?.dispatch({ effects: configuration.reconfigure([
581
677
  EditorState.readOnly.of(readOnly),
582
678
  EditorView.editable.of(!readOnly),
679
+ markdownTasks.of(tasks),
583
680
  EditorView.contentAttributes.of({
584
681
  ...id ? { id } : {},
585
682
  ...ariaLabel ? { "aria-label": ariaLabel } : {},
@@ -595,6 +692,7 @@ function MarkdownInput({ value, onChange, readOnly = false, history: history$1 =
595
692
  configuration,
596
693
  readOnly,
597
694
  history$1,
695
+ tasks,
598
696
  id,
599
697
  ariaLabel,
600
698
  ariaLabelledBy,
@@ -615,7 +713,7 @@ function MarkdownInput({ value, onChange, readOnly = false, history: history$1 =
615
713
  return /* @__PURE__ */ jsx("div", {
616
714
  ...props,
617
715
  ref: container,
618
- className: cn("nesso-input nesso-markdown-input min-h-24 w-full overflow-y-auto border border-input bg-background px-2.5 py-2 focus-within:border-muted-foreground", className)
716
+ 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)
619
717
  });
620
718
  }
621
719
  //#endregion
@@ -941,7 +1039,7 @@ function BottomSheet({ open, onOpenChange, title, closeLabel, popupRef, footer,
941
1039
  })]
942
1040
  }),
943
1041
  /* @__PURE__ */ jsx(Drawer.Content, {
944
- className: "min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 pt-1 pb-5",
1042
+ className: "nesso-scroll min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 pt-1 pb-5",
945
1043
  children
946
1044
  }),
947
1045
  footer && /* @__PURE__ */ jsx("div", {
@@ -1124,7 +1222,7 @@ function MenuPopup({ className, align = "start", anchor, sideOffset = 4, childre
1124
1222
  sideOffset,
1125
1223
  className: "z-50",
1126
1224
  children: /* @__PURE__ */ jsx(Menu.Popup, {
1127
- className: cn("nesso-popup w-max min-w-32 max-w-[calc(100vw-32px)] max-h-(--available-height) overflow-y-auto p-1", className),
1225
+ className: cn("nesso-popup nesso-scroll w-max min-w-32 max-w-[calc(100vw-32px)] max-h-(--available-height) overflow-y-auto p-1", className),
1128
1226
  ...props,
1129
1227
  children
1130
1228
  })
@@ -1155,7 +1253,7 @@ function PopoverPopup({ className, anchor, align = "start", sideOffset = 4, chil
1155
1253
  sideOffset,
1156
1254
  className: "z-50",
1157
1255
  children: /* @__PURE__ */ jsx(Popover.Popup, {
1158
- className: cn("nesso-popup z-50 max-h-(--available-height) overflow-y-auto p-3 outline-none", className),
1256
+ className: cn("nesso-popup nesso-scroll z-50 max-h-(--available-height) overflow-y-auto p-3 outline-none", className),
1159
1257
  ...props,
1160
1258
  children
1161
1259
  })
@@ -1498,7 +1596,7 @@ function AutocompletePopup({ className, children, ...props }) {
1498
1596
  sideOffset: 4,
1499
1597
  className: "z-50 outline-none",
1500
1598
  children: /* @__PURE__ */ jsx(Autocomplete.Popup, {
1501
- className: cn("nesso-popup max-h-72 w-(--anchor-width) overflow-y-auto p-1", className),
1599
+ className: cn("nesso-popup nesso-scroll max-h-72 w-(--anchor-width) overflow-y-auto p-1", className),
1502
1600
  ...props,
1503
1601
  children
1504
1602
  })
package/dist/styles.css CHANGED
@@ -61,6 +61,7 @@
61
61
  }
62
62
 
63
63
  .nesso-markdown-input {
64
+ --nesso-list-inset: 0.5em;
64
65
  display: flex;
65
66
  }
66
67
 
@@ -70,7 +71,7 @@
70
71
  }
71
72
 
72
73
  .nesso-markdown-bold {
73
- font-weight: 700;
74
+ font-weight: 600;
74
75
  }
75
76
 
76
77
  .nesso-markdown-italic {
@@ -92,6 +93,29 @@
92
93
  text-indent: 0;
93
94
  }
94
95
 
96
+ .nesso-markdown-bullet {
97
+ display: inline-block;
98
+ transform: scale(1.2);
99
+ }
100
+
101
+ .nesso-markdown-task {
102
+ width: 0.875em;
103
+ height: 0.875em;
104
+ margin: 0;
105
+ vertical-align: -0.1em;
106
+ accent-color: var(--primary);
107
+ cursor: pointer;
108
+ }
109
+
110
+ .nesso-markdown-input [aria-readonly='true'] .nesso-markdown-task {
111
+ cursor: default;
112
+ }
113
+
114
+ .nesso-markdown-task-done {
115
+ color: var(--muted-foreground);
116
+ text-decoration: line-through;
117
+ }
118
+
95
119
  .nesso-popup {
96
120
  border: 1px solid var(--border);
97
121
  border-radius: var(--radius-object);
@@ -218,6 +242,10 @@
218
242
  width: 26px;
219
243
  height: 28px;
220
244
  }
245
+ .nesso-scroll {
246
+ scrollbar-width: thin;
247
+ scrollbar-color: var(--border) transparent;
248
+ }
221
249
  .nesso-plugin-page {
222
250
  display: flex;
223
251
  flex-direction: column;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nesso-how/ui",
3
- "version": "1.0.0-beta.11",
3
+ "version": "1.0.0-beta.12",
4
4
  "description": "Reusable React primitives and shared styles for Nesso, usable in the app and in isolated plugin panels",
5
5
  "license": "MIT",
6
6
  "repository": {