292 lines
11 KiB
JavaScript
292 lines
11 KiB
JavaScript
/******/ (() => { // webpackBootstrap
|
|
/******/ "use strict";
|
|
/******/ var __webpack_modules__ = ({
|
|
|
|
/***/ "@wordpress/block-editor"
|
|
/*!*************************************!*\
|
|
!*** external ["wp","blockEditor"] ***!
|
|
\*************************************/
|
|
(module) {
|
|
|
|
module.exports = window["wp"]["blockEditor"];
|
|
|
|
/***/ },
|
|
|
|
/***/ "@wordpress/components"
|
|
/*!************************************!*\
|
|
!*** external ["wp","components"] ***!
|
|
\************************************/
|
|
(module) {
|
|
|
|
module.exports = window["wp"]["components"];
|
|
|
|
/***/ },
|
|
|
|
/***/ "@wordpress/element"
|
|
/*!*********************************!*\
|
|
!*** external ["wp","element"] ***!
|
|
\*********************************/
|
|
(module) {
|
|
|
|
module.exports = window["wp"]["element"];
|
|
|
|
/***/ },
|
|
|
|
/***/ "@wordpress/i18n"
|
|
/*!******************************!*\
|
|
!*** external ["wp","i18n"] ***!
|
|
\******************************/
|
|
(module) {
|
|
|
|
module.exports = window["wp"]["i18n"];
|
|
|
|
/***/ },
|
|
|
|
/***/ "@wordpress/plugins"
|
|
/*!*********************************!*\
|
|
!*** external ["wp","plugins"] ***!
|
|
\*********************************/
|
|
(module) {
|
|
|
|
module.exports = window["wp"]["plugins"];
|
|
|
|
/***/ },
|
|
|
|
/***/ "@wordpress/rich-text"
|
|
/*!**********************************!*\
|
|
!*** external ["wp","richText"] ***!
|
|
\**********************************/
|
|
(module) {
|
|
|
|
module.exports = window["wp"]["richText"];
|
|
|
|
/***/ },
|
|
|
|
/***/ "react/jsx-runtime"
|
|
/*!**********************************!*\
|
|
!*** external "ReactJSXRuntime" ***!
|
|
\**********************************/
|
|
(module) {
|
|
|
|
module.exports = window["ReactJSXRuntime"];
|
|
|
|
/***/ }
|
|
|
|
/******/ });
|
|
/************************************************************************/
|
|
/******/ // The module cache
|
|
/******/ var __webpack_module_cache__ = {};
|
|
/******/
|
|
/******/ // The require function
|
|
/******/ function __webpack_require__(moduleId) {
|
|
/******/ // Check if module is in cache
|
|
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
/******/ if (cachedModule !== undefined) {
|
|
/******/ return cachedModule.exports;
|
|
/******/ }
|
|
/******/ // Check if module exists (development only)
|
|
/******/ if (__webpack_modules__[moduleId] === undefined) {
|
|
/******/ var e = new Error("Cannot find module '" + moduleId + "'");
|
|
/******/ e.code = 'MODULE_NOT_FOUND';
|
|
/******/ throw e;
|
|
/******/ }
|
|
/******/ // Create a new module (and put it into the cache)
|
|
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
/******/ // no module.id needed
|
|
/******/ // no module.loaded needed
|
|
/******/ exports: {}
|
|
/******/ };
|
|
/******/
|
|
/******/ // Execute the module function
|
|
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
/******/
|
|
/******/ // Return the exports of the module
|
|
/******/ return module.exports;
|
|
/******/ }
|
|
/******/
|
|
/************************************************************************/
|
|
/******/ /* webpack/runtime/compat get default export */
|
|
/******/ (() => {
|
|
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
/******/ __webpack_require__.n = (module) => {
|
|
/******/ var getter = module && module.__esModule ?
|
|
/******/ () => (module['default']) :
|
|
/******/ () => (module);
|
|
/******/ __webpack_require__.d(getter, { a: getter });
|
|
/******/ return getter;
|
|
/******/ };
|
|
/******/ })();
|
|
/******/
|
|
/******/ /* webpack/runtime/define property getters */
|
|
/******/ (() => {
|
|
/******/ // define getter functions for harmony exports
|
|
/******/ __webpack_require__.d = (exports, definition) => {
|
|
/******/ for(var key in definition) {
|
|
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
/******/ }
|
|
/******/ }
|
|
/******/ };
|
|
/******/ })();
|
|
/******/
|
|
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
/******/ (() => {
|
|
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
/******/ })();
|
|
/******/
|
|
/******/ /* webpack/runtime/make namespace object */
|
|
/******/ (() => {
|
|
/******/ // define __esModule on exports
|
|
/******/ __webpack_require__.r = (exports) => {
|
|
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
/******/ }
|
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
/******/ };
|
|
/******/ })();
|
|
/******/
|
|
/************************************************************************/
|
|
var __webpack_exports__ = {};
|
|
// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
|
|
(() => {
|
|
/*!***********************!*\
|
|
!*** ./src/index.jsx ***!
|
|
\***********************/
|
|
__webpack_require__.r(__webpack_exports__);
|
|
/* harmony import */ var _wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/plugins */ "@wordpress/plugins");
|
|
/* harmony import */ var _wordpress_plugins__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__);
|
|
/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor");
|
|
/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__);
|
|
/* harmony import */ var _wordpress_rich_text__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/rich-text */ "@wordpress/rich-text");
|
|
/* harmony import */ var _wordpress_rich_text__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_2__);
|
|
/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components");
|
|
/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__);
|
|
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
|
|
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__);
|
|
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
|
|
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_5__);
|
|
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! react/jsx-runtime */ "react/jsx-runtime");
|
|
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__);
|
|
/**
|
|
* WordPress dependencies
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const SHORTCODE_NAME = 'wpdiscuz-feedback';
|
|
|
|
/**
|
|
* Generate unique ID
|
|
*/
|
|
function generateId() {
|
|
return Math.random().toString(36).substring(2, 12);
|
|
}
|
|
|
|
/**
|
|
* Escape shortcode attributes
|
|
*/
|
|
function escapeAttribute(value) {
|
|
return String(value).replace(/"/g, '"').replace(/\]/g, ']').replace(/\[/g, '[');
|
|
}
|
|
|
|
/**
|
|
* Open modal helper
|
|
*/
|
|
function openFeedbackModal({
|
|
selectedText,
|
|
value,
|
|
onChange
|
|
}) {
|
|
const container = document.createElement('div');
|
|
document.body.appendChild(container);
|
|
const ModalApp = () => {
|
|
const [question, setQuestion] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useState)(selectedText);
|
|
const [opened, setOpened] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useState)(false);
|
|
const close = () => {
|
|
(0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.unmountComponentAtNode)(container);
|
|
document.body.removeChild(container);
|
|
};
|
|
const insertShortcode = () => {
|
|
const shortcode = `[${SHORTCODE_NAME} ` + `id="${generateId()}" ` + `question="${escapeAttribute(question)}" ` + `opened="${opened ? 1 : 0}"]` + `${selectedText}` + `[/${SHORTCODE_NAME}]`;
|
|
onChange((0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_2__.insert)(value, shortcode, value.start, value.end));
|
|
close();
|
|
};
|
|
return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.Modal, {
|
|
title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Inline Feedback', 'wpdiscuz'),
|
|
onRequestClose: close,
|
|
children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.TextControl, {
|
|
label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Question', 'wpdiscuz'),
|
|
value: question,
|
|
onChange: setQuestion
|
|
}), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.ToggleControl, {
|
|
label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Opened by default', 'wpdiscuz'),
|
|
checked: opened,
|
|
onChange: setOpened
|
|
}), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)("div", {
|
|
style: {
|
|
marginTop: 16
|
|
},
|
|
children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.Button, {
|
|
variant: "primary",
|
|
onClick: insertShortcode,
|
|
children: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Insert', 'wpdiscuz')
|
|
}), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.Button, {
|
|
variant: "secondary",
|
|
onClick: close,
|
|
style: {
|
|
marginLeft: 8
|
|
},
|
|
children: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Cancel', 'wpdiscuz')
|
|
})]
|
|
})]
|
|
});
|
|
};
|
|
(0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.render)(/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(ModalApp, {}), container);
|
|
}
|
|
|
|
/**
|
|
* Register RichText format
|
|
*/
|
|
(0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_2__.registerFormatType)('wpdiscuz/feedback', {
|
|
title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Inline Feedback', 'wpdiscuz'),
|
|
tagName: 'span',
|
|
className: 'wpdiscuz-feedback-format',
|
|
edit({
|
|
value,
|
|
onChange
|
|
}) {
|
|
if (!value || value.start === value.end) {
|
|
return null;
|
|
}
|
|
const selectedText = value.text?.slice(value.start, value.end) || '';
|
|
if (!selectedText) {
|
|
return null;
|
|
}
|
|
return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.RichTextToolbarButton, {
|
|
icon: "shortcode",
|
|
title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Inline Feedback', 'wpdiscuz'),
|
|
onClick: () => openFeedbackModal({
|
|
selectedText,
|
|
value,
|
|
onChange
|
|
})
|
|
});
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Plugin registration
|
|
*/
|
|
(0,_wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__.registerPlugin)('wpdiscuz-shortcode-inserter', {
|
|
render: () => null
|
|
});
|
|
})();
|
|
|
|
/******/ })()
|
|
;
|
|
//# sourceMappingURL=index.js.map
|