decap-cms-core 3.5.0 → 3.6.0
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/dist/decap-cms-core.js +9 -9
- package/dist/decap-cms-core.js.map +1 -1
- package/dist/esm/actions/auth.js +22 -37
- package/dist/esm/actions/collections.js +9 -17
- package/dist/esm/actions/config.js +58 -74
- package/dist/esm/actions/deploys.js +10 -17
- package/dist/esm/actions/editorialWorkflow.js +87 -101
- package/dist/esm/actions/entries.js +161 -211
- package/dist/esm/actions/media.js +31 -46
- package/dist/esm/actions/mediaLibrary.js +94 -126
- package/dist/esm/actions/notifications.js +5 -13
- package/dist/esm/actions/search.js +30 -47
- package/dist/esm/actions/status.js +13 -23
- package/dist/esm/actions/waitUntil.js +4 -11
- package/dist/esm/backend.js +132 -148
- package/dist/esm/bootstrap.js +37 -44
- package/dist/esm/components/App/App.js +82 -89
- package/dist/esm/components/App/Header.js +46 -52
- package/dist/esm/components/App/NotFoundPage.js +11 -18
- package/dist/esm/components/Collection/Collection.js +55 -63
- package/dist/esm/components/Collection/CollectionControls.js +15 -22
- package/dist/esm/components/Collection/CollectionSearch.js +35 -42
- package/dist/esm/components/Collection/CollectionTop.js +23 -30
- package/dist/esm/components/Collection/ControlButton.js +10 -16
- package/dist/esm/components/Collection/Entries/Entries.js +24 -31
- package/dist/esm/components/Collection/Entries/EntriesCollection.js +52 -62
- package/dist/esm/components/Collection/Entries/EntriesSearch.js +26 -33
- package/dist/esm/components/Collection/Entries/EntryCard.js +38 -45
- package/dist/esm/components/Collection/Entries/EntryListing.js +24 -32
- package/dist/esm/components/Collection/FilterControl.js +9 -16
- package/dist/esm/components/Collection/GroupControl.js +9 -16
- package/dist/esm/components/Collection/NestedCollection.js +54 -65
- package/dist/esm/components/Collection/Sidebar.js +36 -43
- package/dist/esm/components/Collection/SortControl.js +19 -26
- package/dist/esm/components/Collection/ViewStyleControl.js +17 -24
- package/dist/esm/components/Editor/Editor.js +100 -108
- package/dist/esm/components/Editor/EditorControlPane/EditorControl.js +105 -112
- package/dist/esm/components/Editor/EditorControlPane/EditorControlPane.js +68 -62
- package/dist/esm/components/Editor/EditorControlPane/Widget.js +87 -73
- package/dist/esm/components/Editor/EditorInterface.js +95 -98
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreview.js +13 -21
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreviewContent.js +64 -23
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreviewPane.js +94 -78
- package/dist/esm/components/Editor/EditorPreviewPane/PreviewHOC.js +9 -16
- package/dist/esm/components/Editor/EditorToolbar.js +133 -140
- package/dist/esm/components/Editor/withWorkflow.js +15 -22
- package/dist/esm/components/EditorWidgets/Unknown/UnknownControl.js +9 -16
- package/dist/esm/components/EditorWidgets/Unknown/UnknownPreview.js +9 -16
- package/dist/esm/components/EditorWidgets/index.js +4 -7
- package/dist/esm/components/MediaLibrary/EmptyMessage.js +12 -19
- package/dist/esm/components/MediaLibrary/MediaLibrary.js +55 -62
- package/dist/esm/components/MediaLibrary/MediaLibraryButtons.js +28 -35
- package/dist/esm/components/MediaLibrary/MediaLibraryCard.js +36 -43
- package/dist/esm/components/MediaLibrary/MediaLibraryCardGrid.js +50 -57
- package/dist/esm/components/MediaLibrary/MediaLibraryHeader.js +16 -23
- package/dist/esm/components/MediaLibrary/MediaLibraryModal.js +59 -64
- package/dist/esm/components/MediaLibrary/MediaLibrarySearch.js +18 -25
- package/dist/esm/components/MediaLibrary/MediaLibraryTop.js +39 -46
- package/dist/esm/components/UI/DragDrop.js +21 -30
- package/dist/esm/components/UI/ErrorBoundary.js +35 -43
- package/dist/esm/components/UI/FileUploadButton.js +11 -18
- package/dist/esm/components/UI/Modal.js +19 -26
- package/dist/esm/components/UI/Notifications.js +21 -28
- package/dist/esm/components/UI/SettingsDropdown.js +28 -34
- package/dist/esm/components/UI/index.js +6 -60
- package/dist/esm/components/Workflow/Workflow.js +52 -61
- package/dist/esm/components/Workflow/WorkflowCard.js +45 -51
- package/dist/esm/components/Workflow/WorkflowList.js +43 -49
- package/dist/esm/constants/collectionTypes.js +2 -8
- package/dist/esm/constants/collectionViews.js +2 -8
- package/dist/esm/constants/commitProps.js +2 -8
- package/dist/esm/constants/configSchema.js +20 -27
- package/dist/esm/constants/fieldInference.js +8 -15
- package/dist/esm/constants/publishModes.js +6 -11
- package/dist/esm/constants/validationErrorTypes.js +1 -7
- package/dist/esm/formats/formats.js +32 -41
- package/dist/esm/formats/frontmatter.js +18 -30
- package/dist/esm/formats/helpers.js +1 -7
- package/dist/esm/formats/json.js +1 -7
- package/dist/esm/formats/toml.js +11 -18
- package/dist/esm/formats/yaml.js +7 -14
- package/dist/esm/index.js +5 -12
- package/dist/esm/integrations/index.js +8 -16
- package/dist/esm/integrations/providers/algolia/implementation.js +14 -22
- package/dist/esm/integrations/providers/assetStore/implementation.js +10 -18
- package/dist/esm/lib/consoleError.js +1 -7
- package/dist/esm/lib/formatters.js +34 -47
- package/dist/esm/lib/i18n.js +37 -66
- package/dist/esm/lib/phrases.js +4 -11
- package/dist/esm/lib/registry.js +40 -75
- package/dist/esm/lib/serializeEntryValues.js +11 -18
- package/dist/esm/lib/textHelper.js +1 -7
- package/dist/esm/lib/urlHelper.js +28 -43
- package/dist/esm/mediaLibrary.js +12 -16
- package/dist/esm/reducers/auth.js +10 -16
- package/dist/esm/reducers/collections.js +70 -102
- package/dist/esm/reducers/combinedReducer.js +4 -11
- package/dist/esm/reducers/config.js +11 -19
- package/dist/esm/reducers/cursors.js +12 -18
- package/dist/esm/reducers/deploys.js +8 -15
- package/dist/esm/reducers/editorialWorkflow.js +37 -47
- package/dist/esm/reducers/entries.js +107 -132
- package/dist/esm/reducers/entryDraft.js +64 -72
- package/dist/esm/reducers/globalUI.js +5 -11
- package/dist/esm/reducers/index.js +43 -64
- package/dist/esm/reducers/integrations.js +8 -16
- package/dist/esm/reducers/mediaLibrary.js +43 -52
- package/dist/esm/reducers/medias.js +11 -18
- package/dist/esm/reducers/notifications.js +9 -15
- package/dist/esm/reducers/search.js +12 -18
- package/dist/esm/reducers/status.js +7 -13
- package/dist/esm/redux/index.js +7 -13
- package/dist/esm/redux/middleware/waitUntilAction.js +3 -10
- package/dist/esm/routing/history.js +7 -15
- package/dist/esm/types/diacritics.d.js +0 -1
- package/dist/esm/types/global.d.js +1 -5
- package/dist/esm/types/immutable.js +1 -5
- package/dist/esm/types/redux.js +7 -8
- package/dist/esm/types/tomlify-j0.4.d.js +0 -1
- package/dist/esm/valueObjects/AssetProxy.js +2 -10
- package/dist/esm/valueObjects/EditorComponent.js +5 -12
- package/dist/esm/valueObjects/Entry.js +3 -10
- package/package.json +3 -2
- package/src/components/Collection/Entries/EntriesCollection.js +7 -8
- package/src/components/Collection/Entries/__tests__/EntriesCollection.spec.js +3 -5
- package/src/components/Collection/Entries/__tests__/__snapshots__/EntriesCollection.spec.js.snap +8 -8
- package/src/components/Collection/NestedCollection.js +2 -2
- package/src/components/Collection/__tests__/__snapshots__/NestedCollection.spec.js.snap +68 -0
- package/src/components/Editor/EditorControlPane/EditorControl.js +0 -3
- package/src/components/Editor/EditorControlPane/EditorControlPane.js +21 -8
- package/src/components/Editor/EditorControlPane/Widget.js +22 -1
- package/src/components/Editor/EditorInterface.js +6 -1
- package/src/components/Editor/EditorPreviewPane/EditorPreviewContent.js +51 -11
- package/src/components/Editor/EditorPreviewPane/EditorPreviewPane.js +33 -1
- package/dist/esm/actions/editorControl.js +0 -14
- package/dist/esm/reducers/editorComponent.js +0 -1
- package/dist/esm/reducers/editorControl.js +0 -17
|
@@ -1,29 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.getIntegrationProvider = void 0;
|
|
7
|
-
exports.resolveIntegrations = resolveIntegrations;
|
|
8
|
-
var _immutable = require("immutable");
|
|
9
|
-
var _implementation = _interopRequireDefault(require("./providers/algolia/implementation"));
|
|
10
|
-
var _implementation2 = _interopRequireDefault(require("./providers/assetStore/implementation"));
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
function resolveIntegrations(integrationsConfig, getToken) {
|
|
13
|
-
let integrationInstances = (0, _immutable.Map)({});
|
|
1
|
+
import { Map } from 'immutable';
|
|
2
|
+
import Algolia from './providers/algolia/implementation';
|
|
3
|
+
import AssetStore from './providers/assetStore/implementation';
|
|
4
|
+
export function resolveIntegrations(integrationsConfig, getToken) {
|
|
5
|
+
let integrationInstances = Map({});
|
|
14
6
|
integrationsConfig.get('providers').forEach((providerData, providerName) => {
|
|
15
7
|
switch (providerName) {
|
|
16
8
|
case 'algolia':
|
|
17
|
-
integrationInstances = integrationInstances.set('algolia', new
|
|
9
|
+
integrationInstances = integrationInstances.set('algolia', new Algolia(providerData));
|
|
18
10
|
break;
|
|
19
11
|
case 'assetStore':
|
|
20
|
-
integrationInstances = integrationInstances.set('assetStore', new
|
|
12
|
+
integrationInstances = integrationInstances.set('assetStore', new AssetStore(providerData, getToken));
|
|
21
13
|
break;
|
|
22
14
|
}
|
|
23
15
|
});
|
|
24
16
|
return integrationInstances;
|
|
25
17
|
}
|
|
26
|
-
const getIntegrationProvider =
|
|
18
|
+
export const getIntegrationProvider = function () {
|
|
27
19
|
let integrations = null;
|
|
28
20
|
return (integrationsConfig, getToken, provider) => {
|
|
29
21
|
if (integrations) {
|
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _flatten2 = _interopRequireDefault(require("lodash/flatten"));
|
|
8
|
-
var _decapCmsLibUtil = require("decap-cms-lib-util");
|
|
9
|
-
var _Entry = require("../../../valueObjects/Entry");
|
|
10
|
-
var _collections = require("../../../reducers/collections");
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
import _flatten from "lodash/flatten";
|
|
12
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
13
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
14
4
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
16
6
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import { unsentRequest } from 'decap-cms-lib-util';
|
|
8
|
+
import { createEntry } from '../../../valueObjects/Entry';
|
|
9
|
+
import { selectEntrySlug } from '../../../reducers/collections';
|
|
17
10
|
const {
|
|
18
11
|
fetchWithTimeout: fetch
|
|
19
|
-
} =
|
|
12
|
+
} = unsentRequest;
|
|
20
13
|
function getSlug(path) {
|
|
21
14
|
return path.split('/').pop().replace(/\.[^.]+$/, '');
|
|
22
15
|
}
|
|
23
|
-
class Algolia {
|
|
16
|
+
export default class Algolia {
|
|
24
17
|
constructor(config) {
|
|
25
18
|
this.config = config;
|
|
26
19
|
if (config.get('applicationID') == null || config.get('apiKey') == null) {
|
|
@@ -90,13 +83,13 @@ class Algolia {
|
|
|
90
83
|
}).then(response => {
|
|
91
84
|
const entries = response.results.map((result, index) => result.hits.map(hit => {
|
|
92
85
|
const slug = getSlug(hit.path);
|
|
93
|
-
return
|
|
86
|
+
return createEntry(collections[index], slug, hit.path, {
|
|
94
87
|
data: hit.data,
|
|
95
88
|
partial: true
|
|
96
89
|
});
|
|
97
90
|
}));
|
|
98
91
|
return {
|
|
99
|
-
entries: (
|
|
92
|
+
entries: _flatten(entries),
|
|
100
93
|
pagination: page
|
|
101
94
|
};
|
|
102
95
|
});
|
|
@@ -122,8 +115,8 @@ class Algolia {
|
|
|
122
115
|
}
|
|
123
116
|
}).then(response => {
|
|
124
117
|
const entries = response.hits.map(hit => {
|
|
125
|
-
const slug =
|
|
126
|
-
return
|
|
118
|
+
const slug = selectEntrySlug(collection, hit.path);
|
|
119
|
+
return createEntry(collection.get('name'), slug, hit.path, {
|
|
127
120
|
data: hit.data,
|
|
128
121
|
partial: true
|
|
129
122
|
});
|
|
@@ -163,8 +156,8 @@ class Algolia {
|
|
|
163
156
|
page = page + 1;
|
|
164
157
|
}
|
|
165
158
|
const entries = hits.map(hit => {
|
|
166
|
-
const slug =
|
|
167
|
-
return
|
|
159
|
+
const slug = selectEntrySlug(collection, hit.path);
|
|
160
|
+
return createEntry(collection.get('name'), slug, hit.path, {
|
|
168
161
|
data: hit.data,
|
|
169
162
|
partial: true
|
|
170
163
|
});
|
|
@@ -174,11 +167,10 @@ class Algolia {
|
|
|
174
167
|
getEntry(collection, slug) {
|
|
175
168
|
return this.searchBy('slug', collection.get('name'), slug).then(response => {
|
|
176
169
|
const entry = response.hits.filter(hit => hit.slug === slug)[0];
|
|
177
|
-
return
|
|
170
|
+
return createEntry(collection.get('name'), slug, entry.path, {
|
|
178
171
|
data: entry.data,
|
|
179
172
|
partial: true
|
|
180
173
|
});
|
|
181
174
|
});
|
|
182
175
|
}
|
|
183
|
-
}
|
|
184
|
-
exports.default = Algolia;
|
|
176
|
+
}
|
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _trimEnd2 = _interopRequireDefault(require("lodash/trimEnd"));
|
|
8
|
-
var _pickBy2 = _interopRequireDefault(require("lodash/pickBy"));
|
|
9
|
-
var _decapCmsLibUtil = require("decap-cms-lib-util");
|
|
10
|
-
var _urlHelper = require("../../../lib/urlHelper");
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
import _trimEnd from "lodash/trimEnd";
|
|
2
|
+
import _pickBy from "lodash/pickBy";
|
|
12
3
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
13
4
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
14
5
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
16
7
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
import { unsentRequest } from 'decap-cms-lib-util';
|
|
9
|
+
import { addParams } from '../../../lib/urlHelper';
|
|
17
10
|
const {
|
|
18
11
|
fetchWithTimeout: fetch
|
|
19
|
-
} =
|
|
20
|
-
class AssetStore {
|
|
12
|
+
} = unsentRequest;
|
|
13
|
+
export default class AssetStore {
|
|
21
14
|
constructor(config, getToken) {
|
|
22
15
|
this.config = config;
|
|
23
16
|
if (config.get('getSignedFormURL') == null) {
|
|
@@ -25,7 +18,7 @@ class AssetStore {
|
|
|
25
18
|
}
|
|
26
19
|
this.getToken = getToken;
|
|
27
20
|
this.shouldConfirmUpload = config.get('shouldConfirmUpload', false);
|
|
28
|
-
this.getSignedFormURL = (
|
|
21
|
+
this.getSignedFormURL = _trimEnd(config.get('getSignedFormURL'), '/');
|
|
29
22
|
}
|
|
30
23
|
parseJsonResponse(response) {
|
|
31
24
|
return response.json().then(json => {
|
|
@@ -74,12 +67,12 @@ class AssetStore {
|
|
|
74
67
|
return content;
|
|
75
68
|
}
|
|
76
69
|
async retrieve(query, page, privateUpload) {
|
|
77
|
-
const params = (
|
|
70
|
+
const params = _pickBy({
|
|
78
71
|
search: query,
|
|
79
72
|
page,
|
|
80
73
|
filter: privateUpload ? 'private' : 'public'
|
|
81
74
|
}, val => !!val);
|
|
82
|
-
const url =
|
|
75
|
+
const url = addParams(this.getSignedFormURL, params);
|
|
83
76
|
const token = await this.getToken();
|
|
84
77
|
const headers = {
|
|
85
78
|
'Content-Type': 'application/json',
|
|
@@ -171,5 +164,4 @@ class AssetStore {
|
|
|
171
164
|
throw error;
|
|
172
165
|
}
|
|
173
166
|
}
|
|
174
|
-
}
|
|
175
|
-
exports.default = AssetStore;
|
|
167
|
+
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = consoleError;
|
|
7
|
-
function consoleError(title, description) {
|
|
1
|
+
export default function consoleError(title, description) {
|
|
8
2
|
console.error(`%c ⛔ ${title}\n` + `%c${description}\n\n`, 'color: black; font-weight: bold; font-size: 16px; line-height: 50px;', 'color: black;');
|
|
9
3
|
}
|
|
@@ -1,38 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.commitMessageFormatter = commitMessageFormatter;
|
|
7
|
-
exports.folderFormatter = folderFormatter;
|
|
8
|
-
exports.getProcessSegment = getProcessSegment;
|
|
9
|
-
exports.prepareSlug = prepareSlug;
|
|
10
|
-
exports.previewUrlFormatter = previewUrlFormatter;
|
|
11
|
-
exports.slugFormatter = slugFormatter;
|
|
12
|
-
exports.summaryFormatter = summaryFormatter;
|
|
13
|
-
var _trimStart2 = _interopRequireDefault(require("lodash/trimStart"));
|
|
14
|
-
var _trimEnd2 = _interopRequireDefault(require("lodash/trimEnd"));
|
|
15
|
-
var _partialRight2 = _interopRequireDefault(require("lodash/partialRight"));
|
|
16
|
-
var _flow2 = _interopRequireDefault(require("lodash/flow"));
|
|
17
|
-
var _decapCmsLibWidgets = require("decap-cms-lib-widgets");
|
|
18
|
-
var _commonTags = require("common-tags");
|
|
19
|
-
var _collections = require("../reducers/collections");
|
|
20
|
-
var _urlHelper = require("./urlHelper");
|
|
21
|
-
var _collectionTypes = require("../constants/collectionTypes");
|
|
22
|
-
var _commitProps = require("../constants/commitProps");
|
|
23
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
import _trimStart from "lodash/trimStart";
|
|
2
|
+
import _trimEnd from "lodash/trimEnd";
|
|
3
|
+
import _partialRight from "lodash/partialRight";
|
|
4
|
+
import _flow from "lodash/flow";
|
|
24
5
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
25
6
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
26
7
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
8
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
28
9
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
|
+
import { stringTemplate } from 'decap-cms-lib-widgets';
|
|
11
|
+
import { stripIndent } from 'common-tags';
|
|
12
|
+
import { selectIdentifier, selectField, selectInferredField, getFileFromSlug } from '../reducers/collections';
|
|
13
|
+
import { sanitizeSlug } from './urlHelper';
|
|
14
|
+
import { FILES } from '../constants/collectionTypes';
|
|
15
|
+
import { COMMIT_AUTHOR, COMMIT_DATE } from '../constants/commitProps';
|
|
29
16
|
const {
|
|
30
17
|
compileStringTemplate,
|
|
31
18
|
parseDateFromEntry,
|
|
32
19
|
SLUG_MISSING_REQUIRED_DATE,
|
|
33
20
|
keyToPathArray,
|
|
34
21
|
addFileTemplateFields
|
|
35
|
-
} =
|
|
22
|
+
} = stringTemplate;
|
|
36
23
|
const commitMessageTemplates = {
|
|
37
24
|
create: 'Create {{collection}} “{{slug}}”',
|
|
38
25
|
update: 'Update {{collection}} “{{slug}}”',
|
|
@@ -42,7 +29,7 @@ const commitMessageTemplates = {
|
|
|
42
29
|
openAuthoring: '{{message}}'
|
|
43
30
|
};
|
|
44
31
|
const variableRegex = /\{\{([^}]+)\}\}/g;
|
|
45
|
-
function commitMessageFormatter(type, config, {
|
|
32
|
+
export function commitMessageFormatter(type, config, {
|
|
46
33
|
slug,
|
|
47
34
|
path,
|
|
48
35
|
collection,
|
|
@@ -85,7 +72,7 @@ function commitMessageFormatter(type, config, {
|
|
|
85
72
|
});
|
|
86
73
|
return message;
|
|
87
74
|
}
|
|
88
|
-
function prepareSlug(slug) {
|
|
75
|
+
export function prepareSlug(slug) {
|
|
89
76
|
return slug.trim()
|
|
90
77
|
// Convert slug to lower-case
|
|
91
78
|
.toLocaleLowerCase()
|
|
@@ -96,12 +83,12 @@ function prepareSlug(slug) {
|
|
|
96
83
|
// Replace periods with dashes.
|
|
97
84
|
.replace(/[.]/g, '-');
|
|
98
85
|
}
|
|
99
|
-
function getProcessSegment(slugConfig, ignoreValues) {
|
|
100
|
-
return value => ignoreValues && ignoreValues.includes(value) ? value : (
|
|
86
|
+
export function getProcessSegment(slugConfig, ignoreValues) {
|
|
87
|
+
return value => ignoreValues && ignoreValues.includes(value) ? value : _flow([value => String(value), prepareSlug, _partialRight(sanitizeSlug, slugConfig)])(value);
|
|
101
88
|
}
|
|
102
|
-
function slugFormatter(collection, entryData, slugConfig) {
|
|
89
|
+
export function slugFormatter(collection, entryData, slugConfig) {
|
|
103
90
|
const slugTemplate = collection.get('slug') || '{{slug}}';
|
|
104
|
-
const identifier = entryData.getIn(keyToPathArray(
|
|
91
|
+
const identifier = entryData.getIn(keyToPathArray(selectIdentifier(collection)));
|
|
105
92
|
if (!identifier) {
|
|
106
93
|
throw new Error('Collection must have a field name that is a valid entry identifier, or must have `identifier_field` set');
|
|
107
94
|
}
|
|
@@ -115,7 +102,7 @@ function slugFormatter(collection, entryData, slugConfig) {
|
|
|
115
102
|
return compileStringTemplate(pathTemplate, date, slug, entryData, value => value === slug ? value : processSegment(value));
|
|
116
103
|
}
|
|
117
104
|
}
|
|
118
|
-
function previewUrlFormatter(baseUrl, collection, slug, entry, slugConfig) {
|
|
105
|
+
export function previewUrlFormatter(baseUrl, collection, slug, entry, slugConfig) {
|
|
119
106
|
/**
|
|
120
107
|
* Preview URL can't be created without `baseUrl`. This makes preview URLs
|
|
121
108
|
* optional for backends that don't support them.
|
|
@@ -123,9 +110,9 @@ function previewUrlFormatter(baseUrl, collection, slug, entry, slugConfig) {
|
|
|
123
110
|
if (!baseUrl) {
|
|
124
111
|
return;
|
|
125
112
|
}
|
|
126
|
-
const basePath = (
|
|
127
|
-
const isFileCollection = collection.get('type') ===
|
|
128
|
-
const file = isFileCollection ?
|
|
113
|
+
const basePath = _trimEnd(baseUrl, '/');
|
|
114
|
+
const isFileCollection = collection.get('type') === FILES;
|
|
115
|
+
const file = isFileCollection ? getFileFromSlug(collection, entry.get('slug')) : undefined;
|
|
129
116
|
function getPathTemplate() {
|
|
130
117
|
var _file$get;
|
|
131
118
|
return (_file$get = file === null || file === void 0 ? void 0 : file.get('preview_path')) !== null && _file$get !== void 0 ? _file$get : collection.get('preview_path');
|
|
@@ -150,7 +137,7 @@ function previewUrlFormatter(baseUrl, collection, slug, entry, slugConfig) {
|
|
|
150
137
|
}
|
|
151
138
|
let fields = entry.get('data');
|
|
152
139
|
fields = addFileTemplateFields(entry.get('path'), fields, collection.get('folder'));
|
|
153
|
-
const dateFieldName = getDateField() ||
|
|
140
|
+
const dateFieldName = getDateField() || selectInferredField(collection, 'date');
|
|
154
141
|
const date = parseDateFromEntry(entry, dateFieldName);
|
|
155
142
|
|
|
156
143
|
// Prepare and sanitize slug variables only, leave the rest of the
|
|
@@ -164,7 +151,7 @@ function previewUrlFormatter(baseUrl, collection, slug, entry, slugConfig) {
|
|
|
164
151
|
// 1. Date is invalid (according to DayJs), and
|
|
165
152
|
// 2. A date expression (eg. `{{year}}`) is used in `preview_path`
|
|
166
153
|
if (err.name === SLUG_MISSING_REQUIRED_DATE) {
|
|
167
|
-
console.error(
|
|
154
|
+
console.error(stripIndent`
|
|
168
155
|
Collection "${collection.get('name')}" configuration error:
|
|
169
156
|
\`preview_path_date_field\` must be a field with a valid date. Ignoring \`preview_path\`.
|
|
170
157
|
`);
|
|
@@ -172,32 +159,32 @@ function previewUrlFormatter(baseUrl, collection, slug, entry, slugConfig) {
|
|
|
172
159
|
}
|
|
173
160
|
throw err;
|
|
174
161
|
}
|
|
175
|
-
const previewPath = (
|
|
162
|
+
const previewPath = _trimStart(compiledPath, ' /');
|
|
176
163
|
return `${basePath}/${previewPath}`;
|
|
177
164
|
}
|
|
178
|
-
function summaryFormatter(summaryTemplate, entry, collection) {
|
|
165
|
+
export function summaryFormatter(summaryTemplate, entry, collection) {
|
|
179
166
|
let entryData = entry.get('data');
|
|
180
|
-
const date = parseDateFromEntry(entry,
|
|
181
|
-
const identifier = entryData.getIn(keyToPathArray(
|
|
167
|
+
const date = parseDateFromEntry(entry, selectInferredField(collection, 'date')) || null;
|
|
168
|
+
const identifier = entryData.getIn(keyToPathArray(selectIdentifier(collection)));
|
|
182
169
|
entryData = addFileTemplateFields(entry.get('path'), entryData, collection.get('folder'));
|
|
183
170
|
// allow commit information in summary template
|
|
184
|
-
if (entry.get('author') && !
|
|
185
|
-
entryData = entryData.set(
|
|
171
|
+
if (entry.get('author') && !selectField(collection, COMMIT_AUTHOR)) {
|
|
172
|
+
entryData = entryData.set(COMMIT_AUTHOR, entry.get('author'));
|
|
186
173
|
}
|
|
187
|
-
if (entry.get('updatedOn') && !
|
|
188
|
-
entryData = entryData.set(
|
|
174
|
+
if (entry.get('updatedOn') && !selectField(collection, COMMIT_DATE)) {
|
|
175
|
+
entryData = entryData.set(COMMIT_DATE, entry.get('updatedOn'));
|
|
189
176
|
}
|
|
190
177
|
const summary = compileStringTemplate(summaryTemplate, date, identifier, entryData);
|
|
191
178
|
return summary;
|
|
192
179
|
}
|
|
193
|
-
function folderFormatter(folderTemplate, entry, collection, defaultFolder, folderKey, slugConfig) {
|
|
180
|
+
export function folderFormatter(folderTemplate, entry, collection, defaultFolder, folderKey, slugConfig) {
|
|
194
181
|
if (!entry || !entry.get('data')) {
|
|
195
182
|
return folderTemplate;
|
|
196
183
|
}
|
|
197
184
|
let fields = entry.get('data').set(folderKey, defaultFolder);
|
|
198
185
|
fields = addFileTemplateFields(entry.get('path'), fields, collection.get('folder'));
|
|
199
|
-
const date = parseDateFromEntry(entry,
|
|
200
|
-
const identifier = fields.getIn(keyToPathArray(
|
|
186
|
+
const date = parseDateFromEntry(entry, selectInferredField(collection, 'date')) || null;
|
|
187
|
+
const identifier = fields.getIn(keyToPathArray(selectIdentifier(collection)));
|
|
201
188
|
const processSegment = getProcessSegment(slugConfig, [defaultFolder, fields.get('dirname')]);
|
|
202
189
|
const mediaFolder = compileStringTemplate(folderTemplate, date, identifier, fields, processSegment);
|
|
203
190
|
return mediaFolder;
|
package/dist/esm/lib/i18n.js
CHANGED
|
@@ -1,59 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.I18N_STRUCTURE = exports.I18N_FIELD = exports.I18N = void 0;
|
|
7
|
-
exports.duplicateDefaultI18nFields = duplicateDefaultI18nFields;
|
|
8
|
-
exports.duplicateI18nFields = duplicateI18nFields;
|
|
9
|
-
exports.formatI18nBackup = formatI18nBackup;
|
|
10
|
-
exports.getDataPath = getDataPath;
|
|
11
|
-
exports.getFilePath = getFilePath;
|
|
12
|
-
exports.getFilePaths = getFilePaths;
|
|
13
|
-
exports.getI18nBackup = getI18nBackup;
|
|
14
|
-
exports.getI18nDataFiles = getI18nDataFiles;
|
|
15
|
-
exports.getI18nEntry = getI18nEntry;
|
|
16
|
-
exports.getI18nFiles = getI18nFiles;
|
|
17
|
-
exports.getI18nFilesDepth = getI18nFilesDepth;
|
|
18
|
-
exports.getI18nInfo = getI18nInfo;
|
|
19
|
-
exports.getLocaleDataPath = getLocaleDataPath;
|
|
20
|
-
exports.getLocaleFromPath = getLocaleFromPath;
|
|
21
|
-
exports.getPreviewEntry = getPreviewEntry;
|
|
22
|
-
exports.groupEntries = groupEntries;
|
|
23
|
-
exports.hasI18n = hasI18n;
|
|
24
|
-
exports.isFieldDuplicate = isFieldDuplicate;
|
|
25
|
-
exports.isFieldHidden = isFieldHidden;
|
|
26
|
-
exports.isFieldTranslatable = isFieldTranslatable;
|
|
27
|
-
exports.normalizeFilePath = normalizeFilePath;
|
|
28
|
-
exports.serializeI18n = serializeI18n;
|
|
29
|
-
var _escapeRegExp2 = _interopRequireDefault(require("lodash/escapeRegExp"));
|
|
30
|
-
var _groupBy2 = _interopRequireDefault(require("lodash/groupBy"));
|
|
31
|
-
var _set2 = _interopRequireDefault(require("lodash/set"));
|
|
32
|
-
var _immutable = require("immutable");
|
|
33
|
-
var _collections = require("../reducers/collections");
|
|
34
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
import _escapeRegExp from "lodash/escapeRegExp";
|
|
2
|
+
import _groupBy from "lodash/groupBy";
|
|
3
|
+
import _set from "lodash/set";
|
|
35
4
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
36
5
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
37
6
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
38
7
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
39
8
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
40
|
-
|
|
41
|
-
|
|
9
|
+
import { Map, List } from 'immutable';
|
|
10
|
+
import { selectEntrySlug } from '../reducers/collections';
|
|
11
|
+
export const I18N = 'i18n';
|
|
12
|
+
export let I18N_STRUCTURE = /*#__PURE__*/function (I18N_STRUCTURE) {
|
|
42
13
|
I18N_STRUCTURE["MULTIPLE_FOLDERS"] = "multiple_folders";
|
|
43
14
|
I18N_STRUCTURE["MULTIPLE_FILES"] = "multiple_files";
|
|
44
15
|
I18N_STRUCTURE["SINGLE_FILE"] = "single_file";
|
|
45
16
|
return I18N_STRUCTURE;
|
|
46
17
|
}({});
|
|
47
|
-
let I18N_FIELD =
|
|
18
|
+
export let I18N_FIELD = /*#__PURE__*/function (I18N_FIELD) {
|
|
48
19
|
I18N_FIELD["TRANSLATE"] = "translate";
|
|
49
20
|
I18N_FIELD["DUPLICATE"] = "duplicate";
|
|
50
21
|
I18N_FIELD["NONE"] = "none";
|
|
51
22
|
return I18N_FIELD;
|
|
52
23
|
}({});
|
|
53
|
-
function hasI18n(collection) {
|
|
24
|
+
export function hasI18n(collection) {
|
|
54
25
|
return collection.has(I18N);
|
|
55
26
|
}
|
|
56
|
-
function getI18nInfo(collection) {
|
|
27
|
+
export function getI18nInfo(collection) {
|
|
57
28
|
if (!hasI18n(collection)) {
|
|
58
29
|
return {};
|
|
59
30
|
}
|
|
@@ -68,7 +39,7 @@ function getI18nInfo(collection) {
|
|
|
68
39
|
defaultLocale
|
|
69
40
|
};
|
|
70
41
|
}
|
|
71
|
-
function getI18nFilesDepth(collection, depth) {
|
|
42
|
+
export function getI18nFilesDepth(collection, depth) {
|
|
72
43
|
const {
|
|
73
44
|
structure
|
|
74
45
|
} = getI18nInfo(collection);
|
|
@@ -77,37 +48,37 @@ function getI18nFilesDepth(collection, depth) {
|
|
|
77
48
|
}
|
|
78
49
|
return depth;
|
|
79
50
|
}
|
|
80
|
-
function isFieldTranslatable(field, locale, defaultLocale) {
|
|
51
|
+
export function isFieldTranslatable(field, locale, defaultLocale) {
|
|
81
52
|
const isTranslatable = locale !== defaultLocale && field.get(I18N) === I18N_FIELD.TRANSLATE;
|
|
82
53
|
return isTranslatable;
|
|
83
54
|
}
|
|
84
|
-
function isFieldDuplicate(field, locale, defaultLocale) {
|
|
55
|
+
export function isFieldDuplicate(field, locale, defaultLocale) {
|
|
85
56
|
const isDuplicate = locale !== defaultLocale && field.get(I18N) === I18N_FIELD.DUPLICATE;
|
|
86
57
|
return isDuplicate;
|
|
87
58
|
}
|
|
88
|
-
function isFieldHidden(field, locale, defaultLocale) {
|
|
59
|
+
export function isFieldHidden(field, locale, defaultLocale) {
|
|
89
60
|
const isHidden = locale !== defaultLocale && field.get(I18N) === I18N_FIELD.NONE;
|
|
90
61
|
return isHidden;
|
|
91
62
|
}
|
|
92
|
-
function getLocaleDataPath(locale) {
|
|
63
|
+
export function getLocaleDataPath(locale) {
|
|
93
64
|
return [I18N, locale, 'data'];
|
|
94
65
|
}
|
|
95
|
-
function getDataPath(locale, defaultLocale) {
|
|
66
|
+
export function getDataPath(locale, defaultLocale) {
|
|
96
67
|
const dataPath = locale !== defaultLocale ? getLocaleDataPath(locale) : ['data'];
|
|
97
68
|
return dataPath;
|
|
98
69
|
}
|
|
99
|
-
function getFilePath(structure, extension, path, slug, locale) {
|
|
70
|
+
export function getFilePath(structure, extension, path, slug, locale) {
|
|
100
71
|
switch (structure) {
|
|
101
72
|
case I18N_STRUCTURE.MULTIPLE_FOLDERS:
|
|
102
73
|
return path.replace(`/${slug}`, `/${locale}/${slug}`);
|
|
103
74
|
case I18N_STRUCTURE.MULTIPLE_FILES:
|
|
104
|
-
return path.replace(new RegExp(`${(
|
|
75
|
+
return path.replace(new RegExp(`${_escapeRegExp(extension)}$`), `${locale}.${extension}`);
|
|
105
76
|
case I18N_STRUCTURE.SINGLE_FILE:
|
|
106
77
|
default:
|
|
107
78
|
return path;
|
|
108
79
|
}
|
|
109
80
|
}
|
|
110
|
-
function getLocaleFromPath(structure, extension, path) {
|
|
81
|
+
export function getLocaleFromPath(structure, extension, path) {
|
|
111
82
|
switch (structure) {
|
|
112
83
|
case I18N_STRUCTURE.MULTIPLE_FOLDERS:
|
|
113
84
|
{
|
|
@@ -127,7 +98,7 @@ function getLocaleFromPath(structure, extension, path) {
|
|
|
127
98
|
return '';
|
|
128
99
|
}
|
|
129
100
|
}
|
|
130
|
-
function getFilePaths(collection, extension, path, slug) {
|
|
101
|
+
export function getFilePaths(collection, extension, path, slug) {
|
|
131
102
|
const {
|
|
132
103
|
structure,
|
|
133
104
|
locales
|
|
@@ -138,7 +109,7 @@ function getFilePaths(collection, extension, path, slug) {
|
|
|
138
109
|
const paths = locales.map(locale => getFilePath(structure, extension, path, slug, locale));
|
|
139
110
|
return paths;
|
|
140
111
|
}
|
|
141
|
-
function normalizeFilePath(structure, path, locale) {
|
|
112
|
+
export function normalizeFilePath(structure, path, locale) {
|
|
142
113
|
switch (structure) {
|
|
143
114
|
case I18N_STRUCTURE.MULTIPLE_FOLDERS:
|
|
144
115
|
return path.replace(`${locale}/`, '');
|
|
@@ -149,7 +120,7 @@ function normalizeFilePath(structure, path, locale) {
|
|
|
149
120
|
return path;
|
|
150
121
|
}
|
|
151
122
|
}
|
|
152
|
-
function getI18nFiles(collection, extension, entryDraft, entryToRaw, path, slug, newPath) {
|
|
123
|
+
export function getI18nFiles(collection, extension, entryDraft, entryToRaw, path, slug, newPath) {
|
|
153
124
|
const {
|
|
154
125
|
structure,
|
|
155
126
|
defaultLocale,
|
|
@@ -159,7 +130,7 @@ function getI18nFiles(collection, extension, entryDraft, entryToRaw, path, slug,
|
|
|
159
130
|
const data = locales.reduce((map, locale) => {
|
|
160
131
|
const dataPath = getDataPath(locale, defaultLocale);
|
|
161
132
|
return map.set(locale, entryDraft.getIn(dataPath));
|
|
162
|
-
},
|
|
133
|
+
}, Map({}));
|
|
163
134
|
const draft = entryDraft.set('data', data);
|
|
164
135
|
return [_objectSpread({
|
|
165
136
|
path: getFilePath(structure, extension, path, slug, locales[0]),
|
|
@@ -182,7 +153,7 @@ function getI18nFiles(collection, extension, entryDraft, entryToRaw, path, slug,
|
|
|
182
153
|
}).filter(dataFile => dataFile.raw);
|
|
183
154
|
return dataFiles;
|
|
184
155
|
}
|
|
185
|
-
function getI18nBackup(collection, entry, entryToRaw) {
|
|
156
|
+
export function getI18nBackup(collection, entry, entryToRaw) {
|
|
186
157
|
const {
|
|
187
158
|
locales,
|
|
188
159
|
defaultLocale
|
|
@@ -202,7 +173,7 @@ function getI18nBackup(collection, entry, entryToRaw) {
|
|
|
202
173
|
}, {});
|
|
203
174
|
return i18nBackup;
|
|
204
175
|
}
|
|
205
|
-
function formatI18nBackup(i18nBackup, formatRawData) {
|
|
176
|
+
export function formatI18nBackup(i18nBackup, formatRawData) {
|
|
206
177
|
const i18n = Object.entries(i18nBackup).reduce((acc, [locale, {
|
|
207
178
|
raw
|
|
208
179
|
}]) => {
|
|
@@ -226,10 +197,10 @@ function mergeValues(collection, structure, defaultLocale, values) {
|
|
|
226
197
|
value
|
|
227
198
|
}) => {
|
|
228
199
|
const dataPath = getLocaleDataPath(locale);
|
|
229
|
-
return (
|
|
200
|
+
return _set(acc, dataPath, value.data);
|
|
230
201
|
}, {});
|
|
231
202
|
const path = normalizeFilePath(structure, defaultEntry.value.path, defaultLocale);
|
|
232
|
-
const slug =
|
|
203
|
+
const slug = selectEntrySlug(collection, path);
|
|
233
204
|
const entryValue = _objectSpread(_objectSpread(_objectSpread({}, defaultEntry.value), {}, {
|
|
234
205
|
raw: ''
|
|
235
206
|
}, i18n), {}, {
|
|
@@ -256,7 +227,7 @@ function mergeSingleFileValue(entryValue, defaultLocale, locales) {
|
|
|
256
227
|
raw: ''
|
|
257
228
|
});
|
|
258
229
|
}
|
|
259
|
-
async function getI18nEntry(collection, extension, path, slug, getEntryValue) {
|
|
230
|
+
export async function getI18nEntry(collection, extension, path, slug, getEntryValue) {
|
|
260
231
|
const {
|
|
261
232
|
structure,
|
|
262
233
|
locales,
|
|
@@ -279,7 +250,7 @@ async function getI18nEntry(collection, extension, path, slug, getEntryValue) {
|
|
|
279
250
|
}
|
|
280
251
|
return entryValue;
|
|
281
252
|
}
|
|
282
|
-
function groupEntries(collection, extension, entries) {
|
|
253
|
+
export function groupEntries(collection, extension, entries) {
|
|
283
254
|
const {
|
|
284
255
|
structure,
|
|
285
256
|
defaultLocale,
|
|
@@ -288,7 +259,7 @@ function groupEntries(collection, extension, entries) {
|
|
|
288
259
|
if (structure === I18N_STRUCTURE.SINGLE_FILE) {
|
|
289
260
|
return entries.map(e => mergeSingleFileValue(e, defaultLocale, locales));
|
|
290
261
|
}
|
|
291
|
-
const grouped = (
|
|
262
|
+
const grouped = _groupBy(entries.map(e => ({
|
|
292
263
|
locale: getLocaleFromPath(structure, extension, e.path),
|
|
293
264
|
value: e
|
|
294
265
|
})), ({
|
|
@@ -303,7 +274,7 @@ function groupEntries(collection, extension, entries) {
|
|
|
303
274
|
}, []);
|
|
304
275
|
return groupedEntries;
|
|
305
276
|
}
|
|
306
|
-
function getI18nDataFiles(collection, extension, path, slug, diffFiles) {
|
|
277
|
+
export function getI18nDataFiles(collection, extension, path, slug, diffFiles) {
|
|
307
278
|
const {
|
|
308
279
|
structure
|
|
309
280
|
} = getI18nInfo(collection);
|
|
@@ -327,7 +298,7 @@ function getI18nDataFiles(collection, extension, path, slug, diffFiles) {
|
|
|
327
298
|
}
|
|
328
299
|
|
|
329
300
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
330
|
-
function duplicateDefaultI18nFields(collection, dataFields) {
|
|
301
|
+
export function duplicateDefaultI18nFields(collection, dataFields) {
|
|
331
302
|
const {
|
|
332
303
|
locales,
|
|
333
304
|
defaultLocale
|
|
@@ -337,19 +308,19 @@ function duplicateDefaultI18nFields(collection, dataFields) {
|
|
|
337
308
|
}]));
|
|
338
309
|
return i18nFields;
|
|
339
310
|
}
|
|
340
|
-
function duplicateI18nFields(entryDraft, field, locales, defaultLocale, fieldPath = [field.get('name')]) {
|
|
311
|
+
export function duplicateI18nFields(entryDraft, field, locales, defaultLocale, fieldPath = [field.get('name')]) {
|
|
341
312
|
const value = entryDraft.getIn(['entry', 'data', ...fieldPath]);
|
|
342
313
|
if (field.get(I18N) === I18N_FIELD.DUPLICATE) {
|
|
343
314
|
locales.filter(l => l !== defaultLocale).forEach(l => {
|
|
344
315
|
entryDraft = entryDraft.setIn(['entry', ...getDataPath(l, defaultLocale), ...fieldPath], value);
|
|
345
316
|
});
|
|
346
317
|
}
|
|
347
|
-
if (field.has('field') && !
|
|
318
|
+
if (field.has('field') && !List.isList(value)) {
|
|
348
319
|
const fields = [field.get('field')];
|
|
349
320
|
fields.forEach(field => {
|
|
350
321
|
entryDraft = duplicateI18nFields(entryDraft, field, locales, defaultLocale, [...fieldPath, field.get('name')]);
|
|
351
322
|
});
|
|
352
|
-
} else if (field.has('fields') && !
|
|
323
|
+
} else if (field.has('fields') && !List.isList(value)) {
|
|
353
324
|
const fields = field.get('fields').toArray();
|
|
354
325
|
fields.forEach(field => {
|
|
355
326
|
entryDraft = duplicateI18nFields(entryDraft, field, locales, defaultLocale, [...fieldPath, field.get('name')]);
|
|
@@ -357,13 +328,13 @@ function duplicateI18nFields(entryDraft, field, locales, defaultLocale, fieldPat
|
|
|
357
328
|
}
|
|
358
329
|
return entryDraft;
|
|
359
330
|
}
|
|
360
|
-
function getPreviewEntry(entry, locale, defaultLocale) {
|
|
331
|
+
export function getPreviewEntry(entry, locale, defaultLocale) {
|
|
361
332
|
if (locale === defaultLocale) {
|
|
362
333
|
return entry;
|
|
363
334
|
}
|
|
364
335
|
return entry.set('data', entry.getIn([I18N, locale, 'data']));
|
|
365
336
|
}
|
|
366
|
-
function serializeI18n(collection, entry,
|
|
337
|
+
export function serializeI18n(collection, entry,
|
|
367
338
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
368
339
|
serializeValues) {
|
|
369
340
|
const {
|
package/dist/esm/lib/phrases.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.getPhrases = getPhrases;
|
|
7
|
-
var _merge2 = _interopRequireDefault(require("lodash/merge"));
|
|
8
|
-
var _registry = require("./registry");
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
function getPhrases(locale) {
|
|
11
|
-
const phrases = (0, _merge2.default)({}, (0, _registry.getLocale)('en'), (0, _registry.getLocale)(locale));
|
|
1
|
+
import _merge from "lodash/merge";
|
|
2
|
+
import { getLocale } from './registry';
|
|
3
|
+
export function getPhrases(locale) {
|
|
4
|
+
const phrases = _merge({}, getLocale('en'), getLocale(locale));
|
|
12
5
|
return phrases;
|
|
13
6
|
}
|