@karimsa/mdxserve 0.3.0 → 0.5.0

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.
Files changed (69) hide show
  1. package/README.md +80 -10
  2. package/client/App.tsx +15 -1
  3. package/client/CodeBlock.tsx +24 -0
  4. package/client/DocView.tsx +9 -2
  5. package/client/ListingView.tsx +14 -10
  6. package/client/MarkdownTable.tsx +190 -0
  7. package/client/MdSection.tsx +63 -23
  8. package/client/MdSectionEditor.tsx +208 -2
  9. package/client/Mermaid.tsx +33 -7
  10. package/client/Settings.css +17 -0
  11. package/client/Settings.tsx +132 -0
  12. package/client/Table.tsx +2 -14
  13. package/client/app.css +341 -1
  14. package/client/block-state/README.md +39 -0
  15. package/client/block-state/storage.ts +73 -0
  16. package/client/block-state/useBlockState.ts +120 -0
  17. package/client/builtins/DataTable.tsx +269 -0
  18. package/client/builtins/chart-data.ts +22 -10
  19. package/client/builtins/index.ts +10 -0
  20. package/client/data-table/ColumnMenu.tsx +168 -0
  21. package/client/data-table/ColumnOptions.tsx +141 -0
  22. package/client/data-table/TableCell.tsx +76 -0
  23. package/client/data-table/TableHeaderCell.tsx +94 -0
  24. package/client/data-table/model.ts +194 -0
  25. package/client/data-table/navigation.ts +34 -0
  26. package/client/data-table/table-state.ts +196 -0
  27. package/client/data-table/useColumnMenu.ts +84 -0
  28. package/client/data-table/useTableState.ts +36 -0
  29. package/client/design/base/editor.css +59 -0
  30. package/client/design/base/prose.css +4 -0
  31. package/client/diagrams/Dialog.tsx +577 -0
  32. package/client/diagrams/EditDialog.tsx +67 -0
  33. package/client/diagrams/Preferences.tsx +213 -0
  34. package/client/diagrams/edit-block.ts +93 -0
  35. package/client/diagrams/edit-context.ts +4 -0
  36. package/client/diagrams/session-id.ts +8 -0
  37. package/client/diagrams/source.ts +73 -0
  38. package/client/diagrams/style.css +580 -0
  39. package/client/doc-module-cache.ts +9 -1
  40. package/client/editor/ImageDialog.tsx +69 -0
  41. package/client/editor/LinkDialog.tsx +60 -0
  42. package/client/editor/blocks.ts +295 -0
  43. package/client/editor/component-fields.css +57 -0
  44. package/client/editor/component-fields.ts +128 -0
  45. package/client/editor/image-dialog.css +44 -0
  46. package/client/editor/mdx-block.tsx +138 -0
  47. package/client/editor/slash.ts +166 -0
  48. package/client/entry.tsx +2 -0
  49. package/client/head-metadata.ts +32 -0
  50. package/client/mdx-components-base.ts +2 -2
  51. package/client/router.ts +56 -17
  52. package/client/shell/AppShell.tsx +38 -15
  53. package/client/shell/Sidebar.tsx +20 -2
  54. package/client/shell/StandaloneShell.tsx +19 -6
  55. package/client/shell/TocRail.tsx +4 -3
  56. package/client/shell/TopBar.tsx +17 -5
  57. package/client/standalone-entry.tsx +11 -2
  58. package/client/state.ts +14 -0
  59. package/client/ui/ConfirmDeleteDialog.tsx +48 -91
  60. package/client/ui/ExpandModal.tsx +63 -104
  61. package/client/ui/Modal.tsx +123 -0
  62. package/client/ui/ResizeHandle.tsx +1 -1
  63. package/client/ui/SearchDialog.tsx +81 -88
  64. package/client/ui/modal.css +42 -0
  65. package/dist/cli.js +4644 -2830
  66. package/dist/diagram-worker.js +17 -0
  67. package/dist/registry.json +297 -0
  68. package/package.json +44 -3
  69. package/skills/mdxserve/SKILL.md +56 -1
@@ -1,3 +1,4 @@
1
+ import { Modal } from "./Modal";
1
2
  import {
2
3
  useEffect,
3
4
  useState,
@@ -5,10 +6,10 @@ import {
5
6
  type KeyboardEvent,
6
7
  type ReactNode,
7
8
  } from "react";
8
- import { AnimatePresence, motion, type MotionProps } from "framer-motion";
9
+ import { motion, type MotionProps } from "framer-motion";
9
10
  import { Icon } from "./Icon";
10
11
  import { Kbd } from "./Kbd";
11
- import { TRANSITIONS, VARIANTS } from "../motion";
12
+ import { TRANSITIONS } from "../motion";
12
13
 
13
14
  export interface SearchResult {
14
15
  title: ReactNode;
@@ -49,7 +50,7 @@ function highlight(text: ReactNode, terms: string[] | undefined): ReactNode {
49
50
  // React still types on `HTMLAttributes`); `Omit` it, along with the
50
51
  // motion.div-owned event props, before extending.
51
52
  export interface SearchDialogProps extends Omit<
52
- HTMLAttributes<HTMLDivElement>,
53
+ HTMLAttributes<HTMLDialogElement>,
53
54
  "results" | "onSelect" | keyof MotionProps
54
55
  > {
55
56
  open?: boolean;
@@ -79,7 +80,7 @@ export function SearchDialog({
79
80
  setHighlighted(0);
80
81
  }, [query, results, open]);
81
82
 
82
- function handleKeyDown(event: KeyboardEvent<HTMLDivElement>) {
83
+ function handleKeyDown(event: KeyboardEvent<HTMLDialogElement>) {
83
84
  if (event.key === "ArrowDown") {
84
85
  event.preventDefault();
85
86
  setHighlighted((current) => Math.min(current + 1, Math.max(results.length - 1, 0)));
@@ -92,96 +93,88 @@ export function SearchDialog({
92
93
  event.preventDefault();
93
94
  onSelect?.(result);
94
95
  }
95
- } else if (event.key === "Escape") {
96
- event.preventDefault();
97
- onClose?.();
98
96
  }
99
97
  }
100
98
 
101
99
  return (
102
- <AnimatePresence>
103
- {open ? (
104
- <motion.div
105
- key="scrim"
100
+ <Modal
101
+ open={open}
102
+ onClose={onClose}
103
+ placement="top"
104
+ aria-label="Search docs"
105
+ className={"w-[560px] max-w-[calc(100vw-2rem)] overflow-hidden " + (className ?? "")}
106
+ onKeyDown={handleKeyDown}
107
+ {...rest}
108
+ >
109
+ <div className="flex h-12 items-center gap-3 border-b border-border-subtle px-4">
110
+ <Icon name="search" size="md" className="text-text-subtle" />
111
+ <input
112
+ autoFocus
113
+ data-bare-focus
114
+ value={query}
115
+ onChange={(event) => onQueryChange?.(event.target.value)}
116
+ placeholder="Search docs"
117
+ aria-label="Search docs"
118
+ className="min-w-0 flex-1 border-0 bg-transparent text-[18px] font-normal text-text-body outline-none placeholder:text-text-subtle"
119
+ />
120
+ <button
121
+ type="button"
122
+ aria-label="Close search"
106
123
  onClick={onClose}
107
- {...VARIANTS.scrim}
108
- className="fixed inset-0 z-[var(--z-modal)] flex justify-center bg-[var(--scrim)] pt-[10vh] backdrop-blur-sm"
124
+ className="flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-md text-text-subtle md:hidden"
109
125
  >
110
- <motion.div
111
- onClick={(event) => event.stopPropagation()}
112
- onKeyDown={handleKeyDown}
113
- {...VARIANTS.pop}
114
- className={
115
- "w-[560px] max-w-[92vw] self-start overflow-hidden rounded-xl border border-border-default bg-surface-raised shadow-lg" +
116
- (className ? " " + className : "")
117
- }
118
- {...rest}
119
- >
120
- <div className="flex h-12 items-center gap-3 border-b border-border-subtle px-4">
121
- <Icon name="search" size="md" className="text-text-subtle" />
122
- <input
123
- autoFocus
124
- data-bare-focus
125
- value={query}
126
- onChange={(event) => onQueryChange?.(event.target.value)}
127
- placeholder="Search docs"
128
- className="flex-1 border-0 bg-transparent text-[18px] font-normal text-text-body outline-none placeholder:text-text-subtle"
129
- />
130
- <Kbd>esc</Kbd>
131
- </div>
132
- <motion.div
133
- layout
134
- transition={TRANSITIONS.glide}
135
- className="max-h-80 overflow-y-auto p-2"
136
- >
137
- {results.length === 0 ? (
138
- <div className="p-6 text-center text-[13px] leading-normal font-medium text-text-subtle">
139
- No matches
126
+ <Icon name="x" size="sm" />
127
+ </button>
128
+ <span className="hidden md:contents">
129
+ <Kbd>esc</Kbd>
130
+ </span>
131
+ </div>
132
+ <motion.div layout transition={TRANSITIONS.glide} className="max-h-80 overflow-y-auto p-2">
133
+ {results.length === 0 ? (
134
+ <div className="p-6 text-center text-[13px] leading-normal font-medium text-text-subtle">
135
+ No matches
136
+ </div>
137
+ ) : (
138
+ results.map((result, index) => {
139
+ const active = index === highlighted;
140
+ return (
141
+ <motion.div
142
+ key={(result.path ?? "") + index}
143
+ layout
144
+ initial={{ opacity: 0, y: 4 }}
145
+ animate={{ opacity: 1, y: 0 }}
146
+ transition={{
147
+ ...TRANSITIONS.glide,
148
+ delay: Math.min(index, STAGGER_CAP - 1) * 0.02,
149
+ }}
150
+ onMouseEnter={() => setHighlighted(index)}
151
+ onClick={() => onSelect?.(result)}
152
+ className={
153
+ "flex cursor-pointer items-start gap-3 rounded-md p-2.5 " +
154
+ (active ? "bg-surface-hover" : "bg-transparent")
155
+ }
156
+ >
157
+ <Icon name="file-text" size="sm" className="mt-0.5 text-text-subtle" />
158
+ <div className="min-w-0 flex-1">
159
+ {result.label ? (
160
+ <div className="overflow-hidden text-ellipsis whitespace-nowrap font-mono text-[length:var(--size-2xs)] text-text-subtle">
161
+ {highlight(result.label, result.terms)}
162
+ </div>
163
+ ) : null}
164
+ <div className="text-[13px] leading-normal font-semibold text-text-heading">
165
+ {highlight(result.title, result.terms)}
166
+ </div>
167
+ {result.excerpt ? (
168
+ <div className="mt-px overflow-hidden text-ellipsis whitespace-nowrap text-[12px] font-normal text-text-muted">
169
+ {highlight(result.excerpt, result.terms)}
170
+ </div>
171
+ ) : null}
140
172
  </div>
141
- ) : (
142
- results.map((result, index) => {
143
- const active = index === highlighted;
144
- return (
145
- <motion.div
146
- key={(result.path ?? "") + index}
147
- layout
148
- initial={{ opacity: 0, y: 4 }}
149
- animate={{ opacity: 1, y: 0 }}
150
- transition={{
151
- ...TRANSITIONS.glide,
152
- delay: Math.min(index, STAGGER_CAP - 1) * 0.02,
153
- }}
154
- onMouseEnter={() => setHighlighted(index)}
155
- onClick={() => onSelect?.(result)}
156
- className={
157
- "flex cursor-pointer items-start gap-3 rounded-md p-2.5 " +
158
- (active ? "bg-surface-hover" : "bg-transparent")
159
- }
160
- >
161
- <Icon name="file-text" size="sm" className="mt-0.5 text-text-subtle" />
162
- <div className="min-w-0 flex-1">
163
- {result.label ? (
164
- <div className="overflow-hidden text-ellipsis whitespace-nowrap font-mono text-[length:var(--size-2xs)] text-text-subtle">
165
- {highlight(result.label, result.terms)}
166
- </div>
167
- ) : null}
168
- <div className="text-[13px] leading-normal font-semibold text-text-heading">
169
- {highlight(result.title, result.terms)}
170
- </div>
171
- {result.excerpt ? (
172
- <div className="mt-px overflow-hidden text-ellipsis whitespace-nowrap text-[12px] font-normal text-text-muted">
173
- {highlight(result.excerpt, result.terms)}
174
- </div>
175
- ) : null}
176
- </div>
177
- </motion.div>
178
- );
179
- })
180
- )}
181
- </motion.div>
182
- </motion.div>
183
- </motion.div>
184
- ) : null}
185
- </AnimatePresence>
173
+ </motion.div>
174
+ );
175
+ })
176
+ )}
177
+ </motion.div>
178
+ </Modal>
186
179
  );
187
180
  }
@@ -0,0 +1,42 @@
1
+ .modal {
2
+ position: fixed;
3
+ inset: 0;
4
+ margin: auto;
5
+ padding: 0;
6
+ max-width: calc(100vw - 32px);
7
+ max-height: calc(100dvh - 32px);
8
+ border: 1px solid var(--border-default);
9
+ border-radius: var(--radius-xl, 12px);
10
+ background: var(--surface-raised);
11
+ color: var(--text-body);
12
+ box-shadow: 0 28px 100px #0006;
13
+ }
14
+ .modal::backdrop {
15
+ background: var(--scrim);
16
+ backdrop-filter: blur(4px);
17
+ animation: modal-backdrop-in var(--dur-fast) var(--ease-standard) both;
18
+ }
19
+ .modal--top {
20
+ margin-top: 10vh;
21
+ max-height: 80dvh;
22
+ }
23
+
24
+ .modal[data-exiting]::backdrop {
25
+ animation-name: modal-backdrop-out;
26
+ }
27
+ @keyframes modal-backdrop-in {
28
+ from {
29
+ opacity: 0;
30
+ }
31
+ to {
32
+ opacity: 1;
33
+ }
34
+ }
35
+ @keyframes modal-backdrop-out {
36
+ from {
37
+ opacity: 1;
38
+ }
39
+ to {
40
+ opacity: 0;
41
+ }
42
+ }