@pranaysahith/decap-cms-core 3.9.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 +9 -0
- package/dist/@pranaysahith/decap-cms-core.js +52 -0
- package/dist/@pranaysahith/decap-cms-core.js.LICENSE.txt +141 -0
- package/dist/@pranaysahith/decap-cms-core.js.map +1 -0
- package/dist/decap-cms-core.js +47 -0
- package/dist/decap-cms-core.js.LICENSE.txt +116 -0
- package/dist/decap-cms-core.js.map +1 -0
- package/dist/esm/actions/auth.js +97 -0
- package/dist/esm/actions/collections.js +15 -0
- package/dist/esm/actions/config.js +493 -0
- package/dist/esm/actions/deploys.js +79 -0
- package/dist/esm/actions/editorialWorkflow.js +480 -0
- package/dist/esm/actions/entries.js +865 -0
- package/dist/esm/actions/media.js +147 -0
- package/dist/esm/actions/mediaLibrary.js +552 -0
- package/dist/esm/actions/notifications.js +21 -0
- package/dist/esm/actions/search.js +149 -0
- package/dist/esm/actions/status.js +74 -0
- package/dist/esm/actions/waitUntil.js +32 -0
- package/dist/esm/backend.js +1082 -0
- package/dist/esm/bootstrap.js +101 -0
- package/dist/esm/components/App/App.js +289 -0
- package/dist/esm/components/App/Header.js +172 -0
- package/dist/esm/components/App/NotFoundPage.js +19 -0
- package/dist/esm/components/Collection/Collection.js +198 -0
- package/dist/esm/components/Collection/CollectionControls.js +46 -0
- package/dist/esm/components/Collection/CollectionSearch.js +222 -0
- package/dist/esm/components/Collection/CollectionTop.js +68 -0
- package/dist/esm/components/Collection/ControlButton.js +17 -0
- package/dist/esm/components/Collection/Entries/Entries.js +73 -0
- package/dist/esm/components/Collection/Entries/EntriesCollection.js +241 -0
- package/dist/esm/components/Collection/Entries/EntriesSearch.js +113 -0
- package/dist/esm/components/Collection/Entries/EntryCard.js +177 -0
- package/dist/esm/components/Collection/Entries/EntryListing.js +143 -0
- package/dist/esm/components/Collection/FilterControl.js +33 -0
- package/dist/esm/components/Collection/FolderRenameControl.js +403 -0
- package/dist/esm/components/Collection/GroupControl.js +33 -0
- package/dist/esm/components/Collection/NestedCollection.js +308 -0
- package/dist/esm/components/Collection/Sidebar.js +91 -0
- package/dist/esm/components/Collection/SortControl.js +59 -0
- package/dist/esm/components/Collection/ViewStyleControl.js +38 -0
- package/dist/esm/components/Editor/Editor.js +466 -0
- package/dist/esm/components/Editor/EditorControlPane/EditorControl.js +395 -0
- package/dist/esm/components/Editor/EditorControlPane/EditorControlPane.js +254 -0
- package/dist/esm/components/Editor/EditorControlPane/Widget.js +374 -0
- package/dist/esm/components/Editor/EditorInterface.js +386 -0
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreview.js +47 -0
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreviewContent.js +66 -0
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreviewPane.js +288 -0
- package/dist/esm/components/Editor/EditorPreviewPane/PreviewHOC.js +27 -0
- package/dist/esm/components/Editor/EditorToolbar.js +536 -0
- package/dist/esm/components/Editor/EntryPathEditor.js +272 -0
- package/dist/esm/components/Editor/withWorkflow.js +56 -0
- package/dist/esm/components/EditorWidgets/Unknown/UnknownControl.js +18 -0
- package/dist/esm/components/EditorWidgets/Unknown/UnknownPreview.js +20 -0
- package/dist/esm/components/EditorWidgets/index.js +4 -0
- package/dist/esm/components/MediaLibrary/EmptyMessage.js +22 -0
- package/dist/esm/components/MediaLibrary/MediaLibrary.js +446 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryButtons.js +93 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryCard.js +99 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryCardGrid.js +198 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryHeader.js +32 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryModal.js +156 -0
- package/dist/esm/components/MediaLibrary/MediaLibrarySearch.js +51 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryTop.js +123 -0
- package/dist/esm/components/UI/DragDrop.js +67 -0
- package/dist/esm/components/UI/ErrorBoundary.js +173 -0
- package/dist/esm/components/UI/FileUploadButton.js +27 -0
- package/dist/esm/components/UI/Modal.js +104 -0
- package/dist/esm/components/UI/Notifications.js +62 -0
- package/dist/esm/components/UI/SettingsDropdown.js +107 -0
- package/dist/esm/components/UI/index.js +6 -0
- package/dist/esm/components/Workflow/Workflow.js +133 -0
- package/dist/esm/components/Workflow/WorkflowCard.js +128 -0
- package/dist/esm/components/Workflow/WorkflowList.js +204 -0
- package/dist/esm/constants/collectionTypes.js +2 -0
- package/dist/esm/constants/collectionViews.js +2 -0
- package/dist/esm/constants/commitProps.js +2 -0
- package/dist/esm/constants/configSchema.js +644 -0
- package/dist/esm/constants/fieldInference.js +57 -0
- package/dist/esm/constants/publishModes.js +18 -0
- package/dist/esm/constants/validationErrorTypes.js +6 -0
- package/dist/esm/formats/formats.js +83 -0
- package/dist/esm/formats/frontmatter.js +146 -0
- package/dist/esm/formats/helpers.js +12 -0
- package/dist/esm/formats/json.js +8 -0
- package/dist/esm/formats/toml.js +32 -0
- package/dist/esm/formats/yaml.js +51 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/integrations/index.js +28 -0
- package/dist/esm/integrations/providers/algolia/implementation.js +174 -0
- package/dist/esm/integrations/providers/assetStore/implementation.js +165 -0
- package/dist/esm/lib/consoleError.js +3 -0
- package/dist/esm/lib/formatters.js +191 -0
- package/dist/esm/lib/i18n.js +367 -0
- package/dist/esm/lib/phrases.js +6 -0
- package/dist/esm/lib/polyfill.js +8 -0
- package/dist/esm/lib/registry.js +329 -0
- package/dist/esm/lib/serializeEntryValues.js +67 -0
- package/dist/esm/lib/stega.js +142 -0
- package/dist/esm/lib/textHelper.js +9 -0
- package/dist/esm/lib/urlHelper.js +111 -0
- package/dist/esm/mediaLibrary.js +37 -0
- package/dist/esm/reducers/auth.js +27 -0
- package/dist/esm/reducers/collections.js +428 -0
- package/dist/esm/reducers/combinedReducer.js +8 -0
- package/dist/esm/reducers/config.js +29 -0
- package/dist/esm/reducers/cursors.js +31 -0
- package/dist/esm/reducers/deploys.js +45 -0
- package/dist/esm/reducers/editorialWorkflow.js +83 -0
- package/dist/esm/reducers/entries.js +568 -0
- package/dist/esm/reducers/entryDraft.js +212 -0
- package/dist/esm/reducers/globalUI.js +25 -0
- package/dist/esm/reducers/index.js +66 -0
- package/dist/esm/reducers/integrations.js +53 -0
- package/dist/esm/reducers/mediaLibrary.js +252 -0
- package/dist/esm/reducers/medias.js +68 -0
- package/dist/esm/reducers/notifications.js +23 -0
- package/dist/esm/reducers/search.js +92 -0
- package/dist/esm/reducers/status.js +30 -0
- package/dist/esm/redux/index.js +7 -0
- package/dist/esm/redux/middleware/waitUntilAction.js +48 -0
- package/dist/esm/routing/history.js +12 -0
- package/dist/esm/types/diacritics.d.js +0 -0
- package/dist/esm/types/global.d.js +1 -0
- package/dist/esm/types/immutable.js +7 -0
- package/dist/esm/types/redux.js +14 -0
- package/dist/esm/types/tomlify-j0.4.d.js +0 -0
- package/dist/esm/valueObjects/AssetProxy.js +44 -0
- package/dist/esm/valueObjects/EditorComponent.js +34 -0
- package/dist/esm/valueObjects/Entry.js +20 -0
- package/index.d.ts +618 -0
- package/package.json +106 -0
- package/src/__tests__/backend.spec.js +1161 -0
- package/src/actions/__tests__/config.spec.js +1009 -0
- package/src/actions/__tests__/editorialWorkflow.spec.js +216 -0
- package/src/actions/__tests__/entries.spec.js +596 -0
- package/src/actions/__tests__/media.spec.ts +171 -0
- package/src/actions/__tests__/mediaLibrary.spec.js +327 -0
- package/src/actions/__tests__/search.spec.js +209 -0
- package/src/actions/auth.ts +127 -0
- package/src/actions/collections.ts +18 -0
- package/src/actions/config.ts +565 -0
- package/src/actions/deploys.ts +104 -0
- package/src/actions/editorialWorkflow.ts +567 -0
- package/src/actions/entries.ts +1055 -0
- package/src/actions/media.ts +139 -0
- package/src/actions/mediaLibrary.ts +574 -0
- package/src/actions/notifications.ts +36 -0
- package/src/actions/search.ts +221 -0
- package/src/actions/status.ts +99 -0
- package/src/actions/waitUntil.ts +49 -0
- package/src/backend.ts +1400 -0
- package/src/bootstrap.js +104 -0
- package/src/components/App/App.js +286 -0
- package/src/components/App/Header.js +266 -0
- package/src/components/App/NotFoundPage.js +23 -0
- package/src/components/Collection/Collection.js +210 -0
- package/src/components/Collection/CollectionControls.js +58 -0
- package/src/components/Collection/CollectionSearch.js +243 -0
- package/src/components/Collection/CollectionTop.js +81 -0
- package/src/components/Collection/ControlButton.js +27 -0
- package/src/components/Collection/Entries/Entries.js +82 -0
- package/src/components/Collection/Entries/EntriesCollection.js +277 -0
- package/src/components/Collection/Entries/EntriesSearch.js +102 -0
- package/src/components/Collection/Entries/EntryCard.js +246 -0
- package/src/components/Collection/Entries/EntryListing.js +151 -0
- package/src/components/Collection/Entries/__tests__/EntriesCollection.spec.js +163 -0
- package/src/components/Collection/Entries/__tests__/__snapshots__/EntriesCollection.spec.js.snap +46 -0
- package/src/components/Collection/FilterControl.js +39 -0
- package/src/components/Collection/GroupControl.js +39 -0
- package/src/components/Collection/NestedCollection.js +330 -0
- package/src/components/Collection/Sidebar.js +136 -0
- package/src/components/Collection/SortControl.js +68 -0
- package/src/components/Collection/ViewStyleControl.js +50 -0
- package/src/components/Collection/__tests__/Collection.spec.js +75 -0
- package/src/components/Collection/__tests__/NestedCollection.spec.js +445 -0
- package/src/components/Collection/__tests__/Sidebar.spec.js +87 -0
- package/src/components/Collection/__tests__/__snapshots__/Collection.spec.js.snap +144 -0
- package/src/components/Collection/__tests__/__snapshots__/NestedCollection.spec.js.snap +550 -0
- package/src/components/Collection/__tests__/__snapshots__/Sidebar.spec.js.snap +312 -0
- package/src/components/Editor/Editor.js +497 -0
- package/src/components/Editor/EditorControlPane/EditorControl.js +452 -0
- package/src/components/Editor/EditorControlPane/EditorControlPane.js +269 -0
- package/src/components/Editor/EditorControlPane/Widget.js +384 -0
- package/src/components/Editor/EditorInterface.js +444 -0
- package/src/components/Editor/EditorPreviewPane/EditorPreview.js +40 -0
- package/src/components/Editor/EditorPreviewPane/EditorPreviewContent.js +74 -0
- package/src/components/Editor/EditorPreviewPane/EditorPreviewPane.js +333 -0
- package/src/components/Editor/EditorPreviewPane/PreviewHOC.js +33 -0
- package/src/components/Editor/EditorToolbar.js +691 -0
- package/src/components/Editor/__tests__/Editor.spec.js +221 -0
- package/src/components/Editor/__tests__/EditorToolbar.spec.js +120 -0
- package/src/components/Editor/__tests__/__snapshots__/Editor.spec.js.snap +45 -0
- package/src/components/Editor/__tests__/__snapshots__/EditorToolbar.spec.js.snap +4233 -0
- package/src/components/Editor/withWorkflow.js +61 -0
- package/src/components/EditorWidgets/Unknown/UnknownControl.js +17 -0
- package/src/components/EditorWidgets/Unknown/UnknownPreview.js +19 -0
- package/src/components/EditorWidgets/index.js +5 -0
- package/src/components/MediaLibrary/EmptyMessage.js +28 -0
- package/src/components/MediaLibrary/MediaLibrary.js +411 -0
- package/src/components/MediaLibrary/MediaLibraryButtons.js +136 -0
- package/src/components/MediaLibrary/MediaLibraryCard.js +128 -0
- package/src/components/MediaLibrary/MediaLibraryCardGrid.js +199 -0
- package/src/components/MediaLibrary/MediaLibraryHeader.js +48 -0
- package/src/components/MediaLibrary/MediaLibraryModal.js +200 -0
- package/src/components/MediaLibrary/MediaLibrarySearch.js +61 -0
- package/src/components/MediaLibrary/MediaLibraryTop.js +143 -0
- package/src/components/MediaLibrary/__tests__/MediaLibraryButtons.spec.js +45 -0
- package/src/components/MediaLibrary/__tests__/MediaLibraryCard.spec.js +49 -0
- package/src/components/MediaLibrary/__tests__/__snapshots__/MediaLibraryCard.spec.js.snap +264 -0
- package/src/components/UI/DragDrop.js +66 -0
- package/src/components/UI/ErrorBoundary.js +214 -0
- package/src/components/UI/FileUploadButton.js +24 -0
- package/src/components/UI/Modal.js +112 -0
- package/src/components/UI/Notifications.tsx +83 -0
- package/src/components/UI/SettingsDropdown.js +103 -0
- package/src/components/UI/__tests__/ErrorBoundary.spec.js +57 -0
- package/src/components/UI/index.js +6 -0
- package/src/components/Workflow/Workflow.js +169 -0
- package/src/components/Workflow/WorkflowCard.js +177 -0
- package/src/components/Workflow/WorkflowList.js +272 -0
- package/src/constants/__tests__/configSchema.spec.js +611 -0
- package/src/constants/collectionTypes.ts +2 -0
- package/src/constants/collectionViews.js +2 -0
- package/src/constants/commitProps.ts +2 -0
- package/src/constants/configSchema.js +441 -0
- package/src/constants/fieldInference.tsx +78 -0
- package/src/constants/publishModes.ts +22 -0
- package/src/constants/validationErrorTypes.js +6 -0
- package/src/formats/__tests__/formats.spec.js +87 -0
- package/src/formats/__tests__/frontmatter.spec.js +429 -0
- package/src/formats/__tests__/toml.spec.js +9 -0
- package/src/formats/__tests__/yaml.spec.js +162 -0
- package/src/formats/formats.ts +97 -0
- package/src/formats/frontmatter.ts +150 -0
- package/src/formats/helpers.ts +14 -0
- package/src/formats/json.ts +9 -0
- package/src/formats/toml.ts +33 -0
- package/src/formats/yaml.ts +58 -0
- package/src/index.js +8 -0
- package/src/integrations/index.js +35 -0
- package/src/integrations/providers/algolia/implementation.js +176 -0
- package/src/integrations/providers/assetStore/implementation.js +148 -0
- package/src/lib/__tests__/formatters.spec.js +751 -0
- package/src/lib/__tests__/i18n.spec.js +792 -0
- package/src/lib/__tests__/phrases.spec.js +119 -0
- package/src/lib/__tests__/registry.spec.js +261 -0
- package/src/lib/__tests__/serializeEntryValues.spec.js +22 -0
- package/src/lib/__tests__/urlHelper.spec.js +138 -0
- package/src/lib/consoleError.js +7 -0
- package/src/lib/formatters.ts +286 -0
- package/src/lib/i18n.ts +454 -0
- package/src/lib/phrases.js +8 -0
- package/src/lib/polyfill.js +9 -0
- package/src/lib/registry.js +312 -0
- package/src/lib/serializeEntryValues.js +75 -0
- package/src/lib/stega.ts +145 -0
- package/src/lib/textHelper.js +11 -0
- package/src/lib/urlHelper.ts +128 -0
- package/src/mediaLibrary.ts +51 -0
- package/src/reducers/__tests__/auth.spec.ts +38 -0
- package/src/reducers/__tests__/collections.spec.js +610 -0
- package/src/reducers/__tests__/config.spec.js +38 -0
- package/src/reducers/__tests__/entries.spec.js +694 -0
- package/src/reducers/__tests__/entryDraft.spec.js +297 -0
- package/src/reducers/__tests__/globalUI.js +43 -0
- package/src/reducers/__tests__/integrations.spec.ts +76 -0
- package/src/reducers/__tests__/mediaLibrary.spec.js +154 -0
- package/src/reducers/__tests__/medias.spec.ts +49 -0
- package/src/reducers/auth.ts +46 -0
- package/src/reducers/collections.ts +535 -0
- package/src/reducers/combinedReducer.ts +11 -0
- package/src/reducers/config.ts +38 -0
- package/src/reducers/cursors.js +36 -0
- package/src/reducers/deploys.ts +52 -0
- package/src/reducers/editorialWorkflow.ts +163 -0
- package/src/reducers/entries.ts +819 -0
- package/src/reducers/entryDraft.js +260 -0
- package/src/reducers/globalUI.ts +45 -0
- package/src/reducers/index.ts +82 -0
- package/src/reducers/integrations.ts +59 -0
- package/src/reducers/mediaLibrary.ts +296 -0
- package/src/reducers/medias.ts +66 -0
- package/src/reducers/notifications.ts +52 -0
- package/src/reducers/search.ts +111 -0
- package/src/reducers/status.ts +40 -0
- package/src/redux/index.ts +18 -0
- package/src/redux/middleware/waitUntilAction.ts +64 -0
- package/src/routing/__tests__/history.spec.ts +49 -0
- package/src/routing/history.ts +17 -0
- package/src/types/diacritics.d.ts +1 -0
- package/src/types/global.d.ts +8 -0
- package/src/types/immutable.ts +49 -0
- package/src/types/redux.ts +827 -0
- package/src/types/tomlify-j0.4.d.ts +13 -0
- package/src/valueObjects/AssetProxy.ts +48 -0
- package/src/valueObjects/EditorComponent.js +38 -0
- package/src/valueObjects/Entry.ts +63 -0
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
4
|
+
import { connect } from 'react-redux';
|
|
5
|
+
import { Loader } from 'decap-cms-ui-default';
|
|
6
|
+
import { translate } from 'react-polyglot';
|
|
7
|
+
import debounce from 'lodash/debounce';
|
|
8
|
+
import { history, navigateToCollection, navigateToNewEntry } from '../../routing/history';
|
|
9
|
+
import { logoutUser } from '../../actions/auth';
|
|
10
|
+
import { loadEntry, loadEntries, createDraftDuplicateFromEntry, createEmptyDraft, discardDraft, changeDraftField, changeDraftFieldValidation, persistEntry, deleteEntry, persistLocalBackup, loadLocalBackup, retrieveLocalBackup, deleteLocalBackup } from '../../actions/entries';
|
|
11
|
+
import { updateUnpublishedEntryStatus, publishUnpublishedEntry, unpublishPublishedEntry, deleteUnpublishedEntry } from '../../actions/editorialWorkflow';
|
|
12
|
+
import { loadDeployPreview } from '../../actions/deploys';
|
|
13
|
+
import { selectEntry, selectUnpublishedEntry, selectDeployPreview } from '../../reducers';
|
|
14
|
+
import { selectFields } from '../../reducers/collections';
|
|
15
|
+
import { status, EDITORIAL_WORKFLOW } from '../../constants/publishModes';
|
|
16
|
+
import EditorInterface from './EditorInterface';
|
|
17
|
+
import withWorkflow from './withWorkflow';
|
|
18
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
19
|
+
export class Editor extends React.Component {
|
|
20
|
+
static propTypes = {
|
|
21
|
+
changeDraftField: PropTypes.func.isRequired,
|
|
22
|
+
changeDraftFieldValidation: PropTypes.func.isRequired,
|
|
23
|
+
collection: ImmutablePropTypes.map.isRequired,
|
|
24
|
+
createDraftDuplicateFromEntry: PropTypes.func.isRequired,
|
|
25
|
+
createEmptyDraft: PropTypes.func.isRequired,
|
|
26
|
+
discardDraft: PropTypes.func.isRequired,
|
|
27
|
+
entry: ImmutablePropTypes.map,
|
|
28
|
+
entryDraft: ImmutablePropTypes.map.isRequired,
|
|
29
|
+
loadEntry: PropTypes.func.isRequired,
|
|
30
|
+
persistEntry: PropTypes.func.isRequired,
|
|
31
|
+
deleteEntry: PropTypes.func.isRequired,
|
|
32
|
+
showDelete: PropTypes.bool.isRequired,
|
|
33
|
+
fields: ImmutablePropTypes.list.isRequired,
|
|
34
|
+
slug: PropTypes.string,
|
|
35
|
+
newEntry: PropTypes.bool.isRequired,
|
|
36
|
+
displayUrl: PropTypes.string,
|
|
37
|
+
hasWorkflow: PropTypes.bool,
|
|
38
|
+
useOpenAuthoring: PropTypes.bool,
|
|
39
|
+
unpublishedEntry: PropTypes.bool,
|
|
40
|
+
isModification: PropTypes.bool,
|
|
41
|
+
collectionEntriesLoaded: PropTypes.bool,
|
|
42
|
+
updateUnpublishedEntryStatus: PropTypes.func.isRequired,
|
|
43
|
+
publishUnpublishedEntry: PropTypes.func.isRequired,
|
|
44
|
+
deleteUnpublishedEntry: PropTypes.func.isRequired,
|
|
45
|
+
logoutUser: PropTypes.func.isRequired,
|
|
46
|
+
loadEntries: PropTypes.func.isRequired,
|
|
47
|
+
deployPreview: PropTypes.object,
|
|
48
|
+
loadDeployPreview: PropTypes.func.isRequired,
|
|
49
|
+
currentStatus: PropTypes.string,
|
|
50
|
+
user: PropTypes.object,
|
|
51
|
+
location: PropTypes.shape({
|
|
52
|
+
pathname: PropTypes.string,
|
|
53
|
+
search: PropTypes.string
|
|
54
|
+
}),
|
|
55
|
+
hasChanged: PropTypes.bool,
|
|
56
|
+
t: PropTypes.func.isRequired,
|
|
57
|
+
retrieveLocalBackup: PropTypes.func.isRequired,
|
|
58
|
+
localBackup: ImmutablePropTypes.map,
|
|
59
|
+
loadLocalBackup: PropTypes.func,
|
|
60
|
+
persistLocalBackup: PropTypes.func.isRequired,
|
|
61
|
+
deleteLocalBackup: PropTypes.func
|
|
62
|
+
};
|
|
63
|
+
componentDidMount() {
|
|
64
|
+
// Manually validate PropTypes - React 19 breaking change
|
|
65
|
+
PropTypes.checkPropTypes(Editor.propTypes, this.props, 'prop', 'Editor');
|
|
66
|
+
const {
|
|
67
|
+
newEntry,
|
|
68
|
+
collection,
|
|
69
|
+
slug,
|
|
70
|
+
loadEntry,
|
|
71
|
+
createEmptyDraft,
|
|
72
|
+
loadEntries,
|
|
73
|
+
retrieveLocalBackup,
|
|
74
|
+
collectionEntriesLoaded,
|
|
75
|
+
t
|
|
76
|
+
} = this.props;
|
|
77
|
+
retrieveLocalBackup(collection, slug);
|
|
78
|
+
if (newEntry) {
|
|
79
|
+
createEmptyDraft(collection, this.props.location.search);
|
|
80
|
+
} else {
|
|
81
|
+
loadEntry(collection, slug);
|
|
82
|
+
}
|
|
83
|
+
const leaveMessage = t('editor.editor.onLeavePage');
|
|
84
|
+
this.exitBlocker = event => {
|
|
85
|
+
if (this.props.entryDraft.get('hasChanged')) {
|
|
86
|
+
// This message is ignored in most browsers, but its presence
|
|
87
|
+
// triggers the confirmation dialog
|
|
88
|
+
event.returnValue = leaveMessage;
|
|
89
|
+
return leaveMessage;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
window.addEventListener('beforeunload', this.exitBlocker);
|
|
93
|
+
const navigationBlocker = (location, action) => {
|
|
94
|
+
/**
|
|
95
|
+
* New entry being saved and redirected to it's new slug based url.
|
|
96
|
+
*/
|
|
97
|
+
const isPersisting = this.props.entryDraft.getIn(['entry', 'isPersisting']);
|
|
98
|
+
const newRecord = this.props.entryDraft.getIn(['entry', 'newRecord']);
|
|
99
|
+
const newEntryPath = `/collections/${collection.get('name')}/new`;
|
|
100
|
+
if (isPersisting && newRecord && this.props.location.pathname === newEntryPath && action === 'PUSH') {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (this.props.hasChanged) {
|
|
104
|
+
return leaveMessage;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const unblock = history.block(navigationBlocker);
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* This will run as soon as the location actually changes, unless creating
|
|
111
|
+
* a new post. The confirmation above will run first.
|
|
112
|
+
*/
|
|
113
|
+
this.unlisten = history.listen((location, action) => {
|
|
114
|
+
const newEntryPath = `/collections/${collection.get('name')}/new`;
|
|
115
|
+
const entriesPath = `/collections/${collection.get('name')}/entries/`;
|
|
116
|
+
const {
|
|
117
|
+
pathname
|
|
118
|
+
} = location;
|
|
119
|
+
if (pathname.startsWith(newEntryPath) || pathname.startsWith(entriesPath) && action === 'PUSH') {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
this.deleteBackup();
|
|
123
|
+
unblock();
|
|
124
|
+
this.unlisten();
|
|
125
|
+
});
|
|
126
|
+
if (!collectionEntriesLoaded) {
|
|
127
|
+
loadEntries(collection);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
componentDidUpdate(prevProps) {
|
|
131
|
+
if (!prevProps.localBackup && this.props.localBackup) {
|
|
132
|
+
const confirmLoadBackup = window.confirm(this.props.t('editor.editor.confirmLoadBackup'));
|
|
133
|
+
if (confirmLoadBackup) {
|
|
134
|
+
this.props.loadLocalBackup();
|
|
135
|
+
} else {
|
|
136
|
+
this.deleteBackup();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (this.props.hasChanged) {
|
|
140
|
+
this.createBackup(this.props.entryDraft.get('entry'), this.props.collection);
|
|
141
|
+
}
|
|
142
|
+
if (prevProps.entry === this.props.entry) return;
|
|
143
|
+
const {
|
|
144
|
+
newEntry,
|
|
145
|
+
collection
|
|
146
|
+
} = this.props;
|
|
147
|
+
if (newEntry) {
|
|
148
|
+
prevProps.createEmptyDraft(collection, this.props.location.search);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
componentWillUnmount() {
|
|
152
|
+
this.createBackup.flush();
|
|
153
|
+
this.props.discardDraft();
|
|
154
|
+
window.removeEventListener('beforeunload', this.exitBlocker);
|
|
155
|
+
}
|
|
156
|
+
createBackup = debounce(function (entry, collection) {
|
|
157
|
+
this.props.persistLocalBackup(entry, collection);
|
|
158
|
+
}, 2000);
|
|
159
|
+
handleChangeDraftField = (field, value, metadata, i18n) => {
|
|
160
|
+
const entries = [this.props.unPublishedEntry, this.props.publishedEntry].filter(Boolean);
|
|
161
|
+
this.props.changeDraftField({
|
|
162
|
+
field,
|
|
163
|
+
value,
|
|
164
|
+
metadata,
|
|
165
|
+
entries,
|
|
166
|
+
i18n
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
handleChangeStatus = newStatusName => {
|
|
170
|
+
const {
|
|
171
|
+
entryDraft,
|
|
172
|
+
updateUnpublishedEntryStatus,
|
|
173
|
+
collection,
|
|
174
|
+
slug,
|
|
175
|
+
currentStatus,
|
|
176
|
+
t
|
|
177
|
+
} = this.props;
|
|
178
|
+
if (entryDraft.get('hasChanged')) {
|
|
179
|
+
window.alert(t('editor.editor.onUpdatingWithUnsavedChanges'));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const newStatus = status.get(newStatusName);
|
|
183
|
+
updateUnpublishedEntryStatus(collection.get('name'), slug, currentStatus, newStatus);
|
|
184
|
+
};
|
|
185
|
+
deleteBackup() {
|
|
186
|
+
const {
|
|
187
|
+
deleteLocalBackup,
|
|
188
|
+
collection,
|
|
189
|
+
slug,
|
|
190
|
+
newEntry
|
|
191
|
+
} = this.props;
|
|
192
|
+
this.createBackup.cancel();
|
|
193
|
+
deleteLocalBackup(collection, !newEntry && slug);
|
|
194
|
+
}
|
|
195
|
+
handlePersistEntry = async (opts = {}) => {
|
|
196
|
+
const {
|
|
197
|
+
createNew = false,
|
|
198
|
+
duplicate = false
|
|
199
|
+
} = opts;
|
|
200
|
+
const {
|
|
201
|
+
persistEntry,
|
|
202
|
+
collection,
|
|
203
|
+
currentStatus,
|
|
204
|
+
hasWorkflow,
|
|
205
|
+
loadEntry,
|
|
206
|
+
slug,
|
|
207
|
+
createDraftDuplicateFromEntry,
|
|
208
|
+
entryDraft
|
|
209
|
+
} = this.props;
|
|
210
|
+
await persistEntry(collection);
|
|
211
|
+
this.deleteBackup();
|
|
212
|
+
if (createNew) {
|
|
213
|
+
navigateToNewEntry(collection.get('name'));
|
|
214
|
+
duplicate && createDraftDuplicateFromEntry(entryDraft.get('entry'));
|
|
215
|
+
} else if (slug && hasWorkflow && !currentStatus) {
|
|
216
|
+
loadEntry(collection, slug);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
handlePublishEntry = async (opts = {}) => {
|
|
220
|
+
const {
|
|
221
|
+
createNew = false,
|
|
222
|
+
duplicate = false
|
|
223
|
+
} = opts;
|
|
224
|
+
const {
|
|
225
|
+
publishUnpublishedEntry,
|
|
226
|
+
createDraftDuplicateFromEntry,
|
|
227
|
+
entryDraft,
|
|
228
|
+
collection,
|
|
229
|
+
slug,
|
|
230
|
+
currentStatus,
|
|
231
|
+
t
|
|
232
|
+
} = this.props;
|
|
233
|
+
if (currentStatus !== status.last()) {
|
|
234
|
+
window.alert(t('editor.editor.onPublishingNotReady'));
|
|
235
|
+
return;
|
|
236
|
+
} else if (entryDraft.get('hasChanged')) {
|
|
237
|
+
window.alert(t('editor.editor.onPublishingWithUnsavedChanges'));
|
|
238
|
+
return;
|
|
239
|
+
} else if (!window.confirm(t('editor.editor.onPublishing'))) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
await publishUnpublishedEntry(collection.get('name'), slug);
|
|
243
|
+
this.deleteBackup();
|
|
244
|
+
if (createNew) {
|
|
245
|
+
navigateToNewEntry(collection.get('name'));
|
|
246
|
+
}
|
|
247
|
+
duplicate && createDraftDuplicateFromEntry(entryDraft.get('entry'));
|
|
248
|
+
};
|
|
249
|
+
handleUnpublishEntry = async () => {
|
|
250
|
+
const {
|
|
251
|
+
unpublishPublishedEntry,
|
|
252
|
+
collection,
|
|
253
|
+
slug,
|
|
254
|
+
t
|
|
255
|
+
} = this.props;
|
|
256
|
+
if (!window.confirm(t('editor.editor.onUnpublishing'))) return;
|
|
257
|
+
await unpublishPublishedEntry(collection, slug);
|
|
258
|
+
return navigateToCollection(collection.get('name'));
|
|
259
|
+
};
|
|
260
|
+
handleDuplicateEntry = () => {
|
|
261
|
+
const {
|
|
262
|
+
createDraftDuplicateFromEntry,
|
|
263
|
+
collection,
|
|
264
|
+
entryDraft
|
|
265
|
+
} = this.props;
|
|
266
|
+
navigateToNewEntry(collection.get('name'));
|
|
267
|
+
createDraftDuplicateFromEntry(entryDraft.get('entry'));
|
|
268
|
+
};
|
|
269
|
+
handleDeleteEntry = () => {
|
|
270
|
+
const {
|
|
271
|
+
entryDraft,
|
|
272
|
+
newEntry,
|
|
273
|
+
collection,
|
|
274
|
+
deleteEntry,
|
|
275
|
+
slug,
|
|
276
|
+
t
|
|
277
|
+
} = this.props;
|
|
278
|
+
if (entryDraft.get('hasChanged')) {
|
|
279
|
+
if (!window.confirm(t('editor.editor.onDeleteWithUnsavedChanges'))) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
} else if (!window.confirm(t('editor.editor.onDeletePublishedEntry'))) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (newEntry) {
|
|
286
|
+
return navigateToCollection(collection.get('name'));
|
|
287
|
+
}
|
|
288
|
+
setTimeout(async () => {
|
|
289
|
+
await deleteEntry(collection, slug);
|
|
290
|
+
this.deleteBackup();
|
|
291
|
+
return navigateToCollection(collection.get('name'));
|
|
292
|
+
}, 0);
|
|
293
|
+
};
|
|
294
|
+
handleDeleteUnpublishedChanges = async () => {
|
|
295
|
+
const {
|
|
296
|
+
entryDraft,
|
|
297
|
+
collection,
|
|
298
|
+
slug,
|
|
299
|
+
deleteUnpublishedEntry,
|
|
300
|
+
loadEntry,
|
|
301
|
+
isModification,
|
|
302
|
+
t
|
|
303
|
+
} = this.props;
|
|
304
|
+
if (entryDraft.get('hasChanged') && !window.confirm(t('editor.editor.onDeleteUnpublishedChangesWithUnsavedChanges'))) {
|
|
305
|
+
return;
|
|
306
|
+
} else if (!window.confirm(t('editor.editor.onDeleteUnpublishedChanges'))) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
await deleteUnpublishedEntry(collection.get('name'), slug);
|
|
310
|
+
this.deleteBackup();
|
|
311
|
+
if (isModification) {
|
|
312
|
+
loadEntry(collection, slug);
|
|
313
|
+
} else {
|
|
314
|
+
navigateToCollection(collection.get('name'));
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
render() {
|
|
318
|
+
const {
|
|
319
|
+
entry,
|
|
320
|
+
entryDraft,
|
|
321
|
+
fields,
|
|
322
|
+
collection,
|
|
323
|
+
changeDraftFieldValidation,
|
|
324
|
+
user,
|
|
325
|
+
hasChanged,
|
|
326
|
+
displayUrl,
|
|
327
|
+
hasWorkflow,
|
|
328
|
+
useOpenAuthoring,
|
|
329
|
+
unpublishedEntry,
|
|
330
|
+
newEntry,
|
|
331
|
+
isModification,
|
|
332
|
+
currentStatus,
|
|
333
|
+
logoutUser,
|
|
334
|
+
deployPreview,
|
|
335
|
+
loadDeployPreview,
|
|
336
|
+
draftKey,
|
|
337
|
+
slug,
|
|
338
|
+
t,
|
|
339
|
+
editorBackLink
|
|
340
|
+
} = this.props;
|
|
341
|
+
const isPublished = !newEntry && !unpublishedEntry;
|
|
342
|
+
if (entry && entry.get('error')) {
|
|
343
|
+
return ___EmotionJSX("div", null, ___EmotionJSX("h3", null, entry.get('error')));
|
|
344
|
+
} else if (entryDraft == null || entryDraft.get('entry') === undefined || entry && entry.get('isFetching')) {
|
|
345
|
+
return ___EmotionJSX(Loader, {
|
|
346
|
+
active: true
|
|
347
|
+
}, t('editor.editor.loadingEntry'));
|
|
348
|
+
}
|
|
349
|
+
return ___EmotionJSX(EditorInterface, {
|
|
350
|
+
draftKey: draftKey,
|
|
351
|
+
entry: entryDraft.get('entry'),
|
|
352
|
+
collection: collection,
|
|
353
|
+
fields: fields,
|
|
354
|
+
fieldsMetaData: entryDraft.get('fieldsMetaData'),
|
|
355
|
+
fieldsErrors: entryDraft.get('fieldsErrors'),
|
|
356
|
+
onChange: this.handleChangeDraftField,
|
|
357
|
+
onValidate: changeDraftFieldValidation,
|
|
358
|
+
onPersist: this.handlePersistEntry,
|
|
359
|
+
onDelete: this.handleDeleteEntry,
|
|
360
|
+
onDeleteUnpublishedChanges: this.handleDeleteUnpublishedChanges,
|
|
361
|
+
onChangeStatus: this.handleChangeStatus,
|
|
362
|
+
onPublish: this.handlePublishEntry,
|
|
363
|
+
unPublish: this.handleUnpublishEntry,
|
|
364
|
+
onDuplicate: this.handleDuplicateEntry,
|
|
365
|
+
showDelete: this.props.showDelete,
|
|
366
|
+
user: user,
|
|
367
|
+
hasChanged: hasChanged,
|
|
368
|
+
displayUrl: displayUrl,
|
|
369
|
+
hasWorkflow: hasWorkflow,
|
|
370
|
+
useOpenAuthoring: useOpenAuthoring,
|
|
371
|
+
hasUnpublishedChanges: unpublishedEntry,
|
|
372
|
+
isNewEntry: newEntry,
|
|
373
|
+
isModification: isModification,
|
|
374
|
+
currentStatus: currentStatus,
|
|
375
|
+
onLogoutClick: logoutUser,
|
|
376
|
+
deployPreview: deployPreview,
|
|
377
|
+
loadDeployPreview: opts => loadDeployPreview(collection, slug, entry, isPublished, opts),
|
|
378
|
+
editorBackLink: editorBackLink,
|
|
379
|
+
t: t
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
function mapStateToProps(state, ownProps) {
|
|
384
|
+
const {
|
|
385
|
+
collections,
|
|
386
|
+
entryDraft,
|
|
387
|
+
auth,
|
|
388
|
+
config,
|
|
389
|
+
entries,
|
|
390
|
+
globalUI
|
|
391
|
+
} = state;
|
|
392
|
+
const slug = ownProps.match.params[0];
|
|
393
|
+
const collection = collections.get(ownProps.match.params.name);
|
|
394
|
+
const collectionName = collection.get('name');
|
|
395
|
+
const newEntry = ownProps.newRecord === true;
|
|
396
|
+
const fields = selectFields(collection, slug);
|
|
397
|
+
const entry = newEntry ? null : selectEntry(state, collectionName, slug);
|
|
398
|
+
const user = auth.user;
|
|
399
|
+
const hasChanged = entryDraft.get('hasChanged');
|
|
400
|
+
const displayUrl = config.display_url;
|
|
401
|
+
const hasWorkflow = config.publish_mode === EDITORIAL_WORKFLOW;
|
|
402
|
+
const useOpenAuthoring = globalUI.useOpenAuthoring;
|
|
403
|
+
const isModification = entryDraft.getIn(['entry', 'isModification']);
|
|
404
|
+
const collectionEntriesLoaded = !!entries.getIn(['pages', collectionName]);
|
|
405
|
+
const unPublishedEntry = selectUnpublishedEntry(state, collectionName, slug);
|
|
406
|
+
const publishedEntry = selectEntry(state, collectionName, slug);
|
|
407
|
+
const currentStatus = unPublishedEntry && unPublishedEntry.get('status');
|
|
408
|
+
const deployPreview = selectDeployPreview(state, collectionName, slug);
|
|
409
|
+
const localBackup = entryDraft.get('localBackup');
|
|
410
|
+
const draftKey = entryDraft.get('key');
|
|
411
|
+
let editorBackLink = `/collections/${collectionName}`;
|
|
412
|
+
if (new URLSearchParams(ownProps.location.search).get('ref') === 'workflow') {
|
|
413
|
+
editorBackLink = `/workflow`;
|
|
414
|
+
}
|
|
415
|
+
if (collection.has('nested') && slug) {
|
|
416
|
+
const pathParts = slug.split('/');
|
|
417
|
+
if (pathParts.length > 2) {
|
|
418
|
+
editorBackLink = `${editorBackLink}/filter/${pathParts.slice(0, -2).join('/')}`;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return {
|
|
422
|
+
collection,
|
|
423
|
+
collections,
|
|
424
|
+
newEntry,
|
|
425
|
+
entryDraft,
|
|
426
|
+
fields,
|
|
427
|
+
slug,
|
|
428
|
+
entry,
|
|
429
|
+
user,
|
|
430
|
+
hasChanged,
|
|
431
|
+
displayUrl,
|
|
432
|
+
hasWorkflow,
|
|
433
|
+
useOpenAuthoring,
|
|
434
|
+
isModification,
|
|
435
|
+
collectionEntriesLoaded,
|
|
436
|
+
currentStatus,
|
|
437
|
+
deployPreview,
|
|
438
|
+
localBackup,
|
|
439
|
+
draftKey,
|
|
440
|
+
publishedEntry,
|
|
441
|
+
unPublishedEntry,
|
|
442
|
+
editorBackLink
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
const mapDispatchToProps = {
|
|
446
|
+
changeDraftField,
|
|
447
|
+
changeDraftFieldValidation,
|
|
448
|
+
loadEntry,
|
|
449
|
+
loadEntries,
|
|
450
|
+
loadDeployPreview,
|
|
451
|
+
loadLocalBackup,
|
|
452
|
+
retrieveLocalBackup,
|
|
453
|
+
persistLocalBackup,
|
|
454
|
+
deleteLocalBackup,
|
|
455
|
+
createDraftDuplicateFromEntry,
|
|
456
|
+
createEmptyDraft,
|
|
457
|
+
discardDraft,
|
|
458
|
+
persistEntry,
|
|
459
|
+
deleteEntry,
|
|
460
|
+
updateUnpublishedEntryStatus,
|
|
461
|
+
publishUnpublishedEntry,
|
|
462
|
+
unpublishPublishedEntry,
|
|
463
|
+
deleteUnpublishedEntry,
|
|
464
|
+
logoutUser
|
|
465
|
+
};
|
|
466
|
+
export default connect(mapStateToProps, mapDispatchToProps)(withWorkflow(translate()(Editor)));
|