@rogieking/figui3 8.11.0 → 8.11.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.
package/fig-lab.js CHANGED
@@ -2603,6 +2603,7 @@ figLabDefineElement("propskit-select", PropskitSelect);
2603
2603
  * @fires input - Shared PropsKit event with selected value and label.
2604
2604
  * @fires change - Shared PropsKit event with selected value and label.
2605
2605
  * @fires optionhover - Shared PropsKit event with hovered value and label.
2606
+ * @fires optionschange - Option mutation with action, option, index, and options.
2606
2607
  */
2607
2608
  class PropskitEditableSelect extends FigLabPropskitElement {
2608
2609
  static observedAttributes = [
@@ -3117,6 +3118,27 @@ class PropskitEditableSelect extends FigLabPropskitElement {
3117
3118
  }
3118
3119
  }
3119
3120
 
3121
+ #dispatchOptionsChange(action, option, index) {
3122
+ const value = this.value;
3123
+ const options = this.options.map((entry) => ({ ...entry }));
3124
+ const label =
3125
+ options.find((entry) => entry.value === value)?.label || "";
3126
+ this.dispatchEvent(
3127
+ new CustomEvent("optionschange", {
3128
+ detail: {
3129
+ ...figLabPropskitEventDetail(this, value),
3130
+ label,
3131
+ action,
3132
+ option: { ...option },
3133
+ index,
3134
+ options,
3135
+ },
3136
+ bubbles: true,
3137
+ composed: true,
3138
+ }),
3139
+ );
3140
+ }
3141
+
3120
3142
  #handleEditClick(event) {
3121
3143
  event.preventDefault();
3122
3144
  event.stopPropagation();
@@ -3151,10 +3173,13 @@ class PropskitEditableSelect extends FigLabPropskitElement {
3151
3173
  if (figLabBooleanAttribute(this, "disabled") || this.#input) return;
3152
3174
 
3153
3175
  const options = this.options;
3154
- const value = `item-${options.length}`;
3155
- this.options = [...options, { value, label: "New item" }];
3176
+ const index = options.length;
3177
+ const option = { value: `item-${index}`, label: "New item" };
3178
+ this.options = [...options, option];
3179
+ const value = option.value;
3156
3180
  this.#reflectValue(value);
3157
3181
  this.#syncSelectAttributes();
3182
+ this.#dispatchOptionsChange("add", option, index);
3158
3183
  for (const type of ["input", "change"]) {
3159
3184
  this.#dispatchOptionEvent(type);
3160
3185
  }
@@ -3218,6 +3243,7 @@ class PropskitEditableSelect extends FigLabPropskitElement {
3218
3243
  if (options.length <= 1) return;
3219
3244
  const index = options.findIndex((option) => option.value === value);
3220
3245
  if (index < 0) return;
3246
+ const removedOption = { ...options[index] };
3221
3247
 
3222
3248
  const wasOpen = this.#select.open;
3223
3249
  const selectedValue = this.value;
@@ -3237,8 +3263,11 @@ class PropskitEditableSelect extends FigLabPropskitElement {
3237
3263
  } finally {
3238
3264
  this.#suppressSelectEvents = false;
3239
3265
  }
3240
- for (const type of ["input", "change"]) {
3241
- this.#dispatchOptionEvent(type);
3266
+ this.#dispatchOptionsChange("delete", removedOption, index);
3267
+ if (selectedValue !== nextValue) {
3268
+ for (const type of ["input", "change"]) {
3269
+ this.#dispatchOptionEvent(type);
3270
+ }
3242
3271
  }
3243
3272
 
3244
3273
  queueMicrotask(() => {
@@ -3344,8 +3373,10 @@ class PropskitEditableSelect extends FigLabPropskitElement {
3344
3373
  const changed = label !== options[index].label;
3345
3374
  this.#finishEditing(false);
3346
3375
  if (changed) {
3347
- options[index] = { ...options[index], label };
3376
+ const option = { ...options[index], label };
3377
+ options[index] = option;
3348
3378
  this.options = options;
3379
+ this.#dispatchOptionsChange("rename", option, index);
3349
3380
  }
3350
3381
  this.#reflectValue(editingValue);
3351
3382
  this.#syncSelectAttributes();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "8.11.0",
3
+ "version": "8.11.1",
4
4
  "description": "A lightweight web components library for building Figma plugin and widget UIs with native look and feel",
5
5
  "author": "Rogie King",
6
6
  "license": "SEE LICENSE IN LICENSE",