This commit is contained in:
9
node_modules/decap-cms-core/dist/esm/lib/consoleError.js
generated
vendored
Normal file
9
node_modules/decap-cms-core/dist/esm/lib/consoleError.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = consoleError;
|
||||
function consoleError(title, description) {
|
||||
console.error(`%c ⛔ ${title}\n` + `%c${description}\n\n`, 'color: black; font-weight: bold; font-size: 16px; line-height: 50px;', 'color: black;');
|
||||
}
|
||||
204
node_modules/decap-cms-core/dist/esm/lib/formatters.js
generated
vendored
Normal file
204
node_modules/decap-cms-core/dist/esm/lib/formatters.js
generated
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.commitMessageFormatter = commitMessageFormatter;
|
||||
exports.folderFormatter = folderFormatter;
|
||||
exports.getProcessSegment = getProcessSegment;
|
||||
exports.prepareSlug = prepareSlug;
|
||||
exports.previewUrlFormatter = previewUrlFormatter;
|
||||
exports.slugFormatter = slugFormatter;
|
||||
exports.summaryFormatter = summaryFormatter;
|
||||
var _trimStart2 = _interopRequireDefault(require("lodash/trimStart"));
|
||||
var _trimEnd2 = _interopRequireDefault(require("lodash/trimEnd"));
|
||||
var _partialRight2 = _interopRequireDefault(require("lodash/partialRight"));
|
||||
var _flow2 = _interopRequireDefault(require("lodash/flow"));
|
||||
var _decapCmsLibWidgets = require("decap-cms-lib-widgets");
|
||||
var _commonTags = require("common-tags");
|
||||
var _collections = require("../reducers/collections");
|
||||
var _urlHelper = require("./urlHelper");
|
||||
var _collectionTypes = require("../constants/collectionTypes");
|
||||
var _commitProps = require("../constants/commitProps");
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
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; }
|
||||
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; }
|
||||
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; }
|
||||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
||||
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); }
|
||||
const {
|
||||
compileStringTemplate,
|
||||
parseDateFromEntry,
|
||||
SLUG_MISSING_REQUIRED_DATE,
|
||||
keyToPathArray,
|
||||
addFileTemplateFields
|
||||
} = _decapCmsLibWidgets.stringTemplate;
|
||||
const commitMessageTemplates = {
|
||||
create: 'Create {{collection}} “{{slug}}”',
|
||||
update: 'Update {{collection}} “{{slug}}”',
|
||||
delete: 'Delete {{collection}} “{{slug}}”',
|
||||
uploadMedia: 'Upload “{{path}}”',
|
||||
deleteMedia: 'Delete “{{path}}”',
|
||||
openAuthoring: '{{message}}'
|
||||
};
|
||||
const variableRegex = /\{\{([^}]+)\}\}/g;
|
||||
function commitMessageFormatter(type, config, {
|
||||
slug,
|
||||
path,
|
||||
collection,
|
||||
authorLogin,
|
||||
authorName
|
||||
}, isOpenAuthoring) {
|
||||
const templates = _objectSpread(_objectSpread({}, commitMessageTemplates), config.backend.commit_messages || {});
|
||||
const commitMessage = templates[type].replace(variableRegex, (_, variable) => {
|
||||
switch (variable) {
|
||||
case 'slug':
|
||||
return slug || '';
|
||||
case 'path':
|
||||
return path || '';
|
||||
case 'collection':
|
||||
return collection ? collection.get('label_singular') || collection.get('label') : '';
|
||||
case 'author-login':
|
||||
return authorLogin || '';
|
||||
case 'author-name':
|
||||
return authorName || '';
|
||||
default:
|
||||
console.warn(`Ignoring unknown variable “${variable}” in commit message template.`);
|
||||
return '';
|
||||
}
|
||||
});
|
||||
if (!isOpenAuthoring) {
|
||||
return commitMessage;
|
||||
}
|
||||
const message = templates.openAuthoring.replace(variableRegex, (_, variable) => {
|
||||
switch (variable) {
|
||||
case 'message':
|
||||
return commitMessage;
|
||||
case 'author-login':
|
||||
return authorLogin || '';
|
||||
case 'author-name':
|
||||
return authorName || '';
|
||||
default:
|
||||
console.warn(`Ignoring unknown variable “${variable}” in open authoring message template.`);
|
||||
return '';
|
||||
}
|
||||
});
|
||||
return message;
|
||||
}
|
||||
function prepareSlug(slug) {
|
||||
return slug.trim()
|
||||
// Convert slug to lower-case
|
||||
.toLocaleLowerCase()
|
||||
|
||||
// Remove single quotes.
|
||||
.replace(/[']/g, '')
|
||||
|
||||
// Replace periods with dashes.
|
||||
.replace(/[.]/g, '-');
|
||||
}
|
||||
function getProcessSegment(slugConfig, ignoreValues) {
|
||||
return value => ignoreValues && ignoreValues.includes(value) ? value : (0, _flow2.default)([value => String(value), prepareSlug, (0, _partialRight2.default)(_urlHelper.sanitizeSlug, slugConfig)])(value);
|
||||
}
|
||||
function slugFormatter(collection, entryData, slugConfig) {
|
||||
const slugTemplate = collection.get('slug') || '{{slug}}';
|
||||
const identifier = entryData.getIn(keyToPathArray((0, _collections.selectIdentifier)(collection)));
|
||||
if (!identifier) {
|
||||
throw new Error('Collection must have a field name that is a valid entry identifier, or must have `identifier_field` set');
|
||||
}
|
||||
const processSegment = getProcessSegment(slugConfig);
|
||||
const date = new Date();
|
||||
const slug = compileStringTemplate(slugTemplate, date, identifier, entryData, processSegment);
|
||||
if (!collection.has('path')) {
|
||||
return slug;
|
||||
} else {
|
||||
const pathTemplate = prepareSlug(collection.get('path'));
|
||||
return compileStringTemplate(pathTemplate, date, slug, entryData, value => value === slug ? value : processSegment(value));
|
||||
}
|
||||
}
|
||||
function previewUrlFormatter(baseUrl, collection, slug, entry, slugConfig) {
|
||||
/**
|
||||
* Preview URL can't be created without `baseUrl`. This makes preview URLs
|
||||
* optional for backends that don't support them.
|
||||
*/
|
||||
if (!baseUrl) {
|
||||
return;
|
||||
}
|
||||
const basePath = (0, _trimEnd2.default)(baseUrl, '/');
|
||||
const isFileCollection = collection.get('type') === _collectionTypes.FILES;
|
||||
const file = isFileCollection ? (0, _collections.getFileFromSlug)(collection, entry.get('slug')) : undefined;
|
||||
function getPathTemplate() {
|
||||
var _file$get;
|
||||
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');
|
||||
}
|
||||
function getDateField() {
|
||||
var _file$get2;
|
||||
return (_file$get2 = file === null || file === void 0 ? void 0 : file.get('preview_path_date_field')) !== null && _file$get2 !== void 0 ? _file$get2 : collection.get('preview_path_date_field');
|
||||
}
|
||||
|
||||
/**
|
||||
* If a `previewPath` is provided for the collection/file, use it to construct the
|
||||
* URL path.
|
||||
*/
|
||||
const pathTemplate = getPathTemplate();
|
||||
|
||||
/**
|
||||
* Without a `previewPath` for the collection/file (via config), the preview URL
|
||||
* will be the URL provided by the backend.
|
||||
*/
|
||||
if (!pathTemplate) {
|
||||
return baseUrl;
|
||||
}
|
||||
let fields = entry.get('data');
|
||||
fields = addFileTemplateFields(entry.get('path'), fields, collection.get('folder'));
|
||||
const dateFieldName = getDateField() || (0, _collections.selectInferredField)(collection, 'date');
|
||||
const date = parseDateFromEntry(entry, dateFieldName);
|
||||
|
||||
// Prepare and sanitize slug variables only, leave the rest of the
|
||||
// `preview_path` template as is.
|
||||
const processSegment = getProcessSegment(slugConfig, [fields.get('dirname')]);
|
||||
let compiledPath;
|
||||
try {
|
||||
compiledPath = compileStringTemplate(pathTemplate, date, slug, fields, processSegment);
|
||||
} catch (err) {
|
||||
// Print an error and ignore `preview_path` if both:
|
||||
// 1. Date is invalid (according to DayJs), and
|
||||
// 2. A date expression (eg. `{{year}}`) is used in `preview_path`
|
||||
if (err.name === SLUG_MISSING_REQUIRED_DATE) {
|
||||
console.error((0, _commonTags.stripIndent)`
|
||||
Collection "${collection.get('name')}" configuration error:
|
||||
\`preview_path_date_field\` must be a field with a valid date. Ignoring \`preview_path\`.
|
||||
`);
|
||||
return basePath;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
const previewPath = (0, _trimStart2.default)(compiledPath, ' /');
|
||||
return `${basePath}/${previewPath}`;
|
||||
}
|
||||
function summaryFormatter(summaryTemplate, entry, collection) {
|
||||
let entryData = entry.get('data');
|
||||
const date = parseDateFromEntry(entry, (0, _collections.selectInferredField)(collection, 'date')) || null;
|
||||
const identifier = entryData.getIn(keyToPathArray((0, _collections.selectIdentifier)(collection)));
|
||||
entryData = addFileTemplateFields(entry.get('path'), entryData, collection.get('folder'));
|
||||
// allow commit information in summary template
|
||||
if (entry.get('author') && !(0, _collections.selectField)(collection, _commitProps.COMMIT_AUTHOR)) {
|
||||
entryData = entryData.set(_commitProps.COMMIT_AUTHOR, entry.get('author'));
|
||||
}
|
||||
if (entry.get('updatedOn') && !(0, _collections.selectField)(collection, _commitProps.COMMIT_DATE)) {
|
||||
entryData = entryData.set(_commitProps.COMMIT_DATE, entry.get('updatedOn'));
|
||||
}
|
||||
const summary = compileStringTemplate(summaryTemplate, date, identifier, entryData);
|
||||
return summary;
|
||||
}
|
||||
function folderFormatter(folderTemplate, entry, collection, defaultFolder, folderKey, slugConfig) {
|
||||
if (!entry || !entry.get('data')) {
|
||||
return folderTemplate;
|
||||
}
|
||||
let fields = entry.get('data').set(folderKey, defaultFolder);
|
||||
fields = addFileTemplateFields(entry.get('path'), fields, collection.get('folder'));
|
||||
const date = parseDateFromEntry(entry, (0, _collections.selectInferredField)(collection, 'date')) || null;
|
||||
const identifier = fields.getIn(keyToPathArray((0, _collections.selectIdentifier)(collection)));
|
||||
const processSegment = getProcessSegment(slugConfig, [defaultFolder, fields.get('dirname')]);
|
||||
const mediaFolder = compileStringTemplate(folderTemplate, date, identifier, fields, processSegment);
|
||||
return mediaFolder;
|
||||
}
|
||||
378
node_modules/decap-cms-core/dist/esm/lib/i18n.js
generated
vendored
Normal file
378
node_modules/decap-cms-core/dist/esm/lib/i18n.js
generated
vendored
Normal file
@@ -0,0 +1,378 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.I18N_STRUCTURE = exports.I18N_FIELD = exports.I18N = void 0;
|
||||
exports.duplicateDefaultI18nFields = duplicateDefaultI18nFields;
|
||||
exports.duplicateI18nFields = duplicateI18nFields;
|
||||
exports.formatI18nBackup = formatI18nBackup;
|
||||
exports.getDataPath = getDataPath;
|
||||
exports.getFilePath = getFilePath;
|
||||
exports.getFilePaths = getFilePaths;
|
||||
exports.getI18nBackup = getI18nBackup;
|
||||
exports.getI18nDataFiles = getI18nDataFiles;
|
||||
exports.getI18nEntry = getI18nEntry;
|
||||
exports.getI18nFiles = getI18nFiles;
|
||||
exports.getI18nFilesDepth = getI18nFilesDepth;
|
||||
exports.getI18nInfo = getI18nInfo;
|
||||
exports.getLocaleDataPath = getLocaleDataPath;
|
||||
exports.getLocaleFromPath = getLocaleFromPath;
|
||||
exports.getPreviewEntry = getPreviewEntry;
|
||||
exports.groupEntries = groupEntries;
|
||||
exports.hasI18n = hasI18n;
|
||||
exports.isFieldDuplicate = isFieldDuplicate;
|
||||
exports.isFieldHidden = isFieldHidden;
|
||||
exports.isFieldTranslatable = isFieldTranslatable;
|
||||
exports.normalizeFilePath = normalizeFilePath;
|
||||
exports.serializeI18n = serializeI18n;
|
||||
var _escapeRegExp2 = _interopRequireDefault(require("lodash/escapeRegExp"));
|
||||
var _groupBy2 = _interopRequireDefault(require("lodash/groupBy"));
|
||||
var _set2 = _interopRequireDefault(require("lodash/set"));
|
||||
var _immutable = require("immutable");
|
||||
var _collections = require("../reducers/collections");
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
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; }
|
||||
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; }
|
||||
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; }
|
||||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
||||
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); }
|
||||
const I18N = exports.I18N = 'i18n';
|
||||
let I18N_STRUCTURE = exports.I18N_STRUCTURE = /*#__PURE__*/function (I18N_STRUCTURE) {
|
||||
I18N_STRUCTURE["MULTIPLE_FOLDERS"] = "multiple_folders";
|
||||
I18N_STRUCTURE["MULTIPLE_FILES"] = "multiple_files";
|
||||
I18N_STRUCTURE["SINGLE_FILE"] = "single_file";
|
||||
return I18N_STRUCTURE;
|
||||
}({});
|
||||
let I18N_FIELD = exports.I18N_FIELD = /*#__PURE__*/function (I18N_FIELD) {
|
||||
I18N_FIELD["TRANSLATE"] = "translate";
|
||||
I18N_FIELD["DUPLICATE"] = "duplicate";
|
||||
I18N_FIELD["NONE"] = "none";
|
||||
return I18N_FIELD;
|
||||
}({});
|
||||
function hasI18n(collection) {
|
||||
return collection.has(I18N);
|
||||
}
|
||||
function getI18nInfo(collection) {
|
||||
if (!hasI18n(collection)) {
|
||||
return {};
|
||||
}
|
||||
const {
|
||||
structure,
|
||||
locales,
|
||||
default_locale: defaultLocale
|
||||
} = collection.get(I18N).toJS();
|
||||
return {
|
||||
structure,
|
||||
locales,
|
||||
defaultLocale
|
||||
};
|
||||
}
|
||||
function getI18nFilesDepth(collection, depth) {
|
||||
const {
|
||||
structure
|
||||
} = getI18nInfo(collection);
|
||||
if (structure === I18N_STRUCTURE.MULTIPLE_FOLDERS) {
|
||||
return depth + 1;
|
||||
}
|
||||
return depth;
|
||||
}
|
||||
function isFieldTranslatable(field, locale, defaultLocale) {
|
||||
const isTranslatable = locale !== defaultLocale && field.get(I18N) === I18N_FIELD.TRANSLATE;
|
||||
return isTranslatable;
|
||||
}
|
||||
function isFieldDuplicate(field, locale, defaultLocale) {
|
||||
const isDuplicate = locale !== defaultLocale && field.get(I18N) === I18N_FIELD.DUPLICATE;
|
||||
return isDuplicate;
|
||||
}
|
||||
function isFieldHidden(field, locale, defaultLocale) {
|
||||
const isHidden = locale !== defaultLocale && field.get(I18N) === I18N_FIELD.NONE;
|
||||
return isHidden;
|
||||
}
|
||||
function getLocaleDataPath(locale) {
|
||||
return [I18N, locale, 'data'];
|
||||
}
|
||||
function getDataPath(locale, defaultLocale) {
|
||||
const dataPath = locale !== defaultLocale ? getLocaleDataPath(locale) : ['data'];
|
||||
return dataPath;
|
||||
}
|
||||
function getFilePath(structure, extension, path, slug, locale) {
|
||||
switch (structure) {
|
||||
case I18N_STRUCTURE.MULTIPLE_FOLDERS:
|
||||
return path.replace(`/${slug}`, `/${locale}/${slug}`);
|
||||
case I18N_STRUCTURE.MULTIPLE_FILES:
|
||||
return path.replace(new RegExp(`${(0, _escapeRegExp2.default)(extension)}$`), `${locale}.${extension}`);
|
||||
case I18N_STRUCTURE.SINGLE_FILE:
|
||||
default:
|
||||
return path;
|
||||
}
|
||||
}
|
||||
function getLocaleFromPath(structure, extension, path) {
|
||||
switch (structure) {
|
||||
case I18N_STRUCTURE.MULTIPLE_FOLDERS:
|
||||
{
|
||||
const parts = path.split('/');
|
||||
// filename
|
||||
parts.pop();
|
||||
// locale
|
||||
return parts.pop();
|
||||
}
|
||||
case I18N_STRUCTURE.MULTIPLE_FILES:
|
||||
{
|
||||
const parts = path.slice(0, -`.${extension}`.length);
|
||||
return parts.split('.').pop();
|
||||
}
|
||||
case I18N_STRUCTURE.SINGLE_FILE:
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
function getFilePaths(collection, extension, path, slug) {
|
||||
const {
|
||||
structure,
|
||||
locales
|
||||
} = getI18nInfo(collection);
|
||||
if (structure === I18N_STRUCTURE.SINGLE_FILE) {
|
||||
return [path];
|
||||
}
|
||||
const paths = locales.map(locale => getFilePath(structure, extension, path, slug, locale));
|
||||
return paths;
|
||||
}
|
||||
function normalizeFilePath(structure, path, locale) {
|
||||
switch (structure) {
|
||||
case I18N_STRUCTURE.MULTIPLE_FOLDERS:
|
||||
return path.replace(`${locale}/`, '');
|
||||
case I18N_STRUCTURE.MULTIPLE_FILES:
|
||||
return path.replace(`.${locale}`, '');
|
||||
case I18N_STRUCTURE.SINGLE_FILE:
|
||||
default:
|
||||
return path;
|
||||
}
|
||||
}
|
||||
function getI18nFiles(collection, extension, entryDraft, entryToRaw, path, slug, newPath) {
|
||||
const {
|
||||
structure,
|
||||
defaultLocale,
|
||||
locales
|
||||
} = getI18nInfo(collection);
|
||||
if (structure === I18N_STRUCTURE.SINGLE_FILE) {
|
||||
const data = locales.reduce((map, locale) => {
|
||||
const dataPath = getDataPath(locale, defaultLocale);
|
||||
return map.set(locale, entryDraft.getIn(dataPath));
|
||||
}, (0, _immutable.Map)({}));
|
||||
const draft = entryDraft.set('data', data);
|
||||
return [_objectSpread({
|
||||
path: getFilePath(structure, extension, path, slug, locales[0]),
|
||||
slug,
|
||||
raw: entryToRaw(draft)
|
||||
}, newPath && {
|
||||
newPath: getFilePath(structure, extension, newPath, slug, locales[0])
|
||||
})];
|
||||
}
|
||||
const dataFiles = locales.map(locale => {
|
||||
const dataPath = getDataPath(locale, defaultLocale);
|
||||
const draft = entryDraft.set('data', entryDraft.getIn(dataPath));
|
||||
return _objectSpread({
|
||||
path: getFilePath(structure, extension, path, slug, locale),
|
||||
slug,
|
||||
raw: draft.get('data') ? entryToRaw(draft) : ''
|
||||
}, newPath && {
|
||||
newPath: getFilePath(structure, extension, newPath, slug, locale)
|
||||
});
|
||||
}).filter(dataFile => dataFile.raw);
|
||||
return dataFiles;
|
||||
}
|
||||
function getI18nBackup(collection, entry, entryToRaw) {
|
||||
const {
|
||||
locales,
|
||||
defaultLocale
|
||||
} = getI18nInfo(collection);
|
||||
const i18nBackup = locales.filter(l => l !== defaultLocale).reduce((acc, locale) => {
|
||||
const dataPath = getDataPath(locale, defaultLocale);
|
||||
const data = entry.getIn(dataPath);
|
||||
if (!data) {
|
||||
return acc;
|
||||
}
|
||||
const draft = entry.set('data', data);
|
||||
return _objectSpread(_objectSpread({}, acc), {}, {
|
||||
[locale]: {
|
||||
raw: entryToRaw(draft)
|
||||
}
|
||||
});
|
||||
}, {});
|
||||
return i18nBackup;
|
||||
}
|
||||
function formatI18nBackup(i18nBackup, formatRawData) {
|
||||
const i18n = Object.entries(i18nBackup).reduce((acc, [locale, {
|
||||
raw
|
||||
}]) => {
|
||||
const entry = formatRawData(raw);
|
||||
return _objectSpread(_objectSpread({}, acc), {}, {
|
||||
[locale]: {
|
||||
data: entry.data
|
||||
}
|
||||
});
|
||||
}, {});
|
||||
return i18n;
|
||||
}
|
||||
function mergeValues(collection, structure, defaultLocale, values) {
|
||||
let defaultEntry = values.find(e => e.locale === defaultLocale);
|
||||
if (!defaultEntry) {
|
||||
defaultEntry = values[0];
|
||||
console.warn(`Could not locale entry for default locale '${defaultLocale}'`);
|
||||
}
|
||||
const i18n = values.filter(e => e.locale !== defaultEntry.locale).reduce((acc, {
|
||||
locale,
|
||||
value
|
||||
}) => {
|
||||
const dataPath = getLocaleDataPath(locale);
|
||||
return (0, _set2.default)(acc, dataPath, value.data);
|
||||
}, {});
|
||||
const path = normalizeFilePath(structure, defaultEntry.value.path, defaultLocale);
|
||||
const slug = (0, _collections.selectEntrySlug)(collection, path);
|
||||
const entryValue = _objectSpread(_objectSpread(_objectSpread({}, defaultEntry.value), {}, {
|
||||
raw: ''
|
||||
}, i18n), {}, {
|
||||
path,
|
||||
slug
|
||||
});
|
||||
return entryValue;
|
||||
}
|
||||
function mergeSingleFileValue(entryValue, defaultLocale, locales) {
|
||||
const data = entryValue.data[defaultLocale] || {};
|
||||
const i18n = locales.filter(l => l !== defaultLocale).map(l => ({
|
||||
locale: l,
|
||||
value: entryValue.data[l]
|
||||
})).filter(e => e.value).reduce((acc, e) => {
|
||||
return _objectSpread(_objectSpread({}, acc), {}, {
|
||||
[e.locale]: {
|
||||
data: e.value
|
||||
}
|
||||
});
|
||||
}, {});
|
||||
return _objectSpread(_objectSpread({}, entryValue), {}, {
|
||||
data,
|
||||
i18n,
|
||||
raw: ''
|
||||
});
|
||||
}
|
||||
async function getI18nEntry(collection, extension, path, slug, getEntryValue) {
|
||||
const {
|
||||
structure,
|
||||
locales,
|
||||
defaultLocale
|
||||
} = getI18nInfo(collection);
|
||||
let entryValue;
|
||||
if (structure === I18N_STRUCTURE.SINGLE_FILE) {
|
||||
entryValue = mergeSingleFileValue(await getEntryValue(path), defaultLocale, locales);
|
||||
} else {
|
||||
const entryValues = await Promise.all(locales.map(async locale => {
|
||||
const entryPath = getFilePath(structure, extension, path, slug, locale);
|
||||
const value = await getEntryValue(entryPath).catch(() => null);
|
||||
return {
|
||||
value,
|
||||
locale
|
||||
};
|
||||
}));
|
||||
const nonNullValues = entryValues.filter(e => e.value !== null);
|
||||
entryValue = mergeValues(collection, structure, defaultLocale, nonNullValues);
|
||||
}
|
||||
return entryValue;
|
||||
}
|
||||
function groupEntries(collection, extension, entries) {
|
||||
const {
|
||||
structure,
|
||||
defaultLocale,
|
||||
locales
|
||||
} = getI18nInfo(collection);
|
||||
if (structure === I18N_STRUCTURE.SINGLE_FILE) {
|
||||
return entries.map(e => mergeSingleFileValue(e, defaultLocale, locales));
|
||||
}
|
||||
const grouped = (0, _groupBy2.default)(entries.map(e => ({
|
||||
locale: getLocaleFromPath(structure, extension, e.path),
|
||||
value: e
|
||||
})), ({
|
||||
locale,
|
||||
value: e
|
||||
}) => {
|
||||
return normalizeFilePath(structure, e.path, locale);
|
||||
});
|
||||
const groupedEntries = Object.values(grouped).reduce((acc, values) => {
|
||||
const entryValue = mergeValues(collection, structure, defaultLocale, values);
|
||||
return [...acc, entryValue];
|
||||
}, []);
|
||||
return groupedEntries;
|
||||
}
|
||||
function getI18nDataFiles(collection, extension, path, slug, diffFiles) {
|
||||
const {
|
||||
structure
|
||||
} = getI18nInfo(collection);
|
||||
if (structure === I18N_STRUCTURE.SINGLE_FILE) {
|
||||
return diffFiles;
|
||||
}
|
||||
const paths = getFilePaths(collection, extension, path, slug);
|
||||
const dataFiles = paths.reduce((acc, path) => {
|
||||
const dataFile = diffFiles.find(file => file.path === path);
|
||||
if (dataFile) {
|
||||
return [...acc, dataFile];
|
||||
} else {
|
||||
return [...acc, {
|
||||
path,
|
||||
id: '',
|
||||
newFile: false
|
||||
}];
|
||||
}
|
||||
}, []);
|
||||
return dataFiles;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function duplicateDefaultI18nFields(collection, dataFields) {
|
||||
const {
|
||||
locales,
|
||||
defaultLocale
|
||||
} = getI18nInfo(collection);
|
||||
const i18nFields = Object.fromEntries(locales.filter(locale => locale !== defaultLocale).map(locale => [locale, {
|
||||
data: dataFields
|
||||
}]));
|
||||
return i18nFields;
|
||||
}
|
||||
function duplicateI18nFields(entryDraft, field, locales, defaultLocale, fieldPath = [field.get('name')]) {
|
||||
const value = entryDraft.getIn(['entry', 'data', ...fieldPath]);
|
||||
if (field.get(I18N) === I18N_FIELD.DUPLICATE) {
|
||||
locales.filter(l => l !== defaultLocale).forEach(l => {
|
||||
entryDraft = entryDraft.setIn(['entry', ...getDataPath(l, defaultLocale), ...fieldPath], value);
|
||||
});
|
||||
}
|
||||
if (field.has('field') && !_immutable.List.isList(value)) {
|
||||
const fields = [field.get('field')];
|
||||
fields.forEach(field => {
|
||||
entryDraft = duplicateI18nFields(entryDraft, field, locales, defaultLocale, [...fieldPath, field.get('name')]);
|
||||
});
|
||||
} else if (field.has('fields') && !_immutable.List.isList(value)) {
|
||||
const fields = field.get('fields').toArray();
|
||||
fields.forEach(field => {
|
||||
entryDraft = duplicateI18nFields(entryDraft, field, locales, defaultLocale, [...fieldPath, field.get('name')]);
|
||||
});
|
||||
}
|
||||
return entryDraft;
|
||||
}
|
||||
function getPreviewEntry(entry, locale, defaultLocale) {
|
||||
if (locale === defaultLocale) {
|
||||
return entry;
|
||||
}
|
||||
return entry.set('data', entry.getIn([I18N, locale, 'data']));
|
||||
}
|
||||
function serializeI18n(collection, entry,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
serializeValues) {
|
||||
const {
|
||||
locales,
|
||||
defaultLocale
|
||||
} = getI18nInfo(collection);
|
||||
locales.filter(locale => locale !== defaultLocale).forEach(locale => {
|
||||
const dataPath = getLocaleDataPath(locale);
|
||||
entry = entry.setIn(dataPath, serializeValues(entry.getIn(dataPath)));
|
||||
});
|
||||
return entry;
|
||||
}
|
||||
13
node_modules/decap-cms-core/dist/esm/lib/phrases.js
generated
vendored
Normal file
13
node_modules/decap-cms-core/dist/esm/lib/phrases.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getPhrases = getPhrases;
|
||||
var _merge2 = _interopRequireDefault(require("lodash/merge"));
|
||||
var _registry = require("./registry");
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
function getPhrases(locale) {
|
||||
const phrases = (0, _merge2.default)({}, (0, _registry.getLocale)('en'), (0, _registry.getLocale)(locale));
|
||||
return phrases;
|
||||
}
|
||||
364
node_modules/decap-cms-core/dist/esm/lib/registry.js
generated
vendored
Normal file
364
node_modules/decap-cms-core/dist/esm/lib/registry.js
generated
vendored
Normal file
@@ -0,0 +1,364 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
exports.getBackend = getBackend;
|
||||
exports.getCustomFormats = getCustomFormats;
|
||||
exports.getCustomFormatsExtensions = getCustomFormatsExtensions;
|
||||
exports.getCustomFormatsFormatters = getCustomFormatsFormatters;
|
||||
exports.getEditorComponents = getEditorComponents;
|
||||
exports.getEventListeners = getEventListeners;
|
||||
exports.getFormatter = getFormatter;
|
||||
exports.getLocale = getLocale;
|
||||
exports.getMediaLibrary = getMediaLibrary;
|
||||
exports.getPreviewStyles = getPreviewStyles;
|
||||
exports.getPreviewTemplate = getPreviewTemplate;
|
||||
exports.getRemarkPlugins = getRemarkPlugins;
|
||||
exports.getWidget = getWidget;
|
||||
exports.getWidgetValueSerializer = getWidgetValueSerializer;
|
||||
exports.getWidgets = getWidgets;
|
||||
exports.invokeEvent = invokeEvent;
|
||||
exports.registerBackend = registerBackend;
|
||||
exports.registerCustomFormat = registerCustomFormat;
|
||||
exports.registerEditorComponent = registerEditorComponent;
|
||||
exports.registerEventListener = registerEventListener;
|
||||
exports.registerLocale = registerLocale;
|
||||
exports.registerMediaLibrary = registerMediaLibrary;
|
||||
exports.registerPreviewStyle = registerPreviewStyle;
|
||||
exports.registerPreviewTemplate = registerPreviewTemplate;
|
||||
exports.registerRemarkPlugin = registerRemarkPlugin;
|
||||
exports.registerWidget = registerWidget;
|
||||
exports.registerWidgetValueSerializer = registerWidgetValueSerializer;
|
||||
exports.removeEventListener = removeEventListener;
|
||||
exports.resolveWidget = resolveWidget;
|
||||
var _immutable = require("immutable");
|
||||
var _immer = require("immer");
|
||||
var _commonTags = require("common-tags");
|
||||
var _EditorComponent = _interopRequireDefault(require("../valueObjects/EditorComponent"));
|
||||
const _excluded = ["name", "controlComponent", "previewComponent", "schema", "allowMapValue", "globalStyles"];
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
||||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
||||
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; }
|
||||
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; }
|
||||
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; }
|
||||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
||||
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); }
|
||||
const allowedEvents = ['prePublish', 'postPublish', 'preUnpublish', 'postUnpublish', 'preSave', 'postSave'];
|
||||
const eventHandlers = {};
|
||||
allowedEvents.forEach(e => {
|
||||
eventHandlers[e] = [];
|
||||
});
|
||||
|
||||
/**
|
||||
* Global Registry Object
|
||||
*/
|
||||
const registry = {
|
||||
backends: {},
|
||||
templates: {},
|
||||
previewStyles: [],
|
||||
widgets: {},
|
||||
editorComponents: (0, _immutable.Map)(),
|
||||
remarkPlugins: [],
|
||||
widgetValueSerializers: {},
|
||||
mediaLibraries: [],
|
||||
locales: {},
|
||||
eventHandlers,
|
||||
formats: {}
|
||||
};
|
||||
var _default = exports.default = {
|
||||
registerPreviewStyle,
|
||||
getPreviewStyles,
|
||||
registerPreviewTemplate,
|
||||
getPreviewTemplate,
|
||||
registerWidget,
|
||||
getWidget,
|
||||
getWidgets,
|
||||
resolveWidget,
|
||||
registerEditorComponent,
|
||||
getEditorComponents,
|
||||
registerRemarkPlugin,
|
||||
getRemarkPlugins,
|
||||
registerWidgetValueSerializer,
|
||||
getWidgetValueSerializer,
|
||||
registerBackend,
|
||||
getBackend,
|
||||
registerMediaLibrary,
|
||||
getMediaLibrary,
|
||||
registerLocale,
|
||||
getLocale,
|
||||
registerEventListener,
|
||||
removeEventListener,
|
||||
getEventListeners,
|
||||
invokeEvent,
|
||||
registerCustomFormat,
|
||||
getCustomFormats,
|
||||
getCustomFormatsExtensions,
|
||||
getCustomFormatsFormatters
|
||||
};
|
||||
/**
|
||||
* Preview Styles
|
||||
*
|
||||
* Valid options:
|
||||
* - raw {boolean} if `true`, `style` value is expected to be a CSS string
|
||||
*/
|
||||
function registerPreviewStyle(style, opts) {
|
||||
registry.previewStyles.push(_objectSpread(_objectSpread({}, opts), {}, {
|
||||
value: style
|
||||
}));
|
||||
}
|
||||
function getPreviewStyles() {
|
||||
return registry.previewStyles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Preview Templates
|
||||
*/
|
||||
function registerPreviewTemplate(name, component) {
|
||||
registry.templates[name] = component;
|
||||
}
|
||||
function getPreviewTemplate(name) {
|
||||
return registry.templates[name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Editor Widgets
|
||||
*/
|
||||
function registerWidget(name, control, preview, schema = {}) {
|
||||
if (Array.isArray(name)) {
|
||||
name.forEach(widget => {
|
||||
if (typeof widget !== 'object') {
|
||||
console.error(`Cannot register widget: ${widget}`);
|
||||
} else {
|
||||
registerWidget(widget);
|
||||
}
|
||||
});
|
||||
} else if (typeof name === 'string') {
|
||||
// A registered widget control can be reused by a new widget, allowing
|
||||
// multiple copies with different previews.
|
||||
const newControl = typeof control === 'string' ? registry.widgets[control].control : control;
|
||||
registry.widgets[name] = {
|
||||
control: newControl,
|
||||
preview,
|
||||
schema
|
||||
};
|
||||
} else if (typeof name === 'object') {
|
||||
const {
|
||||
name: widgetName,
|
||||
controlComponent: control,
|
||||
previewComponent: preview,
|
||||
schema = {},
|
||||
allowMapValue,
|
||||
globalStyles
|
||||
} = name,
|
||||
options = _objectWithoutProperties(name, _excluded);
|
||||
if (registry.widgets[widgetName]) {
|
||||
console.warn((0, _commonTags.oneLine)`
|
||||
Multiple widgets registered with name "${widgetName}". Only the last widget registered with
|
||||
this name will be used.
|
||||
`);
|
||||
}
|
||||
if (!control) {
|
||||
throw Error(`Widget "${widgetName}" registered without \`controlComponent\`.`);
|
||||
}
|
||||
registry.widgets[widgetName] = _objectSpread({
|
||||
control,
|
||||
preview,
|
||||
schema,
|
||||
globalStyles,
|
||||
allowMapValue
|
||||
}, options);
|
||||
} else {
|
||||
console.error('`registerWidget` failed, called with incorrect arguments.');
|
||||
}
|
||||
}
|
||||
function getWidget(name) {
|
||||
return registry.widgets[name];
|
||||
}
|
||||
function getWidgets() {
|
||||
return (0, _immer.produce)(Object.entries(registry.widgets), draft => {
|
||||
return draft.map(([key, value]) => _objectSpread({
|
||||
name: key
|
||||
}, value));
|
||||
});
|
||||
}
|
||||
function resolveWidget(name) {
|
||||
return getWidget(name || 'string') || getWidget('unknown');
|
||||
}
|
||||
|
||||
/**
|
||||
* Markdown Editor Custom Components
|
||||
*/
|
||||
function registerEditorComponent(component) {
|
||||
const plugin = (0, _EditorComponent.default)(component);
|
||||
if (plugin.type === 'code-block') {
|
||||
const codeBlock = registry.editorComponents.find(c => c.type === 'code-block');
|
||||
if (codeBlock) {
|
||||
console.warn((0, _commonTags.oneLine)`
|
||||
Only one editor component of type "code-block" may be registered. Previously registered code
|
||||
block component(s) will be overwritten.
|
||||
`);
|
||||
registry.editorComponents = registry.editorComponents.delete(codeBlock.id);
|
||||
}
|
||||
}
|
||||
registry.editorComponents = registry.editorComponents.set(plugin.id, plugin);
|
||||
}
|
||||
function getEditorComponents() {
|
||||
return registry.editorComponents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remark plugins
|
||||
*/
|
||||
/** @typedef {import('unified').Pluggable} RemarkPlugin */
|
||||
/** @type {(plugin: RemarkPlugin) => void} */
|
||||
function registerRemarkPlugin(plugin) {
|
||||
registry.remarkPlugins.push(plugin);
|
||||
}
|
||||
/** @type {() => Array<RemarkPlugin>} */
|
||||
function getRemarkPlugins() {
|
||||
return registry.remarkPlugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget Serializers
|
||||
*/
|
||||
function registerWidgetValueSerializer(widgetName, serializer) {
|
||||
registry.widgetValueSerializers[widgetName] = serializer;
|
||||
}
|
||||
function getWidgetValueSerializer(widgetName) {
|
||||
return registry.widgetValueSerializers[widgetName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Backend API
|
||||
*/
|
||||
function registerBackend(name, BackendClass) {
|
||||
if (!name || !BackendClass) {
|
||||
console.error("Backend parameters invalid. example: CMS.registerBackend('myBackend', BackendClass)");
|
||||
} else if (registry.backends[name]) {
|
||||
console.error(`Backend [${name}] already registered. Please choose a different name.`);
|
||||
} else {
|
||||
registry.backends[name] = {
|
||||
init: (...args) => new BackendClass(...args)
|
||||
};
|
||||
}
|
||||
}
|
||||
function getBackend(name) {
|
||||
return registry.backends[name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Media Libraries
|
||||
*/
|
||||
function registerMediaLibrary(mediaLibrary, options) {
|
||||
if (registry.mediaLibraries.find(ml => mediaLibrary.name === ml.name)) {
|
||||
throw new Error(`A media library named ${mediaLibrary.name} has already been registered.`);
|
||||
}
|
||||
registry.mediaLibraries.push(_objectSpread(_objectSpread({}, mediaLibrary), {}, {
|
||||
options
|
||||
}));
|
||||
}
|
||||
function getMediaLibrary(name) {
|
||||
return registry.mediaLibraries.find(ml => ml.name === name);
|
||||
}
|
||||
function validateEventName(name) {
|
||||
if (!allowedEvents.includes(name)) {
|
||||
throw new Error(`Invalid event name '${name}'`);
|
||||
}
|
||||
}
|
||||
function getEventListeners(name) {
|
||||
validateEventName(name);
|
||||
return [...registry.eventHandlers[name]];
|
||||
}
|
||||
function registerEventListener({
|
||||
name,
|
||||
handler
|
||||
}, options = {}) {
|
||||
validateEventName(name);
|
||||
registry.eventHandlers[name].push({
|
||||
handler,
|
||||
options
|
||||
});
|
||||
}
|
||||
async function invokeEvent({
|
||||
name,
|
||||
data
|
||||
}) {
|
||||
validateEventName(name);
|
||||
const handlers = registry.eventHandlers[name];
|
||||
let _data = _objectSpread({}, data);
|
||||
for (const {
|
||||
handler,
|
||||
options
|
||||
} of handlers) {
|
||||
const result = await handler(_data, options);
|
||||
if (result !== undefined) {
|
||||
const entry = _data.entry.set('data', result);
|
||||
_data = _objectSpread(_objectSpread({}, data), {}, {
|
||||
entry
|
||||
});
|
||||
}
|
||||
}
|
||||
return _data.entry.get('data');
|
||||
}
|
||||
function removeEventListener({
|
||||
name,
|
||||
handler
|
||||
}) {
|
||||
validateEventName(name);
|
||||
if (handler) {
|
||||
registry.eventHandlers[name] = registry.eventHandlers[name].filter(item => item.handler !== handler);
|
||||
} else {
|
||||
registry.eventHandlers[name] = [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Locales
|
||||
*/
|
||||
function registerLocale(locale, phrases) {
|
||||
if (!locale || !phrases) {
|
||||
console.error("Locale parameters invalid. example: CMS.registerLocale('locale', phrases)");
|
||||
} else {
|
||||
registry.locales[locale] = phrases;
|
||||
}
|
||||
}
|
||||
function getLocale(locale) {
|
||||
return registry.locales[locale];
|
||||
}
|
||||
function registerCustomFormat(name, extension, formatter) {
|
||||
registry.formats[name] = {
|
||||
extension,
|
||||
formatter
|
||||
};
|
||||
}
|
||||
function getCustomFormats() {
|
||||
return registry.formats;
|
||||
}
|
||||
function getCustomFormatsExtensions() {
|
||||
return Object.entries(registry.formats).reduce(function (acc, [name, {
|
||||
extension
|
||||
}]) {
|
||||
return _objectSpread(_objectSpread({}, acc), {}, {
|
||||
[name]: extension
|
||||
});
|
||||
}, {});
|
||||
}
|
||||
|
||||
/** @type {() => Record<string, unknown>} */
|
||||
function getCustomFormatsFormatters() {
|
||||
return Object.entries(registry.formats).reduce(function (acc, [name, {
|
||||
formatter
|
||||
}]) {
|
||||
return _objectSpread(_objectSpread({}, acc), {}, {
|
||||
[name]: formatter
|
||||
});
|
||||
}, {});
|
||||
}
|
||||
function getFormatter(name) {
|
||||
var _registry$formats$nam;
|
||||
return (_registry$formats$nam = registry.formats[name]) === null || _registry$formats$nam === void 0 ? void 0 : _registry$formats$nam.formatter;
|
||||
}
|
||||
74
node_modules/decap-cms-core/dist/esm/lib/serializeEntryValues.js
generated
vendored
Normal file
74
node_modules/decap-cms-core/dist/esm/lib/serializeEntryValues.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.deserializeValues = deserializeValues;
|
||||
exports.serializeValues = serializeValues;
|
||||
var _isNil2 = _interopRequireDefault(require("lodash/isNil"));
|
||||
var _immutable = require("immutable");
|
||||
var _registry = require("./registry");
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
/**
|
||||
* Methods for serializing/deserializing entry field values. Most widgets don't
|
||||
* require this for their values, and those that do can typically serialize/
|
||||
* deserialize on every change from within the widget. The serialization
|
||||
* handlers here are for widgets whose values require heavy serialization that
|
||||
* would hurt performance if run for every change.
|
||||
|
||||
* An example of this is the markdown widget, whose value is stored as a
|
||||
* markdown string. Instead of stringifying on every change of that field, a
|
||||
* deserialization method is registered from the widget's control module that
|
||||
* converts the stored markdown string to an AST, and that AST serves as the
|
||||
* widget model during editing.
|
||||
*
|
||||
* Serialization handlers should be registered for each widget that requires
|
||||
* them, and the registration method is exposed through the registry. Any
|
||||
* registered deserialization handlers run on entry load, and serialization
|
||||
* handlers run on persist.
|
||||
*/
|
||||
function runSerializer(values, fields, method) {
|
||||
/**
|
||||
* Reduce the list of fields to a map where keys are field names and values
|
||||
* are field values, serializing the values of fields whose widgets have
|
||||
* registered serializers. If the field is a list or object, call recursively
|
||||
* for nested fields.
|
||||
*/
|
||||
let serializedData = fields.reduce((acc, field) => {
|
||||
const fieldName = field.get('name');
|
||||
const value = values.get(fieldName);
|
||||
const serializer = (0, _registry.getWidgetValueSerializer)(field.get('widget'));
|
||||
const nestedFields = field.get('fields');
|
||||
|
||||
// Call recursively for fields within lists
|
||||
if (nestedFields && _immutable.List.isList(value)) {
|
||||
return acc.set(fieldName, value.map(val => runSerializer(val, nestedFields, method)));
|
||||
}
|
||||
|
||||
// Call recursively for fields within objects
|
||||
if (nestedFields && _immutable.Map.isMap(value)) {
|
||||
return acc.set(fieldName, runSerializer(value, nestedFields, method));
|
||||
}
|
||||
|
||||
// Run serialization method on value if not null or undefined
|
||||
if (serializer && !(0, _isNil2.default)(value)) {
|
||||
return acc.set(fieldName, serializer[method](value));
|
||||
}
|
||||
|
||||
// If no serializer is registered for the field's widget, use the field as is
|
||||
if (!(0, _isNil2.default)(value)) {
|
||||
return acc.set(fieldName, value);
|
||||
}
|
||||
return acc;
|
||||
}, (0, _immutable.Map)());
|
||||
|
||||
//preserve unknown fields value
|
||||
serializedData = values.mergeDeep(serializedData);
|
||||
return serializedData;
|
||||
}
|
||||
function serializeValues(values, fields) {
|
||||
return runSerializer(values, fields, 'serialize');
|
||||
}
|
||||
function deserializeValues(values, fields) {
|
||||
return runSerializer(values, fields, 'deserialize');
|
||||
}
|
||||
15
node_modules/decap-cms-core/dist/esm/lib/textHelper.js
generated
vendored
Normal file
15
node_modules/decap-cms-core/dist/esm/lib/textHelper.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.stringToRGB = stringToRGB;
|
||||
function stringToRGB(str) {
|
||||
if (!str) return '000000';
|
||||
let hash = 0;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
||||
}
|
||||
const c = (hash & 0x00ffffff).toString(16).toUpperCase();
|
||||
return `00000${c}`.slice(-6);
|
||||
}
|
||||
128
node_modules/decap-cms-core/dist/esm/lib/urlHelper.js
generated
vendored
Normal file
128
node_modules/decap-cms-core/dist/esm/lib/urlHelper.js
generated
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.addParams = addParams;
|
||||
exports.getCharReplacer = getCharReplacer;
|
||||
exports.getCollectionUrl = getCollectionUrl;
|
||||
exports.getNewEntryUrl = getNewEntryUrl;
|
||||
exports.joinUrlPath = joinUrlPath;
|
||||
exports.sanitizeChar = sanitizeChar;
|
||||
exports.sanitizeSlug = sanitizeSlug;
|
||||
exports.sanitizeURI = sanitizeURI;
|
||||
exports.stripProtocol = stripProtocol;
|
||||
var _partialRight2 = _interopRequireDefault(require("lodash/partialRight"));
|
||||
var _flow2 = _interopRequireDefault(require("lodash/flow"));
|
||||
var _escapeRegExp2 = _interopRequireDefault(require("lodash/escapeRegExp"));
|
||||
var _isString2 = _interopRequireDefault(require("lodash/isString"));
|
||||
var _url = _interopRequireDefault(require("url"));
|
||||
var _urlJoin = _interopRequireDefault(require("url-join"));
|
||||
var _diacritics = _interopRequireDefault(require("diacritics"));
|
||||
var _sanitizeFilename = _interopRequireDefault(require("sanitize-filename"));
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
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; }
|
||||
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; }
|
||||
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; }
|
||||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
||||
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); }
|
||||
function getUrl(urlString, direct) {
|
||||
return `${direct ? '/#' : ''}${urlString}`;
|
||||
}
|
||||
function getCollectionUrl(collectionName, direct) {
|
||||
return getUrl(`/collections/${collectionName}`, direct);
|
||||
}
|
||||
function getNewEntryUrl(collectionName, direct) {
|
||||
return getUrl(`/collections/${collectionName}/new`, direct);
|
||||
}
|
||||
function addParams(urlString, params) {
|
||||
const parsedUrl = _url.default.parse(urlString, true);
|
||||
parsedUrl.query = _objectSpread(_objectSpread({}, parsedUrl.query), params);
|
||||
return _url.default.format(parsedUrl);
|
||||
}
|
||||
function stripProtocol(urlString) {
|
||||
const protocolEndIndex = urlString.indexOf('//');
|
||||
return protocolEndIndex > -1 ? urlString.slice(protocolEndIndex + 2) : urlString;
|
||||
}
|
||||
|
||||
/* See https://www.w3.org/International/articles/idn-and-iri/#path.
|
||||
* According to the new IRI (Internationalized Resource Identifier) spec, RFC 3987,
|
||||
* ASCII chars should be kept the same way as in standard URIs (letters digits _ - . ~).
|
||||
* Non-ASCII chars (unless they are not in the allowed "ucschars" list) should be percent-encoded.
|
||||
* If the string is not encoded in Unicode, it should be converted to UTF-8 and normalized first,
|
||||
* but JS stores strings as UTF-16/UCS-2 internally, so we should not normalize or re-encode.
|
||||
*/
|
||||
const uriChars = /[\w\-.~]/i;
|
||||
const ucsChars = /[\xA0-\u{D7FF}\u{F900}-\u{FDCF}\u{FDF0}-\u{FFEF}\u{10000}-\u{1FFFD}\u{20000}-\u{2FFFD}\u{30000}-\u{3FFFD}\u{40000}-\u{4FFFD}\u{50000}-\u{5FFFD}\u{60000}-\u{6FFFD}\u{70000}-\u{7FFFD}\u{80000}-\u{8FFFD}\u{90000}-\u{9FFFD}\u{A0000}-\u{AFFFD}\u{B0000}-\u{BFFFD}\u{C0000}-\u{CFFFD}\u{D0000}-\u{DFFFD}\u{E1000}-\u{EFFFD}]/u;
|
||||
function validURIChar(char) {
|
||||
return uriChars.test(char);
|
||||
}
|
||||
function validIRIChar(char) {
|
||||
return uriChars.test(char) || ucsChars.test(char);
|
||||
}
|
||||
function getCharReplacer(encoding, replacement) {
|
||||
let validChar;
|
||||
if (encoding === 'unicode') {
|
||||
validChar = validIRIChar;
|
||||
} else if (encoding === 'ascii') {
|
||||
validChar = validURIChar;
|
||||
} else {
|
||||
throw new Error('`options.encoding` must be "unicode" or "ascii".');
|
||||
}
|
||||
|
||||
// Check and make sure the replacement character is actually a safe char itself.
|
||||
if (!Array.from(replacement).every(validChar)) {
|
||||
throw new Error('The replacement character(s) (options.replacement) is itself unsafe.');
|
||||
}
|
||||
return char => validChar(char) ? char : replacement;
|
||||
}
|
||||
// `sanitizeURI` does not actually URI-encode the chars (that is the browser's and server's job), just removes the ones that are not allowed.
|
||||
function sanitizeURI(str, options) {
|
||||
const {
|
||||
replacement = '',
|
||||
encoding = 'unicode'
|
||||
} = options || {};
|
||||
if (!(0, _isString2.default)(str)) {
|
||||
throw new Error('The input slug must be a string.');
|
||||
}
|
||||
if (!(0, _isString2.default)(replacement)) {
|
||||
throw new Error('`options.replacement` must be a string.');
|
||||
}
|
||||
|
||||
// `Array.from` must be used instead of `String.split` because
|
||||
// `split` converts things like emojis into UTF-16 surrogate pairs.
|
||||
return Array.from(str).map(getCharReplacer(encoding, replacement)).join('');
|
||||
}
|
||||
function sanitizeChar(char, options) {
|
||||
const {
|
||||
encoding = 'unicode',
|
||||
sanitize_replacement: replacement = ''
|
||||
} = options || {};
|
||||
return getCharReplacer(encoding, replacement)(char);
|
||||
}
|
||||
function sanitizeSlug(str, options) {
|
||||
if (!(0, _isString2.default)(str)) {
|
||||
throw new Error('The input slug must be a string.');
|
||||
}
|
||||
const {
|
||||
encoding,
|
||||
clean_accents: stripDiacritics,
|
||||
sanitize_replacement: replacement
|
||||
} = options || {};
|
||||
const sanitizedSlug = (0, _flow2.default)([...(stripDiacritics ? [_diacritics.default.remove] : []), (0, _partialRight2.default)(sanitizeURI, {
|
||||
replacement,
|
||||
encoding
|
||||
}), (0, _partialRight2.default)(_sanitizeFilename.default, {
|
||||
replacement
|
||||
})])(str);
|
||||
|
||||
// Remove any doubled or leading/trailing replacement characters (that were added in the sanitizers).
|
||||
const doubleReplacement = new RegExp(`(?:${(0, _escapeRegExp2.default)(replacement)})+`, 'g');
|
||||
const trailingReplacement = new RegExp(`${(0, _escapeRegExp2.default)(replacement)}$`);
|
||||
const leadingReplacement = new RegExp(`^${(0, _escapeRegExp2.default)(replacement)}`);
|
||||
const normalizedSlug = sanitizedSlug.replace(doubleReplacement, replacement).replace(leadingReplacement, '').replace(trailingReplacement, '');
|
||||
return normalizedSlug;
|
||||
}
|
||||
function joinUrlPath(base, ...path) {
|
||||
return (0, _urlJoin.default)(base, ...path);
|
||||
}
|
||||
Reference in New Issue
Block a user