Skip to content

Commit

Permalink
Merge pull request #13 from Ehyiah/issue/12-fix-for-asset-mapper
Browse files Browse the repository at this point in the history
fix imports && typescript && add compatiblity with assetMapper auto i…
  • Loading branch information
Ehyiah authored Feb 9, 2024
2 parents 12d23b6 + bfb4db5 commit d8ae655
Show file tree
Hide file tree
Showing 9 changed files with 1,763 additions and 1,630 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
```sh
composer require ehyiah/ux-quill
```
If you are using the AssetMapper Component you're done !

If you are using webpack encore follow next step
### step 2 next run
``` sh
yarn install --force
Expand Down
14 changes: 0 additions & 14 deletions assets/.babelrc

This file was deleted.

12 changes: 12 additions & 0 deletions assets/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
presets: [
['@babel/preset-env', {
"loose": true,
"modules": false
}],
['@babel/preset-typescript', { allowDeclareFields: true }]
],
assumptions: {
superIsCallableConstructor: false,
},
};
198 changes: 89 additions & 109 deletions assets/dist/controller.js
Original file line number Diff line number Diff line change
@@ -1,129 +1,109 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _stimulus = require("@hotwired/stimulus");
var _quill = _interopRequireDefault(require("quill/dist/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"));
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 _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
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 _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
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);
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _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); }
import { Controller } from '@hotwired/stimulus';
import Quill from 'quill';
import axios from 'axios';
import ImageUploader from 'quill-image-uploader';
import 'quill-image-uploader/dist/quill.imageUploader.min.css';
Quill.register('modules/imageUploader', ImageUploader);
import 'quill-emoji/dist/quill-emoji.css';
import * as Emoji from 'quill-emoji';
Quill.register('modules/emoji', Emoji);
var _default = /*#__PURE__*/function (_Controller) {
_inherits(_default, _Controller);
var _super = _createSuper(_default);
_inheritsLoose(_default, _Controller);
function _default() {
_classCallCheck(this, _default);
return _super.apply(this, arguments);
return _callSuper(this, _default, 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
},
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) {
var _proto = _default.prototype;
_proto.connect = function connect() {
var _this = this;
var toolbarOptionsValue = this.toolbarOptionsValue;
var options = {
debug: this.extraOptionsValue.debug,
modules: {
toolbar: toolbarOptionsValue,
'emoji-toolbar': true,
'emoji-shortname': true
},
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.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.post(_this.extraOptionsValue.upload_handler.path, result, {
headers: {
'Content-Type': 'application/json'
}
}).then(function (response) {
resolve(response.data);
}).catch(function (err) {
})["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);
});
});
});
}
}
});
}
var heightDefined = this.extraOptionsValue.height;
if (null !== heightDefined) {
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;
}
});
}
}]);
var heightDefined = this.extraOptionsValue.height;
if (null !== heightDefined) {
this.editorContainerTarget.style.height = this.extraOptionsValue.height;
}
var quill = new Quill(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", {
}(Controller);
_default.targets = ['input', 'editorContainer'];
_default.values = {
toolbarOptions: {
type: Array,
default: []
"default": []
},
extraOptions: {
type: Object,
default: {}
"default": {}
}
});
};
export { _default as default };
42 changes: 31 additions & 11 deletions assets/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ehyiah/ux-quill",
"description": "Symfony bundle to use Quill JS text editor",
"version": "0.0.5",
"version": "0.1.1",
"license": "MIT",
"main": "dist/controller.js",
"symfony": {
Expand All @@ -16,6 +16,19 @@
"quill/dist/quill.bubble.css": false
}
}
},
"importmap": {
"@hotwired/stimulus": "^3.0.0",
"slugify": "^1.6.5",
"quill": "^1.3.7",
"quill-emoji": "^0.2.0",
"quill-image-uploader": "^1.3.0",
"file-loader": "^6.2.0",
"quill/dist/quill.snow.css": "1.3.7",
"quill/dist/quill.bubble.css": "1.3.7",
"quill-image-uploader/dist/quill.imageUploader.min.css": "1.3.0",
"quill-emoji/dist/quill-emoji.css": "0.2.0",
"axios": "^1.4.0"
}
},
"scripts": {
Expand All @@ -29,34 +42,41 @@
"@babel/cli": "^7.20.7",
"@babel/core": "^7.20.12",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@hotwired/stimulus": "^3.2.1",
"@symfony/webpack-encore": "^4.0.0",
"@testing-library/dom": "^9.3.0",
"@types/jest": "^29.5.2",
"@typescript-eslint/eslint-plugin": "^5.2.0",
"@typescript-eslint/parser": "^5.2.0",
"core-js": "^3.30.2",
"ts-loader": "^9.0.0",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"webpack-notifier": "^1.15.0",
"eslint": "^8.1.0",
"eslint-config-prettier": "^8.0.0",
"eslint-plugin-jest": "^25.2.2",
"ts-loader": "^9.0.0",
"typescript": "^4.9.5",
"@typescript-eslint/eslint-plugin": "^5.2.0",
"@typescript-eslint/parser": "^5.2.0",
"eslint-plugin-jest": "^25.2.2"
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"webpack-notifier": "^1.15.0"
},
"peerDependencies": {
"@hotwired/stimulus": "^3.0.0",
"axios": "^1.4.0",
"file-loader": "^6.2.0",
"quill": "^1.3.7",
"quill-emoji": "^0.2.0",
"quill-image-uploader": "^1.3.0",
"slugify": "^1.6.5"
},
"dependencies": {
"@testing-library/dom": "^9.3.0",
"@types/jest": "^29.5.2",
"axios": "^1.4.0",
"file-loader": "^6.2.0",
"quill": "^1.3.7",
"quill-emoji": "^0.2.0",
"quill-image-uploader": "^1.3.0",
"axios": "^1.4.0"
"slugify": "^1.6.5"
},
"eslintConfig": {
"root": true,
Expand Down
23 changes: 12 additions & 11 deletions assets/src/controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Controller } from '@hotwired/stimulus';
import Quill from 'quill/dist/quill';
import Quill from 'quill';

import ImageUploader from 'quill-image-uploader';
import axios from 'axios';

import ImageUploader from 'quill-image-uploader';
import 'quill-image-uploader/dist/quill.imageUploader.min.css';
Quill.register('modules/imageUploader', ImageUploader);

import "quill-emoji/dist/quill-emoji.css";
import * as Emoji from "quill-emoji";
Quill.register("modules/emoji", Emoji);
import 'quill-emoji/dist/quill-emoji.css';
import * as Emoji from 'quill-emoji';
Quill.register('modules/emoji', Emoji);

type ExtraOptions = {
theme: string;
Expand All @@ -23,12 +24,12 @@ type uploadOptions = {
}

export default class extends Controller {
readonly inputTarget: HTMLInputElement;
readonly editorContainerTarget: HTMLDivElement;
declare readonly inputTarget: HTMLInputElement;
declare readonly editorContainerTarget: HTMLDivElement;
static targets = ['input', 'editorContainer'];

readonly extraOptionsValue: ExtraOptions;
readonly toolbarOptionsValue: HTMLDivElement;
declare readonly extraOptionsValue: ExtraOptions;
declare readonly toolbarOptionsValue: HTMLDivElement;
static values = {
toolbarOptions: {
type: Array,
Expand All @@ -47,8 +48,8 @@ export default class extends Controller {
debug: this.extraOptionsValue.debug,
modules: {
toolbar: toolbarOptionsValue,
"emoji-toolbar": true,
"emoji-shortname": true,
'emoji-toolbar': true,
'emoji-shortname': true,
},
placeholder: this.extraOptionsValue.placeholder,
theme: this.extraOptionsValue.theme,
Expand Down
Loading

0 comments on commit d8ae655

Please sign in to comment.