nudge-ui 0.2.2 → 0.2.4
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.
- package/README.md +164 -46
- package/dist/client.mjs +260 -61
- package/dist/css/value-semantics/colorSemantics.d.ts +4 -0
- package/dist/css/value-semantics/colorSemantics.js +17 -0
- package/dist/hosts/astro/astroRuntimeConfig.js +1 -0
- package/dist/hosts/astro/clientTransport.js +38 -32
- package/dist/hosts/astro/integration.js +5 -1
- package/dist/hosts/astro/markdownIdentity.d.ts +28 -0
- package/dist/hosts/astro/markdownIdentity.js +81 -0
- package/dist/hosts/next/manifest.js +1 -1
- package/dist/hosts/next/sidecar.js +5 -1
- package/dist/hosts/static/manifest.js +1 -1
- package/dist/hosts/static/server.js +3 -0
- package/dist/hosts/vite/vite.d.ts +3 -0
- package/dist/hosts/vite/vite.js +24 -4
- package/dist/inspector/agent/McpConnectionDialog.js +13 -19
- package/dist/inspector/agent/activity.d.ts +18 -0
- package/dist/inspector/agent/activity.js +70 -0
- package/dist/inspector/agent/client.d.ts +2 -0
- package/dist/inspector/agent/client.js +29 -1
- package/dist/inspector/agent/connectionStatus.js +1 -1
- package/dist/inspector/agent/httpTransport.js +9 -2
- package/dist/inspector/agent/protocol.d.ts +6 -3
- package/dist/inspector/agent/protocol.js +1 -1
- package/dist/inspector/agent/verification.d.ts +15 -7
- package/dist/inspector/agent/verification.js +113 -41
- package/dist/inspector/canvas/AgentActivityOverlay.d.ts +13 -0
- package/dist/inspector/canvas/AgentActivityOverlay.js +111 -0
- package/dist/inspector/canvas/CanvasCard.d.ts +9 -2
- package/dist/inspector/canvas/CanvasCard.js +135 -38
- package/dist/inspector/canvas/CanvasElementOverlay.js +166 -16
- package/dist/inspector/canvas/CanvasToolIcons.d.ts +10 -0
- package/dist/inspector/canvas/CanvasToolIcons.js +20 -0
- package/dist/inspector/canvas/CanvasToolbar.js +8 -4
- package/dist/inspector/canvas/CanvasWorkspace.js +270 -122
- package/dist/inspector/canvas/StaleChangeIndicator.js +3 -13
- package/dist/inspector/canvas/agentPresentation.d.ts +8 -8
- package/dist/inspector/canvas/agentPresentation.js +64 -52
- package/dist/inspector/canvas/canvasGestures.d.ts +1 -1
- package/dist/inspector/canvas/canvasGestures.js +1 -1
- package/dist/inspector/canvas/canvasStore.d.ts +46 -82
- package/dist/inspector/canvas/canvasStore.js +251 -284
- package/dist/inspector/canvas/frameContent.d.ts +21 -0
- package/dist/inspector/canvas/frameContent.js +44 -0
- package/dist/inspector/canvas/frameProtocol.d.ts +21 -4
- package/dist/inspector/canvas/frameProtocol.js +3 -3
- package/dist/inspector/canvas/frameScrollbarStyles.d.ts +3 -0
- package/dist/inspector/canvas/frameScrollbarStyles.js +21 -0
- package/dist/inspector/canvas/keyboardShortcuts.d.ts +3 -1
- package/dist/inspector/canvas/keyboardShortcuts.js +4 -4
- package/dist/inspector/canvas/layout.d.ts +52 -0
- package/dist/inspector/canvas/layout.js +106 -0
- package/dist/inspector/canvas/projection.d.ts +15 -5
- package/dist/inspector/canvas/projection.js +69 -13
- package/dist/inspector/canvas/rendererBootstrap.js +32 -4
- package/dist/inspector/canvas/rendererElementSelector.js +47 -6
- package/dist/inspector/canvas/rendererStylesheet.js +2 -2
- package/dist/inspector/canvas/resizeHandleScale.js +1 -1
- package/dist/inspector/canvas/sessionStore.d.ts +11 -26
- package/dist/inspector/canvas/sessionStore.js +43 -183
- package/dist/inspector/canvas/staleChangeDetector.js +9 -3
- package/dist/inspector/canvas/useCanvasLayoutAnimation.d.ts +5 -0
- package/dist/inspector/canvas/useCanvasLayoutAnimation.js +107 -0
- package/dist/inspector/canvas/viewStore.d.ts +38 -0
- package/dist/inspector/canvas/viewStore.js +104 -0
- package/dist/inspector/canvas/wheelPan.d.ts +8 -0
- package/dist/inspector/canvas/wheelPan.js +8 -0
- package/dist/inspector/changes/changesLog.d.ts +9 -6
- package/dist/inspector/changes/changesLog.js +48 -32
- package/dist/inspector/changes/codecs.d.ts +1 -0
- package/dist/inspector/changes/codecs.js +10 -1
- package/dist/inspector/changes/draftChanges.d.ts +58 -0
- package/dist/inspector/changes/draftChanges.js +304 -0
- package/dist/inspector/changes/editModel.d.ts +10 -0
- package/dist/inspector/changes/editModel.js +9 -2
- package/dist/inspector/changes/previewDiagnostics.d.ts +4 -2
- package/dist/inspector/changes/previewDiagnostics.js +11 -25
- package/dist/inspector/changes/types.d.ts +7 -0
- package/dist/inspector/clientManifest.d.ts +1 -1
- package/dist/inspector/comments/CommentsOverlay.d.ts +2 -0
- package/dist/inspector/comments/CommentsOverlay.js +250 -0
- package/dist/inspector/comments/element.d.ts +6 -0
- package/dist/inspector/comments/element.js +54 -0
- package/dist/inspector/comments/store.d.ts +29 -0
- package/dist/inspector/comments/store.js +121 -0
- package/dist/inspector/comments/verification.d.ts +5 -0
- package/dist/inspector/comments/verification.js +52 -0
- package/dist/inspector/componentSemantics/adapterRegistry.d.ts +6 -1
- package/dist/inspector/componentSemantics/adapterRegistry.js +23 -1
- package/dist/inspector/componentSemantics/reactRuntime.d.ts +2 -1
- package/dist/inspector/componentSemantics/reactRuntime.js +38 -0
- package/dist/inspector/componentSemantics/runtimeBridge.d.ts +4 -2
- package/dist/inspector/componentSemantics/runtimeBridge.js +17 -0
- package/dist/inspector/componentSemantics/types.d.ts +11 -0
- package/dist/inspector/drafts/model.d.ts +35 -0
- package/dist/inspector/drafts/model.js +45 -0
- package/dist/inspector/drafts/store.d.ts +28 -0
- package/dist/inspector/drafts/store.js +231 -0
- package/dist/inspector/index.js +20 -27
- package/dist/inspector/inline-text/inlineTextEditor.js +7 -0
- package/dist/inspector/inspection/useBrowserCssInspection.js +15 -1
- package/dist/inspector/iterations/capture.d.ts +2 -0
- package/dist/inspector/iterations/capture.js +174 -0
- package/dist/inspector/iterations/client.d.ts +7 -0
- package/dist/inspector/iterations/client.js +52 -0
- package/dist/inspector/iterations/coordinator.d.ts +15 -0
- package/dist/inspector/iterations/coordinator.js +130 -0
- package/dist/inspector/iterations/prompt.d.ts +3 -0
- package/dist/inspector/iterations/prompt.js +26 -0
- package/dist/inspector/overlay/DomNavigator.js +21 -15
- package/dist/inspector/overlay/interactionStyles.js +3 -1
- package/dist/inspector/overlay/spacingGestures.d.ts +13 -1
- package/dist/inspector/overlay/spacingGestures.js +82 -5
- package/dist/inspector/projection/{workspaceProjection.d.ts → draftProjection.d.ts} +6 -6
- package/dist/inspector/projection/{workspaceProjection.js → draftProjection.js} +4 -4
- package/dist/inspector/projection/renderedInstance.d.ts +17 -3
- package/dist/inspector/projection/renderedInstance.js +62 -11
- package/dist/inspector/projection/structuralProjection.d.ts +2 -1
- package/dist/inspector/projection/structuralProjection.js +21 -17
- package/dist/inspector/projection/textProjection.d.ts +2 -1
- package/dist/inspector/projection/textProjection.js +64 -15
- package/dist/inspector/prompt/PromptSettingsDialog.js +1 -5
- package/dist/inspector/prompt/clipboardHandoff.d.ts +15 -18
- package/dist/inspector/prompt/clipboardHandoff.js +97 -143
- package/dist/inspector/prompt/generatePrompt.d.ts +4 -1
- package/dist/inspector/prompt/generatePrompt.js +22 -17
- package/dist/inspector/runtime/runtimeConfig.d.ts +9 -0
- package/dist/inspector/runtime/runtimeConfig.js +24 -0
- package/dist/inspector/selection/sourceSite.d.ts +12 -0
- package/dist/inspector/selection/sourceSite.js +28 -0
- package/dist/inspector/settings/SettingsDialog.js +21 -8
- package/dist/inspector/shell/AgentStatusButton.d.ts +11 -0
- package/dist/inspector/shell/AgentStatusButton.js +36 -0
- package/dist/inspector/shell/AppShell.js +4 -2
- package/dist/inspector/shell/ChangesLog.js +46 -26
- package/dist/inspector/shell/CopyPromptButton.js +184 -93
- package/dist/inspector/shell/EmptyState.js +9 -8
- package/dist/inspector/shell/InspectorShell.js +13 -21
- package/dist/inspector/shell/PeekOriginalButton.js +24 -23
- package/dist/inspector/shell/originalPreview.js +5 -5
- package/dist/inspector/shell/shortcuts.d.ts +3 -0
- package/dist/inspector/shell/shortcuts.js +11 -0
- package/dist/inspector/sketch/SketchEditor.js +14 -14
- package/dist/inspector/sketch/SketchEntryButton.js +1 -1
- package/dist/inspector/sketch/SketchFrameOverlay.d.ts +3 -1
- package/dist/inspector/sketch/SketchFrameOverlay.js +11 -8
- package/dist/inspector/sketch/SketchLayersPanel.js +13 -5
- package/dist/inspector/sketch/SketchOverlay.js +7 -7
- package/dist/inspector/sketch/SketchWorkspace.js +18 -12
- package/dist/inspector/sketch/interaction.d.ts +1 -0
- package/dist/inspector/sketch/interaction.js +8 -4
- package/dist/inspector/sketch/model.d.ts +5 -0
- package/dist/inspector/sketch/model.js +6 -2
- package/dist/inspector/sketch/raster.d.ts +1 -2
- package/dist/inspector/sketch/raster.js +68 -4
- package/dist/inspector/styleEditors/BackgroundEditor.d.ts +4 -0
- package/dist/inspector/styleEditors/BackgroundEditor.js +195 -0
- package/dist/inspector/styleEditors/BorderEditor.js +49 -78
- package/dist/inspector/styleEditors/BorderRadiusEditor.js +6 -1
- package/dist/inspector/styleEditors/BoxShadowEditor.d.ts +1 -2
- package/dist/inspector/styleEditors/BoxShadowEditor.js +132 -4
- package/dist/inspector/styleEditors/ColorPicker.d.ts +5 -1
- package/dist/inspector/styleEditors/ColorPicker.js +10 -4
- package/dist/inspector/styleEditors/GapField.js +3 -5
- package/dist/inspector/styleEditors/GridChildSection.d.ts +1 -1
- package/dist/inspector/styleEditors/GridChildSection.js +18 -9
- package/dist/inspector/styleEditors/GridPicker.d.ts +1 -1
- package/dist/inspector/styleEditors/GridPicker.js +8 -2
- package/dist/inspector/styleEditors/GridSection.js +1 -1
- package/dist/inspector/styleEditors/GridValueField.js +19 -14
- package/dist/inspector/styleEditors/ImageBackgroundEditor.d.ts +18 -0
- package/dist/inspector/styleEditors/ImageBackgroundEditor.js +118 -0
- package/dist/inspector/styleEditors/LayoutBlockedIndicator.d.ts +2 -2
- package/dist/inspector/styleEditors/LayoutBlockedIndicator.js +3 -3
- package/dist/inspector/styleEditors/LayoutComboField.js +6 -4
- package/dist/inspector/styleEditors/LayoutDropdown.js +6 -3
- package/dist/inspector/styleEditors/LayoutSection.js +32 -11
- package/dist/inspector/styleEditors/SpacingBox.js +7 -5
- package/dist/inspector/styleEditors/Typography.js +11 -3
- package/dist/inspector/styleEditors/backgroundLayers.d.ts +24 -0
- package/dist/inspector/styleEditors/backgroundLayers.js +51 -0
- package/dist/inspector/styleEditors/gradientValue.d.ts +17 -0
- package/dist/inspector/styleEditors/gradientValue.js +114 -0
- package/dist/inspector/styleEditors/inlineAuthored.d.ts +10 -0
- package/dist/inspector/styleEditors/inlineAuthored.js +114 -0
- package/dist/inspector/styleEditors/layoutValue.d.ts +0 -8
- package/dist/inspector/styleEditors/layoutValue.js +0 -42
- package/dist/inspector/styleEditors/nudgeValue.d.ts +2 -2
- package/dist/inspector/styleEditors/nudgeValue.js +36 -8
- package/dist/inspector/tokens/TokenField.d.ts +7 -0
- package/dist/inspector/tokens/TokenField.js +35 -25
- package/dist/inspector/tokens/TokenLabel.js +5 -14
- package/dist/inspector/tokens/editActions.d.ts +1 -1
- package/dist/inspector/tokens/editActions.js +7 -1
- package/dist/inspector/ui/AtRuleContext.js +4 -6
- package/dist/inspector/ui/Button.d.ts +6 -2
- package/dist/inspector/ui/Button.js +4 -3
- package/dist/inspector/ui/ControlSurface.d.ts +2 -2
- package/dist/inspector/ui/ControlSurface.js +4 -3
- package/dist/inspector/ui/InlineStyleWarning.d.ts +11 -0
- package/dist/inspector/ui/InlineStyleWarning.js +13 -0
- package/dist/inspector/ui/InspectorPopover.d.ts +2 -1
- package/dist/inspector/ui/InspectorPopover.js +4 -5
- package/dist/inspector/ui/PopoverListbox.d.ts +2 -1
- package/dist/inspector/ui/PopoverListbox.js +8 -7
- package/dist/inspector/ui/SegmentedControl.d.ts +2 -1
- package/dist/inspector/ui/SegmentedControl.js +2 -2
- package/dist/inspector/ui/Select.d.ts +6 -1
- package/dist/inspector/ui/Select.js +7 -11
- package/dist/inspector/ui/SideValuesField.js +1 -1
- package/dist/inspector/ui/Tooltip.d.ts +26 -0
- package/dist/inspector/ui/Tooltip.js +32 -0
- package/dist/inspector/ui/classNames.d.ts +2 -0
- package/dist/inspector/ui/classNames.js +4 -0
- package/dist/inspector/ui/customCursors.d.ts +23 -0
- package/dist/inspector/ui/customCursors.js +122 -0
- package/dist/inspector/ui/dragCursor.d.ts +0 -2
- package/dist/inspector/ui/dragCursor.js +2 -10
- package/dist/inspector/ui/portalContainer.d.ts +2 -0
- package/dist/inspector/ui/portalContainer.js +6 -0
- package/dist/inspector/ui/styles.js +29 -21
- package/dist/inspector/workspace/commands.d.ts +9 -0
- package/dist/inspector/workspace/commands.js +82 -0
- package/dist/inspector/workspace/controller.d.ts +4 -0
- package/dist/inspector/workspace/controller.js +66 -0
- package/dist/inspector/workspace/handoff.d.ts +42 -0
- package/dist/inspector/workspace/handoff.js +115 -0
- package/dist/inspector/workspace/sentItems.d.ts +19 -0
- package/dist/inspector/workspace/sentItems.js +51 -0
- package/dist/inspector/workspace/timeline.d.ts +30 -0
- package/dist/inspector/workspace/timeline.js +108 -0
- package/dist/internal/agent-protocol.d.ts +19 -2
- package/dist/internal/agent-protocol.js +13 -0
- package/dist/nudge-ui.mjs +558 -311
- package/dist/project/artifacts.d.ts +13 -0
- package/dist/project/artifacts.js +253 -0
- package/dist/transport/artifacts.d.ts +8 -0
- package/dist/transport/artifacts.js +9 -0
- package/dist/transport/editor.js +3 -1
- package/dist/transport/routes.d.ts +2 -0
- package/dist/transport/routes.js +2 -0
- package/package.json +7 -3
- package/dist/inspector/changes/workspaceChanges.d.ts +0 -47
- package/dist/inspector/changes/workspaceChanges.js +0 -265
|
@@ -1,265 +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 activeHistoryGroup;
|
|
9
|
-
let snapshot = createSnapshot();
|
|
10
|
-
const listeners = new Set();
|
|
11
|
-
function cloneContents(value) {
|
|
12
|
-
return {
|
|
13
|
-
changes: value.changes.map((change) => cloneValue(change)),
|
|
14
|
-
structuralChanges: value.structuralChanges.map((change) => cloneValue(change)),
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function cloneValue(value, key) {
|
|
18
|
-
// Token entries belong to the shared catalog. Preserve their identity so
|
|
19
|
-
// callers can continue to correlate a change with its catalog entry.
|
|
20
|
-
if (key === "oldToken" || key === "newToken")
|
|
21
|
-
return value;
|
|
22
|
-
if (Array.isArray(value))
|
|
23
|
-
return value.map((item) => cloneValue(item));
|
|
24
|
-
if (value !== null && typeof value === "object") {
|
|
25
|
-
const clone = {};
|
|
26
|
-
for (const [key, child] of Object.entries(value)) {
|
|
27
|
-
clone[key] = cloneValue(child, key);
|
|
28
|
-
}
|
|
29
|
-
return clone;
|
|
30
|
-
}
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
function freezeValue(value, key) {
|
|
34
|
-
if (key === "oldToken" || key === "newToken")
|
|
35
|
-
return value;
|
|
36
|
-
if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
|
|
37
|
-
for (const [childKey, child] of Object.entries(value))
|
|
38
|
-
freezeValue(child, childKey);
|
|
39
|
-
Object.freeze(value);
|
|
40
|
-
}
|
|
41
|
-
return value;
|
|
42
|
-
}
|
|
43
|
-
function createSnapshot() {
|
|
44
|
-
const snapshotContents = freezeValue(cloneContents(contents));
|
|
45
|
-
return Object.freeze({
|
|
46
|
-
revision,
|
|
47
|
-
changes: snapshotContents.changes,
|
|
48
|
-
structuralChanges: snapshotContents.structuralChanges,
|
|
49
|
-
canUndo: undoStack.length > 0,
|
|
50
|
-
canRedo: redoStack.length > 0,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
function publish() {
|
|
54
|
-
revision += 1;
|
|
55
|
-
snapshot = createSnapshot();
|
|
56
|
-
for (const listener of listeners)
|
|
57
|
-
listener();
|
|
58
|
-
}
|
|
59
|
-
function commit(next) {
|
|
60
|
-
if (!canWriteWorkspace())
|
|
61
|
-
return false;
|
|
62
|
-
const before = cloneContents(contents);
|
|
63
|
-
contents = cloneContents(next);
|
|
64
|
-
const previous = undoStack.at(-1);
|
|
65
|
-
const entry = {
|
|
66
|
-
before: activeHistoryGroup && previous?.group === activeHistoryGroup ? previous.before : before,
|
|
67
|
-
after: cloneContents(contents),
|
|
68
|
-
group: activeHistoryGroup,
|
|
69
|
-
};
|
|
70
|
-
if (activeHistoryGroup && previous?.group === activeHistoryGroup)
|
|
71
|
-
undoStack.pop();
|
|
72
|
-
if (!sameWorkspaceContents(entry.before, entry.after))
|
|
73
|
-
undoStack.push(entry);
|
|
74
|
-
redoStack = [];
|
|
75
|
-
publish();
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
/** Groups consecutive synchronous updates from one gesture into one undo step.
|
|
79
|
-
* Updates outside the callback keep their own history entries.
|
|
80
|
-
*/
|
|
81
|
-
export function createChangeHistoryGroup() {
|
|
82
|
-
const group = Symbol("change-history-group");
|
|
83
|
-
return (update) => {
|
|
84
|
-
const previous = activeHistoryGroup;
|
|
85
|
-
activeHistoryGroup = group;
|
|
86
|
-
try {
|
|
87
|
-
update();
|
|
88
|
-
}
|
|
89
|
-
finally {
|
|
90
|
-
activeHistoryGroup = previous;
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function getSnapshot() {
|
|
95
|
-
return snapshot;
|
|
96
|
-
}
|
|
97
|
-
function subscribe(listener) {
|
|
98
|
-
listeners.add(listener);
|
|
99
|
-
return () => listeners.delete(listener);
|
|
100
|
-
}
|
|
101
|
-
function commitChangeRecordsImpl(incoming) {
|
|
102
|
-
if (incoming.length === 0)
|
|
103
|
-
return "unchanged";
|
|
104
|
-
const nextChanges = incoming.reduce((current, change) => mergeChange(current, change), [...contents.changes]);
|
|
105
|
-
if (sameEffectiveChanges([...contents.changes], nextChanges))
|
|
106
|
-
return "unchanged";
|
|
107
|
-
return commit({ ...contents, changes: nextChanges }) ? "applied" : "blocked";
|
|
108
|
-
}
|
|
109
|
-
function revertChangeRecordImpl(change) {
|
|
110
|
-
const key = changeKey(change);
|
|
111
|
-
const changes = contents.changes.filter((candidate) => changeKey(candidate) !== key);
|
|
112
|
-
if (changes.length === contents.changes.length)
|
|
113
|
-
return false;
|
|
114
|
-
return commit({ ...contents, changes });
|
|
115
|
-
}
|
|
116
|
-
function discardChangeRecordsImpl(target) {
|
|
117
|
-
const changes = contents.changes.filter((change) => target.kind === "selector"
|
|
118
|
-
? selectorForChange(change) !== target.selector
|
|
119
|
-
: !isElementChange(change) || change.instanceOverride?.id !== target.id);
|
|
120
|
-
if (changes.length === contents.changes.length)
|
|
121
|
-
return false;
|
|
122
|
-
return commit({ ...contents, changes });
|
|
123
|
-
}
|
|
124
|
-
function commitStructuralChangeImpl(change) {
|
|
125
|
-
if (contents.structuralChanges.some((candidate) => candidate.id === change.id))
|
|
126
|
-
return false;
|
|
127
|
-
return commit({
|
|
128
|
-
...contents,
|
|
129
|
-
structuralChanges: [...contents.structuralChanges, change],
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
function revertStructuralChangeRecordImpl(changeId) {
|
|
133
|
-
const structuralChanges = contents.structuralChanges.filter((change) => change.id !== changeId);
|
|
134
|
-
if (structuralChanges.length === contents.structuralChanges.length)
|
|
135
|
-
return false;
|
|
136
|
-
return commit({ ...contents, structuralChanges });
|
|
137
|
-
}
|
|
138
|
-
function reconcileWorkspaceChangesImpl(verifiedKeys, verifiedStructuralIds) {
|
|
139
|
-
if (!canWriteWorkspace())
|
|
140
|
-
return 0;
|
|
141
|
-
const retain = (value) => ({
|
|
142
|
-
changes: value.changes.filter((change) => !verifiedKeys.has(changeKey(change))),
|
|
143
|
-
structuralChanges: value.structuralChanges.filter((change) => !verifiedStructuralIds.has(change.id)),
|
|
144
|
-
});
|
|
145
|
-
const next = retain(contents);
|
|
146
|
-
const removed = contents.changes.length - next.changes.length
|
|
147
|
-
+ contents.structuralChanges.length - next.structuralChanges.length;
|
|
148
|
-
if (removed === 0)
|
|
149
|
-
return 0;
|
|
150
|
-
contents = next;
|
|
151
|
-
const prune = (entries) => entries
|
|
152
|
-
.map((entry) => ({ group: entry.group, before: retain(entry.before), after: retain(entry.after) }))
|
|
153
|
-
.filter((entry) => !sameWorkspaceContents(entry.before, entry.after));
|
|
154
|
-
undoStack = prune(undoStack);
|
|
155
|
-
redoStack = prune(redoStack);
|
|
156
|
-
publish();
|
|
157
|
-
return removed;
|
|
158
|
-
}
|
|
159
|
-
function sameWorkspaceContents(left, right) {
|
|
160
|
-
return sameEffectiveChanges([...left.changes], [...right.changes])
|
|
161
|
-
&& sameStructuralChanges(left.structuralChanges, right.structuralChanges);
|
|
162
|
-
}
|
|
163
|
-
function sameStructuralChanges(left, right) {
|
|
164
|
-
// Structural intent is an ordered list of small, immutable JSON records.
|
|
165
|
-
// Equality must include operation order and the complete target payload.
|
|
166
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
167
|
-
}
|
|
168
|
-
function undoWorkspaceChangeImpl() {
|
|
169
|
-
if (!canWriteWorkspace())
|
|
170
|
-
return false;
|
|
171
|
-
const entry = undoStack.at(-1);
|
|
172
|
-
if (!entry)
|
|
173
|
-
return false;
|
|
174
|
-
undoStack.pop();
|
|
175
|
-
contents = cloneContents(entry.before);
|
|
176
|
-
redoStack.push(entry);
|
|
177
|
-
publish();
|
|
178
|
-
return true;
|
|
179
|
-
}
|
|
180
|
-
function redoWorkspaceChangeImpl() {
|
|
181
|
-
if (!canWriteWorkspace())
|
|
182
|
-
return false;
|
|
183
|
-
const entry = redoStack.at(-1);
|
|
184
|
-
if (!entry)
|
|
185
|
-
return false;
|
|
186
|
-
redoStack.pop();
|
|
187
|
-
contents = cloneContents(entry.after);
|
|
188
|
-
undoStack.push({ before: entry.before, after: entry.after });
|
|
189
|
-
publish();
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
function restoreWorkspaceChangesImpl(next) {
|
|
193
|
-
contents = cloneContents(next);
|
|
194
|
-
undoStack = [];
|
|
195
|
-
redoStack = [];
|
|
196
|
-
publish();
|
|
197
|
-
}
|
|
198
|
-
function clearWorkspaceChangesImpl() {
|
|
199
|
-
contents = { changes: [], structuralChanges: [] };
|
|
200
|
-
undoStack = [];
|
|
201
|
-
redoStack = [];
|
|
202
|
-
publish();
|
|
203
|
-
}
|
|
204
|
-
/** Resets controller state for teardown and tests without requiring a lease. */
|
|
205
|
-
function resetWorkspaceChangesImpl() {
|
|
206
|
-
contents = { changes: [], structuralChanges: [] };
|
|
207
|
-
undoStack = [];
|
|
208
|
-
redoStack = [];
|
|
209
|
-
revision = 0;
|
|
210
|
-
snapshot = createSnapshot();
|
|
211
|
-
for (const listener of listeners)
|
|
212
|
-
listener();
|
|
213
|
-
}
|
|
214
|
-
export const workspaceChangeStore = {
|
|
215
|
-
getSnapshot,
|
|
216
|
-
subscribe,
|
|
217
|
-
commitChangeRecords: commitChangeRecordsImpl,
|
|
218
|
-
revertChangeRecord: revertChangeRecordImpl,
|
|
219
|
-
discardChangeRecords: discardChangeRecordsImpl,
|
|
220
|
-
commitStructuralChange: commitStructuralChangeImpl,
|
|
221
|
-
revertStructuralChangeRecord: revertStructuralChangeRecordImpl,
|
|
222
|
-
reconcileWorkspaceChanges: reconcileWorkspaceChangesImpl,
|
|
223
|
-
undoWorkspaceChange: undoWorkspaceChangeImpl,
|
|
224
|
-
redoWorkspaceChange: redoWorkspaceChangeImpl,
|
|
225
|
-
restoreWorkspaceChanges: restoreWorkspaceChangesImpl,
|
|
226
|
-
clearWorkspaceChanges: clearWorkspaceChangesImpl,
|
|
227
|
-
};
|
|
228
|
-
/** Compatibility accessors retained for callers that have not adopted the store seam. */
|
|
229
|
-
export function getWorkspaceChanges() {
|
|
230
|
-
return workspaceChangeStore.getSnapshot();
|
|
231
|
-
}
|
|
232
|
-
export function subscribeWorkspaceChanges(listener) {
|
|
233
|
-
return workspaceChangeStore.subscribe(listener);
|
|
234
|
-
}
|
|
235
|
-
export function commitChangeRecords(incoming, project) {
|
|
236
|
-
const result = workspaceChangeStore.commitChangeRecords(incoming);
|
|
237
|
-
if (result === "applied")
|
|
238
|
-
project(workspaceChangeStore.getSnapshot());
|
|
239
|
-
return result;
|
|
240
|
-
}
|
|
241
|
-
export function commitStructuralChange(change, project) {
|
|
242
|
-
const changed = workspaceChangeStore.commitStructuralChange(change);
|
|
243
|
-
if (changed)
|
|
244
|
-
project(workspaceChangeStore.getSnapshot());
|
|
245
|
-
return changed;
|
|
246
|
-
}
|
|
247
|
-
export function undoWorkspaceChange(project) {
|
|
248
|
-
const changed = workspaceChangeStore.undoWorkspaceChange();
|
|
249
|
-
if (changed)
|
|
250
|
-
project(workspaceChangeStore.getSnapshot());
|
|
251
|
-
return changed;
|
|
252
|
-
}
|
|
253
|
-
export function redoWorkspaceChange(project) {
|
|
254
|
-
const changed = workspaceChangeStore.redoWorkspaceChange();
|
|
255
|
-
if (changed)
|
|
256
|
-
project(workspaceChangeStore.getSnapshot());
|
|
257
|
-
return changed;
|
|
258
|
-
}
|
|
259
|
-
export function restoreWorkspaceChanges(next, project) {
|
|
260
|
-
workspaceChangeStore.restoreWorkspaceChanges(next);
|
|
261
|
-
project(workspaceChangeStore.getSnapshot());
|
|
262
|
-
}
|
|
263
|
-
export function resetWorkspaceChanges() {
|
|
264
|
-
resetWorkspaceChangesImpl();
|
|
265
|
-
}
|