@crashbytes/contentful-richtext-editor 1.0.7 → 1.0.9
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 +433 -204
- package/dist/components/ContentfulEditor.d.ts +8 -5
- package/dist/components/ContentfulEditor.stories.d.ts +18 -0
- package/dist/components/ContentfulEmbedded.d.ts +12 -0
- package/dist/components/Toolbar.d.ts +2 -0
- package/dist/components/Toolbar.stories.d.ts +10 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +5 -44
- package/dist/index.esm.css +1 -1
- package/dist/index.esm.js +1031 -1608
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1034 -1616
- package/dist/index.js.map +1 -1
- package/dist/testData/samples.d.ts +11 -0
- package/dist/utils/configParser.d.ts +37 -0
- package/dist/utils/contentfulTransform.d.ts +23 -11
- package/dist/utils/contentfulTransform.stories.d.ts +6 -0
- package/dist/utils/types.d.ts +113 -0
- package/package.json +17 -11
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Document } from '@contentful/rich-text-types';
|
|
2
|
+
export declare const blogPostSample: Document;
|
|
3
|
+
export declare const marketingCopySample: Document;
|
|
4
|
+
export declare const technicalDocSample: Document;
|
|
5
|
+
export declare const recipeSample: Document;
|
|
6
|
+
export declare const testDataSamples: {
|
|
7
|
+
blogPost: Document;
|
|
8
|
+
marketingCopy: Document;
|
|
9
|
+
technicalDoc: Document;
|
|
10
|
+
recipe: Document;
|
|
11
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface ContentfulFieldValidation {
|
|
2
|
+
enabledMarks?: string[];
|
|
3
|
+
enabledNodeTypes?: string[];
|
|
4
|
+
}
|
|
5
|
+
export interface ContentfulFieldConfiguration {
|
|
6
|
+
validations?: ContentfulFieldValidation[];
|
|
7
|
+
settings?: {
|
|
8
|
+
helpText?: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface ParsedEditorConfig {
|
|
12
|
+
availableHeadings: Array<1 | 2 | 3 | 4 | 5 | 6>;
|
|
13
|
+
availableMarks: Array<'bold' | 'italic' | 'underline'>;
|
|
14
|
+
disabledFeatures: string[];
|
|
15
|
+
allowHyperlinks: boolean;
|
|
16
|
+
allowEmbeddedEntries: boolean;
|
|
17
|
+
allowEmbeddedAssets: boolean;
|
|
18
|
+
allowInlineEntries: boolean;
|
|
19
|
+
allowTables: boolean;
|
|
20
|
+
allowQuotes: boolean;
|
|
21
|
+
allowLists: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Parses Contentful field configuration to determine editor capabilities
|
|
25
|
+
*/
|
|
26
|
+
export declare const parseContentfulFieldConfig: (fieldConfiguration?: ContentfulFieldConfiguration) => ParsedEditorConfig;
|
|
27
|
+
/**
|
|
28
|
+
* Helper function to fetch Contentful field configuration from Management API
|
|
29
|
+
*/
|
|
30
|
+
export declare const fetchContentfulFieldConfig: (spaceId: string, contentTypeId: string, fieldId: string, accessToken: string) => Promise<ContentfulFieldConfiguration | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a mock field configuration for testing purposes
|
|
33
|
+
*/
|
|
34
|
+
export declare const createMockFieldConfig: (options: {
|
|
35
|
+
enabledMarks?: string[];
|
|
36
|
+
enabledNodeTypes?: string[];
|
|
37
|
+
}) => ContentfulFieldConfiguration;
|
|
@@ -10,27 +10,39 @@ interface TiptapNode {
|
|
|
10
10
|
}>;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Converts a Contentful Rich Text Document to Tiptap JSON format
|
|
14
14
|
*/
|
|
15
|
-
export declare const
|
|
15
|
+
export declare const contentfulToTiptap: (document: Document) => TiptapNode;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Converts Tiptap JSON format to Contentful Rich Text Document
|
|
18
|
+
*/
|
|
19
|
+
export declare const tiptapToContentful: (tiptapDoc: any) => Document;
|
|
20
|
+
/**
|
|
21
|
+
* Validates if a Contentful document is properly formatted
|
|
18
22
|
*/
|
|
19
23
|
export declare const validateContentfulDocument: (document: any) => document is Document;
|
|
20
24
|
/**
|
|
21
|
-
*
|
|
25
|
+
* Creates an empty Contentful document
|
|
22
26
|
*/
|
|
23
|
-
export declare const
|
|
27
|
+
export declare const createEmptyDocument: () => Document;
|
|
24
28
|
/**
|
|
25
|
-
*
|
|
29
|
+
* Sanitizes a Contentful document by removing invalid nodes/marks based on configuration
|
|
26
30
|
*/
|
|
27
|
-
export declare const
|
|
31
|
+
export declare const sanitizeContentfulDocument: (document: Document, allowedNodeTypes: string[], allowedMarks: string[]) => Document;
|
|
28
32
|
/**
|
|
29
|
-
*
|
|
33
|
+
* Extracts plain text from a Contentful document
|
|
30
34
|
*/
|
|
31
|
-
export declare const
|
|
35
|
+
export declare const extractPlainText: (document: Document) => string;
|
|
32
36
|
/**
|
|
33
|
-
*
|
|
37
|
+
* Counts words in a Contentful document
|
|
34
38
|
*/
|
|
35
|
-
export declare const
|
|
39
|
+
export declare const countWords: (document: Document) => number;
|
|
40
|
+
/**
|
|
41
|
+
* Finds all embedded entries/assets in a document
|
|
42
|
+
*/
|
|
43
|
+
export declare const findEmbeddedContent: (document: Document) => {
|
|
44
|
+
entries: string[];
|
|
45
|
+
assets: string[];
|
|
46
|
+
inlineEntries: string[];
|
|
47
|
+
};
|
|
36
48
|
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
declare const TransformationDemo: () => import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
declare const meta: Meta<typeof TransformationDemo>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof meta>;
|
|
6
|
+
export declare const InteractiveDemo: Story;
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -26,3 +26,116 @@ export interface EmbeddedAsset {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
+
export type { ContentfulFieldValidation, ContentfulFieldConfiguration, ParsedEditorConfig, } from './configParser';
|
|
30
|
+
export interface EditorFeatureConfig {
|
|
31
|
+
bold?: boolean;
|
|
32
|
+
italic?: boolean;
|
|
33
|
+
underline?: boolean;
|
|
34
|
+
code?: boolean;
|
|
35
|
+
link?: boolean;
|
|
36
|
+
headings?: Array<1 | 2 | 3 | 4 | 5 | 6>;
|
|
37
|
+
lists?: boolean;
|
|
38
|
+
quote?: boolean;
|
|
39
|
+
table?: boolean;
|
|
40
|
+
embeddedEntries?: boolean;
|
|
41
|
+
embeddedAssets?: boolean;
|
|
42
|
+
inlineEntries?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface ContentfulNode {
|
|
45
|
+
nodeType: string;
|
|
46
|
+
data: Record<string, any>;
|
|
47
|
+
content?: Array<ContentfulNode | ContentfulText>;
|
|
48
|
+
}
|
|
49
|
+
export interface ContentfulText {
|
|
50
|
+
nodeType: 'text';
|
|
51
|
+
value: string;
|
|
52
|
+
marks?: Array<{
|
|
53
|
+
type: string;
|
|
54
|
+
}>;
|
|
55
|
+
data: Record<string, any>;
|
|
56
|
+
}
|
|
57
|
+
export interface ContentfulDocument extends ContentfulNode {
|
|
58
|
+
nodeType: 'document';
|
|
59
|
+
content: ContentfulNode[];
|
|
60
|
+
}
|
|
61
|
+
export interface TiptapNode {
|
|
62
|
+
type: string;
|
|
63
|
+
attrs?: Record<string, any>;
|
|
64
|
+
content?: TiptapNode[];
|
|
65
|
+
text?: string;
|
|
66
|
+
marks?: Array<{
|
|
67
|
+
type: string;
|
|
68
|
+
attrs?: Record<string, any>;
|
|
69
|
+
}>;
|
|
70
|
+
}
|
|
71
|
+
export interface TiptapDocument extends TiptapNode {
|
|
72
|
+
type: 'doc';
|
|
73
|
+
content: TiptapNode[];
|
|
74
|
+
}
|
|
75
|
+
export interface EditorState {
|
|
76
|
+
canUndo: boolean;
|
|
77
|
+
canRedo: boolean;
|
|
78
|
+
activeMarks: string[];
|
|
79
|
+
activeNodes: string[];
|
|
80
|
+
currentHeading?: number;
|
|
81
|
+
}
|
|
82
|
+
export type OnChangeCallback = (document: any) => void;
|
|
83
|
+
export type OnEmbedCallback = () => Promise<EmbeddedEntry | EmbeddedAsset | null> | void;
|
|
84
|
+
export interface ThemeConfig {
|
|
85
|
+
name: ContentfulEditorTheme;
|
|
86
|
+
className: string;
|
|
87
|
+
toolbarStyle?: 'minimal' | 'full' | 'compact';
|
|
88
|
+
showBorders?: boolean;
|
|
89
|
+
customStyles?: Record<string, string>;
|
|
90
|
+
}
|
|
91
|
+
export interface ValidationRule {
|
|
92
|
+
type: 'required' | 'minLength' | 'maxLength' | 'pattern' | 'custom';
|
|
93
|
+
value?: any;
|
|
94
|
+
message?: string;
|
|
95
|
+
validator?: (value: any) => boolean | string;
|
|
96
|
+
}
|
|
97
|
+
export interface FieldValidationConfig {
|
|
98
|
+
rules?: ValidationRule[];
|
|
99
|
+
showErrors?: boolean;
|
|
100
|
+
validateOnBlur?: boolean;
|
|
101
|
+
validateOnChange?: boolean;
|
|
102
|
+
}
|
|
103
|
+
export interface LocalizationConfig {
|
|
104
|
+
locale: string;
|
|
105
|
+
messages: Record<string, string>;
|
|
106
|
+
rtl?: boolean;
|
|
107
|
+
}
|
|
108
|
+
export interface A11yConfig {
|
|
109
|
+
ariaLabel?: string;
|
|
110
|
+
ariaDescribedBy?: string;
|
|
111
|
+
announceChanges?: boolean;
|
|
112
|
+
keyboardShortcuts?: Record<string, string>;
|
|
113
|
+
}
|
|
114
|
+
export interface AdvancedEditorConfig {
|
|
115
|
+
autofocus?: boolean;
|
|
116
|
+
spellcheck?: boolean;
|
|
117
|
+
autocomplete?: boolean;
|
|
118
|
+
wordWrap?: boolean;
|
|
119
|
+
lineNumbers?: boolean;
|
|
120
|
+
minimap?: boolean;
|
|
121
|
+
dragDrop?: boolean;
|
|
122
|
+
paste?: {
|
|
123
|
+
plainTextOnly?: boolean;
|
|
124
|
+
cleanupPaste?: boolean;
|
|
125
|
+
preserveWhitespace?: boolean;
|
|
126
|
+
};
|
|
127
|
+
history?: {
|
|
128
|
+
depth?: number;
|
|
129
|
+
newGroupDelay?: number;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export interface PluginConfig {
|
|
133
|
+
name: string;
|
|
134
|
+
enabled: boolean;
|
|
135
|
+
options?: Record<string, any>;
|
|
136
|
+
}
|
|
137
|
+
export type DeepPartial<T> = {
|
|
138
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
139
|
+
};
|
|
140
|
+
export type RequiredFields<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
141
|
+
export type OptionalFields<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crashbytes/contentful-richtext-editor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "A Tiptap-based rich text editor compatible with Contentful's rich text format",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"build:watch": "rollup -c -w",
|
|
29
29
|
"dev": "rollup -c -w",
|
|
30
30
|
"clean": "rm -rf dist",
|
|
31
|
-
"prepublishOnly": "npm run clean && npm run build"
|
|
31
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
32
|
+
"storybook": "storybook dev -p 6006",
|
|
33
|
+
"build-storybook": "storybook build"
|
|
32
34
|
},
|
|
33
35
|
"peerDependencies": {
|
|
34
36
|
"react": ">=16.8.0",
|
|
@@ -48,15 +50,19 @@
|
|
|
48
50
|
"@tiptap/starter-kit": "^2.0.0"
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
|
-
"@rollup/plugin-
|
|
52
|
-
"@rollup/plugin-
|
|
53
|
-
"@rollup/plugin-
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"
|
|
53
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
54
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
55
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
56
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
57
|
+
"@storybook/addon-essentials": "^7.6.20",
|
|
58
|
+
"@storybook/addon-interactions": "^7.6.20",
|
|
59
|
+
"@storybook/addon-links": "^7.6.20",
|
|
60
|
+
"@storybook/blocks": "^7.6.20",
|
|
61
|
+
"@storybook/react": "^7.6.20",
|
|
62
|
+
"@storybook/react-vite": "^7.6.20",
|
|
63
|
+
"@storybook/testing-library": "^0.2.2",
|
|
57
64
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
58
65
|
"rollup-plugin-postcss": "^4.0.2",
|
|
59
|
-
"
|
|
60
|
-
"typescript": "^5.0.0"
|
|
66
|
+
"storybook": "^7.6.20"
|
|
61
67
|
}
|
|
62
|
-
}
|
|
68
|
+
}
|