@art-md/constructs 0.0.1 → 0.0.3
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/package.json +2 -2
- package/src/factories/constructs/Document/factory/createDocument.test.ts +17 -0
- package/src/factories/constructs/Document/factory/createDocument.ts +11 -0
- package/src/factories/constructs/Document/factory/types.ts +5 -0
- package/src/factories/constructs/Document/index.ts +3 -0
- package/src/factories/constructs/FieldBlock/factory/createFieldBlock.test.ts +26 -0
- package/src/factories/constructs/FieldBlock/factory/createFieldBlock.ts +15 -0
- package/src/factories/constructs/FieldBlock/factory/types.ts +8 -0
- package/src/factories/constructs/FieldBlock/index.ts +4 -0
- package/src/factories/constructs/FieldBlock/types.ts +11 -0
- package/src/factories/constructs/FieldInline/factory/createFieldInline.test.ts +26 -0
- package/src/factories/constructs/FieldInline/factory/createFieldInline.ts +15 -0
- package/src/factories/constructs/FieldInline/factory/types.ts +8 -0
- package/src/factories/constructs/FieldInline/index.ts +4 -0
- package/src/factories/constructs/FieldInline/types.ts +11 -0
- package/src/factories/constructs/NaturalBlock/factory/createNaturalBlock.test.ts +36 -0
- package/src/factories/constructs/NaturalBlock/factory/createNaturalBlock.ts +25 -0
- package/src/factories/constructs/NaturalBlock/factory/types.ts +13 -0
- package/src/factories/constructs/NaturalBlock/index.ts +4 -0
- package/src/factories/constructs/NaturalBlock/types.ts +14 -0
- package/src/factories/constructs/NaturalExpression/factory/createNaturalExpression.test.ts +22 -0
- package/src/factories/constructs/NaturalExpression/factory/createNaturalExpression.ts +13 -0
- package/src/factories/constructs/NaturalExpression/factory/types.ts +8 -0
- package/src/factories/constructs/NaturalExpression/index.ts +4 -0
- package/src/factories/constructs/NaturalExpression/types.ts +9 -0
- package/src/factories/constructs/SectionBlock/factory/createSectionBlock.test.ts +30 -0
- package/src/factories/constructs/SectionBlock/factory/createSectionBlock.ts +15 -0
- package/src/factories/constructs/SectionBlock/factory/types.ts +11 -0
- package/src/factories/constructs/SectionBlock/index.ts +4 -0
- package/src/factories/constructs/SectionBlock/types.ts +12 -0
- package/src/factories/constructs/Tag/factory/createTag.test.ts +10 -0
- package/src/factories/constructs/Tag/factory/createTag.ts +7 -0
- package/src/factories/constructs/Tag/factory/types.ts +3 -0
- package/src/factories/constructs/Tag/index.ts +4 -0
- package/src/factories/constructs/Tag/types.ts +6 -0
- package/src/factories/index.ts +9 -0
- package/src/factories/public.ts +47 -0
- package/src/factories/types.ts +36 -0
- package/src/index.ts +3 -0
- package/src/parser/constructs/FieldBlock/createFieldBlockParser.test.ts +13 -0
- package/src/parser/constructs/FieldBlock/createFieldBlockParser.ts +9 -0
- package/src/parser/constructs/FieldBlock/index.ts +1 -0
- package/src/parser/constructs/FieldBlock/private/helpers/createFieldBlockFromNode.test.ts +63 -0
- package/src/parser/constructs/FieldBlock/private/helpers/createFieldBlockFromNode.ts +33 -0
- package/src/parser/constructs/FieldBlock/private/helpers/onBeforeConstruct.test.ts +30 -0
- package/src/parser/constructs/FieldBlock/private/helpers/onBeforeConstruct.ts +19 -0
- package/src/parser/constructs/FieldBlock/private/index.ts +2 -0
- package/src/parser/constructs/FieldBlock/private/integrator/createFieldBlockIntegrator.test.ts +23 -0
- package/src/parser/constructs/FieldBlock/private/integrator/createFieldBlockIntegrator.ts +13 -0
- package/src/parser/constructs/FieldBlock/private/processor/createFieldBlockProcessor.test.ts +63 -0
- package/src/parser/constructs/FieldBlock/private/processor/createFieldBlockProcessor.ts +21 -0
- package/src/parser/constructs/FieldInline/createFieldInlineParser.test.ts +12 -0
- package/src/parser/constructs/FieldInline/createFieldInlineParser.ts +8 -0
- package/src/parser/constructs/FieldInline/index.ts +1 -0
- package/src/parser/constructs/FieldInline/private/helpers/createFieldInlineFromNode.test.ts +100 -0
- package/src/parser/constructs/FieldInline/private/helpers/createFieldInlineFromNode.ts +51 -0
- package/src/parser/constructs/FieldInline/private/helpers/trimFieldEdges.test.ts +48 -0
- package/src/parser/constructs/FieldInline/private/helpers/trimFieldEdges.ts +18 -0
- package/src/parser/constructs/FieldInline/private/index.ts +1 -0
- package/src/parser/constructs/FieldInline/private/processor/createFieldInlineProcessor.test.ts +57 -0
- package/src/parser/constructs/FieldInline/private/processor/createFieldInlineProcessor.ts +21 -0
- package/src/parser/constructs/NaturalBlock/createNaturalBlockParser.test.ts +12 -0
- package/src/parser/constructs/NaturalBlock/createNaturalBlockParser.ts +8 -0
- package/src/parser/constructs/NaturalBlock/index.ts +1 -0
- package/src/parser/constructs/NaturalBlock/private/helpers/createNaturalBlockFromNode.test.ts +101 -0
- package/src/parser/constructs/NaturalBlock/private/helpers/createNaturalBlockFromNode.ts +51 -0
- package/src/parser/constructs/NaturalBlock/private/index.ts +1 -0
- package/src/parser/constructs/NaturalBlock/private/processor/createNaturalBlockProcessor.test.ts +24 -0
- package/src/parser/constructs/NaturalBlock/private/processor/createNaturalBlockProcessor.ts +10 -0
- package/src/parser/constructs/SectionBlock/createSectionBlockParser.test.ts +13 -0
- package/src/parser/constructs/SectionBlock/createSectionBlockParser.ts +9 -0
- package/src/parser/constructs/SectionBlock/index.ts +1 -0
- package/src/parser/constructs/SectionBlock/private/constants.test.ts +17 -0
- package/src/parser/constructs/SectionBlock/private/constants.ts +1 -0
- package/src/parser/constructs/SectionBlock/private/helpers/createSectionBlockFromNode.test.ts +58 -0
- package/src/parser/constructs/SectionBlock/private/helpers/createSectionBlockFromNode.ts +28 -0
- package/src/parser/constructs/SectionBlock/private/helpers/findParentSection.test.ts +44 -0
- package/src/parser/constructs/SectionBlock/private/helpers/findParentSection.ts +14 -0
- package/src/parser/constructs/SectionBlock/private/index.ts +2 -0
- package/src/parser/constructs/SectionBlock/private/integrator/createSectionBlockIntegrator.test.ts +60 -0
- package/src/parser/constructs/SectionBlock/private/integrator/createSectionBlockIntegrator.ts +31 -0
- package/src/parser/constructs/SectionBlock/private/processor/createSectionBlockProcessor.test.ts +34 -0
- package/src/parser/constructs/SectionBlock/private/processor/createSectionBlockProcessor.ts +15 -0
- package/src/parser/document/createArtDocumentFromNode.test.ts +23 -0
- package/src/parser/document/createArtDocumentFromNode.ts +10 -0
- package/src/parser/document/index.ts +1 -0
- package/src/parser/fields/constants.test.ts +23 -0
- package/src/parser/fields/constants.ts +1 -0
- package/src/parser/fields/index.ts +3 -0
- package/src/parser/fields/isFieldStrong.test.ts +27 -0
- package/src/parser/fields/isFieldStrong.ts +9 -0
- package/src/parser/fields/stripStrong.test.ts +38 -0
- package/src/parser/fields/stripStrong.ts +12 -0
- package/src/parser/index.ts +8 -0
- package/src/parser/mdast/index.ts +1 -0
- package/src/parser/mdast/rawSlice.test.ts +43 -0
- package/src/parser/mdast/rawSlice.ts +8 -0
- package/src/parser/naturalExpression/createNaturalExpressionFromNode.test.ts +40 -0
- package/src/parser/naturalExpression/createNaturalExpressionFromNode.ts +25 -0
- package/src/parser/naturalExpression/index.ts +1 -0
- package/src/parser/public.ts +16 -0
- package/src/parser/tags/extractTags.test.ts +85 -0
- package/src/parser/tags/extractTags.ts +23 -0
- package/src/parser/tags/index.ts +1 -0
- package/src/parser/types.ts +21 -0
- package/src/serializer/constructs/Document/createDocumentToMdast.test.ts +22 -0
- package/src/serializer/constructs/Document/createDocumentToMdast.ts +15 -0
- package/src/serializer/constructs/Document/index.ts +1 -0
- package/src/serializer/constructs/FieldBlock/createFieldBlockToMdast.test.ts +36 -0
- package/src/serializer/constructs/FieldBlock/createFieldBlockToMdast.ts +26 -0
- package/src/serializer/constructs/FieldBlock/index.ts +1 -0
- package/src/serializer/constructs/FieldInline/createFieldInlineToMdast.test.ts +38 -0
- package/src/serializer/constructs/FieldInline/createFieldInlineToMdast.ts +27 -0
- package/src/serializer/constructs/FieldInline/index.ts +1 -0
- package/src/serializer/constructs/NaturalBlock/createNaturalBlockToMdast.test.ts +122 -0
- package/src/serializer/constructs/NaturalBlock/createNaturalBlockToMdast.ts +30 -0
- package/src/serializer/constructs/NaturalBlock/index.ts +1 -0
- package/src/serializer/constructs/NaturalExpression/createNaturalExpressionToMdast.test.ts +29 -0
- package/src/serializer/constructs/NaturalExpression/createNaturalExpressionToMdast.ts +15 -0
- package/src/serializer/constructs/NaturalExpression/index.ts +1 -0
- package/src/serializer/constructs/SectionBlock/createSectionBlockToMdast.test.ts +83 -0
- package/src/serializer/constructs/SectionBlock/createSectionBlockToMdast.ts +29 -0
- package/src/serializer/constructs/SectionBlock/index.ts +1 -0
- package/src/serializer/index.ts +8 -0
- package/src/serializer/public.ts +18 -0
- package/src/serializer/tags/index.ts +2 -0
- package/src/serializer/tags/tagToMdast.test.ts +10 -0
- package/src/serializer/tags/tagToMdast.ts +7 -0
- package/src/serializer/tags/tagsToMdast.test.ts +19 -0
- package/src/serializer/tags/tagsToMdast.ts +10 -0
- package/src/serializer/types.ts +10 -0
- package/src/test/helpers/constructs/FieldBlock/createFieldBlockFromNodeMock.ts +17 -0
- package/src/test/helpers/constructs/FieldBlock/createFieldBlockMock.ts +17 -0
- package/src/test/helpers/constructs/FieldBlock/makeFieldBlockFixture.ts +16 -0
- package/src/test/helpers/constructs/FieldBlock/makeFieldBlockMock.ts +16 -0
- package/src/test/helpers/constructs/FieldInline/createFieldInlineFromNodeMock.ts +17 -0
- package/src/test/helpers/constructs/FieldInline/createFieldInlineMock.ts +17 -0
- package/src/test/helpers/constructs/FieldInline/makeFieldInlineFixture.ts +16 -0
- package/src/test/helpers/constructs/FieldInline/makeFieldInlineMock.ts +16 -0
- package/src/test/helpers/constructs/NaturalBlock/createNaturalBlockFromNodeMock.ts +17 -0
- package/src/test/helpers/constructs/NaturalBlock/createNaturalBlockMock.ts +17 -0
- package/src/test/helpers/constructs/NaturalBlock/makeNaturalBlockFixture.ts +22 -0
- package/src/test/helpers/constructs/NaturalBlock/makeNaturalBlockMock.ts +22 -0
- package/src/test/helpers/constructs/NaturalExpression/makeNaturalExpressionFixture.ts +18 -0
- package/src/test/helpers/constructs/NaturalExpression/makeNaturalExpressionMock.ts +18 -0
- package/src/test/helpers/constructs/SectionBlock/createSectionBlockFromNodeMock.ts +17 -0
- package/src/test/helpers/constructs/SectionBlock/createSectionBlockMock.ts +17 -0
- package/src/test/helpers/constructs/SectionBlock/makeSectionBlockFixture.ts +20 -0
- package/src/test/helpers/constructs/Tag/makeTagFixture.ts +10 -0
- package/src/test/helpers/constructs/index.ts +14 -0
- package/src/test/helpers/index.ts +2 -0
- package/src/test/helpers/parsers/fields/stripStrongMock.ts +11 -0
- package/src/test/helpers/parsers/index.ts +5 -0
- package/src/test/helpers/parsers/mdast/rawSliceMock.ts +9 -0
- package/src/test/helpers/parsers/natural-expression/createNaturalExpressionFromNodeMock.ts +16 -0
- package/src/test/helpers/parsers/tags/extractTagsMock.ts +12 -0
- package/src/test/helpers/parsers/tags/tagToMdastMock.ts +9 -0
- package/dist/esm/index.js +0 -3135
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@art-md/constructs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Construct factories for Art parser records.",
|
|
5
5
|
"author": "Noodlestan Collective",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"sideEffects": false,
|
|
18
18
|
"main": "./src/index.ts",
|
|
19
19
|
"files": [
|
|
20
|
-
"
|
|
20
|
+
"src",
|
|
21
21
|
"LICENSE-MIT",
|
|
22
22
|
"README.md"
|
|
23
23
|
],
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import type { SectionBlock } from '../../SectionBlock';
|
|
4
|
+
|
|
5
|
+
import { createDocument } from './createDocument';
|
|
6
|
+
|
|
7
|
+
describe('createDocument', () => {
|
|
8
|
+
it('WHEN creating an ArtDocument from data', () => {
|
|
9
|
+
const sectionBlock: SectionBlock = { construct: 'SectionBlock', name: 'Hello', children: [] };
|
|
10
|
+
const data = { children: [sectionBlock] };
|
|
11
|
+
|
|
12
|
+
const result = createDocument(data);
|
|
13
|
+
|
|
14
|
+
expect(result.construct).toBe('Document');
|
|
15
|
+
expect(result.children).toBe(data.children);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ArtDocument, createArtDocument } from '@art-md/primitives';
|
|
2
|
+
|
|
3
|
+
import type { DocumentFactoryData } from './types';
|
|
4
|
+
|
|
5
|
+
export function createDocument(data: DocumentFactoryData): ArtDocument {
|
|
6
|
+
const docData = {
|
|
7
|
+
...data,
|
|
8
|
+
children: data.children || [],
|
|
9
|
+
};
|
|
10
|
+
return createArtDocument(docData);
|
|
11
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
makeFieldBlockFixture,
|
|
5
|
+
makeNaturalBlockFixture,
|
|
6
|
+
makeTagFixture,
|
|
7
|
+
} from '../../../../test/helpers';
|
|
8
|
+
|
|
9
|
+
import { createFieldBlock } from './createFieldBlock';
|
|
10
|
+
|
|
11
|
+
describe('createFieldBlock', () => {
|
|
12
|
+
it('WHEN creating a FieldBlock from minimal data', () => {
|
|
13
|
+
const result = createFieldBlock({ name: 'Test' });
|
|
14
|
+
expect(result).toEqual(makeFieldBlockFixture());
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('WHEN provided includes children and tags', () => {
|
|
18
|
+
const result = createFieldBlock({
|
|
19
|
+
name: 'Test',
|
|
20
|
+
children: [makeNaturalBlockFixture()],
|
|
21
|
+
tags: [makeTagFixture()],
|
|
22
|
+
});
|
|
23
|
+
expect(result.children).toHaveLength(1);
|
|
24
|
+
expect(result.tags).toHaveLength(1);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { FieldBlock } from '../types';
|
|
2
|
+
|
|
3
|
+
import type { FieldBlockFactoryData } from './types';
|
|
4
|
+
|
|
5
|
+
export function createFieldBlock(data: FieldBlockFactoryData): FieldBlock {
|
|
6
|
+
const field: FieldBlock = {
|
|
7
|
+
construct: 'FieldBlock',
|
|
8
|
+
name: data.name,
|
|
9
|
+
children: data.children ?? [],
|
|
10
|
+
};
|
|
11
|
+
if (data.tags?.length) {
|
|
12
|
+
field.tags = data.tags;
|
|
13
|
+
}
|
|
14
|
+
return field;
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ContainerConstructBase } from '@art-md/primitives';
|
|
2
|
+
|
|
3
|
+
import type { BlockContent } from '../../types';
|
|
4
|
+
import type { Tag } from '../Tag';
|
|
5
|
+
|
|
6
|
+
export type FieldBlock = ContainerConstructBase & {
|
|
7
|
+
construct: 'FieldBlock';
|
|
8
|
+
name: string;
|
|
9
|
+
children: BlockContent[];
|
|
10
|
+
tags?: Tag[];
|
|
11
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
makeFieldInlineFixture,
|
|
5
|
+
makeNaturalExpressionFixture,
|
|
6
|
+
makeTagFixture,
|
|
7
|
+
} from '../../../../test/helpers';
|
|
8
|
+
|
|
9
|
+
import { createFieldInline } from './createFieldInline';
|
|
10
|
+
|
|
11
|
+
describe('createFieldInline', () => {
|
|
12
|
+
it('WHEN creating a FieldInline from minimal data', () => {
|
|
13
|
+
const result = createFieldInline({ name: 'Test' });
|
|
14
|
+
expect(result).toEqual(makeFieldInlineFixture());
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('WHEN provided includes children and tags', () => {
|
|
18
|
+
const result = createFieldInline({
|
|
19
|
+
name: 'Test',
|
|
20
|
+
children: [makeNaturalExpressionFixture()],
|
|
21
|
+
tags: [makeTagFixture()],
|
|
22
|
+
});
|
|
23
|
+
expect(result.children).toHaveLength(1);
|
|
24
|
+
expect(result.tags).toHaveLength(1);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { FieldInline } from '../types';
|
|
2
|
+
|
|
3
|
+
import type { FieldInlineFactoryData } from './types';
|
|
4
|
+
|
|
5
|
+
export function createFieldInline(data: FieldInlineFactoryData): FieldInline {
|
|
6
|
+
const field: FieldInline = {
|
|
7
|
+
construct: 'FieldInline',
|
|
8
|
+
name: data.name,
|
|
9
|
+
children: data.children ?? [],
|
|
10
|
+
};
|
|
11
|
+
if (data.tags?.length) {
|
|
12
|
+
field.tags = data.tags;
|
|
13
|
+
}
|
|
14
|
+
return field;
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ContainerConstructBase } from '@art-md/primitives';
|
|
2
|
+
|
|
3
|
+
import type { NaturalExpression } from '../NaturalExpression';
|
|
4
|
+
import type { Tag } from '../Tag';
|
|
5
|
+
|
|
6
|
+
export type FieldInline = ContainerConstructBase & {
|
|
7
|
+
construct: 'FieldInline';
|
|
8
|
+
name: string;
|
|
9
|
+
children: NaturalExpression[];
|
|
10
|
+
tags?: Tag[];
|
|
11
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { makeNaturalBlockFixture, makeTagFixture } from '../../../../test/helpers';
|
|
4
|
+
|
|
5
|
+
import { createNaturalBlock } from './createNaturalBlock';
|
|
6
|
+
|
|
7
|
+
describe('createNaturalBlock', () => {
|
|
8
|
+
it('WHEN creating a NaturalBlock from minimal data', () => {
|
|
9
|
+
const result = createNaturalBlock({ value: 'hello', children: [] });
|
|
10
|
+
expect(result).toEqual(makeNaturalBlockFixture());
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('WHEN provided includes optional properties', () => {
|
|
14
|
+
const result = createNaturalBlock({
|
|
15
|
+
value: 'hello',
|
|
16
|
+
children: [],
|
|
17
|
+
type: 'paragraph',
|
|
18
|
+
lang: 'ts',
|
|
19
|
+
meta: 'test',
|
|
20
|
+
tags: [makeTagFixture()],
|
|
21
|
+
});
|
|
22
|
+
expect(result.type).toBe('paragraph');
|
|
23
|
+
expect(result.lang).toBe('ts');
|
|
24
|
+
expect(result.meta).toBe('test');
|
|
25
|
+
expect(result.tags).toHaveLength(1);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('WHEN provided includes attributes spreads them without overriding value and children', () => {
|
|
29
|
+
const result = createNaturalBlock({
|
|
30
|
+
value: 'hello',
|
|
31
|
+
children: [],
|
|
32
|
+
attributes: { ordered: true, value: 'nope', children: ['x'] },
|
|
33
|
+
});
|
|
34
|
+
expect(result).toMatchObject({ ordered: true, value: 'hello', children: [] });
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { NaturalBlock } from '../types';
|
|
2
|
+
|
|
3
|
+
import type { NaturalBlockFactoryData } from './types';
|
|
4
|
+
|
|
5
|
+
export function createNaturalBlock(data: NaturalBlockFactoryData): NaturalBlock {
|
|
6
|
+
const block: NaturalBlock = {
|
|
7
|
+
...data.attributes,
|
|
8
|
+
construct: 'NaturalBlock',
|
|
9
|
+
value: data.value,
|
|
10
|
+
children: data.children,
|
|
11
|
+
};
|
|
12
|
+
if (data.type) {
|
|
13
|
+
block.type = data.type;
|
|
14
|
+
}
|
|
15
|
+
if (data.lang !== undefined) {
|
|
16
|
+
block.lang = data.lang;
|
|
17
|
+
}
|
|
18
|
+
if (data.meta !== undefined) {
|
|
19
|
+
block.meta = data.meta;
|
|
20
|
+
}
|
|
21
|
+
if (data.tags?.length) {
|
|
22
|
+
block.tags = data.tags;
|
|
23
|
+
}
|
|
24
|
+
return block;
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ContainerConstructBase } from '@art-md/primitives';
|
|
2
|
+
|
|
3
|
+
import type { Tag } from '../../Tag';
|
|
4
|
+
|
|
5
|
+
export type NaturalBlockFactoryData = {
|
|
6
|
+
value: string;
|
|
7
|
+
children: ContainerConstructBase[];
|
|
8
|
+
type?: string;
|
|
9
|
+
lang?: string | null;
|
|
10
|
+
meta?: string | null;
|
|
11
|
+
tags?: Tag[];
|
|
12
|
+
attributes?: Record<string, unknown>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ContainerConstructBase } from '@art-md/primitives';
|
|
2
|
+
|
|
3
|
+
import type { Tag } from '../Tag';
|
|
4
|
+
|
|
5
|
+
export type NaturalBlock = ContainerConstructBase & {
|
|
6
|
+
construct: 'NaturalBlock';
|
|
7
|
+
value: string;
|
|
8
|
+
children: ContainerConstructBase[];
|
|
9
|
+
type?: string;
|
|
10
|
+
lang?: string | null;
|
|
11
|
+
meta?: string | null;
|
|
12
|
+
tags?: Tag[];
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { makeNaturalExpressionFixture } from '../../../../test/helpers';
|
|
4
|
+
|
|
5
|
+
import { createNaturalExpression } from './createNaturalExpression';
|
|
6
|
+
|
|
7
|
+
describe('createNaturalExpression', () => {
|
|
8
|
+
it('WHEN creating a NaturalExpression from data', () => {
|
|
9
|
+
const result = createNaturalExpression({ type: 'text', value: 'hello' });
|
|
10
|
+
expect(result).toEqual(makeNaturalExpressionFixture());
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('WHEN provided includes children and attributes', () => {
|
|
14
|
+
const result = createNaturalExpression({
|
|
15
|
+
type: 'strong',
|
|
16
|
+
attributes: { bold: true },
|
|
17
|
+
children: [makeNaturalExpressionFixture({ value: 'hi' })],
|
|
18
|
+
});
|
|
19
|
+
expect(result.attributes).toEqual({ bold: true });
|
|
20
|
+
expect(result.children).toHaveLength(1);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NaturalExpression } from '../types';
|
|
2
|
+
|
|
3
|
+
import type { NaturalExpressionFactoryData } from './types';
|
|
4
|
+
|
|
5
|
+
export function createNaturalExpression(data: NaturalExpressionFactoryData): NaturalExpression {
|
|
6
|
+
return {
|
|
7
|
+
construct: 'NaturalExpression',
|
|
8
|
+
type: data.type,
|
|
9
|
+
value: data.value,
|
|
10
|
+
attributes: data.attributes,
|
|
11
|
+
children: data.children ?? [],
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ContainerConstructBase } from '@art-md/primitives';
|
|
2
|
+
|
|
3
|
+
export type NaturalExpression = ContainerConstructBase & {
|
|
4
|
+
construct: 'NaturalExpression';
|
|
5
|
+
type: string;
|
|
6
|
+
attributes?: Record<string, unknown>;
|
|
7
|
+
value?: string;
|
|
8
|
+
children: NaturalExpression[];
|
|
9
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
makeNaturalBlockFixture,
|
|
5
|
+
makeSectionBlockFixture,
|
|
6
|
+
makeTagFixture,
|
|
7
|
+
} from '../../../../test/helpers';
|
|
8
|
+
|
|
9
|
+
import { createSectionBlock } from './createSectionBlock';
|
|
10
|
+
|
|
11
|
+
describe('createSectionBlock', () => {
|
|
12
|
+
it('WHEN creating a SectionBlock from minimal data', () => {
|
|
13
|
+
const result = createSectionBlock({ name: 'Test' });
|
|
14
|
+
expect(result).toEqual(makeSectionBlockFixture());
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('WHEN provided includes optional properties', () => {
|
|
18
|
+
const result = createSectionBlock({
|
|
19
|
+
name: 'Test',
|
|
20
|
+
kind: 'Module',
|
|
21
|
+
depth: 2,
|
|
22
|
+
children: [makeNaturalBlockFixture()],
|
|
23
|
+
tags: [makeTagFixture()],
|
|
24
|
+
});
|
|
25
|
+
expect(result.kind).toBe('Module');
|
|
26
|
+
expect(result.depth).toBe(2);
|
|
27
|
+
expect(result.children).toHaveLength(1);
|
|
28
|
+
expect(result.tags).toHaveLength(1);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SectionBlock } from '../types';
|
|
2
|
+
|
|
3
|
+
import type { SectionBlockFactoryData } from './types';
|
|
4
|
+
|
|
5
|
+
export function createSectionBlock(data: SectionBlockFactoryData): SectionBlock {
|
|
6
|
+
const section: SectionBlock = {
|
|
7
|
+
construct: 'SectionBlock',
|
|
8
|
+
name: data.name,
|
|
9
|
+
children: data.children ?? [],
|
|
10
|
+
};
|
|
11
|
+
if (data.kind) section.kind = data.kind;
|
|
12
|
+
if (data.depth !== undefined) section.depth = data.depth;
|
|
13
|
+
if (data.tags?.length) section.tags = data.tags;
|
|
14
|
+
return section;
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ConstructBase, ContainerConstructBase } from '@art-md/primitives';
|
|
2
|
+
|
|
3
|
+
import type { Tag } from '../Tag';
|
|
4
|
+
|
|
5
|
+
export type SectionBlock = ContainerConstructBase & {
|
|
6
|
+
construct: 'SectionBlock';
|
|
7
|
+
kind?: string;
|
|
8
|
+
name: string;
|
|
9
|
+
tags?: Tag[];
|
|
10
|
+
children: ConstructBase[];
|
|
11
|
+
depth?: number;
|
|
12
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { createTag } from './createTag';
|
|
4
|
+
|
|
5
|
+
describe('createTag', () => {
|
|
6
|
+
it('WHEN creating a Tag from data', () => {
|
|
7
|
+
const result = createTag({ name: 'friend' });
|
|
8
|
+
expect(result).toEqual({ construct: 'Tag', name: 'friend' });
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './constructs/Document';
|
|
2
|
+
export * from './constructs/FieldBlock';
|
|
3
|
+
export * from './constructs/FieldInline';
|
|
4
|
+
export * from './constructs/NaturalBlock';
|
|
5
|
+
export * from './constructs/NaturalExpression';
|
|
6
|
+
export * from './constructs/SectionBlock';
|
|
7
|
+
export * from './constructs/Tag';
|
|
8
|
+
|
|
9
|
+
export type * from './types';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createDocument } from './constructs/Document';
|
|
2
|
+
import { createFieldBlock } from './constructs/FieldBlock';
|
|
3
|
+
import { createFieldInline } from './constructs/FieldInline';
|
|
4
|
+
import { createNaturalBlock } from './constructs/NaturalBlock';
|
|
5
|
+
import { createNaturalExpression } from './constructs/NaturalExpression';
|
|
6
|
+
import { createSectionBlock } from './constructs/SectionBlock';
|
|
7
|
+
import { createTag } from './constructs/Tag';
|
|
8
|
+
|
|
9
|
+
export type { FieldBlock } from './constructs/FieldBlock';
|
|
10
|
+
export type { FieldInline } from './constructs/FieldInline';
|
|
11
|
+
export type { NaturalBlock } from './constructs/NaturalBlock';
|
|
12
|
+
export type { NaturalExpression } from './constructs/NaturalExpression';
|
|
13
|
+
export type { SectionBlock } from './constructs/SectionBlock';
|
|
14
|
+
export type { Tag } from './constructs/Tag';
|
|
15
|
+
|
|
16
|
+
export type * from './types';
|
|
17
|
+
|
|
18
|
+
export const FACTORIES = [
|
|
19
|
+
{
|
|
20
|
+
name: 'Document',
|
|
21
|
+
factory: createDocument,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'FieldBlock',
|
|
25
|
+
factory: createFieldBlock,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'FieldInline',
|
|
29
|
+
factory: createFieldInline,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'NaturalBlock',
|
|
33
|
+
factory: createNaturalBlock,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'NaturalExpression',
|
|
37
|
+
factory: createNaturalExpression,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'SectionBlock',
|
|
41
|
+
factory: createSectionBlock,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'Tag',
|
|
45
|
+
factory: createTag,
|
|
46
|
+
},
|
|
47
|
+
];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { FieldBlock } from './constructs/FieldBlock';
|
|
2
|
+
import type { FieldInline } from './constructs/FieldInline';
|
|
3
|
+
import type { NaturalBlock } from './constructs/NaturalBlock';
|
|
4
|
+
import type { NaturalExpression } from './constructs/NaturalExpression';
|
|
5
|
+
import type { SectionBlock } from './constructs/SectionBlock';
|
|
6
|
+
import type { Tag } from './constructs/Tag';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Open registry of block-level constructs. Augment via declaration merging when new constructs land.
|
|
10
|
+
*
|
|
11
|
+
* @conventions-ignore Conventions: Typescript / Types / No Interface
|
|
12
|
+
*/
|
|
13
|
+
export interface BlockConstructMap {
|
|
14
|
+
SectionBlock: SectionBlock;
|
|
15
|
+
FieldBlock: FieldBlock;
|
|
16
|
+
FieldInline: FieldInline;
|
|
17
|
+
NaturalBlock: NaturalBlock;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Open registry of inline/expression-level constructs. Augment via declaration merging when new constructs land.
|
|
22
|
+
*
|
|
23
|
+
* @conventions-ignore Conventions: Typescript / Types / No Interface
|
|
24
|
+
*/
|
|
25
|
+
export interface InlineConstructMap {
|
|
26
|
+
NaturalExpression: NaturalExpression;
|
|
27
|
+
Tag: Tag;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Open registry of all constructs. */
|
|
31
|
+
export type ConstructMap = BlockConstructMap & InlineConstructMap;
|
|
32
|
+
|
|
33
|
+
export type BlockContent = BlockConstructMap[keyof BlockConstructMap];
|
|
34
|
+
export type InlineContent = InlineConstructMap[keyof InlineConstructMap];
|
|
35
|
+
|
|
36
|
+
export type Construct = ConstructMap[keyof ConstructMap];
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { createFieldBlockParser } from './createFieldBlockParser';
|
|
4
|
+
|
|
5
|
+
describe('createFieldBlockParser', () => {
|
|
6
|
+
it('WHEN called returns a parser with FieldBlock name, processor, integrator and factory', () => {
|
|
7
|
+
const parser = createFieldBlockParser();
|
|
8
|
+
|
|
9
|
+
expect(parser.name).toBe('FieldBlock');
|
|
10
|
+
expect(parser.processor).toBeDefined();
|
|
11
|
+
expect(parser.integrator).toBeDefined();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ConstructParserFactory } from '../../types';
|
|
2
|
+
|
|
3
|
+
import { createFieldBlockIntegrator, createFieldBlockProcessor } from './private';
|
|
4
|
+
|
|
5
|
+
export const createFieldBlockParser: ConstructParserFactory = () => ({
|
|
6
|
+
name: 'FieldBlock',
|
|
7
|
+
processor: createFieldBlockProcessor(),
|
|
8
|
+
integrator: createFieldBlockIntegrator(),
|
|
9
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createFieldBlockParser } from './createFieldBlockParser';
|