@ampless/plugin-youtube 1.0.0-alpha.7 → 1.0.0-alpha.8
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/dist/editor.d.ts +20 -2
- package/dist/editor.js +30 -4
- package/package.json +2 -2
package/dist/editor.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Node } from '@tiptap/core';
|
|
2
|
-
import { TiptapNodeMarkdownAdapters } from 'ampless';
|
|
2
|
+
import { TiptapNodeHtmlAdapters, TiptapNodeMarkdownAdapters } from 'ampless';
|
|
3
3
|
|
|
4
4
|
declare module '@tiptap/core' {
|
|
5
5
|
interface Commands<ReturnType> {
|
|
@@ -48,4 +48,22 @@ declare const editorExtension: Node<any, any>;
|
|
|
48
48
|
*/
|
|
49
49
|
declare const tiptapNodeToMarkdown: TiptapNodeMarkdownAdapters;
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
/**
|
|
52
|
+
* tiptap → html adapter map. Serialises `amplessYoutube` nodes to the
|
|
53
|
+
* canonical placeholder div `<div data-ampless-youtube data-video-id="..."
|
|
54
|
+
* class="ampless-youtube-placeholder">…</div>` so the admin's
|
|
55
|
+
* "format: tiptap → html" body switch is lossless. The div is what
|
|
56
|
+
* `Node.parseHTML`'s `tag: 'div[data-ampless-youtube]'` rule restores
|
|
57
|
+
* from. It is an admin format-switch interchange form; public rendering
|
|
58
|
+
* expands YouTube embeds from the `tiptap` / `markdown` walkers, while
|
|
59
|
+
* `format: 'html'` preserves the div literally.
|
|
60
|
+
*
|
|
61
|
+
* `markdown → html` is a 2-hop via `generateJSON` (in admin format-switch);
|
|
62
|
+
* this adapter is reused by that path — no duplicate logic needed.
|
|
63
|
+
*
|
|
64
|
+
* `update-ampless` reads this export (via namespace import `* as`) and
|
|
65
|
+
* wires it into `installAdminTiptapNodeHtml`.
|
|
66
|
+
*/
|
|
67
|
+
declare const tiptapNodeToHtml: TiptapNodeHtmlAdapters;
|
|
68
|
+
|
|
69
|
+
export { AmplessYoutubeNode, editorExtension, tiptapNodeToHtml, tiptapNodeToMarkdown, youtubeEditor };
|
package/dist/editor.js
CHANGED
|
@@ -23,6 +23,23 @@ function getBareUrlLinkHref(el) {
|
|
|
23
23
|
if (el.textContent?.trim() !== linkText) return null;
|
|
24
24
|
return href;
|
|
25
25
|
}
|
|
26
|
+
function placeholderAttrs(attrs) {
|
|
27
|
+
const out = {
|
|
28
|
+
"data-ampless-youtube": "",
|
|
29
|
+
"data-video-id": String(attrs.videoId ?? ""),
|
|
30
|
+
class: "ampless-youtube-placeholder"
|
|
31
|
+
};
|
|
32
|
+
if (attrs.start != null && Number.isFinite(Number(attrs.start))) {
|
|
33
|
+
out["data-start"] = String(attrs.start);
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
function escapeAttr(v) {
|
|
38
|
+
return v.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
39
|
+
}
|
|
40
|
+
function attrsToHtmlString(attrs) {
|
|
41
|
+
return Object.entries(attrs).map(([k, v]) => v === "" ? k : `${k}="${escapeAttr(v)}"`).join(" ");
|
|
42
|
+
}
|
|
26
43
|
var AmplessYoutubeNode = Node.create({
|
|
27
44
|
name: "amplessYoutube",
|
|
28
45
|
group: "block",
|
|
@@ -108,10 +125,10 @@ var AmplessYoutubeNode = Node.create({
|
|
|
108
125
|
renderHTML({ HTMLAttributes }) {
|
|
109
126
|
return [
|
|
110
127
|
"div",
|
|
111
|
-
mergeAttributes(HTMLAttributes, {
|
|
112
|
-
"data-
|
|
113
|
-
|
|
114
|
-
}),
|
|
128
|
+
mergeAttributes(HTMLAttributes, placeholderAttrs({
|
|
129
|
+
videoId: HTMLAttributes["data-video-id"],
|
|
130
|
+
start: HTMLAttributes["data-start"]
|
|
131
|
+
})),
|
|
115
132
|
["span", {}, `YouTube: ${HTMLAttributes["data-video-id"] ?? ""}`]
|
|
116
133
|
];
|
|
117
134
|
},
|
|
@@ -168,9 +185,18 @@ var tiptapNodeToMarkdown = {
|
|
|
168
185
|
return `https://youtu.be/${videoId}`;
|
|
169
186
|
}
|
|
170
187
|
};
|
|
188
|
+
var tiptapNodeToHtml = {
|
|
189
|
+
amplessYoutube: (node) => {
|
|
190
|
+
const videoId = String(node.attrs?.videoId ?? "").trim();
|
|
191
|
+
if (!videoId) return null;
|
|
192
|
+
const attrs = placeholderAttrs(node.attrs ?? {});
|
|
193
|
+
return `<div ${attrsToHtmlString(attrs)}><span>YouTube: ${escapeAttr(videoId)}</span></div>`;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
171
196
|
export {
|
|
172
197
|
AmplessYoutubeNode,
|
|
173
198
|
editorExtension,
|
|
199
|
+
tiptapNodeToHtml,
|
|
174
200
|
tiptapNodeToMarkdown,
|
|
175
201
|
youtubeEditor
|
|
176
202
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ampless/plugin-youtube",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.8",
|
|
4
4
|
"description": "YouTube embed plugin for ampless — renders youtube.com / youtu.be URLs inline as iframes in tiptap + markdown posts",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@tiptap/core": "^3",
|
|
34
34
|
"react": "^18 || ^19",
|
|
35
|
-
"ampless": "1.0.0-alpha.
|
|
35
|
+
"ampless": "1.0.0-alpha.47"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@tiptap/core": "^3.23.6",
|