@manuscripts/transform 3.0.45 → 3.0.46

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.
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.title = void 0;
18
+ exports.isTitleNode = exports.title = void 0;
19
19
  exports.title = {
20
20
  content: '(text | highlight_marker)*',
21
21
  attrs: {
@@ -27,3 +27,5 @@ exports.title = {
27
27
  parseDOM: [{ tag: 'div' }],
28
28
  toDOM: () => ['div', 0],
29
29
  };
30
+ const isTitleNode = (node) => node.type === node.type.schema.nodes.title;
31
+ exports.isTitleNode = isTitleNode;
@@ -33,3 +33,4 @@ __exportStar(require("./id"), exports);
33
33
  __exportStar(require("./node-names"), exports);
34
34
  __exportStar(require("./node-title"), exports);
35
35
  __exportStar(require("./node-types"), exports);
36
+ __exportStar(require("./node-validator"), exports);
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateManuscriptNode = exports.VALIDATION_ERROR_CODES = void 0;
4
+ const prosemirror_utils_1 = require("prosemirror-utils");
5
+ exports.VALIDATION_ERROR_CODES = {
6
+ EMPTY_TITLE: 'EMPTY_TITLE',
7
+ };
8
+ const validateTitleNode = (node) => {
9
+ const errors = [];
10
+ if (!node.textContent) {
11
+ errors.push({
12
+ code: exports.VALIDATION_ERROR_CODES.EMPTY_TITLE,
13
+ id: node.attrs.id,
14
+ });
15
+ }
16
+ return errors;
17
+ };
18
+ const validateNode = (nodeType, node, doc) => {
19
+ switch (nodeType.name) {
20
+ case 'title':
21
+ return validateTitleNode(node);
22
+ default:
23
+ return [];
24
+ }
25
+ };
26
+ const validateManuscriptNode = (doc) => {
27
+ const schema = doc.type.schema;
28
+ const validatableTypes = ['title'];
29
+ const errors = [];
30
+ validatableTypes.forEach((typeName) => {
31
+ const nodeType = schema.nodes[typeName];
32
+ if (nodeType) {
33
+ const nodes = (0, prosemirror_utils_1.findChildrenByType)(doc, nodeType).map((result) => result.node);
34
+ nodes.forEach((node) => {
35
+ const nodeErrors = validateNode(nodeType, node, doc);
36
+ errors.push(...nodeErrors);
37
+ });
38
+ }
39
+ });
40
+ return {
41
+ isValid: errors.length === 0,
42
+ errors,
43
+ };
44
+ };
45
+ exports.validateManuscriptNode = validateManuscriptNode;
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "3.0.45";
4
+ exports.VERSION = "3.0.46";
@@ -24,3 +24,4 @@ export const title = {
24
24
  parseDOM: [{ tag: 'div' }],
25
25
  toDOM: () => ['div', 0],
26
26
  };
27
+ export const isTitleNode = (node) => node.type === node.type.schema.nodes.title;
@@ -17,3 +17,4 @@ export * from './id';
17
17
  export * from './node-names';
18
18
  export * from './node-title';
19
19
  export * from './node-types';
20
+ export * from './node-validator';
@@ -0,0 +1,41 @@
1
+ import { findChildrenByType } from 'prosemirror-utils';
2
+ export const VALIDATION_ERROR_CODES = {
3
+ EMPTY_TITLE: 'EMPTY_TITLE',
4
+ };
5
+ const validateTitleNode = (node) => {
6
+ const errors = [];
7
+ if (!node.textContent) {
8
+ errors.push({
9
+ code: VALIDATION_ERROR_CODES.EMPTY_TITLE,
10
+ id: node.attrs.id,
11
+ });
12
+ }
13
+ return errors;
14
+ };
15
+ const validateNode = (nodeType, node, doc) => {
16
+ switch (nodeType.name) {
17
+ case 'title':
18
+ return validateTitleNode(node);
19
+ default:
20
+ return [];
21
+ }
22
+ };
23
+ export const validateManuscriptNode = (doc) => {
24
+ const schema = doc.type.schema;
25
+ const validatableTypes = ['title'];
26
+ const errors = [];
27
+ validatableTypes.forEach((typeName) => {
28
+ const nodeType = schema.nodes[typeName];
29
+ if (nodeType) {
30
+ const nodes = findChildrenByType(doc, nodeType).map((result) => result.node);
31
+ nodes.forEach((node) => {
32
+ const nodeErrors = validateNode(nodeType, node, doc);
33
+ errors.push(...nodeErrors);
34
+ });
35
+ }
36
+ });
37
+ return {
38
+ isValid: errors.length === 0,
39
+ errors,
40
+ };
41
+ };
@@ -1 +1 @@
1
- export const VERSION = "3.0.45";
1
+ export const VERSION = "3.0.46";
@@ -23,3 +23,4 @@ export interface TitleNode extends ManuscriptNode {
23
23
  attrs: TitleAttrs;
24
24
  }
25
25
  export declare const title: NodeSpec;
26
+ export declare const isTitleNode: (node: ManuscriptNode) => node is TitleNode;
@@ -17,3 +17,4 @@ export * from './id';
17
17
  export * from './node-names';
18
18
  export * from './node-title';
19
19
  export * from './node-types';
20
+ export * from './node-validator';
@@ -0,0 +1,13 @@
1
+ import { Node } from 'prosemirror-model';
2
+ export interface ValidationError {
3
+ code: string;
4
+ id?: string;
5
+ }
6
+ export interface ValidationResult {
7
+ isValid: boolean;
8
+ errors: ValidationError[];
9
+ }
10
+ export declare const VALIDATION_ERROR_CODES: {
11
+ readonly EMPTY_TITLE: "EMPTY_TITLE";
12
+ };
13
+ export declare const validateManuscriptNode: (doc: Node) => ValidationResult;
@@ -1 +1 @@
1
- export declare const VERSION = "3.0.45";
1
+ export declare const VERSION = "3.0.46";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@manuscripts/transform",
3
3
  "description": "ProseMirror transformer for Manuscripts applications",
4
- "version": "3.0.45",
4
+ "version": "3.0.46",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",