Skip to content

Commit 1a42e02

Browse files
authored
Merge pull request framer#448 from framer/global-search/add-design-pages
Global search: Design Pages Support
2 parents 46331bb + ccba3ee commit 1a42e02

8 files changed

Lines changed: 39 additions & 21 deletions

File tree

Binary file not shown.

plugins/global-search/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dependencies": {
1717
"@tanstack/react-virtual": "^3.13.12",
1818
"clsx": "^2.1.1",
19-
"framer-plugin": "3.7.0-alpha.0",
19+
"framer-plugin": "3.7.0-alpha.1",
2020
"idb": "^8.0.3",
2121
"react": "^18.3.1",
2222
"react-aria": "^3.43.2",

plugins/global-search/src/components/GroupHeader.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const defaultIconClassName = "text-tertiary-light dark:text-tertiary-dark"
7373
export function ResultIcon({ rootNodeType }: { rootNodeType: RootNodeType }) {
7474
switch (rootNodeType) {
7575
case "WebPageNode":
76+
case "DesignPageNode":
7677
return <IconWebPage className={defaultIconClassName} />
7778
case "Collection":
7879
return <IconCollection className={defaultIconClassName} />

plugins/global-search/src/components/SearchScene.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,30 +88,25 @@ export function SearchScene() {
8888
)
8989
}
9090

91-
/**
92-
* Contains if you can filter by a root node type.
93-
*
94-
* During current state of the plugin, not all types are indexed yet.
95-
*/
96-
const optionsEnabled = {
91+
const searchOptions: Record<RootNodeType, true> = {
9792
ComponentNode: true,
9893
WebPageNode: true,
9994
Collection: true,
10095
CodeFile: true,
96+
DesignPageNode: true,
10197
}
10298

103-
const defaultSearchOptions = entries(optionsEnabled)
104-
.filter(([, enabled]) => enabled)
105-
.map(([rootNode]) => rootNode)
99+
const defaultSearchOptions = entries(searchOptions).map(([rootNode]) => rootNode)
106100

107101
const optionsMenuLabels = {
108102
ComponentNode: "Components",
109103
WebPageNode: "Pages",
104+
DesignPageNode: "Designs",
110105
Collection: "Collections",
111106
CodeFile: "Code",
112107
} as const satisfies Record<RootNodeType, string>
113108

114-
const sortedRootNodeTypes = entries(optionsEnabled).sort(([a], [b]) => compareRootNodeTypeByPriority(a, b))
109+
const sortedRootNodeTypes = entries(searchOptions).sort(([a], [b]) => compareRootNodeTypeByPriority(a, b))
115110

116111
function useOptionsMenuItems() {
117112
const [searchOptions, setSearchOptions] = useState<readonly RootNodeType[]>(defaultSearchOptions)

plugins/global-search/src/utils/filter/group-results.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ export async function groupResults(
8181
return groups.sort((a, b) => compareRootNodeTypeByPriority(a.entry.rootNodeType, b.entry.rootNodeType))
8282
}
8383

84-
const orderOfResults = ["WebPageNode", "Collection", "ComponentNode", "CodeFile"] satisfies RootNodeType[]
84+
const orderOfResults = [
85+
"WebPageNode",
86+
"DesignPageNode",
87+
"Collection",
88+
"ComponentNode",
89+
"CodeFile",
90+
] satisfies RootNodeType[]
8591

8692
export function compareRootNodeTypeByPriority(a: RootNodeType, b: RootNodeType): number {
8793
return orderOfResults.indexOf(a) - orderOfResults.indexOf(b)

plugins/global-search/src/utils/indexer/indexer.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
type Collection,
55
framer,
66
isComponentNode,
7+
isDesignPageNode,
78
isFrameNode,
89
isTextNode,
910
isWebPageNode,
@@ -27,6 +28,10 @@ async function getNodeName(node: AnyNode): Promise<string | null> {
2728
return node.path
2829
}
2930

31+
if (isDesignPageNode(node)) {
32+
return node.name ?? "Design"
33+
}
34+
3035
if (isComponentNode(node)) {
3136
return node.name ?? "Component"
3237
}
@@ -203,7 +208,9 @@ export class GlobalSearchIndexer {
203208
rootNodes: readonly CanvasRootNode[],
204209
abortSignal?: AbortSignal
205210
) {
206-
const validRootNodes = rootNodes.filter(rootNode => isComponentNode(rootNode) || isWebPageNode(rootNode))
211+
const validRootNodes = rootNodes.filter(
212+
rootNode => isComponentNode(rootNode) || isWebPageNode(rootNode) || isDesignPageNode(rootNode)
213+
)
207214

208215
for await (const batch of this.crawlNodes(currentIndexRun, validRootNodes)) {
209216
if (this.abortRequested || abortSignal?.aborted) break
@@ -258,10 +265,11 @@ export class GlobalSearchIndexer {
258265
const lastIndexRun = await this.db.getLastIndexRun()
259266
const currentIndexRun = lastIndexRun + 1
260267

261-
const [pages, components, canvasRoot] = await Promise.all([
268+
const [canvasRoot, ...rootNodes] = await Promise.all([
269+
framer.getCanvasRoot(),
262270
framer.getNodesWithType("WebPageNode"),
263271
framer.getNodesWithType("ComponentNode"),
264-
framer.getCanvasRoot(),
272+
framer.getNodesWithType("DesignPageNode"),
265273
])
266274

267275
this.abortRequested = false
@@ -273,9 +281,7 @@ export class GlobalSearchIndexer {
273281

274282
// Remove the current open canvas root from the list of root nodes to index
275283
// as it's already being indexed by the canvas root watcher
276-
const rootNodesWithoutCurrentRoot = [...pages, ...components].filter(
277-
rootNode => rootNode.id !== canvasRoot.id
278-
)
284+
const rootNodesWithoutCurrentRoot = rootNodes.flat().filter(rootNode => rootNode.id !== canvasRoot.id)
279285

280286
await Promise.all([
281287
this.processNodes(currentIndexRun, rootNodesWithoutCurrentRoot),

plugins/global-search/src/utils/indexer/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { type AnyNode, ComponentNode, isTextNode, TextNode, WebPageNode } from "framer-plugin"
1+
import { type AnyNode, ComponentNode, DesignPageNode, isTextNode, TextNode, WebPageNode } from "framer-plugin"
22

3-
export type IndexNodeRootNode = ComponentNode | WebPageNode
3+
export type IndexNodeRootNode = ComponentNode | WebPageNode | DesignPageNode
44
export type IndexNodeRootNodeType = IndexNodeRootNode["__class"]
55

66
export type IndexableNode = TextNode

yarn.lock

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6236,6 +6236,16 @@ __metadata:
62366236
languageName: node
62376237
linkType: hard
62386238

6239+
"framer-plugin@npm:3.7.0-alpha.1":
6240+
version: 3.7.0-alpha.1
6241+
resolution: "framer-plugin@npm:3.7.0-alpha.1"
6242+
peerDependencies:
6243+
react: ^18.2.0
6244+
react-dom: ^18.2.0
6245+
checksum: 10/f253047cf9b4f0fe9cf61aa27dd0651a6e1d3b13cd4cde0b8b467700ccd45189f4e134f665875a8a727c5c5ba36be5d2d83ad074781768281b1772f0077aa140
6246+
languageName: node
6247+
linkType: hard
6248+
62396249
"framer-plugin@npm:^3.6.0":
62406250
version: 3.6.0
62416251
resolution: "framer-plugin@npm:3.6.0"
@@ -6342,7 +6352,7 @@ __metadata:
63426352
"@types/react-dom": "npm:^18.3.7"
63436353
"@vitest/ui": "npm:^3.2.4"
63446354
clsx: "npm:^2.1.1"
6345-
framer-plugin: "npm:3.7.0-alpha.0"
6355+
framer-plugin: "npm:3.7.0-alpha.1"
63466356
happy-dom: "npm:^18.0.1"
63476357
idb: "npm:^8.0.3"
63486358
react: "npm:^18.3.1"

0 commit comments

Comments
 (0)