-
-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEATURE: CKE5 placeholder insert plugin #46
Merged
+7,694
−2
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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,15 @@ | ||
{ | ||
"description": "PlaceholderInsert", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"build": "neos-react-scripts build", | ||
"watch": "neos-react-scripts watch" | ||
}, | ||
"devDependencies": { | ||
"@neos-project/neos-ui-extensibility": "*" | ||
}, | ||
"neos": { | ||
"buildTargetDirectory": "../../Public/JavaScript/PlaceholderInsert" | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
Resources/Private/PlaceholderInsert/src/PlaceholderInsertDropdown.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,77 @@ | ||
import { connect } from "react-redux"; | ||
import { SelectBox } from "@neos-project/react-ui-components"; | ||
import React, { PureComponent } from "react"; | ||
import { neos } from "@neos-project/neos-ui-decorators"; | ||
import { $transform } from "plow-js"; | ||
import { selectors } from "@neos-project/neos-ui-redux-store"; | ||
|
||
export const parentNodeContextPath = contextPath => { | ||
if (typeof contextPath !== "string") { | ||
console.error("`contextPath` must be a string!"); // tslint:disable-line | ||
return null; | ||
} | ||
const [path, context] = contextPath.split("@"); | ||
|
||
if (path.length === 0) { | ||
// We are at top level; so there is no parent anymore! | ||
return null; | ||
} | ||
|
||
return `${path.substr(0, path.lastIndexOf("/"))}@${context}`; | ||
}; | ||
|
||
@connect( | ||
$transform({ | ||
nodesByContextPath: selectors.CR.Nodes.nodesByContextPathSelector, | ||
focusedNode: selectors.CR.Nodes.focusedSelector | ||
}) | ||
) | ||
@neos(globalRegistry => ({ | ||
i18nRegistry: globalRegistry.get("i18n"), | ||
nodeTypeRegistry: globalRegistry.get( | ||
"@neos-project/neos-ui-contentrepository" | ||
) | ||
})) | ||
export default class PlaceholderInsertDropdown extends PureComponent { | ||
handleOnSelect = value => { | ||
this.props.executeCommand("placeholderInsert", value); | ||
}; | ||
|
||
render() { | ||
const [formPath, workspace] = parentNodeContextPath( | ||
parentNodeContextPath(this.props.focusedNode.contextPath) | ||
).split("@"); | ||
|
||
const elementsPath = `${formPath}/elements@${workspace}`; | ||
|
||
const elementsNode = this.props.nodesByContextPath[elementsPath]; | ||
if (!elementsNode) { | ||
return null; | ||
} | ||
const options = elementsNode.children | ||
.map(node => this.props.nodesByContextPath[node.contextPath]) | ||
.map(node => ({ | ||
value: node.properties.identifier || node.identifier, | ||
label: | ||
node.properties.label || node.properties.identifier || node.identifier | ||
})); | ||
|
||
if (options.length === 0) { | ||
return null; | ||
} | ||
|
||
const placeholderLabel = this.props.i18nRegistry.translate( | ||
"Neos.Form.Builder:Main:placeholder", | ||
"Insert placeholder" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be localized. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is, once the translations will be in place, it would show up, this is just a fallback |
||
); | ||
|
||
return ( | ||
<SelectBox | ||
placeholder={placeholderLabel} | ||
options={options} | ||
onValueChange={this.handleOnSelect} | ||
value={null} | ||
/> | ||
); | ||
} | ||
} |
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 @@ | ||
require("./manifest"); |
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,28 @@ | ||
import manifest from "@neos-project/neos-ui-extensibility"; | ||
import PlaceholderInsertDropdown from "./PlaceholderInsertDropdown"; | ||
import placeholderInsertPlugin from "./placeholderInsertPlugin"; | ||
import { $add, $get } from "plow-js"; | ||
|
||
const addPlugin = (Plugin, isEnabled) => (ckEditorConfiguration, options) => { | ||
if (!isEnabled || isEnabled(options.editorOptions, options)) { | ||
ckEditorConfiguration.plugins = ckEditorConfiguration.plugins || []; | ||
return $add("plugins", Plugin, ckEditorConfiguration); | ||
} | ||
return ckEditorConfiguration; | ||
}; | ||
|
||
manifest("Neos.Form.Builder:PlaceholderInsert", {}, globalRegistry => { | ||
const richtextToolbar = globalRegistry | ||
.get("ckEditor5") | ||
.get("richtextToolbar"); | ||
richtextToolbar.set("placeholderInsertt", { | ||
component: PlaceholderInsertDropdown, | ||
isVisible: $get("formatting.placeholderInsert") | ||
}); | ||
|
||
const config = globalRegistry.get("ckEditor5").get("config"); | ||
config.set( | ||
"placeholderInsert", | ||
addPlugin(placeholderInsertPlugin, $get("formatting.placeholderInsert")) | ||
); | ||
}); |
25 changes: 25 additions & 0 deletions
25
Resources/Private/PlaceholderInsert/src/placeholderInsertPlugin.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,25 @@ | ||
import { ModelText, Command, Plugin } from "ckeditor5-exports"; | ||
|
||
class PlaceholderInsertCommand extends Command { | ||
execute(value) { | ||
const model = this.editor.model; | ||
const doc = model.document; | ||
const selection = doc.selection; | ||
const placeholder = new ModelText("{" + value + "}"); | ||
model.insertContent(placeholder, selection); | ||
} | ||
} | ||
|
||
export default class PlaceholderInsertPlugin extends Plugin { | ||
static get pluginName() { | ||
return "PlaceholderInsert"; | ||
} | ||
init() { | ||
const editor = this.editor; | ||
|
||
editor.commands.add( | ||
"placeholderInsert", | ||
new PlaceholderInsertCommand(this.editor) | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to have this in
Settings
? While thinking of it, I see that different use-cases are possible; sometimes you want to use speaking identifiers, sometimes not.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you describe your idea in more details: setting name, setting format, what exactly it does etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking again, let's not over-complicate things for the moment and go with it as it is.