@folijs/react 0.4.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
  }
@@ -162,7 +167,7 @@
162
167
  cursor: pointer;
163
168
  }
164
169
 
165
- .foli-menu-item:hover,
170
+ .foli-menu-item:not([aria-disabled="true"]):hover,
166
171
  .foli-menu-item:focus-visible {
167
172
  background: var(--foli-toolbar-hover);
168
173
  }
@@ -172,6 +177,52 @@
172
177
  outline-offset: -2px;
173
178
  }
174
179
 
180
+ /* An item that cannot apply here (the table menu's): shown, focusable, dimmed. */
181
+ .foli-menu-item[aria-disabled="true"] {
182
+ opacity: 0.5;
183
+ cursor: default;
184
+ }
185
+
186
+ /* The table menu's checkbox item: a check before it when on. */
187
+ .foli-menu-item[role="menuitemcheckbox"]::before {
188
+ content: "";
189
+ width: 1em;
190
+ }
191
+
192
+ .foli-menu-item[role="menuitemcheckbox"][aria-checked="true"]::before {
193
+ /* No accessible name of its own: the item's checked state says it. */
194
+ content: "\2713" / "";
195
+ }
196
+
197
+ .foli-table-dialog input {
198
+ flex: 0 0 5em;
199
+ }
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
+
175
226
  .foli-menu-swatch {
176
227
  width: 16px;
177
228
  height: 16px;
@@ -233,6 +284,155 @@
233
284
  outline-offset: 1px;
234
285
  }
235
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
+
236
436
  .foli-link-error {
237
437
  flex-basis: 100%;
238
438
  margin: 0;
@@ -372,6 +572,7 @@
372
572
  }
373
573
  .foli-toolbar,
374
574
  .foli-link-dialog,
575
+ .foli-outline,
375
576
  .foli-comments {
376
577
  display: none;
377
578
  }