Skip to content

Commit

Permalink
new QuillJs component
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehyiah committed Jul 2, 2023
1 parent f05e5f1 commit a7cea4d
Show file tree
Hide file tree
Showing 49 changed files with 16,345 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/QuillJs/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.symfony.bundle.yaml export-ignore
/phpunit.xml.dist export-ignore
/assets/src/**/*.ts export-ignore
/assets/test export-ignore
/assets/jest.config.js export-ignore
/tests export-ignore
11 changes: 11 additions & 0 deletions src/QuillJs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.php-cs-fixer.cache
.phpunit.result.cache
.php-cs-fixer.php
yarn-error.log

var/
vendor/
.idea

assets/node_modules
docker-compose.override.yaml
42 changes: 42 additions & 0 deletions src/QuillJs/.php-cs-fixer.php.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

$finder = PhpCsFixer\Finder::create()
->notPath('Kernel.php')
->notPath('bootstrap.php')
->in(__DIR__ . '/src')
;

return (new \PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PhpCsFixer' => true,
'@DoctrineAnnotation' => true,
'@PHP71Migration' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'cast_spaces' => ['space' => 'none'],
'concat_space' => ['spacing' => 'one'],
'escape_implicit_backslashes' => false,
'explicit_indirect_variable' => false,
'explicit_string_variable' => false,
'no_superfluous_elseif' => false,
'ordered_class_elements' => false,
'php_unit_internal_class' => false,
'phpdoc_order_by_value' => false,
'phpdoc_align' => ['align' => 'left'],
'phpdoc_summary' => false,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'simple_to_complex_string_variable' => false,
'native_constant_invocation' => false,
'native_function_invocation' => false,
'general_phpdoc_annotation_remove' => ['annotations' => ['author', 'package']],
'global_namespace_import' => true,
'linebreak_after_opening_tag' => true,
'no_php4_constructor' => true,
'pow_to_exponentiation' => true,
'random_api_migration' => true,
'list_syntax' => ['syntax' => 'short'],
'method_chaining_indentation' => false,
])
->setFinder($finder)
;
3 changes: 3 additions & 0 deletions src/QuillJs/.symfony.bundle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
branches: ["2.x"]
maintained_branches: ["2.x"]
doc_dir: "doc"
21 changes: 21 additions & 0 deletions src/QuillJs/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Matthieu Gostiaux

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 13 additions & 0 deletions src/QuillJs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Symfony UX QuillJs

Symfony UX QuillJs integrates [QuillJs](https://quilljs.com/) into Symfony applications.

**This repository is a READ-ONLY sub-tree split**. See
https://github.com/symfony/ux to create issues or submit pull requests.

## Resources

- [Documentation](https://symfony.com/bundles/ux-quill/current/index.html)
- [Report issues](https://github.com/symfony/ux/issues) and
[send Pull Requests](https://github.com/symfony/ux/pulls)
in the [main Symfony UX repository](https://github.com/symfony/ux)
14 changes: 14 additions & 0 deletions src/QuillJs/assets/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"presets": [
["@babel/preset-env",
{
"targets": {
"browsers": [">0.25%", "ie >= 11"]
},
"corejs": 3,
"useBuiltIns": "entry"
}
],
"@babel/preset-typescript"
]
}
139 changes: 139 additions & 0 deletions src/QuillJs/assets/dist/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _stimulus = require("@hotwired/stimulus");
var _quill = _interopRequireDefault(require("quill"));
var _quillImageUploader = _interopRequireDefault(require("quill-image-uploader"));
var _axios = _interopRequireDefault(require("axios"));
require("quill-image-uploader/dist/quill.imageUploader.min.css");
require("quill-emoji/dist/quill-emoji.css");
var Emoji = _interopRequireWildcard(require("quill-emoji"));
var _quillBlotFormatter = _interopRequireDefault(require("quill-blot-formatter"));
var _customImage = _interopRequireDefault(require("./customImage"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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 _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
_quill.default.register('modules/imageUploader', _quillImageUploader.default);
_quill.default.register("modules/emoji", Emoji);
_quill.default.register('modules/blotFormatter', _quillBlotFormatter.default);
_quill.default.register(_customImage.default, true);
var _default = /*#__PURE__*/function (_Controller) {
_inherits(_default, _Controller);
var _super = _createSuper(_default);
function _default() {
_classCallCheck(this, _default);
return _super.apply(this, arguments);
}
_createClass(_default, [{
key: "connect",
value: function connect() {
var _this = this;
var toolbarOptionsValue = this.toolbarOptionsValue;
var options = {
debug: this.extraOptionsValue.debug,
modules: {
toolbar: toolbarOptionsValue,
"emoji-toolbar": true,
"emoji-shortname": true,
blotFormatter: {
overlay: {
style: {
border: '2px solid red'
}
}
}
},
placeholder: this.extraOptionsValue.placeholder,
theme: this.extraOptionsValue.theme
};
if (this.extraOptionsValue.upload_handler.path !== null && this.extraOptionsValue.upload_handler.type === 'form') {
Object.assign(options.modules, {
imageUploader: {
upload: function upload(file) {
return new Promise(function (resolve, reject) {
var formData = new FormData();
formData.append('file', file);
_axios.default.post(_this.extraOptionsValue.upload_handler.path, formData).then(function (response) {
resolve(response.data);
}).catch(function (err) {
reject('Upload failed');
console.log(err);
});
});
}
}
});
}
if (this.extraOptionsValue.upload_handler.path !== null && this.extraOptionsValue.upload_handler.type === 'json') {
Object.assign(options.modules, {
imageUploader: {
upload: function upload(file) {
return new Promise(function (resolve, reject) {
var reader = function reader(file) {
return new Promise(function (resolve) {
var fileReader = new FileReader();
fileReader.onload = function () {
return resolve(fileReader.result);
};
fileReader.readAsDataURL(file);
});
};
reader(file).then(function (result) {
return _axios.default.post(_this.extraOptionsValue.upload_handler.path, result, {
headers: {
'Content-Type': 'application/json'
}
}).then(function (response) {
resolve(response.data);
}).catch(function (err) {
reject('Upload failed');
console.log(err);
});
});
});
}
}
});
}
if (typeof this.extraOptionsValue.height === "string") {
this.editorContainerTarget.style.height = this.extraOptionsValue.height;
}
var quill = new _quill.default(this.editorContainerTarget, options);
quill.on('text-change', function () {
var quillContent = quill.root.innerHTML;
var inputContent = _this.inputTarget;
inputContent.value = quillContent;
});
}
}]);
return _default;
}(_stimulus.Controller);
exports.default = _default;
_defineProperty(_default, "targets", ['input', 'editorContainer']);
_defineProperty(_default, "values", {
toolbarOptions: {
type: Array,
default: []
},
extraOptions: {
type: Object,
default: {}
}
});
59 changes: 59 additions & 0 deletions src/QuillJs/assets/dist/customImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _quill = _interopRequireDefault(require("quill"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var BaseImageFormat = _quill.default.import('formats/image');
var ImageFormatAttributesList = ['alt', 'height', 'width', 'class', 'style'];
var ImageFormat = /*#__PURE__*/function (_BaseImageFormat) {
_inherits(ImageFormat, _BaseImageFormat);
var _super = _createSuper(ImageFormat);
function ImageFormat() {
_classCallCheck(this, ImageFormat);
return _super.apply(this, arguments);
}
_createClass(ImageFormat, [{
key: "format",
value: function format(name, value) {
if (ImageFormatAttributesList.indexOf(name) > -1) {
if (value) {
this.domNode.setAttribute(name, value);
} else {
this.domNode.removeAttribute(name);
}
} else {
_get(_getPrototypeOf(ImageFormat.prototype), "format", this).call(this, name, value);
}
}
}], [{
key: "formats",
value: function formats(domNode) {
return ImageFormatAttributesList.reduce(function (formats, attribute) {
if (domNode.hasAttribute(attribute)) {
formats[attribute] = domNode.getAttribute(attribute);
}
return formats;
}, {});
}
}]);
return ImageFormat;
}(BaseImageFormat);
exports.default = ImageFormat;
Loading

0 comments on commit a7cea4d

Please sign in to comment.