-
Notifications
You must be signed in to change notification settings - Fork 123
FE-1509: Add the notebook cell list as an experimental mode #9407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
libs/@hashintel/petrinaut/src/react/state/use-effective-global-mode.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { use } from "react"; | ||
|
|
||
| import { EditorContext } from "./editor-context"; | ||
| import { UserSettingsContext } from "./user-settings-context"; | ||
|
|
||
| import type { EditorGlobalMode } from "./editor-context"; | ||
|
|
||
| /** | ||
| * The global mode the editor actually renders. The stored mode can say | ||
| * "notebook" while the experimental notebook flag is off (e.g. the flag was | ||
| * disabled while the view was active); every consumer must agree that this | ||
| * falls back to "edit" β deriving it in one consumer only would render the | ||
| * edit canvas while mutations are still refused with a notebook explanation. | ||
| */ | ||
| export const useEffectiveGlobalMode = (): EditorGlobalMode => { | ||
| const { globalMode } = use(EditorContext); | ||
| const { enableNotebookView } = use(UserSettingsContext); | ||
|
|
||
| return globalMode === "notebook" && !enableNotebookView ? "edit" : globalMode; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
libs/@hashintel/petrinaut/src/react/state/use-undo-redo-shortcuts.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { use, useEffect, useEffectEvent } from "react"; | ||
|
|
||
| import { UndoRedoContext } from "./undo-redo-context"; | ||
|
|
||
| /** | ||
| * Binds Cmd/Ctrl+Z (undo) and Cmd/Ctrl+Shift+Z (redo) for views that don't | ||
| * mount the canvas BottomBar, which owns the full editor shortcut set. | ||
| * Inputs, textareas and code editors are left alone so their native undo | ||
| * stacks keep working. | ||
| */ | ||
| export function useUndoRedoShortcuts() { | ||
| const undoRedo = use(UndoRedoContext); | ||
|
|
||
| const handleKeyDown = useEffectEvent((event: KeyboardEvent) => { | ||
| if ( | ||
| !undoRedo || | ||
| !(event.metaKey || event.ctrlKey) || | ||
| event.key.toLowerCase() !== "z" | ||
| ) { | ||
| return; | ||
| } | ||
| const target = event.target as HTMLElement; | ||
| const isInputFocused = | ||
| target.tagName === "INPUT" || | ||
| target.tagName === "TEXTAREA" || | ||
| target.isContentEditable || | ||
| target.closest(".monaco-editor") !== null; | ||
| if (isInputFocused) { | ||
| return; | ||
| } | ||
| event.preventDefault(); | ||
| if (event.shiftKey) { | ||
| undoRedo.redo(); | ||
| } else { | ||
| undoRedo.undo(); | ||
| } | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| window.addEventListener("keydown", handleKeyDown); | ||
| return () => { | ||
| window.removeEventListener("keydown", handleKeyDown); | ||
| }; | ||
| }, []); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --- | ||
| layer: ui.views.notebook | ||
| role: Notebook view β the net as expandable cells with editable code, dependency analysis, and a whole-net graph explorer | ||
| --- | ||
|
|
||
| The notebook renders the net as a flat list of cells, one per entity, so a | ||
| model reads like a program: declarations and the flow that uses them. It replaces the canvas and its | ||
| panels wholesale, which is what lets its Monaco editors reuse the LSP | ||
| document URIs β a model is never mounted twice. | ||
|
|
||
| Everything an expanded cell shows edits in place β names, fields, arc | ||
| weights, type assignments, and code β through the same guarded mutations as | ||
| the properties panel; only adding and removing nodes, arcs, and fields | ||
| stays in Edit mode. | ||
|
|
||
| The folder splits into a pure core and thin views. `notebook-model`, | ||
| `notebook-order`, `net-cycles`, `net-siphons` and `net-graph-layout` are | ||
| plain functions over the net definition, unit-tested without the DOM; the | ||
| `.tsx` files render their output and own only view state (selection comes | ||
| from the editor, expansion and search live here). The graph explorer draws | ||
| the whole net from the arc structure alone, ignoring canvas positions, so | ||
| the diagram answers "what feeds what" rather than "where did the author | ||
| drag things". |
52 changes: 52 additions & 0 deletions
52
libs/@hashintel/petrinaut/src/ui/views/Notebook/cell-kinds.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /** | ||
| * Shared per-kind presentation for the notebook view, so cells, the graph | ||
| * explorer and the kind filter all give a kind the same icon and label. | ||
| */ | ||
|
|
||
| import { | ||
| DifferentialEquationIcon, | ||
| ParameterIcon, | ||
| PlaceFilledIcon, | ||
| TokenTypeIcon, | ||
| TransitionFilledIcon, | ||
| } from "../../constants/entity-icons"; | ||
|
|
||
| import type { NotebookCellKind } from "./notebook-model"; | ||
| import type { ComponentType } from "react"; | ||
|
|
||
| export const CELL_KIND_ICONS: Record< | ||
| NotebookCellKind, | ||
| ComponentType<{ size: number }> | ||
| > = { | ||
| place: PlaceFilledIcon, | ||
| transition: TransitionFilledIcon, | ||
| type: TokenTypeIcon, | ||
| differentialEquation: DifferentialEquationIcon, | ||
| parameter: ParameterIcon, | ||
| }; | ||
|
|
||
| /** Keyword shown before a cell's name, as a declaration would read. */ | ||
| export const CELL_KIND_LABELS: Record<NotebookCellKind, string> = { | ||
| place: "Place", | ||
| transition: "Transition", | ||
| type: "Type", | ||
| differentialEquation: "Equation", | ||
| parameter: "Parameter", | ||
| }; | ||
|
|
||
| /** Kinds in the order the filter row lists them. */ | ||
| export const CELL_KINDS: NotebookCellKind[] = [ | ||
| "place", | ||
| "transition", | ||
| "type", | ||
| "differentialEquation", | ||
| "parameter", | ||
| ]; | ||
|
|
||
| export const CELL_KIND_PLURAL_LABELS: Record<NotebookCellKind, string> = { | ||
| place: "Places", | ||
| transition: "Transitions", | ||
| type: "Types", | ||
| differentialEquation: "Equations", | ||
| parameter: "Parameters", | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.