jupiter-dynamic-forms 1.18.6 → 1.18.7

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.mjs CHANGED
@@ -3056,6 +3056,16 @@ function determineInputTypeFromBaseChain(baseTypeChain, datatypes) {
3056
3056
  placeholder: I18n.t("field.enterWholeNumber")
3057
3057
  };
3058
3058
  }
3059
+ if (chainLower.some((type) => type.includes("percent") || type.includes("pure"))) {
3060
+ return {
3061
+ fieldType: "percentage",
3062
+ htmlInputType: "text",
3063
+ inputMode: "decimal",
3064
+ allowDecimals: true,
3065
+ step: 0.01,
3066
+ placeholder: I18n.t("field.enterPercentage")
3067
+ };
3068
+ }
3059
3069
  if (chainLower.some((type) => type.includes("decimal") || type === "decimal")) {
3060
3070
  if (chainString.includes("monetary") || chainString.includes("currency")) {
3061
3071
  if (chainString.includes("nodecimals") || chainString.includes("no-decimals") || chainString.includes("nodecimals20")) {
@@ -3230,6 +3240,17 @@ let JupiterFormField = class extends LitElement {
3230
3240
  }
3231
3241
  this._numericDraftValue = null;
3232
3242
  }
3243
+ if (this._isPercentItemType() && this.value !== null && this.value !== void 0) {
3244
+ const numVal = Number(this.value);
3245
+ if (!isNaN(numVal) && Math.abs(numVal) >= 1) {
3246
+ this.value = numVal / 100;
3247
+ const oldValue = numVal;
3248
+ this.dispatchEvent(new CustomEvent("field-change", {
3249
+ detail: { fieldId: this.field.id, conceptId: this.conceptId, columnId: this.columnId, value: this.value, oldValue },
3250
+ bubbles: true
3251
+ }));
3252
+ }
3253
+ }
3233
3254
  this._touched = true;
3234
3255
  this._validateXBRLDatatype();
3235
3256
  this._validateUnitSelection();
@@ -3264,6 +3285,16 @@ let JupiterFormField = class extends LitElement {
3264
3285
  (type) => type.includes("monetary") || type.includes("Monetary")
3265
3286
  );
3266
3287
  }
3288
+ _isPercentItemType() {
3289
+ if (!this.conceptType)
3290
+ return false;
3291
+ if (this.conceptType.toLowerCase().includes("percent"))
3292
+ return true;
3293
+ if (!this.datatypes)
3294
+ return false;
3295
+ const baseTypeChain = resolveBaseTypeChain(this.conceptType, this.datatypes);
3296
+ return baseTypeChain.some((type) => type.toLowerCase().includes("percent"));
3297
+ }
3267
3298
  /**
3268
3299
  * Prevents non-numeric input in number fields for Firefox compatibility
3269
3300
  * Firefox allows typing any character in type="number" inputs
@@ -3779,7 +3810,14 @@ let JupiterFormField = class extends LitElement {
3779
3810
  const step = typeConfig.step !== void 0 ? typeConfig.step : isNumericType(effectiveFieldType) ? "any" : void 0;
3780
3811
  const min = typeConfig.min;
3781
3812
  const max = typeConfig.max;
3782
- const renderedInputValue = this._isNumericField() && this._numericDraftValue !== null ? this._numericDraftValue : effectiveValue ?? "";
3813
+ let renderedInputValue;
3814
+ if (this._isNumericField() && this._numericDraftValue !== null) {
3815
+ renderedInputValue = this._numericDraftValue;
3816
+ } else if (effectiveFieldType === "percentage" && effectiveValue !== null && effectiveValue !== void 0 && effectiveValue !== "") {
3817
+ renderedInputValue = Number(effectiveValue).toFixed(4);
3818
+ } else {
3819
+ renderedInputValue = effectiveValue ?? "";
3820
+ }
3783
3821
  return html`
3784
3822
  <input
3785
3823
  id="${fieldId}"
@@ -3973,7 +4011,7 @@ let JupiterFormField = class extends LitElement {
3973
4011
  </div>
3974
4012
  ` : ""}
3975
4013
 
3976
- ${this._isMonetaryType() ? html`
4014
+ ${this._isMonetaryType() || this._isPercentItemType() ? html`
3977
4015
  <div class="period-controls">
3978
4016
  <label>${I18n.t("field.scale")}:</label>
3979
4017
  <input
@@ -3981,7 +4019,7 @@ let JupiterFormField = class extends LitElement {
3981
4019
  min="0"
3982
4020
  class="typed-member-input"
3983
4021
  placeholder="Leave blank for INF"
3984
- .value="${this.decimals !== void 0 && this.decimals !== null && this.decimals !== "" ? this.decimals : this.globalDecimals !== "INF" ? this.globalDecimals : ""}"
4022
+ .value="${this.decimals !== void 0 && this.decimals !== null && this.decimals !== "" ? this.decimals : this._isPercentItemType() ? "4" : this.globalDecimals !== "INF" ? this.globalDecimals : ""}"
3985
4023
  @input="${this._handleDecimalsChange}"
3986
4024
  ?disabled="${this.disabled}"
3987
4025
  />
@@ -11268,7 +11306,7 @@ let JupiterDynamicForm = class extends LitElement {
11268
11306
  return null;
11269
11307
  }
11270
11308
  _addConceptDataToSubmission(concept, columnId, value, submissionData, section2) {
11271
- var _a, _b, _c, _d, _e;
11309
+ var _a, _b, _c, _d, _e, _f, _g;
11272
11310
  const field2 = concept.fields.find((f2) => f2.columnId === columnId);
11273
11311
  if (!field2)
11274
11312
  return;
@@ -11280,6 +11318,12 @@ let JupiterDynamicForm = class extends LitElement {
11280
11318
  const periodStartDate = (fieldPeriodData == null ? void 0 : fieldPeriodData.startDate) || (column2 == null ? void 0 : column2.periodStartDate) || field2.periodStartDate || this.periodStartDate;
11281
11319
  const periodEndDate = (fieldPeriodData == null ? void 0 : fieldPeriodData.endDate) || (column2 == null ? void 0 : column2.periodEndDate) || field2.periodEndDate || this.periodEndDate;
11282
11320
  const periodInstantDate = (fieldPeriodData == null ? void 0 : fieldPeriodData.instantDate) || field2.periodInstantDate || periodEndDate || periodStartDate;
11321
+ if ((_c = concept.type) == null ? void 0 : _c.toLowerCase().includes("percentitemtype")) {
11322
+ const numericValue = Number(value);
11323
+ if (!isNaN(numericValue) && Math.abs(numericValue) >= 1) {
11324
+ value = numericValue / 100;
11325
+ }
11326
+ }
11283
11327
  const entry = {
11284
11328
  conceptId: concept.originalConceptId || concept.id,
11285
11329
  columnId,
@@ -11296,14 +11340,16 @@ let JupiterDynamicForm = class extends LitElement {
11296
11340
  entry.unit = fieldUnit;
11297
11341
  console.log(`✅ [Submission] Adding unit to entry: ${fieldUnit} for ${concept.id}/${columnId}`);
11298
11342
  }
11299
- const isMonetary = (_c = concept.type) == null ? void 0 : _c.toLowerCase().includes("monetary");
11300
- const fieldDecimals = (_d = this._decimalsData[concept.id]) == null ? void 0 : _d[columnId];
11301
- const decimalsValue = fieldDecimals || (this.decimals !== "INF" ? this.decimals : void 0);
11302
- if (isMonetary && decimalsValue) {
11343
+ const isMonetary = (_d = concept.type) == null ? void 0 : _d.toLowerCase().includes("monetary");
11344
+ const isPercent = (_e = concept.type) == null ? void 0 : _e.toLowerCase().includes("percentitemtype");
11345
+ const fieldDecimals = (_f = this._decimalsData[concept.id]) == null ? void 0 : _f[columnId];
11346
+ const globalFallback = isPercent ? "4" : this.decimals !== "INF" ? this.decimals : void 0;
11347
+ const decimalsValue = fieldDecimals || globalFallback;
11348
+ if ((isMonetary || isPercent) && decimalsValue) {
11303
11349
  const parsed = parseFloat(decimalsValue);
11304
11350
  entry.decimals = isNaN(parsed) ? decimalsValue : String(-Math.abs(parsed));
11305
11351
  }
11306
- if ((_e = column2 == null ? void 0 : column2.dimensionData) == null ? void 0 : _e.memberLabel) {
11352
+ if ((_g = column2 == null ? void 0 : column2.dimensionData) == null ? void 0 : _g.memberLabel) {
11307
11353
  entry.dimension = column2.dimensionData.memberLabel;
11308
11354
  }
11309
11355
  console.log(`📤 [Submission Entry] Created entry:`, JSON.stringify(entry, null, 2));
@@ -11441,7 +11487,7 @@ let JupiterDynamicForm = class extends LitElement {
11441
11487
  }
11442
11488
  if (concept.fields && concept.fields.length > 0) {
11443
11489
  concept.fields.forEach((field2) => {
11444
- var _a, _b, _c, _d, _e, _f, _g, _h;
11490
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11445
11491
  const conceptData = this._formData[concept.id];
11446
11492
  let fieldValue = conceptData == null ? void 0 : conceptData[field2.columnId];
11447
11493
  const baseConceptId = field2.conceptId || concept.id.split("__").slice(0, -1).join("__") || concept.id;
@@ -11459,8 +11505,14 @@ let JupiterDynamicForm = class extends LitElement {
11459
11505
  }
11460
11506
  }
11461
11507
  if (fieldValue !== void 0 && fieldValue !== null && fieldValue !== "") {
11508
+ if ((_b = concept.type) == null ? void 0 : _b.toLowerCase().includes("percentitemtype")) {
11509
+ const numericFieldValue = Number(fieldValue);
11510
+ if (!isNaN(numericFieldValue) && Math.abs(numericFieldValue) >= 1) {
11511
+ fieldValue = numericFieldValue / 100;
11512
+ }
11513
+ }
11462
11514
  const column2 = this._findColumnByIdInSection(field2.columnId, section2);
11463
- const fieldPeriodData = (_b = this._periodData[concept.id]) == null ? void 0 : _b[field2.columnId];
11515
+ const fieldPeriodData = (_c = this._periodData[concept.id]) == null ? void 0 : _c[field2.columnId];
11464
11516
  const submissionEntry = {
11465
11517
  conceptId: concept.id,
11466
11518
  draftInstanceId: concept.id,
@@ -11482,21 +11534,23 @@ let JupiterDynamicForm = class extends LitElement {
11482
11534
  submissionEntry.period.endDate = endDate;
11483
11535
  }
11484
11536
  console.log(`🔍 [Submission] Concept: ${concept.id}, Column: ${field2.columnId}, Field Period: ${fieldPeriodData ? JSON.stringify(fieldPeriodData) : "none"}, Column Period: ${(column2 == null ? void 0 : column2.periodStartDate) || "none"} - ${(column2 == null ? void 0 : column2.periodEndDate) || "none"}, Used Period: ${submissionEntry.period.type === "instant" ? submissionEntry.period.date : `${submissionEntry.period.startDate} - ${submissionEntry.period.endDate}`}`);
11485
- const fieldUnit = (_c = this._unitData[concept.id]) == null ? void 0 : _c[field2.columnId];
11537
+ const fieldUnit = (_d = this._unitData[concept.id]) == null ? void 0 : _d[field2.columnId];
11486
11538
  if (fieldUnit) {
11487
11539
  submissionEntry.unit = fieldUnit;
11488
11540
  console.log(`✅ [Submission] Adding unit to entry: ${fieldUnit} for ${concept.id}/${field2.columnId}`);
11489
11541
  } else {
11490
11542
  console.log(`⚠️ [Submission] No unit found in _unitData for ${concept.id}/${field2.columnId}. _unitData state:`, JSON.stringify(this._unitData, null, 2));
11491
11543
  }
11492
- const isMonetary = (_d = concept.type) == null ? void 0 : _d.toLowerCase().includes("monetary");
11493
- const fieldDecimals = (_e = this._decimalsData[concept.id]) == null ? void 0 : _e[field2.columnId];
11494
- const decimalsValue = fieldDecimals || (this.decimals !== "INF" ? this.decimals : void 0);
11495
- if (isMonetary && decimalsValue) {
11544
+ const isMonetary = (_e = concept.type) == null ? void 0 : _e.toLowerCase().includes("monetary");
11545
+ const isPercent = (_f = concept.type) == null ? void 0 : _f.toLowerCase().includes("percentitemtype");
11546
+ const fieldDecimals = (_g = this._decimalsData[concept.id]) == null ? void 0 : _g[field2.columnId];
11547
+ const globalFallback = isPercent ? "4" : this.decimals !== "INF" ? this.decimals : void 0;
11548
+ const decimalsValue = fieldDecimals || globalFallback;
11549
+ if ((isMonetary || isPercent) && decimalsValue) {
11496
11550
  const parsed = parseFloat(decimalsValue);
11497
11551
  submissionEntry.decimals = isNaN(parsed) ? decimalsValue : String(-Math.abs(parsed));
11498
11552
  }
11499
- if ((column2 == null ? void 0 : column2.type) === "dimension" && ((_f = column2.dimensionData) == null ? void 0 : _f.dimensionIdKey)) {
11553
+ if ((column2 == null ? void 0 : column2.type) === "dimension" && ((_h = column2.dimensionData) == null ? void 0 : _h.dimensionIdKey)) {
11500
11554
  submissionEntry.dimension = column2.dimensionData.dimensionIdKey;
11501
11555
  console.log(`🔍 [DynamicForm] Using dimension key from field's column (${field2.columnId}):`, column2.dimensionData.dimensionIdKey);
11502
11556
  } else {
@@ -11532,12 +11586,12 @@ let JupiterDynamicForm = class extends LitElement {
11532
11586
  console.log(`🔍 [DynamicForm] Column details:`, {
11533
11587
  id: column2.id,
11534
11588
  type: column2.type,
11535
- hasTypedMembers: (_g = column2.dimensionData) == null ? void 0 : _g.hasTypedMembers,
11589
+ hasTypedMembers: (_i = column2.dimensionData) == null ? void 0 : _i.hasTypedMembers,
11536
11590
  dimensionData: column2.dimensionData
11537
11591
  });
11538
11592
  }
11539
11593
  }
11540
- if (!submissionEntry.typedMembers && ((_h = field2.crossRoleTypedMembers) == null ? void 0 : _h.length)) {
11594
+ if (!submissionEntry.typedMembers && ((_j = field2.crossRoleTypedMembers) == null ? void 0 : _j.length)) {
11541
11595
  const crossRoleKey = `${concept.id}__${field2.columnId}`;
11542
11596
  const crossRoleValues = this._typedMemberData[crossRoleKey];
11543
11597
  if (crossRoleValues) {
@@ -11904,8 +11958,17 @@ let JupiterDynamicForm = class extends LitElement {
11904
11958
  return result;
11905
11959
  }
11906
11960
  const query = searchText.toLowerCase().trim();
11961
+ const addAllDescendants = (concepts) => {
11962
+ var _a2;
11963
+ for (const concept of concepts) {
11964
+ result.add(concept.id);
11965
+ if ((_a2 = concept.children) == null ? void 0 : _a2.length) {
11966
+ addAllDescendants(concept.children);
11967
+ }
11968
+ }
11969
+ };
11907
11970
  const walkConcepts = (concepts) => {
11908
- var _a2, _b2, _c2;
11971
+ var _a2, _b2, _c2, _d;
11909
11972
  for (const concept of concepts) {
11910
11973
  let matches = ((_a2 = concept.conceptName) == null ? void 0 : _a2.toLowerCase().includes(query)) || ((_b2 = concept.id) == null ? void 0 : _b2.toLowerCase().includes(query));
11911
11974
  if (!matches && Array.isArray(concept.labels)) {
@@ -11916,8 +11979,10 @@ let JupiterDynamicForm = class extends LitElement {
11916
11979
  }
11917
11980
  if (matches) {
11918
11981
  result.add(concept.id);
11919
- }
11920
- if ((_c2 = concept.children) == null ? void 0 : _c2.length) {
11982
+ if ((_c2 = concept.children) == null ? void 0 : _c2.length) {
11983
+ addAllDescendants(concept.children);
11984
+ }
11985
+ } else if ((_d = concept.children) == null ? void 0 : _d.length) {
11921
11986
  walkConcepts(concept.children);
11922
11987
  }
11923
11988
  }