Merge branch 'main' into next
This commit is contained in:
commit
9872a0ddb7
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
||||||
"useWorkspaces": true,
|
"useWorkspaces": true,
|
||||||
"version": "1.2.8"
|
"version": "1.2.9"
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@staticcms/app",
|
"name": "@staticcms/app",
|
||||||
"version": "1.2.8",
|
"version": "1.2.9",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "Static CMS application.",
|
"description": "Static CMS application.",
|
||||||
"repository": "https://github.com/StaticJsCMS/static-cms",
|
"repository": "https://github.com/StaticJsCMS/static-cms",
|
||||||
@ -35,7 +35,7 @@
|
|||||||
"@babel/eslint-parser": "7.19.1",
|
"@babel/eslint-parser": "7.19.1",
|
||||||
"@babel/runtime": "7.21.0",
|
"@babel/runtime": "7.21.0",
|
||||||
"@emotion/babel-preset-css-prop": "11.10.0",
|
"@emotion/babel-preset-css-prop": "11.10.0",
|
||||||
"@staticcms/core": "^1.2.8",
|
"@staticcms/core": "^1.2.9",
|
||||||
"buffer": "6.0.3",
|
"buffer": "6.0.3",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@staticcms/core",
|
"name": "@staticcms/core",
|
||||||
"version": "1.2.8",
|
"version": "1.2.9",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "Static CMS core application.",
|
"description": "Static CMS core application.",
|
||||||
"repository": "https://github.com/StaticJsCMS/static-cms",
|
"repository": "https://github.com/StaticJsCMS/static-cms",
|
||||||
@ -112,7 +112,7 @@
|
|||||||
"jwt-decode": "3.1.2",
|
"jwt-decode": "3.1.2",
|
||||||
"localforage": "1.10.0",
|
"localforage": "1.10.0",
|
||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21",
|
||||||
"minimatch": "7.1.0",
|
"minimatch": "7.1.1",
|
||||||
"moment": "2.29.4",
|
"moment": "2.29.4",
|
||||||
"node-polyglot": "2.5.0",
|
"node-polyglot": "2.5.0",
|
||||||
"ol": "7.2.2",
|
"ol": "7.2.2",
|
||||||
@ -141,10 +141,10 @@
|
|||||||
"sanitize-filename": "1.6.3",
|
"sanitize-filename": "1.6.3",
|
||||||
"scheduler": "0.23.0",
|
"scheduler": "0.23.0",
|
||||||
"semaphore": "1.1.0",
|
"semaphore": "1.1.0",
|
||||||
"slate": "0.91.3",
|
"slate": "0.91.4",
|
||||||
"slate-history": "0.86.0",
|
"slate-history": "0.86.0",
|
||||||
"slate-hyperscript": "0.77.0",
|
"slate-hyperscript": "0.77.0",
|
||||||
"slate-react": "0.91.3",
|
"slate-react": "0.91.4",
|
||||||
"stream-browserify": "3.0.0",
|
"stream-browserify": "3.0.0",
|
||||||
"styled-components": "5.3.6",
|
"styled-components": "5.3.6",
|
||||||
"symbol-observable": "4.0.0",
|
"symbol-observable": "4.0.0",
|
||||||
|
@ -383,16 +383,16 @@ export function duplicateI18nFields(
|
|||||||
field: Field,
|
field: Field,
|
||||||
locales: string[],
|
locales: string[],
|
||||||
defaultLocale: string,
|
defaultLocale: string,
|
||||||
fieldPath: string[] = [field.name],
|
fieldPath: string,
|
||||||
) {
|
) {
|
||||||
const value = get(entryDraft, ['entry', 'data', ...fieldPath]);
|
const value = get(entryDraft, ['entry', 'data', ...fieldPath.split('.')]);
|
||||||
if (field.i18n === I18N_FIELD.DUPLICATE) {
|
if (field.i18n === I18N_FIELD.DUPLICATE) {
|
||||||
locales
|
locales
|
||||||
.filter(l => l !== defaultLocale)
|
.filter(l => l !== defaultLocale)
|
||||||
.forEach(l => {
|
.forEach(l => {
|
||||||
entryDraft = set(
|
entryDraft = set(
|
||||||
entryDraft,
|
entryDraft,
|
||||||
['entry', ...getDataPath(l, defaultLocale), ...fieldPath].join('.'),
|
['entry', ...getDataPath(l, defaultLocale), fieldPath].join('.'),
|
||||||
value,
|
value,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -400,10 +400,13 @@ export function duplicateI18nFields(
|
|||||||
|
|
||||||
if ('fields' in field && !Array.isArray(value)) {
|
if ('fields' in field && !Array.isArray(value)) {
|
||||||
field.fields?.forEach(field => {
|
field.fields?.forEach(field => {
|
||||||
entryDraft = duplicateI18nFields(entryDraft, field, locales, defaultLocale, [
|
entryDraft = duplicateI18nFields(
|
||||||
...fieldPath,
|
entryDraft,
|
||||||
field.name,
|
field,
|
||||||
]);
|
locales,
|
||||||
|
defaultLocale,
|
||||||
|
`${fieldPath}.${field.name}`,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import { DRAFT_CHANGE_FIELD, DRAFT_CREATE_EMPTY } from '@staticcms/core/constant
|
|||||||
import mockEntry from '@staticcms/core/lib/test-utils/mock-data/MockEntry';
|
import mockEntry from '@staticcms/core/lib/test-utils/mock-data/MockEntry';
|
||||||
import entryDraftReducer from '../entryDraft';
|
import entryDraftReducer from '../entryDraft';
|
||||||
|
|
||||||
|
import type { I18nSettings, StringOrTextField } from '@staticcms/core/interface';
|
||||||
import type { EntryDraftState } from '../entryDraft';
|
import type { EntryDraftState } from '../entryDraft';
|
||||||
|
|
||||||
describe('entryDraft', () => {
|
describe('entryDraft', () => {
|
||||||
@ -72,6 +73,119 @@ describe('entryDraft', () => {
|
|||||||
path1: ['newValue1', 'newValue2Updated', 'newValue3'],
|
path1: ['newValue1', 'newValue2Updated', 'newValue3'],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('i18n', () => {
|
||||||
|
it('duplicate values to other locales', () => {
|
||||||
|
const state = entryDraftReducer(startState, {
|
||||||
|
type: DRAFT_CHANGE_FIELD,
|
||||||
|
payload: {
|
||||||
|
path: 'path1.path2',
|
||||||
|
field: {
|
||||||
|
widget: 'string',
|
||||||
|
name: 'stringInput',
|
||||||
|
i18n: 'duplicate',
|
||||||
|
},
|
||||||
|
value: 'newValue',
|
||||||
|
i18n: {
|
||||||
|
locales: ['en', 'fr', 'es'],
|
||||||
|
defaultLocale: 'en',
|
||||||
|
currentLocale: 'en',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(state.entry?.data).toEqual({
|
||||||
|
path1: {
|
||||||
|
path2: 'newValue',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(state.entry?.i18n).toEqual({
|
||||||
|
fr: {
|
||||||
|
data: {
|
||||||
|
path1: {
|
||||||
|
path2: 'newValue',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
es: {
|
||||||
|
data: {
|
||||||
|
path1: {
|
||||||
|
path2: 'newValue',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should duplicate values to other locales for singleton list', () => {
|
||||||
|
const field: StringOrTextField = {
|
||||||
|
widget: 'string',
|
||||||
|
name: 'stringInput',
|
||||||
|
i18n: 'duplicate',
|
||||||
|
};
|
||||||
|
|
||||||
|
const i18n: I18nSettings = {
|
||||||
|
locales: ['en', 'fr', 'es'],
|
||||||
|
defaultLocale: 'en',
|
||||||
|
currentLocale: 'en',
|
||||||
|
};
|
||||||
|
|
||||||
|
let state = entryDraftReducer(startState, {
|
||||||
|
type: DRAFT_CHANGE_FIELD,
|
||||||
|
payload: {
|
||||||
|
path: 'path1',
|
||||||
|
field,
|
||||||
|
value: ['newValue1', 'newValue2', 'newValue3'],
|
||||||
|
i18n,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(state.entry?.data).toEqual({
|
||||||
|
path1: ['newValue1', 'newValue2', 'newValue3'],
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(state.entry?.i18n).toEqual({
|
||||||
|
fr: {
|
||||||
|
data: {
|
||||||
|
path1: ['newValue1', 'newValue2', 'newValue3'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
es: {
|
||||||
|
data: {
|
||||||
|
path1: ['newValue1', 'newValue2', 'newValue3'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
state = entryDraftReducer(state, {
|
||||||
|
type: DRAFT_CHANGE_FIELD,
|
||||||
|
payload: {
|
||||||
|
path: 'path1.1',
|
||||||
|
field,
|
||||||
|
value: 'newValue2Updated',
|
||||||
|
i18n,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(state.entry?.data).toEqual({
|
||||||
|
path1: ['newValue1', 'newValue2Updated', 'newValue3'],
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(state.entry?.i18n).toEqual({
|
||||||
|
fr: {
|
||||||
|
data: {
|
||||||
|
path1: ['newValue1', 'newValue2Updated', 'newValue3'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
es: {
|
||||||
|
data: {
|
||||||
|
path1: ['newValue1', 'newValue2Updated', 'newValue3'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -163,7 +163,7 @@ function entryDraftReducer(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (i18n) {
|
if (i18n) {
|
||||||
newState = duplicateI18nFields(newState, field, i18n.locales, i18n.defaultLocale);
|
newState = duplicateI18nFields(newState, field, i18n.locales, i18n.defaultLocale, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
const newData = get(newState.entry, dataPath) ?? {};
|
const newData = get(newState.entry, dataPath) ?? {};
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
"date-fns": "2.29.3",
|
"date-fns": "2.29.3",
|
||||||
"gray-matter": "4.0.3",
|
"gray-matter": "4.0.3",
|
||||||
"js-yaml": "4.1.0",
|
"js-yaml": "4.1.0",
|
||||||
"next": "13.2.0",
|
"next": "13.2.1",
|
||||||
"next-mdx-remote": "4.3.0",
|
"next-mdx-remote": "4.3.0",
|
||||||
"next-pwa": "5.6.0",
|
"next-pwa": "5.6.0",
|
||||||
"prismjs": "1.29.0",
|
"prismjs": "1.29.0",
|
||||||
@ -35,8 +35,8 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "7.21.0",
|
"@babel/core": "7.21.0",
|
||||||
"@emotion/eslint-plugin": "11.10.0",
|
"@emotion/eslint-plugin": "11.10.0",
|
||||||
"@next/bundle-analyzer": "13.2.0",
|
"@next/bundle-analyzer": "13.2.1",
|
||||||
"@next/eslint-plugin-next": "13.2.0",
|
"@next/eslint-plugin-next": "13.2.1",
|
||||||
"@types/js-yaml": "4.0.5",
|
"@types/js-yaml": "4.0.5",
|
||||||
"@types/node": "16.18.12",
|
"@types/node": "16.18.12",
|
||||||
"@types/prettier": "2.7.2",
|
"@types/prettier": "2.7.2",
|
||||||
@ -47,7 +47,7 @@
|
|||||||
"@typescript-eslint/parser": "5.53.0",
|
"@typescript-eslint/parser": "5.53.0",
|
||||||
"babel-eslint": "10.1.0",
|
"babel-eslint": "10.1.0",
|
||||||
"eslint": "8.34.0",
|
"eslint": "8.34.0",
|
||||||
"eslint-config-next": "13.2.0",
|
"eslint-config-next": "13.2.1",
|
||||||
"eslint-config-prettier": "8.6.0",
|
"eslint-config-prettier": "8.6.0",
|
||||||
"eslint-plugin-babel": "5.3.1",
|
"eslint-plugin-babel": "5.3.1",
|
||||||
"eslint-plugin-unicorn": "45.0.2",
|
"eslint-plugin-unicorn": "45.0.2",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user