@gramps-connect/story 0.1.2 → 0.2.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/README.md CHANGED
@@ -13,6 +13,11 @@ writes them and presents them with this package's player.
13
13
  **https://dsblank.github.io/gramps-connect-stories/**. Pick or drop a
14
14
  `.story.zip`, or link to one with `?src=<url>`; `#s3` opens a slide.
15
15
  Everything happens in the browser: an opened story is never uploaded.
16
+ - **Change a story, or make one:** the Story Editor, at
17
+ **https://dsblank.github.io/gramps-connect-stories/edit.html** (or
18
+ **Edit** on an open story in the viewer). Titles, dates, text and the
19
+ order of slides; it saves a new `.story.zip`, back into the opened file
20
+ in Chrome and Edge. Also entirely in the browser.
16
21
  - **Put a story on a web page:** the [`<gramps-connect-story>`](#on-any-web-page-gramps-connect-story)
17
22
  element.
18
23
  - **Format specification:** [`spec/1.0/README.md`](spec/1.0/README.md)
@@ -125,6 +130,8 @@ It fills its container. Props:
125
130
  | `keyboard` | Arrow keys change slides: `true` (default) anywhere on the page, `"focus"` only while the player has focus, `false` never. Swiping on a slide always works. |
126
131
  | `onSlideChange(index)` | Called whenever the slide changes. |
127
132
  | `initialSlide` | The slide to open on. |
133
+ | `brand` | Shown before the title, e.g. `ViewerBrand`. |
134
+ | `actions` | Your own buttons, at the right of the title bar. |
128
135
  | `renderMapModeControl` | Replaces the built-in map-mode control with your own, given the same props. |
129
136
 
130
137
  Peer dependencies: `react`, `react-dom` and `maplibre-gl` (5 or later),
@@ -132,6 +139,46 @@ needed only by the player. With TypeScript 6 or later, add `"geojson"` to
132
139
  `compilerOptions.types`: maplibre's own declarations use its global
133
140
  `GeoJSON` namespace.
134
141
 
142
+ ## The editor: `@gramps-connect/story/editor`
143
+
144
+ A React component that edits a story document: the slides on the left
145
+ (drag to reorder), the selected slide's title, date and text in the
146
+ middle, and the player on the right showing it as it changes, with undo
147
+ and redo and the format's validation as you go. It edits the document;
148
+ opening and saving files is up to you (the Story Editor page uses the File
149
+ System Access API where there is one, a download where not).
150
+
151
+ ```tsx
152
+ import "@mantine/core/styles.css";
153
+ import { MantineProvider } from "@mantine/core";
154
+ import { StoryEditor, pruneMedia } from "@gramps-connect/story/editor";
155
+ import { writeStoryZip } from "@gramps-connect/story";
156
+
157
+ let latest = story.doc;
158
+ <MantineProvider>
159
+ <StoryEditor initialStory={story.doc} files={story.files} resolveMedia={resolveMedia} onChange={(doc) => (latest = doc)} />
160
+ </MantineProvider>
161
+
162
+ // Saving: leave out media nothing uses any more, then zip.
163
+ const saved = pruneMedia(latest, story.files);
164
+ const zip = await writeStoryZip(saved.doc, saved.files);
165
+ ```
166
+
167
+ A date is typed as readers should see it ("about 1850", "um 1850"), and its
168
+ precise form (EDTF, for the timeline and historical maps) is worked out
169
+ from it, in the story's language, by
170
+ [`@gramps-connect/gramps-date`](https://www.npmjs.com/package/@gramps-connect/gramps-date):
171
+ Gramps' own date parser, in all of Gramps' languages. Pass
172
+ `parseDateText` to use another. Fields the editor doesn't know are kept as
173
+ they are, so opening and saving a story never loses anything.
174
+
175
+ The editor is built with [Mantine](https://mantine.dev) 8 (optional peer
176
+ dependencies `@mantine/core` and `@mantine/hooks`, needed only by the
177
+ editor): wrap it in a `MantineProvider` and load Mantine's stylesheet. The
178
+ pieces it's made of (`SlideList`, `StoryTextField`, `DateField`) and its
179
+ editing functions (`addSlide`, `moveSlide`, `updateSlide`, undo history,
180
+ ...) are exported too.
181
+
135
182
  ## Writing stories from Python: `python/gramps_connect_story.py`
136
183
 
137
184
  One file, standard library only, for programs that aren't JavaScript.
@@ -168,13 +215,13 @@ identical.
168
215
  npm install
169
216
  npm test # Node tests (examples, versioning, validation, zip handling)
170
217
  npm run test:browser # in headless Google Chrome: optimizeImage(), the player,
171
- # the embed (cross-origin) and the viewer site
218
+ # the embed (cross-origin), the viewer site and the editor
172
219
  npm run test:pack # what npm would get, installed into an empty project
173
220
  npm run test:python # the Python writer, and its output read by this package
174
221
  npm run typecheck
175
222
  npm run generate # after editing spec/*/story.schema.json
176
223
  npm run build # dist/ (what npm users get)
177
- npm run build:site # site-dist/ (the viewer)
224
+ npm run build:site # site-dist/ (the viewer and the editor)
178
225
  ```
179
226
 
180
227
  Gramps Connect includes this repo as a git submodule and compiles `src/`