Skip to content

cf235 [Grida Canvas] Hierarchy Tree DnD - #350

Merged
softmarshmallow merged 8 commits into
mainfrom
canary
May 23, 2025
Merged

softmarshmallow merged 8 commits into
mainfrom
canary

Conversation

@softmarshmallow

@softmarshmallow softmarshmallow commented May 21, 2025 •

Copy link
Copy Markdown
Member
  • introduces @grida/tree package
day-235-grida-canvas-hierarchy-tree-dnd-move.mp4

Summary by CodeRabbit

  • New Features

    • Introduced a new hierarchical editor interface for managing scenes and nodes, with enhanced drag-and-drop, selection, renaming, and context menu actions.
    • Added support for advanced slide editing, new effect types, rich text styling, and annotation management in the editor schema.
    • Released a new tree utility package for node manipulation and reordering.
  • Improvements

    • Updated visual styling for color and paint chips with rounded corners.
    • Simplified and modularized scene and node hierarchy components for better maintainability and external customization.
    • Improved unique ID generation for new scenes.
  • Bug Fixes

    • Enhanced move operations for nodes, supporting bulk moves and correct reordering within hierarchies.
  • Documentation

    • Added initial README and license files for the new tree utility package.
  • Tests

    • Added comprehensive tests for tree node move operations to ensure correct behavior and error handling.

@codesandbox

codesandbox Bot commented May 21, 2025

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web Editor • VS Code • Insiders

Open Preview

@vercel

vercel Bot commented May 21, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
grida ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 23, 2025 8:01am
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
code ⬜️ Ignored (Inspect) May 23, 2025 8:01am
legacy ⬜️ Ignored (Inspect) May 23, 2025 8:01am
backgrounds ⬜️ Skipped (Inspect) May 23, 2025 8:01am
blog ⬜️ Skipped (Inspect) May 23, 2025 8:01am
docs ⬜️ Skipped (Inspect) May 23, 2025 8:01am
viewer ⬜️ Skipped (Inspect) May 23, 2025 8:01am

@coderabbitai

coderabbitai Bot commented May 21, 2025 •

Copy link
Copy Markdown

Walkthrough

This update introduces a new @grida/tree package providing generic tree manipulation utilities, notably a robust mv (move) function with comprehensive tests. The editor's node hierarchy and scenes sidebar is refactored to use new, externally sourced ScenesList and NodeHierarchyList components. Tree data handling, drag-and-drop, and renaming logic are centralized and improved. The canvas schema is extended for slides and advanced text/effect features.

Changes

File(s) Change Summary
editor/components/formfield/grida-canvas/index.tsx Updated import path for NodeHierarchyList to use the new starter kit module.
editor/components/ui-editor/tree.tsx Added group/item class and data-renaming attribute to TreeItem; adjusted label padding.
editor/grida-canvas-utils/.ref/examples.ts Deleted example file defining template document properties.
editor/grida-react-canvas-starter-kit/starterkit-hierarchy/index.tsx New file: Implements ScenesList and NodeHierarchyList React components with advanced tree, context menu, and renaming logic for scenes and nodes.
editor/grida-react-canvas/action.ts Refactored action types: added EditorHierarchyAction, simplified EditorHierarchyMoveAction target property.
editor/grida-react-canvas/provider.tsx Added mv function to useDocument for moving nodes; exposed as part of the returned API.
editor/grida-react-canvas/reducers/document.reducer.ts Added "mv" action case to handle moving multiple nodes using self_moveNode.
editor/grida-react-canvas/reducers/index.ts Switched scene ID generation from nid() to uuid.v4().
editor/grida-react-canvas/reducers/methods/move.ts Refactored self_moveNode to use a virtual tree and new mv utility; clarified root move constraints.
editor/package.json Added @grida/tree as a workspace dependency.
editor/scaffolds/sidebar/sidebar-node-hierarchy-list.tsx Major refactor: Removed all inline hierarchy/scenes logic and replaced with imports of ScenesList and NodeHierarchyList from the starter kit.
editor/scaffolds/sidecontrol/controls/border.tsx
editor/scaffolds/sidecontrol/controls/color.tsx
editor/scaffolds/sidecontrol/controls/paint.tsx
editor/scaffolds/sidecontrol/controls/box-shadow.tsx
Added rounded-sm class to color/paint chip components for consistent styling.
editor/scaffolds/sidecontrol/controls/utils/paint-chip.tsx Updated PaintChip and subcomponents to accept and merge className prop for styling.
packages/grida-canvas-schema/.ref/examples/static/1.ts
packages/grida-canvas-schema/.ref/examples/static/2.ts
packages/grida-canvas-schema/.ref/examples/static/3.ts
Changed import style, removed root_id, and renamed textures to bitmaps in example exports.
packages/grida-canvas-schema/.ref/figma.d.ts Major extension: Expanded schema for slides, advanced effects, new node types, text decoration, user/payment APIs, and more.
packages/grida-tree/LICENSE New file: Added MIT license.
packages/grida-tree/README.md New file: Added minimal README for the package.
packages/grida-tree/tests/mv.test.ts New file: Added comprehensive tests for mv tree manipulation function.
packages/grida-tree/index.ts New file: Re-exports all from src/lib.
packages/grida-tree/package.json New file: Added package manifest with test script and configuration.
packages/grida-tree/src/lib.ts New file: Implements generic mv function for moving nodes in a tree.
packages/grida-tree/tsconfig.json New file: TypeScript config with strict type checking.

Sequence Diagram(s)

sequenceDiagram
  participant UI as Sidebar UI
  participant StarterKit as starterkit-hierarchy
  participant TreeUtil as @grida/tree
  participant Doc as Document State

  UI->>StarterKit: Render <ScenesList /> and <NodeHierarchyList />
  StarterKit->>Doc: Load scenes/nodes, subscribe to changes
  StarterKit->>UI: Handle drag, select, rename, context menu
  StarterKit->>TreeUtil: On move, call mv(sources, target, index)
  TreeUtil-->>StarterKit: Mutate tree structure
  StarterKit->>Doc: Dispatch move actions, update state
  Doc-->>StarterKit: Emit updated tree
  StarterKit-->>UI: Rerender updated hierarchy
Loading

Possibly related PRs

  • gridaco/grida#349: Implements a hierarchical tree UI with inline renaming and context menus, similar to the functionality now refactored into the starter kit and @grida/tree.

Poem

In the forest of code, a tree grows anew,
With branches that move, and children in view.
Scenes and nodes now dance with glee,
Thanks to a kit and a fresh mv.
From root to leaf, the logic is clear—
A rabbit hops by, and gives a big cheer! 🐇🌳

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@vercel
vercel Bot temporarily deployed to Preview – docs May 21, 2025 20:19 Inactive
@vercel
vercel Bot temporarily deployed to Preview – blog May 21, 2025 20:19 Inactive
@vercel
vercel Bot temporarily deployed to Preview – backgrounds May 21, 2025 20:19 Inactive
@vercel
vercel Bot temporarily deployed to Preview – viewer May 21, 2025 20:19 Inactive
@vercel
vercel Bot temporarily deployed to Preview – blog May 23, 2025 07:56 Inactive
@vercel
vercel Bot temporarily deployed to Preview – backgrounds May 23, 2025 07:56 Inactive
@vercel
vercel Bot temporarily deployed to Preview – docs May 23, 2025 07:56 Inactive
@vercel
vercel Bot temporarily deployed to Preview – viewer May 23, 2025 07:56 Inactive
@softmarshmallow
softmarshmallow marked this pull request as ready for review May 23, 2025 08:15
@softmarshmallow softmarshmallow changed the title [Grida Canvas] Hierarchy DnD cf235 [Grida Canvas] Hierarchy Tree DnD May 23, 2025
@softmarshmallow
softmarshmallow merged commit 413784a into main May 23, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (9)
packages/grida-tree/README.md (1)

1-3: Expand README with usage and examples
The README is very minimal. Consider adding installation instructions, API reference, and code examples demonstrating how to use the mv function (e.g., moving nodes in a tree). This will help consumers onboard quickly and understand the package capabilities.

editor/scaffolds/sidecontrol/controls/border.tsx (1)

59-60: Remove unnecessary React fragments.

The static analysis tool correctly identified unnecessary fragments around the text content.

Apply this diff to remove the unnecessary fragments:

-            {value?.borderStyle === "solid" && <>Solid</>}
-            {value?.borderStyle === "dashed" && <>Dashed</>}
+            {value?.borderStyle === "solid" && "Solid"}
+            {value?.borderStyle === "dashed" && "Dashed"}
🧰 Tools
🪛 Biome (1.9.4)

[error] 59-59: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)


[error] 60-60: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)

editor/grida-react-canvas/reducers/index.ts (1)

112-112: Consider using consistent ID generation for scene duplication.

Scene duplication still uses nid() while new scenes use v4(). For consistency, consider using v4() here as well.

-        id: nid(),
+        id: v4(),
packages/grida-tree/src/lib.ts (2)

44-58: Consider potential performance optimization for large trees.

The current implementation uses Object.values(nodes) to find the parent of each source node, which has O(n) complexity per source node. For large trees with many nodes, this could be inefficient.

Consider optimizing for scenarios with large node counts:

// Alternative approach: maintain parent-child mapping
+ const findParent = (nodeId: string): string | null => {
+   for (const [parentId, node] of Object.entries(nodes)) {
+     if (node.children?.includes(nodeId)) return parentId;
+   }
+   return null;
+ };

  for (const src of srcs) {
    if (!(src in nodes)) {
      throw new Error(`mv: cannot move '${src}': No such node`);
    }

-   // detach from old parent (if any)
-   for (const node of Object.values(nodes)) {
-     const list = node.children;
-     if (!list) continue;
-     const i = list.indexOf(src);
-     if (i !== -1) {
-       list.splice(i, 1);
-       break;
-     }
-   }
+   const parentId = findParent(src);
+   if (parentId) {
+     const parentChildren = nodes[parentId].children!;
+     const index = parentChildren.indexOf(src);
+     parentChildren.splice(index, 1);
+   }

67-68: Consider adding cycle detection for enhanced safety.

While the documentation mentions that cycle detection is not performed, adding a basic check could prevent infinite loops in UI hierarchies.

Consider adding cycle detection:

+ // Basic cycle detection: ensure target is not a descendant of any source
+ const isDescendant = (ancestor: string, node: string): boolean => {
+   const queue = [node];
+   const visited = new Set<string>();
+   
+   while (queue.length > 0) {
+     const current = queue.shift()!;
+     if (visited.has(current)) continue;
+     visited.add(current);
+     
+     if (current === ancestor) return true;
+     
+     const children = nodes[current]?.children;
+     if (children) queue.push(...children);
+   }
+   return false;
+ };
+ 
+ for (const src of srcs) {
+   if (isDescendant(src, target)) {
+     throw new Error(`mv: cannot move '${src}' to '${target}': Would create cycle`);
+   }
+ }

  return nodes;
editor/grida-react-canvas-starter-kit/starterkit-hierarchy/index.tsx (3)

120-122: Add TODO comment or implement scene reordering.

The onDrop handler is empty. If scene reordering is not yet supported, add a TODO comment to indicate this is intentional.

     onDrop(items, target) {
-      //
+      // TODO: Implement scene reordering
     },

347-349: Consider optimizing tree rebuilds for better performance.

Rebuilding the entire tree on every document change could cause performance issues with large hierarchies. Consider using more granular updates or memoization.

   useEffect(() => {
-    tree.rebuildTree();
-  }, [document]);
+    // Only rebuild when structure changes, not on every property update
+    const structureKey = Object.keys(document.nodes).join(',');
+    tree.rebuildTree();
+  }, [structureKey]);

157-159: Document the setTimeout workaround.

While the 200ms delay is explained in the context, consider adding a brief inline comment for clarity.

             onStartRenaming={() => {
+              // Delay to prevent blur from context menu closing
               setTimeout(() => {
                 item.startRenaming();
               }, 200);
             }}

Also applies to: 366-368

packages/grida-canvas-schema/.ref/figma.d.ts (1)

28-30: Comprehensive API additions for collaboration and workflow features.

The new APIs provide essential functionality:

  • User/collaboration: Current user, active users with position tracking
  • Payments: Monetization support with trial/paid states
  • Annotations: Design feedback with categories and markdown support
  • Timer: Time-based operations for presentations/prototypes
  • Markdown support: Added to descriptions, annotations, and measurements

Note: Consider standardizing the markdown field naming pattern (some use descriptionMarkdown, others use labelMarkdown).

Also applies to: 326-338, 401-401, 2028-2028, 2083-2083, 2130-2130, 2156-2157, 2162-2163, 3171-3184

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6414c7b and 8e85849.

⛔ Files ignored due to path filters (2)
  • packages/grida-canvas-schema/.ref/vectornetwork/vectornetwork.png is excluded by !**/*.png
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (27)
  • editor/components/formfield/grida-canvas/index.tsx (1 hunks)
  • editor/components/ui-editor/tree.tsx (3 hunks)
  • editor/grida-canvas-utils/.ref/examples.ts (0 hunks)
  • editor/grida-react-canvas-starter-kit/starterkit-hierarchy/index.tsx (1 hunks)
  • editor/grida-react-canvas/action.ts (2 hunks)
  • editor/grida-react-canvas/provider.tsx (3 hunks)
  • editor/grida-react-canvas/reducers/document.reducer.ts (1 hunks)
  • editor/grida-react-canvas/reducers/index.ts (2 hunks)
  • editor/grida-react-canvas/reducers/methods/move.ts (1 hunks)
  • editor/package.json (1 hunks)
  • editor/scaffolds/sidebar/sidebar-node-hierarchy-list.tsx (1 hunks)
  • editor/scaffolds/sidecontrol/controls/border.tsx (1 hunks)
  • editor/scaffolds/sidecontrol/controls/box-shadow.tsx (2 hunks)
  • editor/scaffolds/sidecontrol/controls/color.tsx (1 hunks)
  • editor/scaffolds/sidecontrol/controls/paint.tsx (1 hunks)
  • editor/scaffolds/sidecontrol/controls/utils/paint-chip.tsx (3 hunks)
  • packages/grida-canvas-schema/.ref/examples/static/1.ts (2 hunks)
  • packages/grida-canvas-schema/.ref/examples/static/2.ts (2 hunks)
  • packages/grida-canvas-schema/.ref/examples/static/3.ts (2 hunks)
  • packages/grida-canvas-schema/.ref/figma.d.ts (47 hunks)
  • packages/grida-tree/LICENSE (1 hunks)
  • packages/grida-tree/README.md (1 hunks)
  • packages/grida-tree/__tests__/mv.test.ts (1 hunks)
  • packages/grida-tree/index.ts (1 hunks)
  • packages/grida-tree/package.json (1 hunks)
  • packages/grida-tree/src/lib.ts (1 hunks)
  • packages/grida-tree/tsconfig.json (1 hunks)
💤 Files with no reviewable changes (1)
  • editor/grida-canvas-utils/.ref/examples.ts
🧰 Additional context used
🧬 Code Graph Analysis (10)
editor/scaffolds/sidecontrol/controls/border.tsx (1)
editor/scaffolds/sidecontrol/controls/utils/paint-chip.tsx (1)
  • RGBAChip (23-46)
editor/scaffolds/sidecontrol/controls/box-shadow.tsx (1)
editor/scaffolds/sidecontrol/controls/utils/paint-chip.tsx (1)
  • PaintChip (6-21)
editor/scaffolds/sidecontrol/controls/paint.tsx (1)
editor/scaffolds/sidecontrol/controls/utils/paint-chip.tsx (1)
  • PaintChip (6-21)
editor/scaffolds/sidecontrol/controls/color.tsx (1)
editor/scaffolds/sidecontrol/controls/utils/paint-chip.tsx (1)
  • RGBAChip (23-46)
packages/grida-tree/__tests__/mv.test.ts (1)
packages/grida-tree/src/lib.ts (1)
  • mv (26-68)
packages/grida-canvas-schema/.ref/examples/static/3.ts (1)
packages/grida-canvas-cg/index.ts (1)
  • cg (1-1)
editor/grida-react-canvas/provider.tsx (1)
packages/grida-tree/src/lib.ts (1)
  • mv (26-68)
editor/grida-react-canvas/reducers/document.reducer.ts (1)
editor/grida-react-canvas/reducers/methods/move.ts (1)
  • self_moveNode (8-49)
editor/scaffolds/sidecontrol/controls/utils/paint-chip.tsx (2)
packages/grida-canvas-cg/lib.ts (4)
  • Paint (281-281)
  • RGBA8888 (107-124)
  • LinearGradientPaint (317-322)
  • RadialGradientPaint (324-329)
editor/components/lib/utils/index.ts (1)
  • cn (4-6)
editor/grida-react-canvas/action.ts (1)
packages/grida-canvas-schema/grida.ts (2)
  • NodeID (806-806)
  • NodeID (2109-2109)
🪛 Biome (1.9.4)
editor/scaffolds/sidecontrol/controls/border.tsx

[error] 59-59: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)


[error] 60-60: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)

editor/grida-react-canvas/reducers/document.reducer.ts

[error] 335-335: This code is unreachable

(lint/correctness/noUnreachable)

packages/grida-canvas-schema/.ref/figma.d.ts

[error] 509-510: An empty interface is equivalent to {}.

Safe fix: Use a type alias instead.

(lint/suspicious/noEmptyInterface)

🔇 Additional comments (47)
packages/grida-canvas-schema/.ref/examples/static/2.ts (3)

1-1:

Details

✅ Verification successful

Verify the import change is consistent across the codebase.

The import has been changed from a named import to a default import. This suggests a structural change in the module exports that could be a breaking change if not updated consistently.


🏁 Script executed:

#!/bin/bash
# Description: Verify all imports of grida are updated consistently across the codebase
# Expected: All imports should use the new default import syntax

echo "=== Checking for old named import patterns ==="
rg "import.*\{.*grida.*\}.*from.*grida" --type ts --type js

echo "=== Checking for new default import patterns ==="
rg "import grida from.*grida" --type ts --type js

echo "=== Checking other grida import patterns ==="
rg "import.*grida" --type ts --type js -A 1 -B 1

Length of output: 73424


Import change verified: default import used consistently across the codebase

A search for import { grida } returned no results—every module now uses the import grida from "@grida/schema" syntax. No further updates are needed here.


95-95:

Details

✅ Verification successful

Verify the property rename from textures to bitmaps is consistent.

The property has been renamed from textures to bitmaps, which suggests a terminology change in the schema. This could be a breaking change if other parts of the codebase still reference the old property name.


🏁 Script executed:

#!/bin/bash
# Description: Verify all references to textures/bitmaps are updated consistently
# Expected: No remaining references to old 'textures' property in schema contexts

echo "=== Checking for remaining 'textures' references ==="
rg "textures" --type ts --type js -C 3

echo "=== Checking for 'bitmaps' usage ==="
rg "bitmaps" --type ts --type js -C 2

echo "=== Checking schema interface definitions ==="
ast-grep --pattern 'interface $_ {
  $$$
  textures: $_
  $$$
}'

echo "=== Checking type definitions with bitmaps ==="
ast-grep --pattern 'interface $_ {
  $$$
  bitmaps: $_
  $$$
}'

Length of output: 12253


Consistent rename from textures to bitmaps

All schema interfaces and code references have been updated—there are no remaining .textures properties. The only occurrences of “textures” are in user-facing strings (e.g. printing page descriptions and search category labels), which don’t refer to the schema field.


4-97:

Details

✅ Verification successful

Verify the removal of root_id property doesn't break dependent code.

According to the AI summary, the root_id property was removed from this schema definition. This could be a breaking change if other parts of the codebase depend on this property.


🏁 Script executed:

#!/bin/bash
# Description: Verify no code depends on the removed root_id property
# Expected: No remaining references to root_id in document schemas

echo "=== Checking for root_id references ==="
rg "root_id" --type ts --type js -C 3

echo "=== Checking for rootId references (camelCase variant) ==="
rg "rootId" --type ts --type js -C 3

echo "=== Checking IDocumentDefinition interface ==="
ast-grep --pattern 'interface IDocumentDefinition {
  $$$
}'

Length of output: 7368


No active code depends on root_id; removal is safe

Searches for root_id/rootId turned up only documentation comments and commented-out example code—not any live references to document.root_id. The interface definition no longer includes this property, and all runtime code has been updated to compute or pass the root ID explicitly.

• Documentation mentions in packages/grida-canvas-schema/grida.ts (JSDoc)
• Commented-out examples in editor/grida-react-canvas/provider.tsx and reducers/document.reducer.ts
• No occurrences of document.root_id in active TS/JS code

You can safely resolve this change.

packages/grida-canvas-schema/.ref/examples/static/3.ts (3)

1-2: LGTM! Import refactoring aligns with package restructuring.

The change from named import to default import for grida and the addition of the separate @grida/cg import are consistent with the package restructuring mentioned in the AI summary. This aligns with the relevant code snippet showing cg as a default export.


4-10:

Details

✅ Verification successful

Verify type consistency with @grida/cg package.

The function signature and return type have been updated to use cg.RGBA8888 instead of the previous type. The satisfies operator ensures type safety.

Please verify that the cg.RGBA8888 type from @grida/cg is compatible with the previous type to ensure no breaking changes:


🏁 Script executed:

#!/bin/bash
# Description: Verify the RGBA8888 type definition in @grida/cg package
# Expected: Type should have r, g, b, a properties matching the usage

ast-grep --pattern $'export type RGBA8888 = {
  $$$
}'

Length of output: 2011


Type consistency verified for RGBA8888

  • Located RGBA8888 in packages/grida-canvas-cg/lib.ts (lines 107–124) and packages/grida-cmath/index.ts (lines 3260–3277); it defines r, g, b: number (0–255) and a: number (0–1).
  • The object returned by randcolor() matches these properties and is correctly validated by the satisfies operator.

No breaking changes introduced.


83-83:

Details

✅ Verification successful

Verify schema compatibility after renaming textures to bitmaps.

The property has been renamed from textures to bitmaps as part of the schema evolution. This could be a breaking change if other parts of the codebase still reference the old property name.

Please verify that all references to the old textures property have been updated:


🏁 Script executed:

#!/bin/bash
# Description: Check for any remaining references to 'textures' property in schema-related files
# Expected: No references to old 'textures' property in document definitions

rg -A 3 -B 3 'textures.*:' --type ts

Length of output: 38


Schema rename verification passed: no remaining textures references

  • Ran rg -A3 -B3 'textures.*:' --type ts across the codebase → no matches found
  • Confirmed that the property has been fully renamed from textures to bitmaps without lingering references
editor/scaffolds/sidecontrol/controls/utils/paint-chip.tsx (4)

3-4: LGTM! Proper type-only import and utility usage.

The change to type cg import is correct since cg is only used for type annotations in this file. The addition of the cn utility import enables proper class name merging.


6-21: LGTM! Clean and backward-compatible enhancement.

The addition of the optional className prop to PaintChip and its proper forwarding to child components is well-implemented. The change maintains backward compatibility while enabling external styling customization.


23-46: LGTM! Proper class name merging implementation.

The RGBAChip component correctly uses the cn utility to merge the default classes with the optional className prop. The existing styling and functionality remain unchanged.


48-71: LGTM! Consistent implementation across gradient components.

Both LinearGradientPaintChip and RadialGradientPaintChip components follow the same pattern as RGBAChip, ensuring consistency across all paint chip components.

editor/components/formfield/grida-canvas/index.tsx (1)

15-15:

Details

✅ Verification successful

Verify component interface compatibility.

The import path has been changed from the local sidebar implementation to the starter kit. This aligns with the PR's objective of using external hierarchy components.

Please verify that the NodeHierarchyList component from the starter kit has the same interface as the previous implementation:


🏁 Script executed:

#!/bin/bash
# Description: Compare the component interfaces to ensure compatibility
# Expected: Same component props and API

ast-grep --pattern $'export function NodeHierarchyList($$$) {
  $$$
}'

Length of output: 17456


🏁 Script executed:

#!/bin/bash
# Display import and usage of NodeHierarchyList in form field component
rg -n 'NodeHierarchyList' -C3 editor/components/formfield/grida-canvas/index.tsx

Length of output: 657


✅ NodeHierarchyList interface compatibility confirmed.

Both the original local implementation and the new starter-kit export declare export function NodeHierarchyList() (no props), and the component is used as <NodeHierarchyList /> in editor/components/formfield/grida-canvas/index.tsx. No API changes are required.

editor/scaffolds/sidecontrol/controls/color.tsx (1)

36-36: LGTM! Consistent styling enhancement.

The addition of className="rounded-sm" to the RGBAChip component utilizes the newly added className prop from the paint-chip utility. This provides consistent styling across the UI controls as mentioned in the AI summary.

editor/scaffolds/sidecontrol/controls/paint.tsx (1)

145-145: Apply consistent rounded styling to solid paint chip
Adding className="rounded-sm" aligns with other controls and leverages the updated PaintChip prop. Implementation looks correct and maintains visual consistency.

editor/package.json (1)

44-44: Add workspace dependency for @grida/tree
The new @grida/tree package is correctly added as a workspace dependency. Ensure that the workspace link resolves and the package is properly built before publishing or running the editor.

editor/scaffolds/sidecontrol/controls/box-shadow.tsx (1)

51-54: Consistent rounded styling for paint chips
The rounded-sm class is correctly applied to both PaintChip instances, matching updates in other controls. This enhances UI consistency without altering functionality.

Also applies to: 79-79

packages/grida-tree/index.ts (1)

1-1: LGTM! Clean package entry point.

This follows the standard barrel export pattern for creating a clean public API for the @grida/tree package.

editor/scaffolds/sidecontrol/controls/border.tsx (2)

55-58: Good styling consistency improvement.

Adding the rounded-sm class aligns with the styling consistency improvements across paint chip components mentioned in the AI summary.


61-67: Good accessibility improvement with semantic element change.

The change from <button> to <span role="button"> with proper ARIA attributes maintains accessibility while providing more styling flexibility. The ms-auto class correctly positions the remove button to the right.

packages/grida-tree/tsconfig.json (1)

1-6: Excellent TypeScript configuration for type safety.

The strict typing configuration (noImplicitAny: true and strict: true) is perfect for a utility package that handles tree manipulation logic. This will help prevent runtime errors and ensure robust type safety.

packages/grida-tree/LICENSE (1)

1-22: Standard MIT License properly applied.

The MIT License is a good choice for an open source utility package, providing clear permissions and limitations. The copyright notice is properly formatted with the correct year and organization.

editor/grida-react-canvas/reducers/index.ts (1)

14-14: Good improvement using UUID v4 for scene IDs.

Using UUID v4 provides better uniqueness guarantees compared to the custom nid() function.

Also applies to: 65-65

packages/grida-canvas-schema/.ref/examples/static/1.ts (2)

1-1: Schema import updated to use default export.

The change from named import to default import aligns with the schema module's updated export structure.


317-317: Property renamed from textures to bitmaps.

This naming change appears to be part of a broader schema update for better semantic clarity.

editor/grida-react-canvas/reducers/document.reducer.ts (1)

328-334: Multi-node move functionality implemented correctly.

The new "mv" action case properly handles moving multiple nodes by iterating over the source array and calling self_moveNode for each node. The implementation follows the established pattern in the reducer.

editor/grida-react-canvas/provider.tsx (2)

1689-1699: Multi-node move function implemented correctly.

The mv function provides a clean API for moving multiple nodes with proper memoization. The function signature aligns with the corresponding action interface and follows the established patterns in the provider.


1991-1991: Function properly exposed in the document hook API.

The mv function is correctly included in both the return object and dependency array, ensuring proper memoization and API exposure.

Also applies to: 2050-2050

editor/components/ui-editor/tree.tsx (3)

93-93: LGTM: CSS group modifier addition enhances styling capabilities.

The addition of "group/item" class provides better CSS targeting for item-specific styling in hierarchical contexts.


106-110: LGTM: Renaming state attribute supports enhanced UX.

The conditional data-renaming attribute properly reflects the item's renaming state, enabling CSS-based styling for rename operations. The implementation correctly handles the optional nature of the isRenaming method.


158-158:

Details

❓ Verification inconclusive

Verify padding adjustment impact on visual hierarchy.

The padding reduction from ps-7 to ps-5 for non-folder items decreases indentation by 8px (0.5rem). Please ensure this change maintains clear visual hierarchy and doesn't negatively impact usability.


🏁 Script executed:

#!/bin/bash
# Description: Search for any CSS classes or style references that might conflict with the new padding
# Expected: Find other padding or indentation styles that might need adjustment

echo "Searching for related padding/indentation styles in tree components..."
rg -A 3 -B 3 "ps-[0-9]|pl-[0-9]|indent" --type tsx --type ts

Length of output: 241


To get a more complete view of how padding and indentation classes are used across your TS/TSX files, let’s run a broader search without the unsupported --type filter:


🏁 Script executed:

#!/bin/bash
echo "Searching for all ps-*, pl-* and indent-* utilities in .tsx/.ts files..."
rg -n -A3 -B3 -E '(ps|pl|indent)-[0-9]+' -g '*.tsx' -g '*.ts'

Length of output: 615


Let’s fall back to a plain grep search to cover TS/TSX files:


🏁 Script executed:

#!/bin/bash
echo "Searching for ps-*, pl-* and indent-* utilities in .tsx/.ts via grep..."
grep -R -n -E '(ps|pl|indent)-[0-9]+' --include='*.tsx' --include='*.ts' .

Length of output: 12633


Verify Tree item indentation consistency

We didn’t find any other ps-7 or related indentation classes in the Tree component or elsewhere in this file—this change only applies at:

  • editor/components/ui-editor/tree.tsx (line 158)

Please confirm that the reduced padding (ps-5) for non-folder items still communicates the nesting hierarchy clearly across all tree levels and aligns with spacing conventions elsewhere in the app.

packages/grida-tree/__tests__/mv.test.ts (1)

1-99: Excellent test coverage for the mv function.

The test suite comprehensively covers:

  • Basic single and multiple node moves
  • Error handling for non-existent source and target nodes
  • Reordering within the same parent
  • Advanced scenarios with specific indices and bulk operations
  • Edge cases like appending with index -1

The test structure is clear and the expectations match the documented behavior of the mv function.

editor/grida-react-canvas/action.ts (3)

45-45: LGTM: Action type refactoring improves extensibility.

Replacing EditorHierarchyOrderAction with the union type EditorHierarchyAction allows for future hierarchy action types while maintaining existing functionality.


223-225: LGTM: Well-structured union type for hierarchy actions.

The EditorHierarchyAction union type properly combines ordering and moving actions, providing a clean interface for different hierarchy operations.


236-237: LGTM: Simplified action structure aligns with mv function.

The simplified structure with target: NodeID and optional index?: number matches the signature of the mv function from the @grida/tree package, ensuring consistency across the codebase.

packages/grida-tree/src/lib.ts (4)

1-25: Comprehensive documentation sets clear expectations.

The JSDoc documentation clearly explains the function's behavior, parameters, mutations, and limitations. The example is helpful and the remarks about non-recursiveness and cycle detection are important caveats.


26-34: Function signature and parameter handling look solid.

The generic type constraint T extends Partial<{ children: string[] }> properly ensures compatibility while maintaining flexibility. Parameter normalization to array format is clean.


36-42: Robust validation for target node.

The validation properly checks for both node existence and the presence of the children array, providing clear error messages for debugging.


60-65: Index positioning logic handles edge cases well.

The insertion logic properly handles both specified and unspecified indices, ensuring nodes are appended when the index exceeds the array length. The increment of pos for multiple nodes maintains proper ordering.

editor/grida-react-canvas/reducers/methods/move.ts (3)

26-30: LGTM! Elegant virtual tree abstraction.

The virtual tree construction that includes the scene as a root node with ID "<root>" is a clean solution for uniform handling of moves to both root level and nested nodes.


44-44: Good refactoring to use the centralized tree manipulation utility.

Replacing manual tree manipulation with the mv function improves maintainability and reduces the chance of bugs in tree operations.


4-4:

Details

❓ Verification inconclusive

Verify the @grida/tree package is properly added as a dependency.

The import references a new package that should be added to the project dependencies.


🏁 Script executed:

#!/bin/bash
# Description: Verify that @grida/tree is properly added as a dependency

# Check if the package is listed in package.json files
fd package.json --exec grep -l "@grida/tree" {} \;

# Check if the package exists in the workspace
fd -t d "grida-tree" packages/

Length of output: 162


✅ @grida/tree dependency confirmed

The @grida/tree package is listed in editor/package.json and the packages/grida-tree/ directory exists in the workspace. You can now proceed with reviewing the virtual tree construction and constraint-checking logic.

editor/scaffolds/sidebar/sidebar-node-hierarchy-list.tsx (1)

13-15: Excellent refactoring to use dedicated hierarchy components.

Moving the complex tree UI logic to a separate starter kit module improves maintainability and reusability. The simplified sidebar components are now much cleaner and focused.

editor/grida-react-canvas-starter-kit/starterkit-hierarchy/index.tsx (2)

445-583: Well-documented complex event handling in NameInput.

The extensive documentation explaining the complexity of event handling is excellent. The implementation correctly handles multiple edge cases for rename operations.


43-43:

Details

✅ Verification successful

Verify NodeTypeIcon component exists.

Ensure the imported NodeTypeIcon component is available in the starter kit icons module.


🏁 Script executed:

#!/bin/bash
# Description: Verify NodeTypeIcon component exists

# Search for NodeTypeIcon component definition
fd -e tsx -e ts | xargs rg "export.*NodeTypeIcon" -A 2

# Check the specific import path
fd node-type-icon.tsx starterkit-icons/

Length of output: 477


NodeTypeIcon component verified
The NodeTypeIcon is exported from editor/grida-react-canvas-starter-kit/starterkit-icons/node-type-icon.tsx, so the import path is correct and no changes are needed.

packages/grida-canvas-schema/.ref/figma.d.ts (4)

129-130: Well-structured slide management API implementation.

The slide-related additions provide a comprehensive API for slide editing:

  • Slide creation methods (createSlide, createSlideRow)
  • Grid management (getSlideGrid, setSlideGrid)
  • Slide node types with proper hierarchy
  • Transition effects with extensive style options
  • Event handling for view changes

The implementation follows consistent patterns with the existing API structure.

Also applies to: 251-252, 609-611, 2996-3058


1164-1214: Excellent additions for advanced visual effects.

The new effect types significantly enhance the visual capabilities:

  • Progressive blur: Allows gradient-like blur effects with start/end points
  • Noise effects: Three variants (monotone, duotone, multitone) for texture overlays
  • Texture effect: Adds organic texture capabilities
  • Pattern paint: Enables tiled pattern fills with various tiling options

These additions align well with modern design tool requirements.

Also applies to: 1282-1298


880-903: Comprehensive text decoration API matching modern CSS capabilities.

The text decoration enhancements provide professional typography control:

  • Decoration styles: solid, wavy, dotted (matching CSS)
  • Precise positioning: offset and thickness with pixel/percent units
  • Color control: independent decoration colors or auto-inherit
  • Skip ink: proper handling of descenders
  • Range-based application: Apply decorations to specific text ranges

The API design is consistent with existing text manipulation methods.

Also applies to: 2191-2376


1900-1904: Valuable node type additions for enhanced design capabilities.

The new node types and AspectRatioLockMixin provide important functionality:

  • AspectRatioLockMixin: Essential for maintaining proportions during resize operations
  • TextPathNode: Enables text along vector paths for creative typography
  • TransformGroupNode: Allows transformation-based grouping without rasterization
  • WashiTapeNode: Adds decorative tape element for annotations/emphasis

These additions enhance both functional and creative aspects of the design tool.

Also applies to: 2469-2482, 2567-2583, 2729-2735

Comment on lines +1 to +11
{
"name": "@grida/tree",
"version": "0.0.0",
"private": true,
"scripts": {
"test": "jest"
},
"jest": {
"preset": "ts-jest"
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Specify package entry points and files
The new @grida/tree package.json is missing fields that guide consumers and tooling to the correct build artifacts. Add "main", "module", and "types" along with a "files" array, and include a build script to compile TypeScript sources.

Example diff:

 {
   "name": "@grida/tree",
   "version": "0.0.0",
   "private": true,
+  "main": "dist/index.js",
+  "module": "dist/index.esm.js",
+  "types": "dist/index.d.ts",
+  "files": ["dist"],
   "scripts": {
-    "test": "jest"
+    "build": "tsc --outDir dist",
+    "test": "jest"
   },
   "jest": {
     "preset": "ts-jest"
   }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
"name": "@grida/tree",
"version": "0.0.0",
"private": true,
"scripts": {
"test": "jest"
},
"jest": {
"preset": "ts-jest"
}
}
{
"name": "@grida/tree",
"version": "0.0.0",
"private": true,
"main": "dist/index.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
"files": ["dist"],
"scripts": {
"build": "tsc --outDir dist",
"test": "jest"
},
"jest": {
"preset": "ts-jest"
}
}
🤖 Prompt for AI Agents
In packages/grida-tree/package.json lines 1 to 11, the package.json lacks
essential fields like "main", "module", "types", and a "files" array to specify
entry points and included files for consumers and tooling. Add these fields
pointing to the appropriate build output files (e.g., "dist/index.js" for main
and module, "dist/index.d.ts" for types), include a "files" array listing the
"dist" directory, and add a "build" script to compile TypeScript sources (e.g.,
"tsc -p tsconfig.json").

self_moveNode(draft, node_id, target, index);
}
});
break;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unreachable break statement.

The break statement after the return is unreachable and should be removed.

-      });
-      break;
+      });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
break;
});
🧰 Tools
🪛 Biome (1.9.4)

[error] 335-335: This code is unreachable

(lint/correctness/noUnreachable)

🤖 Prompt for AI Agents
In editor/grida-react-canvas/reducers/document.reducer.ts at line 335, remove
the break statement that appears immediately after a return statement, as it is
unreachable and unnecessary.

input.removeEventListener("keydown", handleKeyDown, true);
}
};
}, [ref.current, initialValue, onValueCommit, value]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix useEffect dependency - ref.current doesn't trigger re-runs.

Using ref.current in the dependency array is incorrect because ref mutations don't trigger effect re-runs. Consider using a callback ref pattern or removing it from dependencies.

-  }, [ref.current, initialValue, onValueCommit, value]);
+  }, [initialValue, onValueCommit, value]);
🤖 Prompt for AI Agents
In editor/grida-react-canvas-starter-kit/starterkit-hierarchy/index.tsx at line
543, the useEffect dependency array incorrectly includes ref.current, which does
not trigger re-runs on mutation. Remove ref.current from the dependency array
and if necessary, replace the ref with a callback ref or another stateful value
that properly triggers the effect when it changes.

declare type AuthResult = {
type: "AUTH_SUCCESS";
} | null;
interface VSCodeAPI {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the empty interface by using a type alias.

An empty interface is equivalent to {}. Consider using a type alias instead for better clarity and to avoid linting issues.

Apply this diff to fix the empty interface:

-interface VSCodeAPI {}
+type VSCodeAPI = {};

Alternatively, if this is a placeholder for future API methods, consider adding a comment to indicate that:

-interface VSCodeAPI {}
+interface VSCodeAPI {
+  // TODO: VSCode API methods will be added here
+}
🧰 Tools
🪛 Biome (1.9.4)

[error] 509-510: An empty interface is equivalent to {}.

Safe fix: Use a type alias instead.

(lint/suspicious/noEmptyInterface)

🤖 Prompt for AI Agents
In packages/grida-canvas-schema/.ref/figma.d.ts at line 510, replace the empty
interface VSCodeAPI with a type alias to an empty object type for clarity and to
avoid linting issues. Change "interface VSCodeAPI {}" to "type VSCodeAPI = {}".
If this is intended as a placeholder for future methods, add a comment above it
indicating that purpose.

This branch was successfully deployed

1 active and 4 inactive deployments
Preview – grida — 8e858497 Deployed May 23, 2025 by vercel[bot]
Preview – blog — 8e858497 Deployed May 23, 2025 by vercel[bot]
Preview – backgrounds — 8e858497 Deployed May 23, 2025 by vercel[bot]
Preview – docs — 8e858497 Deployed May 23, 2025 by vercel[bot]
Preview – viewer — 8e858497 Deployed May 23, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant