vultus-core 0.5.7 → 0.5.9
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/README.md +199 -5
- package/dist/Components.d.ts +41 -0
- package/dist/Components.d.ts.map +1 -1
- package/dist/Components.js.map +1 -1
- package/dist/action-core.d.ts +1 -0
- package/dist/action-core.d.ts.map +1 -1
- package/dist/action-core.js +3 -0
- package/dist/action-core.js.map +1 -1
- package/dist/changes/ChangeMark.d.ts +85 -0
- package/dist/changes/ChangeMark.d.ts.map +1 -0
- package/dist/changes/ChangeMark.js +113 -0
- package/dist/changes/ChangeMark.js.map +1 -0
- package/dist/changes/ChangingText.d.ts +20 -0
- package/dist/changes/ChangingText.d.ts.map +1 -0
- package/dist/changes/ChangingText.js +31 -0
- package/dist/changes/ChangingText.js.map +1 -0
- package/dist/changes/FallbackMark.d.ts +20 -0
- package/dist/changes/FallbackMark.d.ts.map +1 -0
- package/dist/changes/FallbackMark.js +53 -0
- package/dist/changes/FallbackMark.js.map +1 -0
- package/dist/changes/blocks.d.ts +15 -0
- package/dist/changes/blocks.d.ts.map +1 -0
- package/dist/changes/blocks.js +24 -0
- package/dist/changes/blocks.js.map +1 -0
- package/dist/changes/changeDurations.d.ts +21 -0
- package/dist/changes/changeDurations.d.ts.map +1 -0
- package/dist/changes/changeDurations.js +18 -0
- package/dist/changes/changeDurations.js.map +1 -0
- package/dist/changes/changesIn.d.ts +88 -0
- package/dist/changes/changesIn.d.ts.map +1 -0
- package/dist/changes/changesIn.js +470 -0
- package/dist/changes/changesIn.js.map +1 -0
- package/dist/changes/readText.d.ts +45 -0
- package/dist/changes/readText.d.ts.map +1 -0
- package/dist/changes/readText.js +99 -0
- package/dist/changes/readText.js.map +1 -0
- package/dist/changes/rehypeChanges.d.ts +81 -0
- package/dist/changes/rehypeChanges.d.ts.map +1 -0
- package/dist/changes/rehypeChanges.js +268 -0
- package/dist/changes/rehypeChanges.js.map +1 -0
- package/dist/changes/useTextChanges.d.ts +93 -0
- package/dist/changes/useTextChanges.d.ts.map +1 -0
- package/dist/changes/useTextChanges.js +154 -0
- package/dist/changes/useTextChanges.js.map +1 -0
- package/dist/changes/visibleBlocks.d.ts +42 -0
- package/dist/changes/visibleBlocks.d.ts.map +1 -0
- package/dist/changes/visibleBlocks.js +104 -0
- package/dist/changes/visibleBlocks.js.map +1 -0
- package/dist/changes.d.ts +9 -0
- package/dist/changes.d.ts.map +1 -0
- package/dist/changes.js +10 -0
- package/dist/changes.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useAction.d.ts.map +1 -1
- package/dist/useAction.js +1 -0
- package/dist/useAction.js.map +1 -1
- package/package.json +13 -1
- package/src/Components.tsx +45 -0
- package/src/action-core.ts +4 -0
- package/src/changes/ChangeMark.tsx +165 -0
- package/src/changes/ChangingText.tsx +46 -0
- package/src/changes/FallbackMark.tsx +59 -0
- package/src/changes/blocks.ts +25 -0
- package/src/changes/changeDurations.ts +31 -0
- package/src/changes/changesIn.ts +479 -0
- package/src/changes/readText.ts +123 -0
- package/src/changes/rehypeChanges.ts +302 -0
- package/src/changes/useTextChanges.ts +239 -0
- package/src/changes/visibleBlocks.ts +121 -0
- package/src/changes.ts +14 -0
- package/src/index.ts +4 -0
- package/src/types.ts +4 -0
- package/src/useAction.ts +1 -0
package/README.md
CHANGED
|
@@ -36,10 +36,14 @@ npm install vultus-core
|
|
|
36
36
|
`useInternalLink` / `InternalLinkComponent`, `MessageSinkContext` /
|
|
37
37
|
`useMessageSink` / `MessageSink`, and `VultusComponentsContext` /
|
|
38
38
|
`useVultusComponents` / `SpinnerScope` / `useSpinnerKey` /
|
|
39
|
-
`VultusComponents` / `SpinnerProps` / `SpinnerComponent
|
|
39
|
+
`VultusComponents` / `SpinnerProps` / `SpinnerComponent` /
|
|
40
|
+
`ChangeMarkVariant` / `ChangeMarkProps` / `ChangeMarkComponent`.
|
|
40
41
|
- `./link` — `InternalLinkContext`, `useInternalLink`, and the
|
|
41
42
|
`InternalLinkComponent` type on their own, for consumers that only need the
|
|
42
43
|
link-injection seam.
|
|
44
|
+
- `./changes` — text changes (see Text changes, below): `useTextChanges`,
|
|
45
|
+
`ChangingText`, `changesIn`, `readText`, `changeDurations` and their types.
|
|
46
|
+
Only this entry loads `diff-match-patch`.
|
|
43
47
|
|
|
44
48
|
## Actions report messages
|
|
45
49
|
|
|
@@ -54,6 +58,14 @@ offline", a failed fetch its TypeError's); with neither, "Action failed" (a rout
|
|
|
54
58
|
(`errorRoute`): the registry's entry for the body's `reason`, else the message, else
|
|
55
59
|
`t('common.error')`). A field's commit is an action, so the same holds for the field's messages.
|
|
56
60
|
|
|
61
|
+
## Actions that show or hide something
|
|
62
|
+
|
|
63
|
+
An action whose control shows or hides something says whether that is open with `ariaExpanded`
|
|
64
|
+
(a boolean, or a function giving one): its status carries it, for the renderer's `aria-expanded`,
|
|
65
|
+
and without it there is no attribute. A settings gear that toggles a panel is two actions, one
|
|
66
|
+
visible at a time: show (`invisible: shown`, `ariaExpanded: false`) and hide (`invisible: !shown`,
|
|
67
|
+
`ariaExpanded: true`).
|
|
68
|
+
|
|
57
69
|
## Fields
|
|
58
70
|
|
|
59
71
|
`useBoolField(options)` is the first field hook: the value half of vultus, next to
|
|
@@ -628,10 +640,12 @@ it). The group then keeps the value and re-renders, so every option is computed
|
|
|
628
640
|
## Components
|
|
629
641
|
|
|
630
642
|
`VultusComponentsContext` (default `{}`) / `useVultusComponents()` is how an app lends its own
|
|
631
|
-
UI to vultus/optio in place of their native indicators — today
|
|
632
|
-
`spinnerKey`, `size?`, `label?`; `VultusComponents.Spinner?: SpinnerComponent`)
|
|
633
|
-
`
|
|
634
|
-
|
|
643
|
+
UI to vultus/optio in place of their native indicators — today `Spinner` (`SpinnerProps`:
|
|
644
|
+
`spinnerKey`, `size?`, `label?`; `VultusComponents.Spinner?: SpinnerComponent`) and
|
|
645
|
+
`ChangeMark`, the marks of text changes (`VultusComponents.ChangeMark?: ChangeMarkComponent`;
|
|
646
|
+
see Text changes, below). vultus-antd's `VultusProvider` merges a `components` prop into the
|
|
647
|
+
outer context value; without one, the outer value (or this default) applies, as `linkComponent`
|
|
648
|
+
does today.
|
|
635
649
|
|
|
636
650
|
Every call site that may render a lent `Spinner` asks for its key through `useSpinnerKey(localKey)`
|
|
637
651
|
rather than hardcoding it, so an app can scope a whole subtree's keys to one instance:
|
|
@@ -640,6 +654,186 @@ rather than hardcoding it, so an app can scope a whole subtree's keys to one ins
|
|
|
640
654
|
Library-local keys are namespaced (`vultus:...`, `optio:...`) so they never collide with an
|
|
641
655
|
app's own keys.
|
|
642
656
|
|
|
657
|
+
## Text changes
|
|
658
|
+
|
|
659
|
+
What changed between two versions of a text, found and lit up: when a text switches to a related
|
|
660
|
+
version (another spelling, an edit), its changed words and letters are marked for a moment, then
|
|
661
|
+
the marks go. It lives at `vultus-core/changes`, so the main entry stays light: only an app that
|
|
662
|
+
shows text changes loads `diff-match-patch`.
|
|
663
|
+
|
|
664
|
+
vultus decides what changed and which mark goes where; the look comes from whoever lends the
|
|
665
|
+
`ChangeMark` (a style library's provider, say). vultus has no stylesheet for the marks: without a
|
|
666
|
+
lent mark, it draws static ones in inline styles (the fallback, below).
|
|
667
|
+
|
|
668
|
+
### The API
|
|
669
|
+
|
|
670
|
+
- **`useTextChanges(text, options)`** returns `{ rehypePlugin, components, part(name), active }`
|
|
671
|
+
for a Markdown renderer (react-markdown, vultus-antd's `Markdown`): `rehypePlugin` goes into its
|
|
672
|
+
`rehypePlugins`, and `components` (one `ins` entry, drawing the marks) is merged into its
|
|
673
|
+
`components`. `text` is the whole content, all its parts.
|
|
674
|
+
- **`key`** (required) is the content's identity: the app decides which changes are related,
|
|
675
|
+
and the hook never guesses. Same key, new text: a switch, which animates. A new key: the text
|
|
676
|
+
appears plainly, and a running switch stops at once. Same key, same text (a reload, a
|
|
677
|
+
refetch): nothing. The key carries everything that makes content unrelated (the UI language,
|
|
678
|
+
a data generation), or a language change lights the whole text. The first render has nothing
|
|
679
|
+
before it, so nothing animates.
|
|
680
|
+
- **`animate: false`** swaps plainly once, under the same key too (a live edit), and replaces
|
|
681
|
+
the reading, so the next related change starts from this text.
|
|
682
|
+
- **`near`** limits the marks to the blocks near the screen: a function of the block number, or
|
|
683
|
+
`{ container, blocks, rootMargin? }`, the innermost blocks crossing `container` (the scrolling
|
|
684
|
+
pane, through an IntersectionObserver) as a switch starts, `blocks` more each way. It is frozen
|
|
685
|
+
for the switch. Without `near`, or with no range yet, everything is marked. A ref object as
|
|
686
|
+
`container` is read once, after mount: a pane that mounts later or is replaced is given as the
|
|
687
|
+
element (a callback ref kept in state).
|
|
688
|
+
- **`skip(element)`** names what the reading leaves out (footnote marks, KaTeX's output), besides
|
|
689
|
+
elements carrying `data-vultus-change-skip`; it gets the hast `Element` the plugin visits.
|
|
690
|
+
- **`blockAttribute`** names an existing block numbering (`'data-block'`) for `near`; without it
|
|
691
|
+
the plugin numbers the blocks itself, as `data-vultus-block`.
|
|
692
|
+
- **`speed`**: `'slow'`, `'normal'` (the default) or `'fast'`, the lent mark's `speed`. It is
|
|
693
|
+
taken as a switch starts and held for it, marks and timer alike; a new speed counts from the
|
|
694
|
+
next switch and parses nothing.
|
|
695
|
+
- **`part(name)`** gives one tree's `{ rehypePlugin, components }`, for a text drawn as several
|
|
696
|
+
trees (a heading in a title slot, the body below); the result's own are the default part's.
|
|
697
|
+
Each part diffs its own previous reading, and the parts share one switch: one number, one
|
|
698
|
+
timer, one timeline.
|
|
699
|
+
- **`active`** is true while a switch's marks are shown.
|
|
700
|
+
- **Identities.** `components` never changes; `rehypePlugin` and each part keep theirs while
|
|
701
|
+
nothing changes (they change as a switch starts and ends, and with a plain swap), so a
|
|
702
|
+
memoised Markdown parses again only then: keep the plugin list memoised on `rehypePlugin`.
|
|
703
|
+
Inline `skip` and `near` change nothing.
|
|
704
|
+
- **Plugin order.** `rehypePlugin` goes after the plugins that shape the text it reads (with
|
|
705
|
+
`blockAttribute`, the one that numbers the blocks), and before those that add search marks,
|
|
706
|
+
which must skip `[data-change=removed]`.
|
|
707
|
+
- **`<ChangingText changeKey>{string}</ChangingText>`** does the same for a plain string, with the
|
|
708
|
+
same key rules, `animate` and `speed`, rendered as it is, with no wrapper.
|
|
709
|
+
- **`changesIn(from, to)`**, the diff of two plain texts (`Change[]`: `word` and `letters` spans of
|
|
710
|
+
`to`, and `removed` ones of no width at their place, carrying the old letters as `text`), and
|
|
711
|
+
**`readText(tree, options?)`**, the reading of a hast tree that both sides use, are exported for
|
|
712
|
+
an app's own use.
|
|
713
|
+
- **`changeDurations(element?, speed?, mark?)`** gives `{ plain, removals }`, in ms, when a
|
|
714
|
+
switch's marks may go: `mark.durations(element, speed)`, else vultus's defaults (below). The hook
|
|
715
|
+
times each switch with it, with the lent mark, at `near`'s container (else none) and the
|
|
716
|
+
switch's speed.
|
|
717
|
+
|
|
718
|
+
### The lent mark
|
|
719
|
+
|
|
720
|
+
The marks are drawn by the `ChangeMark` in `VultusComponents` (with vultus-antd,
|
|
721
|
+
`<VultusProvider components={{ ChangeMark }}>`; without it, a `VultusComponentsContext.Provider`).
|
|
722
|
+
It is a component drawing one mark, nested as the changes are (letters inside their word), with
|
|
723
|
+
these props (`ChangeMarkProps`):
|
|
724
|
+
|
|
725
|
+
- `variant` (`ChangeMarkVariant`): `change`, a changed word, lightly; `change-strong`, its changed
|
|
726
|
+
letters inside it, more strongly (a switch with no removed letters); on a switch with removed
|
|
727
|
+
letters, `change-removed`, the old letters that went, at their place, and `change-added`, the
|
|
728
|
+
new ones; `change-replaced`, a replacement, around exactly one `change-removed` and one
|
|
729
|
+
`change-added` (old and new letters at one place);
|
|
730
|
+
- `timeline`: `'removals'` on a word while the switch is on the removals timeline, so that it
|
|
731
|
+
waits with the removed and added letters;
|
|
732
|
+
- `speed`: the switch's (none: normal);
|
|
733
|
+
- `data-change`: the change's level (`word`, `letters`, `removed`, `replaced`), for the element
|
|
734
|
+
the mark draws;
|
|
735
|
+
- `children`.
|
|
736
|
+
|
|
737
|
+
Each switch's marks are new elements (vultus keys them by the switch), so a look timed from its
|
|
738
|
+
element's insertion starts again with each switch. Removed letters are not the page's text: a mark
|
|
739
|
+
keeps them away from assistive technology, the tab order and a selection (`aria-hidden`, `inert`,
|
|
740
|
+
`user-select: none`).
|
|
741
|
+
|
|
742
|
+
Its timings travel with it, as they belong to its look (its CSS): a static
|
|
743
|
+
**`durations(element, speed)`** gives `{ plain, removals }`, when its marks may go on each
|
|
744
|
+
timeline, in ms from the commit that shows the new text, at `speed`, read at `element` (`near`'s
|
|
745
|
+
container, else `undefined`). A lent mark without `durations` gets vultus's defaults. The types its
|
|
746
|
+
props and timings name (`ChangeLevel`, `ChangeSpeed`, `ChangeDurations`) come from `vultus-core`
|
|
747
|
+
too, as types only.
|
|
748
|
+
|
|
749
|
+
The hook times a switch by the mark lent where the hook is called, and the marks are drawn by the
|
|
750
|
+
one lent where they render: keep both under one provider, so that the look and its timings agree.
|
|
751
|
+
|
|
752
|
+
```tsx
|
|
753
|
+
import { version } from 'react';
|
|
754
|
+
import type { ChangeMarkComponent, ChangeMarkProps } from 'vultus-core';
|
|
755
|
+
|
|
756
|
+
// `inert` as this React takes it: a boolean from 19 on; 18 needs '', which 19 reads as false.
|
|
757
|
+
const INERT = (Number.parseInt(version, 10) >= 19 ? { inert: true } : { inert: '' }) as { inert?: boolean };
|
|
758
|
+
|
|
759
|
+
const FadeMark: ChangeMarkComponent = Object.assign(
|
|
760
|
+
({ variant, 'data-change': change, children }: ChangeMarkProps) => {
|
|
761
|
+
const removed = variant === 'change-removed' ? { 'aria-hidden': true, ...INERT } : {};
|
|
762
|
+
return <mark className={`fade-${variant}`} data-change={change} {...removed}>{children}</mark>;
|
|
763
|
+
},
|
|
764
|
+
{ durations: () => ({ plain: 1500, removals: 2500 }) }, // when fade.css's animations end
|
|
765
|
+
);
|
|
766
|
+
|
|
767
|
+
<VultusProvider components={{ ChangeMark: FadeMark }}>{app}</VultusProvider>
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
### Without a lent mark
|
|
771
|
+
|
|
772
|
+
vultus's fallback is static marks in inline styles, with no stylesheet and no animation, each a
|
|
773
|
+
`mark` carrying `data-change`: `change`, `change-strong` and `change-added` a translucent green
|
|
774
|
+
background; `change-removed` a translucent red one, struck through (and `aria-hidden`, `inert`,
|
|
775
|
+
`user-select: none`); `change-replaced` drawn as its new letters (the old ones in it not
|
|
776
|
+
displayed). The colours are fixed and translucent, so they read on a light and a dark background
|
|
777
|
+
alike. Its timings are vultus's defaults: the marks go 1.55 s after the switch on the plain
|
|
778
|
+
timeline and 2.3 s after it on removals, at every speed, so a switch still ends.
|
|
779
|
+
|
|
780
|
+
### Example
|
|
781
|
+
|
|
782
|
+
A task page shaped like Praeceptor's: one Markdown content drawn as two trees (its leading
|
|
783
|
+
heading in the title slot, the body below), over the app's own block numbering and leave-outs.
|
|
784
|
+
`TaskTextProps`, `rehypeBlocks`, `rehypeSearch` and `leadingHeading` stand for the app's own.
|
|
785
|
+
|
|
786
|
+
```tsx
|
|
787
|
+
import { useMemo } from 'react';
|
|
788
|
+
import type { Element } from 'hast';
|
|
789
|
+
import { Markdown } from 'vultus-antd';
|
|
790
|
+
import { useTextChanges } from 'vultus-core/changes';
|
|
791
|
+
|
|
792
|
+
/** What the reader does not read as text: a footnote's link back, KaTeX's output. */
|
|
793
|
+
const skip = (element: Element) =>
|
|
794
|
+
String(element.properties.className ?? '').includes('katex')
|
|
795
|
+
|| (element.tagName === 'a' && element.properties.dataFootnoteBackref !== undefined);
|
|
796
|
+
|
|
797
|
+
function TaskText({ task, markdown, lang, pane }: TaskTextProps) {
|
|
798
|
+
const changes = useTextChanges(markdown, {
|
|
799
|
+
// textOf: the text this task is a version of. Another version of the same text, in the same
|
|
800
|
+
// language, lights up; anything else shows plainly.
|
|
801
|
+
key: `${task.textOf ?? task.id}/${lang}`,
|
|
802
|
+
near: pane ? { container: pane, blocks: 3 } : undefined, // the blocks in view, 3 more each way
|
|
803
|
+
blockAttribute: 'data-block', // rehypeBlocks numbers them already
|
|
804
|
+
skip,
|
|
805
|
+
});
|
|
806
|
+
const heading = changes.part('heading');
|
|
807
|
+
const body = changes.part('body');
|
|
808
|
+
const { title, rest } = leadingHeading(markdown);
|
|
809
|
+
// Memoised on the plugin: a new list every render would make Markdown parse every render.
|
|
810
|
+
const headingPlugins = useMemo(() => [heading.rehypePlugin], [heading.rehypePlugin]);
|
|
811
|
+
const bodyPlugins = useMemo(() => [rehypeBlocks, body.rehypePlugin, rehypeSearch], [body.rehypePlugin]);
|
|
812
|
+
return (
|
|
813
|
+
<>
|
|
814
|
+
<h2><Markdown inline rehypePlugins={headingPlugins} components={heading.components}>{title}</Markdown></h2>
|
|
815
|
+
<Markdown rehypePlugins={bodyPlugins} components={body.components}>{rest}</Markdown>
|
|
816
|
+
</>
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
An app with components of its own merges the hook's over them, memoised:
|
|
822
|
+
`useMemo(() => ({ ...mine, ...body.components }), [body.components])`.
|
|
823
|
+
|
|
824
|
+
### Known gaps
|
|
825
|
+
|
|
826
|
+
Known and not fixed yet, all in what is marked and where, not in how a mark looks:
|
|
827
|
+
|
|
828
|
+
- A word removed altogether right beside a changed word is drawn inside that word's mark (whose
|
|
829
|
+
span runs from white space to white space), not as a removal of its own.
|
|
830
|
+
- Punctuation replaced by other punctuation is not drawn as a replacement: the old and the new
|
|
831
|
+
show side by side.
|
|
832
|
+
- A removed run that starts with a word and touches punctuation, where the new text keeps a space
|
|
833
|
+
at that place, shows after that space.
|
|
834
|
+
- With `near` as the blocks on screen, which go by the innermost blocks, the first lines of an
|
|
835
|
+
outer block in a deeply nested outline can fall outside the range, and are not marked.
|
|
836
|
+
|
|
643
837
|
## Distribution
|
|
644
838
|
|
|
645
839
|
This package ships compiled ESM (`dist/`) with TypeScript declarations to
|
package/dist/Components.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type ComponentType, type ReactNode } from 'react';
|
|
2
|
+
import type { ChangeDurations, ChangeSpeed } from './changes/changeDurations.js';
|
|
3
|
+
import type { ChangeLevel } from './changes/changesIn.js';
|
|
2
4
|
/** A spinner an app lends to vultus/optio, rendered in place of their native loading indicators. */
|
|
3
5
|
export interface SpinnerProps {
|
|
4
6
|
/** The spinner's identity: stable across re-renders and remounts, unique on the page (after scoping). */
|
|
@@ -9,9 +11,48 @@ export interface SpinnerProps {
|
|
|
9
11
|
label?: string;
|
|
10
12
|
}
|
|
11
13
|
export type SpinnerComponent = ComponentType<SpinnerProps>;
|
|
14
|
+
/**
|
|
15
|
+
* What a change mark draws (`vultus-core/changes`): `change`, a changed word, lightly;
|
|
16
|
+
* `change-strong`, its changed letters inside it, more strongly (a switch with no removed letters);
|
|
17
|
+
* on a switch with removed letters, `change-removed`, the old letters that went, at their place,
|
|
18
|
+
* and `change-added`, the new ones; `change-replaced`, a replacement, around exactly one
|
|
19
|
+
* `change-removed` and one `change-added` (old and new letters at one place).
|
|
20
|
+
*/
|
|
21
|
+
export type ChangeMarkVariant = 'change' | 'change-strong' | 'change-removed' | 'change-added' | 'change-replaced';
|
|
22
|
+
/**
|
|
23
|
+
* A change mark's props, as vultus's text changes give them, one mark per change, nested as the
|
|
24
|
+
* changes are (letters inside their word). Each switch's marks are new elements (vultus keys them
|
|
25
|
+
* by the switch), so a look timed from its element's insertion starts with each switch.
|
|
26
|
+
*/
|
|
27
|
+
export interface ChangeMarkProps {
|
|
28
|
+
variant: ChangeMarkVariant;
|
|
29
|
+
/** On a word (`change`), while the switch is on the removals timeline: it waits with the
|
|
30
|
+
* removed and added letters, holding them or not. */
|
|
31
|
+
timeline?: 'removals';
|
|
32
|
+
/** How fast the switch's marks run, the same for every mark of it; none: normal. */
|
|
33
|
+
speed?: ChangeSpeed;
|
|
34
|
+
/** The change's level, for the element the mark draws (`[data-change]`). */
|
|
35
|
+
'data-change': ChangeLevel;
|
|
36
|
+
children?: ReactNode;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A change mark an app lends to vultus's text changes: a component drawing one mark, and, as a
|
|
40
|
+
* static property, `durations`: when a switch's marks may go, in ms from the commit that shows the
|
|
41
|
+
* new text, at `speed`, read at `element` (the near container, else none). The timings belong to
|
|
42
|
+
* the look, so they travel with it. Without `durations`, vultus's defaults; without a lent mark,
|
|
43
|
+
* vultus's fallback: static marks, inline styles.
|
|
44
|
+
*
|
|
45
|
+
* A mark keeps removed letters away from assistive technology, the tab order and a selection
|
|
46
|
+
* (`aria-hidden`, `inert`, `user-select: none`): they are not the page's text.
|
|
47
|
+
*/
|
|
48
|
+
export type ChangeMarkComponent = ComponentType<ChangeMarkProps> & {
|
|
49
|
+
durations?(element: Element | undefined, speed: ChangeSpeed): ChangeDurations;
|
|
50
|
+
};
|
|
12
51
|
/** Components an app lends to the libraries. */
|
|
13
52
|
export interface VultusComponents {
|
|
14
53
|
Spinner?: SpinnerComponent;
|
|
54
|
+
/** The change marks of `vultus-core/changes`. */
|
|
55
|
+
ChangeMark?: ChangeMarkComponent;
|
|
15
56
|
}
|
|
16
57
|
/**
|
|
17
58
|
* The components an app lends to vultus/optio in place of their own UI. Default is `{}`
|
package/dist/Components.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Components.d.ts","sourceRoot":"","sources":["../src/Components.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE/F,oGAAoG;AACpG,MAAM,WAAW,YAAY;IAC3B,yGAAyG;IACzG,UAAU,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;IAC9C,gEAAgE;IAChE,KAAK,CAAC,EAAE,MAA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GAAG,SAAS,EAAE,KAAK,EAAE,WAAW,GAAG,eAAe,CAAC;CAC/E,CAAC;AAEF,gDAAgD;AAChD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,iDAAiD;IACjD,UAAU,CAAC,EAAE,mBAAmB,CAAC;CAClC;AAED;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,2CAAsC,CAAC;AAE3E,wBAAgB,mBAAmB,IAAI,gBAAgB,CAEtD;AAKD,+EAA+E;AAC/E,wBAAgB,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,+BAOtF;AAED,iGAAiG;AACjG,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGtD"}
|
package/dist/Components.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Components.js","sourceRoot":"","sources":["../src/Components.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAsC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Components.js","sourceRoot":"","sources":["../src/Components.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAsC,MAAM,OAAO,CAAC;AA+D/F;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAmB,EAAE,CAAC,CAAC;AAE3E,MAAM,UAAU,mBAAmB;IACjC,OAAO,UAAU,CAAC,uBAAuB,CAAC,CAAC;AAC7C,CAAC;AAED,qGAAqG;AACrG,MAAM,mBAAmB,GAAG,aAAa,CAAW,EAAE,CAAC,CAAC;AAExD,+EAA+E;AAC/E,MAAM,UAAU,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAA0C;IACrF,MAAM,KAAK,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAC9C,uFAAuF;IACvF,uFAAuF;IACvF,2DAA2D;IAC3D,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;IAC7D,OAAO,KAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAgC,CAAC;AAC/F,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC5C,MAAM,KAAK,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,KAAK,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACxC,CAAC"}
|
package/dist/action-core.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface ResolvedFields {
|
|
|
14
14
|
disabled: boolean;
|
|
15
15
|
reason: string | undefined;
|
|
16
16
|
invisible: boolean;
|
|
17
|
+
ariaExpanded: boolean | undefined;
|
|
17
18
|
confirmation: ConfirmationSpec | undefined;
|
|
18
19
|
}
|
|
19
20
|
/** Resolve the static (hookless) ActionStatus fields from the options. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-core.d.ts","sourceRoot":"","sources":["../src/action-core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAK9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,YAAY,EACZ,gBAAgB,EAEhB,mBAAmB,EAEnB,OAAO,EAER,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AAEH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CA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getVerdict(enabledD, true),
|
|
13
13
|
reason: getReason(enabledD),
|
|
14
14
|
invisible: resolve(opts.invisible, false),
|
|
15
|
+
// No default: absent stays absent (no aria-expanded), unlike `invisible`'s false.
|
|
16
|
+
ariaExpanded: resolve(opts.ariaExpanded, undefined),
|
|
15
17
|
confirmation: resolve(opts.confirmation, undefined),
|
|
16
18
|
};
|
|
17
19
|
}
|
|
@@ -81,6 +83,7 @@ export function assembleStatus(opts, fields, pending, messages, firePromise) {
|
|
|
81
83
|
disabled: fields.disabled,
|
|
82
84
|
reason: fields.reason,
|
|
83
85
|
invisible: fields.invisible,
|
|
86
|
+
ariaExpanded: fields.ariaExpanded,
|
|
84
87
|
confirmation: fields.confirmation,
|
|
85
88
|
messages,
|
|
86
89
|
errors: messages.filter((m) => m.severity === 'error').map((m) => m.text),
|
package/dist/action-core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-core.js","sourceRoot":"","sources":["../src/action-core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"action-core.js","sourceRoot":"","sources":["../src/action-core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AA+BnD,0EAA0E;AAC1E,MAAM,UAAU,mBAAmB,CAAC,IAAkC;IACpE,MAAM,QAAQ,GAAG,OAAO,CAAW,IAAI,CAAC,OAA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eSpeed } from './changeDurations.js';
|
|
3
|
+
import type { ChangeLevel } from './changesIn.js';
|
|
4
|
+
/**
|
|
5
|
+
* The timeline a switch's marks run on: `removals` for a switch that shows removed letters, the
|
|
6
|
+
* old letters cut away before the new ones are uncovered; `plain` for one that shows none, its
|
|
7
|
+
* letters lit at once. One per switch, over all its parts: a lent mark's removal timeline may
|
|
8
|
+
* light a word later than its plain one, so a switch's parts on two timelines would light apart
|
|
9
|
+
* (a switch with any removal uses the removals timeline for all its letters).
|
|
10
|
+
*/
|
|
11
|
+
export type ChangeTimeline = 'plain' | 'removals';
|
|
12
|
+
/** A switch as its marks draw it: its number (0 outside one), its timeline (`undefined`: not
|
|
13
|
+
* decided yet, drawn `plain`), and its speed (the lent mark's `speed`; none: normal), taken as it
|
|
14
|
+
* started. */
|
|
15
|
+
export interface ChangeState {
|
|
16
|
+
number: number;
|
|
17
|
+
timeline: ChangeTimeline | undefined;
|
|
18
|
+
speed?: ChangeSpeed;
|
|
19
|
+
}
|
|
20
|
+
/** Where the marks read the switch's state from: the hook's store, read-only. */
|
|
21
|
+
export interface ChangeSource {
|
|
22
|
+
subscribe(listener: () => void): () => void;
|
|
23
|
+
getSnapshot(): ChangeState;
|
|
24
|
+
}
|
|
25
|
+
/** The hook's store of the switch's state: `set` replaces it, and with `notify` re-renders the
|
|
26
|
+
* marks (not the trees: no re-parse). */
|
|
27
|
+
export interface ChangeStore extends ChangeSource {
|
|
28
|
+
set(state: ChangeState, notify: boolean): void;
|
|
29
|
+
}
|
|
30
|
+
/** A store of the switch's state, from `initial` (by default, no switch: number 0, undecided). */
|
|
31
|
+
export declare function changeStore(initial?: ChangeState): ChangeStore;
|
|
32
|
+
/**
|
|
33
|
+
* A change from another version of the text, as the changes plugin marks it (`changesPlugin`): a
|
|
34
|
+
* changed word (`word`), its changed letters inside it (`letters`), the old letters that went
|
|
35
|
+
* (`removed`), and a replacement around old letters and the new ones at their place (`replaced`),
|
|
36
|
+
* each carrying `data-change`, its level. The one place the look is drawn.
|
|
37
|
+
*
|
|
38
|
+
* The look is the lent mark's: the `ChangeMark` an app lends through `VultusComponents`; without
|
|
39
|
+
* one, vultus's fallback (`FallbackMark`), static marks. `variant="change"` on the word, lightly.
|
|
40
|
+
* On the `plain` timeline (and until it is decided), `variant="change-strong"` on its letters
|
|
41
|
+
* inside it, more strongly: lit at once, then faded, each mark timed from its own insertion. On the
|
|
42
|
+
* `removals` timeline, the old letters in `variant="change-removed"` (cut away first) and the new
|
|
43
|
+
* ones in `variant="change-added"` (uncovered after); every word takes `timeline="removals"`, so
|
|
44
|
+
* that one holding neither removed nor added letters (the `vei` of `*hí*vei`, a piece of a word
|
|
45
|
+
* split by markup) waits with the rest rather than lighting at once. `removed` is drawn so on
|
|
46
|
+
* either timeline: a switch that shows any is on `removals`.
|
|
47
|
+
*
|
|
48
|
+
* A replacement (`replaced`), on the `removals` timeline, is `variant="change-replaced"` around its
|
|
49
|
+
* two, which morph from the old letters to the new. A lent mark may measure both letters once, as
|
|
50
|
+
* the wrapper is put in, so on `plain` and while undecided the two are drawn as they are, unwrapped
|
|
51
|
+
* (a Fragment): there the new letters are `change-strong`, with no letters span to measure, and the
|
|
52
|
+
* wrapper would close to no width. It is put in, and measures, in the commit that puts the switch
|
|
53
|
+
* on `removals`, before the paint.
|
|
54
|
+
*
|
|
55
|
+
* Keyed by `number`, the switch's: a lent mark's fade may belong to the element, timed from its
|
|
56
|
+
* insertion, and react-markdown keys an element by its tag's count among its siblings, so the next
|
|
57
|
+
* switch's mark on the same word has the same key. A new number draws new marks, lit from the
|
|
58
|
+
* start, never the switch before's, half faded or gone; a render within one keeps them, fading on.
|
|
59
|
+
*
|
|
60
|
+
* Every mark takes the switch's `speed` (the lent mark's; none: normal), so its words and letters
|
|
61
|
+
* run one timeline.
|
|
62
|
+
*/
|
|
63
|
+
export declare function ChangeMark({ level, number, timeline, speed, children }: {
|
|
64
|
+
level: ChangeLevel;
|
|
65
|
+
number: number;
|
|
66
|
+
timeline: ChangeTimeline | undefined;
|
|
67
|
+
speed?: ChangeSpeed;
|
|
68
|
+
children?: ReactNode;
|
|
69
|
+
}): ReactElement;
|
|
70
|
+
/** An `ins` as react-markdown gives it to its `components`: its props, and the hast `node`. */
|
|
71
|
+
export type InsProps = ComponentPropsWithoutRef<'ins'> & {
|
|
72
|
+
node?: unknown;
|
|
73
|
+
};
|
|
74
|
+
/** The components entry an app merges into its Markdown's `components`. */
|
|
75
|
+
export interface ChangeComponents {
|
|
76
|
+
ins: (props: InsProps) => ReactElement;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The `ins` entry drawing the change marks with `source`'s state: an `ins` whose `data-change` is a
|
|
80
|
+
* change level is a `ChangeMark` with the switch's number, timeline and speed; any other `ins` is
|
|
81
|
+
* drawn as itself (react-markdown's `node` dropped). One frozen object per source, so its identity
|
|
82
|
+
* never changes: an app's Markdown memoises on its `components`.
|
|
83
|
+
*/
|
|
84
|
+
export declare function changeComponents(source: ChangeSource): ChangeComponents;
|
|
85
|
+
//# sourceMappingURL=ChangeMark.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChangeMark.d.ts","sourceRoot":"","sources":["../../src/changes/ChangeMark.tsx"],"names":[],"mappings":"AAAA,OAAO,EAC6C,KAAK,wBAAwB,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EACnH,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,UAAU,CAAC;AAElD;;eAEe;AACf,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,cAAc,GAAG,SAAS,CAAC;IACrC,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAED,iFAAiF;AACjF,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,WAAW,IAAI,WAAW,CAAC;CAC5B;AAED;0CAC0C;AAC1C,MAAM,WAAW,WAAY,SAAQ,YAAY;IAC/C,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;CAChD;AAED,kGAAkG;AAClG,wBAAgB,WAAW,CAAC,OAAO,GAAE,WAAgD,GAAG,WAAW,CAkBlG;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;IACvE,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,cAAc,GAAG,SAAS,CAAC;IACrC,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB,GAAG,YAAY,CAWf;AAED,+FAA+F;AAC/F,MAAM,MAAM,QAAQ,GAAG,wBAAwB,CAAC,KAAK,CAAC,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAE5E,2EAA2E;AAC3E,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,YAAY,CAAC;CACxC;AAOD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,gBAAgB,CAavE"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, useEffect, useLayoutEffect, useReducer, } from 'react';
|
|
3
|
+
import { useVultusComponents } from '../Components.js';
|
|
4
|
+
import { FallbackMark } from './FallbackMark.js';
|
|
5
|
+
/** A store of the switch's state, from `initial` (by default, no switch: number 0, undecided). */
|
|
6
|
+
export function changeStore(initial = { number: 0, timeline: undefined }) {
|
|
7
|
+
let state = initial;
|
|
8
|
+
const listeners = new Set();
|
|
9
|
+
return {
|
|
10
|
+
subscribe(listener) {
|
|
11
|
+
listeners.add(listener);
|
|
12
|
+
return () => {
|
|
13
|
+
listeners.delete(listener);
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
getSnapshot() {
|
|
17
|
+
return state;
|
|
18
|
+
},
|
|
19
|
+
set(next, notify) {
|
|
20
|
+
state = next;
|
|
21
|
+
if (notify)
|
|
22
|
+
for (const listener of Array.from(listeners))
|
|
23
|
+
listener();
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A change from another version of the text, as the changes plugin marks it (`changesPlugin`): a
|
|
29
|
+
* changed word (`word`), its changed letters inside it (`letters`), the old letters that went
|
|
30
|
+
* (`removed`), and a replacement around old letters and the new ones at their place (`replaced`),
|
|
31
|
+
* each carrying `data-change`, its level. The one place the look is drawn.
|
|
32
|
+
*
|
|
33
|
+
* The look is the lent mark's: the `ChangeMark` an app lends through `VultusComponents`; without
|
|
34
|
+
* one, vultus's fallback (`FallbackMark`), static marks. `variant="change"` on the word, lightly.
|
|
35
|
+
* On the `plain` timeline (and until it is decided), `variant="change-strong"` on its letters
|
|
36
|
+
* inside it, more strongly: lit at once, then faded, each mark timed from its own insertion. On the
|
|
37
|
+
* `removals` timeline, the old letters in `variant="change-removed"` (cut away first) and the new
|
|
38
|
+
* ones in `variant="change-added"` (uncovered after); every word takes `timeline="removals"`, so
|
|
39
|
+
* that one holding neither removed nor added letters (the `vei` of `*hí*vei`, a piece of a word
|
|
40
|
+
* split by markup) waits with the rest rather than lighting at once. `removed` is drawn so on
|
|
41
|
+
* either timeline: a switch that shows any is on `removals`.
|
|
42
|
+
*
|
|
43
|
+
* A replacement (`replaced`), on the `removals` timeline, is `variant="change-replaced"` around its
|
|
44
|
+
* two, which morph from the old letters to the new. A lent mark may measure both letters once, as
|
|
45
|
+
* the wrapper is put in, so on `plain` and while undecided the two are drawn as they are, unwrapped
|
|
46
|
+
* (a Fragment): there the new letters are `change-strong`, with no letters span to measure, and the
|
|
47
|
+
* wrapper would close to no width. It is put in, and measures, in the commit that puts the switch
|
|
48
|
+
* on `removals`, before the paint.
|
|
49
|
+
*
|
|
50
|
+
* Keyed by `number`, the switch's: a lent mark's fade may belong to the element, timed from its
|
|
51
|
+
* insertion, and react-markdown keys an element by its tag's count among its siblings, so the next
|
|
52
|
+
* switch's mark on the same word has the same key. A new number draws new marks, lit from the
|
|
53
|
+
* start, never the switch before's, half faded or gone; a render within one keeps them, fading on.
|
|
54
|
+
*
|
|
55
|
+
* Every mark takes the switch's `speed` (the lent mark's; none: normal), so its words and letters
|
|
56
|
+
* run one timeline.
|
|
57
|
+
*/
|
|
58
|
+
export function ChangeMark({ level, number, timeline, speed, children }) {
|
|
59
|
+
const Mark = useVultusComponents().ChangeMark ?? FallbackMark;
|
|
60
|
+
if (level === 'replaced' && timeline !== 'removals')
|
|
61
|
+
return _jsx(Fragment, { children: children }, number);
|
|
62
|
+
const variant = level === 'word' ? 'change'
|
|
63
|
+
: level === 'removed' ? 'change-removed'
|
|
64
|
+
: level === 'replaced' ? 'change-replaced'
|
|
65
|
+
: timeline === 'removals' ? 'change-added' : 'change-strong';
|
|
66
|
+
return (_jsx(Mark, { variant: variant, timeline: level === 'word' && timeline === 'removals' ? 'removals' : undefined, speed: speed, "data-change": level, children: children }, number));
|
|
67
|
+
}
|
|
68
|
+
const LEVELS = new Set(['word', 'letters', 'removed', 'replaced']);
|
|
69
|
+
/** The entries made, one per source. */
|
|
70
|
+
const made = new WeakMap();
|
|
71
|
+
/**
|
|
72
|
+
* The `ins` entry drawing the change marks with `source`'s state: an `ins` whose `data-change` is a
|
|
73
|
+
* change level is a `ChangeMark` with the switch's number, timeline and speed; any other `ins` is
|
|
74
|
+
* drawn as itself (react-markdown's `node` dropped). One frozen object per source, so its identity
|
|
75
|
+
* never changes: an app's Markdown memoises on its `components`.
|
|
76
|
+
*/
|
|
77
|
+
export function changeComponents(source) {
|
|
78
|
+
let components = made.get(source);
|
|
79
|
+
if (!components) {
|
|
80
|
+
const ins = ({ node, ...rest }) => {
|
|
81
|
+
const level = rest['data-change'];
|
|
82
|
+
return typeof level === 'string' && LEVELS.has(level)
|
|
83
|
+
? _jsx(LiveMark, { source: source, level: level, children: rest.children })
|
|
84
|
+
: _jsx("ins", { ...rest });
|
|
85
|
+
};
|
|
86
|
+
components = Object.freeze({ ins });
|
|
87
|
+
made.set(source, components);
|
|
88
|
+
}
|
|
89
|
+
return components;
|
|
90
|
+
}
|
|
91
|
+
// `useLayoutEffect` warns when it does nothing on the server; fall back to a plain effect there.
|
|
92
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
93
|
+
/**
|
|
94
|
+
* A `ChangeMark` drawn with `source`'s state as it reads it in render, re-drawn on its
|
|
95
|
+
* notifications alone (its parents are not re-rendered). It subscribes in a layout effect, not
|
|
96
|
+
* through `useSyncExternalStore`, which subscribes in the passive phase: the hook decides the
|
|
97
|
+
* timeline in its own layout effect, which runs after its children's, so the marks have subscribed
|
|
98
|
+
* by then and take it before the paint. At subscription it re-draws if the state changed since its
|
|
99
|
+
* render.
|
|
100
|
+
*/
|
|
101
|
+
function LiveMark({ source, level, children }) {
|
|
102
|
+
const [, redraw] = useReducer((count) => count + 1, 0);
|
|
103
|
+
const state = source.getSnapshot();
|
|
104
|
+
useIsomorphicLayoutEffect(() => {
|
|
105
|
+
const unsubscribe = source.subscribe(redraw);
|
|
106
|
+
// `state` is the one this effect's render read.
|
|
107
|
+
if (source.getSnapshot() !== state)
|
|
108
|
+
redraw();
|
|
109
|
+
return unsubscribe;
|
|
110
|
+
}, [source]);
|
|
111
|
+
return _jsx(ChangeMark, { level: level, number: state.number, timeline: state.timeline, speed: state.speed, children: children });
|
|
112
|
+
}
|
|
113
|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|
3
|
+
export interface ChangingTextProps {
|
|
4
|
+
/** The string's identity: same key, new string animates; a new key swaps plainly. */
|
|
5
|
+
changeKey: string;
|
|
6
|
+
/** `false`: swap plainly once, under the same key too. */
|
|
7
|
+
animate?: boolean;
|
|
8
|
+
/** How fast a switch's marks run (`useTextChanges`' `speed`): `normal` by default, held per switch. */
|
|
9
|
+
speed?: ChangeSpeed;
|
|
10
|
+
children: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A plain string whose changes light up: `useTextChanges` for one string, with its key
|
|
14
|
+
* semantics (`changeKey`, `animate`) and `speed`. Rendered as it is, with no wrapper (a Fragment):
|
|
15
|
+
* the string's text as strings, its change marks through the hook's `ins` entry. The string is read
|
|
16
|
+
* inside a private `span`, never rendered: a text right under the root counts as between blocks,
|
|
17
|
+
* and would never be marked.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ChangingText({ changeKey, animate, speed, children }: ChangingTextProps): ReactElement;
|
|
20
|
+
//# sourceMappingURL=ChangingText.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChangingText.d.ts","sourceRoot":"","sources":["../../src/changes/ChangingText.tsx"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAC;AAE7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGxD,MAAM,WAAW,iBAAiB;IAChC,qFAAqF;IACrF,SAAS,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,uGAAuG;IACvG,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,iBAAiB,GAAG,YAAY,CASrG"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, useMemo } from 'react';
|
|
3
|
+
import { useTextChanges } from './useTextChanges.js';
|
|
4
|
+
/**
|
|
5
|
+
* A plain string whose changes light up: `useTextChanges` for one string, with its key
|
|
6
|
+
* semantics (`changeKey`, `animate`) and `speed`. Rendered as it is, with no wrapper (a Fragment):
|
|
7
|
+
* the string's text as strings, its change marks through the hook's `ins` entry. The string is read
|
|
8
|
+
* inside a private `span`, never rendered: a text right under the root counts as between blocks,
|
|
9
|
+
* and would never be marked.
|
|
10
|
+
*/
|
|
11
|
+
export function ChangingText({ changeKey, animate, speed, children }) {
|
|
12
|
+
const { rehypePlugin, components } = useTextChanges(children, { key: changeKey, animate, speed });
|
|
13
|
+
const marked = useMemo(() => {
|
|
14
|
+
const span = { type: 'element', tagName: 'span', properties: {}, children: [{ type: 'text', value: children }] };
|
|
15
|
+
const tree = { type: 'root', children: [span] };
|
|
16
|
+
rehypePlugin()(tree);
|
|
17
|
+
return span.children;
|
|
18
|
+
}, [children, rehypePlugin]);
|
|
19
|
+
return _jsx(Fragment, { children: marked.map((node, i) => drawn(node, i, components)) });
|
|
20
|
+
}
|
|
21
|
+
/** A node of the marked string, keyed by `key`: a text as its value, an `ins` (a change mark)
|
|
22
|
+
* through `components`' entry, with its level and what it holds. */
|
|
23
|
+
function drawn(node, key, components) {
|
|
24
|
+
if (node.type === 'text')
|
|
25
|
+
return node.value;
|
|
26
|
+
if (node.type !== 'element')
|
|
27
|
+
return null;
|
|
28
|
+
const { ins: Ins } = components;
|
|
29
|
+
return (_jsx(Ins, { "data-change": String(node.properties.dataChange), children: node.children.map((child, i) => drawn(child, i, components)) }, key));
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=ChangingText.js.map
|