nudge-ui 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/README.md +164 -46
  2. package/dist/client.mjs +252 -54
  3. package/dist/css/value-semantics/colorSemantics.d.ts +4 -0
  4. package/dist/css/value-semantics/colorSemantics.js +17 -0
  5. package/dist/hosts/astro/astroRuntimeConfig.js +1 -0
  6. package/dist/hosts/astro/clientTransport.js +41 -32
  7. package/dist/hosts/astro/integration.d.ts +2 -2
  8. package/dist/hosts/astro/integration.js +9 -4
  9. package/dist/hosts/astro/markdownIdentity.d.ts +28 -0
  10. package/dist/hosts/astro/markdownIdentity.js +81 -0
  11. package/dist/hosts/environment.d.ts +15 -0
  12. package/dist/hosts/environment.js +16 -0
  13. package/dist/hosts/next/manifest.js +1 -1
  14. package/dist/hosts/next/sidecar.js +12 -2
  15. package/dist/hosts/next/wrapper.d.ts +2 -0
  16. package/dist/hosts/next/wrapper.js +2 -1
  17. package/dist/hosts/projectBridge.d.ts +1 -0
  18. package/dist/hosts/projectBridge.js +1 -0
  19. package/dist/hosts/static/manifest.js +3 -1
  20. package/dist/hosts/static/server.js +4 -0
  21. package/dist/hosts/vite/vite.d.ts +4 -0
  22. package/dist/hosts/vite/vite.js +28 -5
  23. package/dist/inspector/agent/McpConnectionDialog.d.ts +3 -2
  24. package/dist/inspector/agent/McpConnectionDialog.js +23 -22
  25. package/dist/inspector/agent/activity.d.ts +18 -0
  26. package/dist/inspector/agent/activity.js +70 -0
  27. package/dist/inspector/agent/client.d.ts +8 -0
  28. package/dist/inspector/agent/client.js +65 -5
  29. package/dist/inspector/agent/connectionStatus.d.ts +3 -3
  30. package/dist/inspector/agent/connectionStatus.js +9 -2
  31. package/dist/inspector/agent/httpTransport.d.ts +6 -0
  32. package/dist/inspector/agent/httpTransport.js +50 -3
  33. package/dist/inspector/agent/protocol.d.ts +9 -3
  34. package/dist/inspector/agent/protocol.js +1 -1
  35. package/dist/inspector/agent/verification.d.ts +11 -1
  36. package/dist/inspector/agent/verification.js +53 -25
  37. package/dist/inspector/canvas/AgentActivityOverlay.d.ts +13 -0
  38. package/dist/inspector/canvas/AgentActivityOverlay.js +111 -0
  39. package/dist/inspector/canvas/CanvasCard.d.ts +9 -2
  40. package/dist/inspector/canvas/CanvasCard.js +133 -38
  41. package/dist/inspector/canvas/CanvasElementOverlay.js +200 -22
  42. package/dist/inspector/canvas/CanvasToolIcons.d.ts +10 -0
  43. package/dist/inspector/canvas/CanvasToolIcons.js +20 -0
  44. package/dist/inspector/canvas/CanvasToolbar.js +8 -4
  45. package/dist/inspector/canvas/CanvasWorkspace.js +243 -56
  46. package/dist/inspector/canvas/StaleChangeIndicator.js +3 -13
  47. package/dist/inspector/canvas/agentPresentation.d.ts +8 -8
  48. package/dist/inspector/canvas/agentPresentation.js +64 -52
  49. package/dist/inspector/canvas/canvasGestures.d.ts +1 -1
  50. package/dist/inspector/canvas/canvasGestures.js +1 -1
  51. package/dist/inspector/canvas/canvasStore.d.ts +46 -82
  52. package/dist/inspector/canvas/canvasStore.js +251 -284
  53. package/dist/inspector/canvas/frameContent.d.ts +21 -0
  54. package/dist/inspector/canvas/frameContent.js +44 -0
  55. package/dist/inspector/canvas/frameProtocol.d.ts +34 -4
  56. package/dist/inspector/canvas/frameProtocol.js +9 -2
  57. package/dist/inspector/canvas/keyboardShortcuts.d.ts +4 -1
  58. package/dist/inspector/canvas/keyboardShortcuts.js +5 -3
  59. package/dist/inspector/canvas/layout.d.ts +52 -0
  60. package/dist/inspector/canvas/layout.js +106 -0
  61. package/dist/inspector/canvas/linkEligibility.d.ts +0 -5
  62. package/dist/inspector/canvas/linkEligibility.js +0 -29
  63. package/dist/inspector/canvas/projection.d.ts +15 -5
  64. package/dist/inspector/canvas/projection.js +69 -13
  65. package/dist/inspector/canvas/rendererBootstrap.js +45 -4
  66. package/dist/inspector/canvas/rendererElementSelector.d.ts +1 -1
  67. package/dist/inspector/canvas/rendererElementSelector.js +102 -45
  68. package/dist/inspector/canvas/rendererStylesheet.js +2 -2
  69. package/dist/inspector/canvas/resizeHandleScale.js +1 -1
  70. package/dist/inspector/canvas/sessionStore.d.ts +11 -26
  71. package/dist/inspector/canvas/sessionStore.js +43 -183
  72. package/dist/inspector/canvas/staleChangeDetector.js +9 -3
  73. package/dist/inspector/canvas/useCanvasLayoutAnimation.d.ts +5 -0
  74. package/dist/inspector/canvas/useCanvasLayoutAnimation.js +107 -0
  75. package/dist/inspector/canvas/viewStore.d.ts +38 -0
  76. package/dist/inspector/canvas/viewStore.js +104 -0
  77. package/dist/inspector/canvas/wheelPan.d.ts +8 -0
  78. package/dist/inspector/canvas/wheelPan.js +8 -0
  79. package/dist/inspector/changes/changesLog.d.ts +6 -5
  80. package/dist/inspector/changes/changesLog.js +40 -32
  81. package/dist/inspector/changes/draftChanges.d.ts +56 -0
  82. package/dist/inspector/changes/draftChanges.js +300 -0
  83. package/dist/inspector/changes/previewDiagnostics.d.ts +4 -2
  84. package/dist/inspector/changes/previewDiagnostics.js +11 -25
  85. package/dist/inspector/clientManifest.d.ts +3 -1
  86. package/dist/inspector/clientManifest.js +1 -0
  87. package/dist/inspector/comments/CommentsOverlay.d.ts +2 -0
  88. package/dist/inspector/comments/CommentsOverlay.js +250 -0
  89. package/dist/inspector/comments/element.d.ts +6 -0
  90. package/dist/inspector/comments/element.js +47 -0
  91. package/dist/inspector/comments/store.d.ts +29 -0
  92. package/dist/inspector/comments/store.js +121 -0
  93. package/dist/inspector/comments/verification.d.ts +5 -0
  94. package/dist/inspector/comments/verification.js +52 -0
  95. package/dist/inspector/drafts/model.d.ts +35 -0
  96. package/dist/inspector/drafts/model.js +45 -0
  97. package/dist/inspector/drafts/store.d.ts +28 -0
  98. package/dist/inspector/drafts/store.js +231 -0
  99. package/dist/inspector/index.js +26 -35
  100. package/dist/inspector/inline-text/inlineTextEditor.js +7 -0
  101. package/dist/inspector/inspection/useBrowserCssInspection.js +15 -1
  102. package/dist/inspector/iterations/capture.d.ts +2 -0
  103. package/dist/inspector/iterations/capture.js +173 -0
  104. package/dist/inspector/iterations/client.d.ts +7 -0
  105. package/dist/inspector/iterations/client.js +52 -0
  106. package/dist/inspector/iterations/coordinator.d.ts +15 -0
  107. package/dist/inspector/iterations/coordinator.js +130 -0
  108. package/dist/inspector/iterations/prompt.d.ts +3 -0
  109. package/dist/inspector/iterations/prompt.js +26 -0
  110. package/dist/inspector/overlay/DomNavigator.d.ts +10 -0
  111. package/dist/inspector/overlay/DomNavigator.js +46 -0
  112. package/dist/inspector/overlay/InspectorOverlay.js +6 -2
  113. package/dist/inspector/overlay/clickPolicy.d.ts +18 -2
  114. package/dist/inspector/overlay/clickPolicy.js +34 -3
  115. package/dist/inspector/overlay/elementSelector.d.ts +1 -1
  116. package/dist/inspector/overlay/elementSelector.js +18 -7
  117. package/dist/inspector/overlay/interactionStyles.js +3 -1
  118. package/dist/inspector/overlay/spacingGestures.d.ts +15 -3
  119. package/dist/inspector/overlay/spacingGestures.js +88 -13
  120. package/dist/inspector/projection/{workspaceProjection.d.ts → draftProjection.d.ts} +6 -6
  121. package/dist/inspector/projection/{workspaceProjection.js → draftProjection.js} +4 -4
  122. package/dist/inspector/projection/renderedInstance.d.ts +2 -1
  123. package/dist/inspector/projection/renderedInstance.js +9 -5
  124. package/dist/inspector/projection/structuralProjection.d.ts +2 -1
  125. package/dist/inspector/projection/structuralProjection.js +19 -15
  126. package/dist/inspector/projection/textProjection.d.ts +2 -1
  127. package/dist/inspector/projection/textProjection.js +8 -4
  128. package/dist/inspector/prompt/PromptSettingsDialog.js +1 -5
  129. package/dist/inspector/prompt/clipboardHandoff.d.ts +10 -18
  130. package/dist/inspector/prompt/clipboardHandoff.js +92 -143
  131. package/dist/inspector/prompt/generatePrompt.d.ts +4 -1
  132. package/dist/inspector/prompt/generatePrompt.js +17 -16
  133. package/dist/inspector/runtime/runtimeConfig.d.ts +10 -1
  134. package/dist/inspector/runtime/runtimeConfig.js +24 -0
  135. package/dist/inspector/selection/hierarchy.d.ts +6 -0
  136. package/dist/inspector/selection/hierarchy.js +8 -0
  137. package/dist/inspector/settings/SettingsDialog.d.ts +1 -1
  138. package/dist/inspector/settings/SettingsDialog.js +22 -9
  139. package/dist/inspector/shell/AgentStatusButton.d.ts +11 -0
  140. package/dist/inspector/shell/AgentStatusButton.js +36 -0
  141. package/dist/inspector/shell/AppShell.js +4 -2
  142. package/dist/inspector/shell/ChangesLog.js +47 -27
  143. package/dist/inspector/shell/CopyPromptButton.js +146 -90
  144. package/dist/inspector/shell/EmptyState.js +9 -8
  145. package/dist/inspector/shell/InspectorShell.js +14 -25
  146. package/dist/inspector/shell/PeekOriginalButton.js +24 -23
  147. package/dist/inspector/shell/originalPreview.js +5 -5
  148. package/dist/inspector/shell/shortcuts.d.ts +3 -0
  149. package/dist/inspector/shell/shortcuts.js +11 -0
  150. package/dist/inspector/sketch/SketchEditor.js +14 -14
  151. package/dist/inspector/sketch/SketchEntryButton.js +1 -1
  152. package/dist/inspector/sketch/SketchFrameOverlay.d.ts +3 -1
  153. package/dist/inspector/sketch/SketchFrameOverlay.js +11 -8
  154. package/dist/inspector/sketch/SketchLayersPanel.js +13 -5
  155. package/dist/inspector/sketch/SketchOverlay.js +7 -7
  156. package/dist/inspector/sketch/SketchWorkspace.js +18 -12
  157. package/dist/inspector/sketch/interaction.d.ts +1 -0
  158. package/dist/inspector/sketch/interaction.js +8 -4
  159. package/dist/inspector/sketch/model.d.ts +5 -0
  160. package/dist/inspector/sketch/model.js +6 -2
  161. package/dist/inspector/sketch/raster.d.ts +1 -2
  162. package/dist/inspector/sketch/raster.js +68 -4
  163. package/dist/inspector/sketch/store.js +48 -23
  164. package/dist/inspector/styleEditors/BackgroundEditor.d.ts +4 -0
  165. package/dist/inspector/styleEditors/BackgroundEditor.js +195 -0
  166. package/dist/inspector/styleEditors/BorderEditor.js +49 -78
  167. package/dist/inspector/styleEditors/BorderRadiusEditor.js +6 -1
  168. package/dist/inspector/styleEditors/BoxShadowEditor.d.ts +1 -2
  169. package/dist/inspector/styleEditors/BoxShadowEditor.js +132 -4
  170. package/dist/inspector/styleEditors/ColorPicker.d.ts +5 -1
  171. package/dist/inspector/styleEditors/ColorPicker.js +10 -4
  172. package/dist/inspector/styleEditors/GapField.js +3 -5
  173. package/dist/inspector/styleEditors/GridChildSection.d.ts +1 -1
  174. package/dist/inspector/styleEditors/GridChildSection.js +18 -9
  175. package/dist/inspector/styleEditors/GridPicker.d.ts +1 -1
  176. package/dist/inspector/styleEditors/GridPicker.js +8 -2
  177. package/dist/inspector/styleEditors/GridSection.js +1 -1
  178. package/dist/inspector/styleEditors/GridValueField.js +19 -14
  179. package/dist/inspector/styleEditors/ImageBackgroundEditor.d.ts +18 -0
  180. package/dist/inspector/styleEditors/ImageBackgroundEditor.js +118 -0
  181. package/dist/inspector/styleEditors/LayoutBlockedIndicator.d.ts +2 -2
  182. package/dist/inspector/styleEditors/LayoutBlockedIndicator.js +3 -3
  183. package/dist/inspector/styleEditors/LayoutComboField.js +6 -4
  184. package/dist/inspector/styleEditors/LayoutDropdown.js +6 -3
  185. package/dist/inspector/styleEditors/LayoutSection.js +32 -11
  186. package/dist/inspector/styleEditors/SpacingBox.js +16 -9
  187. package/dist/inspector/styleEditors/Typography.js +11 -3
  188. package/dist/inspector/styleEditors/backgroundLayers.d.ts +24 -0
  189. package/dist/inspector/styleEditors/backgroundLayers.js +51 -0
  190. package/dist/inspector/styleEditors/gradientValue.d.ts +17 -0
  191. package/dist/inspector/styleEditors/gradientValue.js +114 -0
  192. package/dist/inspector/styleEditors/inlineAuthored.d.ts +10 -0
  193. package/dist/inspector/styleEditors/inlineAuthored.js +114 -0
  194. package/dist/inspector/styleEditors/layoutValue.d.ts +0 -8
  195. package/dist/inspector/styleEditors/layoutValue.js +0 -42
  196. package/dist/inspector/styleEditors/nudgeValue.d.ts +4 -4
  197. package/dist/inspector/styleEditors/nudgeValue.js +41 -11
  198. package/dist/inspector/tokens/TokenField.d.ts +7 -0
  199. package/dist/inspector/tokens/TokenField.js +49 -22
  200. package/dist/inspector/tokens/TokenLabel.js +5 -14
  201. package/dist/inspector/tokens/TokensPanel.js +2 -1
  202. package/dist/inspector/tokens/dragPointerLock.d.ts +8 -0
  203. package/dist/inspector/tokens/dragPointerLock.js +70 -0
  204. package/dist/inspector/tokens/editActions.d.ts +1 -1
  205. package/dist/inspector/tokens/editActions.js +1 -1
  206. package/dist/inspector/ui/AtRuleContext.js +4 -6
  207. package/dist/inspector/ui/Button.d.ts +6 -2
  208. package/dist/inspector/ui/Button.js +4 -3
  209. package/dist/inspector/ui/ControlSurface.d.ts +2 -2
  210. package/dist/inspector/ui/ControlSurface.js +4 -3
  211. package/dist/inspector/ui/Disclosure.d.ts +22 -0
  212. package/dist/inspector/ui/Disclosure.js +13 -0
  213. package/dist/inspector/ui/InlineStyleWarning.d.ts +11 -0
  214. package/dist/inspector/ui/InlineStyleWarning.js +13 -0
  215. package/dist/inspector/ui/InspectorPopover.d.ts +2 -1
  216. package/dist/inspector/ui/InspectorPopover.js +4 -5
  217. package/dist/inspector/ui/PopoverListbox.d.ts +2 -1
  218. package/dist/inspector/ui/PopoverListbox.js +8 -7
  219. package/dist/inspector/ui/SegmentedControl.d.ts +2 -1
  220. package/dist/inspector/ui/SegmentedControl.js +2 -2
  221. package/dist/inspector/ui/Select.d.ts +6 -1
  222. package/dist/inspector/ui/Select.js +7 -11
  223. package/dist/inspector/ui/SideValuesField.js +1 -1
  224. package/dist/inspector/ui/Tooltip.d.ts +26 -0
  225. package/dist/inspector/ui/Tooltip.js +32 -0
  226. package/dist/inspector/ui/classNames.d.ts +2 -0
  227. package/dist/inspector/ui/classNames.js +4 -0
  228. package/dist/inspector/ui/customCursors.d.ts +23 -0
  229. package/dist/inspector/ui/customCursors.js +122 -0
  230. package/dist/inspector/ui/dragCursor.d.ts +6 -0
  231. package/dist/inspector/ui/dragCursor.js +13 -0
  232. package/dist/inspector/ui/portalContainer.d.ts +2 -0
  233. package/dist/inspector/ui/portalContainer.js +6 -0
  234. package/dist/inspector/ui/styles.js +34 -24
  235. package/dist/inspector/workspace/commands.d.ts +9 -0
  236. package/dist/inspector/workspace/commands.js +82 -0
  237. package/dist/inspector/workspace/controller.d.ts +4 -0
  238. package/dist/inspector/workspace/controller.js +66 -0
  239. package/dist/inspector/workspace/handoff.d.ts +42 -0
  240. package/dist/inspector/workspace/handoff.js +115 -0
  241. package/dist/inspector/workspace/timeline.d.ts +30 -0
  242. package/dist/inspector/workspace/timeline.js +108 -0
  243. package/dist/internal/agent-protocol.d.ts +19 -2
  244. package/dist/internal/agent-protocol.js +13 -0
  245. package/dist/nudge-ui.mjs +560 -299
  246. package/dist/project/artifacts.d.ts +13 -0
  247. package/dist/project/artifacts.js +253 -0
  248. package/dist/transport/artifacts.d.ts +8 -0
  249. package/dist/transport/artifacts.js +9 -0
  250. package/dist/transport/editor.d.ts +20 -1
  251. package/dist/transport/editor.js +44 -11
  252. package/dist/transport/routes.d.ts +6 -1
  253. package/dist/transport/routes.js +6 -1
  254. package/package.json +6 -2
  255. package/dist/inspector/changes/workspaceChanges.d.ts +0 -43
  256. package/dist/inspector/changes/workspaceChanges.js +0 -239
  257. package/dist/inspector/shell/DomNavigation.d.ts +0 -8
  258. package/dist/inspector/shell/DomNavigation.js +0 -30
@@ -1,239 +0,0 @@
1
- import { canWriteWorkspace } from "../canvas/workspaceLease.js";
2
- import { changeKey, mergeChange, sameEffectiveChanges, selectorForChange } from "./model.js";
3
- import { isElementChange } from "./types.js";
4
- let contents = { changes: [], structuralChanges: [] };
5
- let revision = 0;
6
- let undoStack = [];
7
- let redoStack = [];
8
- let snapshot = createSnapshot();
9
- const listeners = new Set();
10
- function cloneContents(value) {
11
- return {
12
- changes: value.changes.map((change) => cloneValue(change)),
13
- structuralChanges: value.structuralChanges.map((change) => cloneValue(change)),
14
- };
15
- }
16
- function cloneValue(value, key) {
17
- // Token entries belong to the shared catalog. Preserve their identity so
18
- // callers can continue to correlate a change with its catalog entry.
19
- if (key === "oldToken" || key === "newToken")
20
- return value;
21
- if (Array.isArray(value))
22
- return value.map((item) => cloneValue(item));
23
- if (value !== null && typeof value === "object") {
24
- const clone = {};
25
- for (const [key, child] of Object.entries(value)) {
26
- clone[key] = cloneValue(child, key);
27
- }
28
- return clone;
29
- }
30
- return value;
31
- }
32
- function freezeValue(value, key) {
33
- if (key === "oldToken" || key === "newToken")
34
- return value;
35
- if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
36
- for (const [childKey, child] of Object.entries(value))
37
- freezeValue(child, childKey);
38
- Object.freeze(value);
39
- }
40
- return value;
41
- }
42
- function createSnapshot() {
43
- const snapshotContents = freezeValue(cloneContents(contents));
44
- return Object.freeze({
45
- revision,
46
- changes: snapshotContents.changes,
47
- structuralChanges: snapshotContents.structuralChanges,
48
- canUndo: undoStack.length > 0,
49
- canRedo: redoStack.length > 0,
50
- });
51
- }
52
- function publish() {
53
- revision += 1;
54
- snapshot = createSnapshot();
55
- for (const listener of listeners)
56
- listener();
57
- }
58
- function commit(next) {
59
- if (!canWriteWorkspace())
60
- return false;
61
- const before = cloneContents(contents);
62
- contents = cloneContents(next);
63
- undoStack.push({ before, after: cloneContents(contents) });
64
- redoStack = [];
65
- publish();
66
- return true;
67
- }
68
- function getSnapshot() {
69
- return snapshot;
70
- }
71
- function subscribe(listener) {
72
- listeners.add(listener);
73
- return () => listeners.delete(listener);
74
- }
75
- function commitChangeRecordsImpl(incoming) {
76
- if (incoming.length === 0)
77
- return "unchanged";
78
- const nextChanges = incoming.reduce((current, change) => mergeChange(current, change), [...contents.changes]);
79
- if (sameEffectiveChanges([...contents.changes], nextChanges))
80
- return "unchanged";
81
- return commit({ ...contents, changes: nextChanges }) ? "applied" : "blocked";
82
- }
83
- function revertChangeRecordImpl(change) {
84
- const key = changeKey(change);
85
- const changes = contents.changes.filter((candidate) => changeKey(candidate) !== key);
86
- if (changes.length === contents.changes.length)
87
- return false;
88
- return commit({ ...contents, changes });
89
- }
90
- function discardChangeRecordsImpl(target) {
91
- const changes = contents.changes.filter((change) => target.kind === "selector"
92
- ? selectorForChange(change) !== target.selector
93
- : !isElementChange(change) || change.instanceOverride?.id !== target.id);
94
- if (changes.length === contents.changes.length)
95
- return false;
96
- return commit({ ...contents, changes });
97
- }
98
- function commitStructuralChangeImpl(change) {
99
- if (contents.structuralChanges.some((candidate) => candidate.id === change.id))
100
- return false;
101
- return commit({
102
- ...contents,
103
- structuralChanges: [...contents.structuralChanges, change],
104
- });
105
- }
106
- function revertStructuralChangeRecordImpl(changeId) {
107
- const structuralChanges = contents.structuralChanges.filter((change) => change.id !== changeId);
108
- if (structuralChanges.length === contents.structuralChanges.length)
109
- return false;
110
- return commit({ ...contents, structuralChanges });
111
- }
112
- function reconcileWorkspaceChangesImpl(verifiedKeys, verifiedStructuralIds) {
113
- if (!canWriteWorkspace())
114
- return 0;
115
- const retain = (value) => ({
116
- changes: value.changes.filter((change) => !verifiedKeys.has(changeKey(change))),
117
- structuralChanges: value.structuralChanges.filter((change) => !verifiedStructuralIds.has(change.id)),
118
- });
119
- const next = retain(contents);
120
- const removed = contents.changes.length - next.changes.length
121
- + contents.structuralChanges.length - next.structuralChanges.length;
122
- if (removed === 0)
123
- return 0;
124
- contents = next;
125
- const prune = (entries) => entries
126
- .map((entry) => ({ before: retain(entry.before), after: retain(entry.after) }))
127
- .filter((entry) => !sameWorkspaceContents(entry.before, entry.after));
128
- undoStack = prune(undoStack);
129
- redoStack = prune(redoStack);
130
- publish();
131
- return removed;
132
- }
133
- function sameWorkspaceContents(left, right) {
134
- return sameEffectiveChanges([...left.changes], [...right.changes])
135
- && sameStructuralChanges(left.structuralChanges, right.structuralChanges);
136
- }
137
- function sameStructuralChanges(left, right) {
138
- // Structural intent is an ordered list of small, immutable JSON records.
139
- // Equality must include operation order and the complete target payload.
140
- return JSON.stringify(left) === JSON.stringify(right);
141
- }
142
- function undoWorkspaceChangeImpl() {
143
- if (!canWriteWorkspace())
144
- return false;
145
- const entry = undoStack.at(-1);
146
- if (!entry)
147
- return false;
148
- undoStack.pop();
149
- contents = cloneContents(entry.before);
150
- redoStack.push(entry);
151
- publish();
152
- return true;
153
- }
154
- function redoWorkspaceChangeImpl() {
155
- if (!canWriteWorkspace())
156
- return false;
157
- const entry = redoStack.at(-1);
158
- if (!entry)
159
- return false;
160
- redoStack.pop();
161
- contents = cloneContents(entry.after);
162
- undoStack.push(entry);
163
- publish();
164
- return true;
165
- }
166
- function restoreWorkspaceChangesImpl(next) {
167
- contents = cloneContents(next);
168
- undoStack = [];
169
- redoStack = [];
170
- publish();
171
- }
172
- function clearWorkspaceChangesImpl() {
173
- contents = { changes: [], structuralChanges: [] };
174
- undoStack = [];
175
- redoStack = [];
176
- publish();
177
- }
178
- /** Resets controller state for teardown and tests without requiring a lease. */
179
- function resetWorkspaceChangesImpl() {
180
- contents = { changes: [], structuralChanges: [] };
181
- undoStack = [];
182
- redoStack = [];
183
- revision = 0;
184
- snapshot = createSnapshot();
185
- for (const listener of listeners)
186
- listener();
187
- }
188
- export const workspaceChangeStore = {
189
- getSnapshot,
190
- subscribe,
191
- commitChangeRecords: commitChangeRecordsImpl,
192
- revertChangeRecord: revertChangeRecordImpl,
193
- discardChangeRecords: discardChangeRecordsImpl,
194
- commitStructuralChange: commitStructuralChangeImpl,
195
- revertStructuralChangeRecord: revertStructuralChangeRecordImpl,
196
- reconcileWorkspaceChanges: reconcileWorkspaceChangesImpl,
197
- undoWorkspaceChange: undoWorkspaceChangeImpl,
198
- redoWorkspaceChange: redoWorkspaceChangeImpl,
199
- restoreWorkspaceChanges: restoreWorkspaceChangesImpl,
200
- clearWorkspaceChanges: clearWorkspaceChangesImpl,
201
- };
202
- /** Compatibility accessors retained for callers that have not adopted the store seam. */
203
- export function getWorkspaceChanges() {
204
- return workspaceChangeStore.getSnapshot();
205
- }
206
- export function subscribeWorkspaceChanges(listener) {
207
- return workspaceChangeStore.subscribe(listener);
208
- }
209
- export function commitChangeRecords(incoming, project) {
210
- const result = workspaceChangeStore.commitChangeRecords(incoming);
211
- if (result === "applied")
212
- project(workspaceChangeStore.getSnapshot());
213
- return result;
214
- }
215
- export function commitStructuralChange(change, project) {
216
- const changed = workspaceChangeStore.commitStructuralChange(change);
217
- if (changed)
218
- project(workspaceChangeStore.getSnapshot());
219
- return changed;
220
- }
221
- export function undoWorkspaceChange(project) {
222
- const changed = workspaceChangeStore.undoWorkspaceChange();
223
- if (changed)
224
- project(workspaceChangeStore.getSnapshot());
225
- return changed;
226
- }
227
- export function redoWorkspaceChange(project) {
228
- const changed = workspaceChangeStore.redoWorkspaceChange();
229
- if (changed)
230
- project(workspaceChangeStore.getSnapshot());
231
- return changed;
232
- }
233
- export function restoreWorkspaceChanges(next, project) {
234
- workspaceChangeStore.restoreWorkspaceChanges(next);
235
- project(workspaceChangeStore.getSnapshot());
236
- }
237
- export function resetWorkspaceChanges() {
238
- resetWorkspaceChangesImpl();
239
- }
@@ -1,8 +0,0 @@
1
- import type { ReactElement } from "react";
2
- import type { SelectedElement } from "../selection/selectionStore.js";
3
- interface DomNavigationProps {
4
- selected: SelectedElement;
5
- hierarchy: HTMLElement[];
6
- }
7
- export declare function DomNavigation({ selected, hierarchy }: DomNavigationProps): ReactElement | null;
8
- export {};
@@ -1,30 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { resolveSelectionFromElement } from "../selection/resolveSelection.js";
3
- import { setSelectedElement } from "../selection/selectionStore.js";
4
- import { computeDescendants } from "../selection/hierarchy.js";
5
- import { Button } from "../ui/Button.js";
6
- const MAX_PARENT_LEVELS = 2;
7
- const MAX_CHILD_NODES = 2;
8
- function nodeLabel(node) {
9
- return node.getAttribute("data-cid") ?? node.localName;
10
- }
11
- function nodeDescription(node) {
12
- const id = node.id ? `#${node.id}` : "";
13
- const className = typeof node.className === "string"
14
- ? node.className.trim().split(/\s+/).filter(Boolean).slice(0, 2).map((name) => `.${name}`).join("")
15
- : "";
16
- const source = node.getAttribute("data-src");
17
- return `${node.localName}${id}${className}${source ? ` — ${source}` : ""}`;
18
- }
19
- function selectNode(node) {
20
- const resolved = resolveSelectionFromElement(node);
21
- if (resolved)
22
- setSelectedElement(resolved);
23
- }
24
- export function DomNavigation({ selected, hierarchy }) {
25
- const parents = hierarchy.slice(1, MAX_PARENT_LEVELS + 1);
26
- const children = computeDescendants(selected.domElement, 2, MAX_CHILD_NODES);
27
- if (parents.length === 0 && children.length === 0)
28
- return null;
29
- return (_jsxs("section", { className: "dom-navigation", "data-test": "dom-navigation", "aria-label": "DOM navigation", children: [_jsx("div", { className: "dom-navigation__header", children: _jsx("span", { className: "dom-navigation__title", children: "DOM" }) }), parents.length > 0 ? (_jsxs("div", { className: "dom-navigation__group", "data-test": "dom-parents", children: [_jsx("span", { className: "dom-navigation__label", children: "Parents" }), _jsx("div", { className: "dom-navigation__items", children: parents.map((node, index) => (_jsxs(Button, { size: "compact", variant: "quiet", className: "dom-navigation__item", "data-test": "dom-parent-step", "data-depth": index + 1, "data-cid": node.getAttribute("data-cid") ?? undefined, title: nodeDescription(node), onClick: () => selectNode(node), children: [_jsx("span", { "aria-hidden": "true", children: "\u2191" }), index === 0 ? "Parent" : "Grandparent", _jsx("span", { className: "dom-navigation__value", children: nodeLabel(node) })] }, `${index}-${nodeLabel(node)}`))) })] })) : null, children.length > 0 ? (_jsxs("div", { className: "dom-navigation__group", "data-test": "dom-children", children: [_jsx("span", { className: "dom-navigation__label", children: "Children" }), _jsx("div", { className: "dom-navigation__items", children: children.map(({ element, depth }, index) => (_jsxs(Button, { size: "compact", variant: "quiet", className: "dom-navigation__item", "data-test": "dom-child-step", "data-depth": depth, "data-cid": element.getAttribute("data-cid") ?? undefined, title: nodeDescription(element), onClick: () => selectNode(element), children: [_jsx("span", { "aria-hidden": "true", children: "\u2193" }), depth === 1 ? "Child" : "Descendant", _jsx("span", { className: "dom-navigation__value", children: nodeLabel(element) })] }, `${depth}-${index}-${nodeLabel(element)}`))) })] })) : null] }));
30
- }