Click the button, then paste (Cmd+V) into Paper. You should see a dark frame with "Hello Paper!" text.
+ + + + + diff --git a/packages/paper/tsconfig.json b/packages/paper/tsconfig.json new file mode 100644 index 000000000..9c3d6789d --- /dev/null +++ b/packages/paper/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "bundler", + "esModuleInterop": true, + "strict": true, + "skipLibCheck": true, + "declaration": true, + "outDir": "dist", + "rootDir": "src", + "lib": ["esnext", "dom", "dom.iterable"] + }, + "include": ["src/**/*"] +} diff --git a/packages/paper/tsup.config.ts b/packages/paper/tsup.config.ts new file mode 100644 index 000000000..41e218fda --- /dev/null +++ b/packages/paper/tsup.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from "tsup"; + +export default defineConfig({ + entry: { index: "./src/index.ts" }, + format: ["esm", "cjs"], + dts: true, + clean: true, + target: "es2022", + treeshake: true, +}); diff --git a/packages/react-grab/package.json b/packages/react-grab/package.json index 73cab3e89..090c8eba9 100644 --- a/packages/react-grab/package.json +++ b/packages/react-grab/package.json @@ -94,6 +94,7 @@ }, "dependencies": { "@medv/finder": "^4.0.2", + "@react-grab/paper": "workspace:*", "bippy": "^0.5.30", "solid-js": "^1.9.10" }, diff --git a/packages/react-grab/src/core/context.ts b/packages/react-grab/src/core/context.ts index 36ce4b0a4..beb77c845 100644 --- a/packages/react-grab/src/core/context.ts +++ b/packages/react-grab/src/core/context.ts @@ -563,6 +563,8 @@ const formatPriorityAttrs = ( return priorityAttrs.length > 0 ? ` ${priorityAttrs.join(" ")}` : ""; }; + + const getHTMLPreview = (element: Element): string => { const tagName = getTagName(element); if (!(element instanceof HTMLElement)) { diff --git a/packages/react-grab/src/core/copy.ts b/packages/react-grab/src/core/copy.ts index ac4a39dc1..52c68384d 100644 --- a/packages/react-grab/src/core/copy.ts +++ b/packages/react-grab/src/core/copy.ts @@ -1,7 +1,37 @@ +import { + getFiberFromHostInstance, + isCompositeFiber, + getDisplayName, +} from "bippy"; +import { domToPaper } from "@react-grab/paper"; import { copyContent, type ReactGrabEntry } from "../utils/copy-content.js"; import { generateSnippet } from "../utils/generate-snippet.js"; import { joinSnippets } from "../utils/join-snippets.js"; +const getReactComponentName = (element: Element): string | null => { + try { + const fiber = getFiberFromHostInstance(element); + if (!fiber) return null; + + const parentFiber = fiber.return; + if (!parentFiber || !isCompositeFiber(parentFiber)) return null; + + const componentName = getDisplayName(parentFiber); + if (!componentName) return null; + + if ( + element.parentElement && + getFiberFromHostInstance(element.parentElement)?.return === parentFiber + ) { + return null; + } + + return componentName; + } catch { + return null; + } +}; + interface CopyOptions { maxContextLines?: number; getContent?: (elements: Element[]) => Promise${escapeHtml(content)}`,
+ htmlContent: paperHtml
+ ? `${paperHtml}`
+ : `${escapeHtml(content)}`,
lexicalData: JSON.stringify({
namespace: `chat-input${namespaceUuid}-pane`,
nodes: [
@@ -150,6 +154,7 @@ export const copyContent = (
const { plainText, htmlContent, lexicalData } = createClipboardData(
content,
elementName,
+ options?.paperHtml,
);
const entries = options?.entries ?? [
{
diff --git a/packages/react-grab/tsup.config.ts b/packages/react-grab/tsup.config.ts
index 34d0049ca..e29ad7e8d 100644
--- a/packages/react-grab/tsup.config.ts
+++ b/packages/react-grab/tsup.config.ts
@@ -50,7 +50,7 @@ const DEFAULT_OPTIONS: Options = {
".css": "text",
},
minify: process.env.NODE_ENV === "production",
- noExternal: ["clsx", "tailwind-merge", "solid-js", "bippy"],
+ noExternal: ["clsx", "tailwind-merge", "solid-js", "bippy", "@react-grab/paper"],
onSuccess: process.env.COPY ? "pbcopy < ./dist/index.global.js" : undefined,
outDir: "./dist",
sourcemap: false,
@@ -140,7 +140,7 @@ const reactBuildConfig: Options = {
".css": "text",
},
minify: false,
- noExternal: ["bippy", "solid-js", "clsx", "tailwind-merge"],
+ noExternal: ["bippy", "solid-js", "clsx", "tailwind-merge", "@react-grab/paper"],
outDir: "./dist",
platform: "neutral",
sourcemap: false,
diff --git a/packages/website/public/script.js b/packages/website/public/script.js
index d9d882f2f..596d74265 100644
--- a/packages/website/public/script.js
+++ b/packages/website/public/script.js
@@ -6,65 +6,65 @@ this.globalThis=this.globalThis||{};this.globalThis.__REACT_GRAB_MODULE__=(funct
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
-var op=(e,t)=>e===t,nn=Symbol("solid-proxy"),rp=typeof Proxy=="function",Nr=Symbol("solid-track"),zi={equals:op},bc=Ec,Ft=1,Mr=2,yc={owned:null,cleanups:null,context:null,owner:null},ma={},$e=null,J=null,Fo=null,Ye=null,ft=null,Ct=null,Ui=0;function Tn(e,t){let n=Ye,o=$e,i=e.length===0,s=t===void 0?o:t,r=i?yc:{owned:null,cleanups:null,context:s?s.context:null,owner:s},c=i?e:()=>e(()=>Et(()=>Gn(r)));$e=r,Ye=null;try{return Ot(c,!0)}finally{Ye=n,$e=o;}}function U(e,t){t=t?Object.assign({},zi,t):zi;let n={value:e,observers:null,observerSlots:null,comparator:t.equals||void 0},o=i=>(typeof i=="function"&&(i=i(n.value)),Cc(n,i));return [vc.bind(n),o]}function mc(e,t,n){let o=Ki(e,t,true,Ft);Ho(o);}function te(e,t,n){let o=Ki(e,t,false,Ft);Ho(o);}function be(e,t,n){bc=cp;let o=Ki(e,t,false,Ft);(o.user=true),Ct?Ct.push(o):Ho(o);}function se(e,t,n){n=n?Object.assign({},zi,n):zi;let o=Ki(e,t,true,0);return o.observers=null,o.observerSlots=null,o.comparator=n.equals||void 0,Ho(o),vc.bind(o)}function ip(e){return e&&typeof e=="object"&&"then"in e}function ba(e,t,n){let o,i,s;typeof t=="function"?(o=e,i=t,s={}):(o=true,i=e,s=t||{});let r=null,c=ma,f=false,p="initialValue"in s,b=typeof o=="function"&&se(o),x=new Set,[H,M]=(s.storage||U)(s.initialValue),[Y,m]=U(void 0),[E,T]=U(void 0,{equals:false}),[C,R]=U(p?"ready":"unresolved");function X(L,A,y,h){return r===L&&(r=null,h!==void 0&&(p=true),(L===c||A===c)&&s.onHydrated&&queueMicrotask(()=>s.onHydrated(h,{value:A})),c=ma,fe(A,y)),A}function fe(L,A){Ot(()=>{A===void 0&&M(()=>L),R(A!==void 0?"errored":p?"ready":"unresolved"),m(A);for(let y of x.keys())y.decrement();x.clear();},false);}function j(){let L=Rr,A=H(),y=Y();if(y!==void 0&&!r)throw y;return Ye&&!Ye.user&&L,A}function le(L=true){if(L!==false&&f)return;f=false;let A=b?b():o;if(A==null||A===false){X(r,Et(H));return}let y,h=c!==ma?c:Et(()=>{try{return i(A,{value:H(),refetching:L})}catch(S){y=S;}});if(y!==void 0){X(r,void 0,Bi(y),A);return}else if(!ip(h))return X(r,h,void 0,A),h;return r=h,"v"in h?(h.s===1?X(r,h.v,void 0,A):X(r,void 0,Bi(h.v),A),h):(f=true,queueMicrotask(()=>f=false),Ot(()=>{R(p?"refreshing":"pending"),T();},false),h.then(S=>X(h,S,void 0,A),S=>X(h,void 0,Bi(S),A)))}Object.defineProperties(j,{state:{get:()=>C()},error:{get:()=>Y()},loading:{get(){let L=C();return L==="pending"||L==="refreshing"}},latest:{get(){if(!p)return j();let L=Y();if(L&&!r)throw L;return H()}}});let ue=$e;return b?mc(()=>(ue=$e,le(false))):le(false),[j,{refetch:L=>wc(ue,()=>le(L)),mutate:M}]}function ji(e){return Ot(e,false)}function Et(e){if(Ye===null)return e();let t=Ye;Ye=null;try{return Fo?Fo.untrack(e):e()}finally{Ye=t;}}function He(e,t,n){let o=Array.isArray(e),i,s=n&&n.defer;return r=>{let c;if(o){c=Array(e.length);for(let u=0;u