@salesforce/metadata-plugins 1.1.0 → 1.2.0
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/dist/plugins/flexipage/FlexipageParser.d.ts +7 -1
- package/dist/plugins/flexipage/FlexipageParser.d.ts.map +1 -1
- package/dist/plugins/flexipage/FlexipageParser.js +10 -0
- package/dist/plugins/flexipage/ui/assets/index-DT5lcUwK.js +48 -0
- package/dist/plugins/flexipage/ui/index.html +1 -1
- package/dist/plugins/schema/SchemaParser.d.ts +9 -1
- package/dist/plugins/schema/SchemaParser.d.ts.map +1 -1
- package/dist/plugins/schema/SchemaParser.js +35 -2
- package/dist/plugins/schema/types/SchemaERDData.d.ts +6 -0
- package/dist/plugins/schema/types/SchemaERDData.d.ts.map +1 -1
- package/dist/plugins/schema/ui/assets/index-jqcasNAD.js +70 -0
- package/dist/plugins/schema/ui/index.html +1 -1
- package/dist/shared/bootstrap/createPluginApp.d.ts +14 -10
- package/dist/shared/bootstrap/createPluginApp.d.ts.map +1 -1
- package/dist/shared/bootstrap/createPluginApp.js +158 -62
- package/package.json +3 -3
- package/dist/plugins/flexipage/ui/assets/index-BAFqMU7k.js +0 -48
- package/dist/plugins/schema/ui/assets/index-Ho7jg9o_.js +0 -70
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>Schema ERD Visualizer</title>
|
|
7
|
-
<script type="module" crossorigin src="./assets/index-
|
|
7
|
+
<script type="module" crossorigin src="./assets/index-jqcasNAD.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="./assets/index-DCLgZby3.css">
|
|
9
9
|
<link rel="stylesheet" href="@dist/design-system/platform.css" data-platform-styles="true">
|
|
10
10
|
</head>
|
|
@@ -31,20 +31,24 @@ export interface CreatePluginAppOptions<T = unknown> {
|
|
|
31
31
|
validateData?: (data: T) => string | null;
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
* Bootstraps the plugin React app: fetches data from the host, validates it, manages the
|
|
35
|
-
* lifecycle, and renders your component inside StrictMode and ErrorBoundary.
|
|
34
|
+
* Bootstraps the plugin React app: fetches data from the host, validates it, manages the
|
|
35
|
+
* React root lifecycle, and renders your component inside StrictMode and ErrorBoundary.
|
|
36
36
|
*
|
|
37
37
|
* Flow:
|
|
38
38
|
* 1. Resolves the #root element (exits if missing).
|
|
39
|
-
* 2.
|
|
40
|
-
* 3.
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
39
|
+
* 2. Tears down any prior subscription and root from a previous bootstrap.
|
|
40
|
+
* 3. Subscribes to onDataUpdate *before* fetching initial data, buffering events that
|
|
41
|
+
* arrive during the await (latest wins) and replaying them after initial render.
|
|
42
|
+
* 4. Fetches initial data via getPluginData(); on missing response, shows an error and
|
|
43
|
+
* leaves the subscription installed so the host can push corrected data to recover.
|
|
44
|
+
* 5. Validates data (if validator provided); on failure, shows error.
|
|
45
|
+
* 6. Creates a React root keyed by filePath: same file → re-render into existing root
|
|
46
|
+
* (preserves component state); different file → unmount + recreate.
|
|
47
|
+
* 7. Live updates flow through the same handler, so initial and update paths share
|
|
48
|
+
* validation, error handling, and remount logic.
|
|
45
49
|
*
|
|
46
|
-
* Prefer calling this indirectly via runPluginAppWhenReady so DOM readiness and global
|
|
47
|
-
* handlers are set up first.
|
|
50
|
+
* Prefer calling this indirectly via runPluginAppWhenReady so DOM readiness and global
|
|
51
|
+
* error handlers are set up first.
|
|
48
52
|
*
|
|
49
53
|
* @typeParam T - Type of the plugin data.
|
|
50
54
|
* @param options - Plugin name, root class, render function, and optional validateData.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPluginApp.d.ts","sourceRoot":"","sources":["../../../src/shared/bootstrap/createPluginApp.tsx"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"createPluginApp.d.ts","sourceRoot":"","sources":["../../../src/shared/bootstrap/createPluginApp.tsx"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ,OAAO,KAAK,MAAM,OAAO,CAAC;AAkB1B;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAuED;;;;GAIG;AACH,MAAM,WAAW,sBAAsB,CAAC,CAAC,GAAG,OAAO;IACjD,2EAA2E;IAC3E,UAAU,EAAE,MAAM,CAAC;IACnB,wEAAwE;IACxE,SAAS,EAAE,MAAM,CAAC;IAClB,sFAAsF;IACtF,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,gBAAgB,KAAK,KAAK,CAAC,SAAS,CAAC;IAChE;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,IAAI,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,eAAe,CAAC,CAAC,GAAG,OAAO,EAC/C,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC,GACjC,OAAO,CAAC,IAAI,CAAC,CA8Kf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,GAAG,OAAO,EAC/C,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC,GACjC,IAAI,CAoBN"}
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import ReactDOM from 'react-dom/client';
|
|
9
9
|
import { ErrorBoundary } from '@shared/components/ErrorBoundary';
|
|
10
|
-
import { ErrorBuilder, ErrorCategory, getPluginData, setupErrorHandlers, } from '@salesforce/metadata-core-sdk';
|
|
10
|
+
import { ErrorBuilder, ErrorCategory, getPluginData, onDataUpdate, setupErrorHandlers, } from '@salesforce/metadata-core-sdk';
|
|
11
11
|
let currentRoot = null;
|
|
12
|
-
let
|
|
12
|
+
let currentFilePath = null;
|
|
13
|
+
let currentUnsubscribe = null;
|
|
14
|
+
let pageHideListenerInstalled = false;
|
|
13
15
|
/**
|
|
14
16
|
* Renders a user-visible error message into the root element when the plugin cannot render
|
|
15
17
|
* (e.g. missing data, validation failure). Uses innerHTML so the app shows a clear message
|
|
@@ -49,20 +51,24 @@ function reportAndShowError(rootElement, opts) {
|
|
|
49
51
|
});
|
|
50
52
|
}
|
|
51
53
|
/**
|
|
52
|
-
* Bootstraps the plugin React app: fetches data from the host, validates it, manages the
|
|
53
|
-
* lifecycle, and renders your component inside StrictMode and ErrorBoundary.
|
|
54
|
+
* Bootstraps the plugin React app: fetches data from the host, validates it, manages the
|
|
55
|
+
* React root lifecycle, and renders your component inside StrictMode and ErrorBoundary.
|
|
54
56
|
*
|
|
55
57
|
* Flow:
|
|
56
58
|
* 1. Resolves the #root element (exits if missing).
|
|
57
|
-
* 2.
|
|
58
|
-
* 3.
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
59
|
+
* 2. Tears down any prior subscription and root from a previous bootstrap.
|
|
60
|
+
* 3. Subscribes to onDataUpdate *before* fetching initial data, buffering events that
|
|
61
|
+
* arrive during the await (latest wins) and replaying them after initial render.
|
|
62
|
+
* 4. Fetches initial data via getPluginData(); on missing response, shows an error and
|
|
63
|
+
* leaves the subscription installed so the host can push corrected data to recover.
|
|
64
|
+
* 5. Validates data (if validator provided); on failure, shows error.
|
|
65
|
+
* 6. Creates a React root keyed by filePath: same file → re-render into existing root
|
|
66
|
+
* (preserves component state); different file → unmount + recreate.
|
|
67
|
+
* 7. Live updates flow through the same handler, so initial and update paths share
|
|
68
|
+
* validation, error handling, and remount logic.
|
|
63
69
|
*
|
|
64
|
-
* Prefer calling this indirectly via runPluginAppWhenReady so DOM readiness and global
|
|
65
|
-
* handlers are set up first.
|
|
70
|
+
* Prefer calling this indirectly via runPluginAppWhenReady so DOM readiness and global
|
|
71
|
+
* error handlers are set up first.
|
|
66
72
|
*
|
|
67
73
|
* @typeParam T - Type of the plugin data.
|
|
68
74
|
* @param options - Plugin name, root class, render function, and optional validateData.
|
|
@@ -75,23 +81,17 @@ export async function createPluginApp(options) {
|
|
|
75
81
|
console.error(`${logPrefix} Root element not found`);
|
|
76
82
|
return;
|
|
77
83
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
context: { reason: 'Failed to receive plugin data from host' },
|
|
87
|
-
domMessage: `Could not receive ${pluginName} data from the extension host.`,
|
|
88
|
-
});
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
const { data: currentData, context: currentContext, fileId } = pluginData;
|
|
92
|
-
if (currentFileId === fileId && currentRoot) {
|
|
93
|
-
return;
|
|
84
|
+
// Tear down any prior subscription. The new one is installed below, before the await,
|
|
85
|
+
// so updates arriving during async bootstrap are not silently dropped: events that
|
|
86
|
+
// fire before the handler is wired up are buffered (latest wins) and replayed.
|
|
87
|
+
// Error return paths leave the subscription in place so the host can push corrected
|
|
88
|
+
// data to recover.
|
|
89
|
+
if (currentUnsubscribe) {
|
|
90
|
+
currentUnsubscribe();
|
|
91
|
+
currentUnsubscribe = null;
|
|
94
92
|
}
|
|
93
|
+
// Unmount any previous root synchronously. Doing this up front (rather than after the
|
|
94
|
+
// await) avoids a window where two roots could try to render into the same element.
|
|
95
95
|
if (currentRoot) {
|
|
96
96
|
try {
|
|
97
97
|
currentRoot.unmount();
|
|
@@ -100,49 +100,134 @@ export async function createPluginApp(options) {
|
|
|
100
100
|
console.warn(`${logPrefix} Error unmounting previous root:`, e);
|
|
101
101
|
}
|
|
102
102
|
currentRoot = null;
|
|
103
|
+
currentFilePath = null;
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
const handlerRef = { fn: null };
|
|
106
|
+
let pendingUpdate = null;
|
|
107
|
+
const unsubscribe = onDataUpdate((freshPluginData) => {
|
|
108
|
+
if (handlerRef.fn) {
|
|
109
|
+
try {
|
|
110
|
+
handlerRef.fn(freshPluginData);
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
console.error(`${logPrefix} Update handler threw:`, e);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
pendingUpdate = freshPluginData;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
currentUnsubscribe = unsubscribe;
|
|
121
|
+
const renderInto = (target, data, ctx) => {
|
|
122
|
+
target.render(React.createElement(React.StrictMode, null,
|
|
123
|
+
React.createElement(ErrorBoundary, null, render(data, ctx))));
|
|
124
|
+
};
|
|
125
|
+
// Unmount the current React root before painting an error message via innerHTML.
|
|
126
|
+
// showErrorInDOM wipes the container React owns; if we leave currentRoot live, a later
|
|
127
|
+
// valid update would render into a root whose DOM was clobbered, producing React
|
|
128
|
+
// warnings and transient glitches. Clearing currentFilePath also forces the next
|
|
129
|
+
// valid update to take the recreate-root branch in handleData.
|
|
130
|
+
const tearDownRootForError = () => {
|
|
131
|
+
if (currentRoot) {
|
|
132
|
+
try {
|
|
133
|
+
currentRoot.unmount();
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
console.warn(`${logPrefix} Error unmounting previous root:`, e);
|
|
137
|
+
}
|
|
138
|
+
currentRoot = null;
|
|
139
|
+
}
|
|
140
|
+
currentFilePath = null;
|
|
141
|
+
};
|
|
142
|
+
const handleData = (incoming, isUpdate) => {
|
|
143
|
+
const incomingContext = incoming?.context;
|
|
144
|
+
const incomingData = incoming?.data;
|
|
145
|
+
if (!incomingContext || incomingData == null) {
|
|
146
|
+
tearDownRootForError();
|
|
147
|
+
reportAndShowError(rootElement, {
|
|
148
|
+
logPrefix,
|
|
149
|
+
rootClass,
|
|
150
|
+
title: isUpdate ? 'Error: No updated data provided' : 'Error: No data provided',
|
|
151
|
+
consoleMessage: 'No data provided',
|
|
152
|
+
errorBuilderMessage: `${pluginName} data is missing or invalid`,
|
|
153
|
+
context: {
|
|
154
|
+
filePath: incomingContext?.filePath,
|
|
155
|
+
reason: 'No data provided in response',
|
|
156
|
+
},
|
|
157
|
+
domMessage: `${pluginName} data is missing or invalid.`,
|
|
158
|
+
filePath: incomingContext?.filePath || 'Unknown',
|
|
159
|
+
});
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const validationError = validateData != null ? validateData(incomingData) : null;
|
|
163
|
+
if (validationError != null) {
|
|
164
|
+
tearDownRootForError();
|
|
165
|
+
reportAndShowError(rootElement, {
|
|
166
|
+
logPrefix,
|
|
167
|
+
rootClass,
|
|
168
|
+
title: isUpdate ? 'Error: Invalid Updated Data' : 'Error: Invalid Data',
|
|
169
|
+
consoleMessage: `Validation failed: ${validationError}`,
|
|
170
|
+
errorBuilderMessage: `${pluginName} data structure is invalid`,
|
|
171
|
+
context: {
|
|
172
|
+
filePath: incomingContext.filePath,
|
|
173
|
+
reason: validationError,
|
|
174
|
+
},
|
|
175
|
+
domMessage: validationError,
|
|
176
|
+
});
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const ctx = {
|
|
180
|
+
filePath: incomingContext.filePath,
|
|
181
|
+
fileName: incomingContext.fileName,
|
|
182
|
+
};
|
|
183
|
+
// If the underlying file changed (or no root yet), unmount and recreate so React
|
|
184
|
+
// state doesn't bleed across distinct files. Compare on filePath rather than fileId
|
|
185
|
+
// because fileId is a host-side counter that changes on every push, which would
|
|
186
|
+
// force a remount on each update and discard scroll/expand/selection state.
|
|
187
|
+
if (currentRoot == null || ctx.filePath !== currentFilePath) {
|
|
188
|
+
if (currentRoot) {
|
|
189
|
+
try {
|
|
190
|
+
currentRoot.unmount();
|
|
191
|
+
}
|
|
192
|
+
catch (e) {
|
|
193
|
+
console.warn(`${logPrefix} Error unmounting previous root:`, e);
|
|
194
|
+
}
|
|
195
|
+
currentRoot = null;
|
|
196
|
+
}
|
|
197
|
+
rootElement.innerHTML = '';
|
|
198
|
+
currentRoot = ReactDOM.createRoot(rootElement);
|
|
199
|
+
currentFilePath = ctx.filePath;
|
|
200
|
+
}
|
|
201
|
+
renderInto(currentRoot, incomingData, ctx);
|
|
202
|
+
};
|
|
203
|
+
const pluginData = await getPluginData();
|
|
204
|
+
if (!pluginData) {
|
|
106
205
|
reportAndShowError(rootElement, {
|
|
107
206
|
logPrefix,
|
|
108
207
|
rootClass,
|
|
109
|
-
title: 'Error:
|
|
110
|
-
consoleMessage: '
|
|
208
|
+
title: 'Error: Failed to load data',
|
|
209
|
+
consoleMessage: 'Failed to receive plugin data from host',
|
|
111
210
|
errorBuilderMessage: `${pluginName} data is missing or invalid`,
|
|
112
|
-
context: {
|
|
113
|
-
|
|
114
|
-
reason: 'No data provided in response',
|
|
115
|
-
},
|
|
116
|
-
domMessage: `${pluginName} data is missing or invalid.`,
|
|
117
|
-
filePath: currentContext?.filePath || 'Unknown',
|
|
211
|
+
context: { reason: 'Failed to receive plugin data from host' },
|
|
212
|
+
domMessage: `Could not receive ${pluginName} data from the extension host.`,
|
|
118
213
|
});
|
|
214
|
+
// Leave the subscription installed so the host can push corrected data later.
|
|
215
|
+
handlerRef.fn = (fresh) => handleData(fresh, true);
|
|
216
|
+
if (pendingUpdate) {
|
|
217
|
+
const buffered = pendingUpdate;
|
|
218
|
+
pendingUpdate = null;
|
|
219
|
+
handlerRef.fn(buffered);
|
|
220
|
+
}
|
|
119
221
|
return;
|
|
120
222
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
errorBuilderMessage: `${pluginName} data structure is invalid`,
|
|
129
|
-
context: {
|
|
130
|
-
filePath: currentContext?.filePath,
|
|
131
|
-
reason: validationError,
|
|
132
|
-
},
|
|
133
|
-
domMessage: validationError,
|
|
134
|
-
});
|
|
135
|
-
return;
|
|
223
|
+
handleData(pluginData, false);
|
|
224
|
+
// Install the live update handler and replay any update buffered during the await.
|
|
225
|
+
handlerRef.fn = (fresh) => handleData(fresh, true);
|
|
226
|
+
if (pendingUpdate) {
|
|
227
|
+
const buffered = pendingUpdate;
|
|
228
|
+
pendingUpdate = null;
|
|
229
|
+
handlerRef.fn(buffered);
|
|
136
230
|
}
|
|
137
|
-
const root = ReactDOM.createRoot(rootElement);
|
|
138
|
-
currentRoot = root;
|
|
139
|
-
currentFileId = fileId;
|
|
140
|
-
const context = {
|
|
141
|
-
filePath: currentContext.filePath,
|
|
142
|
-
fileName: currentContext.fileName,
|
|
143
|
-
};
|
|
144
|
-
root.render(React.createElement(React.StrictMode, null,
|
|
145
|
-
React.createElement(ErrorBoundary, null, render(currentData, context))));
|
|
146
231
|
}
|
|
147
232
|
/**
|
|
148
233
|
* Entry point for plugin UIs. Sets up global error handlers, waits for DOM readiness, then
|
|
@@ -174,6 +259,17 @@ export async function createPluginApp(options) {
|
|
|
174
259
|
*/
|
|
175
260
|
export function runPluginAppWhenReady(options) {
|
|
176
261
|
setupErrorHandlers();
|
|
262
|
+
// Ensure the subscription is cleaned up on page teardown so listeners do not leak.
|
|
263
|
+
// Guard against multiple bootstraps in the same page registering duplicate listeners.
|
|
264
|
+
if (!pageHideListenerInstalled) {
|
|
265
|
+
window.addEventListener('pagehide', () => {
|
|
266
|
+
if (currentUnsubscribe) {
|
|
267
|
+
currentUnsubscribe();
|
|
268
|
+
currentUnsubscribe = null;
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
pageHideListenerInstalled = true;
|
|
272
|
+
}
|
|
177
273
|
if (document.readyState === 'loading') {
|
|
178
274
|
document.addEventListener('DOMContentLoaded', () => {
|
|
179
275
|
void createPluginApp(options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/metadata-plugins",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Visualizer implementations for Salesforce metadata",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -58,14 +58,14 @@
|
|
|
58
58
|
"url": "https://github.com/forcedotcom/salesforce-metadata-visualizer-support/issues"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"@salesforce/metadata-core-sdk": "^1.
|
|
61
|
+
"@salesforce/metadata-core-sdk": "^1.3.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@commitlint/cli": "^19.6.0",
|
|
65
65
|
"@commitlint/config-conventional": "^19.6.0",
|
|
66
66
|
"@dagrejs/dagre": "^2.0.4",
|
|
67
67
|
"@eslint/js": "^9.15.0",
|
|
68
|
-
"@salesforce/metadata-core-sdk": "^1.
|
|
68
|
+
"@salesforce/metadata-core-sdk": "^1.3.0",
|
|
69
69
|
"@salesforce/salesforcedx-vscode-test-tools": "^1.2.5",
|
|
70
70
|
"@tony.ganchev/eslint-plugin-header": "^3.1.6",
|
|
71
71
|
"@types/chai": "^4.3.11",
|