@alpaca-editor/sharedien-dam 1.0.4146 → 1.0.4147

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alpaca-editor/sharedien-dam",
3
- "version": "1.0.4146",
3
+ "version": "1.0.4147",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,11 +1,12 @@
1
- import { ClientFieldButton, PictureRawValue } from "@alpaca-editor/core";
1
+ import { ClientFieldButton, PictureRawValue, VariantFieldActionProps } from "@alpaca-editor/core";
2
2
  import { DamSelector } from "./DamSelector";
3
3
  import { DamImageValue, DamSelectorProps } from "./types";
4
4
 
5
5
  export const DamSelectorButton: ClientFieldButton = {
6
- label: "Open sharedien DAM",
6
+ label: "Select from DAM",
7
7
  icon: "pi pi-external-link",
8
- clientAction: async ({ editContext, field }) => {
8
+ showInMenu: false, // Primary action - appears outside menu
9
+ clientAction: async ({ editContext, field, variantName: contextVariantName }: VariantFieldActionProps) => {
9
10
  const data = await editContext.openDialog<DamImageValue, DamSelectorProps>(DamSelector, {
10
11
  language: field.descriptor.item.language
11
12
  });
@@ -22,24 +23,43 @@ export const DamSelectorButton: ClientFieldButton = {
22
23
  }
23
24
  })();
24
25
 
25
- if (raw.Variants && raw.Variants.length > 0 && raw.Variants[0]?.Name) {
26
- const variantName = raw.Variants[0].Name;
27
- const selected = raw.Variants.find((x: any) => x.Name == variantName);
28
- if (selected) {
29
- selected.MediaId = data.mediaId;
30
- selected.VideoId = data.videoId;
31
- } else {
32
- raw.Variants.push({
33
- Name: variantName,
34
- MediaId: data.mediaId,
35
- VideoId: data.videoId,
36
- });
26
+ // Get variant name from context (when called from PictureEditor variant button)
27
+ // or fallback to trying to determine it from field data
28
+ let variantName: string | undefined = contextVariantName;
29
+
30
+ if (!variantName && raw.Variants && raw.Variants.length > 0) {
31
+ // Use the first variant's name if available
32
+ variantName = raw.Variants[0]?.Name;
33
+ }
34
+
35
+ // If we still don't have a variant name, try to get it from the field's value
36
+ if (!variantName && field.value && typeof field.value === 'object' && 'variants' in field.value) {
37
+ const variants = (field.value as any).variants;
38
+ if (Array.isArray(variants) && variants.length > 0 && variants[0]?.name) {
39
+ variantName = variants[0].name;
37
40
  }
38
- } else {
39
- console.warn("No existing variants with valid names found in picture field. Cannot determine variant name for DAM selection.");
41
+ }
42
+
43
+ if (!variantName) {
44
+ console.warn("Cannot determine variant name for DAM selection. No variants found in picture field.");
40
45
  return;
41
46
  }
42
47
 
48
+ // Update or create the variant
49
+ if (!raw.Variants) raw.Variants = [];
50
+ const selected = raw.Variants.find((x: any) => x.Name == variantName);
51
+
52
+ if (selected) {
53
+ selected.MediaId = data.mediaId;
54
+ selected.VideoId = data.videoId;
55
+ } else {
56
+ raw.Variants.push({
57
+ Name: variantName,
58
+ MediaId: data.mediaId,
59
+ VideoId: data.videoId,
60
+ });
61
+ }
62
+
43
63
  editContext!.operations.editField({
44
64
  field: field.descriptor,
45
65
  rawValue: JSON.stringify(raw),
@@ -48,6 +68,6 @@ export const DamSelectorButton: ClientFieldButton = {
48
68
  }
49
69
  },
50
70
  isGenerator: false,
51
- id: "open-sharedien-dam",
52
- description: "Opens the sharedien DAM to select an image",
71
+ id: "select-from-dam",
72
+ description: "Opens the sharedien DAM to select an image or video",
53
73
  }
package/src/index.ts CHANGED
@@ -19,15 +19,16 @@ export function configureSharedienDam(
19
19
  if (!configuration.fieldTypes.picture) {
20
20
  configuration.fieldTypes.picture = {
21
21
  editor: () => null,
22
- buttons: []
22
+ variantButtons: []
23
23
  }
24
24
  }
25
25
 
26
- if (!configuration.fieldTypes.picture.buttons) {
27
- configuration.fieldTypes.picture.buttons = [];
26
+ if (!configuration.fieldTypes.picture.variantButtons) {
27
+ configuration.fieldTypes.picture.variantButtons = [];
28
28
  }
29
29
 
30
- //configuration.fieldTypes.picture.buttons.push(DamSelectorButton);
30
+ // Add DAM selector button as a variant button (appears for each picture variant)
31
+ configuration.fieldTypes.picture.variantButtons.push(DamSelectorButton);
31
32
 
32
33
  return configuration;
33
34
  }