@tinacms/mdx 0.0.0-20220718181631

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.
@@ -0,0 +1,21 @@
1
+ /**
2
+
3
+ Copyright 2021 Forestry.io Holdings, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ */
18
+ import type { MdxJsxAttribute } from 'mdast-util-mdx-jsx';
19
+ import type { TinaFieldBase } from '@tinacms/schema-tools';
20
+ export declare const extractAttributes: (attributes: MdxJsxAttribute[], fields: TinaFieldBase[], imageCallback: (image: string) => string) => Record<string, unknown>;
21
+ export declare const extractAttribute: (attribute: MdxJsxAttribute, field: TinaFieldBase, imageCallback: (image: string) => string) => string | number | bigint | boolean | RegExp | Record<string, unknown> | (string | number | bigint | boolean | RegExp | null | undefined)[] | Record<string, unknown>[] | null | undefined;
@@ -0,0 +1,69 @@
1
+ /**
2
+
3
+ Copyright 2021 Forestry.io Holdings, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ */
18
+ import type { RichTypeInner } from '@tinacms/schema-tools';
19
+ /**
20
+ * ### Convert the MDXAST into an API-friendly format
21
+ *
22
+ * When we parse with Remark + MDX we get an AST which has a ton of JS capabilities, meaning
23
+ * we could pass this back into a JS runtime and evaluate it. Ex.
24
+ *
25
+ * ```mdx
26
+ * ## Hello world! The time and date is: {(new Date().toLocaleString())}
27
+ * ```
28
+ *
29
+ * However, as an intentional constraint we don't want this information as part of our API, as
30
+ * we don't intend to support the true JS runtime properties of MDX. Rather, we're using MDX for
31
+ * it's expressive syntax and it's advanced tooling with how it parses JSX inside Markdown.
32
+ *
33
+ * Parsing here does 2 things:
34
+ *
35
+ * #### Remove non-literal uses of JSX
36
+ * Things like <MyComponent myProp={() => alert("HI")} /> are not supported and will be ignored
37
+ *
38
+ * #### Convert remark nodes to slate-compatible nodes
39
+ *
40
+ * A remark node might look like this:
41
+ * ```js
42
+ * {
43
+ * type: "heading",
44
+ * depth: 1
45
+ * children: [{type: 'text', value: 'Hello'}]
46
+ * }
47
+ * ```
48
+ * A slate-compatible node would be:
49
+ * ```js
50
+ * {
51
+ * type: "heading_one",
52
+ * children: [{type: 'text', text: 'Hello'}]
53
+ * }
54
+ * ```
55
+ * It's not a huge difference, but in general slate does better with less layers of indirection.
56
+ *
57
+ * While it may be desirable to ultimately serve a remark AST shape as part of the API response,
58
+ * it's currently much easier to only support the shape that works with Slate. This is ok for now for 2
59
+ * reasons.
60
+ *
61
+ * 1. Us providing the `TinaMarkdown` component on the frontend abstracts away an work the developer
62
+ * would need to do, so it doesn't really matter what shape the response is as long as the external API
63
+ * doesn't change
64
+ *
65
+ * 2. We don't need to do any client-side parsing. Since TinaMarkdown and the slate editor work with the same
66
+ * format we can just allow Tina to do it's thing and update the form valuse with no additional work.
67
+ */
68
+ export declare const markdownToAst: (value: string, skipMDX: boolean, field: RichTypeInner) => import("mdast").Root | undefined;
69
+ export declare const parseMDX: (value: string, field: RichTypeInner, imageCallback: (s: string) => string, skipMDX?: boolean | undefined) => import("./plate").RootElement;
@@ -0,0 +1,22 @@
1
+ /**
2
+
3
+ Copyright 2021 Forestry.io Holdings, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ */
18
+ import type { MdxJsxTextElement, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
19
+ import type { RichTypeInner } from '@tinacms/schema-tools';
20
+ import type * as Plate from './plate';
21
+ export declare function mdxJsxElement(node: MdxJsxTextElement, field: RichTypeInner, imageCallback: (url: string) => string): Plate.MdxInlineElement;
22
+ export declare function mdxJsxElement(node: MdxJsxFlowElement, field: RichTypeInner, imageCallback: (url: string) => string): Plate.MdxBlockElement;
@@ -0,0 +1,19 @@
1
+ /**
2
+
3
+ Copyright 2021 Forestry.io Holdings, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ */
18
+ import { RootElement } from './plate';
19
+ export declare const root: RootElement;
@@ -0,0 +1,109 @@
1
+ /**
2
+
3
+ Copyright 2021 Forestry.io Holdings, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ */
18
+ export declare type RootElement = {
19
+ type: 'root';
20
+ children: BlockElement[];
21
+ };
22
+ export declare type HeadingElement = {
23
+ type: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
24
+ children: InlineElement[];
25
+ };
26
+ export declare type ParagraphElement = {
27
+ type: 'p';
28
+ children: InlineElement[];
29
+ };
30
+ export declare type MdxBlockElement = {
31
+ type: 'mdxJsxFlowElement';
32
+ name: string | null;
33
+ props: Record<string, unknown>;
34
+ children: [EmptyTextElement];
35
+ };
36
+ export declare type HrElement = {
37
+ type: 'hr';
38
+ children: [EmptyTextElement];
39
+ };
40
+ export declare type HTMLElement = {
41
+ type: 'html';
42
+ value: string;
43
+ children: [EmptyTextElement];
44
+ };
45
+ export declare type CodeBlockElement = {
46
+ type: 'code_block';
47
+ lang?: string;
48
+ value: string;
49
+ children: [EmptyTextElement];
50
+ };
51
+ export declare type BlockquoteElement = {
52
+ type: 'blockquote';
53
+ children: InlineElement[];
54
+ };
55
+ export declare type ListItemContentElement = {
56
+ type: 'lic';
57
+ children: LicElement[];
58
+ };
59
+ export declare type ListItemChildrenElement = ListItemContentElement | UnorderedListElement | OrderedListElement;
60
+ export declare type ListItemElement = {
61
+ type: 'li';
62
+ children: ListItemChildrenElement[];
63
+ };
64
+ export declare type UnorderedListElement = {
65
+ type: 'ul';
66
+ children: ListItemElement[];
67
+ };
68
+ export declare type OrderedListElement = {
69
+ type: 'ol';
70
+ children: ListItemElement[];
71
+ };
72
+ export declare type List = OrderedListElement | UnorderedListElement;
73
+ export declare type BlockElement = HeadingElement | ParagraphElement | CodeBlockElement | BlockquoteElement | MdxBlockElement | HTMLElement | UnorderedListElement | OrderedListElement | ListItemElement | HrElement;
74
+ export declare type MdxInlineElement = {
75
+ type: 'mdxJsxTextElement';
76
+ name: string | null;
77
+ props: Record<string, unknown>;
78
+ children: [EmptyTextElement];
79
+ };
80
+ export declare type EmptyTextElement = {
81
+ type: 'text';
82
+ text: '';
83
+ };
84
+ export declare type TextElement = {
85
+ type: 'text';
86
+ text: string;
87
+ bold?: boolean;
88
+ italic?: boolean;
89
+ code?: boolean;
90
+ };
91
+ export declare type ImageElement = {
92
+ type: 'img';
93
+ url: string;
94
+ alt?: string;
95
+ caption?: string | null;
96
+ children: [EmptyTextElement];
97
+ };
98
+ export declare type LinkElement = {
99
+ type: 'a';
100
+ url: string;
101
+ title?: string | null;
102
+ children: InlineElement[];
103
+ };
104
+ export declare type BreakElement = {
105
+ type: 'break';
106
+ children: [EmptyTextElement];
107
+ };
108
+ export declare type LicElement = InlineElement;
109
+ export declare type InlineElement = TextElement | MdxInlineElement | BreakElement | LinkElement | ImageElement;
@@ -0,0 +1,36 @@
1
+ /**
2
+
3
+ Copyright 2021 Forestry.io Holdings, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ */
18
+ import type * as Md from 'mdast';
19
+ import type * as Plate from './plate';
20
+ import type { RichTypeInner } from '@tinacms/schema-tools';
21
+ import type { MdxJsxTextElement, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
22
+ declare module 'mdast' {
23
+ interface StaticPhrasingContentMap {
24
+ mdxJsxTextElement: MdxJsxTextElement;
25
+ }
26
+ interface PhrasingContentMap {
27
+ mdxJsxTextElement: MdxJsxTextElement;
28
+ }
29
+ interface BlockContentMap {
30
+ mdxJsxFlowElement: MdxJsxFlowElement;
31
+ }
32
+ interface ContentMap {
33
+ mdxJsxFlowElement: MdxJsxFlowElement;
34
+ }
35
+ }
36
+ export declare const remarkToSlate: (root: Md.Root, field: RichTypeInner, imageCallback: (url: string) => string) => Plate.RootElement;
@@ -0,0 +1,12 @@
1
+ import type { RichTypeInner } from '@tinacms/schema-tools';
2
+ import type { MdxJsxAttribute } from 'mdast-util-mdx-jsx';
3
+ import type * as Plate from '../parse/plate';
4
+ import type * as Md from 'mdast';
5
+ export declare const stringifyPropsInline: (element: Plate.MdxInlineElement, field: RichTypeInner, imageCallback: (url: string) => string) => {
6
+ attributes: MdxJsxAttribute[];
7
+ children: Md.PhrasingContent[];
8
+ };
9
+ export declare const stringifyProps: (element: Plate.MdxBlockElement, parentField: RichTypeInner, flatten: boolean, imageCallback: (url: string) => string) => {
10
+ attributes: MdxJsxAttribute[];
11
+ children: Md.BlockContent[];
12
+ };
@@ -0,0 +1,25 @@
1
+ /**
2
+
3
+ Copyright 2021 Forestry.io Holdings, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ */
18
+ import type { RichTypeInner } from '@tinacms/schema-tools';
19
+ import type * as Md from 'mdast';
20
+ import type * as Plate from '../parse/plate';
21
+ export declare const stringifyMDX: (value: Plate.RootElement, field: RichTypeInner, imageCallback: (url: string) => string) => string;
22
+ export declare const rootElement: (content: Plate.RootElement, field: RichTypeInner, imageCallback: (url: string) => string) => Md.Root;
23
+ export declare const blockElement: (content: Plate.BlockElement, field: RichTypeInner, imageCallback: (url: string) => string) => Md.Content | null;
24
+ export declare type Marks = 'strong' | 'emphasis' | 'inlineCode';
25
+ export declare const getMarks: (content: Plate.InlineElement) => Marks[];
@@ -0,0 +1,25 @@
1
+ /**
2
+
3
+ Copyright 2021 Forestry.io Holdings, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ */
18
+ import type * as Md from 'mdast';
19
+ import type * as Plate from '../parse/plate';
20
+ import type { RichTypeInner } from '@tinacms/schema-tools';
21
+ declare type InlineElementWithCallback = Plate.InlineElement & {
22
+ linkifyTextNode?: (arg: Md.Text) => Md.Link;
23
+ };
24
+ export declare const eat: (c: InlineElementWithCallback[], field: RichTypeInner, imageCallback: (url: string) => string) => Md.PhrasingContent[];
25
+ export {};
@@ -0,0 +1,38 @@
1
+ /**
2
+
3
+ Copyright 2021 Forestry.io Holdings, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ */
18
+ import type { MdxJsxTextElement, MdxJsxFlowElement, MdxJsxAttribute } from 'mdast-util-mdx-jsx';
19
+ import type { RichTypeInner } from '@tinacms/schema-tools';
20
+ import type * as Plate from '../parse/plate';
21
+ import type * as Md from 'mdast';
22
+ declare module 'mdast' {
23
+ interface StaticPhrasingContentMap {
24
+ mdxJsxTextElement: MdxJsxTextElement;
25
+ }
26
+ interface PhrasingContentMap {
27
+ mdxJsxTextElement: MdxJsxTextElement;
28
+ }
29
+ interface BlockContentMap {
30
+ mdxJsxFlowElement: MdxJsxFlowElement;
31
+ }
32
+ interface ContentMap {
33
+ mdxJsxFlowElement: MdxJsxFlowElement;
34
+ }
35
+ }
36
+ export declare function mdxJsxInlineElement(node: Plate.MdxInlineElement, field: RichTypeInner): MdxJsxTextElement;
37
+ export declare function processAttributes(node: Plate.MdxInlineElement | Plate.MdxBlockElement, field: RichTypeInner): MdxJsxAttribute[];
38
+ export declare function processBlockChildren(node: Plate.MdxBlockElement, field: RichTypeInner): Md.BlockContent[];
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "@tinacms/mdx",
3
+ "version": "0.0.0-20220718181631",
4
+ "main": "dist/index.cjs",
5
+ "typings": "dist/index.d.ts",
6
+ "module": "./dist/index.es.js",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.es.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "package.json",
17
+ "dist"
18
+ ],
19
+ "license": "Apache-2.0",
20
+ "buildConfig": {
21
+ "entryPoints": [
22
+ {
23
+ "name": "src/index.ts",
24
+ "target": "node",
25
+ "bundleDeps": true
26
+ }
27
+ ]
28
+ },
29
+ "dependencies": {
30
+ "acorn": "^8.7.1",
31
+ "lodash.flatten": "^4.4.0",
32
+ "mdast-util-mdx-jsx": "^2.0.1",
33
+ "mdast-util-to-markdown": "^1.3.0",
34
+ "prettier": "^2.7.1",
35
+ "remark": "^14.0.2",
36
+ "remark-mdx": "^2.1.2",
37
+ "unist-util-visit": "^4.1.0",
38
+ "vfile": "^4.2.0"
39
+ },
40
+ "publishConfig": {
41
+ "registry": "https://registry.npmjs.org"
42
+ },
43
+ "repository": {
44
+ "url": "https://github.com/tinacms/tinacms.git",
45
+ "directory": "packages/tina-graphql"
46
+ },
47
+ "devDependencies": {
48
+ "mdast": "^3.0.0",
49
+ "vitest": "^0.18.0",
50
+ "@swc/core": "^1.2.210",
51
+ "@types/prettier": "^2.6.3",
52
+ "@swc/jest": "^0.2.21",
53
+ "@tinacms/datalayer": "0.2.1",
54
+ "@tinacms/schema-tools": "0.0.8",
55
+ "@tinacms/scripts": "0.50.9",
56
+ "@types/cors": "^2.8.7",
57
+ "@types/estree": "^0.0.50",
58
+ "@types/express": "^4.17.8",
59
+ "@types/fs-extra": "^9.0.2",
60
+ "@types/jest": "^26.0.4",
61
+ "@types/js-yaml": "^3.12.5",
62
+ "@types/lodash.flatten": "4.4.7",
63
+ "@types/mdast": "3.0.7",
64
+ "@types/node": "^14.17.34",
65
+ "@types/normalize-path": "^3.0.0",
66
+ "@types/ws": "^7.2.6",
67
+ "@types/yup": "^0.29.7",
68
+ "c8": "^7.11.3",
69
+ "jest": "^28.1.2",
70
+ "jest-diff": "^28.1.1",
71
+ "jest-file-snapshot": "^0.5.0",
72
+ "jest-matcher-utils": "^28.1.1",
73
+ "nodemon": "^2.0.4",
74
+ "ts-node": "^10.8.2",
75
+ "typescript": "^4.3.5"
76
+ },
77
+ "peerDependencies": {
78
+ "@tinacms/schema-tools": "*"
79
+ },
80
+ "scripts": {
81
+ "types": "yarn tsc",
82
+ "build": "tinacms-scripts build",
83
+ "docs": "yarn typedoc",
84
+ "serve": "yarn nodemon dist/server.js",
85
+ "test": "vitest",
86
+ "coverage": "vitest run --coverage",
87
+ "test-watch": "jest --watch"
88
+ }
89
+ }
package/readme.md ADDED
File without changes