diff --git a/Resources/Private/PlaceholderInsert/src/PlaceholderInsertDropdown.js b/Resources/Private/PlaceholderInsert/src/PlaceholderInsertDropdown.js index 1fab161..b1ee613 100644 --- a/Resources/Private/PlaceholderInsert/src/PlaceholderInsertDropdown.js +++ b/Resources/Private/PlaceholderInsert/src/PlaceholderInsertDropdown.js @@ -40,17 +40,38 @@ export default class PlaceholderInsertDropdown extends PureComponent { }; render() { + let options = []; + const [formPath, workspace] = parentNodeContextPath( parentNodeContextPath(this.props.focusedNode.contextPath) ).split("@"); + // get options of first page const elementsPath = `${formPath}/elements@${workspace}`; const elementsNode = this.props.nodesByContextPath[elementsPath]; if (!elementsNode) { return null; } - const options = this.getOptionsRecursively(elementsNode.children); + const firstPageOptions = this.getOptionsRecursively(elementsNode.children); + if (firstPageOptions && firstPageOptions.length > 0) { + options = options.concat(firstPageOptions); + } + + // get options of further pages + const furtherPagesPath = `${formPath}/furtherpages@${workspace}`; + const furtherPagesNode = this.props.nodesByContextPath[furtherPagesPath]; + if (furtherPagesNode && furtherPagesNode.children && furtherPagesNode.children.length > 0) { + furtherPagesNode.children.forEach(furtherPageChildren => { + if (furtherPageChildren) { + const pageOptions = this.getOptionsOfPage(furtherPageChildren); + + if (pageOptions && pageOptions.length > 0) { + options = options.concat(pageOptions); + } + } + }); + } if (options.length === 0) { return null; @@ -71,6 +92,17 @@ export default class PlaceholderInsertDropdown extends PureComponent { ); } + getOptionsOfPage(page) { + const [path, workspace] = page.contextPath.split("@"); + const elementsPath = `${path}/elements@${workspace}`; + const elementsNode = this.props.nodesByContextPath[elementsPath]; + if (!elementsNode) { + return null; + } + + return this.getOptionsRecursively(elementsNode.children); + } + getOptionsRecursively(elements) { const {frontendConfiguration} = this.props; const ignoreNodeTypeInDropdown = frontendConfiguration.get('Neos.Form.Builder:PlaceholderInsert').ignoreNodeTypeInDropdown; diff --git a/Resources/Public/JavaScript/PlaceholderInsert/Plugin.js b/Resources/Public/JavaScript/PlaceholderInsert/Plugin.js index aa82480..5614f70 100644 --- a/Resources/Public/JavaScript/PlaceholderInsert/Plugin.js +++ b/Resources/Public/JavaScript/PlaceholderInsert/Plugin.js @@ -286,7 +286,7 @@ eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n}); /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.default = exports.parentNodeContextPath = undefined;\n\nvar _dec, _dec2, _class;\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar _reactRedux = __webpack_require__(/*! react-redux */ \"./node_modules/@neos-project/neos-ui-extensibility/dist/shims/vendor/react-redux/index.js\");\n\nvar _reactUiComponents = __webpack_require__(/*! @neos-project/react-ui-components */ \"./node_modules/@neos-project/neos-ui-extensibility/dist/shims/neosProjectPackages/react-ui-components/index.js\");\n\nvar _react = __webpack_require__(/*! react */ \"./node_modules/@neos-project/neos-ui-extensibility/dist/shims/vendor/react/index.js\");\n\nvar _react2 = _interopRequireDefault(_react);\n\nvar _neosUiDecorators = __webpack_require__(/*! @neos-project/neos-ui-decorators */ \"./node_modules/@neos-project/neos-ui-extensibility/dist/shims/neosProjectPackages/neos-ui-decorators/index.js\");\n\nvar _plowJs = __webpack_require__(/*! plow-js */ \"./node_modules/@neos-project/neos-ui-extensibility/dist/shims/vendor/plow-js/index.js\");\n\nvar _neosUiReduxStore = __webpack_require__(/*! @neos-project/neos-ui-redux-store */ \"./node_modules/@neos-project/neos-ui-extensibility/dist/shims/neosProjectPackages/neos-ui-redux-store/index.js\");\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nvar parentNodeContextPath = exports.parentNodeContextPath = function parentNodeContextPath(contextPath) {\n if (typeof contextPath !== \"string\") {\n console.error(\"`contextPath` must be a string!\"); // tslint:disable-line\n return null;\n }\n\n var _contextPath$split = contextPath.split(\"@\"),\n _contextPath$split2 = _slicedToArray(_contextPath$split, 2),\n path = _contextPath$split2[0],\n context = _contextPath$split2[1];\n\n if (path.length === 0) {\n // We are at top level; so there is no parent anymore!\n return null;\n }\n\n return path.substr(0, path.lastIndexOf(\"/\")) + \"@\" + context;\n};\n\nvar PlaceholderInsertDropdown = (_dec = (0, _reactRedux.connect)((0, _plowJs.$transform)({\n nodesByContextPath: _neosUiReduxStore.selectors.CR.Nodes.nodesByContextPathSelector,\n focusedNode: _neosUiReduxStore.selectors.CR.Nodes.focusedSelector\n})), _dec2 = (0, _neosUiDecorators.neos)(function (globalRegistry) {\n return {\n i18nRegistry: globalRegistry.get(\"i18n\"),\n nodeTypeRegistry: globalRegistry.get(\"@neos-project/neos-ui-contentrepository\"),\n frontendConfiguration: globalRegistry.get('frontendConfiguration')\n };\n}), _dec(_class = _dec2(_class = class PlaceholderInsertDropdown extends _react.PureComponent {\n constructor() {\n var _temp, _this;\n\n return _temp = _this = super(...arguments), this.handleOnSelect = function (value) {\n _this.props.executeCommand(\"placeholderInsert\", value);\n }, _temp;\n }\n\n render() {\n var _parentNodeContextPat = parentNodeContextPath(parentNodeContextPath(this.props.focusedNode.contextPath)).split(\"@\"),\n _parentNodeContextPat2 = _slicedToArray(_parentNodeContextPat, 2),\n formPath = _parentNodeContextPat2[0],\n workspace = _parentNodeContextPat2[1];\n\n var elementsPath = formPath + \"/elements@\" + workspace;\n\n var elementsNode = this.props.nodesByContextPath[elementsPath];\n if (!elementsNode) {\n return null;\n }\n var options = this.getOptionsRecursively(elementsNode.children);\n\n if (options.length === 0) {\n return null;\n }\n\n var placeholderLabel = this.props.i18nRegistry.translate(\"Neos.Form.Builder:Main:placeholder\", \"Insert placeholder\");\n\n return _react2.default.createElement(_reactUiComponents.SelectBox, {\n placeholder: placeholderLabel,\n options: options,\n onValueChange: this.handleOnSelect,\n value: null\n });\n }\n\n getOptionsRecursively(elements) {\n var _this2 = this;\n\n var frontendConfiguration = this.props.frontendConfiguration;\n\n var returnValues = [];\n\n elements.forEach(function (element) {\n var node = _this2.props.nodesByContextPath[element.contextPath];\n var childNodes = _this2.props.nodesByContextPath[element.contextPath].children;\n var ignoredNodeTypes = frontendConfiguration.get('Neos.Form.Builder:PlaceholderInsert').ignoreNodeTypesInDropdown;\n\n if (!(ignoredNodeTypes.hasOwnProperty(node.nodeType) && ignoredNodeTypes[node.nodeType] === true)) {\n returnValues.push({\n value: node.properties.identifier || node.identifier,\n label: node.properties.label || node.properties.identifier || node.identifier\n });\n }\n\n var childOptions = _this2.getOptionsRecursively(childNodes);\n\n if (Array.isArray(childOptions)) {\n childOptions.forEach(function (childOption) {\n returnValues.push(childOption);\n });\n }\n });\n\n return returnValues;\n }\n}) || _class) || _class);\nexports.default = PlaceholderInsertDropdown;\n\n//# sourceURL=webpack:///./src/PlaceholderInsertDropdown.js?"); +eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.default = exports.parentNodeContextPath = undefined;\n\nvar _dec, _dec2, _class;\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }();\n\nvar _reactRedux = __webpack_require__(/*! react-redux */ \"./node_modules/@neos-project/neos-ui-extensibility/dist/shims/vendor/react-redux/index.js\");\n\nvar _reactUiComponents = __webpack_require__(/*! @neos-project/react-ui-components */ \"./node_modules/@neos-project/neos-ui-extensibility/dist/shims/neosProjectPackages/react-ui-components/index.js\");\n\nvar _react = __webpack_require__(/*! react */ \"./node_modules/@neos-project/neos-ui-extensibility/dist/shims/vendor/react/index.js\");\n\nvar _react2 = _interopRequireDefault(_react);\n\nvar _neosUiDecorators = __webpack_require__(/*! @neos-project/neos-ui-decorators */ \"./node_modules/@neos-project/neos-ui-extensibility/dist/shims/neosProjectPackages/neos-ui-decorators/index.js\");\n\nvar _plowJs = __webpack_require__(/*! plow-js */ \"./node_modules/@neos-project/neos-ui-extensibility/dist/shims/vendor/plow-js/index.js\");\n\nvar _neosUiReduxStore = __webpack_require__(/*! @neos-project/neos-ui-redux-store */ \"./node_modules/@neos-project/neos-ui-extensibility/dist/shims/neosProjectPackages/neos-ui-redux-store/index.js\");\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nvar parentNodeContextPath = exports.parentNodeContextPath = function parentNodeContextPath(contextPath) {\n if (typeof contextPath !== \"string\") {\n console.error(\"`contextPath` must be a string!\"); // tslint:disable-line\n return null;\n }\n\n var _contextPath$split = contextPath.split(\"@\"),\n _contextPath$split2 = _slicedToArray(_contextPath$split, 2),\n path = _contextPath$split2[0],\n context = _contextPath$split2[1];\n\n if (path.length === 0) {\n // We are at top level; so there is no parent anymore!\n return null;\n }\n\n return path.substr(0, path.lastIndexOf(\"/\")) + \"@\" + context;\n};\n\nvar PlaceholderInsertDropdown = (_dec = (0, _reactRedux.connect)((0, _plowJs.$transform)({\n nodesByContextPath: _neosUiReduxStore.selectors.CR.Nodes.nodesByContextPathSelector,\n focusedNode: _neosUiReduxStore.selectors.CR.Nodes.focusedSelector\n})), _dec2 = (0, _neosUiDecorators.neos)(function (globalRegistry) {\n return {\n i18nRegistry: globalRegistry.get(\"i18n\"),\n nodeTypeRegistry: globalRegistry.get(\"@neos-project/neos-ui-contentrepository\"),\n frontendConfiguration: globalRegistry.get('frontendConfiguration')\n };\n}), _dec(_class = _dec2(_class = class PlaceholderInsertDropdown extends _react.PureComponent {\n constructor() {\n var _temp, _this;\n\n return _temp = _this = super(...arguments), this.handleOnSelect = function (value) {\n _this.props.executeCommand(\"placeholderInsert\", value);\n }, _temp;\n }\n\n render() {\n var _this2 = this;\n\n var options = [];\n\n var _parentNodeContextPat = parentNodeContextPath(parentNodeContextPath(this.props.focusedNode.contextPath)).split(\"@\"),\n _parentNodeContextPat2 = _slicedToArray(_parentNodeContextPat, 2),\n formPath = _parentNodeContextPat2[0],\n workspace = _parentNodeContextPat2[1];\n\n // get options of first page\n\n\n var elementsPath = formPath + \"/elements@\" + workspace;\n\n var elementsNode = this.props.nodesByContextPath[elementsPath];\n if (!elementsNode) {\n return null;\n }\n var firstPageOptions = this.getOptionsRecursively(elementsNode.children);\n if (firstPageOptions && firstPageOptions.length > 0) {\n options = options.concat(firstPageOptions);\n }\n\n // get options of further pages\n var furtherPagesPath = formPath + \"/furtherpages@\" + workspace;\n var furtherPagesNode = this.props.nodesByContextPath[furtherPagesPath];\n if (furtherPagesNode && furtherPagesNode.children && furtherPagesNode.children.length > 0) {\n furtherPagesNode.children.forEach(function (furtherPageChildren) {\n if (furtherPageChildren) {\n var pageOptions = _this2.getOptionsOfPage(furtherPageChildren);\n\n if (pageOptions && pageOptions.length > 0) {\n options = options.concat(pageOptions);\n }\n }\n });\n }\n\n if (options.length === 0) {\n return null;\n }\n\n var placeholderLabel = this.props.i18nRegistry.translate(\"Neos.Form.Builder:Main:placeholder\", \"Insert placeholder\");\n\n return _react2.default.createElement(_reactUiComponents.SelectBox, {\n placeholder: placeholderLabel,\n options: options,\n onValueChange: this.handleOnSelect,\n value: null\n });\n }\n\n getOptionsOfPage(page) {\n var _page$contextPath$spl = page.contextPath.split(\"@\"),\n _page$contextPath$spl2 = _slicedToArray(_page$contextPath$spl, 2),\n path = _page$contextPath$spl2[0],\n workspace = _page$contextPath$spl2[1];\n\n var elementsPath = path + \"/elements@\" + workspace;\n var elementsNode = this.props.nodesByContextPath[elementsPath];\n if (!elementsNode) {\n return null;\n }\n\n return this.getOptionsRecursively(elementsNode.children);\n }\n\n getOptionsRecursively(elements) {\n var _this3 = this;\n\n var frontendConfiguration = this.props.frontendConfiguration;\n\n var ignoreNodeTypeInDropdown = frontendConfiguration.get('Neos.Form.Builder:PlaceholderInsert').ignoreNodeTypeInDropdown;\n var ignoreAllChildNodesOfNodeTypeInDropdown = frontendConfiguration.get('Neos.Form.Builder:PlaceholderInsert').ignoreAllChildNodesOfNodeTypeInDropdown;\n var returnValues = [];\n\n elements.forEach(function (element) {\n var node = _this3.props.nodesByContextPath[element.contextPath];\n if (!node) {\n return null;\n }\n\n if (!(ignoreNodeTypeInDropdown.hasOwnProperty(node.nodeType) && ignoreNodeTypeInDropdown[node.nodeType] === true)) {\n returnValues.push({\n value: node.properties.identifier || node.identifier,\n label: node.properties.label || node.properties.identifier || node.identifier\n });\n }\n\n if (!(ignoreAllChildNodesOfNodeTypeInDropdown.hasOwnProperty(node.nodeType) && ignoreAllChildNodesOfNodeTypeInDropdown[node.nodeType] === true)) {\n var childNodes = _this3.props.nodesByContextPath[element.contextPath].children;\n var childOptions = _this3.getOptionsRecursively(childNodes);\n\n if (Array.isArray(childOptions)) {\n childOptions.forEach(function (childOption) {\n returnValues.push(childOption);\n });\n }\n }\n });\n\n return returnValues;\n }\n}) || _class) || _class);\nexports.default = PlaceholderInsertDropdown;\n\n//# sourceURL=webpack:///./src/PlaceholderInsertDropdown.js?"); /***/ }),