Skip to content

Commit

Permalink
FEATURE: Allow syncing the section id with the jump marker title (#2)
Browse files Browse the repository at this point in the history
Resolves: #1
  • Loading branch information
Sebobo committed Sep 21, 2022
1 parent 4efce6f commit 4ab037b
Show file tree
Hide file tree
Showing 12 changed files with 3,181 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Configuration/NodeTypes.Mixin.SectionConfiguration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
label: i18n
inspector:
group: jumpmarker
editor: 'CodeQ.JumpMarkers/Inspector/Editors/SegmentIdEditor'
editorOptions:
sectionId: "ClientEval:node.properties.jumpMarkerTitle"
# Implements the most common subset of CodeQ.JumpMarkers:Integration.Helper.NodeAnchorId,
# fully implementing Carbon.String.urlize(value) would bloat the code too much
placeholder: "ClientEval: (node.properties.jumpMarkerTitle || '').replace('&nbsp;', '-').replace(/<[^>]*>/g, ' ').substr(0, 100).trim().toLowerCase().replaceAll('ä', 'ae').replaceAll('ü', 'ue').replaceAll('ö', 'oe').replaceAll('ß', 'ss').replace(/[^A-Za-z0-9\/]+/g, '-').trim().replace(/^.*?([a-z].*)$/, /*remove non-alpha chars from start*/ '$1').replace(/(.*)-$/, /*remove dashes from end*/ '$1')"
Expand Down
4 changes: 4 additions & 0 deletions Resources/Private/JavaScript/AnchorView/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
},
"neos": {
"buildTargetDirectory": "../../../Public/JavaScript/AnchorView"
},
"dependencies": {
"@sindresorhus/slugify": "^2.1.0",
"lodash.unescape": "^4.0.1"
}
}
96 changes: 96 additions & 0 deletions Resources/Private/JavaScript/AnchorView/src/SectionIdEditor.js
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>
);
}
}
16 changes: 11 additions & 5 deletions Resources/Private/JavaScript/AnchorView/src/manifest.js
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
});
});
3 changes: 3 additions & 0 deletions Resources/Private/JavaScript/AnchorView/src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.syncButton {
outline: none !important;
}
31 changes: 31 additions & 0 deletions Resources/Private/JavaScript/AnchorView/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,22 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@sindresorhus/slugify@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/slugify/-/slugify-2.1.0.tgz#1e252117008cd1121e4cdea9fc67767dd1653d25"
integrity sha512-gU3Gdm/V167BmUwIn8APHZ3SeeRVRUSOdXxnt7Q/JkUHLXaaTA/prYmoRumwsSitJZWUDYMzDWdWgrOdvE8IRQ==
dependencies:
"@sindresorhus/transliterate" "^1.0.0"
escape-string-regexp "^5.0.0"

"@sindresorhus/transliterate@^1.0.0":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/transliterate/-/transliterate-1.5.0.tgz#841109db51fe3158787c42a91c45c3ffea7589be"
integrity sha512-/sfSkoNelLq5riqNRp5uBjHIKBi1MWZk9ubRT1WiBQuTfmDf7BeQkph2DJzRB83QagMPHk2VDjuvpy0VuwyzdA==
dependencies:
escape-string-regexp "^5.0.0"
lodash.deburr "^4.1.0"

"@stylelint/postcss-css-in-js@^0.37.2":
version "0.37.2"
resolved "https://registry.yarnpkg.com/@stylelint/postcss-css-in-js/-/postcss-css-in-js-0.37.2.tgz#7e5a84ad181f4234a2480803422a47b8749af3d2"
Expand Down Expand Up @@ -2896,6 +2912,11 @@ escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=

escape-string-regexp@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz#4683126b500b61762f2dbebace1806e8be31b1c8"
integrity sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==

escodegen@^1.9.0:
version "1.14.3"
resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.14.3.tgz#4e7b81fba61581dc97582ed78cab7f0e8d63f503"
Expand Down Expand Up @@ -4573,6 +4594,11 @@ lodash.clonedeep@^4.5.0:
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"
integrity sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=

lodash.deburr@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/lodash.deburr/-/lodash.deburr-4.1.0.tgz#ddb1bbb3ef07458c0177ba07de14422cb033ff9b"
integrity sha512-m/M1U1f3ddMCs6Hq2tAsYThTBDaAKFDX3dwDo97GEYzamXi9SqUpjWi/Rrj/gf3X2n8ktwgZrlP1z6E3v/IExQ==

lodash.memoize@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
Expand Down Expand Up @@ -4603,6 +4629,11 @@ lodash.truncate@^4.4.2:
resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193"
integrity sha1-WjUNoLERO4N+z//VgSy+WNbq4ZM=

lodash.unescape@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/lodash.unescape/-/lodash.unescape-4.0.1.tgz#bf2249886ce514cda112fae9218cdc065211fc9c"
integrity sha512-DhhGRshNS1aX6s5YdBE3njCCouPgnG29ebyHvImlZzXZf2SHgt+J08DHgytTPnpywNbO1Y8mNUFyQuIDBq2JZg==

lodash.uniq@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<source>Copy link</source>
<target>Teilen-Link</target>
</trans-unit>
<trans-unit id="syncSectionId" xml:space="preserve">
<source>Synchronize section id with the jump marker title</source>
<target>Abschnitts-ID mit Titel synchronisieren</target>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<trans-unit id="properties.sectionId.copy-uri" xml:space="preserve">
<source>Copy link</source>
</trans-unit>
<trans-unit id="syncSectionId" xml:space="preserve">
<source>Synchronize section id with the jump marker title</source>
</trans-unit>
</body>
</file>
</xliff>
6 changes: 6 additions & 0 deletions Resources/Public/JavaScript/AnchorView/Plugin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Resources/Public/JavaScript/AnchorView/Plugin.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4ab037b

Please sign in to comment.