jedison 0.2.0 → 0.2.2

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);
@@ -1530,6 +1557,7 @@ class Validator {
1530
1557
  }
1531
1558
  if (isBoolean(schemaClone) && schemaClone === false) {
1532
1559
  return [{
1560
+ type: "error",
1533
1561
  messages: ["invalid"],
1534
1562
  path
1535
1563
  }];
@@ -2071,8 +2099,9 @@ class Editor {
2071
2099
  }
2072
2100
  return this.description;
2073
2101
  }
2074
- getInfo() {
2075
- const schemaInfo = getSchemaXOption(this.instance.schema, "info");
2102
+ getInfo(schema = null) {
2103
+ const _schema = schema ?? this.instance.schema;
2104
+ const schemaInfo = getSchemaXOption(_schema, "info");
2076
2105
  if (!isSet(schemaInfo)) {
2077
2106
  return schemaInfo;
2078
2107
  }
@@ -2814,6 +2843,7 @@ const fontAwesome3 = {
2814
2843
  delete: "icon-trash",
2815
2844
  add: "icon-plus",
2816
2845
  moveUp: "icon-arrow-up",
2846
+ moveDown: "icon-arrow-down",
2817
2847
  collapse: "icon-chevron-down",
2818
2848
  expand: "icon-plus",
2819
2849
  drag: "icon-th",
@@ -3698,8 +3728,17 @@ class EditorArray extends Editor {
3698
3728
  }
3699
3729
  }
3700
3730
  class EditorArrayTable extends EditorArray {
3701
- static resolves(schema) {
3702
- return getSchemaType(schema) === "array" && getSchemaXOption(schema, "format") === "table";
3731
+ static resolves(schema, refParser) {
3732
+ const schemaItems = getSchemaItems(schema);
3733
+ if (!schemaItems) {
3734
+ return false;
3735
+ }
3736
+ const expandedSchemaItems = refParser.expand(schemaItems);
3737
+ const itemType = getSchemaType(expandedSchemaItems);
3738
+ if (!itemType) {
3739
+ return false;
3740
+ }
3741
+ return getSchemaType(schema) === "array" && itemType === "object" && getSchemaXOption(schema, "format") === "table";
3703
3742
  }
3704
3743
  addEventListeners() {
3705
3744
  this.control.addBtn.addEventListener("click", () => {
@@ -3721,24 +3760,28 @@ class EditorArrayTable extends EditorArray {
3721
3760
  });
3722
3761
  th.appendChild(label);
3723
3762
  table.thead.appendChild(th);
3724
- const tempEditor = this.instance.createItemInstance();
3725
- const tableColMinWidth = getSchemaXOption(this.instance.schema, "tableColMinWidth");
3726
- tempEditor.children.forEach((child) => {
3727
- const itemTableColWidth = getSchemaXOption(child.schema, "tableColMinWidth");
3728
- const th2 = this.theme.getTableHeader({
3729
- minWidth: itemTableColWidth || tableColMinWidth || "auto"
3730
- });
3731
- if (child.ui.control.label && child.ui.control.description) {
3732
- th2.appendChild(child.ui.control.label);
3733
- child.ui.control.label.setAttribute("title", child.ui.control.description.textContent);
3763
+ const schemaItems = getSchemaItems(this.instance.schema);
3764
+ const expandedSchemaItems = this.instance.jedison.refParser.expand(schemaItems);
3765
+ const itemProperties = getSchemaProperties(expandedSchemaItems);
3766
+ Object.values(itemProperties).forEach((propertySchema) => {
3767
+ const th2 = this.theme.getTableHeader();
3768
+ if (propertySchema.title) {
3769
+ const fakeLabel = this.theme.getFakeLabel({
3770
+ content: propertySchema.title
3771
+ });
3772
+ th2.appendChild(fakeLabel.label);
3734
3773
  }
3735
- if (child.ui.control.legend && child.ui.control.description) {
3736
- th2.appendChild(child.ui.control.legend);
3737
- child.ui.control.legend.setAttribute("title", child.ui.control.description.textContent);
3774
+ const schemaXInfo = getSchemaXOption(propertySchema, "info");
3775
+ if (isSet(schemaXInfo)) {
3776
+ const infoContent = this.getInfo(propertySchema);
3777
+ const info = this.theme.getInfo(infoContent);
3778
+ if (schemaXInfo.variant === "modal") {
3779
+ this.theme.infoAsModal(info, this.getIdFromPath(this.instance.path), infoContent);
3780
+ }
3781
+ th2.appendChild(info.container);
3738
3782
  }
3739
3783
  table.thead.appendChild(th2);
3740
3784
  });
3741
- tempEditor.destroy();
3742
3785
  const arrayDelete = getSchemaXOption(this.instance.schema, "arrayDelete") ?? this.instance.jedison.options.arrayDelete;
3743
3786
  const arrayMove = getSchemaXOption(this.instance.schema, "arrayMove") ?? this.instance.jedison.options.arrayMove;
3744
3787
  this.instance.children.forEach((child, index2) => {
@@ -3942,13 +3985,13 @@ class EditorArrayNav extends EditorArray {
3942
3985
  }
3943
3986
  const active = index2 === this.activeItemIndex;
3944
3987
  const id = pathToAttribute(child.path);
3945
- const { list } = this.theme.getTab({
3988
+ const { list, arrayActions } = this.theme.getTab({
3946
3989
  hasErrors: child.children.some((grandChild) => grandChild.ui.showingValidationErrors),
3947
3990
  title: (titleTemplate == null ? void 0 : titleTemplate.length) ? titleTemplate : childTitle,
3948
3991
  id,
3949
3992
  active
3950
3993
  });
3951
- list.appendChild(btnGroup);
3994
+ arrayActions.appendChild(btnGroup);
3952
3995
  list.addEventListener("click", () => {
3953
3996
  this.activeItemIndex = index2;
3954
3997
  });
@@ -4297,6 +4340,7 @@ class EditorArrayCheckboxes extends Editor {
4297
4340
  class UiResolver {
4298
4341
  constructor(options) {
4299
4342
  this.customEditors = options.customEditors ?? [];
4343
+ this.refParser = options.refParser ?? null;
4300
4344
  this.editors = [
4301
4345
  EditorMultiple,
4302
4346
  EditorIfThenElse,
@@ -4330,12 +4374,12 @@ class UiResolver {
4330
4374
  }
4331
4375
  getClass(schema) {
4332
4376
  for (const editor of this.customEditors) {
4333
- if (editor.resolves(schema)) {
4377
+ if (editor.resolves(schema, this.refParser)) {
4334
4378
  return editor;
4335
4379
  }
4336
4380
  }
4337
4381
  for (const editor of this.editors) {
4338
- if (editor.resolves(schema)) {
4382
+ if (editor.resolves(schema, this.refParser)) {
4339
4383
  return editor;
4340
4384
  }
4341
4385
  }
@@ -4691,7 +4735,8 @@ class Jedison extends EventEmitter {
4691
4735
  this.isEditor = true;
4692
4736
  }
4693
4737
  this.uiResolver = new UiResolver({
4694
- customEditors: this.options.customEditors
4738
+ customEditors: this.options.customEditors,
4739
+ refParser: this.refParser
4695
4740
  });
4696
4741
  this.theme = this.options.theme;
4697
4742
  if (this.theme) {
@@ -5020,25 +5065,30 @@ class Jedison extends EventEmitter {
5020
5065
  }
5021
5066
  /**
5022
5067
  * Get an array of validation errors
5023
- * @param filters
5068
+ * @param {string[]} filters - Types to include, e.g., ['errors', 'warnings']
5024
5069
  * @returns {*[]}
5025
5070
  */
5026
- getErrors(filters = {}) {
5027
- const finalOptions = Object.assign({
5028
- errors: true,
5029
- warnings: true
5030
- }, filters);
5071
+ getErrors(filters = ["error"]) {
5031
5072
  let results = [];
5032
5073
  Object.keys(this.instances).forEach((key) => {
5033
5074
  const instance = this.instances[key];
5034
5075
  results = [...results, ...instance.getErrors()];
5035
5076
  });
5036
- if (finalOptions.results === false) {
5037
- results = results.filter((error) => error.type !== "error");
5038
- }
5039
- if (finalOptions.warnings === false) {
5040
- results = results.filter((error) => error.type !== "warning");
5041
- }
5077
+ return results.filter((error) => {
5078
+ return filters.includes(error.type.toLowerCase());
5079
+ });
5080
+ }
5081
+ export() {
5082
+ const results = [];
5083
+ Object.keys(this.instances).forEach((key) => {
5084
+ const instance = this.instances[key];
5085
+ results.push({
5086
+ path: instance.path ?? "-",
5087
+ type: instance.schema.type ?? "-",
5088
+ title: instance.ui.getTitle() ?? "-",
5089
+ value: instance.getValue() ?? "-"
5090
+ });
5091
+ });
5042
5092
  return results;
5043
5093
  }
5044
5094
  /**
@@ -5054,7 +5104,7 @@ class Jedison extends EventEmitter {
5054
5104
  if (!this.options.container) {
5055
5105
  return false;
5056
5106
  }
5057
- const errors = errorsList || this.getErrors();
5107
+ const errors = errorsList ?? this.getErrors();
5058
5108
  Object.keys(this.instances).forEach((key) => {
5059
5109
  const instance = this.instances[key];
5060
5110
  instance.ui.showValidationErrors(errors, true);
@@ -6563,11 +6613,16 @@ class Theme {
6563
6613
  getTab(config) {
6564
6614
  const list = document.createElement("li");
6565
6615
  const link = document.createElement("a");
6616
+ const arrayActions = document.createElement("span");
6617
+ const text = document.createElement("span");
6566
6618
  link.classList.add("jedi-nav-link");
6567
6619
  link.setAttribute("href", "#" + config.id);
6568
- link.textContent = config.hasErrors ? "" + config.title : config.title;
6620
+ text.classList.add("jedi-nav-text");
6621
+ text.textContent = config.hasErrors ? "⚠ " + config.title : config.title;
6622
+ link.appendChild(arrayActions);
6623
+ link.appendChild(text);
6569
6624
  list.appendChild(link);
6570
- return { list, link };
6625
+ return { list, link, arrayActions, text };
6571
6626
  }
6572
6627
  /**
6573
6628
  * Wrapper for tabs
@@ -6889,6 +6944,7 @@ class ThemeBootstrap3 extends Theme {
6889
6944
  }
6890
6945
  getTab(config) {
6891
6946
  const tab = super.getTab(config);
6947
+ tab.text.style.marginLeft = "15px";
6892
6948
  if (config.active) {
6893
6949
  tab.list.classList.add("active");
6894
6950
  }
@@ -7222,6 +7278,8 @@ class ThemeBootstrap4 extends Theme {
7222
7278
  getTab(config) {
7223
7279
  const tab = super.getTab(config);
7224
7280
  tab.list.classList.add("nav-item");
7281
+ tab.list.classList.add("mb-3");
7282
+ tab.text.classList.add("ml-3");
7225
7283
  tab.link.classList.add("nav-link");
7226
7284
  tab.link.setAttribute("data-toggle", "tab");
7227
7285
  if (config.active) {
@@ -7552,6 +7610,8 @@ class ThemeBootstrap5 extends Theme {
7552
7610
  getTab(config) {
7553
7611
  const tab = super.getTab(config);
7554
7612
  tab.list.classList.add("nav-item");
7613
+ tab.list.classList.add("mb-3");
7614
+ tab.text.classList.add("ms-3");
7555
7615
  tab.link.classList.add("nav-link");
7556
7616
  tab.link.setAttribute("data-bs-toggle", "tab");
7557
7617
  if (config.active) {
@@ -7664,7 +7724,8 @@ const index = {
7664
7724
  ThemeBootstrap4,
7665
7725
  ThemeBootstrap5,
7666
7726
  RefParser,
7667
- Create: Jedison
7727
+ Create: Jedison,
7728
+ SchemaGenerator
7668
7729
  };
7669
7730
  export {
7670
7731
  index as default