@particle-academy/react-fancy 5.60.2 → 5.61.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.
- package/CHANGELOG.md +42 -0
- package/dist/autocomplete.cjs +4 -3
- package/dist/autocomplete.js +3 -2
- package/dist/{chunk-EEMNTO7L.cjs → chunk-3DMVK74Q.cjs} +4 -4
- package/dist/{chunk-EEMNTO7L.cjs.map → chunk-3DMVK74Q.cjs.map} +1 -1
- package/dist/{chunk-M77BB2QI.cjs → chunk-3I6PE2US.cjs} +12 -12
- package/dist/{chunk-M77BB2QI.cjs.map → chunk-3I6PE2US.cjs.map} +1 -1
- package/dist/{chunk-TGBLDJ72.js → chunk-4FJWHVC7.js} +3 -3
- package/dist/{chunk-TGBLDJ72.js.map → chunk-4FJWHVC7.js.map} +1 -1
- package/dist/{chunk-EXQ33MJR.cjs → chunk-4HUD33OP.cjs} +4 -4
- package/dist/{chunk-EXQ33MJR.cjs.map → chunk-4HUD33OP.cjs.map} +1 -1
- package/dist/chunk-4JLFIPHZ.js +43 -0
- package/dist/chunk-4JLFIPHZ.js.map +1 -0
- package/dist/{chunk-XAQQX7J2.cjs → chunk-4TTBPEQX.cjs} +48 -13
- package/dist/chunk-4TTBPEQX.cjs.map +1 -0
- package/dist/{chunk-YQTKTEWS.js → chunk-5JFA7NYE.js} +3 -3
- package/dist/{chunk-YQTKTEWS.js.map → chunk-5JFA7NYE.js.map} +1 -1
- package/dist/chunk-5VMILVWD.js +3 -0
- package/dist/chunk-5VMILVWD.js.map +1 -0
- package/dist/{chunk-DN244T6G.cjs → chunk-6GBO7R25.cjs} +4 -4
- package/dist/{chunk-DN244T6G.cjs.map → chunk-6GBO7R25.cjs.map} +1 -1
- package/dist/{chunk-4FZOH7BJ.js → chunk-74MEJWMH.js} +3 -3
- package/dist/{chunk-4FZOH7BJ.js.map → chunk-74MEJWMH.js.map} +1 -1
- package/dist/{chunk-4DGXL6JC.cjs → chunk-7KTBVKNO.cjs} +4 -4
- package/dist/{chunk-4DGXL6JC.cjs.map → chunk-7KTBVKNO.cjs.map} +1 -1
- package/dist/{chunk-XQDGUXMS.js → chunk-BHUSI56C.js} +3 -3
- package/dist/{chunk-XQDGUXMS.js.map → chunk-BHUSI56C.js.map} +1 -1
- package/dist/{chunk-UIE5FP3A.js → chunk-BQFPC5FL.js} +3 -3
- package/dist/{chunk-UIE5FP3A.js.map → chunk-BQFPC5FL.js.map} +1 -1
- package/dist/{chunk-VD3C7IA4.js → chunk-CEZVKKYW.js} +48 -13
- package/dist/chunk-CEZVKKYW.js.map +1 -0
- package/dist/{chunk-UZG6LO4Z.cjs → chunk-FU6K7XXZ.cjs} +4 -4
- package/dist/{chunk-UZG6LO4Z.cjs.map → chunk-FU6K7XXZ.cjs.map} +1 -1
- package/dist/{chunk-5ZNOLPIJ.cjs → chunk-H2YRZYKK.cjs} +5 -5
- package/dist/{chunk-5ZNOLPIJ.cjs.map → chunk-H2YRZYKK.cjs.map} +1 -1
- package/dist/{chunk-7R7HENZG.cjs → chunk-HRYM76ZE.cjs} +9 -9
- package/dist/{chunk-7R7HENZG.cjs.map → chunk-HRYM76ZE.cjs.map} +1 -1
- package/dist/{chunk-ZGQEKDG6.js → chunk-IHQHTJNN.js} +5 -5
- package/dist/{chunk-ZGQEKDG6.js.map → chunk-IHQHTJNN.js.map} +1 -1
- package/dist/{chunk-6HJF55U7.js → chunk-IY6LVALS.js} +3 -3
- package/dist/{chunk-6HJF55U7.js.map → chunk-IY6LVALS.js.map} +1 -1
- package/dist/{chunk-HTNQ5XUR.cjs → chunk-J4FKJ4IR.cjs} +4 -4
- package/dist/{chunk-HTNQ5XUR.cjs.map → chunk-J4FKJ4IR.cjs.map} +1 -1
- package/dist/{chunk-43ZRUYJC.cjs → chunk-JOWAS5A5.cjs} +9 -9
- package/dist/{chunk-43ZRUYJC.cjs.map → chunk-JOWAS5A5.cjs.map} +1 -1
- package/dist/{chunk-JRRYYW3Y.cjs → chunk-K6NADZ7O.cjs} +6 -6
- package/dist/{chunk-JRRYYW3Y.cjs.map → chunk-K6NADZ7O.cjs.map} +1 -1
- package/dist/{chunk-5JA4ENMF.js → chunk-LMOPAY7Q.js} +3 -3
- package/dist/{chunk-5JA4ENMF.js.map → chunk-LMOPAY7Q.js.map} +1 -1
- package/dist/{chunk-DAJPPKPO.js → chunk-M52S3TFI.js} +3 -3
- package/dist/{chunk-DAJPPKPO.js.map → chunk-M52S3TFI.js.map} +1 -1
- package/dist/{chunk-GLGUQGAQ.cjs → chunk-M6MGQI6G.cjs} +4 -4
- package/dist/{chunk-GLGUQGAQ.cjs.map → chunk-M6MGQI6G.cjs.map} +1 -1
- package/dist/chunk-MKHYENKR.cjs +4 -0
- package/dist/chunk-MKHYENKR.cjs.map +1 -0
- package/dist/{chunk-NHGU2BWT.js → chunk-MSGKIWYX.js} +3 -3
- package/dist/{chunk-NHGU2BWT.js.map → chunk-MSGKIWYX.js.map} +1 -1
- package/dist/{chunk-KQYOIPHQ.js → chunk-N7KUGFRG.js} +4 -4
- package/dist/{chunk-KQYOIPHQ.js.map → chunk-N7KUGFRG.js.map} +1 -1
- package/dist/{chunk-XB3H2EEL.js → chunk-NDLESFUH.js} +3 -3
- package/dist/{chunk-XB3H2EEL.js.map → chunk-NDLESFUH.js.map} +1 -1
- package/dist/chunk-NE3BZV3F.js +224 -0
- package/dist/chunk-NE3BZV3F.js.map +1 -0
- package/dist/{chunk-XYOT75HH.js → chunk-NORVXHRU.js} +3 -3
- package/dist/{chunk-XYOT75HH.js.map → chunk-NORVXHRU.js.map} +1 -1
- package/dist/chunk-O4HZVZMY.cjs +226 -0
- package/dist/chunk-O4HZVZMY.cjs.map +1 -0
- package/dist/{chunk-5H6IUCOD.cjs → chunk-P6V4QWJK.cjs} +4 -4
- package/dist/{chunk-5H6IUCOD.cjs.map → chunk-P6V4QWJK.cjs.map} +1 -1
- package/dist/{chunk-LZHGXRFD.js → chunk-PKFEJWVI.js} +3 -3
- package/dist/{chunk-LZHGXRFD.js.map → chunk-PKFEJWVI.js.map} +1 -1
- package/dist/chunk-QMCMRQ2G.cjs +53 -0
- package/dist/chunk-QMCMRQ2G.cjs.map +1 -0
- package/dist/{chunk-BJKKW77L.cjs → chunk-QXMQVLRQ.cjs} +4 -4
- package/dist/{chunk-BJKKW77L.cjs.map → chunk-QXMQVLRQ.cjs.map} +1 -1
- package/dist/{chunk-WHEXTDPV.js → chunk-RBCMKPBX.js} +7 -5
- package/dist/chunk-RBCMKPBX.js.map +1 -0
- package/dist/{chunk-LVE6ERRS.cjs → chunk-RRMQGTVB.cjs} +6 -6
- package/dist/{chunk-LVE6ERRS.cjs.map → chunk-RRMQGTVB.cjs.map} +1 -1
- package/dist/{chunk-T67FLC55.js → chunk-SHF44YGG.js} +3 -3
- package/dist/{chunk-T67FLC55.js.map → chunk-SHF44YGG.js.map} +1 -1
- package/dist/{chunk-NBZC6LOB.cjs → chunk-TI7D4QDM.cjs} +6 -3
- package/dist/chunk-TI7D4QDM.cjs.map +1 -0
- package/dist/{chunk-5JK2VDWY.cjs → chunk-TYTENEJQ.cjs} +6 -6
- package/dist/{chunk-5JK2VDWY.cjs.map → chunk-TYTENEJQ.cjs.map} +1 -1
- package/dist/{chunk-WW56U3RV.js → chunk-UBEOB55O.js} +3 -3
- package/dist/{chunk-WW56U3RV.js.map → chunk-UBEOB55O.js.map} +1 -1
- package/dist/chunk-UGXBTIV5.js +51 -0
- package/dist/chunk-UGXBTIV5.js.map +1 -0
- package/dist/{chunk-M6XBF2ZS.js → chunk-UJZJBHMH.js} +3 -3
- package/dist/{chunk-M6XBF2ZS.js.map → chunk-UJZJBHMH.js.map} +1 -1
- package/dist/{chunk-T45LBTXH.js → chunk-ULG4OA2T.js} +3 -3
- package/dist/{chunk-T45LBTXH.js.map → chunk-ULG4OA2T.js.map} +1 -1
- package/dist/{chunk-SIEPD6NR.cjs → chunk-UM4JXBRZ.cjs} +4 -4
- package/dist/{chunk-SIEPD6NR.cjs.map → chunk-UM4JXBRZ.cjs.map} +1 -1
- package/dist/{chunk-FGI2EC32.cjs → chunk-Z5OTOYWI.cjs} +4 -4
- package/dist/{chunk-FGI2EC32.cjs.map → chunk-Z5OTOYWI.cjs.map} +1 -1
- package/dist/chunk-ZPBCZPMD.cjs +48 -0
- package/dist/chunk-ZPBCZPMD.cjs.map +1 -0
- package/dist/command.cjs +5 -4
- package/dist/command.js +3 -2
- package/dist/composer.cjs +7 -6
- package/dist/composer.js +5 -4
- package/dist/context-menu.cjs +5 -4
- package/dist/context-menu.js +3 -2
- package/dist/drawer.cjs +5 -4
- package/dist/drawer.js +3 -2
- package/dist/dropdown.cjs +5 -4
- package/dist/dropdown.js +3 -2
- package/dist/editor.cjs +8 -3
- package/dist/editor.d.cts +53 -4
- package/dist/editor.d.ts +53 -4
- package/dist/editor.js +6 -1
- package/dist/full-screen.cjs +39 -0
- package/dist/full-screen.cjs.map +1 -0
- package/dist/full-screen.d.cts +54 -0
- package/dist/full-screen.d.ts +54 -0
- package/dist/full-screen.js +10 -0
- package/dist/full-screen.js.map +1 -0
- package/dist/index.cjs +152 -120
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +35 -31
- package/dist/index.js.map +1 -1
- package/dist/input.cjs +6 -5
- package/dist/input.js +5 -4
- package/dist/inputs.cjs +17 -16
- package/dist/inputs.js +9 -8
- package/dist/json-editor.cjs +19 -18
- package/dist/json-editor.js +8 -7
- package/dist/magic-wand.cjs +4 -3
- package/dist/magic-wand.js +3 -2
- package/dist/mobile-menu.cjs +6 -4
- package/dist/mobile-menu.js +4 -2
- package/dist/modal.cjs +5 -4
- package/dist/modal.js +3 -2
- package/dist/paste-pills.cjs +17 -16
- package/dist/paste-pills.js +4 -3
- package/dist/popover.cjs +5 -4
- package/dist/popover.js +3 -2
- package/dist/portal.cjs +7 -2
- package/dist/portal.d.cts +12 -1
- package/dist/portal.d.ts +12 -1
- package/dist/portal.js +2 -1
- package/dist/prompt-input.cjs +7 -6
- package/dist/prompt-input.js +6 -5
- package/dist/reason-tag.cjs +5 -4
- package/dist/reason-tag.js +4 -3
- package/dist/select.cjs +4 -3
- package/dist/select.js +3 -2
- package/dist/sidebar.cjs +1 -0
- package/dist/sidebar.js +1 -0
- package/dist/toast.cjs +5 -4
- package/dist/toast.js +3 -2
- package/dist/tooltip.cjs +4 -3
- package/dist/tooltip.js +3 -2
- package/dist/use-full-screen-H2j6qXDB.d.cts +85 -0
- package/dist/use-full-screen-H2j6qXDB.d.ts +85 -0
- package/docs/Editor.md +24 -0
- package/docs/FullScreen.md +95 -0
- package/package.json +11 -1
- package/dist/chunk-NBZC6LOB.cjs.map +0 -1
- package/dist/chunk-VD3C7IA4.js.map +0 -1
- package/dist/chunk-WHEXTDPV.js.map +0 -1
- package/dist/chunk-XAQQX7J2.cjs.map +0 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# FullScreen
|
|
2
|
+
|
|
3
|
+
One full-screen behaviour for every surface that can take over the viewport. `Editor` uses it; DeckEditor (fancy-slides) and SheetWorkbook (fancy-sheets) are meant to adopt the same hook.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { FullScreen, useFullScreen, FullScreenProvider } from "@particle-academy/react-fancy";
|
|
9
|
+
// or the subpath
|
|
10
|
+
import { FullScreen } from "@particle-academy/react-fancy/full-screen";
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## A box with a toggle
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
<FullScreen className="rounded-xl border bg-white dark:bg-zinc-900">
|
|
17
|
+
<FullScreen.Toggle />
|
|
18
|
+
<Chart … />
|
|
19
|
+
</FullScreen>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Give it a background: while active it covers the page, and in `native` mode the browser paints black behind anything transparent.
|
|
23
|
+
|
|
24
|
+
## A surface that owns its root
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
function DeckEditor({ fullScreen, defaultFullScreen, onFullScreenChange }) {
|
|
28
|
+
const fs = useFullScreen<HTMLDivElement>({ fullScreen, defaultFullScreen, onFullScreenChange });
|
|
29
|
+
return (
|
|
30
|
+
<FullScreenProvider value={fs}>
|
|
31
|
+
<div {...fs.targetProps} data-fancy-deck-editor="" className="flex flex-col …">
|
|
32
|
+
<Toolbar>
|
|
33
|
+
<FullScreen.Toggle />
|
|
34
|
+
</Toolbar>
|
|
35
|
+
<Canvas className="min-h-0 flex-1" />
|
|
36
|
+
</div>
|
|
37
|
+
</FullScreenProvider>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`targetProps` carries the ref, `data-fullscreen`, the overlay `style` and the `onKeyDown` handler. If the root has its own `style` or `onKeyDown`, merge them. `FullScreenProvider` makes `<FullScreen.Toggle />` work anywhere inside and redirects descendant `<Portal>`s into the surface while it is active.
|
|
43
|
+
|
|
44
|
+
## Overlay or the browser's Fullscreen API
|
|
45
|
+
|
|
46
|
+
| `mode` | What happens | When it fails |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| `"overlay"` (default) | The element itself becomes `position: fixed` over the viewport, in place, with `z-index` 50 (as `Modal`) | Never refused. An ancestor with `transform`, `filter`, `perspective` or `contain: paint` confines it to that ancestor |
|
|
49
|
+
| `"native"` | The overlay, plus `element.requestFullscreen()` so the browser chrome hides too | Refused in an iframe without `allow="fullscreen"`, without a user gesture, or by a permissions policy. It then stays in the overlay. `data-fullscreen-mode` says which one is active |
|
|
50
|
+
|
|
51
|
+
The overlay is the default because it never asks the browser for permission. The element is not portalled, so nothing inside remounts. An editor keeps its caret, undo history and seeded content.
|
|
52
|
+
|
|
53
|
+
In `native` mode the browser handles Esc itself. When the user leaves through the browser's UI, `onFullScreenChange(false)` fires so controlled state stays in sync.
|
|
54
|
+
|
|
55
|
+
## Behaviour
|
|
56
|
+
|
|
57
|
+
- **Controlled:** `fullScreen` + `onFullScreenChange`, or `defaultFullScreen` uncontrolled. `onFullScreenChange` only fires on real transitions.
|
|
58
|
+
- **Escape** leaves full screen. An Escape that a child already handled (`preventDefault`), or that comes from a menu or dialog opened from inside, is left to that child. The Escape is stopped at the surface, so an enclosing dialog does not also close. `closeOnEscape={false}` turns this off.
|
|
59
|
+
- **Focus** moves inside on entry if it was outside. On exit it returns to the element that had it before, unless the user has since focused something else. Tab wraps within the surface.
|
|
60
|
+
- **Scroll:** body scroll is locked while active (`lockScroll`, reference-counted). On exit the window and every scrolled ancestor go back to their offsets. Those offsets are read before the surface leaves the flow, which would otherwise clamp them.
|
|
61
|
+
- **SSR:** nothing touches `window` or `document` during render. A surface that starts full screen renders the overlay on the server.
|
|
62
|
+
|
|
63
|
+
## Props / options
|
|
64
|
+
|
|
65
|
+
| Prop | Type | Default | Description |
|
|
66
|
+
|------|------|---------|-------------|
|
|
67
|
+
| fullScreen | `boolean` | - | Controlled flag |
|
|
68
|
+
| defaultFullScreen | `boolean` | `false` | Initial flag when uncontrolled |
|
|
69
|
+
| onFullScreenChange | `(fullScreen: boolean) => void` | - | Requested state, from the toggle, Escape, `setFullScreen` or the browser |
|
|
70
|
+
| mode | `"overlay" \| "native"` | `"overlay"` | See above |
|
|
71
|
+
| closeOnEscape | `boolean` | `true` | Leave on Escape |
|
|
72
|
+
| lockScroll | `boolean` | `true` | Lock body scroll while active |
|
|
73
|
+
| zIndex | `number` | `50` | Stacking order of the overlay |
|
|
74
|
+
| labels | `{ enter?: string; exit?: string }` | "Enter full screen" / "Exit full screen" | Toggle accessible names |
|
|
75
|
+
|
|
76
|
+
`useFullScreen()` returns `{ fullScreen, setFullScreen, toggle, activeMode, ref, targetProps, toggleProps, portalContainer }`.
|
|
77
|
+
|
|
78
|
+
### FullScreen.Toggle
|
|
79
|
+
|
|
80
|
+
| Prop | Type | Default | Description |
|
|
81
|
+
|------|------|---------|-------------|
|
|
82
|
+
| enterIcon | `string` | `"maximize-2"` | Lucide name shown while not full screen |
|
|
83
|
+
| exitIcon | `string` | `"minimize-2"` | Lucide name shown while full screen |
|
|
84
|
+
| children | `ReactNode \| (fullScreen) => ReactNode` | - | Replace the icon |
|
|
85
|
+
|
|
86
|
+
Renders nothing outside a `FullScreen` / `FullScreenProvider`.
|
|
87
|
+
|
|
88
|
+
## Data attributes
|
|
89
|
+
|
|
90
|
+
| Selector | Meaning |
|
|
91
|
+
|---|---|
|
|
92
|
+
| `[data-react-fancy-fullscreen]` | `<FullScreen>` root |
|
|
93
|
+
| `[data-fullscreen="true"]` | Any surface while full screen (also on the toggle) |
|
|
94
|
+
| `[data-fullscreen-mode="overlay" \| "native"]` | Which mechanism is active |
|
|
95
|
+
| `[data-react-fancy-fullscreen-toggle]` | Any full-screen toggle |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@particle-academy/react-fancy",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.61.0",
|
|
4
4
|
"description": "React UI component library for Human+ UX — controlled, agent-bridgeable primitives",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -373,6 +373,16 @@
|
|
|
373
373
|
"default": "./dist/file-upload.cjs"
|
|
374
374
|
}
|
|
375
375
|
},
|
|
376
|
+
"./full-screen": {
|
|
377
|
+
"import": {
|
|
378
|
+
"types": "./dist/full-screen.d.ts",
|
|
379
|
+
"default": "./dist/full-screen.js"
|
|
380
|
+
},
|
|
381
|
+
"require": {
|
|
382
|
+
"types": "./dist/full-screen.d.cts",
|
|
383
|
+
"default": "./dist/full-screen.cjs"
|
|
384
|
+
}
|
|
385
|
+
},
|
|
376
386
|
"./grid": {
|
|
377
387
|
"import": {
|
|
378
388
|
"types": "./dist/grid.d.ts",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Portal/Portal.tsx"],"names":["useState","useEffect","createPortal","jsx","useRef"],"mappings":";;;;;;;AAQO,SAAS,MAAA,CAAO,EAAE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AA,EAAG,EAAE,CAAA;AAEL,EAAA,uBACEE,cAAA,CAAC,KAAA,EAAA,EAAI,GAAA,EAAU,yBAAA,EAAwB,EAAA,EAAG,OAAO,EAAE,OAAA,EAAS,UAAA,EAAW,EACpE,QAAA,EACH,CAAA;AAEJ","file":"chunk-NBZC6LOB.cjs","sourcesContent":["import { createPortal } from \"react-dom\";\nimport { useEffect, useRef, useState, type ReactNode } from \"react\";\n\nexport interface PortalProps {\n children: ReactNode;\n container?: HTMLElement;\n}\n\nexport function Portal({ children, container }: PortalProps) {\n // Render nothing on the server AND on the client's first (hydration) render,\n // then portal after mount. Without the `mounted` gate the client would render\n // the portal immediately while the server rendered null — a hydration\n // mismatch (the portal wrapper appears client-only). Deferring to after mount\n // keeps the first client render identical to the server. SSR-safe for every\n // Portal consumer (Toast, Modal, Dropdown, Tooltip, Popover, …).\n const [mounted, setMounted] = useState(false);\n useEffect(() => {\n setMounted(true);\n }, []);\n\n if (!mounted || typeof document === \"undefined\") return null;\n\n const target = container ?? document.body;\n\n return createPortal(\n <PortalDarkWrapper>{children}</PortalDarkWrapper>,\n target,\n );\n}\n\n/**\n * Wrapper that propagates the `dark` class from <html> into the portal subtree.\n * This ensures Tailwind `dark:` utilities work even though Portal renders\n * outside the React component tree.\n */\nfunction PortalDarkWrapper({ children }: { children: ReactNode }) {\n const ref = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const root = document.documentElement;\n const wrapper = ref.current;\n if (!wrapper) return;\n\n const sync = () => {\n const isDark =\n root.classList.contains(\"dark\") ||\n root.getAttribute(\"data-theme\") === \"dark\";\n wrapper.classList.toggle(\"dark\", isDark);\n };\n\n sync();\n\n const observer = new MutationObserver(sync);\n observer.observe(root, {\n attributes: true,\n attributeFilter: [\"class\", \"data-theme\"],\n });\n\n return () => observer.disconnect();\n }, []);\n\n return (\n <div ref={ref} data-react-fancy-portal=\"\" style={{ display: \"contents\" }}>\n {children}\n </div>\n );\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Editor/Editor.context.ts","../src/components/Editor/EditorSourceToggle.tsx","../src/components/Editor/EditorToolbar.tsx","../src/components/Editor/EditorToolbarSeparator.tsx","../src/components/Editor/EditorContent.tsx","../src/components/Editor/Editor.tsx"],"names":["jsx","useRef","useEffect","useMemo"],"mappings":";;;;;;;;;;AA4BO,IAAM,aAAA,GAAgB,cAAyC,IAAI,CAAA;AAEnE,SAAS,SAAA,GAAgC;AAC9C,EAAA,MAAM,GAAA,GAAM,WAAW,aAAa,CAAA;AACpC,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,MAAM,IAAI,MAAM,qDAAqD,CAAA;AAAA,EACvE;AACA,EAAA,OAAO,GAAA;AACT;AC3BO,SAAS,kBAAA,CAAmB;AAAA,EACjC,SAAA;AAAA,EACA,IAAA,GAAO,KAAA;AAAA,EACP,KAAA,GAAQ,QAAA;AAAA,EACR,WAAA,GAAc;AAChB,CAAA,EAA4B;AAC1B,EAAA,MAAM,EAAE,UAAA,EAAY,aAAA,EAAc,GAAI,SAAA,EAAU;AAEhD,EAAA,uBACE,GAAA;AAAA,IAAC,QAAA;AAAA,IAAA;AAAA,MACC,IAAA,EAAK,QAAA;AAAA,MACL,OAAA,EAAS,MAAM,aAAA,CAAc,CAAC,UAAU,CAAA;AAAA,MACxC,KAAA,EAAO,aAAa,WAAA,GAAc,KAAA;AAAA,MAClC,cAAA,EAAc,UAAA;AAAA,MACd,uCAAA,EAAsC,EAAA;AAAA,MACtC,SAAA,EAAW,EAAA;AAAA,QACT,iGAAA;AAAA,QACA,aACI,qHAAA,GACA,+IAAA;AAAA,QACJ;AAAA,OACF;AAAA,MAEC,QAAA,EAAA;AAAA;AAAA,GACH;AAEJ;AAEA,kBAAA,CAAmB,WAAA,GAAc,oBAAA;AChCjC,IAAM,eAAA,GAAkB;AAAA,EACtB,EAAE,IAAA,EAAM,GAAA,EAAK,KAAA,EAAO,MAAA,EAAQ,SAAS,MAAA,EA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A,CAAc,UAAd,EAAuB,KAAA,EAAO,cAC7B,QAAA,kBAAAA,GAAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,yBAAA,EAAwB,EAAA;AAAA,MACxB,WAAA,EAAU,MAAA;AAAA,MACV,SAAA,EAAW,EAAA;AAAA,QACT,gSAAA;AAAA,QACA;AAAA,OACF;AAAA,MAEC;AAAA;AAAA,GACH,EACF,CAAA;AAEJ;AAEA,IAAM,oBAAA,GAAuB,MAAA,CAAO,MAAA,CAAO,aAAA,EAAe;AAAA,EACxD,SAAA,EAAW;AACb,CAAC,CAAA;AAEM,IAAM,MAAA,GAAS,MAAA,CAAO,MAAA,CAAO,UAAA,EAAY;AAAA,EAC9C,OAAA,EAAS,oBAAA;AAAA,EACT,OAAA,EAAS,aAAA;AAAA,EACT,YAAA,EAAc;AAChB,CAAC","file":"chunk-VD3C7IA4.js","sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { RefObject } from \"react\";\nimport type { RenderExtension } from \"../ContentRenderer/extensions\";\n\nexport interface EditorContextValue {\n contentRef: RefObject<HTMLDivElement | null>;\n exec: (command: string, arg?: string) => void;\n insertText: (text: string) => void;\n wrapSelection: (before: string, after: string) => void;\n outputFormat: \"html\" | \"markdown\";\n lineSpacing: number;\n placeholder?: string;\n /** Merged render extensions (global + instance). */\n extensions: RenderExtension[];\n /** Whether the raw-source view (textarea) is showing instead of the rich-text surface. */\n showSource: boolean;\n /** Toggle/set the raw-source view. */\n setShowSource: (showSource: boolean) => void;\n /** Initial HTML content to load into the editor on mount */\n _initialHtml: string;\n /** @internal Called by EditorContent on input events */\n _onInput: () => void;\n /** @internal Raw source value (`value` in `outputFormat`), for the source textarea. */\n _sourceValue: string;\n /** @internal Commit an edit made directly in the source textarea. */\n _onSourceInput: (value: string) => void;\n}\n\nexport const EditorContext = createContext<EditorContextValue | null>(null);\n\nexport function useEditor(): EditorContextValue {\n const ctx = useContext(EditorContext);\n if (!ctx) {\n throw new Error(\"useEditor must be used within an <Editor> component\");\n }\n return ctx;\n}\n","import { cn } from \"../../utils/cn\";\nimport { useEditor } from \"./Editor.context\";\nimport type { EditorSourceToggleProps } from \"./Editor.types\";\n\n/**\n * Toolbar button that reveals the raw HTML/Markdown behind the editor. Reads\n * `showSource` / `setShowSource` from context, so it works in the default\n * toolbar and in any custom toolbar composed with `useEditor()`.\n */\nexport function EditorSourceToggle({\n className,\n icon = \"</>\",\n title = \"Source\",\n activeTitle = \"Rich text\",\n}: EditorSourceToggleProps) {\n const { showSource, setShowSource } = useEditor();\n\n return (\n <button\n type=\"button\"\n onClick={() => setShowSource(!showSource)}\n title={showSource ? activeTitle : title}\n aria-pressed={showSource}\n data-react-fancy-editor-source-toggle=\"\"\n className={cn(\n \"inline-flex h-8 items-center justify-center rounded-md px-2 font-mono text-xs transition-colors\",\n showSource\n ? \"bg-[color:var(--fancy-border,var(--color-zinc-200))] dark:bg-[color:var(--fancy-border-dark,var(--color-zinc-700))]\"\n : \"hover:bg-[color:var(--fancy-surface-muted,var(--color-zinc-100))] dark:hover:bg-[color:var(--fancy-surface-muted-dark,var(--color-zinc-800))]\",\n className,\n )}\n >\n {icon}\n </button>\n );\n}\n\nEditorSourceToggle.displayName = \"EditorSourceToggle\";\n","import { cn } from \"../../utils/cn\";\nimport { useEditor } from \"./Editor.context\";\nimport { EditorSourceToggle } from \"./EditorSourceToggle\";\nimport type { EditorToolbarProps } from \"./Editor.types\";\n\nconst DEFAULT_ACTIONS = [\n { icon: \"B\", label: \"Bold\", command: \"bold\" },\n { icon: \"I\", label: \"Italic\", command: \"italic\" },\n { icon: \"U\", label: \"Underline\", command: \"underline\" },\n { icon: \"S\", label: \"Strikethrough\", command: \"strikeThrough\" },\n];\n\nexport function EditorToolbar({\n actions = DEFAULT_ACTIONS,\n onAction,\n children,\n className,\n showSourceToggle = true,\n}: EditorToolbarProps) {\n const { exec, showSource } = useEditor();\n\n return (\n <div\n data-react-fancy-editor-toolbar=\"\"\n className={cn(\n \"flex shrink-0 items-center gap-0.5 border-b border-[color:var(--fancy-border,var(--color-zinc-200))] px-2 py-1.5 dark:border-[color:var(--fancy-border-dark,var(--color-zinc-700))]\",\n className,\n )}\n >\n {children ?? (\n <>\n {actions.map((action) => (\n <button\n key={`${action.command}-${action.commandArg ?? \"\"}`}\n type=\"button\"\n // Rich-text commands don't apply to the raw-source textarea.\n disabled={showSource}\n onClick={() => {\n if (onAction) {\n onAction(action.command);\n } else {\n exec(action.command, action.commandArg);\n }\n }}\n title={action.label}\n className={cn(\n \"inline-flex h-8 w-8 items-center justify-center rounded-md text-sm transition-colors\",\n action.active\n ? \"bg-[color:var(--fancy-border,var(--color-zinc-200))] dark:bg-[color:var(--fancy-border-dark,var(--color-zinc-700))]\"\n : \"hover:bg-[color:var(--fancy-surface-muted,var(--color-zinc-100))] dark:hover:bg-[color:var(--fancy-surface-muted-dark,var(--color-zinc-800))]\",\n showSource && \"cursor-not-allowed opacity-40 hover:bg-transparent\",\n )}\n >\n {action.icon}\n </button>\n ))}\n {showSourceToggle && <EditorSourceToggle className=\"ml-auto\" />}\n </>\n )}\n </div>\n );\n}\n\nEditorToolbar.displayName = \"EditorToolbar\";\n","export function EditorToolbarSeparator() {\n return (\n <span\n data-react-fancy-editor-toolbar-separator=\"\"\n className=\"mx-1 h-5 w-px bg-[color:var(--fancy-border,var(--color-zinc-200))] dark:bg-[color:var(--fancy-border-dark,var(--color-zinc-700))]\"\n />\n );\n}\n\nEditorToolbarSeparator.displayName = \"EditorToolbarSeparator\";\n","import { useEffect, useMemo, useRef } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { CodeView } from \"../CodeView\";\nimport { useEditor } from \"./Editor.context\";\nimport { proseClasses, extensionEditorClasses } from \"./editor.utils\";\nimport type { EditorContentProps } from \"./Editor.types\";\n\nexport function EditorContent({ className, maxHeight, sourceClassName }: EditorContentProps) {\n const {\n contentRef,\n lineSpacing,\n placeholder,\n extensions,\n outputFormat,\n showSource,\n _initialHtml,\n _onInput,\n _sourceValue,\n _onSourceInput,\n } = useEditor();\n // Tracks which seed HTML is currently in the contentEditable. Seeding on the\n // seed VALUE (not a one-shot boolean) re-seeds when the source view rewrites\n // `value`, while still never re-seeding on plain keystrokes — typing leaves\n // `_initialHtml` untouched, so `seededHtml.current === _initialHtml` holds.\n const seededHtml = useRef<string | null>(null);\n\n useEffect(() => {\n // Source view replaces the contentEditable in the tree, so it unmounts.\n // Forget what we seeded — the div that returns is a fresh, empty one and\n // must always be re-seeded, even if `value` was left untouched.\n if (showSource) {\n seededHtml.current = null;\n return;\n }\n const el = contentRef.current;\n if (el && seededHtml.current !== _initialHtml) {\n el.innerHTML = _initialHtml;\n seededHtml.current = _initialHtml;\n }\n }, [contentRef, _initialHtml, showSource]);\n\n const extClasses = useMemo(\n () => extensionEditorClasses(extensions),\n [extensions],\n );\n\n if (showSource) {\n // Raw-source view — a syntax-highlighted code surface (HTML highlighted;\n // markdown/plain un-highlighted), built on the shared fancy-file-commons\n // primitives. It's a DIRECT child of the flex-column editor root (no\n // wrapper — a nested flex box collapses the fill), so `flex-auto` makes it\n // fill the editor body when height-constrained and grow with content\n // (≥ minHeight) when not. `maxHeight` caps + scrolls.\n return (\n <CodeView\n value={_sourceValue}\n onChange={_onSourceInput}\n language={outputFormat === \"html\" ? \"html\" : \"plaintext\"}\n placeholder={placeholder}\n maxHeight={maxHeight}\n className={cn(\"min-h-0 flex-auto\", sourceClassName)}\n />\n );\n }\n\n return (\n <div\n ref={contentRef}\n contentEditable\n suppressContentEditableWarning\n data-react-fancy-editor-content=\"\"\n data-placeholder={placeholder}\n onInput={_onInput}\n style={{\n lineHeight: lineSpacing,\n maxHeight: maxHeight ? `${maxHeight}px` : undefined,\n }}\n className={cn(\n \"min-h-[120px] flex-auto overflow-y-auto px-4 py-3 text-sm outline-none\",\n \"focus:outline-none\",\n proseClasses,\n extClasses,\n \"empty:before:content-[attr(data-placeholder)] empty:before:text-zinc-400 empty:before:pointer-events-none\",\n className,\n )}\n />\n );\n}\n\nEditorContent.displayName = \"EditorContent\";\n","import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { marked } from \"marked\";\nimport { cn } from \"../../utils/cn\";\nimport { sanitizeHtml } from \"../../utils/sanitize\";\nimport { useControllableState } from \"../../hooks\";\nimport { EditorContext } from \"./Editor.context\";\nimport { EditorToolbar } from \"./EditorToolbar\";\nimport { EditorToolbarSeparator } from \"./EditorToolbarSeparator\";\nimport { EditorSourceToggle } from \"./EditorSourceToggle\";\nimport { EditorContent } from \"./EditorContent\";\nimport { htmlToMarkdown, detectFormat, markdownToEditorHtml, type MarkdownSource } from \"./editor.utils\";\nimport { mergeExtensions } from \"../ContentRenderer/extensions\";\nimport { ContentRenderer } from \"../ContentRenderer/ContentRenderer\";\nimport { useFieldMode } from \"../inputs/mode/FieldMode.context\";\nimport type { EditorProps } from \"./Editor.types\";\n\ninterface Seed {\n html: string;\n /** Source map for source-preserving markdown output; null when there is none. */\n source: MarkdownSource | null;\n}\n\nfunction toHtml(\n value: string,\n outputFormat: \"html\" | \"markdown\",\n unsafe: boolean,\n valueFormat: \"markdown\" | \"html\" | \"auto\" = \"auto\",\n): Seed {\n if (!value) return { html: \"\", source: null };\n const sanitize = (html: string) => (unsafe ? html : sanitizeHtml(html));\n // An explicit valueFormat is authoritative — the sniff misclassifies\n // markdown that merely MENTIONS HTML-ish snippets (`<code>`, `<table`),\n // collapsing it into an innerHTML wall of text (#10).\n const format =\n valueFormat !== \"auto\"\n ? valueFormat\n : outputFormat === \"html\"\n ? \"html\"\n : detectFormat(value);\n if (format === \"html\") return { html: sanitize(value), source: null };\n // Markdown in, markdown out: tag each block with its source so untouched\n // blocks are emitted byte-identical.\n if (outputFormat === \"markdown\") return markdownToEditorHtml(value, sanitize);\n return { html: sanitize((marked.parse(value, { async: false }) as string).trim()), source: null };\n}\n\nfunction EditorRoot({\n children,\n className,\n value: controlledValue,\n defaultValue = \"\",\n onChange,\n outputFormat = \"html\",\n valueFormat = \"auto\",\n lineSpacing = 1.6,\n placeholder,\n mode: modeProp,\n extensions: instanceExtensions,\n unsafe = false,\n showSource: showSourceProp,\n defaultShowSource = false,\n onShowSourceChange,\n}: EditorProps) {\n const contentRef = useRef<HTMLDivElement | null>(null);\n const [value, setValue] = useControllableState(controlledValue, defaultValue, onChange);\n const [showSource, setShowSource] = useControllableState(\n showSourceProp,\n defaultShowSource,\n onShowSourceChange,\n );\n // View/edit mode — same resolution as the inputs: prop → <Form> context → \"edit\".\n const mode = useFieldMode(modeProp);\n const isView = mode === \"view\";\n\n // The value this editor last emitted through `onChange`. An incoming `value`\n // equal to it is our own keystroke echoing back; anything else came from\n // OUTSIDE — an async load, a host reset, a form repopulating.\n const lastEmitted = useRef<string | null>(null);\n\n // Bumped only on an external `value` change, so the seed memo below recomputes\n // for those and stays put while the user types. Without this, `value` was\n // excluded from the deps to avoid re-seeding on keystrokes, which also meant a\n // value arriving after mount was silently dropped and the editor stayed blank\n // forever (#15).\n const [externalSeed, setExternalSeed] = useState(0);\n useEffect(() => {\n if (value !== lastEmitted.current) setExternalSeed((n) => n + 1);\n }, [value]);\n\n const seed = useMemo(\n () => toHtml(value, outputFormat, unsafe, valueFormat),\n // Seed the contentEditable from the LIVE value when (re)entering edit mode —\n // and when returning from the raw-source view, which may have rewritten the\n // value out from under the rich-text surface. `value` itself stays out of\n // the deps so typing never re-seeds (which would fight the caret);\n // `externalSeed` covers the externally-driven case instead.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [isView, outputFormat, unsafe, valueFormat, showSource, externalSeed],\n );\n const initialHtml = seed.html;\n const seedSource = seed.source;\n\n const extensions = useMemo(\n () => mergeExtensions(instanceExtensions),\n [instanceExtensions],\n );\n\n const getOutputValue = useCallback(\n (html: string): string => {\n return outputFormat === \"markdown\" ? htmlToMarkdown(html, seedSource) : html;\n },\n [outputFormat, seedSource],\n );\n\n const handleInput = useCallback(() => {\n const el = contentRef.current;\n if (!el) return;\n const next = getOutputValue(el.innerHTML);\n // Record what we emitted BEFORE publishing it, so the value coming back in\n // is recognised as our own and does not trigger a re-seed mid-keystroke.\n lastEmitted.current = next;\n setValue(next);\n }, [setValue, getOutputValue]);\n\n const exec = useCallback(\n (command: string, arg?: string) => {\n const el = contentRef.current;\n if (!el) return;\n el.focus();\n document.execCommand(command, false, arg);\n handleInput();\n },\n [handleInput],\n );\n\n const insertText = useCallback(\n (text: string) => {\n const el = contentRef.current;\n if (!el) return;\n el.focus();\n document.execCommand(\"insertText\", false, text);\n handleInput();\n },\n [handleInput],\n );\n\n // The source textarea edits `value` directly — it is already the canonical\n // source in `outputFormat` (html or markdown), so no conversion round-trip.\n const handleSourceInput = useCallback(\n (next: string) => {\n // Also an internal emission — record it so typing in the source view is\n // not mistaken for an external change on every keystroke.\n lastEmitted.current = next;\n setValue(next);\n },\n [setValue],\n );\n\n const wrapSelection = useCallback(\n (before: string, after: string) => {\n const sel = window.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n const selectedText = range.toString();\n const el = contentRef.current;\n if (!el) return;\n el.focus();\n document.execCommand(\"insertText\", false, `${before}${selectedText}${after}`);\n handleInput();\n },\n [handleInput],\n );\n\n const contextValue = {\n contentRef,\n exec,\n insertText,\n wrapSelection,\n outputFormat,\n lineSpacing,\n placeholder,\n extensions,\n showSource,\n setShowSource,\n _initialHtml: initialHtml,\n _onInput: handleInput,\n _sourceValue: value,\n _onSourceInput: handleSourceInput,\n };\n\n // View mode — render the value read-only through ContentRenderer, matching the\n // editor's own format (markdown/html), instead of the editable toolbar+content\n // tree. Driven by `mode` / a `<Form mode=\"view\">`, exactly like the inputs.\n if (isView) {\n return (\n <div\n data-react-fancy-editor=\"\"\n data-mode=\"view\"\n className={cn(\n \"overflow-hidden rounded-xl border border-[color:var(--fancy-border,var(--color-zinc-200))] bg-[color:var(--fancy-surface,var(--color-white))] dark:border-[color:var(--fancy-border-dark,var(--color-zinc-700))] dark:bg-[color:var(--fancy-surface-dark,var(--color-zinc-900))]\",\n className,\n )}\n >\n <ContentRenderer\n value={value}\n format={valueFormat !== \"auto\" ? valueFormat : outputFormat}\n lineSpacing={lineSpacing}\n extensions={instanceExtensions}\n unsafe={unsafe}\n className=\"px-4 py-3\"\n />\n </div>\n );\n }\n\n return (\n <EditorContext.Provider value={contextValue}>\n <div\n data-react-fancy-editor=\"\"\n data-mode=\"edit\"\n className={cn(\n \"flex flex-col overflow-hidden rounded-xl border border-[color:var(--fancy-border,var(--color-zinc-200))] bg-[color:var(--fancy-surface,var(--color-white))] dark:border-[color:var(--fancy-border-dark,var(--color-zinc-700))] dark:bg-[color:var(--fancy-surface-dark,var(--color-zinc-900))]\",\n className,\n )}\n >\n {children}\n </div>\n </EditorContext.Provider>\n );\n}\n\nconst ToolbarWithSeparator = Object.assign(EditorToolbar, {\n Separator: EditorToolbarSeparator,\n});\n\nexport const Editor = Object.assign(EditorRoot, {\n Toolbar: ToolbarWithSeparator,\n Content: EditorContent,\n SourceToggle: EditorSourceToggle,\n});\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Portal/Portal.tsx"],"names":[],"mappings":";;;;;AAQO,SAAS,MAAA,CAAO,EAAE,QAAA,EAAU,SAAA,EAAU,EAAgB;AAO3D,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAI,SAAS,KAAK,CAAA;AAC5C,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,UAAA,CAAW,IAAI,CAAA;AAAA,EACjB,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,IAAI,CAAC,OAAA,IAAW,OAAO,QAAA,KAAa,aAAa,OAAO,IAAA;AAExD,EAAA,MAAM,MAAA,GAAS,aAAa,QAAA,CAAS,IAAA;AAErC,EAAA,OAAO,YAAA;AAAA,oBACL,GAAA,CAAC,qBAAmB,QAAA,EAAS,CAAA;AAAA,IAC7B;AAAA,GACF;AACF;AAOA,SAAS,iBAAA,CAAkB,EAAE,QAAA,EAAS,EAA4B;AAChE,EAAA,MAAM,GAAA,GAAM,OAAuB,IAAI,CAAA;AAEvC,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,MAAM,OAAO,QAAA,CAAS,eAAA;AACtB,IAAA,MAAM,UAAU,GAAA,CAAI,OAAA;AACpB,IAAA,IAAI,CAAC,OAAA,EAAS;AAEd,IAAA,MAAM,OAAO,MAAM;AACjB,MAAA,MAAM,MAAA,GACJ,KAAK,SAAA,CAAU,QAAA,CAAS,MAAM,CAAA,IAC9B,IAAA,CAAK,YAAA,CAAa,YAAY,CAAA,KAAM,MAAA;AACtC,MAAA,OAAA,CAAQ,SAAA,CAAU,MAAA,CAAO,MAAA,EAAQ,MAAM,CAAA;AAAA,IACzC,CAAA;AAEA,IAAA,IAAA,EAAK;AAEL,IAAA,MAAM,QAAA,GAAW,IAAI,gBAAA,CAAiB,IAAI,CAAA;AAC1C,IAAA,QAAA,CAAS,QAAQ,IAAA,EAAM;AAAA,MACrB,UAAA,EAAY,IAAA;AAAA,MACZ,eAAA,EAAiB,CAAC,OAAA,EAAS,YAAY;AAAA,KACxC,CAAA;AAED,IAAA,OAAO,MAAM,SAAS,UAAA,EAAW;AAAA,EACnC,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,uBACE,GAAA,CAAC,KAAA,EAAA,EAAI,GAAA,EAAU,yBAAA,EAAwB,EAAA,EAAG,OAAO,EAAE,OAAA,EAAS,UAAA,EAAW,EACpE,QAAA,EACH,CAAA;AAEJ","file":"chunk-WHEXTDPV.js","sourcesContent":["import { createPortal } from \"react-dom\";\nimport { useEffect, useRef, useState, type ReactNode } from \"react\";\n\nexport interface PortalProps {\n children: ReactNode;\n container?: HTMLElement;\n}\n\nexport function Portal({ children, container }: PortalProps) {\n // Render nothing on the server AND on the client's first (hydration) render,\n // then portal after mount. Without the `mounted` gate the client would render\n // the portal immediately while the server rendered null — a hydration\n // mismatch (the portal wrapper appears client-only). Deferring to after mount\n // keeps the first client render identical to the server. SSR-safe for every\n // Portal consumer (Toast, Modal, Dropdown, Tooltip, Popover, …).\n const [mounted, setMounted] = useState(false);\n useEffect(() => {\n setMounted(true);\n }, []);\n\n if (!mounted || typeof document === \"undefined\") return null;\n\n const target = container ?? document.body;\n\n return createPortal(\n <PortalDarkWrapper>{children}</PortalDarkWrapper>,\n target,\n );\n}\n\n/**\n * Wrapper that propagates the `dark` class from <html> into the portal subtree.\n * This ensures Tailwind `dark:` utilities work even though Portal renders\n * outside the React component tree.\n */\nfunction PortalDarkWrapper({ children }: { children: ReactNode }) {\n const ref = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const root = document.documentElement;\n const wrapper = ref.current;\n if (!wrapper) return;\n\n const sync = () => {\n const isDark =\n root.classList.contains(\"dark\") ||\n root.getAttribute(\"data-theme\") === \"dark\";\n wrapper.classList.toggle(\"dark\", isDark);\n };\n\n sync();\n\n const observer = new MutationObserver(sync);\n observer.observe(root, {\n attributes: true,\n attributeFilter: [\"class\", \"data-theme\"],\n });\n\n return () => observer.disconnect();\n }, []);\n\n return (\n <div ref={ref} data-react-fancy-portal=\"\" style={{ display: \"contents\" }}>\n {children}\n </div>\n );\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Editor/Editor.context.ts","../src/components/Editor/EditorSourceToggle.tsx","../src/components/Editor/EditorToolbar.tsx","../src/components/Editor/EditorToolbarSeparator.tsx","../src/components/Editor/EditorContent.tsx","../src/components/Editor/Editor.tsx"],"names":["createContext","useContext","jsx","cn","jsxs","Fragment","useRef","useEffect","useMemo","extensionEditorClasses","CodeView","proseClasses","sanitizeHtml","detectFormat","markdownToEditorHtml","marked","useControllableState","useFieldMode","useState","mergeExtensions","useCallback","htmlToMarkdown","ContentRenderer"],"mappings":";;;;;;;;;;;;AA4BO,IAAM,aAAA,GAAgBA,oBAAyC,IAAI,CAAA;AAEnE,SAAS,SAAA,GAAgC;AAC9C,EAAA,MAAM,GAAA,GAAMC,iBAAW,aAAa,CAAA;AACpC,EAAA,IAAI,CAAC,GAA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O,MAAA,CAAO,aAAA,EAAe;AAAA,EACxD,SAAA,EAAW;AACb,CAAC,CAAA;AAEM,IAAM,MAAA,GAAS,MAAA,CAAO,MAAA,CAAO,UAAA,EAAY;AAAA,EAC9C,OAAA,EAAS,oBAAA;AAAA,EACT,OAAA,EAAS,aAAA;AAAA,EACT,YAAA,EAAc;AAChB,CAAC","file":"chunk-XAQQX7J2.cjs","sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { RefObject } from \"react\";\nimport type { RenderExtension } from \"../ContentRenderer/extensions\";\n\nexport interface EditorContextValue {\n contentRef: RefObject<HTMLDivElement | null>;\n exec: (command: string, arg?: string) => void;\n insertText: (text: string) => void;\n wrapSelection: (before: string, after: string) => void;\n outputFormat: \"html\" | \"markdown\";\n lineSpacing: number;\n placeholder?: string;\n /** Merged render extensions (global + instance). */\n extensions: RenderExtension[];\n /** Whether the raw-source view (textarea) is showing instead of the rich-text surface. */\n showSource: boolean;\n /** Toggle/set the raw-source view. */\n setShowSource: (showSource: boolean) => void;\n /** Initial HTML content to load into the editor on mount */\n _initialHtml: string;\n /** @internal Called by EditorContent on input events */\n _onInput: () => void;\n /** @internal Raw source value (`value` in `outputFormat`), for the source textarea. */\n _sourceValue: string;\n /** @internal Commit an edit made directly in the source textarea. */\n _onSourceInput: (value: string) => void;\n}\n\nexport const EditorContext = createContext<EditorContextValue | null>(null);\n\nexport function useEditor(): EditorContextValue {\n const ctx = useContext(EditorContext);\n if (!ctx) {\n throw new Error(\"useEditor must be used within an <Editor> component\");\n }\n return ctx;\n}\n","import { cn } from \"../../utils/cn\";\nimport { useEditor } from \"./Editor.context\";\nimport type { EditorSourceToggleProps } from \"./Editor.types\";\n\n/**\n * Toolbar button that reveals the raw HTML/Markdown behind the editor. Reads\n * `showSource` / `setShowSource` from context, so it works in the default\n * toolbar and in any custom toolbar composed with `useEditor()`.\n */\nexport function EditorSourceToggle({\n className,\n icon = \"</>\",\n title = \"Source\",\n activeTitle = \"Rich text\",\n}: EditorSourceToggleProps) {\n const { showSource, setShowSource } = useEditor();\n\n return (\n <button\n type=\"button\"\n onClick={() => setShowSource(!showSource)}\n title={showSource ? activeTitle : title}\n aria-pressed={showSource}\n data-react-fancy-editor-source-toggle=\"\"\n className={cn(\n \"inline-flex h-8 items-center justify-center rounded-md px-2 font-mono text-xs transition-colors\",\n showSource\n ? \"bg-[color:var(--fancy-border,var(--color-zinc-200))] dark:bg-[color:var(--fancy-border-dark,var(--color-zinc-700))]\"\n : \"hover:bg-[color:var(--fancy-surface-muted,var(--color-zinc-100))] dark:hover:bg-[color:var(--fancy-surface-muted-dark,var(--color-zinc-800))]\",\n className,\n )}\n >\n {icon}\n </button>\n );\n}\n\nEditorSourceToggle.displayName = \"EditorSourceToggle\";\n","import { cn } from \"../../utils/cn\";\nimport { useEditor } from \"./Editor.context\";\nimport { EditorSourceToggle } from \"./EditorSourceToggle\";\nimport type { EditorToolbarProps } from \"./Editor.types\";\n\nconst DEFAULT_ACTIONS = [\n { icon: \"B\", label: \"Bold\", command: \"bold\" },\n { icon: \"I\", label: \"Italic\", command: \"italic\" },\n { icon: \"U\", label: \"Underline\", command: \"underline\" },\n { icon: \"S\", label: \"Strikethrough\", command: \"strikeThrough\" },\n];\n\nexport function EditorToolbar({\n actions = DEFAULT_ACTIONS,\n onAction,\n children,\n className,\n showSourceToggle = true,\n}: EditorToolbarProps) {\n const { exec, showSource } = useEditor();\n\n return (\n <div\n data-react-fancy-editor-toolbar=\"\"\n className={cn(\n \"flex shrink-0 items-center gap-0.5 border-b border-[color:var(--fancy-border,var(--color-zinc-200))] px-2 py-1.5 dark:border-[color:var(--fancy-border-dark,var(--color-zinc-700))]\",\n className,\n )}\n >\n {children ?? (\n <>\n {actions.map((action) => (\n <button\n key={`${action.command}-${action.commandArg ?? \"\"}`}\n type=\"button\"\n // Rich-text commands don't apply to the raw-source textarea.\n disabled={showSource}\n onClick={() => {\n if (onAction) {\n onAction(action.command);\n } else {\n exec(action.command, action.commandArg);\n }\n }}\n title={action.label}\n className={cn(\n \"inline-flex h-8 w-8 items-center justify-center rounded-md text-sm transition-colors\",\n action.active\n ? \"bg-[color:var(--fancy-border,var(--color-zinc-200))] dark:bg-[color:var(--fancy-border-dark,var(--color-zinc-700))]\"\n : \"hover:bg-[color:var(--fancy-surface-muted,var(--color-zinc-100))] dark:hover:bg-[color:var(--fancy-surface-muted-dark,var(--color-zinc-800))]\",\n showSource && \"cursor-not-allowed opacity-40 hover:bg-transparent\",\n )}\n >\n {action.icon}\n </button>\n ))}\n {showSourceToggle && <EditorSourceToggle className=\"ml-auto\" />}\n </>\n )}\n </div>\n );\n}\n\nEditorToolbar.displayName = \"EditorToolbar\";\n","export function EditorToolbarSeparator() {\n return (\n <span\n data-react-fancy-editor-toolbar-separator=\"\"\n className=\"mx-1 h-5 w-px bg-[color:var(--fancy-border,var(--color-zinc-200))] dark:bg-[color:var(--fancy-border-dark,var(--color-zinc-700))]\"\n />\n );\n}\n\nEditorToolbarSeparator.displayName = \"EditorToolbarSeparator\";\n","import { useEffect, useMemo, useRef } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { CodeView } from \"../CodeView\";\nimport { useEditor } from \"./Editor.context\";\nimport { proseClasses, extensionEditorClasses } from \"./editor.utils\";\nimport type { EditorContentProps } from \"./Editor.types\";\n\nexport function EditorContent({ className, maxHeight, sourceClassName }: EditorContentProps) {\n const {\n contentRef,\n lineSpacing,\n placeholder,\n extensions,\n outputFormat,\n showSource,\n _initialHtml,\n _onInput,\n _sourceValue,\n _onSourceInput,\n } = useEditor();\n // Tracks which seed HTML is currently in the contentEditable. Seeding on the\n // seed VALUE (not a one-shot boolean) re-seeds when the source view rewrites\n // `value`, while still never re-seeding on plain keystrokes — typing leaves\n // `_initialHtml` untouched, so `seededHtml.current === _initialHtml` holds.\n const seededHtml = useRef<string | null>(null);\n\n useEffect(() => {\n // Source view replaces the contentEditable in the tree, so it unmounts.\n // Forget what we seeded — the div that returns is a fresh, empty one and\n // must always be re-seeded, even if `value` was left untouched.\n if (showSource) {\n seededHtml.current = null;\n return;\n }\n const el = contentRef.current;\n if (el && seededHtml.current !== _initialHtml) {\n el.innerHTML = _initialHtml;\n seededHtml.current = _initialHtml;\n }\n }, [contentRef, _initialHtml, showSource]);\n\n const extClasses = useMemo(\n () => extensionEditorClasses(extensions),\n [extensions],\n );\n\n if (showSource) {\n // Raw-source view — a syntax-highlighted code surface (HTML highlighted;\n // markdown/plain un-highlighted), built on the shared fancy-file-commons\n // primitives. It's a DIRECT child of the flex-column editor root (no\n // wrapper — a nested flex box collapses the fill), so `flex-auto` makes it\n // fill the editor body when height-constrained and grow with content\n // (≥ minHeight) when not. `maxHeight` caps + scrolls.\n return (\n <CodeView\n value={_sourceValue}\n onChange={_onSourceInput}\n language={outputFormat === \"html\" ? \"html\" : \"plaintext\"}\n placeholder={placeholder}\n maxHeight={maxHeight}\n className={cn(\"min-h-0 flex-auto\", sourceClassName)}\n />\n );\n }\n\n return (\n <div\n ref={contentRef}\n contentEditable\n suppressContentEditableWarning\n data-react-fancy-editor-content=\"\"\n data-placeholder={placeholder}\n onInput={_onInput}\n style={{\n lineHeight: lineSpacing,\n maxHeight: maxHeight ? `${maxHeight}px` : undefined,\n }}\n className={cn(\n \"min-h-[120px] flex-auto overflow-y-auto px-4 py-3 text-sm outline-none\",\n \"focus:outline-none\",\n proseClasses,\n extClasses,\n \"empty:before:content-[attr(data-placeholder)] empty:before:text-zinc-400 empty:before:pointer-events-none\",\n className,\n )}\n />\n );\n}\n\nEditorContent.displayName = \"EditorContent\";\n","import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { marked } from \"marked\";\nimport { cn } from \"../../utils/cn\";\nimport { sanitizeHtml } from \"../../utils/sanitize\";\nimport { useControllableState } from \"../../hooks\";\nimport { EditorContext } from \"./Editor.context\";\nimport { EditorToolbar } from \"./EditorToolbar\";\nimport { EditorToolbarSeparator } from \"./EditorToolbarSeparator\";\nimport { EditorSourceToggle } from \"./EditorSourceToggle\";\nimport { EditorContent } from \"./EditorContent\";\nimport { htmlToMarkdown, detectFormat, markdownToEditorHtml, type MarkdownSource } from \"./editor.utils\";\nimport { mergeExtensions } from \"../ContentRenderer/extensions\";\nimport { ContentRenderer } from \"../ContentRenderer/ContentRenderer\";\nimport { useFieldMode } from \"../inputs/mode/FieldMode.context\";\nimport type { EditorProps } from \"./Editor.types\";\n\ninterface Seed {\n html: string;\n /** Source map for source-preserving markdown output; null when there is none. */\n source: MarkdownSource | null;\n}\n\nfunction toHtml(\n value: string,\n outputFormat: \"html\" | \"markdown\",\n unsafe: boolean,\n valueFormat: \"markdown\" | \"html\" | \"auto\" = \"auto\",\n): Seed {\n if (!value) return { html: \"\", source: null };\n const sanitize = (html: string) => (unsafe ? html : sanitizeHtml(html));\n // An explicit valueFormat is authoritative — the sniff misclassifies\n // markdown that merely MENTIONS HTML-ish snippets (`<code>`, `<table`),\n // collapsing it into an innerHTML wall of text (#10).\n const format =\n valueFormat !== \"auto\"\n ? valueFormat\n : outputFormat === \"html\"\n ? \"html\"\n : detectFormat(value);\n if (format === \"html\") return { html: sanitize(value), source: null };\n // Markdown in, markdown out: tag each block with its source so untouched\n // blocks are emitted byte-identical.\n if (outputFormat === \"markdown\") return markdownToEditorHtml(value, sanitize);\n return { html: sanitize((marked.parse(value, { async: false }) as string).trim()), source: null };\n}\n\nfunction EditorRoot({\n children,\n className,\n value: controlledValue,\n defaultValue = \"\",\n onChange,\n outputFormat = \"html\",\n valueFormat = \"auto\",\n lineSpacing = 1.6,\n placeholder,\n mode: modeProp,\n extensions: instanceExtensions,\n unsafe = false,\n showSource: showSourceProp,\n defaultShowSource = false,\n onShowSourceChange,\n}: EditorProps) {\n const contentRef = useRef<HTMLDivElement | null>(null);\n const [value, setValue] = useControllableState(controlledValue, defaultValue, onChange);\n const [showSource, setShowSource] = useControllableState(\n showSourceProp,\n defaultShowSource,\n onShowSourceChange,\n );\n // View/edit mode — same resolution as the inputs: prop → <Form> context → \"edit\".\n const mode = useFieldMode(modeProp);\n const isView = mode === \"view\";\n\n // The value this editor last emitted through `onChange`. An incoming `value`\n // equal to it is our own keystroke echoing back; anything else came from\n // OUTSIDE — an async load, a host reset, a form repopulating.\n const lastEmitted = useRef<string | null>(null);\n\n // Bumped only on an external `value` change, so the seed memo below recomputes\n // for those and stays put while the user types. Without this, `value` was\n // excluded from the deps to avoid re-seeding on keystrokes, which also meant a\n // value arriving after mount was silently dropped and the editor stayed blank\n // forever (#15).\n const [externalSeed, setExternalSeed] = useState(0);\n useEffect(() => {\n if (value !== lastEmitted.current) setExternalSeed((n) => n + 1);\n }, [value]);\n\n const seed = useMemo(\n () => toHtml(value, outputFormat, unsafe, valueFormat),\n // Seed the contentEditable from the LIVE value when (re)entering edit mode —\n // and when returning from the raw-source view, which may have rewritten the\n // value out from under the rich-text surface. `value` itself stays out of\n // the deps so typing never re-seeds (which would fight the caret);\n // `externalSeed` covers the externally-driven case instead.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [isView, outputFormat, unsafe, valueFormat, showSource, externalSeed],\n );\n const initialHtml = seed.html;\n const seedSource = seed.source;\n\n const extensions = useMemo(\n () => mergeExtensions(instanceExtensions),\n [instanceExtensions],\n );\n\n const getOutputValue = useCallback(\n (html: string): string => {\n return outputFormat === \"markdown\" ? htmlToMarkdown(html, seedSource) : html;\n },\n [outputFormat, seedSource],\n );\n\n const handleInput = useCallback(() => {\n const el = contentRef.current;\n if (!el) return;\n const next = getOutputValue(el.innerHTML);\n // Record what we emitted BEFORE publishing it, so the value coming back in\n // is recognised as our own and does not trigger a re-seed mid-keystroke.\n lastEmitted.current = next;\n setValue(next);\n }, [setValue, getOutputValue]);\n\n const exec = useCallback(\n (command: string, arg?: string) => {\n const el = contentRef.current;\n if (!el) return;\n el.focus();\n document.execCommand(command, false, arg);\n handleInput();\n },\n [handleInput],\n );\n\n const insertText = useCallback(\n (text: string) => {\n const el = contentRef.current;\n if (!el) return;\n el.focus();\n document.execCommand(\"insertText\", false, text);\n handleInput();\n },\n [handleInput],\n );\n\n // The source textarea edits `value` directly — it is already the canonical\n // source in `outputFormat` (html or markdown), so no conversion round-trip.\n const handleSourceInput = useCallback(\n (next: string) => {\n // Also an internal emission — record it so typing in the source view is\n // not mistaken for an external change on every keystroke.\n lastEmitted.current = next;\n setValue(next);\n },\n [setValue],\n );\n\n const wrapSelection = useCallback(\n (before: string, after: string) => {\n const sel = window.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n const selectedText = range.toString();\n const el = contentRef.current;\n if (!el) return;\n el.focus();\n document.execCommand(\"insertText\", false, `${before}${selectedText}${after}`);\n handleInput();\n },\n [handleInput],\n );\n\n const contextValue = {\n contentRef,\n exec,\n insertText,\n wrapSelection,\n outputFormat,\n lineSpacing,\n placeholder,\n extensions,\n showSource,\n setShowSource,\n _initialHtml: initialHtml,\n _onInput: handleInput,\n _sourceValue: value,\n _onSourceInput: handleSourceInput,\n };\n\n // View mode — render the value read-only through ContentRenderer, matching the\n // editor's own format (markdown/html), instead of the editable toolbar+content\n // tree. Driven by `mode` / a `<Form mode=\"view\">`, exactly like the inputs.\n if (isView) {\n return (\n <div\n data-react-fancy-editor=\"\"\n data-mode=\"view\"\n className={cn(\n \"overflow-hidden rounded-xl border border-[color:var(--fancy-border,var(--color-zinc-200))] bg-[color:var(--fancy-surface,var(--color-white))] dark:border-[color:var(--fancy-border-dark,var(--color-zinc-700))] dark:bg-[color:var(--fancy-surface-dark,var(--color-zinc-900))]\",\n className,\n )}\n >\n <ContentRenderer\n value={value}\n format={valueFormat !== \"auto\" ? valueFormat : outputFormat}\n lineSpacing={lineSpacing}\n extensions={instanceExtensions}\n unsafe={unsafe}\n className=\"px-4 py-3\"\n />\n </div>\n );\n }\n\n return (\n <EditorContext.Provider value={contextValue}>\n <div\n data-react-fancy-editor=\"\"\n data-mode=\"edit\"\n className={cn(\n \"flex flex-col overflow-hidden rounded-xl border border-[color:var(--fancy-border,var(--color-zinc-200))] bg-[color:var(--fancy-surface,var(--color-white))] dark:border-[color:var(--fancy-border-dark,var(--color-zinc-700))] dark:bg-[color:var(--fancy-surface-dark,var(--color-zinc-900))]\",\n className,\n )}\n >\n {children}\n </div>\n </EditorContext.Provider>\n );\n}\n\nconst ToolbarWithSeparator = Object.assign(EditorToolbar, {\n Separator: EditorToolbarSeparator,\n});\n\nexport const Editor = Object.assign(EditorRoot, {\n Toolbar: ToolbarWithSeparator,\n Content: EditorContent,\n SourceToggle: EditorSourceToggle,\n});\n"]}
|