Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/roam/src/components/canvas/Clipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { useAtom } from "@tldraw/state";
import AutocompleteInput from "roamjs-components/components/AutocompleteInput";
import { Result } from "roamjs-components/types/query-builder";
import fuzzy from "fuzzy";
import { getAllReferencesOnPage } from "~/utils/hyde";
import getAllReferencesOnPage from "~/utils/getAllReferencesOnPage";
import isDiscourseNode from "~/utils/isDiscourseNode";
import {
DiscourseNodeShape,
Expand Down Expand Up @@ -287,8 +287,8 @@ const AddPageModal = ({ isOpen, onClose, onConfirm }: AddPageModalProps) => {
// eslint-disable-next-line @typescript-eslint/await-thenable
const raw = await window.roamAlphaAPI.data.backend.q(
`
[:find ?text ?uid
:where
[:find ?text ?uid
:where
[?e :node/title ?text]
[?e :block/uid ?uid]]`,
);
Expand Down
53 changes: 53 additions & 0 deletions apps/roam/src/utils/getAllReferencesOnPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import normalizePageTitle from "roamjs-components/queries/normalizePageTitle";

const getAllReferencesOnPage = async (
pageTitle: string,
): Promise<{ uid: string; text: string }[]> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: uid;text; is Result[], which is commonly used in the repo

pageTitle = normalizePageTitle(pageTitle);
let referencedPages: Array<[string, string]> = [];
if (pageTitle.startsWith("Canvas/")) {
Copy link
Contributor

@mdroidian mdroidian Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Canvas page format is defined in settings, so this could change. Let's make sure we grab the up to date format.

const oldCanvasContent = window.roamAlphaAPI.data.fast.q(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we should see if we can reuse some code with CanvasReferences

`[:find ?uid ?title
:where
[?c :node/title "${pageTitle}"]
[?c :block/props ?props]
[(get ?props :roamjs-query-builder) ?rqb]
[(get ?rqb :tldraw) [[?k ?v]]]
[(get ?v :props) ?shape-props]
[(get ?shape-props :uid) ?uid]
[?n :block/uid ?uid]
[?n :node/title ?title]
]`,
) as Array<[string, string]>;
const newCanvasContent = window.roamAlphaAPI.data.fast.q(
`[:find ?uid ?title
:where
[?c :node/title "${pageTitle}"]
[?c :block/props ?props]
[(get ?props :roamjs-query-builder) ?rqb]
[(get ?rqb :tldraw) ?tldraw]
[(get ?tldraw :store) [[?k ?v]]]
[(get ?v :props) ?shape-props]
[(get ?shape-props :uid) ?uid]
[?n :block/uid ?uid]
[?n :node/title ?title]
]`,
) as Array<[string, string]>;
referencedPages = [...oldCanvasContent, ...newCanvasContent];
} else {
referencedPages = (await Promise.resolve(
window.roamAlphaAPI.data.backend.q(
`[:find ?uid ?text
:where
[?page :node/title "${pageTitle}"]
[?b :block/page ?page]
[?b :block/refs ?refPage]
[?refPage :block/uid ?uid]
[?refPage :node/title ?text]]`,
),
)) as Array<[string, string]>;
}
return referencedPages.map(([uid, text]) => ({ uid, text }));
};

export default getAllReferencesOnPage;
18 changes: 1 addition & 17 deletions apps/roam/src/utils/hyde.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { nextApiRoot } from "@repo/utils/execContext";
import { DiscourseNode } from "./getDiscourseNodes";
import getExtensionAPI from "roamjs-components/util/extensionApiContext";
import { getNodesByType } from "@repo/database/lib/queries";
import getAllReferencesOnPage from "./getAllReferencesOnPage";

type ApiEmbeddingResponse = {
data: Array<{
Expand Down Expand Up @@ -391,23 +392,6 @@ export const extractPagesFromParentBlock = async (
return results.map(([uid, title]) => ({ uid, text: title }));
};

export const getAllReferencesOnPage = async (
pageTitle: string,
): Promise<{ uid: string; text: string }[]> => {
const referencedPages = (await Promise.resolve(
window.roamAlphaAPI.data.backend.q(
`[:find ?uid ?text
:where
[?page :node/title "${normalizePageTitle(pageTitle)}"]
[?b :block/page ?page]
[?b :block/refs ?refPage]
[?refPage :block/uid ?uid]
[?refPage :node/title ?text]]`,
),
)) as Array<[string, string]>;
return referencedPages.map(([uid, text]) => ({ uid, text }));
};

export type PerformHydeSearchParams = {
useAllPagesForSuggestions: boolean;
selectedPages: string[];
Expand Down