jedison 0.2.0 → 0.2.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.
@@ -1530,6 +1530,7 @@ class Validator {
1530
1530
  }
1531
1531
  if (isBoolean(schemaClone) && schemaClone === false) {
1532
1532
  return [{
1533
+ type: "error",
1533
1534
  messages: ["invalid"],
1534
1535
  path
1535
1536
  }];
@@ -2071,8 +2072,9 @@ class Editor {
2071
2072
  }
2072
2073
  return this.description;
2073
2074
  }
2074
- getInfo() {
2075
- const schemaInfo = getSchemaXOption(this.instance.schema, "info");
2075
+ getInfo(schema = null) {
2076
+ const _schema = schema ?? this.instance.schema;
2077
+ const schemaInfo = getSchemaXOption(_schema, "info");
2076
2078
  if (!isSet(schemaInfo)) {
2077
2079
  return schemaInfo;
2078
2080
  }
@@ -2814,6 +2816,7 @@ const fontAwesome3 = {
2814
2816
  delete: "icon-trash",
2815
2817
  add: "icon-plus",
2816
2818
  moveUp: "icon-arrow-up",
2819
+ moveDown: "icon-arrow-down",
2817
2820
  collapse: "icon-chevron-down",
2818
2821
  expand: "icon-plus",
2819
2822
  drag: "icon-th",
@@ -3698,8 +3701,17 @@ class EditorArray extends Editor {
3698
3701
  }
3699
3702
  }
3700
3703
  class EditorArrayTable extends EditorArray {
3701
- static resolves(schema) {
3702
- return getSchemaType(schema) === "array" && getSchemaXOption(schema, "format") === "table";
3704
+ static resolves(schema, refParser) {
3705
+ const schemaItems = getSchemaItems(schema);
3706
+ if (!schemaItems) {
3707
+ return false;
3708
+ }
3709
+ const expandedSchemaItems = refParser.expand(schemaItems);
3710
+ const itemType = getSchemaType(expandedSchemaItems);
3711
+ if (!itemType) {
3712
+ return false;
3713
+ }
3714
+ return getSchemaType(schema) === "array" && itemType === "object" && getSchemaXOption(schema, "format") === "table";
3703
3715
  }
3704
3716
  addEventListeners() {
3705
3717
  this.control.addBtn.addEventListener("click", () => {
@@ -3721,24 +3733,28 @@ class EditorArrayTable extends EditorArray {
3721
3733
  });
3722
3734
  th.appendChild(label);
3723
3735
  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);
3736
+ const schemaItems = getSchemaItems(this.instance.schema);
3737
+ const expandedSchemaItems = this.instance.jedison.refParser.expand(schemaItems);
3738
+ const itemProperties = getSchemaProperties(expandedSchemaItems);
3739
+ Object.values(itemProperties).forEach((propertySchema) => {
3740
+ const th2 = this.theme.getTableHeader();
3741
+ if (propertySchema.title) {
3742
+ const fakeLabel = this.theme.getFakeLabel({
3743
+ content: propertySchema.title
3744
+ });
3745
+ th2.appendChild(fakeLabel.label);
3734
3746
  }
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);
3747
+ const schemaXInfo = getSchemaXOption(propertySchema, "info");
3748
+ if (isSet(schemaXInfo)) {
3749
+ const infoContent = this.getInfo(propertySchema);
3750
+ const info = this.theme.getInfo(infoContent);
3751
+ if (schemaXInfo.variant === "modal") {
3752
+ this.theme.infoAsModal(info, this.getIdFromPath(this.instance.path), infoContent);
3753
+ }
3754
+ th2.appendChild(info.container);
3738
3755
  }
3739
3756
  table.thead.appendChild(th2);
3740
3757
  });
3741
- tempEditor.destroy();
3742
3758
  const arrayDelete = getSchemaXOption(this.instance.schema, "arrayDelete") ?? this.instance.jedison.options.arrayDelete;
3743
3759
  const arrayMove = getSchemaXOption(this.instance.schema, "arrayMove") ?? this.instance.jedison.options.arrayMove;
3744
3760
  this.instance.children.forEach((child, index2) => {
@@ -4297,6 +4313,7 @@ class EditorArrayCheckboxes extends Editor {
4297
4313
  class UiResolver {
4298
4314
  constructor(options) {
4299
4315
  this.customEditors = options.customEditors ?? [];
4316
+ this.refParser = options.refParser ?? null;
4300
4317
  this.editors = [
4301
4318
  EditorMultiple,
4302
4319
  EditorIfThenElse,
@@ -4330,12 +4347,12 @@ class UiResolver {
4330
4347
  }
4331
4348
  getClass(schema) {
4332
4349
  for (const editor of this.customEditors) {
4333
- if (editor.resolves(schema)) {
4350
+ if (editor.resolves(schema, this.refParser)) {
4334
4351
  return editor;
4335
4352
  }
4336
4353
  }
4337
4354
  for (const editor of this.editors) {
4338
- if (editor.resolves(schema)) {
4355
+ if (editor.resolves(schema, this.refParser)) {
4339
4356
  return editor;
4340
4357
  }
4341
4358
  }
@@ -4691,7 +4708,8 @@ class Jedison extends EventEmitter {
4691
4708
  this.isEditor = true;
4692
4709
  }
4693
4710
  this.uiResolver = new UiResolver({
4694
- customEditors: this.options.customEditors
4711
+ customEditors: this.options.customEditors,
4712
+ refParser: this.refParser
4695
4713
  });
4696
4714
  this.theme = this.options.theme;
4697
4715
  if (this.theme) {
@@ -5020,26 +5038,18 @@ class Jedison extends EventEmitter {
5020
5038
  }
5021
5039
  /**
5022
5040
  * Get an array of validation errors
5023
- * @param filters
5041
+ * @param {string[]} filters - Types to include, e.g., ['errors', 'warnings']
5024
5042
  * @returns {*[]}
5025
5043
  */
5026
- getErrors(filters = {}) {
5027
- const finalOptions = Object.assign({
5028
- errors: true,
5029
- warnings: true
5030
- }, filters);
5044
+ getErrors(filters = ["error"]) {
5031
5045
  let results = [];
5032
5046
  Object.keys(this.instances).forEach((key) => {
5033
5047
  const instance = this.instances[key];
5034
5048
  results = [...results, ...instance.getErrors()];
5035
5049
  });
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
- }
5042
- return results;
5050
+ return results.filter((error) => {
5051
+ return filters.includes(error.type.toLowerCase());
5052
+ });
5043
5053
  }
5044
5054
  /**
5045
5055
  * Displays validation errors in the respective editors.
@@ -5054,7 +5064,7 @@ class Jedison extends EventEmitter {
5054
5064
  if (!this.options.container) {
5055
5065
  return false;
5056
5066
  }
5057
- const errors = errorsList || this.getErrors();
5067
+ const errors = errorsList ?? this.getErrors();
5058
5068
  Object.keys(this.instances).forEach((key) => {
5059
5069
  const instance = this.instances[key];
5060
5070
  instance.ui.showValidationErrors(errors, true);