From 813b6d9f0df04cab89a43226d7f387be6e4541ee Mon Sep 17 00:00:00 2001 From: oscargross Date: Tue, 11 Jan 2022 09:06:16 -0300 Subject: [PATCH 1/4] style(preview_onFocus): try_add_borders_in_field_preview_when_edit_field_is_onFocus --- .../netlify-cms-core/src/actions/entries.ts | 14 +++++++++++++ .../src/components/Editor/Editor.js | 9 +++++++++ .../Editor/EditorControlPane/EditorControl.js | 3 +++ .../EditorControlPane/EditorControlPane.js | 4 +++- .../src/components/Editor/EditorInterface.js | 3 +++ .../src/reducers/entryDraft.js | 20 ++++++++++++++++++- 6 files changed, 51 insertions(+), 2 deletions(-) diff --git a/netlify-cms@2/packages/netlify-cms-core/src/actions/entries.ts b/netlify-cms@2/packages/netlify-cms-core/src/actions/entries.ts index 6eaa8d1..172d170 100644 --- a/netlify-cms@2/packages/netlify-cms-core/src/actions/entries.ts +++ b/netlify-cms@2/packages/netlify-cms-core/src/actions/entries.ts @@ -69,6 +69,7 @@ export const DRAFT_CREATE_FROM_ENTRY = 'DRAFT_CREATE_FROM_ENTRY'; export const DRAFT_CREATE_EMPTY = 'DRAFT_CREATE_EMPTY'; export const DRAFT_DISCARD = 'DRAFT_DISCARD'; export const DRAFT_CHANGE_FIELD = 'DRAFT_CHANGE_FIELD'; +export const DRAFT_FOCUS_FIELD = 'DRAFT_FOCUS_FIELD'; export const DRAFT_VALIDATION_ERRORS = 'DRAFT_VALIDATION_ERRORS'; export const DRAFT_CLEAR_ERRORS = 'DRAFT_CLEAR_ERRORS'; export const DRAFT_LOCAL_BACKUP_RETRIEVED = 'DRAFT_LOCAL_BACKUP_RETRIEVED'; @@ -433,6 +434,19 @@ export function changeDraftField({ }; } +export function focusDraftField({ + field, + value, +}: { + field: EntryField; + value: string; +}) { + return { + type: DRAFT_FOCUS_FIELD, + payload: { field, value }, + }; +} + export function changeDraftFieldValidation( uniquefieldId: string, errors: { type: string; parentIds: string[]; message: string }[], diff --git a/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/Editor.js b/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/Editor.js index 47f3ade..24f23d0 100644 --- a/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/Editor.js +++ b/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/Editor.js @@ -15,6 +15,7 @@ import { createEmptyDraft, discardDraft, changeDraftField, + focusDraftField, changeDraftFieldValidation, persistEntry, deleteEntry, @@ -39,6 +40,7 @@ import withWorkflow from './withWorkflow'; export class Editor extends React.Component { static propTypes = { changeDraftField: PropTypes.func.isRequired, + focusDraftField: PropTypes.func.isRequired, changeDraftFieldValidation: PropTypes.func.isRequired, collection: ImmutablePropTypes.map.isRequired, createDraftDuplicateFromEntry: PropTypes.func.isRequired, @@ -201,6 +203,11 @@ export class Editor extends React.Component { this.props.changeDraftField({ field, value, metadata, entries, i18n }); }; + handleFocusDraftField = (field, value, metadata, i18n) => { + const entries = [this.props.unPublishedEntry, this.props.publishedEntry].filter(Boolean); + this.props.focusDraftField({ field, value, metadata, entries, i18n }); + }; + handleChangeStatus = newStatusName => { const { entryDraft, updateUnpublishedEntryStatus, collection, slug, currentStatus, t } = this.props; @@ -383,6 +390,7 @@ export class Editor extends React.Component { fieldsMetaData={entryDraft.get('fieldsMetaData')} fieldsErrors={entryDraft.get('fieldsErrors')} onChange={this.handleChangeDraftField} + onFocus={this.handleFocusDraftField} onValidate={changeDraftFieldValidation} onPersist={this.handlePersistEntry} onDelete={this.handleDeleteEntry} @@ -471,6 +479,7 @@ function mapStateToProps(state, ownProps) { const mapDispatchToProps = { changeDraftField, + focusDraftField, changeDraftFieldValidation, loadEntry, loadEntries, diff --git a/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js b/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js index e3ad8ee..7dea5d8 100644 --- a/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js +++ b/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js @@ -119,6 +119,7 @@ class EditorControl extends React.Component { mediaPaths: ImmutablePropTypes.map.isRequired, boundGetAsset: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired, + onFocus: PropTypes.func.isRequired, openMediaLibrary: PropTypes.func.isRequired, addAsset: PropTypes.func.isRequired, removeInsertedMedia: PropTypes.func.isRequired, @@ -177,6 +178,7 @@ class EditorControl extends React.Component { mediaPaths, boundGetAsset, onChange, + onFocus, openMediaLibrary, clearMediaControl, removeMediaControl, @@ -220,6 +222,7 @@ class EditorControl extends React.Component { {({ css, cx }) => ( onFocus(field)} className={className} css={css` ${isHidden && styleStrings.hidden}; diff --git a/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControlPane.js b/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControlPane.js index 8711c87..eb6b603 100644 --- a/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControlPane.js +++ b/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControlPane.js @@ -166,7 +166,7 @@ export default class ControlPane extends React.Component { }; render() { - const { collection, entry, fields, fieldsMetaData, fieldsErrors, onChange, onValidate, t } = + const { collection, entry, fields, fieldsMetaData, fieldsErrors, onChange, onFocus, onValidate, t } = this.props; if (!collection || !fields) { @@ -227,6 +227,7 @@ export default class ControlPane extends React.Component { console.log('newMeta', newMetadata); onChange(field, newValue, newMetadata, i18n); }} + onFocus={(item) => onFocus(item)} onValidate={onValidate} processControlRef={this.controlRef.bind(this)} controlRef={this.controlRef} @@ -251,5 +252,6 @@ ControlPane.propTypes = { fieldsMetaData: ImmutablePropTypes.map.isRequired, fieldsErrors: ImmutablePropTypes.map.isRequired, onChange: PropTypes.func.isRequired, + onFocus: PropTypes.func.isRequired, onValidate: PropTypes.func.isRequired, }; diff --git a/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorInterface.js b/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorInterface.js index 0baefea..d67ea10 100644 --- a/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorInterface.js +++ b/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorInterface.js @@ -209,6 +209,7 @@ class EditorInterface extends Component { fieldsMetaData, fieldsErrors, onChange, + onFocus, showDelete, onDelete, onDeleteUnpublishedChanges, @@ -247,6 +248,7 @@ class EditorInterface extends Component { fieldsMetaData, fieldsErrors, onChange, + onFocus, onValidate, }; @@ -405,6 +407,7 @@ EditorInterface.propTypes = { fieldsMetaData: ImmutablePropTypes.map.isRequired, fieldsErrors: ImmutablePropTypes.map.isRequired, onChange: PropTypes.func.isRequired, + onFocus: PropTypes.func.isRequired, onValidate: PropTypes.func.isRequired, onPersist: PropTypes.func.isRequired, showDelete: PropTypes.bool.isRequired, diff --git a/netlify-cms@2/packages/netlify-cms-core/src/reducers/entryDraft.js b/netlify-cms@2/packages/netlify-cms-core/src/reducers/entryDraft.js index c82b1ab..54a5918 100644 --- a/netlify-cms@2/packages/netlify-cms-core/src/reducers/entryDraft.js +++ b/netlify-cms@2/packages/netlify-cms-core/src/reducers/entryDraft.js @@ -8,6 +8,7 @@ import { DRAFT_CREATE_EMPTY, DRAFT_DISCARD, DRAFT_CHANGE_FIELD, + DRAFT_FOCUS_FIELD, DRAFT_VALIDATION_ERRORS, DRAFT_CLEAR_ERRORS, DRAFT_LOCAL_BACKUP_RETRIEVED, @@ -117,10 +118,27 @@ function entryDraftReducer(state = Map(), action) { state.set( 'hasChanged', !entries.some(e => newData.equals(e.get(...dataPath))) || - !entries.some(e => newMeta.equals(e.get('meta'))), + !entries.some(e => newMeta.equals(e.get('meta'))), ); }); } + case DRAFT_FOCUS_FIELD: { + return state.withMutations(state => { + const { field, value } = action.payload; + const name = field.get('name'); + const meta = field.get('meta'); + + if (meta) { + state.setIn(['entry', 'meta', name], value); + const newData = state.getIn(['entry', ...dataPath]); + const newMeta = state.getIn(['entry', 'meta']); + state.set( + 'hasFocused', + !entries.some(e => newMeta.equals(e.get('meta'))), + ); + }; + }) + } case DRAFT_VALIDATION_ERRORS: if (action.payload.errors.length === 0) { return state.deleteIn(['fieldsErrors', action.payload.uniquefieldId]); From 5de407ea478b579751efab39d1799ec67cd1352c Mon Sep 17 00:00:00 2001 From: oscargross Date: Mon, 17 Jan 2022 10:25:01 -0300 Subject: [PATCH 2/4] feat(preview): prop_onFocus_in_all_widgets --- netlify-cms@2/dev-test/config.yml | 18 +++--- .../netlify-cms-core/src/actions/entries.ts | 36 +++++++----- .../Editor/EditorControlPane/EditorControl.js | 4 +- .../EditorControlPane/EditorControlPane.js | 5 +- .../Editor/EditorControlPane/Widget.js | 4 ++ .../src/reducers/entryDraft.js | 29 ++++++---- .../src/CodeControl.js | 1 + .../src/CodePreview.js | 7 ++- .../src/SettingsPane.js | 3 +- .../src/ColorControl.js | 13 ++++- .../src/ColorPreview.js | 4 +- .../src/DateControl.js | 17 ++++++ .../src/DatePreview.js | 4 +- .../src/DateTimeControl.js | 16 ++++++ .../src/DateTimePreview.js | 4 +- .../src/FilePreview.js | 4 +- .../src/ImagePreview.js | 4 +- .../src/ListControl.js | 14 ++++- .../src/MarkdownControl/index.js | 4 ++ .../src/MarkdownPreview.js | 4 +- .../src/NumberControl.js | 18 +++++- .../src/NumberPreview.js | 6 +- .../src/ObjectControl.js | 3 + .../src/ObjectPreview.js | 4 +- .../src/RelationControl.js | 56 +++++++++++++++---- .../src/RelationPreview.js | 4 +- .../src/SelectControl.js | 23 +++++++- .../src/SelectPreview.js | 8 +-- .../src/StringControl.js | 10 +++- .../src/StringPreview.js | 6 +- .../src/TextControl.js | 5 +- .../src/TextPreview.js | 6 +- 32 files changed, 257 insertions(+), 87 deletions(-) diff --git a/netlify-cms@2/dev-test/config.yml b/netlify-cms@2/dev-test/config.yml index 2ffe504..0e27a13 100644 --- a/netlify-cms@2/dev-test/config.yml +++ b/netlify-cms@2/dev-test/config.yml @@ -110,16 +110,16 @@ collections: # A list of collections the CMS should be able to edit folder: '_sink' create: true fields: - - label: 'Related Post' - name: 'post' - widget: 'relationKitchenSinkPost' - collection: 'posts' - display_fields: ['title', 'date'] - search_fields: ['title', 'body'] - value_field: 'title' + # - label: 'Related Post' + # name: 'post' + # widget: 'relationKitchenSinkPost' + # collection: 'posts' + # display_fields: ['title', 'date'] + # search_fields: ['title', 'body'] + # value_field: 'title' - { label: 'Title', name: 'title', widget: 'string' } - - { label: 'Boolean', name: 'boolean', widget: 'boolean', default: true } - - { label: 'Map', name: 'map', widget: 'map' } + # - { label: 'Boolean', name: 'boolean', widget: 'boolean', default: true } + # - { label: 'Map', name: 'map', widget: 'map' } - { label: 'Text', name: 'text', widget: 'text', hint: 'Plain text, not markdown' } - { label: 'Number', name: 'number', widget: 'number', hint: 'To infinity and beyond!' } - { label: 'Markdown', name: 'markdown', widget: 'markdown' } diff --git a/netlify-cms@2/packages/netlify-cms-core/src/actions/entries.ts b/netlify-cms@2/packages/netlify-cms-core/src/actions/entries.ts index 172d170..d5b411a 100644 --- a/netlify-cms@2/packages/netlify-cms-core/src/actions/entries.ts +++ b/netlify-cms@2/packages/netlify-cms-core/src/actions/entries.ts @@ -437,13 +437,23 @@ export function changeDraftField({ export function focusDraftField({ field, value, + metadata, + entries, + i18n, }: { field: EntryField; value: string; + metadata: Record; + entries: EntryMap[]; + i18n?: { + currentLocale: string; + defaultLocale: string; + locales: string[]; + }; }) { return { type: DRAFT_FOCUS_FIELD, - payload: { field, value }, + payload: { field, value, metadata, entries, i18n }, }; } @@ -624,7 +634,7 @@ export function loadEntries(collection: Collection, page = 0) { entries: EntryValue[]; } = await (loadAllEntries ? // nested collections require all entries to construct the tree - provider.listAllEntries(collection).then((entries: EntryValue[]) => ({ entries })) + provider.listAllEntries(collection).then((entries: EntryValue[]) => ({ entries })) : provider.listEntries(collection, page)); response = { ...response, @@ -636,10 +646,10 @@ export function loadEntries(collection: Collection, page = 0) { // cursor, which behaves identically to no cursor at all. cursor: integration ? Cursor.create({ - actions: ['next'], - meta: { usingOldPaginationAPI: true }, - data: { nextPage: page + 1 }, - }) + actions: ['next'], + meta: { usingOldPaginationAPI: true }, + data: { nextPage: page + 1 }, + }) : Cursor.create(response.cursor), }; @@ -790,13 +800,13 @@ export function createEmptyDraft(collection: Collection, search: string) { interface DraftEntryData { [name: string]: - | string - | null - | boolean - | List - | DraftEntryData - | DraftEntryData[] - | (string | DraftEntryData | boolean | List)[]; + | string + | null + | boolean + | List + | DraftEntryData + | DraftEntryData[] + | (string | DraftEntryData | boolean | List)[]; } export function createEmptyDraftData( diff --git a/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js b/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js index 7dea5d8..4b6e412 100644 --- a/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js +++ b/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js @@ -119,7 +119,7 @@ class EditorControl extends React.Component { mediaPaths: ImmutablePropTypes.map.isRequired, boundGetAsset: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired, - onFocus: PropTypes.func.isRequired, + onFocus: PropTypes.func, openMediaLibrary: PropTypes.func.isRequired, addAsset: PropTypes.func.isRequired, removeInsertedMedia: PropTypes.func.isRequired, @@ -222,7 +222,6 @@ class EditorControl extends React.Component { {({ css, cx }) => ( onFocus(field)} className={className} css={css` ${isHidden && styleStrings.hidden}; @@ -293,6 +292,7 @@ class EditorControl extends React.Component { mediaPaths={mediaPaths} metadata={metadata} onChange={(newValue, newMetadata) => onChange(field, newValue, newMetadata)} + onFocus={(newValue, newMetadata) => onFocus(field, newValue, newMetadata)} onValidate={onValidate && partial(onValidate, this.uniqueFieldId)} onOpenMediaLibrary={openMediaLibrary} onClearMediaControl={clearMediaControl} diff --git a/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControlPane.js b/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControlPane.js index eb6b603..308125e 100644 --- a/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControlPane.js +++ b/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControlPane.js @@ -227,7 +227,10 @@ export default class ControlPane extends React.Component { console.log('newMeta', newMetadata); onChange(field, newValue, newMetadata, i18n); }} - onFocus={(item) => onFocus(item)} + onFocus={(field, newValue, newMetadata) => { + console.log('newMeta', newMetadata); + onFocus(field, newValue, newMetadata, i18n); + }} onValidate={onValidate} processControlRef={this.controlRef.bind(this)} controlRef={this.controlRef} diff --git a/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/Widget.js b/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/Widget.js index f6093a4..048ac7c 100644 --- a/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/Widget.js +++ b/netlify-cms@2/packages/netlify-cms-core/src/components/Editor/EditorControlPane/Widget.js @@ -43,6 +43,8 @@ export default class Widget extends Component { metadata: ImmutablePropTypes.map, fieldsErrors: ImmutablePropTypes.map, onChange: PropTypes.func.isRequired, + onFocus: PropTypes.func.isRequired, + onValidate: PropTypes.func, onOpenMediaLibrary: PropTypes.func.isRequired, onClearMediaControl: PropTypes.func.isRequired, @@ -257,6 +259,7 @@ export default class Widget extends Component { mediaPaths, metadata, onChange, + onFocus, onValidateObject, onOpenMediaLibrary, onRemoveMediaControl, @@ -303,6 +306,7 @@ export default class Widget extends Component { mediaPaths, metadata, onChange, + onFocus, onChangeObject: this.onChangeObject, onValidateObject, onOpenMediaLibrary, diff --git a/netlify-cms@2/packages/netlify-cms-core/src/reducers/entryDraft.js b/netlify-cms@2/packages/netlify-cms-core/src/reducers/entryDraft.js index 54a5918..5cf4e06 100644 --- a/netlify-cms@2/packages/netlify-cms-core/src/reducers/entryDraft.js +++ b/netlify-cms@2/packages/netlify-cms-core/src/reducers/entryDraft.js @@ -124,20 +124,25 @@ function entryDraftReducer(state = Map(), action) { } case DRAFT_FOCUS_FIELD: { return state.withMutations(state => { - const { field, value } = action.payload; + + const { field, value, metadata, entries, i18n } = action.payload; const name = field.get('name'); - const meta = field.get('meta'); + window.previewStyle = { + name: field.get('name'), + label: field.get('label'), + } + const dataPath = (i18n && getDataPath(i18n.currentLocale, i18n.defaultLocale)) || ['data']; + state.setIn(['entry', 'meta', name], value); - if (meta) { - state.setIn(['entry', 'meta', name], value); - const newData = state.getIn(['entry', ...dataPath]); - const newMeta = state.getIn(['entry', 'meta']); - state.set( - 'hasFocused', - !entries.some(e => newMeta.equals(e.get('meta'))), - ); - }; - }) + state.mergeDeepIn(['fieldsMetaData'], fromJS(metadata)); + const newData = state.getIn(['entry', ...dataPath]); + const newMeta = state.getIn(['entry', 'meta']); + state.set( + 'hasFocused', + !entries.some(e => newData.equals(e.get(...dataPath))) || + !entries.some(e => newMeta.equals(e.get('meta'))), + ); + }); } case DRAFT_VALIDATION_ERRORS: if (action.payload.errors.length === 0) { diff --git a/netlify-cms@2/packages/netlify-cms-widget-code/src/CodeControl.js b/netlify-cms@2/packages/netlify-cms-widget-code/src/CodeControl.js index ad5b0d2..630cde2 100644 --- a/netlify-cms@2/packages/netlify-cms-widget-code/src/CodeControl.js +++ b/netlify-cms@2/packages/netlify-cms-widget-code/src/CodeControl.js @@ -64,6 +64,7 @@ export default class CodeControl extends React.Component { static propTypes = { field: ImmutablePropTypes.map.isRequired, onChange: PropTypes.func.isRequired, + onFocus: PropTypes.func.isRequired, value: PropTypes.node, forID: PropTypes.string.isRequired, classNameWrapper: PropTypes.string.isRequired, diff --git a/netlify-cms@2/packages/netlify-cms-widget-code/src/CodePreview.js b/netlify-cms@2/packages/netlify-cms-widget-code/src/CodePreview.js index 46da098..13a9a27 100644 --- a/netlify-cms@2/packages/netlify-cms-widget-code/src/CodePreview.js +++ b/netlify-cms@2/packages/netlify-cms-widget-code/src/CodePreview.js @@ -16,7 +16,12 @@ function toValue(value, field) { function CodePreview(props) { return ( - +
         {toValue(props.value, props.field)}
       
diff --git a/netlify-cms@2/packages/netlify-cms-widget-code/src/SettingsPane.js b/netlify-cms@2/packages/netlify-cms-widget-code/src/SettingsPane.js index c683afd..95f5da6 100644 --- a/netlify-cms@2/packages/netlify-cms-widget-code/src/SettingsPane.js +++ b/netlify-cms@2/packages/netlify-cms-widget-code/src/SettingsPane.js @@ -39,7 +39,7 @@ const SettingsSectionTitle = styled.h3` } `; -function SettingsSelect({ value, options, onChange, forID, type, autoFocus }) { +function SettingsSelect({ value, options, onChange, forID, type, autoFocus, onFocus }) { return ( ); diff --git a/netlify-cms@2/packages/netlify-cms-widget-string/src/StringPreview.js b/netlify-cms@2/packages/netlify-cms-widget-string/src/StringPreview.js index 4e591b0..0998b5e 100644 --- a/netlify-cms@2/packages/netlify-cms-widget-string/src/StringPreview.js +++ b/netlify-cms@2/packages/netlify-cms-widget-string/src/StringPreview.js @@ -2,8 +2,10 @@ import React from 'react'; import PropTypes from 'prop-types'; import { WidgetPreviewContainer } from 'netlify-cms-ui-default'; -function StringPreview({ value }) { - return {value}; +function StringPreview({ value, field }) { + return {value}; } StringPreview.propTypes = { diff --git a/netlify-cms@2/packages/netlify-cms-widget-text/src/TextControl.js b/netlify-cms@2/packages/netlify-cms-widget-text/src/TextControl.js index 26cbe44..6f0beba 100644 --- a/netlify-cms@2/packages/netlify-cms-widget-text/src/TextControl.js +++ b/netlify-cms@2/packages/netlify-cms-widget-text/src/TextControl.js @@ -5,6 +5,7 @@ import Textarea from 'react-textarea-autosize'; export default class TextControl extends React.Component { static propTypes = { onChange: PropTypes.func.isRequired, + onFocus: PropTypes.func.isRequired, forID: PropTypes.string, value: PropTypes.node, classNameWrapper: PropTypes.string.isRequired, @@ -28,7 +29,7 @@ export default class TextControl extends React.Component { } render() { - const { forID, value, onChange, classNameWrapper, setActiveStyle, setInactiveStyle } = + const { forID, value, onChange, classNameWrapper, setActiveStyle, setInactiveStyle, onFocus } = this.props; return ( @@ -36,7 +37,7 @@ export default class TextControl extends React.Component { id={forID} value={value || ''} className={classNameWrapper} - onFocus={setActiveStyle} + onFocus={e => { onFocus(e.target.value); this.props.setActiveStyle() }} onBlur={setInactiveStyle} minRows={5} css={{ fontFamily: 'inherit' }} diff --git a/netlify-cms@2/packages/netlify-cms-widget-text/src/TextPreview.js b/netlify-cms@2/packages/netlify-cms-widget-text/src/TextPreview.js index ec5fb8f..61098b8 100644 --- a/netlify-cms@2/packages/netlify-cms-widget-text/src/TextPreview.js +++ b/netlify-cms@2/packages/netlify-cms-widget-text/src/TextPreview.js @@ -2,8 +2,10 @@ import React from 'react'; import PropTypes from 'prop-types'; import { WidgetPreviewContainer } from 'netlify-cms-ui-default'; -function TextPreview({ value }) { - return {value}; +function TextPreview({ value, field }) { + return {value}; } TextPreview.propTypes = { From fd6098cc02bff047d6079162035a61987b638640 Mon Sep 17 00:00:00 2001 From: oscargross Date: Mon, 17 Jan 2022 10:26:21 -0300 Subject: [PATCH 3/4] feat(preview): prop_onFocus_in_all_widgets --- netlify-cms@2/dev-test/config.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/netlify-cms@2/dev-test/config.yml b/netlify-cms@2/dev-test/config.yml index 0e27a13..2ffe504 100644 --- a/netlify-cms@2/dev-test/config.yml +++ b/netlify-cms@2/dev-test/config.yml @@ -110,16 +110,16 @@ collections: # A list of collections the CMS should be able to edit folder: '_sink' create: true fields: - # - label: 'Related Post' - # name: 'post' - # widget: 'relationKitchenSinkPost' - # collection: 'posts' - # display_fields: ['title', 'date'] - # search_fields: ['title', 'body'] - # value_field: 'title' + - label: 'Related Post' + name: 'post' + widget: 'relationKitchenSinkPost' + collection: 'posts' + display_fields: ['title', 'date'] + search_fields: ['title', 'body'] + value_field: 'title' - { label: 'Title', name: 'title', widget: 'string' } - # - { label: 'Boolean', name: 'boolean', widget: 'boolean', default: true } - # - { label: 'Map', name: 'map', widget: 'map' } + - { label: 'Boolean', name: 'boolean', widget: 'boolean', default: true } + - { label: 'Map', name: 'map', widget: 'map' } - { label: 'Text', name: 'text', widget: 'text', hint: 'Plain text, not markdown' } - { label: 'Number', name: 'number', widget: 'number', hint: 'To infinity and beyond!' } - { label: 'Markdown', name: 'markdown', widget: 'markdown' } From 696236e021c19d653becf62c80a89f5f8d678cda Mon Sep 17 00:00:00 2001 From: oscargross Date: Tue, 18 Jan 2022 09:23:46 -0300 Subject: [PATCH 4/4] fix(global_var): change_name_global_var --- .../packages/netlify-cms-core/src/reducers/entryDraft.js | 2 +- .../packages/netlify-cms-widget-code/src/CodePreview.js | 2 +- .../netlify-cms-widget-colorstring/src/ColorPreview.js | 2 +- .../packages/netlify-cms-widget-date/src/DatePreview.js | 2 +- .../netlify-cms-widget-datetime/src/DateTimePreview.js | 2 +- .../packages/netlify-cms-widget-file/src/FilePreview.js | 4 ++-- .../packages/netlify-cms-widget-image/src/ImagePreview.js | 4 ++-- .../netlify-cms-widget-markdown/src/MarkdownPreview.js | 2 +- .../packages/netlify-cms-widget-number/src/NumberPreview.js | 2 +- .../packages/netlify-cms-widget-object/src/ObjectPreview.js | 2 +- .../netlify-cms-widget-relation/src/RelationPreview.js | 2 +- .../packages/netlify-cms-widget-select/src/SelectPreview.js | 2 +- .../packages/netlify-cms-widget-string/src/StringPreview.js | 2 +- .../packages/netlify-cms-widget-text/src/TextPreview.js | 2 +- 14 files changed, 16 insertions(+), 16 deletions(-) diff --git a/netlify-cms@2/packages/netlify-cms-core/src/reducers/entryDraft.js b/netlify-cms@2/packages/netlify-cms-core/src/reducers/entryDraft.js index 5cf4e06..2d287df 100644 --- a/netlify-cms@2/packages/netlify-cms-core/src/reducers/entryDraft.js +++ b/netlify-cms@2/packages/netlify-cms-core/src/reducers/entryDraft.js @@ -127,7 +127,7 @@ function entryDraftReducer(state = Map(), action) { const { field, value, metadata, entries, i18n } = action.payload; const name = field.get('name'); - window.previewStyle = { + window.storefrontCmsFocusField = { name: field.get('name'), label: field.get('label'), } diff --git a/netlify-cms@2/packages/netlify-cms-widget-code/src/CodePreview.js b/netlify-cms@2/packages/netlify-cms-widget-code/src/CodePreview.js index 13a9a27..23e19fc 100644 --- a/netlify-cms@2/packages/netlify-cms-widget-code/src/CodePreview.js +++ b/netlify-cms@2/packages/netlify-cms-widget-code/src/CodePreview.js @@ -19,7 +19,7 @@ function CodePreview(props) {
diff --git a/netlify-cms@2/packages/netlify-cms-widget-colorstring/src/ColorPreview.js b/netlify-cms@2/packages/netlify-cms-widget-colorstring/src/ColorPreview.js
index 6faaa25..43515e4 100644
--- a/netlify-cms@2/packages/netlify-cms-widget-colorstring/src/ColorPreview.js
+++ b/netlify-cms@2/packages/netlify-cms-widget-colorstring/src/ColorPreview.js
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
 import { WidgetPreviewContainer } from 'netlify-cms-ui-default';
 
 function ColorPreview({ value, field }) {
-  return {value};
+  return {value};
 }
 
 ColorPreview.propTypes = {
diff --git a/netlify-cms@2/packages/netlify-cms-widget-date/src/DatePreview.js b/netlify-cms@2/packages/netlify-cms-widget-date/src/DatePreview.js
index 35efbbb..a68edc6 100644
--- a/netlify-cms@2/packages/netlify-cms-widget-date/src/DatePreview.js
+++ b/netlify-cms@2/packages/netlify-cms-widget-date/src/DatePreview.js
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
 import { WidgetPreviewContainer } from 'netlify-cms-ui-default';
 
 function DatePreview({ value, field }) {
-  return {value ? value.toString() : null};
+  return {value ? value.toString() : null};
 }
 
 DatePreview.propTypes = {
diff --git a/netlify-cms@2/packages/netlify-cms-widget-datetime/src/DateTimePreview.js b/netlify-cms@2/packages/netlify-cms-widget-datetime/src/DateTimePreview.js
index 35efbbb..a68edc6 100644
--- a/netlify-cms@2/packages/netlify-cms-widget-datetime/src/DateTimePreview.js
+++ b/netlify-cms@2/packages/netlify-cms-widget-datetime/src/DateTimePreview.js
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
 import { WidgetPreviewContainer } from 'netlify-cms-ui-default';
 
 function DatePreview({ value, field }) {
-  return {value ? value.toString() : null};
+  return {value ? value.toString() : null};
 }
 
 DatePreview.propTypes = {
diff --git a/netlify-cms@2/packages/netlify-cms-widget-file/src/FilePreview.js b/netlify-cms@2/packages/netlify-cms-widget-file/src/FilePreview.js
index 3ebf796..2340630 100644
--- a/netlify-cms@2/packages/netlify-cms-widget-file/src/FilePreview.js
+++ b/netlify-cms@2/packages/netlify-cms-widget-file/src/FilePreview.js
@@ -25,14 +25,14 @@ function FileLinkList({ values, getAsset, field }) {
 function FileContent(props) {
   const { value, getAsset, field } = props;
   if (Array.isArray(value) || List.isList(value)) {
-    return ;
+    return ;
   }
   return ;
 }
 
 function FilePreview(props) {
   return (
-    
+    
       {props.value ?  : null}
     
   );
diff --git a/netlify-cms@2/packages/netlify-cms-widget-image/src/ImagePreview.js b/netlify-cms@2/packages/netlify-cms-widget-image/src/ImagePreview.js
index 1dd9982..c0042bc 100644
--- a/netlify-cms@2/packages/netlify-cms-widget-image/src/ImagePreview.js
+++ b/netlify-cms@2/packages/netlify-cms-widget-image/src/ImagePreview.js
@@ -11,7 +11,7 @@ const StyledImage = styled(({ src }) => ;
+  return ;
 }
 
 function ImagePreviewContent(props) {
@@ -26,7 +26,7 @@ function ImagePreviewContent(props) {
 
 function ImagePreview(props) {
   return (
-    
+    
       {props.value ?  : null}
     
   );
diff --git a/netlify-cms@2/packages/netlify-cms-widget-markdown/src/MarkdownPreview.js b/netlify-cms@2/packages/netlify-cms-widget-markdown/src/MarkdownPreview.js
index 867788f..bfe23f6 100644
--- a/netlify-cms@2/packages/netlify-cms-widget-markdown/src/MarkdownPreview.js
+++ b/netlify-cms@2/packages/netlify-cms-widget-markdown/src/MarkdownPreview.js
@@ -21,7 +21,7 @@ class MarkdownPreview extends React.Component {
     const toRender = field?.get('sanitize_preview', false) ? DOMPurify.sanitize(html) : html;
 
     return ;
   }
 }
diff --git a/netlify-cms@2/packages/netlify-cms-widget-number/src/NumberPreview.js b/netlify-cms@2/packages/netlify-cms-widget-number/src/NumberPreview.js
index 0cb501b..930c2f0 100644
--- a/netlify-cms@2/packages/netlify-cms-widget-number/src/NumberPreview.js
+++ b/netlify-cms@2/packages/netlify-cms-widget-number/src/NumberPreview.js
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
 import { WidgetPreviewContainer } from 'netlify-cms-ui-default';
 
 function NumberPreview({ value, field }) {
-  return {value};
+  return {value};
 }
 
 NumberPreview.propTypes = {
diff --git a/netlify-cms@2/packages/netlify-cms-widget-object/src/ObjectPreview.js b/netlify-cms@2/packages/netlify-cms-widget-object/src/ObjectPreview.js
index cbfb12e..05007df 100644
--- a/netlify-cms@2/packages/netlify-cms-widget-object/src/ObjectPreview.js
+++ b/netlify-cms@2/packages/netlify-cms-widget-object/src/ObjectPreview.js
@@ -5,7 +5,7 @@ import { WidgetPreviewContainer } from 'netlify-cms-ui-default';
 function ObjectPreview({ field }) {
   return (
     
       {(field && field.get('fields')) || field.get('field') || null}
     
diff --git a/netlify-cms@2/packages/netlify-cms-widget-relation/src/RelationPreview.js b/netlify-cms@2/packages/netlify-cms-widget-relation/src/RelationPreview.js
index e2d21e4..0a6891b 100644
--- a/netlify-cms@2/packages/netlify-cms-widget-relation/src/RelationPreview.js
+++ b/netlify-cms@2/packages/netlify-cms-widget-relation/src/RelationPreview.js
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
 import { WidgetPreviewContainer } from 'netlify-cms-ui-default';
 
 function RelationPreview({ value, field }) {
-  return {value};
+  return {value};
 }
 
 RelationPreview.propTypes = {
diff --git a/netlify-cms@2/packages/netlify-cms-widget-select/src/SelectPreview.js b/netlify-cms@2/packages/netlify-cms-widget-select/src/SelectPreview.js
index 01adc37..2000a11 100644
--- a/netlify-cms@2/packages/netlify-cms-widget-select/src/SelectPreview.js
+++ b/netlify-cms@2/packages/netlify-cms-widget-select/src/SelectPreview.js
@@ -16,7 +16,7 @@ function ListPreview({ values }) {
 
 function SelectPreview(props) {
   return (
-    
+    
       {props.value && (List.isList(props.value) ?  : props.value)}
       {!props.value && null}
     
diff --git a/netlify-cms@2/packages/netlify-cms-widget-string/src/StringPreview.js b/netlify-cms@2/packages/netlify-cms-widget-string/src/StringPreview.js
index 0998b5e..bb64617 100644
--- a/netlify-cms@2/packages/netlify-cms-widget-string/src/StringPreview.js
+++ b/netlify-cms@2/packages/netlify-cms-widget-string/src/StringPreview.js
@@ -4,7 +4,7 @@ import { WidgetPreviewContainer } from 'netlify-cms-ui-default';
 
 function StringPreview({ value, field }) {
   return {value};
 }
 
diff --git a/netlify-cms@2/packages/netlify-cms-widget-text/src/TextPreview.js b/netlify-cms@2/packages/netlify-cms-widget-text/src/TextPreview.js
index 61098b8..deb06e4 100644
--- a/netlify-cms@2/packages/netlify-cms-widget-text/src/TextPreview.js
+++ b/netlify-cms@2/packages/netlify-cms-widget-text/src/TextPreview.js
@@ -4,7 +4,7 @@ import { WidgetPreviewContainer } from 'netlify-cms-ui-default';
 
 function TextPreview({ value, field }) {
   return {value};
 }