@elementor/editor-controls 4.2.0-895 → 4.2.0-897

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/index.js CHANGED
@@ -8206,6 +8206,35 @@ var FORM_FIELD_WIDGET_TYPES = [
8206
8206
  "e-form-date-picker",
8207
8207
  "e-form-time-picker"
8208
8208
  ];
8209
+ var FORM_ELEMENT_TYPE = "e-form";
8210
+ var CSS_ID_PROP_KEY = "_cssid";
8211
+ function isFormFieldWidgetType(widgetType) {
8212
+ return FORM_FIELD_WIDGET_TYPES.includes(widgetType);
8213
+ }
8214
+ function extractStringPropValue(value) {
8215
+ return import_editor_props64.stringPropTypeUtil.extract(value);
8216
+ }
8217
+ function getSettingWithDefault(child, widgetType, key) {
8218
+ const fromGet = child.settings.get(key);
8219
+ if (fromGet !== null && fromGet !== void 0) {
8220
+ return fromGet;
8221
+ }
8222
+ const schema = (0, import_editor_elements7.getWidgetsCache)()?.[widgetType]?.atomic_props_schema;
8223
+ return schema?.[key]?.default ?? null;
8224
+ }
8225
+ function getFieldCssId(child, widgetType) {
8226
+ return extractStringPropValue(getSettingWithDefault(child, widgetType, CSS_ID_PROP_KEY));
8227
+ }
8228
+ function getFormContainer(elementId) {
8229
+ let container = (0, import_editor_elements7.getContainer)(elementId);
8230
+ while (container) {
8231
+ if (container.model.get("elType") === FORM_ELEMENT_TYPE) {
8232
+ return container;
8233
+ }
8234
+ container = container.parent ?? null;
8235
+ }
8236
+ return null;
8237
+ }
8209
8238
  function useFormFieldSuggestions(options) {
8210
8239
  return (0, import_editor_v1_adapters2.__privateUseListenTo)(
8211
8240
  [
@@ -8216,32 +8245,33 @@ function useFormFieldSuggestions(options) {
8216
8245
  ],
8217
8246
  () => {
8218
8247
  const selectedElements = (0, import_editor_elements7.getSelectedElements)();
8219
- const formElement = selectedElements[0];
8220
- if (!formElement) {
8248
+ const selectedElement = selectedElements[0];
8249
+ if (!selectedElement) {
8221
8250
  return [];
8222
8251
  }
8223
- const container = (0, import_editor_elements7.getContainer)(formElement.id);
8224
- if (!container?.children) {
8252
+ const formContainer = getFormContainer(selectedElement.id);
8253
+ if (!formContainer?.children) {
8225
8254
  return [];
8226
8255
  }
8227
8256
  const suggestions = [];
8228
- container.children.forEachRecursive?.((child) => {
8257
+ const seenCssIds = /* @__PURE__ */ new Set();
8258
+ formContainer.children.forEachRecursive?.((child) => {
8229
8259
  const widgetType = child.model.get("widgetType");
8230
- if (!widgetType || !FORM_FIELD_WIDGET_TYPES.includes(widgetType)) {
8260
+ if (!widgetType || !isFormFieldWidgetType(widgetType)) {
8231
8261
  return;
8232
8262
  }
8233
8263
  if (options?.inputType) {
8234
- const typeProp = child.settings.get("type");
8235
- const typeValue = (0, import_editor_props64.isTransformable)(typeProp) ? typeProp.value : typeProp;
8264
+ const typeValue = extractStringPropValue(getSettingWithDefault(child, widgetType, "type"));
8236
8265
  if (typeValue !== options.inputType) {
8237
8266
  return;
8238
8267
  }
8239
8268
  }
8240
- const cssIdProp = child.settings.get("_cssid");
8241
- const fieldId = (0, import_editor_props64.isTransformable)(cssIdProp) ? cssIdProp.value : cssIdProp;
8242
- if (fieldId && typeof fieldId === "string") {
8243
- suggestions.push({ label: fieldId, value: fieldId });
8269
+ const cssId = getFieldCssId(child, widgetType);
8270
+ if (!cssId || seenCssIds.has(cssId)) {
8271
+ return;
8244
8272
  }
8273
+ seenCssIds.add(cssId);
8274
+ suggestions.push({ label: cssId, value: cssId });
8245
8275
  });
8246
8276
  return suggestions;
8247
8277
  },