Skip to content

Commit 99a9f26

Browse files
committed
new QuillJs component
1 parent f05e5f1 commit 99a9f26

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+16347
-0
lines changed

src/QuillJs/.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.gitattributes export-ignore
2+
/.gitignore export-ignore
3+
/.symfony.bundle.yaml export-ignore
4+
/phpunit.xml.dist export-ignore
5+
/assets/src/**/*.ts export-ignore
6+
/assets/test export-ignore
7+
/assets/jest.config.js export-ignore
8+
/tests export-ignore

src/QuillJs/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.php-cs-fixer.cache
2+
.phpunit.result.cache
3+
.php-cs-fixer.php
4+
yarn-error.log
5+
6+
var/
7+
vendor/
8+
.idea
9+
10+
assets/node_modules
11+
docker-compose.override.yaml

src/QuillJs/.php-cs-fixer.php.dist

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->notPath('Kernel.php')
5+
->notPath('bootstrap.php')
6+
->in(__DIR__ . '/src')
7+
;
8+
9+
return (new \PhpCsFixer\Config())
10+
->setRiskyAllowed(true)
11+
->setRules([
12+
'@PhpCsFixer' => true,
13+
'@DoctrineAnnotation' => true,
14+
'@PHP71Migration' => true,
15+
'@Symfony' => true,
16+
'@Symfony:risky' => true,
17+
'cast_spaces' => ['space' => 'none'],
18+
'concat_space' => ['spacing' => 'one'],
19+
'escape_implicit_backslashes' => false,
20+
'explicit_indirect_variable' => false,
21+
'explicit_string_variable' => false,
22+
'no_superfluous_elseif' => false,
23+
'ordered_class_elements' => false,
24+
'php_unit_internal_class' => false,
25+
'phpdoc_order_by_value' => false,
26+
'phpdoc_align' => ['align' => 'left'],
27+
'phpdoc_summary' => false,
28+
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
29+
'simple_to_complex_string_variable' => false,
30+
'native_constant_invocation' => false,
31+
'native_function_invocation' => false,
32+
'general_phpdoc_annotation_remove' => ['annotations' => ['author', 'package']],
33+
'global_namespace_import' => true,
34+
'linebreak_after_opening_tag' => true,
35+
'no_php4_constructor' => true,
36+
'pow_to_exponentiation' => true,
37+
'random_api_migration' => true,
38+
'list_syntax' => ['syntax' => 'short'],
39+
'method_chaining_indentation' => false,
40+
])
41+
->setFinder($finder)
42+
;

src/QuillJs/.symfony.bundle.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
branches: ["2.x"]
2+
maintained_branches: ["2.x"]
3+
doc_dir: "doc"

src/QuillJs/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Matthieu Gostiaux
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

src/QuillJs/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Symfony UX QuillJs
2+
3+
Symfony UX QuillJs integrates [QuillJs](https://quilljs.com/) into Symfony applications.
4+
5+
**This repository is a READ-ONLY sub-tree split**. See
6+
https://github.com/symfony/ux to create issues or submit pull requests.
7+
8+
## Resources
9+
10+
- [Documentation](https://symfony.com/bundles/ux-quill/current/index.html)
11+
- [Report issues](https://github.com/symfony/ux/issues) and
12+
[send Pull Requests](https://github.com/symfony/ux/pulls)
13+
in the [main Symfony UX repository](https://github.com/symfony/ux)

src/QuillJs/assets/.babelrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"presets": [
3+
["@babel/preset-env",
4+
{
5+
"targets": {
6+
"browsers": [">0.25%", "ie >= 11"]
7+
},
8+
"corejs": 3,
9+
"useBuiltIns": "entry"
10+
}
11+
],
12+
"@babel/preset-typescript"
13+
]
14+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.default = void 0;
7+
var _stimulus = require("@hotwired/stimulus");
8+
var _quill = _interopRequireDefault(require("quill"));
9+
var _quillImageUploader = _interopRequireDefault(require("quill-image-uploader"));
10+
var _axios = _interopRequireDefault(require("axios"));
11+
require("quill-image-uploader/dist/quill.imageUploader.min.css");
12+
require("quill-emoji/dist/quill-emoji.css");
13+
var Emoji = _interopRequireWildcard(require("quill-emoji"));
14+
var _quillBlotFormatter = _interopRequireDefault(require("quill-blot-formatter"));
15+
var _customImage = _interopRequireDefault(require("./customImage"));
16+
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); }
17+
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; }
18+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19+
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); }
20+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21+
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); } }
22+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
23+
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); }
24+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
25+
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); }; }
26+
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); }
27+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
28+
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; } }
29+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
30+
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; }
31+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
32+
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); }
33+
_quill.default.register('modules/imageUploader', _quillImageUploader.default);
34+
_quill.default.register("modules/emoji", Emoji);
35+
_quill.default.register('modules/blotFormatter', _quillBlotFormatter.default);
36+
_quill.default.register(_customImage.default, true);
37+
var _default = /*#__PURE__*/function (_Controller) {
38+
_inherits(_default, _Controller);
39+
var _super = _createSuper(_default);
40+
function _default() {
41+
_classCallCheck(this, _default);
42+
return _super.apply(this, arguments);
43+
}
44+
_createClass(_default, [{
45+
key: "connect",
46+
value: function connect() {
47+
var _this = this;
48+
var toolbarOptionsValue = this.toolbarOptionsValue;
49+
var options = {
50+
debug: this.extraOptionsValue.debug,
51+
modules: {
52+
toolbar: toolbarOptionsValue,
53+
"emoji-toolbar": true,
54+
"emoji-shortname": true,
55+
blotFormatter: {
56+
overlay: {
57+
style: {
58+
border: '2px solid red'
59+
}
60+
}
61+
}
62+
},
63+
placeholder: this.extraOptionsValue.placeholder,
64+
theme: this.extraOptionsValue.theme
65+
};
66+
if (this.extraOptionsValue.upload_handler.path !== null && this.extraOptionsValue.upload_handler.type === 'form') {
67+
Object.assign(options.modules, {
68+
imageUploader: {
69+
upload: function upload(file) {
70+
return new Promise(function (resolve, reject) {
71+
var formData = new FormData();
72+
formData.append('file', file);
73+
_axios.default.post(_this.extraOptionsValue.upload_handler.path, formData).then(function (response) {
74+
resolve(response.data);
75+
}).catch(function (err) {
76+
reject('Upload failed');
77+
console.log(err);
78+
});
79+
});
80+
}
81+
}
82+
});
83+
}
84+
if (this.extraOptionsValue.upload_handler.path !== null && this.extraOptionsValue.upload_handler.type === 'json') {
85+
Object.assign(options.modules, {
86+
imageUploader: {
87+
upload: function upload(file) {
88+
return new Promise(function (resolve, reject) {
89+
var reader = function reader(file) {
90+
return new Promise(function (resolve) {
91+
var fileReader = new FileReader();
92+
fileReader.onload = function () {
93+
return resolve(fileReader.result);
94+
};
95+
fileReader.readAsDataURL(file);
96+
});
97+
};
98+
reader(file).then(function (result) {
99+
return _axios.default.post(_this.extraOptionsValue.upload_handler.path, result, {
100+
headers: {
101+
'Content-Type': 'application/json'
102+
}
103+
}).then(function (response) {
104+
resolve(response.data);
105+
}).catch(function (err) {
106+
reject('Upload failed');
107+
console.log(err);
108+
});
109+
});
110+
});
111+
}
112+
}
113+
});
114+
}
115+
if (typeof this.extraOptionsValue.height === "string") {
116+
this.editorContainerTarget.style.height = this.extraOptionsValue.height;
117+
}
118+
var quill = new _quill.default(this.editorContainerTarget, options);
119+
quill.on('text-change', function () {
120+
var quillContent = quill.root.innerHTML;
121+
var inputContent = _this.inputTarget;
122+
inputContent.value = quillContent;
123+
});
124+
}
125+
}]);
126+
return _default;
127+
}(_stimulus.Controller);
128+
exports.default = _default;
129+
_defineProperty(_default, "targets", ['input', 'editorContainer']);
130+
_defineProperty(_default, "values", {
131+
toolbarOptions: {
132+
type: Array,
133+
default: []
134+
},
135+
extraOptions: {
136+
type: Object,
137+
default: {}
138+
}
139+
});
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"use strict";
2+
3+
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); }
4+
Object.defineProperty(exports, "__esModule", {
5+
value: true
6+
});
7+
exports.default = void 0;
8+
var _quill = _interopRequireDefault(require("quill"));
9+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11+
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); } }
12+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
14+
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); }
15+
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); }
16+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
17+
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); }
18+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
19+
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); }; }
20+
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); }
21+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
22+
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; } }
23+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
24+
var BaseImageFormat = _quill.default.import('formats/image');
25+
var ImageFormatAttributesList = ['alt', 'height', 'width', 'class', 'style'];
26+
var ImageFormat = /*#__PURE__*/function (_BaseImageFormat) {
27+
_inherits(ImageFormat, _BaseImageFormat);
28+
var _super = _createSuper(ImageFormat);
29+
function ImageFormat() {
30+
_classCallCheck(this, ImageFormat);
31+
return _super.apply(this, arguments);
32+
}
33+
_createClass(ImageFormat, [{
34+
key: "format",
35+
value: function format(name, value) {
36+
if (ImageFormatAttributesList.indexOf(name) > -1) {
37+
if (value) {
38+
this.domNode.setAttribute(name, value);
39+
} else {
40+
this.domNode.removeAttribute(name);
41+
}
42+
} else {
43+
_get(_getPrototypeOf(ImageFormat.prototype), "format", this).call(this, name, value);
44+
}
45+
}
46+
}], [{
47+
key: "formats",
48+
value: function formats(domNode) {
49+
return ImageFormatAttributesList.reduce(function (formats, attribute) {
50+
if (domNode.hasAttribute(attribute)) {
51+
formats[attribute] = domNode.getAttribute(attribute);
52+
}
53+
return formats;
54+
}, {});
55+
}
56+
}]);
57+
return ImageFormat;
58+
}(BaseImageFormat);
59+
exports.default = ImageFormat;

0 commit comments

Comments
 (0)