@accelerated-agency/visual-editor 0.7.0 → 0.7.1

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 (2) hide show
  1. package/dist/index.js +87 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4936,6 +4936,9 @@ function PlatformVisualEditorV2({
4936
4936
  onSaveError,
4937
4937
  onRequestSave,
4938
4938
  onUploadImage,
4939
+ onListImages,
4940
+ onAiAssist,
4941
+ onAiApplied,
4939
4942
  onNavigateRequested,
4940
4943
  onDiscardDirty,
4941
4944
  renderHeader,
@@ -4994,6 +4997,58 @@ function PlatformVisualEditorV2({
4994
4997
  },
4995
4998
  [sendToVvveb]
4996
4999
  );
5000
+ const handleListImages = useCallback(
5001
+ async (payload) => {
5002
+ const requestId = typeof payload?.requestId === "string" ? payload.requestId : null;
5003
+ if (!onListImages) {
5004
+ sendToVvveb("list-images-result", {
5005
+ requestId,
5006
+ ok: false,
5007
+ error: "Image list is not available"
5008
+ });
5009
+ return;
5010
+ }
5011
+ try {
5012
+ const result = await onListImages();
5013
+ const images = Array.isArray(result?.images) ? result.images.filter((img) => img && typeof img.url === "string" && img.url) : [];
5014
+ sendToVvveb("list-images-result", { requestId, ok: true, images });
5015
+ } catch (err) {
5016
+ sendToVvveb("list-images-result", {
5017
+ requestId,
5018
+ ok: false,
5019
+ error: uploadImageErrorMessage(err, "The list was refused")
5020
+ });
5021
+ }
5022
+ },
5023
+ [onListImages, sendToVvveb]
5024
+ );
5025
+ const handleAiRequest = useCallback(
5026
+ async (payload) => {
5027
+ const requestId = typeof payload?.requestId === "string" ? payload.requestId : null;
5028
+ if (!onAiAssist) {
5029
+ sendToVvveb("ai-result", {
5030
+ requestId,
5031
+ ok: false,
5032
+ error: "The assistant is not switched on for this workspace"
5033
+ });
5034
+ return;
5035
+ }
5036
+ try {
5037
+ const result = await onAiAssist(payload ?? {});
5038
+ sendToVvveb("ai-result", {
5039
+ ...result,
5040
+ requestId: result?.requestId || requestId
5041
+ });
5042
+ } catch (err) {
5043
+ sendToVvveb("ai-result", {
5044
+ requestId,
5045
+ ok: false,
5046
+ error: uploadImageErrorMessage(err, "The assistant did not answer. Try again.")
5047
+ });
5048
+ }
5049
+ },
5050
+ [onAiAssist, sendToVvveb]
5051
+ );
4997
5052
  const loadPayload = useMemo(
4998
5053
  () => ({
4999
5054
  iid: experiment?.iid,
@@ -5011,10 +5066,20 @@ function PlatformVisualEditorV2({
5011
5066
  // state; an older shell ignores the field and behaves as it did before.
5012
5067
  capabilities: {
5013
5068
  saveResult: true,
5014
- ...onUploadImage ? { uploadImage: true } : {}
5069
+ ...onUploadImage ? { uploadImage: true } : {},
5070
+ ...onListImages ? { listImages: true } : {},
5071
+ ...onAiAssist ? { ai: true } : {}
5015
5072
  }
5016
5073
  }),
5017
- [conversionProxyBaseUrl, experiment, onUploadImage, strictObserverFreeze, trackingMarkers]
5074
+ [
5075
+ conversionProxyBaseUrl,
5076
+ experiment,
5077
+ onAiAssist,
5078
+ onListImages,
5079
+ onUploadImage,
5080
+ strictObserverFreeze,
5081
+ trackingMarkers
5082
+ ]
5018
5083
  );
5019
5084
  const editorSrc = useMemo(() => {
5020
5085
  const workerBase = normalizeProxyBaseUrl(conversionProxyBaseUrl);
@@ -5098,6 +5163,21 @@ function PlatformVisualEditorV2({
5098
5163
  sendUploadImageResult(payload, null, err);
5099
5164
  }
5100
5165
  break;
5166
+ case "list-images":
5167
+ if (typeof e.stopImmediatePropagation === "function") e.stopImmediatePropagation();
5168
+ await handleListImages(payload);
5169
+ break;
5170
+ case "ai-request":
5171
+ if (typeof e.stopImmediatePropagation === "function") e.stopImmediatePropagation();
5172
+ await handleAiRequest(payload);
5173
+ break;
5174
+ case "ai-applied":
5175
+ if (typeof e.stopImmediatePropagation === "function") e.stopImmediatePropagation();
5176
+ try {
5177
+ await onAiApplied?.(payload ?? {});
5178
+ } catch {
5179
+ }
5180
+ break;
5101
5181
  case "close-editor":
5102
5182
  if (payload?.discard === true) {
5103
5183
  onClose?.();
@@ -5124,6 +5204,11 @@ function PlatformVisualEditorV2({
5124
5204
  onEditorUrlChanged,
5125
5205
  onRequestSave,
5126
5206
  onUploadImage,
5207
+ onListImages,
5208
+ onAiAssist,
5209
+ onAiApplied,
5210
+ handleListImages,
5211
+ handleAiRequest,
5127
5212
  onSaveSuccess,
5128
5213
  onSaveError,
5129
5214
  onNavigateRequested,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@accelerated-agency/visual-editor",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "private": false,
5
5
  "description": "Conversion visual editor as a reusable React package",
6
6
  "type": "module",