pro-editor-schema 0.1.184 → 0.1.186

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;
@@ -2575,6 +2572,9 @@ var validateChildren = (element, schema) => {
2575
2572
  (child) => !isIgnoredElement(child)
2576
2573
  );
2577
2574
  const allowedChildren = [...schema.allowedChildTagNames];
2575
+ if (schema.kind === "atom") {
2576
+ return errors;
2577
+ }
2578
2578
  for (const child of childElements) {
2579
2579
  const childTag = child.tagName.toUpperCase();
2580
2580
  const allowedChild = allowedChildren.find(
@@ -2663,14 +2663,14 @@ var getLinkableRoles = () => {
2663
2663
  };
2664
2664
 
2665
2665
  // src/validation/validateXml.ts
2666
- var validateElement = (element, root, elementsLinkedTo, shouldValidateAgainstSchema = false) => {
2666
+ var validateElement = (element, root, elementsLinkedTo, schemasToValidateAgainst) => {
2667
2667
  if (isIgnoredElement(element)) {
2668
2668
  return [];
2669
2669
  }
2670
2670
  const errors = [];
2671
2671
  const schema = findSchemaByElement(element);
2672
2672
  if (schema) {
2673
- if (shouldValidateAgainstSchema) {
2673
+ if (schemasToValidateAgainst.includes(schema.code)) {
2674
2674
  errors.push(...validateElementAgainstSchema(element, schema));
2675
2675
  }
2676
2676
  const role = element.getAttribute("role") || "";
@@ -2683,11 +2683,18 @@ var validateElement = (element, root, elementsLinkedTo, shouldValidateAgainstSch
2683
2683
  }
2684
2684
  }
2685
2685
  for (const child of Array.from(element.children)) {
2686
- errors.push(...validateElement(child, root, elementsLinkedTo));
2686
+ errors.push(
2687
+ ...validateElement(
2688
+ child,
2689
+ root,
2690
+ elementsLinkedTo,
2691
+ schemasToValidateAgainst
2692
+ )
2693
+ );
2687
2694
  }
2688
2695
  return errors;
2689
2696
  };
2690
- var validateXml = (xml, elementsLinkedTo, shouldValidateAgainstSchema) => {
2697
+ var validateXml = (xml, elementsLinkedTo, schemasToValidateAgainst) => {
2691
2698
  const errors = [];
2692
2699
  errors.push(...validateConsecutiveFootnotes(xml));
2693
2700
  errors.push(...validateConsecutiveFootnoteCues(xml));
@@ -2697,7 +2704,7 @@ var validateXml = (xml, elementsLinkedTo, shouldValidateAgainstSchema) => {
2697
2704
  child,
2698
2705
  xml,
2699
2706
  elementsLinkedTo,
2700
- shouldValidateAgainstSchema
2707
+ schemasToValidateAgainst
2701
2708
  )
2702
2709
  );
2703
2710
  }
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;
@@ -2512,6 +2509,9 @@ var validateChildren = (element, schema) => {
2512
2509
  (child) => !isIgnoredElement(child)
2513
2510
  );
2514
2511
  const allowedChildren = [...schema.allowedChildTagNames];
2512
+ if (schema.kind === "atom") {
2513
+ return errors;
2514
+ }
2515
2515
  for (const child of childElements) {
2516
2516
  const childTag = child.tagName.toUpperCase();
2517
2517
  const allowedChild = allowedChildren.find(
@@ -2600,14 +2600,14 @@ var getLinkableRoles = () => {
2600
2600
  };
2601
2601
 
2602
2602
  // src/validation/validateXml.ts
2603
- var validateElement = (element, root, elementsLinkedTo, shouldValidateAgainstSchema = false) => {
2603
+ var validateElement = (element, root, elementsLinkedTo, schemasToValidateAgainst) => {
2604
2604
  if (isIgnoredElement(element)) {
2605
2605
  return [];
2606
2606
  }
2607
2607
  const errors = [];
2608
2608
  const schema = findSchemaByElement(element);
2609
2609
  if (schema) {
2610
- if (shouldValidateAgainstSchema) {
2610
+ if (schemasToValidateAgainst.includes(schema.code)) {
2611
2611
  errors.push(...validateElementAgainstSchema(element, schema));
2612
2612
  }
2613
2613
  const role = element.getAttribute("role") || "";
@@ -2620,11 +2620,18 @@ var validateElement = (element, root, elementsLinkedTo, shouldValidateAgainstSch
2620
2620
  }
2621
2621
  }
2622
2622
  for (const child of Array.from(element.children)) {
2623
- errors.push(...validateElement(child, root, elementsLinkedTo));
2623
+ errors.push(
2624
+ ...validateElement(
2625
+ child,
2626
+ root,
2627
+ elementsLinkedTo,
2628
+ schemasToValidateAgainst
2629
+ )
2630
+ );
2624
2631
  }
2625
2632
  return errors;
2626
2633
  };
2627
- var validateXml = (xml, elementsLinkedTo, shouldValidateAgainstSchema) => {
2634
+ var validateXml = (xml, elementsLinkedTo, schemasToValidateAgainst) => {
2628
2635
  const errors = [];
2629
2636
  errors.push(...validateConsecutiveFootnotes(xml));
2630
2637
  errors.push(...validateConsecutiveFootnoteCues(xml));
@@ -2634,7 +2641,7 @@ var validateXml = (xml, elementsLinkedTo, shouldValidateAgainstSchema) => {
2634
2641
  child,
2635
2642
  xml,
2636
2643
  elementsLinkedTo,
2637
- shouldValidateAgainstSchema
2644
+ schemasToValidateAgainst
2638
2645
  )
2639
2646
  );
2640
2647
  }
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.186",
4
4
  "description": "Pro Editor XML schemas",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",