pro-editor-schema 1.3.0 → 1.4.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.
package/README.md CHANGED
@@ -2,11 +2,15 @@
2
2
 
3
3
  TypeScript library that defines XML/HTML schema rules used by the editor and provides validation utilities for document structure, attributes, links, and footnotes.
4
4
 
5
+ ## NPM
6
+
7
+ https://www.npmjs.com/package/pro-editor-schema?activeTab=versions
8
+
5
9
  ## What this repository contains
6
10
 
7
11
  - Schema definitions for supported tags and schema codes.
8
12
  - Shared schema constants and attribute helpers.
9
- - Runtime schema lookup utilities.
13
+ - Runtime schema lookup and DOM helpers.
10
14
  - XML validation utilities (`validateXml` and related validators).
11
15
  - Type-safe element factory (`createElement`) based on schema definitions.
12
16
 
@@ -18,94 +22,121 @@ npm install
18
22
 
19
23
  ## Scripts
20
24
 
21
- | Command | Description |
22
- | -------------------- | ----------------------------------------------------------------------------------- |
23
- | `npm run dev` | Build in watch mode |
24
- | `npm run build` | Build CJS, ESM, and type declarations |
25
- | `npm run typecheck` | Run TypeScript without emitting files |
26
- | `npm run lint` | Run ESLint on `src/` |
27
- | `npm run test` | Run tests once with Vitest |
28
- | `npm run test:watch` | Run tests in watch mode |
29
- | `npm run check` | Run the full verification pipeline (`npm ci`, `typecheck`, `lint`, `test`, `build`) |
25
+ | Command | Description |
26
+ | ---------------------------- | ----------------------------------------------------------------------------------- |
27
+ | `npm run dev` | Build in watch mode |
28
+ | `npm run build` | Build CJS, ESM, and type declarations |
29
+ | `npm run typecheck` | Run TypeScript without emitting files |
30
+ | `npm run lint` | Run ESLint on `src/` |
31
+ | `npm run test` | Run tests once with Vitest |
32
+ | `npm run test:watch` | Run tests in watch mode |
33
+ | `npm run check` | Run the full verification pipeline (`npm ci`, `typecheck`, `lint`, `test`, `build`) |
34
+ | `npm run release:patch` | Create `release/v*`, bump patch, and push (`1.3.4` → `1.3.5`) |
35
+ | `npm run release:minor` | Create `release/v*`, bump minor, and push (`1.3.4` → `1.4.0`) |
36
+ | `npm run release:major` | Create `release/v*`, bump major, and push (`1.3.4` → `2.0.0`) |
37
+ | `npm run release:prerelease` | Create `prerelease/v*`, bump prerelease, and push (`1.4.0` → `1.4.0-1`) |
30
38
 
31
39
  For local development, `npm run check` is the fastest way to verify everything before pushing.
32
40
 
33
41
  ## Publishing
34
42
 
35
- The package is published to npm as `pro-editor-schema`. Use the `beta` tag for pre-release installs, and the default `latest` tag for latest.
43
+ The package is published to npm as `pro-editor-schema`.
44
+
45
+ Publishing is automated by GitHub Actions when a pull request into `master` is merged from a `release/` or `prerelease/` branch.
46
+
47
+ | Branch prefix | npm dist-tag |
48
+ | ------------- | ------------ |
49
+ | `release/` | `latest` |
50
+ | `prerelease/` | `prerelease` |
51
+
52
+ Other merged branches do not publish.
36
53
 
37
54
  ### Prerequisites
38
55
 
39
56
  1. You must have publish access to the `pro-editor-schema` package on npm.
40
- 2. Log in if needed:
57
+ 2. Start from a clean git working tree.
41
58
 
42
- ```bash
43
- npm login
44
- ```
59
+ ### Publish a release
45
60
 
46
- 3. Bump the version in `package.json` (and commit it). npm rejects republishing an existing version.
47
- 4. Verify the package:
61
+ From your current branch, run one of:
48
62
 
49
- ```bash
50
- npm run check
51
- ```
63
+ - `npm run release:patch` — bug fixes / small backwards-compatible changes, e.g. `1.3.4` → branch `release/v1.3.5`
64
+ - `npm run release:minor` — backwards-compatible functionality, e.g. `1.3.4` → branch `release/v1.4.0`
65
+ - `npm run release:major` — breaking changes, e.g. `1.3.4` → branch `release/v2.0.0`
66
+ - `npm run release:prerelease` — first prerelease of a version, e.g. `1.4.0` → branch `prerelease/v1.4.0-1` (then `1.4.0-1` → `prerelease/v1.4.0-2`)
52
67
 
53
- ### Publish to beta
68
+ Each command:
54
69
 
55
- ```bash
56
- npm publish --tag beta --access public
57
- ```
70
+ 1. Creates the `release/v*` or `prerelease/v*` branch.
71
+ 2. Bumps `package.json` and commits the version.
72
+ 3. Pushes the branch (and version tag) to origin.
58
73
 
59
- Install the beta build in a consumer app with:
74
+ Then open a pull request into `master` and merge it.
60
75
 
61
- ```bash
62
- npm install pro-editor-schema@beta
63
- ```
76
+ Merging a `release/` or `prerelease/` branch into `master` starts the publishing workflow.
77
+
78
+ The workflow:
79
+
80
+ 1. Checks out the repository.
81
+ 2. Installs dependencies with `npm ci`.
82
+ 3. Runs the full test suite.
83
+ 4. Runs TypeScript typechecking.
84
+ 5. Runs ESLint.
85
+ 6. Builds the package.
86
+ 7. Publishes to npm with the `latest` or `prerelease` dist-tag, based on the branch prefix.
64
87
 
65
- ### Publish to latest
88
+ ### Latest releases
66
89
 
67
- Production uses npm’s default `latest` tag:
90
+ Production releases are published with npm's `latest` dist-tag.
91
+ Prereleases are published with the `prerelease` dist-tag.
92
+
93
+ Install the latest production version:
68
94
 
69
95
  ```bash
70
- npm publish --access public
96
+ npm install pro-editor-schema
71
97
  ```
72
98
 
73
- Install the latest build with:
99
+ Or explicitly:
74
100
 
75
101
  ```bash
76
- npm install pro-editor-schema
77
- # or explicitly:
78
102
  npm install pro-editor-schema@latest
79
103
  ```
80
104
 
105
+ Install a prerelease:
106
+
107
+ ```bash
108
+ npm install pro-editor-schema@prerelease
109
+ ```
110
+
81
111
  ### Notes
82
112
 
83
- - Always run `npm run check` before publishing so typecheck, lint, tests, and build succeed.
84
- - Each publish needs a new `version` in `package.json`.
85
- - Staging and latest can point at different versions at the same time (for example `1.1.3` on `beta` and `1.1.2` on `latest`).
86
- - GitHub Actions also publishes to `latest` when you push a `v*` git tag (see `.github/workflows/publish.yml`).
113
+ - Each npm version can only be published once.
114
+ - Do not manually run `npm publish` when using the GitHub Actions workflow.
87
115
 
88
116
  ## CI
89
117
 
90
- GitHub Actions runs on push and pull requests to `main` / `master`:
118
+ GitHub Actions CI runs on pull requests (`.github/workflows/ci.yml`):
91
119
 
92
- - **Typecheck** — `npm run typecheck`
93
- - **Lint** — `npm run lint`
94
- - **Test** — `npm test`
120
+ - **Typecheck** — `npm run typecheck` (full project)
121
+ - **Lint** — `npm run lint` (full `src/`)
122
+ - **Test** — Vitest for files changed in the PR (`vitest run --changed` against the PR base branch)
95
123
 
96
- Workflow file: `.github/workflows/ci.yml`
124
+ The publishing workflow is defined in `.github/workflows/publish.yml`.
97
125
 
98
126
  ## Project structure
99
127
 
100
- - `src/index.ts` — public exports for schemas, types, shared constants, and validation.
128
+ - `src/index.ts` — public exports for schemas, types, helpers, and validation.
101
129
  - `src/schema/schema.types.ts` — core schema and validation-related types.
102
130
  - `src/schema/schemas.ts` — central `SCHEMAS` map (`code -> schema`).
103
131
  - `src/schema/elementSchemas/elements` — element schema definitions and `ELEMENT_SCHEMAS`.
104
132
  - `src/schema/elementSchemas/atoms` — atom schema definitions and `ATOM_SCHEMAS`.
105
133
  - `src/schema/elementSchemas/inlineElements` — inline schema definitions and `INLINE_ELEMENT_SCHEMAS`.
106
- - `src/schema/shared` — shared attribute and ignored-node constants.
107
- - `src/schema/utils` — schema lookup, element creation, and label helpers.
134
+ - `src/schema/shared` — shared allowed-children lists, global attributes, and labels.
135
+ - `src/schema/helpers` — `createSchema` and schema lookup/attribute helpers.
136
+ - `src/helpers` — DOM helpers (`createElement`, `closestElementBySchema`, ignored attributes/elements, and related utilities).
108
137
  - `src/validation` — document validation entrypoint and validation modules.
138
+ - `src/validation/helpers` — validation issue helpers and ignored-validation codes.
139
+ - `src/validation/utils` — validation-only DOM helpers.
109
140
  - `src/**/*.test.ts` — Vitest test files (run with `happy-dom`).
110
141
 
111
142
  ## Schema model
@@ -147,9 +178,11 @@ From `src/index.ts`, consumers can import:
147
178
 
148
179
  - **Types:** `Schema`, `SchemaCode`, `ElementSchemaCode`, `AtomSchemaCode`, `InlineSchemaCode`, `ValidationError`
149
180
  - **Maps:** `SCHEMAS`, `ELEMENT_SCHEMAS`, `ATOM_SCHEMAS`, `INLINE_ELEMENT_SCHEMAS`
150
- - **Utilities:** `findSchemaByCode`, `findSchemaByElement`, `createElement`, `ElementLabel`
181
+ - **Schema helpers:** `findSchemaByCode`, `findSchemaByElement`, `findAttributeDefinitionByName`, `getAttributeName`, `isAttributeRestricted`, `isTrackChangesSchema`
182
+ - **DOM helpers:** `createElement`, `closestElementBySchema`, `queryElementBySchema`, `queryAllElementsBySchema`, `getElementLinks`, `getStore`, `isDeletedElement`
183
+ - **Ignored nodes:** `isIgnoredAttribute`, `isIgnoredElement`, `IGNORED_ATTRIBUTES`, `IGNORED_ELEMENT_SELECTORS`
151
184
  - **Validation:** `validateXml`
152
- - **Shared constants:** ignored elements/attributes, global attribute constants, dependents forbidden elements
185
+ - **Shared constants:** `ElementLabel`, global attribute constants, dependents forbidden elements
153
186
 
154
187
  ## Usage examples
155
188
 
@@ -175,6 +208,20 @@ const para = createElement({
175
208
  });
176
209
  ```
177
210
 
211
+ ### Find the closest matching element
212
+
213
+ ```ts
214
+ import { closestElementBySchema } from "pro-editor-schema";
215
+
216
+ const heading = closestElementBySchema({
217
+ element,
218
+ code: "heading",
219
+ ignoreDeletedElements: true,
220
+ });
221
+ ```
222
+
223
+ `closest()` includes the starting element. To look at a parent only, pass `element.parentElement`.
224
+
178
225
  ### Validate an XML root
179
226
 
180
227
  ```ts
@@ -202,19 +249,21 @@ const errors = validateXml(rootElement, elementsToLink, linkElements, [
202
249
  It also runs per-element checks for:
203
250
 
204
251
  - Link targets (`linkend`) on linkable elements
205
- - Uncited bibliographic references
206
- - Unreferenced footnotes
252
+ - Uncited elements
207
253
  - Heading hierarchy
254
+ - ORCID `olink` values
208
255
 
209
256
  Schema-based attribute and child validation only runs for codes listed in `schemasToValidateAgainst`.
210
257
 
211
258
  ## How validation works
212
259
 
213
260
  - `validateXml` traverses the XML tree and delegates checks per element.
261
+ - `isIgnoredElement` skips editor UI helper nodes.
214
262
  - `findSchemaByElement` resolves schema from tag and optional `matchesElement`.
215
263
  - `validateAttributes` validates restricted attribute values.
216
264
  - `validateChildren` ensures child tags are allowed and required children exist.
217
- - `validateFootnotes`, `validateLinkend`, and `validateReferenceCited` provide cross-reference integrity checks.
265
+ - `validateFootnotes`, `validateLinkend`, `validateElementToLinkTo`, `validateHeadingHierarchy`, `validateOlink`, and `validateWeblink` provide additional integrity checks.
266
+ - `isIgnoredValidation` skips remaining child-tree validation for selected schema codes (for example bibliographic mixed content).
218
267
 
219
268
  Validation results use `ValidationError`:
220
269
 
@@ -245,5 +294,5 @@ Validation results use `ValidationError`:
245
294
 
246
295
  - Tag matching is done in uppercase in schema definitions and validation.
247
296
  - Some schema codes represent block/group-like structures while still being typed as `kind: "element"` in the current model.
248
- - Ignored attributes and ignored UI helper elements are excluded from strict validation by design.
249
- - Track-changes atoms (`insertion`, `deletion`) are unwrapped when validating required children.
297
+ - Ignored attributes and ignored UI helper elements live in `src/helpers` and are excluded from strict validation by design.
298
+ - Track-changes atoms (`insertion`, `deletion`, `lineGroupRemoval`) are unwrapped when validating required children.
package/dist/index.d.mts CHANGED
@@ -22,7 +22,7 @@ type Schema<TRequiredAttributes = readonly AttributeDefinition[], TOptionalAttri
22
22
  };
23
23
  type SchemaCode = ElementSchemaCode | InlineSchemaCode | AtomSchemaCode;
24
24
  type ElementSchemaCode = "referenceBibliomixed" | "referenceBibliography" | "bibliodiv" | "degrees" | "email" | "equation" | "fignote" | "figsource" | "firstname" | "footnote" | "footnoteno" | "honorific" | "img" | "informalfigure" | "keyword" | "label1" | "li" | "line" | "linegroup" | "lrh" | "math" | "mathphrase" | "merror" | "mfrac" | "mi" | "mmultiscripts" | "mn" | "mo" | "mover" | "mpadded" | "mphantom" | "mprescripts" | "mroot" | "mrow" | "ms" | "mspace" | "msqrt" | "mstyle" | "msub" | "msubsup" | "msup" | "mtable" | "mtd" | "mtext" | "mtr" | "munder" | "munderover" | "olink" | "org" | "orgname" | "para" | "punc" | "rrh" | "source1" | "speaker" | "subtitle1" | "surname" | "tag" | "tblfn" | "tblsource" | "thead" | "title1" | "token" | "tp" | "abstract1" | "affiliation" | "alttext" | "appendix" | "author" | "authorgroup" | "blockquote" | "caption1" | "chapter" | "dialogue" | "epigraph" | "figure1" | "footnoteSection" | "heading" | "imageobject" | "info1" | "keywordset" | "mediaobject" | "ol" | "personname" | "poem" | "sidebar" | "table" | "table1" | "tbody" | "td" | "tgroup" | "tr" | "ul";
25
- type AtomSchemaCode = "indexterm" | "primary" | "secondary" | "tertiary" | "quaternary" | "bookmark" | "see" | "commentQuerySection" | "comment" | "content" | "query" | "reply" | "deletion" | "lineGroupRemoval" | "emphasis" | "highlightmark" | "i" | "insertion" | "sc" | "strike" | "sub" | "sup" | "u" | "b" | "referenceMark" | "abbreviation";
25
+ type AtomSchemaCode = "mark" | "indexterm" | "primary" | "secondary" | "tertiary" | "quaternary" | "bookmark" | "see" | "commentQuerySection" | "comment" | "content" | "query" | "reply" | "deletion" | "lineGroupRemoval" | "emphasis" | "highlightmark" | "i" | "insertion" | "sc" | "strike" | "sub" | "sup" | "u" | "b" | "referenceMark" | "abbreviation";
26
26
  type InlineSchemaCode = "footnote1" | "inlineequation" | "link" | "uri" | "phrase";
27
27
 
28
28
  declare const SCHEMAS: {
@@ -338,42 +338,28 @@ declare const SCHEMAS: {
338
338
  readonly values: readonly ["add", "edit"];
339
339
  readonly defaultValue: "add";
340
340
  }], readonly []>;
341
+ mark: Schema<readonly ["id"], readonly ["data-markjs", {
342
+ readonly name: "data-replaceable";
343
+ readonly values: readonly ["true", "false"];
344
+ readonly defaultValue: "true";
345
+ }]>;
341
346
  };
342
347
  type SchemasByCode = typeof SCHEMAS;
343
348
 
344
- declare const isTrackChangesSchema: (schema: Schema) => boolean;
345
- declare const isIgnoredAttribute: (attribute: string) => boolean;
346
- declare const isIgnoredElement: (element: Element) => boolean;
347
- declare const isIgnoredValidation: (code: SchemaCode) => boolean;
349
+ declare const findAttributeDefinitionByName: (definitions: readonly AttributeDefinition[], name: string) => AttributeDefinition | undefined;
350
+
348
351
  declare const findSchemaByCode: (code: SchemaCode) => Schema;
352
+
349
353
  declare const findSchemaByElement: (element: Element) => Schema | undefined;
350
- declare const isAttributeRestricted: (attr: AttributeDefinition) => attr is RestrictedAttribute;
354
+
351
355
  declare const getAttributeName: (attribute: AttributeDefinition) => string;
352
- declare const findAttributeDefinitionByName: (definitions: readonly AttributeDefinition[], name: string) => AttributeDefinition | undefined;
353
356
 
354
- type AttributeValue<TAttribute extends AttributeDefinition> = TAttribute extends string ? string : TAttribute extends RestrictedAttribute<infer TValues> ? TValues extends readonly string[] ? TValues[number] : string : never;
355
- type AttributeName<TAttribute extends AttributeDefinition> = TAttribute extends string ? TAttribute : TAttribute extends RestrictedAttribute ? TAttribute["name"] : never;
356
- type AttributesFromDefinitions<TDefinitions extends readonly AttributeDefinition[]> = {
357
- [TAttribute in TDefinitions[number] as AttributeName<TAttribute>]: AttributeValue<TAttribute>;
358
- };
359
- type SchemaAttributes<TSchema extends Schema> = TSchema extends Schema<infer TRequired extends readonly AttributeDefinition[], infer TOptional extends readonly AttributeDefinition[]> ? AttributesFromDefinitions<TRequired> & Partial<AttributesFromDefinitions<TOptional>> : never;
360
- type CreateElementParams<TCode extends SchemaCode> = {
361
- schemaCode: TCode;
362
- attributes: SchemaAttributes<SchemasByCode[TCode]>;
363
- };
364
- declare const createElement: <TCode extends SchemaCode>({ schemaCode, attributes, }: CreateElementParams<TCode>) => HTMLElement;
357
+ declare const isAttributeRestricted: (attr: AttributeDefinition) => attr is RestrictedAttribute;
365
358
 
366
- declare const queryElementBySchema: (content: Document | Element | HTMLElement | ParentNode, schemaCode: SchemaCode) => HTMLElement | undefined;
367
- declare const queryAllElementsBySchema: (content: Document | Element | HTMLElement | ParentNode, schemaCode: SchemaCode) => HTMLElement[];
359
+ declare const isTrackChangesSchema: (schema: Schema) => boolean;
368
360
 
369
361
  declare const ElementLabel: Record<SchemaCode, string>;
370
362
 
371
- declare const IGNORED_ELEMENT_SELECTORS: string[];
372
- declare const IGNORED_VALIDATION_ELEMENT_SELECTORS: SchemaCode[];
373
-
374
- declare const IGNORED_ATTRIBUTES: string[];
375
- declare const IGNORED_ATTRIBUTES_STARTS_WITH: string[];
376
-
377
363
  type DependentForbiddenElement = {
378
364
  code: SchemaCode;
379
365
  dependentElements: SchemaCode[];
@@ -401,6 +387,8 @@ declare const TRACK_CHANGES_ATTR_DATA_DATE = "data-date";
401
387
  declare const TRACK_CHANGES_ATTRS: readonly ["data-username", "data-userid", "data-time", "data-date"];
402
388
  declare const ELE_ID_ATTRIBUTE = "ele-id";
403
389
  declare const STORE_ATTRIBUTE = "store";
390
+ declare const XMLID_ATTRIBUTE = "xmlid";
391
+ declare const LINKEND_ATTRIBUTE = "linkend";
404
392
  declare const ID_ATTRS: readonly ["store", "ele-id"];
405
393
 
406
394
  declare const ELEMENT_SCHEMAS: {
@@ -722,10 +710,15 @@ declare const ATOM_SCHEMAS: {
722
710
  readonly values: readonly ["add", "edit"];
723
711
  readonly defaultValue: "add";
724
712
  }], readonly []>;
713
+ mark: Schema<readonly ["id"], readonly ["data-markjs", {
714
+ readonly name: "data-replaceable";
715
+ readonly values: readonly ["true", "false"];
716
+ readonly defaultValue: "true";
717
+ }]>;
725
718
  };
726
719
 
727
720
  type ValidationErrorLevel = "blocker" | "warning" | "info";
728
- type ValidationErrorKind = "unlinked" | "forbidden" | "missing" | "converted" | "possible-url" | "unreachable-url";
721
+ type ValidationErrorKind = "unlinked" | "uncited" | "forbidden" | "missing" | "converted" | "possible-url" | "unreachable-url";
729
722
  type ValidationError = {
730
723
  id: string;
731
724
  store: string;
@@ -747,4 +740,49 @@ type ValidationError = {
747
740
  */
748
741
  declare const validateXml: (xml: Element, elementsToLink: string[], linkElements: string[], schemasToValidateAgainst: SchemaCode[]) => ValidationError[];
749
742
 
750
- export { ALIGNMENT_ATTRIBUTE, ATOM_SCHEMAS, type AllowedChildren, type AtomSchemaCode, type AttributeDefinition, DEPENDENT_FORBIDDEN_ELEMENTS, ELEMENT_SCHEMAS, ELE_ID_ATTRIBUTE, ElementLabel, type ElementSchemaCode, FIGURE_PLACEMENT_ATTRIBUTE, type FreeAttribute, ID_ATTRS, IGNORED_ATTRIBUTES, IGNORED_ATTRIBUTES_STARTS_WITH, IGNORED_ELEMENT_SELECTORS, IGNORED_VALIDATION_ELEMENT_SELECTORS, INDENT_TYPE_ATTRIBUTE, INLINE_ELEMENT_SCHEMAS, type InlineSchemaCode, LAYOUT_ATTRIBUTES, LAYOUT_CELL_WIDTH_ATTRIBUTE, LAYOUT_TABLE_ORIENTATION_ATTRIBUTE, LAYOUT_TABLE_PLACEMENT_ATTRIBUTE, LAYOUT_USER_ATTRIBUTE, LEFT_INDENT_ATTRIBUTE, RIGHT_INDENT_ATTRIBUTE, type RestrictedAttribute, SCHEMAS, SPACE_ABOVE_ATTRIBUTE, SPACE_BELOW_ATTRIBUTE, SPECIAL_INDENT_ATTRIBUTE, STORE_ATTRIBUTE, STYLE_NAME_ATTRIBUTE, type Schema, type SchemaAttributes, type SchemaCode, type SchemaKind, type SchemasByCode, 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, isIgnoredValidation, isTrackChangesSchema, queryAllElementsBySchema, queryElementBySchema, validateXml };
743
+ declare const getElementLinks: (contentChaptersToValidate: string[]) => {
744
+ elementsToLink: string[];
745
+ linkedElements: string[];
746
+ };
747
+
748
+ type AttributeValue<TAttribute extends AttributeDefinition> = TAttribute extends string ? string : TAttribute extends RestrictedAttribute<infer TValues> ? TValues extends readonly string[] ? TValues[number] : string : never;
749
+ type AttributeName<TAttribute extends AttributeDefinition> = TAttribute extends string ? TAttribute : TAttribute extends RestrictedAttribute ? TAttribute["name"] : never;
750
+ type AttributesFromDefinitions<TDefinitions extends readonly AttributeDefinition[]> = {
751
+ [TAttribute in TDefinitions[number] as AttributeName<TAttribute>]: AttributeValue<TAttribute>;
752
+ };
753
+ type SchemaAttributes<TSchema extends Schema> = TSchema extends Schema<infer TRequired extends readonly AttributeDefinition[], infer TOptional extends readonly AttributeDefinition[]> ? AttributesFromDefinitions<TRequired> & Partial<AttributesFromDefinitions<TOptional>> : never;
754
+ type CreateElementParams<TCode extends SchemaCode> = {
755
+ schemaCode: TCode;
756
+ attributes: SchemaAttributes<SchemasByCode[TCode]>;
757
+ };
758
+ declare const createElement: <TCode extends SchemaCode>({ schemaCode, attributes, }: CreateElementParams<TCode>) => HTMLElement;
759
+
760
+ declare const queryElementBySchema: (content: Document | Element | HTMLElement | ParentNode, schemaCode: SchemaCode) => HTMLElement | undefined;
761
+ declare const queryAllElementsBySchema: (content: Document | Element | HTMLElement | ParentNode, schemaCode: SchemaCode) => HTMLElement[];
762
+
763
+ type ClosestElementBySchemaOptions = {
764
+ element: Element | HTMLElement;
765
+ code: SchemaCode;
766
+ ignoreDeletedElements?: boolean;
767
+ };
768
+ declare const closestElementBySchema: ({ element, code, ignoreDeletedElements, }: ClosestElementBySchemaOptions) => HTMLElement | undefined;
769
+
770
+ declare const getStore: (element: Element) => string;
771
+
772
+ declare const isDeletedElement: (element: Element) => boolean;
773
+
774
+ declare const IGNORED_ATTRIBUTES: string[];
775
+ declare const IGNORED_ATTRIBUTES_STARTS_WITH: string[];
776
+ declare const isIgnoredAttribute: (attribute: string) => boolean;
777
+
778
+ declare const IGNORED_ELEMENT_SELECTORS: string[];
779
+ declare const isIgnoredElement: (element: Element) => boolean;
780
+
781
+ type GetAdjacentElementOptions = {
782
+ element: HTMLElement | Element;
783
+ direction: "next" | "previous";
784
+ code: SchemaCode;
785
+ };
786
+ declare const getAdjacentElement: ({ element, direction, code, }: GetAdjacentElementOptions) => HTMLElement | undefined;
787
+
788
+ export { ALIGNMENT_ATTRIBUTE, ATOM_SCHEMAS, type AllowedChildren, type AtomSchemaCode, type AttributeDefinition, DEPENDENT_FORBIDDEN_ELEMENTS, ELEMENT_SCHEMAS, ELE_ID_ATTRIBUTE, ElementLabel, type ElementSchemaCode, FIGURE_PLACEMENT_ATTRIBUTE, 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_ATTRIBUTE, LAYOUT_TABLE_ORIENTATION_ATTRIBUTE, LAYOUT_TABLE_PLACEMENT_ATTRIBUTE, LAYOUT_USER_ATTRIBUTE, LEFT_INDENT_ATTRIBUTE, LINKEND_ATTRIBUTE, RIGHT_INDENT_ATTRIBUTE, type RestrictedAttribute, SCHEMAS, SPACE_ABOVE_ATTRIBUTE, SPACE_BELOW_ATTRIBUTE, SPECIAL_INDENT_ATTRIBUTE, STORE_ATTRIBUTE, STYLE_NAME_ATTRIBUTE, type Schema, type SchemaAttributes, type SchemaCode, type SchemaKind, type SchemasByCode, 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, XMLID_ATTRIBUTE, closestElementBySchema, createElement, findAttributeDefinitionByName, findSchemaByCode, findSchemaByElement, getAdjacentElement, getAttributeName, getElementLinks, getStore, isAttributeRestricted, isDeletedElement, isIgnoredAttribute, isIgnoredElement, isTrackChangesSchema, queryAllElementsBySchema, queryElementBySchema, validateXml };
package/dist/index.d.ts CHANGED
@@ -22,7 +22,7 @@ type Schema<TRequiredAttributes = readonly AttributeDefinition[], TOptionalAttri
22
22
  };
23
23
  type SchemaCode = ElementSchemaCode | InlineSchemaCode | AtomSchemaCode;
24
24
  type ElementSchemaCode = "referenceBibliomixed" | "referenceBibliography" | "bibliodiv" | "degrees" | "email" | "equation" | "fignote" | "figsource" | "firstname" | "footnote" | "footnoteno" | "honorific" | "img" | "informalfigure" | "keyword" | "label1" | "li" | "line" | "linegroup" | "lrh" | "math" | "mathphrase" | "merror" | "mfrac" | "mi" | "mmultiscripts" | "mn" | "mo" | "mover" | "mpadded" | "mphantom" | "mprescripts" | "mroot" | "mrow" | "ms" | "mspace" | "msqrt" | "mstyle" | "msub" | "msubsup" | "msup" | "mtable" | "mtd" | "mtext" | "mtr" | "munder" | "munderover" | "olink" | "org" | "orgname" | "para" | "punc" | "rrh" | "source1" | "speaker" | "subtitle1" | "surname" | "tag" | "tblfn" | "tblsource" | "thead" | "title1" | "token" | "tp" | "abstract1" | "affiliation" | "alttext" | "appendix" | "author" | "authorgroup" | "blockquote" | "caption1" | "chapter" | "dialogue" | "epigraph" | "figure1" | "footnoteSection" | "heading" | "imageobject" | "info1" | "keywordset" | "mediaobject" | "ol" | "personname" | "poem" | "sidebar" | "table" | "table1" | "tbody" | "td" | "tgroup" | "tr" | "ul";
25
- type AtomSchemaCode = "indexterm" | "primary" | "secondary" | "tertiary" | "quaternary" | "bookmark" | "see" | "commentQuerySection" | "comment" | "content" | "query" | "reply" | "deletion" | "lineGroupRemoval" | "emphasis" | "highlightmark" | "i" | "insertion" | "sc" | "strike" | "sub" | "sup" | "u" | "b" | "referenceMark" | "abbreviation";
25
+ type AtomSchemaCode = "mark" | "indexterm" | "primary" | "secondary" | "tertiary" | "quaternary" | "bookmark" | "see" | "commentQuerySection" | "comment" | "content" | "query" | "reply" | "deletion" | "lineGroupRemoval" | "emphasis" | "highlightmark" | "i" | "insertion" | "sc" | "strike" | "sub" | "sup" | "u" | "b" | "referenceMark" | "abbreviation";
26
26
  type InlineSchemaCode = "footnote1" | "inlineequation" | "link" | "uri" | "phrase";
27
27
 
28
28
  declare const SCHEMAS: {
@@ -338,42 +338,28 @@ declare const SCHEMAS: {
338
338
  readonly values: readonly ["add", "edit"];
339
339
  readonly defaultValue: "add";
340
340
  }], readonly []>;
341
+ mark: Schema<readonly ["id"], readonly ["data-markjs", {
342
+ readonly name: "data-replaceable";
343
+ readonly values: readonly ["true", "false"];
344
+ readonly defaultValue: "true";
345
+ }]>;
341
346
  };
342
347
  type SchemasByCode = typeof SCHEMAS;
343
348
 
344
- declare const isTrackChangesSchema: (schema: Schema) => boolean;
345
- declare const isIgnoredAttribute: (attribute: string) => boolean;
346
- declare const isIgnoredElement: (element: Element) => boolean;
347
- declare const isIgnoredValidation: (code: SchemaCode) => boolean;
349
+ declare const findAttributeDefinitionByName: (definitions: readonly AttributeDefinition[], name: string) => AttributeDefinition | undefined;
350
+
348
351
  declare const findSchemaByCode: (code: SchemaCode) => Schema;
352
+
349
353
  declare const findSchemaByElement: (element: Element) => Schema | undefined;
350
- declare const isAttributeRestricted: (attr: AttributeDefinition) => attr is RestrictedAttribute;
354
+
351
355
  declare const getAttributeName: (attribute: AttributeDefinition) => string;
352
- declare const findAttributeDefinitionByName: (definitions: readonly AttributeDefinition[], name: string) => AttributeDefinition | undefined;
353
356
 
354
- type AttributeValue<TAttribute extends AttributeDefinition> = TAttribute extends string ? string : TAttribute extends RestrictedAttribute<infer TValues> ? TValues extends readonly string[] ? TValues[number] : string : never;
355
- type AttributeName<TAttribute extends AttributeDefinition> = TAttribute extends string ? TAttribute : TAttribute extends RestrictedAttribute ? TAttribute["name"] : never;
356
- type AttributesFromDefinitions<TDefinitions extends readonly AttributeDefinition[]> = {
357
- [TAttribute in TDefinitions[number] as AttributeName<TAttribute>]: AttributeValue<TAttribute>;
358
- };
359
- type SchemaAttributes<TSchema extends Schema> = TSchema extends Schema<infer TRequired extends readonly AttributeDefinition[], infer TOptional extends readonly AttributeDefinition[]> ? AttributesFromDefinitions<TRequired> & Partial<AttributesFromDefinitions<TOptional>> : never;
360
- type CreateElementParams<TCode extends SchemaCode> = {
361
- schemaCode: TCode;
362
- attributes: SchemaAttributes<SchemasByCode[TCode]>;
363
- };
364
- declare const createElement: <TCode extends SchemaCode>({ schemaCode, attributes, }: CreateElementParams<TCode>) => HTMLElement;
357
+ declare const isAttributeRestricted: (attr: AttributeDefinition) => attr is RestrictedAttribute;
365
358
 
366
- declare const queryElementBySchema: (content: Document | Element | HTMLElement | ParentNode, schemaCode: SchemaCode) => HTMLElement | undefined;
367
- declare const queryAllElementsBySchema: (content: Document | Element | HTMLElement | ParentNode, schemaCode: SchemaCode) => HTMLElement[];
359
+ declare const isTrackChangesSchema: (schema: Schema) => boolean;
368
360
 
369
361
  declare const ElementLabel: Record<SchemaCode, string>;
370
362
 
371
- declare const IGNORED_ELEMENT_SELECTORS: string[];
372
- declare const IGNORED_VALIDATION_ELEMENT_SELECTORS: SchemaCode[];
373
-
374
- declare const IGNORED_ATTRIBUTES: string[];
375
- declare const IGNORED_ATTRIBUTES_STARTS_WITH: string[];
376
-
377
363
  type DependentForbiddenElement = {
378
364
  code: SchemaCode;
379
365
  dependentElements: SchemaCode[];
@@ -401,6 +387,8 @@ declare const TRACK_CHANGES_ATTR_DATA_DATE = "data-date";
401
387
  declare const TRACK_CHANGES_ATTRS: readonly ["data-username", "data-userid", "data-time", "data-date"];
402
388
  declare const ELE_ID_ATTRIBUTE = "ele-id";
403
389
  declare const STORE_ATTRIBUTE = "store";
390
+ declare const XMLID_ATTRIBUTE = "xmlid";
391
+ declare const LINKEND_ATTRIBUTE = "linkend";
404
392
  declare const ID_ATTRS: readonly ["store", "ele-id"];
405
393
 
406
394
  declare const ELEMENT_SCHEMAS: {
@@ -722,10 +710,15 @@ declare const ATOM_SCHEMAS: {
722
710
  readonly values: readonly ["add", "edit"];
723
711
  readonly defaultValue: "add";
724
712
  }], readonly []>;
713
+ mark: Schema<readonly ["id"], readonly ["data-markjs", {
714
+ readonly name: "data-replaceable";
715
+ readonly values: readonly ["true", "false"];
716
+ readonly defaultValue: "true";
717
+ }]>;
725
718
  };
726
719
 
727
720
  type ValidationErrorLevel = "blocker" | "warning" | "info";
728
- type ValidationErrorKind = "unlinked" | "forbidden" | "missing" | "converted" | "possible-url" | "unreachable-url";
721
+ type ValidationErrorKind = "unlinked" | "uncited" | "forbidden" | "missing" | "converted" | "possible-url" | "unreachable-url";
729
722
  type ValidationError = {
730
723
  id: string;
731
724
  store: string;
@@ -747,4 +740,49 @@ type ValidationError = {
747
740
  */
748
741
  declare const validateXml: (xml: Element, elementsToLink: string[], linkElements: string[], schemasToValidateAgainst: SchemaCode[]) => ValidationError[];
749
742
 
750
- export { ALIGNMENT_ATTRIBUTE, ATOM_SCHEMAS, type AllowedChildren, type AtomSchemaCode, type AttributeDefinition, DEPENDENT_FORBIDDEN_ELEMENTS, ELEMENT_SCHEMAS, ELE_ID_ATTRIBUTE, ElementLabel, type ElementSchemaCode, FIGURE_PLACEMENT_ATTRIBUTE, type FreeAttribute, ID_ATTRS, IGNORED_ATTRIBUTES, IGNORED_ATTRIBUTES_STARTS_WITH, IGNORED_ELEMENT_SELECTORS, IGNORED_VALIDATION_ELEMENT_SELECTORS, INDENT_TYPE_ATTRIBUTE, INLINE_ELEMENT_SCHEMAS, type InlineSchemaCode, LAYOUT_ATTRIBUTES, LAYOUT_CELL_WIDTH_ATTRIBUTE, LAYOUT_TABLE_ORIENTATION_ATTRIBUTE, LAYOUT_TABLE_PLACEMENT_ATTRIBUTE, LAYOUT_USER_ATTRIBUTE, LEFT_INDENT_ATTRIBUTE, RIGHT_INDENT_ATTRIBUTE, type RestrictedAttribute, SCHEMAS, SPACE_ABOVE_ATTRIBUTE, SPACE_BELOW_ATTRIBUTE, SPECIAL_INDENT_ATTRIBUTE, STORE_ATTRIBUTE, STYLE_NAME_ATTRIBUTE, type Schema, type SchemaAttributes, type SchemaCode, type SchemaKind, type SchemasByCode, 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, isIgnoredValidation, isTrackChangesSchema, queryAllElementsBySchema, queryElementBySchema, validateXml };
743
+ declare const getElementLinks: (contentChaptersToValidate: string[]) => {
744
+ elementsToLink: string[];
745
+ linkedElements: string[];
746
+ };
747
+
748
+ type AttributeValue<TAttribute extends AttributeDefinition> = TAttribute extends string ? string : TAttribute extends RestrictedAttribute<infer TValues> ? TValues extends readonly string[] ? TValues[number] : string : never;
749
+ type AttributeName<TAttribute extends AttributeDefinition> = TAttribute extends string ? TAttribute : TAttribute extends RestrictedAttribute ? TAttribute["name"] : never;
750
+ type AttributesFromDefinitions<TDefinitions extends readonly AttributeDefinition[]> = {
751
+ [TAttribute in TDefinitions[number] as AttributeName<TAttribute>]: AttributeValue<TAttribute>;
752
+ };
753
+ type SchemaAttributes<TSchema extends Schema> = TSchema extends Schema<infer TRequired extends readonly AttributeDefinition[], infer TOptional extends readonly AttributeDefinition[]> ? AttributesFromDefinitions<TRequired> & Partial<AttributesFromDefinitions<TOptional>> : never;
754
+ type CreateElementParams<TCode extends SchemaCode> = {
755
+ schemaCode: TCode;
756
+ attributes: SchemaAttributes<SchemasByCode[TCode]>;
757
+ };
758
+ declare const createElement: <TCode extends SchemaCode>({ schemaCode, attributes, }: CreateElementParams<TCode>) => HTMLElement;
759
+
760
+ declare const queryElementBySchema: (content: Document | Element | HTMLElement | ParentNode, schemaCode: SchemaCode) => HTMLElement | undefined;
761
+ declare const queryAllElementsBySchema: (content: Document | Element | HTMLElement | ParentNode, schemaCode: SchemaCode) => HTMLElement[];
762
+
763
+ type ClosestElementBySchemaOptions = {
764
+ element: Element | HTMLElement;
765
+ code: SchemaCode;
766
+ ignoreDeletedElements?: boolean;
767
+ };
768
+ declare const closestElementBySchema: ({ element, code, ignoreDeletedElements, }: ClosestElementBySchemaOptions) => HTMLElement | undefined;
769
+
770
+ declare const getStore: (element: Element) => string;
771
+
772
+ declare const isDeletedElement: (element: Element) => boolean;
773
+
774
+ declare const IGNORED_ATTRIBUTES: string[];
775
+ declare const IGNORED_ATTRIBUTES_STARTS_WITH: string[];
776
+ declare const isIgnoredAttribute: (attribute: string) => boolean;
777
+
778
+ declare const IGNORED_ELEMENT_SELECTORS: string[];
779
+ declare const isIgnoredElement: (element: Element) => boolean;
780
+
781
+ type GetAdjacentElementOptions = {
782
+ element: HTMLElement | Element;
783
+ direction: "next" | "previous";
784
+ code: SchemaCode;
785
+ };
786
+ declare const getAdjacentElement: ({ element, direction, code, }: GetAdjacentElementOptions) => HTMLElement | undefined;
787
+
788
+ export { ALIGNMENT_ATTRIBUTE, ATOM_SCHEMAS, type AllowedChildren, type AtomSchemaCode, type AttributeDefinition, DEPENDENT_FORBIDDEN_ELEMENTS, ELEMENT_SCHEMAS, ELE_ID_ATTRIBUTE, ElementLabel, type ElementSchemaCode, FIGURE_PLACEMENT_ATTRIBUTE, 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_ATTRIBUTE, LAYOUT_TABLE_ORIENTATION_ATTRIBUTE, LAYOUT_TABLE_PLACEMENT_ATTRIBUTE, LAYOUT_USER_ATTRIBUTE, LEFT_INDENT_ATTRIBUTE, LINKEND_ATTRIBUTE, RIGHT_INDENT_ATTRIBUTE, type RestrictedAttribute, SCHEMAS, SPACE_ABOVE_ATTRIBUTE, SPACE_BELOW_ATTRIBUTE, SPECIAL_INDENT_ATTRIBUTE, STORE_ATTRIBUTE, STYLE_NAME_ATTRIBUTE, type Schema, type SchemaAttributes, type SchemaCode, type SchemaKind, type SchemasByCode, 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, XMLID_ATTRIBUTE, closestElementBySchema, createElement, findAttributeDefinitionByName, findSchemaByCode, findSchemaByElement, getAdjacentElement, getAttributeName, getElementLinks, getStore, isAttributeRestricted, isDeletedElement, isIgnoredAttribute, isIgnoredElement, isTrackChangesSchema, queryAllElementsBySchema, queryElementBySchema, validateXml };