jedison 0.2.1 → 0.2.3

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.
@@ -439,6 +439,33 @@ const Schema = {
439
439
  getSchemaUnevaluatedProperties,
440
440
  getSchemaUniqueItems
441
441
  };
442
+ class SchemaGenerator {
443
+ static inferType(value) {
444
+ if (Array.isArray(value)) return "array";
445
+ if (value === null) return "null";
446
+ return typeof value;
447
+ }
448
+ static generate(obj) {
449
+ if (typeof obj !== "object" || obj === null) {
450
+ return { type: this.inferType(obj) };
451
+ }
452
+ if (Array.isArray(obj)) {
453
+ const itemSchemas = obj.map((item) => this.generate(item));
454
+ return {
455
+ type: "array",
456
+ items: itemSchemas.length ? itemSchemas[0] : {}
457
+ };
458
+ }
459
+ const properties2 = {};
460
+ for (const key in obj) {
461
+ properties2[key] = this.generate(obj[key]);
462
+ }
463
+ return {
464
+ type: "object",
465
+ properties: properties2
466
+ };
467
+ }
468
+ }
442
469
  function allOf(context) {
443
470
  let errors = [];
444
471
  const allOf2 = getSchemaAllOf(context.schema);
@@ -3702,12 +3729,14 @@ class EditorArray extends Editor {
3702
3729
  }
3703
3730
  class EditorArrayTable extends EditorArray {
3704
3731
  static resolves(schema, refParser) {
3705
- const schemaItems = getSchemaItems(schema);
3732
+ let schemaItems = getSchemaItems(schema);
3706
3733
  if (!schemaItems) {
3707
3734
  return false;
3708
3735
  }
3709
- const expandedSchemaItems = refParser.expand(schemaItems);
3710
- const itemType = getSchemaType(expandedSchemaItems);
3736
+ if (refParser) {
3737
+ schemaItems = refParser.expand(schemaItems);
3738
+ }
3739
+ const itemType = getSchemaType(schemaItems);
3711
3740
  if (!itemType) {
3712
3741
  return false;
3713
3742
  }
@@ -3733,9 +3762,11 @@ class EditorArrayTable extends EditorArray {
3733
3762
  });
3734
3763
  th.appendChild(label);
3735
3764
  table.thead.appendChild(th);
3736
- const schemaItems = getSchemaItems(this.instance.schema);
3737
- const expandedSchemaItems = this.instance.jedison.refParser.expand(schemaItems);
3738
- const itemProperties = getSchemaProperties(expandedSchemaItems);
3765
+ let schemaItems = getSchemaItems(this.instance.schema);
3766
+ if (this.instance.jedison.refParser) {
3767
+ schemaItems = this.instance.jedison.refParser.expand(schemaItems);
3768
+ }
3769
+ const itemProperties = getSchemaProperties(schemaItems);
3739
3770
  Object.values(itemProperties).forEach((propertySchema) => {
3740
3771
  const th2 = this.theme.getTableHeader();
3741
3772
  if (propertySchema.title) {
@@ -3958,13 +3989,13 @@ class EditorArrayNav extends EditorArray {
3958
3989
  }
3959
3990
  const active = index2 === this.activeItemIndex;
3960
3991
  const id = pathToAttribute(child.path);
3961
- const { list } = this.theme.getTab({
3992
+ const { list, arrayActions } = this.theme.getTab({
3962
3993
  hasErrors: child.children.some((grandChild) => grandChild.ui.showingValidationErrors),
3963
3994
  title: (titleTemplate == null ? void 0 : titleTemplate.length) ? titleTemplate : childTitle,
3964
3995
  id,
3965
3996
  active
3966
3997
  });
3967
- list.appendChild(btnGroup);
3998
+ arrayActions.appendChild(btnGroup);
3968
3999
  list.addEventListener("click", () => {
3969
4000
  this.activeItemIndex = index2;
3970
4001
  });
@@ -5051,6 +5082,19 @@ class Jedison extends EventEmitter {
5051
5082
  return filters.includes(error.type.toLowerCase());
5052
5083
  });
5053
5084
  }
5085
+ export() {
5086
+ const results = [];
5087
+ Object.keys(this.instances).forEach((key) => {
5088
+ const instance = this.instances[key];
5089
+ results.push({
5090
+ path: instance.path ?? "-",
5091
+ type: instance.schema.type ?? "-",
5092
+ title: instance.ui.getTitle() ?? "-",
5093
+ value: instance.getValue() ?? "-"
5094
+ });
5095
+ });
5096
+ return results;
5097
+ }
5054
5098
  /**
5055
5099
  * Displays validation errors in the respective editors.
5056
5100
  * If an errors list is passed, it will display these errors;
@@ -6573,11 +6617,16 @@ class Theme {
6573
6617
  getTab(config) {
6574
6618
  const list = document.createElement("li");
6575
6619
  const link = document.createElement("a");
6620
+ const arrayActions = document.createElement("span");
6621
+ const text = document.createElement("span");
6576
6622
  link.classList.add("jedi-nav-link");
6577
6623
  link.setAttribute("href", "#" + config.id);
6578
- link.textContent = config.hasErrors ? "" + config.title : config.title;
6624
+ text.classList.add("jedi-nav-text");
6625
+ text.textContent = config.hasErrors ? "⚠ " + config.title : config.title;
6626
+ link.appendChild(arrayActions);
6627
+ link.appendChild(text);
6579
6628
  list.appendChild(link);
6580
- return { list, link };
6629
+ return { list, link, arrayActions, text };
6581
6630
  }
6582
6631
  /**
6583
6632
  * Wrapper for tabs
@@ -6899,6 +6948,7 @@ class ThemeBootstrap3 extends Theme {
6899
6948
  }
6900
6949
  getTab(config) {
6901
6950
  const tab = super.getTab(config);
6951
+ tab.text.style.marginLeft = "15px";
6902
6952
  if (config.active) {
6903
6953
  tab.list.classList.add("active");
6904
6954
  }
@@ -7232,6 +7282,8 @@ class ThemeBootstrap4 extends Theme {
7232
7282
  getTab(config) {
7233
7283
  const tab = super.getTab(config);
7234
7284
  tab.list.classList.add("nav-item");
7285
+ tab.list.classList.add("mb-3");
7286
+ tab.text.classList.add("ml-3");
7235
7287
  tab.link.classList.add("nav-link");
7236
7288
  tab.link.setAttribute("data-toggle", "tab");
7237
7289
  if (config.active) {
@@ -7562,6 +7614,8 @@ class ThemeBootstrap5 extends Theme {
7562
7614
  getTab(config) {
7563
7615
  const tab = super.getTab(config);
7564
7616
  tab.list.classList.add("nav-item");
7617
+ tab.list.classList.add("mb-3");
7618
+ tab.text.classList.add("ms-3");
7565
7619
  tab.link.classList.add("nav-link");
7566
7620
  tab.link.setAttribute("data-bs-toggle", "tab");
7567
7621
  if (config.active) {
@@ -7674,7 +7728,8 @@ const index = {
7674
7728
  ThemeBootstrap4,
7675
7729
  ThemeBootstrap5,
7676
7730
  RefParser,
7677
- Create: Jedison
7731
+ Create: Jedison,
7732
+ SchemaGenerator
7678
7733
  };
7679
7734
  export {
7680
7735
  index as default