-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Allow syncing the section id with the jump marker title (#2)
Resolves: #1
- Loading branch information
Showing
12 changed files
with
3,181 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
Resources/Private/JavaScript/AnchorView/src/SectionIdEditor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import React, {PureComponent} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import unescape from 'lodash.unescape'; | ||
import slugify from '@sindresorhus/slugify'; | ||
import {neos} from '@neos-project/neos-ui-decorators'; | ||
import {TextInput, IconButton} from '@neos-project/react-ui-components'; | ||
import style from './style.css'; | ||
|
||
const defaultOptions = { | ||
autoFocus: false, | ||
disabled: false, | ||
maxlength: null, | ||
readonly: false | ||
}; | ||
|
||
@neos(globalRegistry => ({ | ||
i18nRegistry: globalRegistry.get('i18n') | ||
})) | ||
export default class SectionIdEditor extends PureComponent { | ||
static propTypes = { | ||
className: PropTypes.string, | ||
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
commit: PropTypes.func.isRequired, | ||
options: PropTypes.object, | ||
onKeyPress: PropTypes.func, | ||
onEnterKey: PropTypes.func, | ||
id: PropTypes.string, | ||
|
||
i18nRegistry: PropTypes.object.isRequired | ||
}; | ||
|
||
static defaultProps = { | ||
options: {} | ||
}; | ||
|
||
render() { | ||
const { | ||
id, | ||
value, | ||
className, | ||
commit, | ||
options, | ||
i18nRegistry, | ||
onKeyPress, | ||
onEnterKey | ||
} = this.props; | ||
|
||
// Placeholder text must be unescaped in case html entities were used | ||
const placeholder = | ||
options && | ||
options.placeholder && | ||
i18nRegistry.translate(unescape(options.placeholder)); | ||
const finalOptions = Object.assign({}, defaultOptions, options); | ||
const showSyncButton = !( | ||
finalOptions.readonly || finalOptions.disabled | ||
); | ||
|
||
const sectionIdValue = options && options.sectionId ? options.sectionId : ''; | ||
const sectionId = slugify(sectionIdValue); | ||
|
||
return ( | ||
<div style={{display: 'flex'}} className={className}> | ||
<div style={{flexGrow: 1}}> | ||
<TextInput | ||
id={id} | ||
autoFocus={finalOptions.autoFocus} | ||
value={value} | ||
onChange={commit} | ||
placeholder={placeholder} | ||
onKeyPress={onKeyPress} | ||
onEnterKey={onEnterKey} | ||
disabled={finalOptions.disabled} | ||
maxLength={finalOptions.maxlength} | ||
readOnly={finalOptions.readonly} | ||
/> | ||
</div> | ||
{showSyncButton ? ( | ||
<div style={{flexGrow: 0}}> | ||
<IconButton | ||
id="neos-SectionIdEditor-sync" | ||
size="regular" | ||
icon="sync" | ||
onClick={() => commit(sectionId)} | ||
className={style.syncButton} | ||
style="neutral" | ||
hoverStyle="clean" | ||
title={i18nRegistry.translate( | ||
'CodeQ.JumpMarkers:NodeTypes.Mixin.SectionConfiguration:syncSectionId' | ||
)} | ||
/> | ||
</div> | ||
) : null} | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
import manifest from '@neos-project/neos-ui-extensibility'; | ||
import AnchorView from './AnchorView'; | ||
import SectionIdEditor from "./SectionIdEditor"; | ||
|
||
manifest('CodeQ.JumpMarkers:AnchorView', {}, globalRegistry => { | ||
const viewsRegistry = globalRegistry.get('inspector').get('views'); | ||
const viewsRegistry = globalRegistry.get('inspector').get('views'); | ||
const editorsRegistry = globalRegistry.get('inspector').get('editors'); | ||
|
||
viewsRegistry.set('CodeQ.JumpMarkers/Views/AnchorView', { | ||
component: AnchorView, | ||
hasOwnLabel: true | ||
}); | ||
viewsRegistry.set('CodeQ.JumpMarkers/Views/AnchorView', { | ||
component: AnchorView, | ||
hasOwnLabel: true | ||
}); | ||
|
||
editorsRegistry.set('CodeQ.JumpMarkers/Inspector/Editors/SegmentIdEditor', { | ||
component: SectionIdEditor | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.syncButton { | ||
outline: none !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.