@particle-academy/react-fancy 5.60.2 → 5.61.1

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 (168) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/dist/autocomplete.cjs +4 -3
  3. package/dist/autocomplete.js +3 -2
  4. package/dist/{chunk-EEMNTO7L.cjs → chunk-3DMVK74Q.cjs} +4 -4
  5. package/dist/{chunk-EEMNTO7L.cjs.map → chunk-3DMVK74Q.cjs.map} +1 -1
  6. package/dist/{chunk-M77BB2QI.cjs → chunk-3I6PE2US.cjs} +12 -12
  7. package/dist/{chunk-M77BB2QI.cjs.map → chunk-3I6PE2US.cjs.map} +1 -1
  8. package/dist/{chunk-TGBLDJ72.js → chunk-4FJWHVC7.js} +3 -3
  9. package/dist/{chunk-TGBLDJ72.js.map → chunk-4FJWHVC7.js.map} +1 -1
  10. package/dist/{chunk-EXQ33MJR.cjs → chunk-4HUD33OP.cjs} +4 -4
  11. package/dist/{chunk-EXQ33MJR.cjs.map → chunk-4HUD33OP.cjs.map} +1 -1
  12. package/dist/chunk-4JLFIPHZ.js +43 -0
  13. package/dist/chunk-4JLFIPHZ.js.map +1 -0
  14. package/dist/{chunk-YQTKTEWS.js → chunk-5JFA7NYE.js} +3 -3
  15. package/dist/{chunk-YQTKTEWS.js.map → chunk-5JFA7NYE.js.map} +1 -1
  16. package/dist/chunk-5VMILVWD.js +3 -0
  17. package/dist/chunk-5VMILVWD.js.map +1 -0
  18. package/dist/chunk-645CRPU6.cjs +53 -0
  19. package/dist/chunk-645CRPU6.cjs.map +1 -0
  20. package/dist/{chunk-DN244T6G.cjs → chunk-6GBO7R25.cjs} +4 -4
  21. package/dist/{chunk-DN244T6G.cjs.map → chunk-6GBO7R25.cjs.map} +1 -1
  22. package/dist/{chunk-4FZOH7BJ.js → chunk-74MEJWMH.js} +3 -3
  23. package/dist/{chunk-4FZOH7BJ.js.map → chunk-74MEJWMH.js.map} +1 -1
  24. package/dist/{chunk-4DGXL6JC.cjs → chunk-7KTBVKNO.cjs} +4 -4
  25. package/dist/{chunk-4DGXL6JC.cjs.map → chunk-7KTBVKNO.cjs.map} +1 -1
  26. package/dist/{chunk-XQDGUXMS.js → chunk-BHUSI56C.js} +3 -3
  27. package/dist/{chunk-XQDGUXMS.js.map → chunk-BHUSI56C.js.map} +1 -1
  28. package/dist/{chunk-VD3C7IA4.js → chunk-BLS2IGPY.js} +48 -13
  29. package/dist/chunk-BLS2IGPY.js.map +1 -0
  30. package/dist/{chunk-XAQQX7J2.cjs → chunk-BMVYOVSW.cjs} +48 -13
  31. package/dist/chunk-BMVYOVSW.cjs.map +1 -0
  32. package/dist/{chunk-UIE5FP3A.js → chunk-BQFPC5FL.js} +3 -3
  33. package/dist/{chunk-UIE5FP3A.js.map → chunk-BQFPC5FL.js.map} +1 -1
  34. package/dist/chunk-CHQH6M67.js +297 -0
  35. package/dist/chunk-CHQH6M67.js.map +1 -0
  36. package/dist/{chunk-UZG6LO4Z.cjs → chunk-FU6K7XXZ.cjs} +4 -4
  37. package/dist/{chunk-UZG6LO4Z.cjs.map → chunk-FU6K7XXZ.cjs.map} +1 -1
  38. package/dist/{chunk-5ZNOLPIJ.cjs → chunk-H2YRZYKK.cjs} +5 -5
  39. package/dist/{chunk-5ZNOLPIJ.cjs.map → chunk-H2YRZYKK.cjs.map} +1 -1
  40. package/dist/{chunk-7R7HENZG.cjs → chunk-HRYM76ZE.cjs} +9 -9
  41. package/dist/{chunk-7R7HENZG.cjs.map → chunk-HRYM76ZE.cjs.map} +1 -1
  42. package/dist/{chunk-ZGQEKDG6.js → chunk-IHQHTJNN.js} +5 -5
  43. package/dist/{chunk-ZGQEKDG6.js.map → chunk-IHQHTJNN.js.map} +1 -1
  44. package/dist/{chunk-6HJF55U7.js → chunk-IY6LVALS.js} +3 -3
  45. package/dist/{chunk-6HJF55U7.js.map → chunk-IY6LVALS.js.map} +1 -1
  46. package/dist/{chunk-HTNQ5XUR.cjs → chunk-J4FKJ4IR.cjs} +4 -4
  47. package/dist/{chunk-HTNQ5XUR.cjs.map → chunk-J4FKJ4IR.cjs.map} +1 -1
  48. package/dist/{chunk-43ZRUYJC.cjs → chunk-JOWAS5A5.cjs} +9 -9
  49. package/dist/{chunk-43ZRUYJC.cjs.map → chunk-JOWAS5A5.cjs.map} +1 -1
  50. package/dist/{chunk-JRRYYW3Y.cjs → chunk-K6NADZ7O.cjs} +6 -6
  51. package/dist/{chunk-JRRYYW3Y.cjs.map → chunk-K6NADZ7O.cjs.map} +1 -1
  52. package/dist/{chunk-5JA4ENMF.js → chunk-LMOPAY7Q.js} +3 -3
  53. package/dist/{chunk-5JA4ENMF.js.map → chunk-LMOPAY7Q.js.map} +1 -1
  54. package/dist/{chunk-DAJPPKPO.js → chunk-M52S3TFI.js} +3 -3
  55. package/dist/{chunk-DAJPPKPO.js.map → chunk-M52S3TFI.js.map} +1 -1
  56. package/dist/{chunk-GLGUQGAQ.cjs → chunk-M6MGQI6G.cjs} +4 -4
  57. package/dist/{chunk-GLGUQGAQ.cjs.map → chunk-M6MGQI6G.cjs.map} +1 -1
  58. package/dist/chunk-MKHYENKR.cjs +4 -0
  59. package/dist/chunk-MKHYENKR.cjs.map +1 -0
  60. package/dist/{chunk-NHGU2BWT.js → chunk-MSGKIWYX.js} +3 -3
  61. package/dist/{chunk-NHGU2BWT.js.map → chunk-MSGKIWYX.js.map} +1 -1
  62. package/dist/{chunk-KQYOIPHQ.js → chunk-N7KUGFRG.js} +4 -4
  63. package/dist/{chunk-KQYOIPHQ.js.map → chunk-N7KUGFRG.js.map} +1 -1
  64. package/dist/{chunk-XB3H2EEL.js → chunk-NDLESFUH.js} +3 -3
  65. package/dist/{chunk-XB3H2EEL.js.map → chunk-NDLESFUH.js.map} +1 -1
  66. package/dist/chunk-NFTTNFQR.js +51 -0
  67. package/dist/chunk-NFTTNFQR.js.map +1 -0
  68. package/dist/{chunk-XYOT75HH.js → chunk-NORVXHRU.js} +3 -3
  69. package/dist/{chunk-XYOT75HH.js.map → chunk-NORVXHRU.js.map} +1 -1
  70. package/dist/{chunk-5H6IUCOD.cjs → chunk-P6V4QWJK.cjs} +4 -4
  71. package/dist/{chunk-5H6IUCOD.cjs.map → chunk-P6V4QWJK.cjs.map} +1 -1
  72. package/dist/{chunk-LZHGXRFD.js → chunk-PKFEJWVI.js} +3 -3
  73. package/dist/{chunk-LZHGXRFD.js.map → chunk-PKFEJWVI.js.map} +1 -1
  74. package/dist/{chunk-BJKKW77L.cjs → chunk-QXMQVLRQ.cjs} +4 -4
  75. package/dist/{chunk-BJKKW77L.cjs.map → chunk-QXMQVLRQ.cjs.map} +1 -1
  76. package/dist/{chunk-WHEXTDPV.js → chunk-RBCMKPBX.js} +7 -5
  77. package/dist/chunk-RBCMKPBX.js.map +1 -0
  78. package/dist/{chunk-LVE6ERRS.cjs → chunk-RRMQGTVB.cjs} +6 -6
  79. package/dist/{chunk-LVE6ERRS.cjs.map → chunk-RRMQGTVB.cjs.map} +1 -1
  80. package/dist/{chunk-T67FLC55.js → chunk-SHF44YGG.js} +3 -3
  81. package/dist/{chunk-T67FLC55.js.map → chunk-SHF44YGG.js.map} +1 -1
  82. package/dist/{chunk-NBZC6LOB.cjs → chunk-TI7D4QDM.cjs} +6 -3
  83. package/dist/chunk-TI7D4QDM.cjs.map +1 -0
  84. package/dist/{chunk-5JK2VDWY.cjs → chunk-TYTENEJQ.cjs} +6 -6
  85. package/dist/{chunk-5JK2VDWY.cjs.map → chunk-TYTENEJQ.cjs.map} +1 -1
  86. package/dist/{chunk-WW56U3RV.js → chunk-UBEOB55O.js} +3 -3
  87. package/dist/{chunk-WW56U3RV.js.map → chunk-UBEOB55O.js.map} +1 -1
  88. package/dist/{chunk-M6XBF2ZS.js → chunk-UJZJBHMH.js} +3 -3
  89. package/dist/{chunk-M6XBF2ZS.js.map → chunk-UJZJBHMH.js.map} +1 -1
  90. package/dist/{chunk-T45LBTXH.js → chunk-ULG4OA2T.js} +3 -3
  91. package/dist/{chunk-T45LBTXH.js.map → chunk-ULG4OA2T.js.map} +1 -1
  92. package/dist/{chunk-SIEPD6NR.cjs → chunk-UM4JXBRZ.cjs} +4 -4
  93. package/dist/{chunk-SIEPD6NR.cjs.map → chunk-UM4JXBRZ.cjs.map} +1 -1
  94. package/dist/chunk-X6TGRSVH.cjs +299 -0
  95. package/dist/chunk-X6TGRSVH.cjs.map +1 -0
  96. package/dist/{chunk-FGI2EC32.cjs → chunk-Z5OTOYWI.cjs} +4 -4
  97. package/dist/{chunk-FGI2EC32.cjs.map → chunk-Z5OTOYWI.cjs.map} +1 -1
  98. package/dist/chunk-ZPBCZPMD.cjs +48 -0
  99. package/dist/chunk-ZPBCZPMD.cjs.map +1 -0
  100. package/dist/command.cjs +5 -4
  101. package/dist/command.js +3 -2
  102. package/dist/composer.cjs +7 -6
  103. package/dist/composer.js +5 -4
  104. package/dist/context-menu.cjs +5 -4
  105. package/dist/context-menu.js +3 -2
  106. package/dist/drawer.cjs +5 -4
  107. package/dist/drawer.js +3 -2
  108. package/dist/dropdown.cjs +5 -4
  109. package/dist/dropdown.js +3 -2
  110. package/dist/editor.cjs +8 -3
  111. package/dist/editor.d.cts +53 -4
  112. package/dist/editor.d.ts +53 -4
  113. package/dist/editor.js +6 -1
  114. package/dist/full-screen.cjs +39 -0
  115. package/dist/full-screen.cjs.map +1 -0
  116. package/dist/full-screen.d.cts +54 -0
  117. package/dist/full-screen.d.ts +54 -0
  118. package/dist/full-screen.js +10 -0
  119. package/dist/full-screen.js.map +1 -0
  120. package/dist/index.cjs +152 -120
  121. package/dist/index.cjs.map +1 -1
  122. package/dist/index.d.cts +4 -2
  123. package/dist/index.d.ts +4 -2
  124. package/dist/index.js +35 -31
  125. package/dist/index.js.map +1 -1
  126. package/dist/input.cjs +6 -5
  127. package/dist/input.js +5 -4
  128. package/dist/inputs.cjs +17 -16
  129. package/dist/inputs.js +9 -8
  130. package/dist/json-editor.cjs +19 -18
  131. package/dist/json-editor.js +8 -7
  132. package/dist/magic-wand.cjs +4 -3
  133. package/dist/magic-wand.js +3 -2
  134. package/dist/mobile-menu.cjs +6 -4
  135. package/dist/mobile-menu.js +4 -2
  136. package/dist/modal.cjs +5 -4
  137. package/dist/modal.js +3 -2
  138. package/dist/paste-pills.cjs +17 -16
  139. package/dist/paste-pills.js +4 -3
  140. package/dist/popover.cjs +5 -4
  141. package/dist/popover.js +3 -2
  142. package/dist/portal.cjs +7 -2
  143. package/dist/portal.d.cts +12 -1
  144. package/dist/portal.d.ts +12 -1
  145. package/dist/portal.js +2 -1
  146. package/dist/prompt-input.cjs +7 -6
  147. package/dist/prompt-input.js +6 -5
  148. package/dist/reason-tag.cjs +5 -4
  149. package/dist/reason-tag.js +4 -3
  150. package/dist/select.cjs +4 -3
  151. package/dist/select.js +3 -2
  152. package/dist/sidebar.cjs +1 -0
  153. package/dist/sidebar.js +1 -0
  154. package/dist/styles.css +9 -0
  155. package/dist/styles.css.map +1 -1
  156. package/dist/toast.cjs +5 -4
  157. package/dist/toast.js +3 -2
  158. package/dist/tooltip.cjs +4 -3
  159. package/dist/tooltip.js +3 -2
  160. package/dist/use-full-screen-BUJ1ujG4.d.cts +94 -0
  161. package/dist/use-full-screen-BUJ1ujG4.d.ts +94 -0
  162. package/docs/Editor.md +24 -0
  163. package/docs/FullScreen.md +106 -0
  164. package/package.json +11 -1
  165. package/dist/chunk-NBZC6LOB.cjs.map +0 -1
  166. package/dist/chunk-VD3C7IA4.js.map +0 -1
  167. package/dist/chunk-WHEXTDPV.js.map +0 -1
  168. package/dist/chunk-XAQQX7J2.cjs.map +0 -1
@@ -0,0 +1,94 @@
1
+ import { RefObject, CSSProperties, KeyboardEvent } from 'react';
2
+
3
+ /**
4
+ * How a surface goes full screen.
5
+ *
6
+ * - `"overlay"` (default): the element itself becomes `position: fixed` over the
7
+ * viewport, in place. It always works: inside an iframe without
8
+ * `allow="fullscreen"`, inside a dialog, without a user gesture. Nothing is
9
+ * reparented, so an editor keeps its caret, undo stack and DOM.
10
+ * - `"native"`: the browser Fullscreen API (`element.requestFullscreen()`),
11
+ * which hides the browser chrome too. The overlay is applied first and stays
12
+ * if the request is rejected or the API is missing, so the user gets full
13
+ * screen either way; `activeMode` reports which one took.
14
+ */
15
+ type FullScreenMode = "overlay" | "native";
16
+ interface UseFullScreenOptions {
17
+ /** Controlled flag. Pair with `onFullScreenChange`. */
18
+ fullScreen?: boolean;
19
+ /** Initial flag when uncontrolled. @default false */
20
+ defaultFullScreen?: boolean;
21
+ /**
22
+ * Fired with the requested state — from the toggle, Escape, an agent calling
23
+ * `setFullScreen`, or the user leaving the browser's own full screen.
24
+ */
25
+ onFullScreenChange?: (fullScreen: boolean) => void;
26
+ /** @default "overlay" */
27
+ mode?: FullScreenMode;
28
+ /** Leave full screen on Escape. @default true */
29
+ closeOnEscape?: boolean;
30
+ /** Stop the page behind from scrolling while active. @default true */
31
+ lockScroll?: boolean;
32
+ /** Stacking order of the overlay. Matches `Modal`. @default 50 */
33
+ zIndex?: number;
34
+ /** Accessible names for the toggle. */
35
+ labels?: {
36
+ enter?: string;
37
+ exit?: string;
38
+ };
39
+ }
40
+ interface FullScreenTargetProps<T extends HTMLElement> {
41
+ ref: RefObject<T | null>;
42
+ "data-fullscreen": "true" | "false";
43
+ "data-fullscreen-mode"?: FullScreenMode;
44
+ "data-fullscreen-layer"?: FullScreenLayer;
45
+ style?: CSSProperties;
46
+ onKeyDown: (event: KeyboardEvent<T>) => void;
47
+ }
48
+ interface FullScreenToggleProps {
49
+ type: "button";
50
+ onClick: () => void;
51
+ "aria-pressed": boolean;
52
+ "aria-label": string;
53
+ title: string;
54
+ "data-react-fancy-fullscreen-toggle": "";
55
+ "data-fullscreen": "true" | "false";
56
+ }
57
+ interface UseFullScreenResult<T extends HTMLElement = HTMLElement> {
58
+ fullScreen: boolean;
59
+ setFullScreen: (fullScreen: boolean) => void;
60
+ toggle: () => void;
61
+ /** The mechanism in effect while active; `null` when not full screen. */
62
+ activeMode: FullScreenMode | null;
63
+ /**
64
+ * `"top"` while the surface is in the browser's top layer (a manual popover,
65
+ * or the native full screen), `"fixed"` while it relies on `position: fixed`
66
+ * (no popover API, or the browser refused). `null` when not full screen.
67
+ */
68
+ layer: FullScreenLayer | null;
69
+ /** Attach to the element that goes full screen. Also inside `targetProps`. */
70
+ ref: RefObject<T | null>;
71
+ /**
72
+ * Spread onto the surface's root. Carries the ref, the `data-fullscreen`
73
+ * handle, the overlay style and the Escape/Tab handler. Merge your own
74
+ * `style` / `onKeyDown` if the root has them.
75
+ */
76
+ targetProps: FullScreenTargetProps<T>;
77
+ /** Spread onto a `<button>` to make it the toggle. */
78
+ toggleProps: FullScreenToggleProps;
79
+ /**
80
+ * The element to portal into while active, else `null`. Provide it through
81
+ * `PortalContainerContext` so menus opened inside stay visible.
82
+ */
83
+ portalContainer: HTMLElement | null;
84
+ }
85
+ /** Which mechanism keeps the surface over the page. */
86
+ type FullScreenLayer = "top" | "fixed";
87
+ /**
88
+ * A controlled full-screen state for any surface: Editor today, DeckEditor and
89
+ * SheetWorkbook next. Render-time output is pure (no `window`/`document`), so it
90
+ * server-renders; everything that touches the DOM runs in effects.
91
+ */
92
+ declare function useFullScreen<T extends HTMLElement = HTMLElement>(options?: UseFullScreenOptions): UseFullScreenResult<T>;
93
+
94
+ export { type FullScreenLayer as F, type UseFullScreenOptions as U, type FullScreenMode as a, type FullScreenTargetProps as b, type FullScreenToggleProps as c, type UseFullScreenResult as d, useFullScreen as u };
@@ -0,0 +1,94 @@
1
+ import { RefObject, CSSProperties, KeyboardEvent } from 'react';
2
+
3
+ /**
4
+ * How a surface goes full screen.
5
+ *
6
+ * - `"overlay"` (default): the element itself becomes `position: fixed` over the
7
+ * viewport, in place. It always works: inside an iframe without
8
+ * `allow="fullscreen"`, inside a dialog, without a user gesture. Nothing is
9
+ * reparented, so an editor keeps its caret, undo stack and DOM.
10
+ * - `"native"`: the browser Fullscreen API (`element.requestFullscreen()`),
11
+ * which hides the browser chrome too. The overlay is applied first and stays
12
+ * if the request is rejected or the API is missing, so the user gets full
13
+ * screen either way; `activeMode` reports which one took.
14
+ */
15
+ type FullScreenMode = "overlay" | "native";
16
+ interface UseFullScreenOptions {
17
+ /** Controlled flag. Pair with `onFullScreenChange`. */
18
+ fullScreen?: boolean;
19
+ /** Initial flag when uncontrolled. @default false */
20
+ defaultFullScreen?: boolean;
21
+ /**
22
+ * Fired with the requested state — from the toggle, Escape, an agent calling
23
+ * `setFullScreen`, or the user leaving the browser's own full screen.
24
+ */
25
+ onFullScreenChange?: (fullScreen: boolean) => void;
26
+ /** @default "overlay" */
27
+ mode?: FullScreenMode;
28
+ /** Leave full screen on Escape. @default true */
29
+ closeOnEscape?: boolean;
30
+ /** Stop the page behind from scrolling while active. @default true */
31
+ lockScroll?: boolean;
32
+ /** Stacking order of the overlay. Matches `Modal`. @default 50 */
33
+ zIndex?: number;
34
+ /** Accessible names for the toggle. */
35
+ labels?: {
36
+ enter?: string;
37
+ exit?: string;
38
+ };
39
+ }
40
+ interface FullScreenTargetProps<T extends HTMLElement> {
41
+ ref: RefObject<T | null>;
42
+ "data-fullscreen": "true" | "false";
43
+ "data-fullscreen-mode"?: FullScreenMode;
44
+ "data-fullscreen-layer"?: FullScreenLayer;
45
+ style?: CSSProperties;
46
+ onKeyDown: (event: KeyboardEvent<T>) => void;
47
+ }
48
+ interface FullScreenToggleProps {
49
+ type: "button";
50
+ onClick: () => void;
51
+ "aria-pressed": boolean;
52
+ "aria-label": string;
53
+ title: string;
54
+ "data-react-fancy-fullscreen-toggle": "";
55
+ "data-fullscreen": "true" | "false";
56
+ }
57
+ interface UseFullScreenResult<T extends HTMLElement = HTMLElement> {
58
+ fullScreen: boolean;
59
+ setFullScreen: (fullScreen: boolean) => void;
60
+ toggle: () => void;
61
+ /** The mechanism in effect while active; `null` when not full screen. */
62
+ activeMode: FullScreenMode | null;
63
+ /**
64
+ * `"top"` while the surface is in the browser's top layer (a manual popover,
65
+ * or the native full screen), `"fixed"` while it relies on `position: fixed`
66
+ * (no popover API, or the browser refused). `null` when not full screen.
67
+ */
68
+ layer: FullScreenLayer | null;
69
+ /** Attach to the element that goes full screen. Also inside `targetProps`. */
70
+ ref: RefObject<T | null>;
71
+ /**
72
+ * Spread onto the surface's root. Carries the ref, the `data-fullscreen`
73
+ * handle, the overlay style and the Escape/Tab handler. Merge your own
74
+ * `style` / `onKeyDown` if the root has them.
75
+ */
76
+ targetProps: FullScreenTargetProps<T>;
77
+ /** Spread onto a `<button>` to make it the toggle. */
78
+ toggleProps: FullScreenToggleProps;
79
+ /**
80
+ * The element to portal into while active, else `null`. Provide it through
81
+ * `PortalContainerContext` so menus opened inside stay visible.
82
+ */
83
+ portalContainer: HTMLElement | null;
84
+ }
85
+ /** Which mechanism keeps the surface over the page. */
86
+ type FullScreenLayer = "top" | "fixed";
87
+ /**
88
+ * A controlled full-screen state for any surface: Editor today, DeckEditor and
89
+ * SheetWorkbook next. Render-time output is pure (no `window`/`document`), so it
90
+ * server-renders; everything that touches the DOM runs in effects.
91
+ */
92
+ declare function useFullScreen<T extends HTMLElement = HTMLElement>(options?: UseFullScreenOptions): UseFullScreenResult<T>;
93
+
94
+ export { type FullScreenLayer as F, type UseFullScreenOptions as U, type FullScreenMode as a, type FullScreenTargetProps as b, type FullScreenToggleProps as c, type UseFullScreenResult as d, useFullScreen as u };
package/docs/Editor.md CHANGED
@@ -33,6 +33,10 @@ import { Editor } from "@particle-academy/react-fancy";
33
33
  | showSource | `boolean` | - | Controlled source-view flag. When `true`, the content area shows the raw `value` (in `outputFormat`) in an editable `<textarea>` |
34
34
  | defaultShowSource | `boolean` | `false` | Initial source-view flag when uncontrolled |
35
35
  | onShowSourceChange | `(showSource: boolean) => void` | - | Fired when the Source toggle (or an agent) flips source view on/off |
36
+ | fullScreen | `boolean` | - | Controlled full-screen flag. While `true` the editor covers the viewport, the toolbar stays on top and the content fills the rest |
37
+ | defaultFullScreen | `boolean` | `false` | Initial full-screen flag when uncontrolled |
38
+ | onFullScreenChange | `(fullScreen: boolean) => void` | - | Fired by the toggle, Escape, an agent, or the user leaving the browser's full screen |
39
+ | fullScreenMode | `"overlay" \| "native"` | `"overlay"` | `overlay` covers the viewport in place and always works; `native` uses the browser Fullscreen API and falls back to the overlay. See [FullScreen](./FullScreen.md) |
36
40
  | className | `string` | - | Additional CSS classes |
37
41
 
38
42
  ### Editor.Toolbar
@@ -43,6 +47,7 @@ import { Editor } from "@particle-academy/react-fancy";
43
47
  | onAction | `(command: string) => void` | - | Custom action handler |
44
48
  | children | `ReactNode` | - | Custom toolbar content |
45
49
  | showSourceToggle | `boolean` | `true` | Append a Source toggle to the default toolbar. Ignored when `children` are supplied — custom toolbars compose their own `<Editor.SourceToggle />` |
50
+ | showFullScreenToggle | `boolean` | `false` | Append a full-screen toggle (Lucide `maximize-2` / `minimize-2`) at the right end of the default toolbar. Ignored when `children` are supplied — use `<Editor.FullScreenToggle />` |
46
51
  | className | `string` | - | Additional CSS classes |
47
52
 
48
53
  #### EditorAction
@@ -70,6 +75,25 @@ A toolbar button that reveals the raw HTML/Markdown behind the editor. It is app
70
75
  | activeTitle | `string` | `"Rich text"` | Accessible title in source mode (click → rich text) |
71
76
  | className | `string` | - | Additional CSS classes |
72
77
 
78
+ ### Editor.FullScreenToggle
79
+
80
+ Toolbar button that takes the editor full screen and back. Carries `data-react-fancy-editor-fullscreen-toggle` and the shared `data-react-fancy-fullscreen-toggle`, `aria-pressed` and an `aria-label` of "Enter full screen" / "Exit full screen".
81
+
82
+ | Prop | Type | Default | Description |
83
+ |------|------|---------|-------------|
84
+ | enterIcon | `string` | `"maximize-2"` | Lucide name shown while not full screen |
85
+ | exitIcon | `string` | `"minimize-2"` | Lucide name shown while full screen |
86
+ | className | `string` | - | Additional CSS classes |
87
+
88
+ ```tsx
89
+ <Editor defaultValue={doc} onFullScreenChange={(on) => console.log(on)}>
90
+ <Editor.Toolbar showFullScreenToggle />
91
+ <Editor.Content maxHeight={240} />
92
+ </Editor>
93
+ ```
94
+
95
+ While full screen the root has `data-fullscreen="true"`, `maxHeight` is ignored so the content fills the screen, and Escape leaves. The editor is not remounted, so the caret, undo history and text survive the round trip.
96
+
73
97
  ### Editor.Content
74
98
 
75
99
  | Prop | Type | Default | Description |
@@ -0,0 +1,106 @@
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 covers the viewport in place: `position: fixed` plus, where the browser has the popover API, promotion into the **top layer** with `popover="manual"` | Never refused. Without the popover API it stays `position: fixed` (z-index 50, as `Modal`) and an ancestor with `transform`, `filter`, `perspective` or `contain: paint` confines it to that ancestor |
49
+ | `"native"` | `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 drops to the overlay, top layer included. `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
+ **Why the top layer.** `position: fixed` is fixed to the viewport only while no ancestor has a transform, filter, perspective or paint containment. With one, the overlay is fixed to that ancestor instead. A Tabs panel whose fade-in animation holds its end keyframe (`animation-fill-mode: both`) traps it this way, and so does a dialog centred with `transform`. A top-layer element's containing block is the viewport whatever its ancestors do. `data-fullscreen-layer` reports `"top"` (popover, or the native full screen) or `"fixed"` (no popover API, or the browser refused).
54
+
55
+ What the top layer changes:
56
+
57
+ - **Light dismiss does not apply.** The popover is `manual`, so outside clicks do not close it, and Escape goes through the surface's own handling.
58
+ - **The UA popover box is reset.** `styles.css` puts padding, border, background, text colour and overflow back to a plain box, in a zero-specificity rule in the `base` layer, so your own classes still win. Geometry is set inline. Without `styles.css` the UA popover padding, border and `Canvas` colours show.
59
+ - **Portals opened from inside stay visible**, because they are redirected into the surface. Overlays rendered from OUTSIDE the surface while it is active, such as an app-level toast, sit under it, like anything else in the page.
60
+ - **Native mode requests the browser's full screen before any popover.** Chromium refuses `requestFullscreen()` on an element that is already an open popover, so the popover is only used if that request fails.
61
+ - If something else closes the popover, the surface drops back to `position: fixed` rather than disappearing.
62
+
63
+ 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.
64
+
65
+ ## Behaviour
66
+
67
+ - **Controlled:** `fullScreen` + `onFullScreenChange`, or `defaultFullScreen` uncontrolled. `onFullScreenChange` only fires on real transitions.
68
+ - **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.
69
+ - **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.
70
+ - **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.
71
+ - **SSR:** nothing touches `window` or `document` during render. A surface that starts full screen renders the overlay on the server.
72
+
73
+ ## Props / options
74
+
75
+ | Prop | Type | Default | Description |
76
+ |------|------|---------|-------------|
77
+ | fullScreen | `boolean` | - | Controlled flag |
78
+ | defaultFullScreen | `boolean` | `false` | Initial flag when uncontrolled |
79
+ | onFullScreenChange | `(fullScreen: boolean) => void` | - | Requested state, from the toggle, Escape, `setFullScreen` or the browser |
80
+ | mode | `"overlay" \| "native"` | `"overlay"` | See above |
81
+ | closeOnEscape | `boolean` | `true` | Leave on Escape |
82
+ | lockScroll | `boolean` | `true` | Lock body scroll while active |
83
+ | zIndex | `number` | `50` | Stacking order of the overlay |
84
+ | labels | `{ enter?: string; exit?: string }` | "Enter full screen" / "Exit full screen" | Toggle accessible names |
85
+
86
+ `useFullScreen()` returns `{ fullScreen, setFullScreen, toggle, activeMode, layer, ref, targetProps, toggleProps, portalContainer }`.
87
+
88
+ ### FullScreen.Toggle
89
+
90
+ | Prop | Type | Default | Description |
91
+ |------|------|---------|-------------|
92
+ | enterIcon | `string` | `"maximize-2"` | Lucide name shown while not full screen |
93
+ | exitIcon | `string` | `"minimize-2"` | Lucide name shown while full screen |
94
+ | children | `ReactNode \| (fullScreen) => ReactNode` | - | Replace the icon |
95
+
96
+ Renders nothing outside a `FullScreen` / `FullScreenProvider`.
97
+
98
+ ## Data attributes
99
+
100
+ | Selector | Meaning |
101
+ |---|---|
102
+ | `[data-react-fancy-fullscreen]` | `<FullScreen>` root |
103
+ | `[data-fullscreen="true"]` | Any surface while full screen (also on the toggle) |
104
+ | `[data-fullscreen-mode="overlay" \| "native"]` | Which mechanism is active |
105
+ | `[data-fullscreen-layer="top" \| "fixed"]` | Whether the surface is in the top layer or relies on `position: fixed` |
106
+ | `[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.60.2",
3
+ "version": "5.61.1",
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,QAAA,EAAU,SAAA,EAAU,EAAgB;AAO3D,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAIA,eAAS,KAAK,CAAA;AAC5C,EAAAC,eAAA,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,OAAOC,qBAAA;AAAA,oBACLC,cAAA,CAAC,qBAAmB,QAAA,EAAS,CAAA;AAAA,IAC7B;AAAA,GACF;AACF;AAOA,SAAS,iBAAA,CAAkB,EAAE,QAAA,EAAS,EAA4B;AAChE,EAAA,MAAM,GAAA,GAAMC,aAAuB,IAAI,CAAA;AAEvC,EAAAH,eAAA,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,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;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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,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,uBACEC,cAAA;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,GAA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EAAwB,EAAA;AAAA,QACxB,WAAA,EAAU,MAAA;AAAA,QACV,SAAA,EAAWC,oBAAA;AAAA,UACT,kRAAA;AAAA,UACA;AAAA,SACF;AAAA,QAEA,QAAA,kBAAAD,cAAAA;AAAA,UAACoB,iCAAA;AAAA,UAAA;AAAA,YACC,KAAA;AAAA,YACA,MAAA,EAAQ,WAAA,KAAgB,MAAA,GAAS,WAAA,GAAc,YAAA;AAAA,YAC/C,WAAA;AAAA,YACA,UAAA,EAAY,kBAAA;AAAA,YACZ,MAAA;AAAA,YACA,SAAA,EAAU;AAAA;AAAA;AACZ;AAAA,KACF;AAAA,EAEJ;AAEA,EAAA,uBACEpB,cAAAA,CAAC,aAAA,CAAc,UAAd,EAAuB,KAAA,EAAO,cAC7B,QAAA,kBAAAA,cAAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,yBAAA,EAAwB,EAAA;AAAA,MACxB,WAAA,EAAU,MAAA;AAAA,MACV,SAAA,EAAWC,oBAAA;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-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"]}