pro-editor-schema 0.1.183 → 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
@@ -2037,9 +2037,9 @@ var MATHPHRASE_SCHEMA = createSchema({
2037
2037
  }
2038
2038
  ],
2039
2039
  forbiddenElements: [
2040
- { code: QUERY_SCHEMA.code, resolveTo: "remove" },
2041
- { code: COMMENT_SCHEMA.code, resolveTo: "remove" },
2042
- { code: COMMENT_QUERY_SECTION_SCHEMA.code, resolveTo: "unwrap" }
2040
+ { code: QUERY_SCHEMA.code, resolveTo: "skip" },
2041
+ { code: COMMENT_SCHEMA.code, resolveTo: "skip" },
2042
+ { code: COMMENT_QUERY_SECTION_SCHEMA.code, resolveTo: "skip" }
2043
2043
  ]
2044
2044
  });
2045
2045
 
@@ -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;
@@ -2601,6 +2598,21 @@ var validateChildren = (element, schema) => {
2601
2598
  });
2602
2599
  continue;
2603
2600
  }
2601
+ if (schema.forbiddenElements) {
2602
+ const forbiddenChild = Array.from(schema.forbiddenElements).find(
2603
+ (candidate) => candidate.code === childSchema.code
2604
+ );
2605
+ if (forbiddenChild) {
2606
+ addValidationIssue(errors, {
2607
+ store: getStore(child),
2608
+ title: `Forbidden element ${child.tagName}`,
2609
+ level: "blocker",
2610
+ kind: "forbidden",
2611
+ description: `The element ${childSchema.code} is not permitted within ${schema.tag} content. Please delete the element or move it to a different location.`
2612
+ });
2613
+ continue;
2614
+ }
2615
+ }
2604
2616
  errors.push(...validateElementAgainstSchema(child, childSchema));
2605
2617
  }
2606
2618
  for (const allowedChild of allowedChildren) {
@@ -2623,10 +2635,10 @@ var validateChildren = (element, schema) => {
2623
2635
  if (schema.allowedChildTagNames.size === 0 && childElements.length > 0) {
2624
2636
  addValidationIssue(errors, {
2625
2637
  store: getStore(element),
2626
- title: "Leaf element cannot contain child elements",
2638
+ title: "Atom element cannot contain child elements",
2627
2639
  level: "warning",
2628
2640
  kind: "forbidden",
2629
- description: `The element is a leaf element and cannot contain child elements.`
2641
+ description: `The element is an atom element and cannot contain child elements.`
2630
2642
  });
2631
2643
  }
2632
2644
  return errors;
@@ -2648,14 +2660,14 @@ var getLinkableRoles = () => {
2648
2660
  };
2649
2661
 
2650
2662
  // src/validation/validateXml.ts
2651
- var validateElement = (element, root, elementsLinkedTo, shouldValidateAgainstSchema = false) => {
2663
+ var validateElement = (element, root, elementsLinkedTo, schemasToValidateAgainst) => {
2652
2664
  if (isIgnoredElement(element)) {
2653
2665
  return [];
2654
2666
  }
2655
2667
  const errors = [];
2656
2668
  const schema = findSchemaByElement(element);
2657
2669
  if (schema) {
2658
- if (shouldValidateAgainstSchema) {
2670
+ if (schemasToValidateAgainst.includes(schema.code)) {
2659
2671
  errors.push(...validateElementAgainstSchema(element, schema));
2660
2672
  }
2661
2673
  const role = element.getAttribute("role") || "";
@@ -2668,11 +2680,18 @@ var validateElement = (element, root, elementsLinkedTo, shouldValidateAgainstSch
2668
2680
  }
2669
2681
  }
2670
2682
  for (const child of Array.from(element.children)) {
2671
- errors.push(...validateElement(child, root, elementsLinkedTo));
2683
+ errors.push(
2684
+ ...validateElement(
2685
+ child,
2686
+ root,
2687
+ elementsLinkedTo,
2688
+ schemasToValidateAgainst
2689
+ )
2690
+ );
2672
2691
  }
2673
2692
  return errors;
2674
2693
  };
2675
- var validateXml = (xml, elementsLinkedTo, shouldValidateAgainstSchema) => {
2694
+ var validateXml = (xml, elementsLinkedTo, schemasToValidateAgainst) => {
2676
2695
  const errors = [];
2677
2696
  errors.push(...validateConsecutiveFootnotes(xml));
2678
2697
  errors.push(...validateConsecutiveFootnoteCues(xml));
@@ -2682,7 +2701,7 @@ var validateXml = (xml, elementsLinkedTo, shouldValidateAgainstSchema) => {
2682
2701
  child,
2683
2702
  xml,
2684
2703
  elementsLinkedTo,
2685
- shouldValidateAgainstSchema
2704
+ schemasToValidateAgainst
2686
2705
  )
2687
2706
  );
2688
2707
  }
package/dist/index.mjs CHANGED
@@ -1974,9 +1974,9 @@ var MATHPHRASE_SCHEMA = createSchema({
1974
1974
  }
1975
1975
  ],
1976
1976
  forbiddenElements: [
1977
- { code: QUERY_SCHEMA.code, resolveTo: "remove" },
1978
- { code: COMMENT_SCHEMA.code, resolveTo: "remove" },
1979
- { code: COMMENT_QUERY_SECTION_SCHEMA.code, resolveTo: "unwrap" }
1977
+ { code: QUERY_SCHEMA.code, resolveTo: "skip" },
1978
+ { code: COMMENT_SCHEMA.code, resolveTo: "skip" },
1979
+ { code: COMMENT_QUERY_SECTION_SCHEMA.code, resolveTo: "skip" }
1980
1980
  ]
1981
1981
  });
1982
1982
 
@@ -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;
@@ -2538,6 +2535,21 @@ var validateChildren = (element, schema) => {
2538
2535
  });
2539
2536
  continue;
2540
2537
  }
2538
+ if (schema.forbiddenElements) {
2539
+ const forbiddenChild = Array.from(schema.forbiddenElements).find(
2540
+ (candidate) => candidate.code === childSchema.code
2541
+ );
2542
+ if (forbiddenChild) {
2543
+ addValidationIssue(errors, {
2544
+ store: getStore(child),
2545
+ title: `Forbidden element ${child.tagName}`,
2546
+ level: "blocker",
2547
+ kind: "forbidden",
2548
+ description: `The element ${childSchema.code} is not permitted within ${schema.tag} content. Please delete the element or move it to a different location.`
2549
+ });
2550
+ continue;
2551
+ }
2552
+ }
2541
2553
  errors.push(...validateElementAgainstSchema(child, childSchema));
2542
2554
  }
2543
2555
  for (const allowedChild of allowedChildren) {
@@ -2560,10 +2572,10 @@ var validateChildren = (element, schema) => {
2560
2572
  if (schema.allowedChildTagNames.size === 0 && childElements.length > 0) {
2561
2573
  addValidationIssue(errors, {
2562
2574
  store: getStore(element),
2563
- title: "Leaf element cannot contain child elements",
2575
+ title: "Atom element cannot contain child elements",
2564
2576
  level: "warning",
2565
2577
  kind: "forbidden",
2566
- description: `The element is a leaf element and cannot contain child elements.`
2578
+ description: `The element is an atom element and cannot contain child elements.`
2567
2579
  });
2568
2580
  }
2569
2581
  return errors;
@@ -2585,14 +2597,14 @@ var getLinkableRoles = () => {
2585
2597
  };
2586
2598
 
2587
2599
  // src/validation/validateXml.ts
2588
- var validateElement = (element, root, elementsLinkedTo, shouldValidateAgainstSchema = false) => {
2600
+ var validateElement = (element, root, elementsLinkedTo, schemasToValidateAgainst) => {
2589
2601
  if (isIgnoredElement(element)) {
2590
2602
  return [];
2591
2603
  }
2592
2604
  const errors = [];
2593
2605
  const schema = findSchemaByElement(element);
2594
2606
  if (schema) {
2595
- if (shouldValidateAgainstSchema) {
2607
+ if (schemasToValidateAgainst.includes(schema.code)) {
2596
2608
  errors.push(...validateElementAgainstSchema(element, schema));
2597
2609
  }
2598
2610
  const role = element.getAttribute("role") || "";
@@ -2605,11 +2617,18 @@ var validateElement = (element, root, elementsLinkedTo, shouldValidateAgainstSch
2605
2617
  }
2606
2618
  }
2607
2619
  for (const child of Array.from(element.children)) {
2608
- errors.push(...validateElement(child, root, elementsLinkedTo));
2620
+ errors.push(
2621
+ ...validateElement(
2622
+ child,
2623
+ root,
2624
+ elementsLinkedTo,
2625
+ schemasToValidateAgainst
2626
+ )
2627
+ );
2609
2628
  }
2610
2629
  return errors;
2611
2630
  };
2612
- var validateXml = (xml, elementsLinkedTo, shouldValidateAgainstSchema) => {
2631
+ var validateXml = (xml, elementsLinkedTo, schemasToValidateAgainst) => {
2613
2632
  const errors = [];
2614
2633
  errors.push(...validateConsecutiveFootnotes(xml));
2615
2634
  errors.push(...validateConsecutiveFootnoteCues(xml));
@@ -2619,7 +2638,7 @@ var validateXml = (xml, elementsLinkedTo, shouldValidateAgainstSchema) => {
2619
2638
  child,
2620
2639
  xml,
2621
2640
  elementsLinkedTo,
2622
- shouldValidateAgainstSchema
2641
+ schemasToValidateAgainst
2623
2642
  )
2624
2643
  );
2625
2644
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pro-editor-schema",
3
- "version": "0.1.183",
3
+ "version": "0.1.185",
4
4
  "description": "Pro Editor XML schemas",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -17,6 +17,7 @@
17
17
  ],
18
18
  "scripts": {
19
19
  "build": "tsup src/index.ts --format cjs,esm --dts",
20
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
20
21
  "typecheck": "tsc --noEmit",
21
22
  "test": "vitest run",
22
23
  "test:watch": "vitest"