Skip to content

Commit 95c8852

Browse files
committed
Merge branch 'widget-richtext' into moc
2 parents 21813d9 + a4a87c3 commit 95c8852

File tree

66 files changed

+5005
-6477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+5005
-6477
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ module.exports = {
7070
node: {
7171
extensions: ['.js', '.jsx', '.ts', '.tsx'],
7272
},
73+
exports: {},
7374
},
7475
'import/core-modules': [...packages, 'decap-cms-app/dist/esm'],
7576
},

dev-test/config.yml

Lines changed: 133 additions & 942 deletions
Large diffs are not rendered by default.

dev-test/index.html

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@
131131
h('p', {},
132132
h('small', {}, "Written " + entry.getIn(['data', 'date']))
133133
),
134-
h('div', {"className": "text"}, this.props.widgetFor('body'))
134+
h('h2', {}, "Richtext Widget"),
135+
h('div', {"className": "text"}, this.props.widgetFor('body')),
136+
h('h2', {}, "Markdown Widget"),
137+
h('div', {"className": "text"}, this.props.widgetFor('bodyold'))
135138
);
136139
}
137140
});
@@ -243,6 +246,39 @@
243246
);
244247
}
245248
});
249+
CMS.registerEditorComponent({
250+
id: 'container-markdown',
251+
label: 'Container Markdown',
252+
fields: [
253+
{ name: 'inner', label: 'Body', widget: 'markdown', editor_components: [] },
254+
],
255+
pattern: /^{{< container-markdown >}}(.*?){{< \/container-markdown >}}/s,
256+
fromBlock (match) {
257+
return {
258+
inner: match[1] || '',
259+
}
260+
},
261+
toBlock (obj) {
262+
return `{{< container-markdown >}}${obj.inner}{{< /container-markdown >}}`
263+
},
264+
})
265+
CMS.registerEditorComponent({
266+
id: 'container-richtext',
267+
label: 'Container Richtext',
268+
fields: [
269+
{ name: 'inner', label: 'Body', widget: 'richtext', editor_components: ['container-richtext'] },
270+
],
271+
pattern: /^{{< container-richtext >}}(.*?){{< \/container-richtext >}}/s,
272+
fromBlock (match) {
273+
return {
274+
inner: match[1] || '',
275+
}
276+
},
277+
toBlock (obj) {
278+
return `{{< container-richtext >}}${obj.inner}{{< /container-richtext >}}`
279+
},
280+
})
281+
246282
</script>
247283
</body>
248284
</html>

package-lock.json

Lines changed: 812 additions & 5506 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"cypress-plugin-tab": "^1.0.0",
9696
"dotenv": "^10.0.0",
9797
"eslint": "^8.12.0",
98+
"eslint-import-resolver-exports": "^1.0.0-beta.5",
9899
"eslint-plugin-cypress": "^2.6.0",
99100
"eslint-plugin-import": "^2.18.2",
100101
"eslint-plugin-prettier": "^4.0.0",

packages/decap-cms-app/src/extensions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import DecapCmsWidgetImage from 'decap-cms-widget-image';
1818
import DecapCmsWidgetFile from 'decap-cms-widget-file';
1919
import DecapCmsWidgetSelect from 'decap-cms-widget-select';
2020
import DecapCmsWidgetMarkdown from 'decap-cms-widget-markdown';
21+
import DecapCmsWidgetRichtext from 'decap-cms-widget-richtext';
2122
import DecapCmsWidgetList from 'decap-cms-widget-list';
2223
import DecapCmsWidgetObject from 'decap-cms-widget-object';
2324
import DecapCmsWidgetRelation from 'decap-cms-widget-relation';
@@ -49,6 +50,7 @@ CMS.registerWidget([
4950
DecapCmsWidgetFile.Widget(),
5051
DecapCmsWidgetSelect.Widget(),
5152
DecapCmsWidgetMarkdown.Widget(),
53+
DecapCmsWidgetRichtext.Widget(),
5254
DecapCmsWidgetList.Widget(),
5355
DecapCmsWidgetObject.Widget(),
5456
DecapCmsWidgetRelation.Widget(),

packages/decap-cms-backend-github/src/implementation.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,9 @@ export default class GitHub implements Implementation {
517517
});
518518

519519
console.log(
520-
`[entriesByFolder] Created cursor with actions: ${JSON.stringify(cursor.actions?.toArray())}`,
520+
`[entriesByFolder] Created cursor with actions: ${JSON.stringify(
521+
cursor.actions?.toArray(),
522+
)}`,
521523
);
522524

523525
return filtered;
@@ -540,11 +542,15 @@ export default class GitHub implements Implementation {
540542
});
541543
console.log(`[entriesByFolder] REST API returned ${files.length} files`);
542544
const filtered = files.filter(file => filterByExtension(file, extension));
543-
console.log(`[entriesByFolder] Filtered to ${filtered.length} files with extension: ${extension}`);
545+
console.log(
546+
`[entriesByFolder] Filtered to ${filtered.length} files with extension: ${extension}`,
547+
);
544548
const result = this.getCursorAndFiles(filtered, page, pageSize);
545549
cursor = result.cursor;
546550
console.log(
547-
`[entriesByFolder] Created cursor with actions: ${JSON.stringify(cursor.actions?.toArray())}, returning ${result.files.length} files for page ${page}`,
551+
`[entriesByFolder] Created cursor with actions: ${JSON.stringify(
552+
cursor.actions?.toArray(),
553+
)}, returning ${result.files.length} files for page ${page}`,
548554
);
549555
return result.files;
550556
};
@@ -613,7 +619,11 @@ export default class GitHub implements Implementation {
613619
extension: string,
614620
depth: number,
615621
pathRegex?: RegExp,
616-
onProgress?: (progress: { loadedCount: number; totalCount: number; entries: ImplementationEntry[] }) => void,
622+
onProgress?: (progress: {
623+
loadedCount: number;
624+
totalCount: number;
625+
entries: ImplementationEntry[];
626+
}) => void,
617627
) {
618628
const repoURL = this.api!.originRepoURL;
619629

@@ -720,7 +730,7 @@ export default class GitHub implements Implementation {
720730
)}%)`,
721731
);
722732
}
723-
733+
724734
// Call progress callback with current state
725735
if (onProgress) {
726736
onProgress({

packages/decap-cms-core/src/actions/entries.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,11 @@ export function loadEntriesPage(collection: Collection, page: number) {
237237
export async function getAllEntries(
238238
state: State,
239239
collection: Collection,
240-
onProgress?: (progress: { loadedCount: number; totalCount: number; entries: EntryValue[] }) => void,
240+
onProgress?: (progress: {
241+
loadedCount: number;
242+
totalCount: number;
243+
entries: EntryValue[];
244+
}) => void,
241245
) {
242246
const backend = currentBackend(state.config);
243247
const integration = selectIntegration(state, collection.get('name'), 'listEntries');
@@ -838,19 +842,21 @@ const appendActions = fromJS({
838842

839843
function addAppendActionsToCursor(cursor: Cursor) {
840844
const originalActions = cursor.actions?.toArray() || [];
841-
console.log(`[addAppendActionsToCursor] Original cursor actions: ${JSON.stringify(originalActions)}`);
842-
845+
console.log(
846+
`[addAppendActionsToCursor] Original cursor actions: ${JSON.stringify(originalActions)}`,
847+
);
848+
843849
const updatedCursor = Cursor.create(cursor).updateStore('actions', (actions: Set<string>) => {
844850
return actions.union(
845851
appendActions
846852
.filter((v: Map<string, string | boolean>) => actions.has(v.get('action') as string))
847853
.keySeq(),
848854
);
849855
});
850-
856+
851857
const newActions = updatedCursor.actions?.toArray() || [];
852858
console.log(`[addAppendActionsToCursor] Updated cursor actions: ${JSON.stringify(newActions)}`);
853-
859+
854860
return updatedCursor;
855861
}
856862

@@ -864,6 +870,8 @@ export function loadEntries(collection: Collection, page = 0) {
864870

865871
// If user has already set a sort, use it
866872
const sortFields = selectEntriesSortFields(state.entries, collectionName);
873+
874+
// If user has already set a sort, use it
867875
if (sortFields && sortFields.length > 0) {
868876
const field = sortFields[0];
869877
return dispatch(sortByField(collection, field.get('key'), field.get('direction')));
@@ -893,11 +901,11 @@ export function loadEntries(collection: Collection, page = 0) {
893901
// eslint-disable-next-line @typescript-eslint/no-explicit-any
894902
const backendConfig = state.config?.backend as any;
895903
const useGraphQL = backendConfig?.use_graphql === true;
896-
904+
897905
// For GraphQL, nested collections, or i18n collections, load all entries
898906
// GraphQL will handle batching automatically via listFilesPaginated with progressive loading
899907
const loadAllEntries = isNestedCollection || isI18nCollection || useGraphQL;
900-
908+
901909
console.log(
902910
`[loadEntries] ${collectionName}: isNested=${isNestedCollection}, isI18n=${isI18nCollection}, useGraphQL=${useGraphQL}, loadAllEntries=${loadAllEntries}`,
903911
);
@@ -956,13 +964,15 @@ export function loadEntries(collection: Collection, page = 0) {
956964
// so that i18n grouping works correctly (entries in different locales get grouped).
957965
// Use getAllEntries which calls listAllEntries that processes all entries together.
958966
console.log(`[loadEntries] Loading all entries for i18n collection: ${collectionName}`);
959-
const allEntries = await getAllEntries(state, collection, (progress) => {
967+
const allEntries = await getAllEntries(state, collection, progress => {
960968
// Dispatch progress update
961969
dispatch(entriesProgress(collection, progress.loadedCount, progress.totalCount));
962-
970+
963971
// Show entries progressively as they load (only if not the final batch)
964972
if (progress.loadedCount < progress.totalCount) {
965-
dispatch(entriesLoaded(collection, progress.entries, 0, Cursor.create({}), false, false));
973+
dispatch(
974+
entriesLoaded(collection, progress.entries, 0, Cursor.create({}), false, false),
975+
);
966976
}
967977
});
968978
console.log(
@@ -988,13 +998,15 @@ export function loadEntries(collection: Collection, page = 0) {
988998
// For GraphQL collections, load ALL entries progressively in batches
989999
// GraphQL handles batching automatically via listFilesPaginated
9901000
console.log(`[loadEntries] Loading all entries for GraphQL collection: ${collectionName}`);
991-
const allEntries = await getAllEntries(state, collection, (progress) => {
1001+
const allEntries = await getAllEntries(state, collection, progress => {
9921002
// Dispatch progress update
9931003
dispatch(entriesProgress(collection, progress.loadedCount, progress.totalCount));
994-
1004+
9951005
// Show entries progressively as they load (only if not the final batch)
9961006
if (progress.loadedCount < progress.totalCount) {
997-
dispatch(entriesLoaded(collection, progress.entries, 0, Cursor.create({}), false, false));
1007+
dispatch(
1008+
entriesLoaded(collection, progress.entries, 0, Cursor.create({}), false, false),
1009+
);
9981010
}
9991011
});
10001012
console.log(
@@ -1097,11 +1109,15 @@ export function traverseCollectionCursor(collection: Collection, action: string)
10971109
try {
10981110
dispatch(entriesLoading(collection));
10991111
console.log(
1100-
`[traverseCollectionCursor] Calling traverseCursor with action: ${action}, realAction: ${realAction}, cursor actions: ${JSON.stringify(cursor.actions?.toArray())}`,
1112+
`[traverseCollectionCursor] Calling traverseCursor with action: ${action}, realAction: ${realAction}, cursor actions: ${JSON.stringify(
1113+
cursor.actions?.toArray(),
1114+
)}`,
11011115
);
11021116
const { entries, cursor: newCursor } = await traverseCursor(backend, cursor, realAction);
11031117
console.log(
1104-
`[traverseCollectionCursor] traverseCursor succeeded, got ${entries.length} entries, new cursor actions: ${JSON.stringify(newCursor.actions?.toArray())}`,
1118+
`[traverseCollectionCursor] traverseCursor succeeded, got ${
1119+
entries.length
1120+
} entries, new cursor actions: ${JSON.stringify(newCursor.actions?.toArray())}`,
11051121
);
11061122

11071123
const pagination = newCursor.meta?.get('page');

packages/decap-cms-core/src/backend.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,11 @@ export class Backend {
665665
// for local searches and queries.
666666
async listAllEntries(
667667
collection: Collection,
668-
onProgress?: (progress: { loadedCount: number; totalCount: number; entries: EntryValue[] }) => void,
668+
onProgress?: (progress: {
669+
loadedCount: number;
670+
totalCount: number;
671+
entries: EntryValue[];
672+
}) => void,
669673
) {
670674
if (collection.get('folder') && this.implementation.allEntriesByFolder) {
671675
const depth = collectionDepth(collection);
@@ -677,7 +681,7 @@ export class Backend {
677681
collection,
678682
)}`,
679683
);
680-
684+
681685
// Wrap onProgress to process entries before calling callback
682686
const wrappedOnProgress = onProgress
683687
? (progress: { loadedCount: number; totalCount: number; entries: any[] }) => {
@@ -689,9 +693,15 @@ export class Backend {
689693
});
690694
}
691695
: undefined;
692-
696+
693697
return this.implementation
694-
.allEntriesByFolder(folder, extension, depth, collectionRegex(collection), wrappedOnProgress)
698+
.allEntriesByFolder(
699+
folder,
700+
extension,
701+
depth,
702+
collectionRegex(collection),
703+
wrappedOnProgress,
704+
)
695705
.then(entries => {
696706
console.log(
697707
`[backend.listAllEntries] allEntriesByFolder returned ${entries.length} entries`,

packages/decap-cms-core/src/components/Editor/EditorPreviewPane/EditorPreviewContent.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class PreviewContent extends React.Component {
6767

6868
PreviewContent.propTypes = {
6969
previewComponent: PropTypes.func.isRequired,
70+
getEditorComponents: PropTypes.func,
7071
previewProps: PropTypes.object,
7172
onFieldClick: PropTypes.func,
7273
};

0 commit comments

Comments
 (0)