Liferay.Loader.define("fragment-web@3.0.53/js/fragment-editor/CodeMirrorEditor", ['module', 'exports', 'require', 'fragment-web$codemirror/addon/display/autorefresh', 'fragment-web$codemirror/addon/edit/closebrackets', 'fragment-web$codemirror/addon/edit/closetag', 'fragment-web$codemirror/addon/edit/matchbrackets', 'fragment-web$codemirror/addon/fold/brace-fold', 'fragment-web$codemirror/addon/fold/comment-fold', 'fragment-web$codemirror/addon/fold/foldcode', 'fragment-web$codemirror/addon/fold/foldgutter.css', 'fragment-web$codemirror/addon/fold/foldgutter', 'fragment-web$codemirror/addon/fold/indent-fold', 'fragment-web$codemirror/addon/fold/xml-fold', 'fragment-web$codemirror/addon/hint/css-hint', 'fragment-web$codemirror/addon/hint/html-hint', 'fragment-web$codemirror/addon/hint/javascript-hint', 'fragment-web$codemirror/addon/hint/show-hint.css', 'fragment-web$codemirror/addon/hint/show-hint', 'fragment-web$codemirror/addon/hint/xml-hint', 'fragment-web$codemirror/lib/codemirror.css', 'fragment-web$codemirror/mode/css/css', 'fragment-web$codemirror/mode/htmlmixed/htmlmixed', 'fragment-web$codemirror/mode/javascript/javascript', 'fragment-web$codemirror/mode/xml/xml', '@frontend-taglib-clay$clayui/icon', 'fragment-web$codemirror', 'frontend-js-react-web$react'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    function _typeof(obj) {
      "@babel/helpers - typeof";
      if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
        _typeof = function _typeof(obj) {
          return typeof obj;
        };
      } else {
        _typeof = function _typeof(obj) {
          return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
        };
      }return _typeof(obj);
    }

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = void 0;

    require("fragment-web$codemirror/addon/display/autorefresh");

    require("fragment-web$codemirror/addon/edit/closebrackets");

    require("fragment-web$codemirror/addon/edit/closetag");

    require("fragment-web$codemirror/addon/edit/matchbrackets");

    require("fragment-web$codemirror/addon/fold/brace-fold");

    require("fragment-web$codemirror/addon/fold/comment-fold");

    require("fragment-web$codemirror/addon/fold/foldcode");

    require("fragment-web$codemirror/addon/fold/foldgutter.css");

    require("fragment-web$codemirror/addon/fold/foldgutter");

    require("fragment-web$codemirror/addon/fold/indent-fold");

    require("fragment-web$codemirror/addon/fold/xml-fold");

    require("fragment-web$codemirror/addon/hint/css-hint");

    require("fragment-web$codemirror/addon/hint/html-hint");

    require("fragment-web$codemirror/addon/hint/javascript-hint");

    require("fragment-web$codemirror/addon/hint/show-hint.css");

    require("fragment-web$codemirror/addon/hint/show-hint");

    require("fragment-web$codemirror/addon/hint/xml-hint");

    require("fragment-web$codemirror/lib/codemirror.css");

    require("fragment-web$codemirror/mode/css/css");

    require("fragment-web$codemirror/mode/htmlmixed/htmlmixed");

    require("fragment-web$codemirror/mode/javascript/javascript");

    require("fragment-web$codemirror/mode/xml/xml");

    var _icon = _interopRequireDefault(require("@frontend-taglib-clay$clayui/icon"));

    var _codemirror2 = _interopRequireDefault(require("fragment-web$codemirror"));

    var _react = _interopRequireWildcard(require("frontend-js-react-web$react"));

    function _getRequireWildcardCache() {
      if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function _getRequireWildcardCache() {
        return cache;
      };return cache;
    }

    function _interopRequireWildcard(obj) {
      if (obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { default: obj };
      }var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }newObj.default = obj;if (cache) {
        cache.set(obj, newObj);
      }return newObj;
    }

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { default: obj };
    }

    function ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    var AUTOCOMPLETE_EXCLUDED_KEY_CODES = new Set(Object.values({
      ALT: 18,
      ARROW_DOWN: 40,
      ARROW_LEFT: 37,
      ARROW_RIGHT: 39,
      ARROW_UP: 38,
      BACKSPACE: 8,
      CONTROL: 17,
      ESCAPE: 27,
      META: 91,
      RETURN: 13,
      SHIFT: 16,
      SPACE: 32
    }));
    var MODES = {
      css: {
        name: 'CSS',
        type: 'text/css'
      },
      html: {
        hint: function hint(cm, options) {
          var customDataAttributes = options.customDataAttributes,
              customEntities = options.customEntities,
              customEntitiesSymbolsRegex = options.customEntitiesSymbolsRegex,
              customTags = options.customTags;
          var cursor = cm.getCursor();
          var token = cm.getTokenAt(cursor);

          if (token.type && token.type !== 'string') {
            var content = token.string;

            var htmlCompletion = _codemirror2.default.hint.html(cm, options);

            if (!htmlCompletion) {
              return;
            }

            var resultSet = new Set(htmlCompletion.list);

            if (token.type === 'attribute' && token.string.startsWith('data')) {
              customDataAttributes.forEach(function (item) {
                var attributeName = "data-".concat(item);
                var attributeValue = '';

                if (attributeName.indexOf(':') !== -1) {
                  attributeValue = attributeName.substring(attributeName.indexOf(':') + 1);
                  attributeName = attributeName.substring(0, attributeName.indexOf(':'));
                }

                if (attributeName.startsWith(content) && !resultSet.has(attributeName)) {
                  resultSet.add({
                    displayText: "".concat(attributeName).concat(attributeValue ? ':' + attributeValue : ''),
                    text: "".concat(attributeName, "=\"").concat(attributeValue, "\"")
                  });
                }
              });
            } else {
              customTags.forEach(function (item) {
                if (item.name.startsWith(content) && !resultSet.has(item.content)) {
                  resultSet.add({
                    displayText: item.name,
                    text: item.content
                  });
                }
              });
            }

            return _objectSpread(_objectSpread({}, htmlCompletion), {}, {
              list: Array.from(resultSet)
            });
          } else if (customEntities && customEntitiesSymbolsRegex) {
            var line = cm.getLine(cursor.line).slice(0, cursor.ch);
            var match = (line.match(new RegExp(customEntitiesSymbolsRegex, 'g')) || []).pop();

            if (!match) {
              return;
            }

            var customEntity = customEntities.find(function (entity) {
              return match.startsWith(entity.start);
            });

            var _content = match.slice(customEntity.start.length);

            var results = customEntity.content.filter(function (entityContent) {
              return entityContent.startsWith(_content);
            }).map(function (entityContent) {
              return "".concat(customEntity.start).concat(entityContent);
            });
            return {
              from: _codemirror2.default.Pos(cursor.line, cursor.ch - match.length),
              list: results,
              to: _codemirror2.default.Pos(cursor.line, cursor.ch)
            };
          }
        },
        name: 'HTML',
        type: 'text/html'
      },
      javascript: {
        name: 'JavaScript',
        type: 'text/javascript'
      },
      json: {
        name: 'JSON',
        type: 'application/json'
      }
    };

    var escapeChars = function escapeChars(string) {
      return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
    };

    var noop = function noop() {};

    var FixedText = function FixedText(_ref) {
      var helpText = _ref.helpText,
          _ref$text = _ref.text,
          text = _ref$text === void 0 ? '' : _ref$text;
      return (/*#__PURE__*/_react.default.createElement("div", {
          className: "source-editor__fixed-text"
        }, /*#__PURE__*/_react.default.createElement("code", {
          className: "source-editor__fixed-text__content"
        }, text), helpText && /*#__PURE__*/_react.default.createElement("span", {
          className: "float-right source-editor__fixed-text__help",
          "data-title": helpText
        }, /*#__PURE__*/_react.default.createElement(_icon.default, {
          className: "icon-monospaced",
          symbol: "question-circle-full"
        })))
      );
    };

    var CodeMirrorEditor = function CodeMirrorEditor(_ref2) {
      var customDataAttributes = _ref2.customDataAttributes,
          customEntities = _ref2.customEntities,
          customTags = _ref2.customTags,
          _ref2$onChange = _ref2.onChange,
          onChange = _ref2$onChange === void 0 ? noop : _ref2$onChange,
          _ref2$mode = _ref2.mode,
          mode = _ref2$mode === void 0 ? 'html' : _ref2$mode,
          codeFooterText = _ref2.codeFooterText,
          codeHeaderText = _ref2.codeHeaderText,
          codeHeaderHelpText = _ref2.codeHeaderHelpText,
          _ref2$content = _ref2.content,
          content = _ref2$content === void 0 ? '' : _ref2$content,
          readOnly = _ref2.readOnly;
      var editor = (0, _react.useRef)();
      var ref = (0, _react.useRef)();
      var customEntitiesSymbolsRegex = (0, _react.useMemo)(function () {
        if (!customEntities) {
          return;
        }

        return "".concat(customEntities.map(function (entity) {
          var start = escapeChars(entity.start);
          var end = escapeChars(entity.end);
          return "".concat(start, "((?!\\s|").concat(end, ").)*(?:").concat(end, ")?");
        }).join('|'), "$");
      }, [customEntities]);
      (0, _react.useEffect)(function () {
        if (ref.current) {
          var codeMirror = (0, _codemirror2.default)(ref.current, {
            autoCloseTags: true,
            autoRefresh: true,
            extraKeys: {
              'Ctrl-Space': 'autocomplete'
            },
            foldGutter: true,
            gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
            hintOptions: {
              completeSingle: false,
              customDataAttributes: customDataAttributes,
              customEntities: customEntities,
              customEntitiesSymbolsRegex: customEntitiesSymbolsRegex,
              customTags: customTags,
              hint: MODES[mode].hint
            },
            indentWithTabs: true,
            inputStyle: 'contenteditable',
            lineNumbers: true,
            matchBrackets: true,
            mode: {
              globalVars: true,
              name: MODES[mode].type
            },
            readOnly: readOnly,
            showHint: true,
            tabSize: 2,
            value: content,
            viewportMargin: Infinity
          });
          codeMirror.on('change', function (cm) {
            onChange(cm.getValue());
          });
          codeMirror.on('keyup', function (cm, event) {
            if (!cm.state.completionActive && !AUTOCOMPLETE_EXCLUDED_KEY_CODES.has(event.keyCode)) {
              codeMirror.showHint();
            }
          });
          editor.current = codeMirror;
        }
      }, [ref]); // eslint-disable-line

      (0, _react.useEffect)(function () {
        if (editor.current) {
          editor.current.setOption('mode', {
            globalVars: true,
            name: MODES[mode].type
          });
          editor.current.setOption('readOnly', readOnly);
          editor.current.setOption('hintOptions', _objectSpread(_objectSpread({}, editor.current.getOption('hintOptions')), {}, {
            customEntities: customEntities,
            customEntitiesSymbolsRegex: customEntitiesSymbolsRegex,
            customTags: customTags
          }));
        }
      }, [customEntities, customEntitiesSymbolsRegex, customTags, mode, readOnly]);
      (0, _react.useEffect)(function () {
        if (editor.current) {
          editor.current.setValue(content);
        }
      }, [content]);
      return (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("nav", {
          className: "source-editor-toolbar tbar"
        }, /*#__PURE__*/_react.default.createElement("ul", {
          className: "tbar-nav"
        }, /*#__PURE__*/_react.default.createElement("li", {
          className: "source-editor-toolbar__syntax tbar-item tbar-item-expand text-center"
        }, MODES[mode].name))), (codeHeaderHelpText || codeHeaderText) && /*#__PURE__*/_react.default.createElement(FixedText, {
          helpText: codeHeaderHelpText,
          text: codeHeaderText
        }), /*#__PURE__*/_react.default.createElement("div", {
          className: "codemirror-editor-wrapper",
          ref: ref
        }), codeFooterText && /*#__PURE__*/_react.default.createElement(FixedText, {
          text: codeFooterText
        }))
      );
    };

    var _default = CodeMirrorEditor;
    exports.default = _default;
    //# sourceMappingURL=CodeMirrorEditor.js.map
  }
});
//# sourceMappingURL=CodeMirrorEditor.js.map