@brett_lamy/docstream-editor 0.3.1 → 0.3.2

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
@@ -172,3 +172,9 @@ import { GitbookStreamdown } from "@brett_lamy/docstream"
172
172
 
173
173
  <GitbookStreamdown markdown={markdown} isStreaming={false} />
174
174
  ```
175
+
176
+ Embed nodes preserve the Docstream media attributes (`title`, `poster`,
177
+ `autoplay`, `loop`, `muted`, and `controls`) when converting between the
178
+ editable TipTap document and GitBook markdown. This makes short, muted,
179
+ autoplaying clips round-trip through the editor without losing their playback
180
+ contract.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brett_lamy/docstream-editor",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "TipTap editor for Docstream GitBook-style markdown documents.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -20,7 +20,7 @@
20
20
  "./styles.css": "./src/styles.css"
21
21
  },
22
22
  "dependencies": {
23
- "@brett_lamy/docstream": "0.3.0",
23
+ "@brett_lamy/docstream": "0.3.2",
24
24
  "lowlight": "^3.3.0",
25
25
  "lucide-react": "^1.17.0"
26
26
  },
@@ -98,8 +98,16 @@ function blockToPM(b: Block): PMNode {
98
98
  content: blocksPM(s.children),
99
99
  })),
100
100
  }
101
- case "embed":
102
- return { type: "gbEmbed", attrs: { url: b.url } }
101
+ case "embed": {
102
+ const attrs: Record<string, string | boolean> = { url: b.url }
103
+ if (b.title !== undefined) attrs.title = b.title
104
+ if (b.poster !== undefined) attrs.poster = b.poster
105
+ if (b.autoplay !== undefined) attrs.autoplay = b.autoplay
106
+ if (b.loop !== undefined) attrs.loop = b.loop
107
+ if (b.muted !== undefined) attrs.muted = b.muted
108
+ if (b.controls !== undefined) attrs.controls = b.controls
109
+ return { type: "gbEmbed", attrs }
110
+ }
103
111
  case "content-ref":
104
112
  return { type: "gbContentRef", attrs: { url: b.url, label: plainText(b.children) } }
105
113
  case "columns":
@@ -255,8 +263,19 @@ function pmToBlock(n: PMNode): Block | null {
255
263
  children: pmToBlocks(s.content),
256
264
  })),
257
265
  }
258
- case "gbEmbed":
259
- return { type: "embed", url: String(n.attrs?.url ?? "") }
266
+ case "gbEmbed": {
267
+ const embed: Extract<Block, { type: "embed" }> = {
268
+ type: "embed",
269
+ url: String(n.attrs?.url ?? ""),
270
+ }
271
+ if (typeof n.attrs?.title === "string") embed.title = n.attrs.title
272
+ if (typeof n.attrs?.poster === "string") embed.poster = n.attrs.poster
273
+ if (typeof n.attrs?.autoplay === "boolean") embed.autoplay = n.attrs.autoplay
274
+ if (typeof n.attrs?.loop === "boolean") embed.loop = n.attrs.loop
275
+ if (typeof n.attrs?.muted === "boolean") embed.muted = n.attrs.muted
276
+ if (typeof n.attrs?.controls === "boolean") embed.controls = n.attrs.controls
277
+ return embed
278
+ }
260
279
  case "gbContentRef":
261
280
  return {
262
281
  type: "content-ref",
@@ -306,15 +306,34 @@ function isDirectVideo(url: string): boolean {
306
306
  return /\.(?:mp4|webm|ogg)(?:[?#]|$)/i.test(url)
307
307
  }
308
308
 
309
+ function booleanAttribute(value: unknown): boolean | undefined {
310
+ return typeof value === "boolean" ? value : undefined
311
+ }
312
+
309
313
  function EmbedView({ node, updateAttributes, editor }: NodeViewProps) {
310
314
  const url = node.attrs.url as string
311
315
  const preview = embedPreview(url)
316
+ const title = typeof node.attrs.title === "string" && node.attrs.title ? node.attrs.title : url
317
+ const poster = typeof node.attrs.poster === "string" ? node.attrs.poster : undefined
318
+ const autoplay = booleanAttribute(node.attrs.autoplay)
319
+ const loop = booleanAttribute(node.attrs.loop)
320
+ const muted = booleanAttribute(node.attrs.muted)
321
+ const controls = booleanAttribute(node.attrs.controls)
312
322
  return (
313
323
  <NodeViewWrapper className="gb-embed" contentEditable={false}>
314
324
  {isReplayQaUrl(url) ? (
315
325
  <ReplayPreview source={url} title="Replay preview" />
316
326
  ) : preview || isDirectVideo(url) ? (
317
- <VideoEmbed src={preview ?? url} className="gb-embed-frame" title={url} />
327
+ <VideoEmbed
328
+ src={preview ?? url}
329
+ className="gb-embed-frame"
330
+ title={title}
331
+ {...(autoplay === undefined ? {} : { autoplay })}
332
+ {...(loop === undefined ? {} : { loop })}
333
+ {...(muted === undefined ? {} : { muted })}
334
+ {...(controls === undefined ? {} : { controls })}
335
+ {...(poster === undefined ? {} : { poster })}
336
+ />
318
337
  ) : (
319
338
  <a className="gb-embed-link" href={url} target="_blank" rel="noreferrer">
320
339
  <Link2 className="size-4" /> {url || "Embed URL…"}
@@ -337,7 +356,15 @@ export const GbEmbed = Node.create({
337
356
  group: "block",
338
357
  atom: true,
339
358
  addAttributes() {
340
- return { url: { default: "" } }
359
+ return {
360
+ url: { default: "" },
361
+ title: { default: null },
362
+ autoplay: { default: null },
363
+ loop: { default: null },
364
+ muted: { default: null },
365
+ controls: { default: null },
366
+ poster: { default: null },
367
+ }
341
368
  },
342
369
  parseHTML() {
343
370
  return [{ tag: "div[data-gb-embed]" }]