@velocity-astro/cms-admin 0.1.0-beta.5 → 0.1.0-beta.7
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/app-dist/assets/{RichTextEditor-3V2J98jv.js → RichTextEditor-BpltDhwX.js} +1 -1
- package/app-dist/assets/index-Bx7Xh90l.js +80 -0
- package/app-dist/assets/index-DLXIqdLb.css +2 -0
- package/app-dist/index.html +5 -3
- package/dist/app/AdminLayout.d.ts.map +1 -1
- package/dist/app/AdminLayout.js +1 -1
- package/dist/app/AdminLayout.js.map +1 -1
- package/dist/app/paths.d.ts +2 -0
- package/dist/app/paths.d.ts.map +1 -1
- package/dist/app/paths.js +2 -0
- package/dist/app/paths.js.map +1 -1
- package/dist/client/queries.d.ts.map +1 -1
- package/dist/client/queries.js +32 -7
- package/dist/client/queries.js.map +1 -1
- package/dist/fields/BlocksControl.d.ts +6 -0
- package/dist/fields/BlocksControl.d.ts.map +1 -1
- package/dist/fields/BlocksControl.js +332 -50
- package/dist/fields/BlocksControl.js.map +1 -1
- package/dist/fields/SiteImagePicker.d.ts +22 -0
- package/dist/fields/SiteImagePicker.d.ts.map +1 -0
- package/dist/fields/SiteImagePicker.js +42 -0
- package/dist/fields/SiteImagePicker.js.map +1 -0
- package/dist/fields/block-icons.d.ts.map +1 -1
- package/dist/fields/block-icons.js +3 -1
- package/dist/fields/block-icons.js.map +1 -1
- package/dist/fields/carry.d.ts +19 -0
- package/dist/fields/carry.d.ts.map +1 -0
- package/dist/fields/carry.js +61 -0
- package/dist/fields/carry.js.map +1 -0
- package/dist/fields/controls.d.ts.map +1 -1
- package/dist/fields/controls.js +82 -58
- package/dist/fields/controls.js.map +1 -1
- package/dist/fields/field-control.d.ts +80 -0
- package/dist/fields/field-control.d.ts.map +1 -1
- package/dist/fields/field-control.js.map +1 -1
- package/dist/fields/page-focus.d.ts +41 -0
- package/dist/fields/page-focus.d.ts.map +1 -1
- package/dist/fields/page-focus.js +70 -1
- package/dist/fields/page-focus.js.map +1 -1
- package/dist/lib/open-site.d.ts +6 -0
- package/dist/lib/open-site.d.ts.map +1 -0
- package/dist/lib/open-site.js +8 -0
- package/dist/lib/open-site.js.map +1 -0
- package/dist/lib/rich-from-html.d.ts +9 -0
- package/dist/lib/rich-from-html.d.ts.map +1 -0
- package/dist/lib/rich-from-html.js +129 -0
- package/dist/lib/rich-from-html.js.map +1 -0
- package/dist/lib/sittings.d.ts +16 -0
- package/dist/lib/sittings.d.ts.map +1 -0
- package/dist/lib/sittings.js +29 -0
- package/dist/lib/sittings.js.map +1 -0
- package/dist/lib/use-history.d.ts +24 -0
- package/dist/lib/use-history.d.ts.map +1 -0
- package/dist/lib/use-history.js +48 -0
- package/dist/lib/use-history.js.map +1 -0
- package/dist/lib/use-narrow.d.ts +5 -0
- package/dist/lib/use-narrow.d.ts.map +1 -0
- package/dist/lib/use-narrow.js +19 -0
- package/dist/lib/use-narrow.js.map +1 -0
- package/dist/lib/use-save-key.d.ts +15 -0
- package/dist/lib/use-save-key.d.ts.map +1 -0
- package/dist/lib/use-save-key.js +27 -0
- package/dist/lib/use-save-key.js.map +1 -0
- package/dist/lib/use-undo-keys.d.ts +14 -0
- package/dist/lib/use-undo-keys.d.ts.map +1 -0
- package/dist/lib/use-undo-keys.js +46 -0
- package/dist/lib/use-undo-keys.js.map +1 -0
- package/dist/messages/en.d.ts +36 -2
- package/dist/messages/en.d.ts.map +1 -1
- package/dist/messages/en.js +36 -2
- package/dist/messages/en.js.map +1 -1
- package/dist/page-bridge/preview-bridge.d.ts +3 -0
- package/dist/page-bridge/preview-bridge.d.ts.map +1 -1
- package/dist/page-bridge/preview-bridge.js +1086 -12
- package/dist/page-bridge/preview-bridge.js.map +1 -1
- package/dist/screens/Contact/ContactScreen.js +1 -1
- package/dist/screens/Contact/ContactScreen.js.map +1 -1
- package/dist/screens/Contacts/ContactsScreen.js +2 -2
- package/dist/screens/Contacts/ContactsScreen.js.map +1 -1
- package/dist/screens/ContentList/ContentListScreen.d.ts.map +1 -1
- package/dist/screens/ContentList/ContentListScreen.js +5 -2
- package/dist/screens/ContentList/ContentListScreen.js.map +1 -1
- package/dist/screens/ContentType/ContentTypeScreen.js +1 -1
- package/dist/screens/ContentType/ContentTypeScreen.js.map +1 -1
- package/dist/screens/EntryEditor/EntryEditorScreen.d.ts.map +1 -1
- package/dist/screens/EntryEditor/EntryEditorScreen.js +5 -3
- package/dist/screens/EntryEditor/EntryEditorScreen.js.map +1 -1
- package/dist/screens/EntryEditor/EntryForm.d.ts +2 -0
- package/dist/screens/EntryEditor/EntryForm.d.ts.map +1 -1
- package/dist/screens/EntryEditor/EntryForm.js +164 -19
- package/dist/screens/EntryEditor/EntryForm.js.map +1 -1
- package/dist/screens/EntryEditor/HistoryDialog.d.ts +2 -1
- package/dist/screens/EntryEditor/HistoryDialog.d.ts.map +1 -1
- package/dist/screens/EntryEditor/HistoryDialog.js +24 -5
- package/dist/screens/EntryEditor/HistoryDialog.js.map +1 -1
- package/dist/screens/EntryEditor/PagePane.d.ts +12 -2
- package/dist/screens/EntryEditor/PagePane.d.ts.map +1 -1
- package/dist/screens/EntryEditor/PagePane.js +53 -15
- package/dist/screens/EntryEditor/PagePane.js.map +1 -1
- package/dist/screens/EntryEditor/ThemeCard.d.ts +32 -0
- package/dist/screens/EntryEditor/ThemeCard.d.ts.map +1 -0
- package/dist/screens/EntryEditor/ThemeCard.js +67 -0
- package/dist/screens/EntryEditor/ThemeCard.js.map +1 -0
- package/dist/screens/Home/HomeScreen.d.ts.map +1 -1
- package/dist/screens/Home/HomeScreen.js +8 -3
- package/dist/screens/Home/HomeScreen.js.map +1 -1
- package/package.json +5 -5
- package/app-dist/assets/index-BvWFILf6.css +0 -2
- package/app-dist/assets/index-XV61GS8z.js +0 -80
|
@@ -38,6 +38,51 @@ export interface WordsPlace {
|
|
|
38
38
|
/** The value with these words at the place, or `undefined` when that leaves the field empty. */
|
|
39
39
|
readonly put: (words: string) => unknown;
|
|
40
40
|
}
|
|
41
|
+
/** One place in a value where a picture is held: the image's name there now, and how the value reads with another. */
|
|
42
|
+
export interface PicturePlace extends WordsPlace {
|
|
43
|
+
readonly name: string | null;
|
|
44
|
+
}
|
|
45
|
+
/** One place in a value where a link is held: the field it is a value of, the link there now, and how the value reads with another. */
|
|
46
|
+
export interface LinkPlace {
|
|
47
|
+
readonly place: string;
|
|
48
|
+
/** The field whose control changes the link: the field itself, or the one a group or a list holds there. */
|
|
49
|
+
readonly field: FieldDef;
|
|
50
|
+
readonly link: unknown;
|
|
51
|
+
/** The value with this link at the place, or `undefined` when that leaves the field empty. */
|
|
52
|
+
readonly put: (link: unknown) => unknown;
|
|
53
|
+
}
|
|
54
|
+
/** One place in a value where a list is held: its items now, whether it takes more, and how the value reads with other items. */
|
|
55
|
+
export interface ListPlace {
|
|
56
|
+
readonly place: string;
|
|
57
|
+
readonly items: readonly unknown[];
|
|
58
|
+
/** True when the list holds as many items as it may. */
|
|
59
|
+
readonly isFull: boolean;
|
|
60
|
+
/** The value with these items at the place, or `undefined` when that leaves the field empty. */
|
|
61
|
+
readonly put: (items: readonly unknown[]) => unknown;
|
|
62
|
+
}
|
|
63
|
+
/** One place in a value where a look is chosen among a few of the site's colours: the choices with a sample of each, and the one chosen. */
|
|
64
|
+
export interface SwatchPlace {
|
|
65
|
+
readonly place: string;
|
|
66
|
+
/** The field the choice is a value of, for its name. */
|
|
67
|
+
readonly field: FieldDef;
|
|
68
|
+
readonly choices: readonly {
|
|
69
|
+
readonly value: string;
|
|
70
|
+
readonly colour: string;
|
|
71
|
+
readonly name: (locale: string) => string;
|
|
72
|
+
}[];
|
|
73
|
+
readonly chosen: string | undefined;
|
|
74
|
+
/** The value with this choice at the place. */
|
|
75
|
+
readonly put: (value: string) => unknown;
|
|
76
|
+
}
|
|
77
|
+
/** One place in a value where sections are held: the field that says which blocks it takes, the sections there now, and how the value reads with others. */
|
|
78
|
+
export interface SectionsPlace {
|
|
79
|
+
readonly place: string;
|
|
80
|
+
readonly field: FieldDef;
|
|
81
|
+
readonly sections: readonly unknown[];
|
|
82
|
+
/** The value with these sections at the place, or `undefined` when that leaves the field empty. */
|
|
83
|
+
readonly put: (sections: readonly unknown[]) => unknown;
|
|
84
|
+
}
|
|
85
|
+
type ControlFor = (type: string) => FieldControl | undefined;
|
|
41
86
|
export interface FieldControl {
|
|
42
87
|
/** The editor name a field type asks for: `text-input`. */
|
|
43
88
|
readonly type: string;
|
|
@@ -69,6 +114,40 @@ export interface FieldControl {
|
|
|
69
114
|
* theirs (`controlFor`). Without it, the field is edited only in the form.
|
|
70
115
|
*/
|
|
71
116
|
readonly words?: (field: FieldDef, value: unknown, controlFor: (type: string) => FieldControl | undefined) => readonly WordsPlace[];
|
|
117
|
+
/**
|
|
118
|
+
* Where a value of this kind holds a picture of the site's: the places a picture can be changed
|
|
119
|
+
* from the page itself. A control that holds other fields asks theirs. Without it, the field is
|
|
120
|
+
* changed only in the form.
|
|
121
|
+
*/
|
|
122
|
+
readonly pictures?: (field: FieldDef, value: unknown, controlFor: ControlFor) => readonly PicturePlace[];
|
|
123
|
+
/**
|
|
124
|
+
* Where a value of this kind holds a link: the places a link or a button can be changed from
|
|
125
|
+
* the page itself, in a window that holds the control of the field there. A control that holds
|
|
126
|
+
* other fields asks theirs. Without it, the field is changed only in the form.
|
|
127
|
+
*/
|
|
128
|
+
readonly links?: (field: FieldDef, value: unknown, controlFor: ControlFor) => readonly LinkPlace[];
|
|
129
|
+
/**
|
|
130
|
+
* Where a value of this kind holds a list: the places whose items can be moved, copied and
|
|
131
|
+
* removed from the page itself. A list is its own place and asks its items for theirs.
|
|
132
|
+
*/
|
|
133
|
+
readonly lists?: (field: FieldDef, value: unknown, controlFor: ControlFor) => readonly ListPlace[];
|
|
134
|
+
/**
|
|
135
|
+
* Where a value of this kind is a choice among a few of the site's colours: the places a look
|
|
136
|
+
* (a section's background) can be chosen from the page itself, as swatches on the section's bar.
|
|
137
|
+
*/
|
|
138
|
+
readonly swatches?: (field: FieldDef, value: unknown, controlFor: ControlFor) => readonly SwatchPlace[];
|
|
139
|
+
/**
|
|
140
|
+
* Where a value of this kind holds sections of its own: the columns of a row. The field that
|
|
141
|
+
* holds the page answers to the page for those too. A control that holds other fields asks theirs.
|
|
142
|
+
*/
|
|
143
|
+
readonly sections?: (field: FieldDef, value: unknown, controlFor: ControlFor) => readonly SectionsPlace[];
|
|
144
|
+
/**
|
|
145
|
+
* A value of one field as another field of the same kind and keys holds it, where what a value
|
|
146
|
+
* is keyed by (the ids of a group's fields, of a block and its fields) differs between the two:
|
|
147
|
+
* a section moved from one column to another. `undefined` when it cannot be held there whole.
|
|
148
|
+
* Without it, a value is the same in both.
|
|
149
|
+
*/
|
|
150
|
+
readonly carried?: (from: FieldDef, to: FieldDef, value: unknown, controlFor: ControlFor) => unknown;
|
|
72
151
|
/** `end` when summaries are figures, so a column of them lines up. */
|
|
73
152
|
readonly summaryAlign?: 'start' | 'end';
|
|
74
153
|
}
|
|
@@ -82,4 +161,5 @@ export interface FieldControlsProviderProps {
|
|
|
82
161
|
export declare function FieldControlsProvider({ controls, children }: FieldControlsProviderProps): import("react").JSX.Element;
|
|
83
162
|
/** Every control the editor has. */
|
|
84
163
|
export declare function useFieldControls(): FieldControls;
|
|
164
|
+
export {};
|
|
85
165
|
//# sourceMappingURL=field-control.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-control.d.ts","sourceRoot":"","sources":["../../src/fields/field-control.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAA6B,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEtF,yCAAyC;AACzC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,kDAAkD;IAClD,QAAQ,CAAC,KAAK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AAK,SAAS,WAAW,EAAE,CAAC;IACxG;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,KAAK,SAAS,aAAa,EAAE,CAAC;IAC1G;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,KAAK,OAAO,CAAC;IACrG,sEAAsE;IACtE,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;CACzC;AAED,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;AAEnD,oDAAoD;AACpD,wBAAgB,0BAA0B,IAAI,aAAa,CAE1D;AAID,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;CAC9B;AAED,wBAAgB,qBAAqB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,0BAA0B,+BAEvF;AAED,oCAAoC;AACpC,wBAAgB,gBAAgB,IAAI,aAAa,CAIhD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-control.js","sourceRoot":"","sources":["../../src/fields/field-control.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAsC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"field-control.js","sourceRoot":"","sources":["../../src/fields/field-control.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAsC,MAAM,OAAO,CAAC;AAgKtF,oDAAoD;AACpD,MAAM,UAAU,0BAA0B;IACxC,OAAO,IAAI,QAAQ,CAAe,eAAe,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,oBAAoB,GAAG,aAAa,CAAuB,IAAI,CAAC,CAAC;AAOvE,MAAM,UAAU,qBAAqB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAA8B;IACtF,OAAO,KAAC,oBAAoB,IAAC,KAAK,EAAE,QAAQ,YAAG,QAAQ,GAAwB,CAAC;AAClF,CAAC;AAED,oCAAoC;AACpC,MAAM,UAAU,gBAAgB;IAC9B,MAAM,QAAQ,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAClD,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAAC;IACjH,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PageItemAction, PageSectionAction, PageSectionTools } from '@velocity-astro/cms-ui';
|
|
1
2
|
import { type ReactNode } from 'react';
|
|
2
3
|
/**
|
|
3
4
|
* Which section the form and the page beside it are both looking at. The page says which
|
|
@@ -29,11 +30,51 @@ export interface PageFocus {
|
|
|
29
30
|
readonly typed: (id: string, field: string, words: string) => void;
|
|
30
31
|
/** Listens to what is typed on the page. Answers with how to stop. */
|
|
31
32
|
readonly onTyped: (listener: TypedListener) => () => void;
|
|
33
|
+
/** What the page may offer on each section (move, copy, remove, add beside it). The form says so, since it holds the sections. */
|
|
34
|
+
readonly tools: PageSectionTools | undefined;
|
|
35
|
+
readonly setTools: (tools: PageSectionTools | undefined) => void;
|
|
36
|
+
/** The page says a section's button was pressed; whoever listens makes the change. */
|
|
37
|
+
readonly acted: (id: string, action: PageSectionAction) => void;
|
|
38
|
+
readonly onActed: (listener: ActedListener) => () => void;
|
|
39
|
+
/** The page says a section was dragged to before another, or to the end (`null`). */
|
|
40
|
+
readonly dragged: DraggedListener;
|
|
41
|
+
readonly onDragged: (listener: DraggedListener) => () => void;
|
|
42
|
+
/** The page says the button on a picture was pressed: the section, and the picture's field as keys. */
|
|
43
|
+
readonly pictured: (id: string, field: string) => void;
|
|
44
|
+
readonly onPictured: (listener: PicturedListener) => () => void;
|
|
45
|
+
/** The page says the button on a link was pressed: the section, and the link's field as keys. */
|
|
46
|
+
readonly linked: (id: string, field: string) => void;
|
|
47
|
+
readonly onLinked: (listener: PicturedListener) => () => void;
|
|
48
|
+
/** The page says a button on an item of a list was pressed: the section, the list's field as keys, the item's place and what to do. */
|
|
49
|
+
readonly itemActed: ItemListener;
|
|
50
|
+
readonly onItemActed: (listener: ItemListener) => () => void;
|
|
51
|
+
/** The page says a swatch on a section's bar was pressed: the section, the field as keys and the choice. */
|
|
52
|
+
readonly swatched: SwatchListener;
|
|
53
|
+
readonly onSwatched: (listener: SwatchListener) => () => void;
|
|
54
|
+
/** The page says the button of an empty place inside a section was pressed: the section, and the place's field as keys. */
|
|
55
|
+
readonly slotted: PicturedListener;
|
|
56
|
+
readonly onSlotted: (listener: PicturedListener) => () => void;
|
|
57
|
+
/** True for sections inside a section, which the field that holds the page answers for. */
|
|
58
|
+
readonly isInside?: boolean;
|
|
32
59
|
}
|
|
60
|
+
export type SwatchListener = (id: string, field: string, value: string) => void;
|
|
61
|
+
export type ItemListener = (id: string, field: string, at: number, action: PageItemAction) => void;
|
|
62
|
+
export type PicturedListener = (id: string, field: string) => void;
|
|
63
|
+
/** `into` names the place inside a section it was let go in, where that is not the place it was in. */
|
|
64
|
+
export type DraggedListener = (id: string, beforeId: string | null, into?: string) => void;
|
|
65
|
+
export type ActedListener = (id: string, action: PageSectionAction) => void;
|
|
33
66
|
export type TypedListener = (id: string, field: string, words: string) => void;
|
|
34
67
|
export declare function PageFocusProvider({ children }: {
|
|
35
68
|
readonly children: ReactNode;
|
|
36
69
|
}): import("react").JSX.Element;
|
|
37
70
|
/** The focus shared with the page beside the form, or nothing when no page is shown. */
|
|
38
71
|
export declare function usePageFocus(): PageFocus | null;
|
|
72
|
+
/**
|
|
73
|
+
* The focus as the sections inside a section see it. They open what is pressed on the page and
|
|
74
|
+
* say what was opened, and nothing more: the field that holds the whole page answers for every
|
|
75
|
+
* section in it, however deep, so nothing is done twice.
|
|
76
|
+
*/
|
|
77
|
+
export declare function PageFocusInside({ children }: {
|
|
78
|
+
readonly children: ReactNode;
|
|
79
|
+
}): import("react").JSX.Element;
|
|
39
80
|
//# sourceMappingURL=page-focus.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-focus.d.ts","sourceRoot":"","sources":["../../src/fields/page-focus.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAwD,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE7F;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IACpG,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACrD,2CAA2C;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;IAC9D,QAAQ,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC;IACnF,uGAAuG;IACvG,QAAQ,CAAC,KAAK,EAAE,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I,CAE/C;AAID;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,+BAqB7E"}
|
|
@@ -7,6 +7,14 @@ export function PageFocusProvider({ children }) {
|
|
|
7
7
|
const [opened, setOpened] = useState(undefined);
|
|
8
8
|
const [typable, setPlaces] = useState(NOWHERE);
|
|
9
9
|
const listeners = useRef(new Set());
|
|
10
|
+
const [tools, setOffered] = useState(undefined);
|
|
11
|
+
const acting = useRef(new Set());
|
|
12
|
+
const dragging = useRef(new Set());
|
|
13
|
+
const picturing = useRef(new Set());
|
|
14
|
+
const linking = useRef(new Set());
|
|
15
|
+
const itemActing = useRef(new Set());
|
|
16
|
+
const swatching = useRef(new Set());
|
|
17
|
+
const slotting = useRef(new Set());
|
|
10
18
|
const focus = useMemo(() => ({
|
|
11
19
|
pressed,
|
|
12
20
|
press: (id, field) => setPressed((last) => ({ id, ...(field !== undefined && { field }), at: (last?.at ?? 0) + 1 })),
|
|
@@ -20,11 +28,72 @@ export function PageFocusProvider({ children }) {
|
|
|
20
28
|
listeners.current.add(listener);
|
|
21
29
|
return () => void listeners.current.delete(listener);
|
|
22
30
|
},
|
|
23
|
-
|
|
31
|
+
tools,
|
|
32
|
+
setTools: (next) => setOffered((last) => (JSON.stringify(last) === JSON.stringify(next) ? last : next)),
|
|
33
|
+
acted: (id, action) => acting.current.forEach((listener) => listener(id, action)),
|
|
34
|
+
onActed: (listener) => {
|
|
35
|
+
acting.current.add(listener);
|
|
36
|
+
return () => void acting.current.delete(listener);
|
|
37
|
+
},
|
|
38
|
+
dragged: (id, beforeId, into) => dragging.current.forEach((listener) => listener(id, beforeId, into)),
|
|
39
|
+
onDragged: (listener) => {
|
|
40
|
+
dragging.current.add(listener);
|
|
41
|
+
return () => void dragging.current.delete(listener);
|
|
42
|
+
},
|
|
43
|
+
pictured: (id, field) => picturing.current.forEach((listener) => listener(id, field)),
|
|
44
|
+
onPictured: (listener) => {
|
|
45
|
+
picturing.current.add(listener);
|
|
46
|
+
return () => void picturing.current.delete(listener);
|
|
47
|
+
},
|
|
48
|
+
linked: (id, field) => linking.current.forEach((listener) => listener(id, field)),
|
|
49
|
+
onLinked: (listener) => {
|
|
50
|
+
linking.current.add(listener);
|
|
51
|
+
return () => void linking.current.delete(listener);
|
|
52
|
+
},
|
|
53
|
+
itemActed: (id, field, at, action) => itemActing.current.forEach((listener) => listener(id, field, at, action)),
|
|
54
|
+
onItemActed: (listener) => {
|
|
55
|
+
itemActing.current.add(listener);
|
|
56
|
+
return () => void itemActing.current.delete(listener);
|
|
57
|
+
},
|
|
58
|
+
swatched: (id, field, value) => swatching.current.forEach((listener) => listener(id, field, value)),
|
|
59
|
+
onSwatched: (listener) => {
|
|
60
|
+
swatching.current.add(listener);
|
|
61
|
+
return () => void swatching.current.delete(listener);
|
|
62
|
+
},
|
|
63
|
+
slotted: (id, field) => slotting.current.forEach((listener) => listener(id, field)),
|
|
64
|
+
onSlotted: (listener) => {
|
|
65
|
+
slotting.current.add(listener);
|
|
66
|
+
return () => void slotting.current.delete(listener);
|
|
67
|
+
},
|
|
68
|
+
}), [pressed, opened, typable, tools]);
|
|
24
69
|
return _jsx(PageFocusContext, { value: focus, children: children });
|
|
25
70
|
}
|
|
26
71
|
/** The focus shared with the page beside the form, or nothing when no page is shown. */
|
|
27
72
|
export function usePageFocus() {
|
|
28
73
|
return useContext(PageFocusContext);
|
|
29
74
|
}
|
|
75
|
+
const unheard = () => () => undefined;
|
|
76
|
+
/**
|
|
77
|
+
* The focus as the sections inside a section see it. They open what is pressed on the page and
|
|
78
|
+
* say what was opened, and nothing more: the field that holds the whole page answers for every
|
|
79
|
+
* section in it, however deep, so nothing is done twice.
|
|
80
|
+
*/
|
|
81
|
+
export function PageFocusInside({ children }) {
|
|
82
|
+
const focus = useContext(PageFocusContext);
|
|
83
|
+
const inside = useMemo(() => focus && {
|
|
84
|
+
...focus,
|
|
85
|
+
setTypable: () => undefined,
|
|
86
|
+
setTools: () => undefined,
|
|
87
|
+
onTyped: unheard,
|
|
88
|
+
onActed: unheard,
|
|
89
|
+
onDragged: unheard,
|
|
90
|
+
onPictured: unheard,
|
|
91
|
+
onLinked: unheard,
|
|
92
|
+
onItemActed: unheard,
|
|
93
|
+
onSwatched: unheard,
|
|
94
|
+
onSlotted: unheard,
|
|
95
|
+
isInside: true,
|
|
96
|
+
}, [focus]);
|
|
97
|
+
return _jsx(PageFocusContext, { value: inside, children: children });
|
|
98
|
+
}
|
|
30
99
|
//# sourceMappingURL=page-focus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-focus.js","sourceRoot":"","sources":["../../src/fields/page-focus.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"page-focus.js","sourceRoot":"","sources":["../../src/fields/page-focus.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAqE7F,MAAM,OAAO,GAAgD,EAAE,CAAC;AAEhE,MAAM,gBAAgB,GAAG,aAAa,CAAmB,IAAI,CAAC,CAAC;AAE/D,MAAM,UAAU,iBAAiB,CAAC,EAAE,QAAQ,EAAoC;IAC9E,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAuB,SAAS,CAAC,CAAC;IACxE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAqB,SAAS,CAAC,CAAC;IACpE,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC/C,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,GAAG,EAAiB,CAAC,CAAC;IACnD,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,QAAQ,CAA+B,SAAS,CAAC,CAAC;IAC9E,MAAM,MAAM,GAAG,MAAM,CAA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AC,gBAAgB,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,OAAO,CACpB,GAAG,EAAE,CACH,KAAK,IAAI;QACP,GAAG,KAAK;QACR,UAAU,EAAE,GAAG,EAAE,CAAC,SAAS;QAC3B,QAAQ,EAAE,GAAG,EAAE,CAAC,SAAS;QACzB,OAAO,EAAE,OAAO;QAChB,OAAO,EAAE,OAAO;QAChB,SAAS,EAAE,OAAO;QAClB,UAAU,EAAE,OAAO;QACnB,QAAQ,EAAE,OAAO;QACjB,WAAW,EAAE,OAAO;QACpB,UAAU,EAAE,OAAO;QACnB,SAAS,EAAE,OAAO;QAClB,QAAQ,EAAE,IAAI;KACf,EACH,CAAC,KAAK,CAAC,CACR,CAAC;IACF,OAAO,KAAC,gBAAgB,IAAC,KAAK,EAAE,MAAM,YAAG,QAAQ,GAAoB,CAAC;AACxE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-site.d.ts","sourceRoot":"","sources":["../../src/lib/open-site.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,OAAO,SAAM,GAAG,IAAI,CAE5C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opens a page of the site itself, as visitors see it, in a new tab. The editor's own links stay
|
|
3
|
+
* inside the editor, so the site is reached from its top.
|
|
4
|
+
*/
|
|
5
|
+
export function openSite(address = '/') {
|
|
6
|
+
window.open(new URL(address, window.location.origin).href, '_blank', 'noopener');
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=open-site.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-site.js","sourceRoot":"","sources":["../../src/lib/open-site.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAO,GAAG,GAAG;IACpC,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type RichText } from '@velocity-astro/cms-core';
|
|
2
|
+
/**
|
|
3
|
+
* Text written on a page of the site, as the formatted text a field holds. Only what the format
|
|
4
|
+
* keeps comes through: paragraphs, headings, lists, quotes, bold, italics, line breaks and links
|
|
5
|
+
* to where a site may link. Any other markup is dropped and its words kept. Nothing to read is
|
|
6
|
+
* `undefined`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function richTextFromHtml(html: string): RichText | undefined;
|
|
9
|
+
//# sourceMappingURL=rich-from-html.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rich-from-html.d.ts","sourceRoot":"","sources":["../../src/lib/rich-from-html.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,QAAQ,EAAqF,MAAM,0BAA0B,CAAC;AAuGxJ;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAMnE"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { isSafeLink } from '@velocity-astro/cms-core';
|
|
2
|
+
/** What starts a line of its own. Anything else is part of the line it is in. */
|
|
3
|
+
const BLOCKS = new Set(['P', 'DIV', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'BLOCKQUOTE', 'UL', 'OL', 'LI']);
|
|
4
|
+
const isElement = (node) => node.nodeType === 1;
|
|
5
|
+
const isBlock = (node) => isElement(node) && BLOCKS.has(node.tagName);
|
|
6
|
+
/** The marks an element puts on the words inside it, before those of what is around it: the first is the innermost. */
|
|
7
|
+
function marked(element, marks) {
|
|
8
|
+
const has = (type) => marks.some((mark) => mark.type === type);
|
|
9
|
+
if ((element.tagName === 'B' || element.tagName === 'STRONG') && !has('bold'))
|
|
10
|
+
return [{ type: 'bold' }, ...marks];
|
|
11
|
+
if ((element.tagName === 'I' || element.tagName === 'EM') && !has('italic'))
|
|
12
|
+
return [{ type: 'italic' }, ...marks];
|
|
13
|
+
const href = element.tagName === 'A' ? (element.getAttribute('href') ?? '').trim() : '';
|
|
14
|
+
if (href !== '' && isSafeLink(href) && !has('link'))
|
|
15
|
+
return [{ type: 'link', attrs: { href } }, ...marks];
|
|
16
|
+
return marks;
|
|
17
|
+
}
|
|
18
|
+
/** The words and line breaks of one line, each with the marks of everything around it. */
|
|
19
|
+
function inlines(nodes, marks = []) {
|
|
20
|
+
const found = [];
|
|
21
|
+
for (const node of nodes) {
|
|
22
|
+
if (node.nodeType === 3) {
|
|
23
|
+
// A line of the page's own markup is a space, as a browser shows it.
|
|
24
|
+
const text = (node.nodeValue ?? '').replace(/[\t\n\r ]+/g, ' ');
|
|
25
|
+
if (text !== '')
|
|
26
|
+
found.push(marks.length > 0 ? { type: 'text', text, marks } : { type: 'text', text });
|
|
27
|
+
}
|
|
28
|
+
else if (isElement(node)) {
|
|
29
|
+
if (node.tagName === 'BR')
|
|
30
|
+
found.push({ type: 'hardBreak' });
|
|
31
|
+
else
|
|
32
|
+
found.push(...inlines(node.childNodes, marked(node, marks)));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return found;
|
|
36
|
+
}
|
|
37
|
+
/** A line without the space around it and the break a browser keeps at the end of an empty one. */
|
|
38
|
+
function line(parts) {
|
|
39
|
+
// Words that follow each other with the same marks are one run, as the editor keeps them.
|
|
40
|
+
const kept = [];
|
|
41
|
+
for (const part of parts) {
|
|
42
|
+
const last = kept.at(-1);
|
|
43
|
+
if (part.type === 'text' && last?.type === 'text' && JSON.stringify(last.marks ?? []) === JSON.stringify(part.marks ?? []))
|
|
44
|
+
kept.splice(-1, 1, { ...last, text: `${last.text}${part.text}`.replace(/ {2,}/g, ' ') });
|
|
45
|
+
else
|
|
46
|
+
kept.push(part);
|
|
47
|
+
}
|
|
48
|
+
while (kept.at(-1)?.type === 'hardBreak')
|
|
49
|
+
kept.pop();
|
|
50
|
+
const trim = (at, how) => {
|
|
51
|
+
const part = kept.at(at);
|
|
52
|
+
if (part?.type !== 'text')
|
|
53
|
+
return;
|
|
54
|
+
const text = how(part.text);
|
|
55
|
+
if (text === '')
|
|
56
|
+
kept.splice(at, 1);
|
|
57
|
+
else
|
|
58
|
+
kept.splice(at, 1, { ...part, text });
|
|
59
|
+
};
|
|
60
|
+
trim(0, (text) => text.replace(/^ +/, ''));
|
|
61
|
+
trim(-1, (text) => text.replace(/ +$/, ''));
|
|
62
|
+
return kept.length > 0 ? kept : undefined;
|
|
63
|
+
}
|
|
64
|
+
const paragraph = (parts) => {
|
|
65
|
+
const content = line(parts);
|
|
66
|
+
return content ? { type: 'paragraph', content } : { type: 'paragraph' };
|
|
67
|
+
};
|
|
68
|
+
function blocks(nodes) {
|
|
69
|
+
const found = [];
|
|
70
|
+
// Words that stand outside any paragraph are a paragraph of their own.
|
|
71
|
+
let loose = [];
|
|
72
|
+
const flush = () => {
|
|
73
|
+
const content = line(inlines(loose));
|
|
74
|
+
if (content)
|
|
75
|
+
found.push({ type: 'paragraph', content });
|
|
76
|
+
loose = [];
|
|
77
|
+
};
|
|
78
|
+
for (const node of nodes) {
|
|
79
|
+
if (!isBlock(node)) {
|
|
80
|
+
loose.push(node);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
flush();
|
|
84
|
+
const tag = node.tagName;
|
|
85
|
+
const holdsBlocks = [...node.childNodes].some(isBlock);
|
|
86
|
+
if (tag === 'UL' || tag === 'OL') {
|
|
87
|
+
const items = [...node.children]
|
|
88
|
+
.filter((child) => child.tagName === 'LI')
|
|
89
|
+
.map((item) => ({ type: 'listItem', content: within(item) }));
|
|
90
|
+
if (items.length > 0)
|
|
91
|
+
found.push({ type: tag === 'UL' ? 'bulletList' : 'orderedList', content: items });
|
|
92
|
+
}
|
|
93
|
+
else if (tag === 'BLOCKQUOTE') {
|
|
94
|
+
found.push({ type: 'blockquote', content: within(node) });
|
|
95
|
+
}
|
|
96
|
+
else if (holdsBlocks) {
|
|
97
|
+
found.push(...blocks(node.childNodes));
|
|
98
|
+
}
|
|
99
|
+
else if (/^H[1-6]$/.test(tag)) {
|
|
100
|
+
const content = line(inlines(node.childNodes));
|
|
101
|
+
found.push({ type: 'heading', attrs: { level: tag === 'H1' || tag === 'H2' ? 2 : 3 }, ...(content && { content }) });
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
found.push(paragraph(inlines(node.childNodes)));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
flush();
|
|
108
|
+
return found;
|
|
109
|
+
}
|
|
110
|
+
/** What a quote or an item of a list holds: always at least a line, as the format asks. */
|
|
111
|
+
function within(element) {
|
|
112
|
+
const found = blocks(element.childNodes);
|
|
113
|
+
return found.length > 0 ? found : [{ type: 'paragraph' }];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Text written on a page of the site, as the formatted text a field holds. Only what the format
|
|
117
|
+
* keeps comes through: paragraphs, headings, lists, quotes, bold, italics, line breaks and links
|
|
118
|
+
* to where a site may link. Any other markup is dropped and its words kept. Nothing to read is
|
|
119
|
+
* `undefined`.
|
|
120
|
+
*/
|
|
121
|
+
export function richTextFromHtml(html) {
|
|
122
|
+
const parsed = new DOMParser().parseFromString(`<!doctype html><body>${html}`, 'text/html');
|
|
123
|
+
const content = blocks(parsed.body.childNodes);
|
|
124
|
+
// An empty line at the end is where the caret was, not something written.
|
|
125
|
+
while (content.at(-1)?.type === 'paragraph' && content.at(-1).content === undefined)
|
|
126
|
+
content.pop();
|
|
127
|
+
return content.length > 0 ? { type: 'doc', content } : undefined;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=rich-from-html.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rich-from-html.js","sourceRoot":"","sources":["../../src/lib/rich-from-html.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAoG,MAAM,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0 +1,16 @@
|
|
|
1
|
+
import type { Revision } from '@velocity-astro/cms-core';
|
|
2
|
+
/** Saves by one person that follow each other this closely are one sitting, in milliseconds. */
|
|
3
|
+
export declare const SITTING_PAUSE_MS: number;
|
|
4
|
+
/** Saves made in one go: the latest, which stands for them, and those before it, the latest first. */
|
|
5
|
+
export interface Sitting {
|
|
6
|
+
readonly latest: Revision;
|
|
7
|
+
readonly earlier: readonly Revision[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Folds a history, the latest first, into sittings. A draft saves itself every few seconds of
|
|
11
|
+
* work, and a list of every one of those hides the saves that matter. Saves are one sitting when
|
|
12
|
+
* one person made them, none waited long after the one before, and none changed whether the entry
|
|
13
|
+
* is on the site. The save visitors see (`onSite`) always stands by itself.
|
|
14
|
+
*/
|
|
15
|
+
export declare function sittings(revisions: readonly Revision[], onSite?: number): Sitting[];
|
|
16
|
+
//# sourceMappingURL=sittings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sittings.d.ts","sourceRoot":"","sources":["../../src/lib/sittings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,gGAAgG;AAChG,eAAO,MAAM,gBAAgB,QAAc,CAAC;AAE5C,sGAAsG;AACtG,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,CAAC;CACvC;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,EAAE,CAkBnF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Saves by one person that follow each other this closely are one sitting, in milliseconds. */
|
|
2
|
+
export const SITTING_PAUSE_MS = 10 * 60_000;
|
|
3
|
+
/**
|
|
4
|
+
* Folds a history, the latest first, into sittings. A draft saves itself every few seconds of
|
|
5
|
+
* work, and a list of every one of those hides the saves that matter. Saves are one sitting when
|
|
6
|
+
* one person made them, none waited long after the one before, and none changed whether the entry
|
|
7
|
+
* is on the site. The save visitors see (`onSite`) always stands by itself.
|
|
8
|
+
*/
|
|
9
|
+
export function sittings(revisions, onSite) {
|
|
10
|
+
const folded = [];
|
|
11
|
+
let after;
|
|
12
|
+
for (const revision of revisions) {
|
|
13
|
+
const open = folded.at(-1);
|
|
14
|
+
const joins = open !== undefined &&
|
|
15
|
+
after !== undefined &&
|
|
16
|
+
after.actorId === revision.actorId &&
|
|
17
|
+
after.status === revision.status &&
|
|
18
|
+
after.revision !== onSite &&
|
|
19
|
+
revision.revision !== onSite &&
|
|
20
|
+
Date.parse(after.createdAt) - Date.parse(revision.createdAt) < SITTING_PAUSE_MS;
|
|
21
|
+
if (joins)
|
|
22
|
+
open.earlier.push(revision);
|
|
23
|
+
else
|
|
24
|
+
folded.push({ latest: revision, earlier: [] });
|
|
25
|
+
after = revision;
|
|
26
|
+
}
|
|
27
|
+
return folded;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=sittings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sittings.js","sourceRoot":"","sources":["../../src/lib/sittings.ts"],"names":[],"mappings":"AAEA,gGAAgG;AAChG,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,GAAG,MAAM,CAAC;AAQ5C;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,SAA8B,EAAE,MAAe;IACtE,MAAM,MAAM,GAAgD,EAAE,CAAC;IAC/D,IAAI,KAA2B,CAAC;IAChC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3B,MAAM,KAAK,GACT,IAAI,KAAK,SAAS;YAClB,KAAK,KAAK,SAAS;YACnB,KAAK,CAAC,OAAO,KAAK,QAAQ,CAAC,OAAO;YAClC,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM;YAChC,KAAK,CAAC,QAAQ,KAAK,MAAM;YACzB,QAAQ,CAAC,QAAQ,KAAK,MAAM;YAC5B,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,gBAAgB,CAAC;QAClF,IAAI,KAAK;YAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;;YAClC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;QACpD,KAAK,GAAG,QAAQ,CAAC;IACnB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Changes of one thing that follow each other this closely are one step: a word, not a letter. */
|
|
2
|
+
export declare const STEP_PAUSE_MS = 700;
|
|
3
|
+
/** How many steps back are kept. */
|
|
4
|
+
export declare const STEPS_KEPT = 100;
|
|
5
|
+
/** A value and the steps that led to it, so a change can be taken back and made again. */
|
|
6
|
+
export interface History<T> {
|
|
7
|
+
readonly value: T;
|
|
8
|
+
/** Changes the value. Changes with the same `mark` that follow each other closely are one step. */
|
|
9
|
+
readonly set: (next: (current: T) => T, mark?: string) => void;
|
|
10
|
+
/** Takes a value as what is held now without a step: what the server made of a save. */
|
|
11
|
+
readonly settle: (value: T) => void;
|
|
12
|
+
/** Starts again from a value, with nothing to take back. */
|
|
13
|
+
readonly restart: (value: T) => void;
|
|
14
|
+
readonly undo: () => void;
|
|
15
|
+
readonly redo: () => void;
|
|
16
|
+
readonly canUndo: boolean;
|
|
17
|
+
readonly canRedo: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Holds a value with its steps, in memory only. A change that leaves the value as it was (by
|
|
21
|
+
* `same`) is no step, and a change after going back drops what was ahead.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useHistory<T extends object>(start: T, same: (a: T, b: T) => boolean): History<T>;
|
|
24
|
+
//# sourceMappingURL=use-history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-history.d.ts","sourceRoot":"","sources":["../../src/lib/use-history.ts"],"names":[],"mappings":"AAEA,mGAAmG;AACnG,eAAO,MAAM,aAAa,MAAM,CAAC;AAEjC,oCAAoC;AACpC,eAAO,MAAM,UAAU,MAAM,CAAC;AAyC9B,0FAA0F;AAC1F,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,mGAAmG;IACnG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/D,wFAAwF;IACxF,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACpC,4DAA4D;IAC5D,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAQhG"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useCallback, useReducer } from 'react';
|
|
2
|
+
/** Changes of one thing that follow each other this closely are one step: a word, not a letter. */
|
|
3
|
+
export const STEP_PAUSE_MS = 700;
|
|
4
|
+
/** How many steps back are kept. */
|
|
5
|
+
export const STEPS_KEPT = 100;
|
|
6
|
+
function steps(state, said) {
|
|
7
|
+
if (said.type === 'set') {
|
|
8
|
+
const value = said.next(state.present);
|
|
9
|
+
if (said.same(value, state.present))
|
|
10
|
+
return state;
|
|
11
|
+
const joins = said.mark !== undefined && said.mark === state.mark && said.at - state.at < STEP_PAUSE_MS && state.past.length > 0;
|
|
12
|
+
return {
|
|
13
|
+
past: joins ? state.past : [...state.past, state.present].slice(-STEPS_KEPT),
|
|
14
|
+
present: value,
|
|
15
|
+
future: [],
|
|
16
|
+
mark: said.mark,
|
|
17
|
+
at: said.at,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (said.type === 'settle')
|
|
21
|
+
return { ...state, present: said.value, mark: undefined };
|
|
22
|
+
if (said.type === 'restart')
|
|
23
|
+
return { past: [], present: said.value, future: [], mark: undefined, at: 0 };
|
|
24
|
+
if (said.type === 'undo') {
|
|
25
|
+
const last = state.past.at(-1);
|
|
26
|
+
if (last === undefined)
|
|
27
|
+
return state;
|
|
28
|
+
return { past: state.past.slice(0, -1), present: last, future: [state.present, ...state.future], mark: undefined, at: 0 };
|
|
29
|
+
}
|
|
30
|
+
const [next, ...future] = state.future;
|
|
31
|
+
if (next === undefined)
|
|
32
|
+
return state;
|
|
33
|
+
return { past: [...state.past, state.present], present: next, future, mark: undefined, at: 0 };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Holds a value with its steps, in memory only. A change that leaves the value as it was (by
|
|
37
|
+
* `same`) is no step, and a change after going back drops what was ahead.
|
|
38
|
+
*/
|
|
39
|
+
export function useHistory(start, same) {
|
|
40
|
+
const [state, say] = useReducer((steps), { past: [], present: start, future: [], mark: undefined, at: 0 });
|
|
41
|
+
const set = useCallback((next, mark) => say({ type: 'set', next, mark, at: Date.now(), same }), [same]);
|
|
42
|
+
const settle = useCallback((value) => say({ type: 'settle', value }), []);
|
|
43
|
+
const restart = useCallback((value) => say({ type: 'restart', value }), []);
|
|
44
|
+
const undo = useCallback(() => say({ type: 'undo' }), []);
|
|
45
|
+
const redo = useCallback(() => say({ type: 'redo' }), []);
|
|
46
|
+
return { value: state.present, set, settle, restart, undo, redo, canUndo: state.past.length > 0, canRedo: state.future.length > 0 };
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=use-history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-history.js","sourceRoot":"","sources":["../../src/lib/use-history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEhD,mGAAmG;AACnG,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC;AAEjC,oCAAoC;AACpC,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC;AAgB9B,SAAS,KAAK,CAAI,KAAe,EAAE,IAAa;IAC9C,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACvC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC;YAAE,OAAO,KAAK,CAAC;QAClD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,GAAG,aAAa,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QACjI,OAAO;YACL,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,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