@folijs/react 0.5.0 → 0.6.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/src/editor.tsx CHANGED
@@ -89,6 +89,17 @@ export function useEditorOrContext(editor: Editor | undefined, caller: string):
89
89
  return found;
90
90
  }
91
91
 
92
+ /** The editor commands go to: the story open on its page, if any, else `editor`. */
93
+ export function useActiveEditor(editor: Editor): Editor {
94
+ const subscribe = useCallback((notify: () => void) => editor.subscribe(notify), [editor]);
95
+ const id = useSyncExternalStore(
96
+ subscribe,
97
+ () => editor.storyView?.open?.id ?? null,
98
+ () => null,
99
+ );
100
+ return (id && editor.story(id)) || editor;
101
+ }
102
+
92
103
  export interface UseEditorStateOptions<T> {
93
104
  /** Default: the context's editor. */
94
105
  editor?: Editor | undefined;
package/src/index.ts CHANGED
@@ -14,4 +14,5 @@ export {
14
14
  type FoliEditorHandle,
15
15
  type FoliEditorProps,
16
16
  } from "./FoliEditor.js";
17
+ export { FoliNavigation, type FoliNavigationProps } from "./FoliNavigation.js";
17
18
  export { FoliToolbar, type FoliToolbarProps } from "./FoliToolbar.js";
package/styles.css CHANGED
@@ -40,6 +40,11 @@
40
40
  outline: none;
41
41
  }
42
42
 
43
+ /* A header or footer being edited on its page (the view dims the rest of the page). */
44
+ .foli-story-mount {
45
+ outline-color: var(--foli-focus-ring);
46
+ }
47
+
43
48
  .foli-content ::selection {
44
49
  background: var(--foli-selection-color);
45
50
  }
@@ -193,6 +198,31 @@
193
198
  flex: 0 0 5em;
194
199
  }
195
200
 
201
+ .foli-setup-field {
202
+ display: flex;
203
+ flex-direction: column;
204
+ gap: 2px;
205
+ flex: 0 1 12em;
206
+ }
207
+
208
+ .foli-setup-field select,
209
+ .foli-setup-field input {
210
+ flex: none;
211
+ height: 32px;
212
+ font: inherit;
213
+ }
214
+
215
+ .foli-setup-check {
216
+ flex-direction: row;
217
+ align-items: center;
218
+ gap: 6px;
219
+ }
220
+
221
+ .foli-setup-check input {
222
+ width: 16px;
223
+ height: 16px;
224
+ }
225
+
196
226
  .foli-menu-swatch {
197
227
  width: 16px;
198
228
  height: 16px;
@@ -254,6 +284,155 @@
254
284
  outline-offset: 1px;
255
285
  }
256
286
 
287
+ /* Find and replace, bookmarks (FoliNavigation): over the pages, not moving them. */
288
+ .foli-navigation {
289
+ display: contents;
290
+ }
291
+
292
+ .foli-find-panel {
293
+ position: fixed;
294
+ top: 8px;
295
+ right: 16px;
296
+ z-index: 20;
297
+ box-sizing: border-box;
298
+ width: min(30rem, calc(100vw - 32px));
299
+ max-height: calc(100vh - 16px);
300
+ overflow: auto;
301
+ border: 1px solid var(--foli-border-color);
302
+ border-radius: 6px;
303
+ box-shadow: var(--foli-page-shadow);
304
+ }
305
+
306
+ .foli-bookmarks {
307
+ top: 64px;
308
+ }
309
+
310
+ .foli-find-modes {
311
+ display: flex;
312
+ gap: 4px;
313
+ margin-bottom: 8px;
314
+ }
315
+
316
+ .foli-find-modes [role="tablist"] {
317
+ display: flex;
318
+ gap: 4px;
319
+ margin-inline-end: auto;
320
+ }
321
+
322
+ .foli-find-modes [aria-selected="true"] {
323
+ background: var(--foli-toolbar-pressed);
324
+ }
325
+
326
+ .foli-find-panel label:not(.foli-find-option) {
327
+ flex: 0 0 7em;
328
+ }
329
+
330
+ .foli-find-panel input[type="text"],
331
+ .foli-find-panel select {
332
+ flex: 1 1 14em;
333
+ min-width: 0;
334
+ font: inherit;
335
+ }
336
+
337
+ .foli-find-panel select {
338
+ min-height: 32px;
339
+ }
340
+
341
+ .foli-find-option {
342
+ display: inline-flex;
343
+ align-items: center;
344
+ gap: 4px;
345
+ }
346
+
347
+ .foli-find-option input {
348
+ flex: none;
349
+ height: auto;
350
+ }
351
+
352
+ .foli-find-panel button:disabled {
353
+ color: GrayText;
354
+ cursor: default;
355
+ }
356
+
357
+ .foli-find-status {
358
+ flex-basis: 100%;
359
+ min-height: 1.4em;
360
+ margin: 0;
361
+ }
362
+
363
+ @media (forced-colors: active) {
364
+ .foli-find-modes [aria-selected="true"] {
365
+ outline: 2px solid Highlight;
366
+ outline-offset: -2px;
367
+ }
368
+ }
369
+
370
+ /* The outline (FoliNavigation): a column beside the pages. */
371
+ .foli-outline {
372
+ position: sticky;
373
+ top: 0;
374
+ flex: 0 0 16rem;
375
+ box-sizing: border-box;
376
+ max-height: 100vh;
377
+ overflow: auto;
378
+ padding: 8px;
379
+ border-inline-end: 1px solid var(--foli-border-color);
380
+ background: var(--foli-toolbar-background);
381
+ color: var(--foli-toolbar-color);
382
+ font:
383
+ 13px / 1.4 system-ui,
384
+ sans-serif;
385
+ }
386
+
387
+ .foli-outline-head {
388
+ display: flex;
389
+ align-items: center;
390
+ justify-content: space-between;
391
+ }
392
+
393
+ .foli-outline h2 {
394
+ margin: 0;
395
+ font-size: 14px;
396
+ }
397
+
398
+ .foli-outline ol {
399
+ margin: 8px 0 0;
400
+ padding: 0;
401
+ list-style: none;
402
+ }
403
+
404
+ .foli-outline button {
405
+ display: flex;
406
+ justify-content: space-between;
407
+ gap: 8px;
408
+ width: 100%;
409
+ padding: 3px 4px;
410
+ border: none;
411
+ border-radius: 3px;
412
+ background: none;
413
+ color: inherit;
414
+ font: inherit;
415
+ text-align: start;
416
+ cursor: pointer;
417
+ }
418
+
419
+ .foli-outline-head button {
420
+ width: auto;
421
+ }
422
+
423
+ .foli-outline button:hover {
424
+ background: var(--foli-toolbar-hover);
425
+ }
426
+
427
+ .foli-outline button[aria-current] {
428
+ background: var(--foli-toolbar-pressed);
429
+ }
430
+
431
+ .foli-outline :focus-visible {
432
+ outline: 2px solid var(--foli-focus-ring);
433
+ outline-offset: -2px;
434
+ }
435
+
257
436
  .foli-link-error {
258
437
  flex-basis: 100%;
259
438
  margin: 0;
@@ -393,6 +572,7 @@
393
572
  }
394
573
  .foli-toolbar,
395
574
  .foli-link-dialog,
575
+ .foli-outline,
396
576
  .foli-comments {
397
577
  display: none;
398
578
  }