@veluai/velu 0.2.12 → 0.2.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veluai/velu",
3
- "version": "0.2.12",
3
+ "version": "0.2.14",
4
4
  "type": "module",
5
5
  "bin": "./dist/cli.js",
6
6
  "publishConfig": {
@@ -39,6 +39,9 @@ import {
39
39
  * siteName?: string, // for MCP deep-link labels
40
40
  * options?: Array<string|{title,description,href,icon}>,
41
41
  * onAssistant?: () => void, // 'assistant' option → in-site Ask AI
42
+ * getMarkdown?: () => string|Promise<string>, // override the .md-twin fetch
43
+ * // (instant preview: no .md twin exists —
44
+ * // the raw source comes from the store)
42
45
  * }} props
43
46
  */
44
47
 
@@ -73,6 +76,7 @@ export default function ContextMenu({
73
76
  siteName = 'docs',
74
77
  options = [],
75
78
  onAssistant,
79
+ getMarkdown,
76
80
  }) {
77
81
  const [open, setOpen] = React.useState(false);
78
82
  const [copied, setCopied] = React.useState(false);
@@ -119,18 +123,39 @@ export default function ContextMenu({
119
123
  items.push({ ...def, key: o });
120
124
  }
121
125
 
126
+ // Last-resort copy for contexts where the async Clipboard API is
127
+ // permission-denied — notably the instant preview's sandboxed iframe, whose
128
+ // opaque origin can never be granted clipboard-write.
129
+ const legacyCopy = (text) => {
130
+ const ta = document.createElement('textarea');
131
+ ta.value = text;
132
+ ta.setAttribute('readonly', '');
133
+ ta.style.position = 'fixed';
134
+ ta.style.opacity = '0';
135
+ document.body.appendChild(ta);
136
+ ta.select();
137
+ let ok = false;
138
+ try {
139
+ ok = document.execCommand('copy');
140
+ } catch {
141
+ /* not supported — give up below */
142
+ }
143
+ ta.remove();
144
+ return ok;
145
+ };
146
+
122
147
  const copyText = async (text) => {
123
148
  try {
124
149
  await navigator.clipboard.writeText(text);
125
150
  flashCopied();
126
151
  } catch {
127
- /* clipboard blocked — no-op */
152
+ if (legacyCopy(text)) flashCopied();
128
153
  }
129
154
  };
130
155
 
131
156
  const copyPage = async () => {
132
157
  try {
133
- const md = await fetch(mdUrl).then((r) => r.text());
158
+ const md = getMarkdown ? await getMarkdown() : await fetch(mdUrl).then((r) => r.text());
134
159
  await copyText(md);
135
160
  } catch {
136
161
  /* fetch failed — no-op */
@@ -1507,6 +1507,7 @@ function DocsPage() {
1507
1507
  siteName={site.name}
1508
1508
  options={site.contextual?.options ?? []}
1509
1509
  onAssistant={IS_DEV_PREVIEW ? undefined : () => askAI('')}
1510
+ getMarkdown={entry?.getSource}
1510
1511
  />
1511
1512
 
1512
1513
  {/* Page hero from MDX frontmatter. `.velu-hero` rules