pro-editor-schema 0.1.184 → 0.1.185

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.d.mts CHANGED
@@ -34,8 +34,8 @@ declare const SCHEMAS: Record<SchemaCode, Schema>;
34
34
 
35
35
  declare const isIgnoredAttribute: (attribute: string) => boolean;
36
36
  declare const isIgnoredElement: (element: Element) => boolean;
37
- declare const findSchemaByCode: (code: SchemaCode) => Schema | undefined;
38
- declare const findSchemaByElement: (element: Element) => Schema | undefined;
37
+ declare const findSchemaByCode: (code: SchemaCode) => Schema;
38
+ declare const findSchemaByElement: (element: Element) => Schema;
39
39
  declare const isAttributeRestricted: (attr: AttributeDefinition) => attr is RestrictedAttribute;
40
40
  declare const getAttributeName: (attribute: AttributeDefinition) => string;
41
41
  declare const findAttributeDefinitionByName: (definitions: readonly AttributeDefinition[], name: string) => AttributeDefinition | undefined;
@@ -102,10 +102,10 @@ type ValidationError = {
102
102
 
103
103
  * @param xml - The XML document to validate.
104
104
  * @param elementsLinkedTo - The elements IDs that are linked to.
105
- * @param shouldValidateAgainstSchema - Whether to validate against the schema.
105
+ * @param schemasToValidateAgainst - The schemas to validate against.
106
106
  * * ValidateConsecutiveFootnotes and ValidateConsecutiveFootnoteCues are default validations.
107
107
  * @returns The validation errors.
108
108
  */
109
- declare const validateXml: (xml: Element, elementsLinkedTo: readonly string[], shouldValidateAgainstSchema?: boolean) => ValidationError[];
109
+ declare const validateXml: (xml: Element, elementsLinkedTo: readonly string[], schemasToValidateAgainst: SchemaCode[]) => ValidationError[];
110
110
 
111
111
  export { ALIGNMENT_ATTRIBUTE, ATOM_SCHEMAS, type AllowedChildren, type AtomSchemaCode, type AttributeDefinition, ELEMENT_SCHEMAS, ELE_ID_ATTRIBUTE, type ElementSchemaCode, FIGURE_PLACEMENT_ATTRIBUTE, type ForbiddenElement, type FreeAttribute, ID_ATTRS, IGNORED_ATTRIBUTES, IGNORED_ATTRIBUTES_STARTS_WITH, IGNORED_ELEMENT_SELECTORS, INDENT_TYPE_ATTRIBUTE, INLINE_ELEMENT_SCHEMAS, type InlineSchemaCode, LAYOUT_ATTRIBUTES, LAYOUT_CELL_WIDTH, LAYOUT_USER_ATTRIBUTE, LEFT_INDENT_ATTRIBUTE, ORIENTATION_ATTRIBUTE, PLACEMENT_ATTRIBUTE, RIGHT_INDENT_ATTRIBUTE, type ResolveTo, type RestrictedAttribute, SCHEMAS, SPACE_ABOVE_ATTRIBUTE, SPACE_BELOW_ATTRIBUTE, SPECIAL_INDENT_ATTRIBUTE, STORE_ATTRIBUTE, STYLE_NAME_ATTRIBUTE, type Schema, type SchemaCode, type SchemaKind, TRACK_CHANGES_ATTRS, TRACK_CHANGES_ATTR_DATA_DATE, TRACK_CHANGES_ATTR_DATA_TIME, TRACK_CHANGES_ATTR_DATA_USERID, TRACK_CHANGES_ATTR_DATA_USERNAME, type ValidationError, type ValidationErrorKind, type ValidationErrorLevel, createElement, findAttributeDefinitionByName, findSchemaByCode, findSchemaByElement, getAttributeName, isAttributeRestricted, isIgnoredAttribute, isIgnoredElement, validateXml };
package/dist/index.d.ts CHANGED
@@ -34,8 +34,8 @@ declare const SCHEMAS: Record<SchemaCode, Schema>;
34
34
 
35
35
  declare const isIgnoredAttribute: (attribute: string) => boolean;
36
36
  declare const isIgnoredElement: (element: Element) => boolean;
37
- declare const findSchemaByCode: (code: SchemaCode) => Schema | undefined;
38
- declare const findSchemaByElement: (element: Element) => Schema | undefined;
37
+ declare const findSchemaByCode: (code: SchemaCode) => Schema;
38
+ declare const findSchemaByElement: (element: Element) => Schema;
39
39
  declare const isAttributeRestricted: (attr: AttributeDefinition) => attr is RestrictedAttribute;
40
40
  declare const getAttributeName: (attribute: AttributeDefinition) => string;
41
41
  declare const findAttributeDefinitionByName: (definitions: readonly AttributeDefinition[], name: string) => AttributeDefinition | undefined;
@@ -102,10 +102,10 @@ type ValidationError = {
102
102
 
103
103
  * @param xml - The XML document to validate.
104
104
  * @param elementsLinkedTo - The elements IDs that are linked to.
105
- * @param shouldValidateAgainstSchema - Whether to validate against the schema.
105
+ * @param schemasToValidateAgainst - The schemas to validate against.
106
106
  * * ValidateConsecutiveFootnotes and ValidateConsecutiveFootnoteCues are default validations.
107
107
  * @returns The validation errors.
108
108
  */
109
- declare const validateXml: (xml: Element, elementsLinkedTo: readonly string[], shouldValidateAgainstSchema?: boolean) => ValidationError[];
109
+ declare const validateXml: (xml: Element, elementsLinkedTo: readonly string[], schemasToValidateAgainst: SchemaCode[]) => ValidationError[];
110
110
 
111
111
  export { ALIGNMENT_ATTRIBUTE, ATOM_SCHEMAS, type AllowedChildren, type AtomSchemaCode, type AttributeDefinition, ELEMENT_SCHEMAS, ELE_ID_ATTRIBUTE, type ElementSchemaCode, FIGURE_PLACEMENT_ATTRIBUTE, type ForbiddenElement, type FreeAttribute, ID_ATTRS, IGNORED_ATTRIBUTES, IGNORED_ATTRIBUTES_STARTS_WITH, IGNORED_ELEMENT_SELECTORS, INDENT_TYPE_ATTRIBUTE, INLINE_ELEMENT_SCHEMAS, type InlineSchemaCode, LAYOUT_ATTRIBUTES, LAYOUT_CELL_WIDTH, LAYOUT_USER_ATTRIBUTE, LEFT_INDENT_ATTRIBUTE, ORIENTATION_ATTRIBUTE, PLACEMENT_ATTRIBUTE, RIGHT_INDENT_ATTRIBUTE, type ResolveTo, type RestrictedAttribute, SCHEMAS, SPACE_ABOVE_ATTRIBUTE, SPACE_BELOW_ATTRIBUTE, SPECIAL_INDENT_ATTRIBUTE, STORE_ATTRIBUTE, STYLE_NAME_ATTRIBUTE, type Schema, type SchemaCode, type SchemaKind, TRACK_CHANGES_ATTRS, TRACK_CHANGES_ATTR_DATA_DATE, TRACK_CHANGES_ATTR_DATA_TIME, TRACK_CHANGES_ATTR_DATA_USERID, TRACK_CHANGES_ATTR_DATA_USERNAME, type ValidationError, type ValidationErrorKind, type ValidationErrorLevel, createElement, findAttributeDefinitionByName, findSchemaByCode, findSchemaByElement, getAttributeName, isAttributeRestricted, isIgnoredAttribute, isIgnoredElement, validateXml };
package/dist/index.js CHANGED
@@ -2272,10 +2272,7 @@ var findSchemaByElement = (element) => {
2272
2272
  const candidates = Object.values(SCHEMAS).filter(
2273
2273
  (schema) => schema.tag === element.tagName.toUpperCase()
2274
2274
  );
2275
- if (candidates.length > 0) {
2276
- return candidates[0];
2277
- }
2278
- return void 0;
2275
+ return candidates[0];
2279
2276
  };
2280
2277
  var isAttributeRestricted = (attr) => typeof attr !== "string";
2281
2278
  var getAttributeName = (attribute) => typeof attribute === "string" ? attribute : attribute.name;
@@ -2663,14 +2660,14 @@ var getLinkableRoles = () => {
2663
2660
  };
2664
2661
 
2665
2662
  // src/validation/validateXml.ts
2666
- var validateElement = (element, root, elementsLinkedTo, shouldValidateAgainstSchema = false) => {
2663
+ var validateElement = (element, root, elementsLinkedTo, schemasToValidateAgainst) => {
2667
2664
  if (isIgnoredElement(element)) {
2668
2665
  return [];
2669
2666
  }
2670
2667
  const errors = [];
2671
2668
  const schema = findSchemaByElement(element);
2672
2669
  if (schema) {
2673
- if (shouldValidateAgainstSchema) {
2670
+ if (schemasToValidateAgainst.includes(schema.code)) {
2674
2671
  errors.push(...validateElementAgainstSchema(element, schema));
2675
2672
  }
2676
2673
  const role = element.getAttribute("role") || "";
@@ -2683,11 +2680,18 @@ var validateElement = (element, root, elementsLinkedTo, shouldValidateAgainstSch
2683
2680
  }
2684
2681
  }
2685
2682
  for (const child of Array.from(element.children)) {
2686
- errors.push(...validateElement(child, root, elementsLinkedTo));
2683
+ errors.push(
2684
+ ...validateElement(
2685
+ child,
2686
+ root,
2687
+ elementsLinkedTo,
2688
+ schemasToValidateAgainst
2689
+ )
2690
+ );
2687
2691
  }
2688
2692
  return errors;
2689
2693
  };
2690
- var validateXml = (xml, elementsLinkedTo, shouldValidateAgainstSchema) => {
2694
+ var validateXml = (xml, elementsLinkedTo, schemasToValidateAgainst) => {
2691
2695
  const errors = [];
2692
2696
  errors.push(...validateConsecutiveFootnotes(xml));
2693
2697
  errors.push(...validateConsecutiveFootnoteCues(xml));
@@ -2697,7 +2701,7 @@ var validateXml = (xml, elementsLinkedTo, shouldValidateAgainstSchema) => {
2697
2701
  child,
2698
2702
  xml,
2699
2703
  elementsLinkedTo,
2700
- shouldValidateAgainstSchema
2704
+ schemasToValidateAgainst
2701
2705
  )
2702
2706
  );
2703
2707
  }
package/dist/index.mjs CHANGED
@@ -2209,10 +2209,7 @@ var findSchemaByElement = (element) => {
2209
2209
  const candidates = Object.values(SCHEMAS).filter(
2210
2210
  (schema) => schema.tag === element.tagName.toUpperCase()
2211
2211
  );
2212
- if (candidates.length > 0) {
2213
- return candidates[0];
2214
- }
2215
- return void 0;
2212
+ return candidates[0];
2216
2213
  };
2217
2214
  var isAttributeRestricted = (attr) => typeof attr !== "string";
2218
2215
  var getAttributeName = (attribute) => typeof attribute === "string" ? attribute : attribute.name;
@@ -2600,14 +2597,14 @@ var getLinkableRoles = () => {
2600
2597
  };
2601
2598
 
2602
2599
  // src/validation/validateXml.ts
2603
- var validateElement = (element, root, elementsLinkedTo, shouldValidateAgainstSchema = false) => {
2600
+ var validateElement = (element, root, elementsLinkedTo, schemasToValidateAgainst) => {
2604
2601
  if (isIgnoredElement(element)) {
2605
2602
  return [];
2606
2603
  }
2607
2604
  const errors = [];
2608
2605
  const schema = findSchemaByElement(element);
2609
2606
  if (schema) {
2610
- if (shouldValidateAgainstSchema) {
2607
+ if (schemasToValidateAgainst.includes(schema.code)) {
2611
2608
  errors.push(...validateElementAgainstSchema(element, schema));
2612
2609
  }
2613
2610
  const role = element.getAttribute("role") || "";
@@ -2620,11 +2617,18 @@ var validateElement = (element, root, elementsLinkedTo, shouldValidateAgainstSch
2620
2617
  }
2621
2618
  }
2622
2619
  for (const child of Array.from(element.children)) {
2623
- errors.push(...validateElement(child, root, elementsLinkedTo));
2620
+ errors.push(
2621
+ ...validateElement(
2622
+ child,
2623
+ root,
2624
+ elementsLinkedTo,
2625
+ schemasToValidateAgainst
2626
+ )
2627
+ );
2624
2628
  }
2625
2629
  return errors;
2626
2630
  };
2627
- var validateXml = (xml, elementsLinkedTo, shouldValidateAgainstSchema) => {
2631
+ var validateXml = (xml, elementsLinkedTo, schemasToValidateAgainst) => {
2628
2632
  const errors = [];
2629
2633
  errors.push(...validateConsecutiveFootnotes(xml));
2630
2634
  errors.push(...validateConsecutiveFootnoteCues(xml));
@@ -2634,7 +2638,7 @@ var validateXml = (xml, elementsLinkedTo, shouldValidateAgainstSchema) => {
2634
2638
  child,
2635
2639
  xml,
2636
2640
  elementsLinkedTo,
2637
- shouldValidateAgainstSchema
2641
+ schemasToValidateAgainst
2638
2642
  )
2639
2643
  );
2640
2644
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pro-editor-schema",
3
- "version": "0.1.184",
3
+ "version": "0.1.185",
4
4
  "description": "Pro Editor XML schemas",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",