@ampless/plugin-x-embed 1.0.0-alpha.4 → 1.0.0-alpha.6

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 CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Node } from '@tiptap/core';
2
+ import { TiptapNodeMarkdownAdapters } from 'ampless';
2
3
 
3
4
  declare module '@tiptap/core' {
4
5
  interface Commands<ReturnType> {
@@ -32,4 +33,18 @@ declare const tweetEditor: {
32
33
  */
33
34
  declare const editorExtension: Node<any, any>;
34
35
 
35
- export { AmplessTweetNode, editorExtension, tweetEditor };
36
+ /**
37
+ * tiptap → markdown adapter map. Serialises `amplessTweet` nodes back
38
+ * to a bare `https://x.com/i/status/<tweetId>` URL line so the admin's
39
+ * "format: tiptap → markdown" body switch is lossless. The URL form
40
+ * uses `i` as the handle — confirmed to match the existing `TWEET_URL`
41
+ * regex (`/[A-Za-z0-9_]{1,15}/`). The reverse direction (URL → embed
42
+ * node on paste) is handled by the existing paste rule + `extractSingleUrl`
43
+ * path in the runtime.
44
+ *
45
+ * `update-ampless` reads this export (via namespace import `* as`) and
46
+ * wires it into `installAdminTiptapNodeMarkdown`.
47
+ */
48
+ declare const tiptapNodeToMarkdown: TiptapNodeMarkdownAdapters;
49
+
50
+ export { AmplessTweetNode, editorExtension, tiptapNodeToMarkdown, tweetEditor };
package/dist/editor.js CHANGED
@@ -60,7 +60,15 @@ var AmplessTweetNode = Node.create({
60
60
  return [
61
61
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
62
  {
63
- find: TWEET_URL,
63
+ // tiptap's paste rule internally calls `String.prototype.matchAll`
64
+ // which throws when the regex doesn't carry the `g` flag. Clone
65
+ // the source regex (which is anchored `^...$` for use in the
66
+ // renderer / markdown extractor) into a global form here. Anchored
67
+ // global is fine — without the `m` flag, `^...$` only anchor at the
68
+ // start / end of the **entire input**, so this matches at most
69
+ // once for the pasted input as a whole (= exactly the single-URL
70
+ // paste case we care about).
71
+ find: new RegExp(TWEET_URL.source, "g"),
64
72
  handler: ({ range, match, commands }) => {
65
73
  const tweetId = match[1];
66
74
  if (!tweetId) return;
@@ -78,8 +86,16 @@ var tweetEditor = {
78
86
  extension: AmplessTweetNode
79
87
  };
80
88
  var editorExtension = AmplessTweetNode;
89
+ var tiptapNodeToMarkdown = {
90
+ amplessTweet: (node) => {
91
+ const tweetId = String(node.attrs?.tweetId ?? "").trim();
92
+ if (!tweetId) return null;
93
+ return `https://x.com/i/status/${tweetId}`;
94
+ }
95
+ };
81
96
  export {
82
97
  AmplessTweetNode,
83
98
  editorExtension,
99
+ tiptapNodeToMarkdown,
84
100
  tweetEditor
85
101
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampless/plugin-x-embed",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.6",
4
4
  "description": "x.com (Twitter) embed plugin for ampless — renders tweet URLs inline as blockquotes hydrated by widgets.js",
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.44"
35
+ "ampless": "1.0.0-alpha.45"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@tiptap/core": "^3.23.6",