Changeset 2830213
- Timestamp:
- 12/07/2022 06:17:30 PM (3 years ago)
- Location:
- writers-block-block
- Files:
-
- 3 added
- 12 deleted
- 11 edited
- 1 copied
-
assets/screenshot-1.png (modified) (previous)
-
assets/screenshot-2.png (added)
-
tags/0.3.1 (copied) (copied from writers-block-block/trunk)
-
tags/0.3.1/block.json (deleted)
-
tags/0.3.1/build/index.asset.php (modified) (1 diff)
-
tags/0.3.1/build/index.css (modified) (1 diff)
-
tags/0.3.1/build/index.css.map (deleted)
-
tags/0.3.1/build/index.js (modified) (1 diff)
-
tags/0.3.1/build/index.js.map (deleted)
-
tags/0.3.1/build/style-index.css (modified) (1 diff)
-
tags/0.3.1/build/style-index.css.map (deleted)
-
tags/0.3.1/coauthor.php (added)
-
tags/0.3.1/readme.txt (modified) (5 diffs)
-
tags/0.3.1/webpack.config.js (deleted)
-
tags/0.3.1/writers-block-block.php (deleted)
-
trunk/block.json (deleted)
-
trunk/build/index.asset.php (modified) (1 diff)
-
trunk/build/index.css (modified) (1 diff)
-
trunk/build/index.css.map (deleted)
-
trunk/build/index.js (modified) (1 diff)
-
trunk/build/index.js.map (deleted)
-
trunk/build/style-index.css (modified) (1 diff)
-
trunk/build/style-index.css.map (deleted)
-
trunk/coauthor.php (added)
-
trunk/readme.txt (modified) (5 diffs)
-
trunk/webpack.config.js (deleted)
-
trunk/writers-block-block.php (deleted)
Legend:
- Unmodified
- Added
- Removed
-
writers-block-block/tags/0.3.1/build/index.asset.php
r2447227 r2830213 1 <?php return array('dependencies' => array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n' , 'wp-polyfill'), 'version' => '88e33d174ae417ab67c90d7cc5711978');1 <?php return array('dependencies' => array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '8e011ee4c2d87fd36bb2'); -
writers-block-block/tags/0.3.1/build/index.css
r2447227 r2830213 1 /** 2 * The following styles get applied inside the editor only. 3 * 4 * Replace them with your own styles or remove the file completely. 5 */ 6 .wp-block-writers-block-block-generate-suggestion { 7 border: 1px solid #3b2479; 8 padding: 0; } 9 10 .wp-block-writers-block-block-generate-suggestion .disclaimer, .wp-block-writers-block-block-generate-suggestion .components-base-control__label { 11 width: 100%; 12 background-color: #3b2479; 13 padding-top: 4px; 14 padding-bottom: 4px; 15 padding-left: 8px; 16 color: white; 17 font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; 18 font-size: small; } 19 20 .wp-block-writers-block-block-generate-suggestion .content { 21 padding: 4px; } 22 23 .wp-block-writers-block-block-generate-suggestion .components-text-control__input { 24 margin: 10px; 25 width: 80%; } 26 27 .wp-block-writers-block-block-generate-suggestion .components-button.is-primary { 28 margin: 10px; } 29 30 31 /*# sourceMappingURL=index.css.map*/ 1 .wp-block-coauthor-generate-suggestion{padding:0}.wp-block-coauthor-generate-suggestion .components-text-control__input{margin:10px;width:80%}.wp-block-coauthor-generate-suggestion .components-button.is-primary{margin:10px} -
writers-block-block/tags/0.3.1/build/index.js
r2447227 r2830213 1 (window["webpackJsonp"] = window["webpackJsonp"] || []).push([["style-index"],{ 2 3 /***/ "./src/style.scss": 4 /*!************************!*\ 5 !*** ./src/style.scss ***! 6 \************************/ 7 /*! no static exports found */ 8 /***/ (function(module, exports, __webpack_require__) { 9 10 // extracted by mini-css-extract-plugin 11 12 /***/ }) 13 14 }]); 15 16 /******/ (function(modules) { // webpackBootstrap 17 /******/ // install a JSONP callback for chunk loading 18 /******/ function webpackJsonpCallback(data) { 19 /******/ var chunkIds = data[0]; 20 /******/ var moreModules = data[1]; 21 /******/ var executeModules = data[2]; 22 /******/ 23 /******/ // add "moreModules" to the modules object, 24 /******/ // then flag all "chunkIds" as loaded and fire callback 25 /******/ var moduleId, chunkId, i = 0, resolves = []; 26 /******/ for(;i < chunkIds.length; i++) { 27 /******/ chunkId = chunkIds[i]; 28 /******/ if(Object.prototype.hasOwnProperty.call(installedChunks, chunkId) && installedChunks[chunkId]) { 29 /******/ resolves.push(installedChunks[chunkId][0]); 30 /******/ } 31 /******/ installedChunks[chunkId] = 0; 32 /******/ } 33 /******/ for(moduleId in moreModules) { 34 /******/ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) { 35 /******/ modules[moduleId] = moreModules[moduleId]; 36 /******/ } 37 /******/ } 38 /******/ if(parentJsonpFunction) parentJsonpFunction(data); 39 /******/ 40 /******/ while(resolves.length) { 41 /******/ resolves.shift()(); 42 /******/ } 43 /******/ 44 /******/ // add entry modules from loaded chunk to deferred list 45 /******/ deferredModules.push.apply(deferredModules, executeModules || []); 46 /******/ 47 /******/ // run deferred modules when all chunks ready 48 /******/ return checkDeferredModules(); 49 /******/ }; 50 /******/ function checkDeferredModules() { 51 /******/ var result; 52 /******/ for(var i = 0; i < deferredModules.length; i++) { 53 /******/ var deferredModule = deferredModules[i]; 54 /******/ var fulfilled = true; 55 /******/ for(var j = 1; j < deferredModule.length; j++) { 56 /******/ var depId = deferredModule[j]; 57 /******/ if(installedChunks[depId] !== 0) fulfilled = false; 58 /******/ } 59 /******/ if(fulfilled) { 60 /******/ deferredModules.splice(i--, 1); 61 /******/ result = __webpack_require__(__webpack_require__.s = deferredModule[0]); 62 /******/ } 63 /******/ } 64 /******/ 65 /******/ return result; 66 /******/ } 67 /******/ 68 /******/ // The module cache 69 /******/ var installedModules = {}; 70 /******/ 71 /******/ // object to store loaded and loading chunks 72 /******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched 73 /******/ // Promise = chunk loading, 0 = chunk loaded 74 /******/ var installedChunks = { 75 /******/ "index": 0 76 /******/ }; 77 /******/ 78 /******/ var deferredModules = []; 79 /******/ 80 /******/ // The require function 81 /******/ function __webpack_require__(moduleId) { 82 /******/ 83 /******/ // Check if module is in cache 84 /******/ if(installedModules[moduleId]) { 85 /******/ return installedModules[moduleId].exports; 86 /******/ } 87 /******/ // Create a new module (and put it into the cache) 88 /******/ var module = installedModules[moduleId] = { 89 /******/ i: moduleId, 90 /******/ l: false, 91 /******/ exports: {} 92 /******/ }; 93 /******/ 94 /******/ // Execute the module function 95 /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 96 /******/ 97 /******/ // Flag the module as loaded 98 /******/ module.l = true; 99 /******/ 100 /******/ // Return the exports of the module 101 /******/ return module.exports; 102 /******/ } 103 /******/ 104 /******/ 105 /******/ // expose the modules object (__webpack_modules__) 106 /******/ __webpack_require__.m = modules; 107 /******/ 108 /******/ // expose the module cache 109 /******/ __webpack_require__.c = installedModules; 110 /******/ 111 /******/ // define getter function for harmony exports 112 /******/ __webpack_require__.d = function(exports, name, getter) { 113 /******/ if(!__webpack_require__.o(exports, name)) { 114 /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); 115 /******/ } 116 /******/ }; 117 /******/ 118 /******/ // define __esModule on exports 119 /******/ __webpack_require__.r = function(exports) { 120 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 121 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 122 /******/ } 123 /******/ Object.defineProperty(exports, '__esModule', { value: true }); 124 /******/ }; 125 /******/ 126 /******/ // create a fake namespace object 127 /******/ // mode & 1: value is a module id, require it 128 /******/ // mode & 2: merge all properties of value into the ns 129 /******/ // mode & 4: return value when already ns object 130 /******/ // mode & 8|1: behave like require 131 /******/ __webpack_require__.t = function(value, mode) { 132 /******/ if(mode & 1) value = __webpack_require__(value); 133 /******/ if(mode & 8) return value; 134 /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; 135 /******/ var ns = Object.create(null); 136 /******/ __webpack_require__.r(ns); 137 /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); 138 /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); 139 /******/ return ns; 140 /******/ }; 141 /******/ 142 /******/ // getDefaultExport function for compatibility with non-harmony modules 143 /******/ __webpack_require__.n = function(module) { 144 /******/ var getter = module && module.__esModule ? 145 /******/ function getDefault() { return module['default']; } : 146 /******/ function getModuleExports() { return module; }; 147 /******/ __webpack_require__.d(getter, 'a', getter); 148 /******/ return getter; 149 /******/ }; 150 /******/ 151 /******/ // Object.prototype.hasOwnProperty.call 152 /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 153 /******/ 154 /******/ // __webpack_public_path__ 155 /******/ __webpack_require__.p = ""; 156 /******/ 157 /******/ var jsonpArray = window["webpackJsonp"] = window["webpackJsonp"] || []; 158 /******/ var oldJsonpFunction = jsonpArray.push.bind(jsonpArray); 159 /******/ jsonpArray.push = webpackJsonpCallback; 160 /******/ jsonpArray = jsonpArray.slice(); 161 /******/ for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]); 162 /******/ var parentJsonpFunction = oldJsonpFunction; 163 /******/ 164 /******/ 165 /******/ // add entry module to deferred list 166 /******/ deferredModules.push(["./src/index.js","style-index"]); 167 /******/ // run deferred modules when ready 168 /******/ return checkDeferredModules(); 169 /******/ }) 170 /************************************************************************/ 171 /******/ ({ 172 173 /***/ "./node_modules/@babel/runtime/helpers/arrayLikeToArray.js": 174 /*!*****************************************************************!*\ 175 !*** ./node_modules/@babel/runtime/helpers/arrayLikeToArray.js ***! 176 \*****************************************************************/ 177 /*! no static exports found */ 178 /***/ (function(module, exports) { 179 180 function _arrayLikeToArray(arr, len) { 181 if (len == null || len > arr.length) len = arr.length; 182 183 for (var i = 0, arr2 = new Array(len); i < len; i++) { 184 arr2[i] = arr[i]; 185 } 186 187 return arr2; 188 } 189 190 module.exports = _arrayLikeToArray; 191 192 /***/ }), 193 194 /***/ "./node_modules/@babel/runtime/helpers/arrayWithHoles.js": 195 /*!***************************************************************!*\ 196 !*** ./node_modules/@babel/runtime/helpers/arrayWithHoles.js ***! 197 \***************************************************************/ 198 /*! no static exports found */ 199 /***/ (function(module, exports) { 200 201 function _arrayWithHoles(arr) { 202 if (Array.isArray(arr)) return arr; 203 } 204 205 module.exports = _arrayWithHoles; 206 207 /***/ }), 208 209 /***/ "./node_modules/@babel/runtime/helpers/iterableToArrayLimit.js": 210 /*!*********************************************************************!*\ 211 !*** ./node_modules/@babel/runtime/helpers/iterableToArrayLimit.js ***! 212 \*********************************************************************/ 213 /*! no static exports found */ 214 /***/ (function(module, exports) { 215 216 function _iterableToArrayLimit(arr, i) { 217 if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; 218 var _arr = []; 219 var _n = true; 220 var _d = false; 221 var _e = undefined; 222 223 try { 224 for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { 225 _arr.push(_s.value); 226 227 if (i && _arr.length === i) break; 228 } 229 } catch (err) { 230 _d = true; 231 _e = err; 232 } finally { 233 try { 234 if (!_n && _i["return"] != null) _i["return"](); 235 } finally { 236 if (_d) throw _e; 237 } 238 } 239 240 return _arr; 241 } 242 243 module.exports = _iterableToArrayLimit; 244 245 /***/ }), 246 247 /***/ "./node_modules/@babel/runtime/helpers/nonIterableRest.js": 248 /*!****************************************************************!*\ 249 !*** ./node_modules/@babel/runtime/helpers/nonIterableRest.js ***! 250 \****************************************************************/ 251 /*! no static exports found */ 252 /***/ (function(module, exports) { 253 254 function _nonIterableRest() { 255 throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); 256 } 257 258 module.exports = _nonIterableRest; 259 260 /***/ }), 261 262 /***/ "./node_modules/@babel/runtime/helpers/slicedToArray.js": 263 /*!**************************************************************!*\ 264 !*** ./node_modules/@babel/runtime/helpers/slicedToArray.js ***! 265 \**************************************************************/ 266 /*! no static exports found */ 267 /***/ (function(module, exports, __webpack_require__) { 268 269 var arrayWithHoles = __webpack_require__(/*! ./arrayWithHoles */ "./node_modules/@babel/runtime/helpers/arrayWithHoles.js"); 270 271 var iterableToArrayLimit = __webpack_require__(/*! ./iterableToArrayLimit */ "./node_modules/@babel/runtime/helpers/iterableToArrayLimit.js"); 272 273 var unsupportedIterableToArray = __webpack_require__(/*! ./unsupportedIterableToArray */ "./node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js"); 274 275 var nonIterableRest = __webpack_require__(/*! ./nonIterableRest */ "./node_modules/@babel/runtime/helpers/nonIterableRest.js"); 276 277 function _slicedToArray(arr, i) { 278 return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest(); 279 } 280 281 module.exports = _slicedToArray; 282 283 /***/ }), 284 285 /***/ "./node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js": 286 /*!***************************************************************************!*\ 287 !*** ./node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js ***! 288 \***************************************************************************/ 289 /*! no static exports found */ 290 /***/ (function(module, exports, __webpack_require__) { 291 292 var arrayLikeToArray = __webpack_require__(/*! ./arrayLikeToArray */ "./node_modules/@babel/runtime/helpers/arrayLikeToArray.js"); 293 294 function _unsupportedIterableToArray(o, minLen) { 295 if (!o) return; 296 if (typeof o === "string") return arrayLikeToArray(o, minLen); 297 var n = Object.prototype.toString.call(o).slice(8, -1); 298 if (n === "Object" && o.constructor) n = o.constructor.name; 299 if (n === "Map" || n === "Set") return Array.from(o); 300 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen); 301 } 302 303 module.exports = _unsupportedIterableToArray; 304 305 /***/ }), 306 307 /***/ "./src/edit.js": 308 /*!*********************!*\ 309 !*** ./src/edit.js ***! 310 \*********************/ 311 /*! exports provided: default */ 312 /***/ (function(module, __webpack_exports__, __webpack_require__) { 313 314 "use strict"; 315 __webpack_require__.r(__webpack_exports__); 316 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Edit; }); 317 /* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/slicedToArray */ "./node_modules/@babel/runtime/helpers/slicedToArray.js"); 318 /* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__); 319 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); 320 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__); 321 /* harmony import */ var _editor_scss__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./editor.scss */ "./src/editor.scss"); 322 /* harmony import */ var _editor_scss__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_editor_scss__WEBPACK_IMPORTED_MODULE_2__); 323 /* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/api-fetch */ "@wordpress/api-fetch"); 324 /* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3__); 325 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); 326 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__); 327 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); 328 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_5__); 329 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); 330 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_6__); 331 332 333 334 335 336 337 338 339 /** 340 * This function formats the prompt to OpenAI. 341 * In this case, it gets all the blocks in the editor BEFORE the current blocks, extracts text and creates a continous prompt. 342 * But other modes are possible - for example get first sentence from every block and only prompt this way. 343 * 344 * @see https://beta.openai.com/docs/introduction/prompt-design-101 345 * @param {Object} editor - reference to GB block editor instance. @see https://developer.wordpress.org/block-editor/data/data-core-editor/. 346 */ 347 348 function formatPromptToOpenAI(editor) { 349 var index = editor.getBlockInsertionPoint().index - 1; 350 var allBlocksBefore = editor.getBlocks().slice(0, index); 351 return allBlocksBefore.filter(function (block) { 352 return block && block.attributes && block.attributes.content; 353 }).map(function (block) { 354 return block.attributes.content.replaceAll('<br>', '\n\n'); 355 }).join('\n\n'); 356 } 357 358 function getSuggestionFromOpenAI(setAttributes, token, setPromptedForToken, formattedPrompt) { 359 var data = { 360 content: formattedPrompt 361 }; 362 363 if (token) { 364 data.token = token; 365 setPromptedForToken(false); 366 } 367 368 _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3___default()({ 369 path: '/writers-block/prompt', 370 method: 'POST', 371 data: data 372 }).then(function (res) { 373 setAttributes({ 374 content: res.prompts[0].text 375 }); 376 }).catch(function (res) { 377 // We have not yet submitted a token. 378 if (res.code === 'openai_token_missing') { 379 setPromptedForToken(true); 380 } 381 }); 382 } 383 /** 384 * The edit function describes the structure of your block in the context of the 385 * editor. This represents what the editor will render when the block is used. 386 * 387 * @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#edit 388 * 389 * @return {WPElement} Element to render. 390 */ 391 392 393 function Edit(_ref) { 394 var attributes = _ref.attributes, 395 setAttributes = _ref.setAttributes; 396 397 var _useState = Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["useState"])(false), 398 _useState2 = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default()(_useState, 2), 399 promptedForToken = _useState2[0], 400 setPromptedForToken = _useState2[1]; 401 402 var _useState3 = Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["useState"])(''), 403 _useState4 = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default()(_useState3, 2), 404 tokenField = _useState4[0], 405 setTokenField = _useState4[1]; 406 407 var formattedPrompt = Object(_wordpress_data__WEBPACK_IMPORTED_MODULE_6__["useSelect"])(function (select) { 408 return formatPromptToOpenAI(select('core/block-editor')); 409 }, []); 410 411 function submitToken() { 412 getSuggestionFromOpenAI(setAttributes, tokenField, setPromptedForToken, formattedPrompt); 413 } //useEffect hook is called only once when block is first rendered. 414 415 416 Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["useEffect"])(function () { 417 //Theoretically useEffect would ensure we only fire this once, but I don't want to fire it when we get data to edit either. 418 setAttributes({ 419 requestedPrompt: true 420 }); 421 422 if (!attributes.requestedPrompt) { 423 getSuggestionFromOpenAI(setAttributes, false, setPromptedForToken, formattedPrompt); 424 } 425 }, []); 426 return Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])("div", Object(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__["useBlockProps"])(), promptedForToken && Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])("div", null, Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])(_wordpress_components__WEBPACK_IMPORTED_MODULE_5__["TextControl"], { 427 label: "Please provide the OpenAI token to continue:", 428 value: tokenField, 429 onChange: function onChange(val) { 430 return setTokenField(val); 431 } 432 }), Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])(_wordpress_components__WEBPACK_IMPORTED_MODULE_5__["Button"], { 433 isPrimary: true, 434 onClick: function onClick() { 435 return submitToken(); 436 } 437 }, 'Submit')), !promptedForToken && Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])("div", null, Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])("div", { 438 className: "disclaimer" 439 }, "GPT-3 says:"), Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])("div", { 440 className: "content" 441 }, Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["RawHTML"], null, attributes.content.trim().replaceAll('\n', '<br/>'))))); 442 } 443 444 /***/ }), 445 446 /***/ "./src/editor.scss": 447 /*!*************************!*\ 448 !*** ./src/editor.scss ***! 449 \*************************/ 450 /*! no static exports found */ 451 /***/ (function(module, exports, __webpack_require__) { 452 453 // extracted by mini-css-extract-plugin 454 455 /***/ }), 456 457 /***/ "./src/index.js": 458 /*!**********************!*\ 459 !*** ./src/index.js ***! 460 \**********************/ 461 /*! no exports provided */ 462 /***/ (function(module, __webpack_exports__, __webpack_require__) { 463 464 "use strict"; 465 __webpack_require__.r(__webpack_exports__); 466 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks"); 467 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__); 468 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); 469 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__); 470 /* harmony import */ var _style_scss__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./style.scss */ "./src/style.scss"); 471 /* harmony import */ var _style_scss__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_style_scss__WEBPACK_IMPORTED_MODULE_2__); 472 /* harmony import */ var _edit__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./edit */ "./src/edit.js"); 473 /* harmony import */ var _save__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./save */ "./src/save.js"); 474 475 476 477 478 479 /** 480 * Every block starts by registering a new block type definition. 481 * 482 * @see https://developer.wordpress.org/block-editor/developers/block-api/#registering-a-block 483 */ 484 485 Object(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__["registerBlockType"])('writers-block-block/generate-suggestion', { 486 apiVersion: 2, 487 title: Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__["__"])('Writers Block Block', 'writers-block-block'), 488 description: Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__["__"])('Automatically generate new paragraphs using your existing content, GPT-3 and robots.', 'writers-block-block'), 489 category: 'common', 490 icon: 'welcome-write-blog', 491 supports: { 492 html: false 493 }, 494 attributes: { 495 content: { 496 type: 'string', 497 source: 'text', 498 default: Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__["__"])('Please wait, consulting robots about your content… 🤖', 'writers-block-block') 499 }, 500 requestedPrompt: { 501 type: 'boolean', 502 default: false 503 } 504 }, 505 // We are allowing transform to a paragraph to use the generated content. 506 // Maybe we should provide a button inside the block that triggers the transform? 507 transforms: { 508 to: [{ 509 type: 'block', 510 blocks: ['core/paragraph'], 511 transform: function transform(_ref) { 512 var content = _ref.content; 513 return Object(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__["createBlock"])('core/paragraph', { 514 content: content 515 }); 516 } 517 }] 518 }, 519 520 /** 521 * @see ./edit.js 522 */ 523 edit: _edit__WEBPACK_IMPORTED_MODULE_3__["default"], 524 525 /** 526 * @see ./save.js 527 */ 528 save: _save__WEBPACK_IMPORTED_MODULE_4__["default"] 529 }); 530 531 /***/ }), 532 533 /***/ "./src/save.js": 534 /*!*********************!*\ 535 !*** ./src/save.js ***! 536 \*********************/ 537 /*! exports provided: default */ 538 /***/ (function(module, __webpack_exports__, __webpack_require__) { 539 540 "use strict"; 541 __webpack_require__.r(__webpack_exports__); 542 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return save; }); 543 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); 544 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__); 545 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); 546 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__); 547 548 549 /** 550 * Retrieves the translation of text. 551 * 552 * @see https://developer.wordpress.org/block-editor/packages/packages-i18n/ 553 */ 554 555 /** 556 * The save function defines the way in which the different attributes should 557 * be combined into the final markup, which is then serialized by the block 558 * editor into `post_content`. 559 * 560 * @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save 561 * 562 * @return {WPElement} Element to render. 563 */ 564 565 function save(_ref) { 566 var attributes = _ref.attributes; 567 var blockProps = _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__["useBlockProps"].save(); 568 return Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__["createElement"])("div", blockProps, attributes.content); 569 } 570 571 /***/ }), 572 573 /***/ "@wordpress/api-fetch": 574 /*!**********************************!*\ 575 !*** external ["wp","apiFetch"] ***! 576 \**********************************/ 577 /*! no static exports found */ 578 /***/ (function(module, exports) { 579 580 (function() { module.exports = window["wp"]["apiFetch"]; }()); 581 582 /***/ }), 583 584 /***/ "@wordpress/block-editor": 585 /*!*************************************!*\ 586 !*** external ["wp","blockEditor"] ***! 587 \*************************************/ 588 /*! no static exports found */ 589 /***/ (function(module, exports) { 590 591 (function() { module.exports = window["wp"]["blockEditor"]; }()); 592 593 /***/ }), 594 595 /***/ "@wordpress/blocks": 596 /*!********************************!*\ 597 !*** external ["wp","blocks"] ***! 598 \********************************/ 599 /*! no static exports found */ 600 /***/ (function(module, exports) { 601 602 (function() { module.exports = window["wp"]["blocks"]; }()); 603 604 /***/ }), 605 606 /***/ "@wordpress/components": 607 /*!************************************!*\ 608 !*** external ["wp","components"] ***! 609 \************************************/ 610 /*! no static exports found */ 611 /***/ (function(module, exports) { 612 613 (function() { module.exports = window["wp"]["components"]; }()); 614 615 /***/ }), 616 617 /***/ "@wordpress/data": 618 /*!******************************!*\ 619 !*** external ["wp","data"] ***! 620 \******************************/ 621 /*! no static exports found */ 622 /***/ (function(module, exports) { 623 624 (function() { module.exports = window["wp"]["data"]; }()); 625 626 /***/ }), 627 628 /***/ "@wordpress/element": 629 /*!*********************************!*\ 630 !*** external ["wp","element"] ***! 631 \*********************************/ 632 /*! no static exports found */ 633 /***/ (function(module, exports) { 634 635 (function() { module.exports = window["wp"]["element"]; }()); 636 637 /***/ }), 638 639 /***/ "@wordpress/i18n": 640 /*!******************************!*\ 641 !*** external ["wp","i18n"] ***! 642 \******************************/ 643 /*! no static exports found */ 644 /***/ (function(module, exports) { 645 646 (function() { module.exports = window["wp"]["i18n"]; }()); 647 648 /***/ }) 649 650 /******/ }); 651 //# sourceMappingURL=index.js.map 1 !function(){"use strict";var e,t={75:function(e,t,n){var o=window.wp.blocks,r=window.wp.i18n,a=window.wp.element,c=window.wp.apiFetch,i=n.n(c),l=window.wp.blockEditor,s=window.wp.components,u=window.wp.data;function p(e,t,n,o,r){const a={content:o};t&&(a.token=t,n(!1)),r(!0),e({requestedPrompt:!0}),i()({path:"/coauthor/prompt",method:"POST",data:a}).then((t=>{r(!1);const n=t.prompts[0].text.split(" ");for(let t=0;t<n.length;t++){const o=n.slice(0,t).join(" ");setTimeout((()=>e({content:o})),50*t)}})).catch((t=>{"openai_token_missing"===t.code&&(n(!0),r(!1),e({requestedPrompt:!1}))}))}(0,o.registerBlockType)("coauthor/paragraph",{apiVersion:2,title:(0,r.__)("Coauthor Paragraph","coauthor"),description:(0,r.__)("Automatically generate new paragraphs using your existing content, GPT-3 and robots.","coauthor"),category:"common",icon:"welcome-write-blog",supports:{html:!1},attributes:{content:{type:"string",source:"text"},requestedPrompt:{type:"boolean",default:!1}},transforms:{to:[{type:"block",blocks:["core/paragraph"],transform:e=>{let{content:t}=e;return(0,o.createBlock)("core/paragraph",{content:t})}}]},edit:function(e){let{attributes:t,setAttributes:n}=e;const[o,r]=(0,a.useState)(!1),[c,i]=(0,a.useState)(!1),[m,d]=(0,a.useState)(""),g=(0,u.useSelect)((e=>function(e){const t=e.getBlockInsertionPoint().index-1;return e.getBlocks().slice(0,t).filter((function(e){return e&&e.attributes&&e.attributes.content})).map((function(e){return e.attributes.content.replaceAll("<br>","\n\n")})).join("\n\n")}(e("core/block-editor"))),[]);return(0,a.useEffect)((()=>{t.content||t.requestedPrompt||p(n,!1,r,g,i)}),[]),(0,a.createElement)("div",(0,l.useBlockProps)(),o&&(0,a.createElement)("div",null,(0,a.createElement)(s.TextControl,{label:"Please provide the OpenAI token to continue:",value:m,onChange:e=>d(e)}),(0,a.createElement)(s.Button,{isPrimary:!0,onClick:()=>{p(n,m,r,g,i)}},"Submit")),t.content&&!c&&(0,a.createElement)("div",null,(0,a.createElement)("div",{className:"content"},(0,a.createElement)(a.RawHTML,null,t.content.trim().replaceAll("\n","<br/>")))),c&&(0,a.createElement)("div",{style:{padding:"10px",textAlign:"center"}},(0,a.createElement)(s.Spinner,{style:{height:"calc(4px * 20)",width:"calc(4px * 20)"}})))},saveParagraph:function(e){let{attributes:t}=e;const n=l.useBlockProps.save();return(0,a.createElement)("div",n,t.content)}}),(0,o.registerBlockType)("coauthor/image",{apiVersion:2,title:(0,r.__)("Coauthor Image","coauthor"),description:(0,r.__)("Automatically generate an illustration for your post","coauthor"),category:"common",icon:"welcome-write-blog",supports:{html:!1},attributes:{content:{type:"string",source:"text"},requestedPrompt:{type:"string",default:!1}},edit:function(e){let{attributes:t,setAttributes:n,clientId:r}=e;const[c,p]=(0,a.useState)(!1),[m,d]=(0,a.useState)([]),[g,h]=(0,a.useState)(""),{replaceBlock:f}=(0,u.useDispatch)(l.store),{mediaUpload:b}=(0,u.useSelect)((e=>{const{getSettings:t}=e(l.store);return{mediaUpload:t().mediaUpload}}),[]);return(0,a.createElement)("div",(0,l.useBlockProps)(),(0,a.createElement)(s.Placeholder,{label:"Coauthor Image"},!t.requestedPrompt&&(0,a.createElement)("div",null,(0,a.createElement)(s.TextControl,{label:"What would you like to see?",onChange:h}),(0,a.createElement)(s.Button,{isPrimary:!0,onClick:()=>function(e,t,n,o){n(!0),t({requestedPrompt:e}),i()({path:"/coauthor/image",method:"POST",data:{prompt:e}}).then((e=>{n(!1);const t=e.data.map((e=>"data:image/png;base64,"+e.b64_json));o(t)})).catch((e=>{"openai_token_missing"===e.code&&(setPromptedForToken(!0),n(!1),t({requestedPrompt:""}))}))}(g,n,p,d)},"Submit")),!c&&m.length>0&&(0,a.createElement)("div",null,(0,a.createElement)("div",{style:{textAlign:"center",margin:"12px",fontStyle:"italic"}},t.requestedPrompt),(0,a.createElement)("div",{style:{fontSize:"20px",lineHeight:"38px"}},"Please choose your image"),(0,a.createElement)("div",{style:{flexDirection:"row",justifyContent:"space-between",textAlign:"center"}},m.map((e=>(0,a.createElement)("img",{style:{width:"128px",padding:"8px"},src:e,key:e,onClick:async()=>{const n=await fetch(e),a=await n.blob(),c=new File([a],"coauthor_image.png",{type:"image/png"});b({filesList:[c],onFileChange:e=>{let[n]=e;f(r,(0,o.createBlock)("core/image",{url:n.url,caption:t.requestedPrompt,alt:t.requestedPrompt}))},allowedTypes:["image"],onError:e=>{console.error(e)}})}}))))),t.content&&!c&&(0,a.createElement)("div",null,(0,a.createElement)("div",{className:"content"},t.content)),c&&(0,a.createElement)("div",{style:{padding:"10px",textAlign:"center"}},(0,a.createElement)(s.Spinner,{style:{height:"calc(4px * 20)",width:"calc(4px * 20)"}}))))},save:function(e){let{attributes:t}=e;const n=l.useBlockProps.save();return(0,a.createElement)("div",n,t.content)}})}},n={};function o(e){var r=n[e];if(void 0!==r)return r.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,o),a.exports}o.m=t,e=[],o.O=function(t,n,r,a){if(!n){var c=1/0;for(u=0;u<e.length;u++){n=e[u][0],r=e[u][1],a=e[u][2];for(var i=!0,l=0;l<n.length;l++)(!1&a||c>=a)&&Object.keys(o.O).every((function(e){return o.O[e](n[l])}))?n.splice(l--,1):(i=!1,a<c&&(c=a));if(i){e.splice(u--,1);var s=r();void 0!==s&&(t=s)}}return t}a=a||0;for(var u=e.length;u>0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,c=n[0],i=n[1],l=n[2],s=0;if(c.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(l)var u=l(o)}for(t&&t(n);s<c.length;s++)a=c[s],o.o(e,a)&&e[a]&&e[a][0](),e[a]=0;return o.O(u)},n=self.webpackChunkcoauthor=self.webpackChunkcoauthor||[];n.forEach(t.bind(null,0)),n.push=t.bind(null,n.push.bind(n))}();var r=o.O(void 0,[431],(function(){return o(75)}));r=o.O(r)}(); -
writers-block-block/tags/0.3.1/build/style-index.css
r2447227 r2830213 1 /** 2 * The following styles get applied both on the front of your site 3 * and in the editor. 4 * 5 * Replace them with your own styles or remove the file completely. 6 */ 7 .wp-block-create-block-writers-block-block { 8 padding: 2px; } 9 10 11 /*# sourceMappingURL=style-index.css.map*/ 1 .wp-block-create-block-coauthor{padding:2px} -
writers-block-block/tags/0.3.1/readme.txt
r2450614 r2830213 1 === Writer's Block Block===1 === Coauthor - AI Writing Assistant and Artist === 2 2 Contributors: artpi 3 Tags: block, openai, gpt -3, writing3 Tags: block, openai, gpt3, ai, dalle 4 4 Requires at least: 5.3.1 5 Tested up to: 5.3.16 Stable tag: 0. 1.15 Tested up to: 6.1.1 6 Stable tag: 0.3.1 7 7 Requires PHP: 7.0.0 8 8 License: GPL-2.0-or-later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 A block generating writing prompts using OpenAI's GPT-3. **You will need OpenAI token to use this block**. 11 12 Coauthor helps you write with GPT-3 and illustrate your posts with DALL-e. You will need an OpenAI token to use this block. 12 13 13 14 == Description == 14 15 16 Coauthor brings the power of AI to help you focus on your best writing: 17 - Coauthor Paragraph completes your post using GPT-3 18 - Coauthor Image lets you conjure beautiful images painted by AI 19 15 20 GPT-3 is a text-completion algorithm developed by OpenAI - [read more here](https://deliber.at/2020/gpt-3/). 16 21 It can generate text using a provided sample. And so - it can help you get out of the writer's block! 17 18 Writer's Block Block provides a Gutenberg block that completes your content for you. Simply write few paragraphs and insert writer's block block into your post to see what robots can write for you.19 22 20 23 == Installation == … … 23 26 1. Install this plugin, activate 24 27 1. Go to the block editor, write some content 25 1. Search for " Writing Block Block" block, insert into your content28 1. Search for "Coauthor Paragraph" block, insert into your content 26 29 1. First time you use it, it will ask you for the OpenAI token 27 30 1. When you submit the token or use it next time - it will auto-complete the writing for you. … … 29 32 == How does it work == 30 33 34 === Coauthor Paragraph === 35 31 36 * You write some content 32 * Insert ` Writer's Block Block` block into your post37 * Insert `Coauthor Paragraph` block into your post 33 38 * It grabs the content of your post, calls OpenAI to generate a completion 34 39 * Inserts that completion to your post 35 40 * If you like it, you can transform that block into a Paragraph block. If you don't like it - you can delete it. 36 41 * This plugin is automatically limiting the requests to one per 60s to protect your OpenAI quota. If you call the suggestion endpoint in succession, you will get the same answer. 42 43 === Coauthor Image === 44 45 * Insert `Coauthor Image` block into your post 46 * Fill in the prompt to generate an image you would like to see 47 * It calls OpenAI api to generate 4 images 48 * You choose one that you like best 49 * That image gets uploaded to your media gallery and inserted into your post 50 * Image generations are cached for a month. If you ask for images using the same prompt, you will get the same result. 37 51 38 52 == Frequently Asked Questions == … … 63 77 == Screenshots == 64 78 65 1. Auto-completed poetry 79 1. Auto-completed poetry with Coauthor Paragraph 80 2. Coauthor Image showing image selection 66 81 67 82 == Changelog == … … 74 89 75 90 * Fix WP Version preventing installation on WP 5.6 91 92 = 0.3.1 = 93 94 * Rename to Coauthor 95 * Introduce another block - Coauthor Image to generate images using DALL-e -
writers-block-block/trunk/build/index.asset.php
r2447227 r2830213 1 <?php return array('dependencies' => array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n' , 'wp-polyfill'), 'version' => '88e33d174ae417ab67c90d7cc5711978');1 <?php return array('dependencies' => array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '8e011ee4c2d87fd36bb2'); -
writers-block-block/trunk/build/index.css
r2447227 r2830213 1 /** 2 * The following styles get applied inside the editor only. 3 * 4 * Replace them with your own styles or remove the file completely. 5 */ 6 .wp-block-writers-block-block-generate-suggestion { 7 border: 1px solid #3b2479; 8 padding: 0; } 9 10 .wp-block-writers-block-block-generate-suggestion .disclaimer, .wp-block-writers-block-block-generate-suggestion .components-base-control__label { 11 width: 100%; 12 background-color: #3b2479; 13 padding-top: 4px; 14 padding-bottom: 4px; 15 padding-left: 8px; 16 color: white; 17 font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; 18 font-size: small; } 19 20 .wp-block-writers-block-block-generate-suggestion .content { 21 padding: 4px; } 22 23 .wp-block-writers-block-block-generate-suggestion .components-text-control__input { 24 margin: 10px; 25 width: 80%; } 26 27 .wp-block-writers-block-block-generate-suggestion .components-button.is-primary { 28 margin: 10px; } 29 30 31 /*# sourceMappingURL=index.css.map*/ 1 .wp-block-coauthor-generate-suggestion{padding:0}.wp-block-coauthor-generate-suggestion .components-text-control__input{margin:10px;width:80%}.wp-block-coauthor-generate-suggestion .components-button.is-primary{margin:10px} -
writers-block-block/trunk/build/index.js
r2447227 r2830213 1 (window["webpackJsonp"] = window["webpackJsonp"] || []).push([["style-index"],{ 2 3 /***/ "./src/style.scss": 4 /*!************************!*\ 5 !*** ./src/style.scss ***! 6 \************************/ 7 /*! no static exports found */ 8 /***/ (function(module, exports, __webpack_require__) { 9 10 // extracted by mini-css-extract-plugin 11 12 /***/ }) 13 14 }]); 15 16 /******/ (function(modules) { // webpackBootstrap 17 /******/ // install a JSONP callback for chunk loading 18 /******/ function webpackJsonpCallback(data) { 19 /******/ var chunkIds = data[0]; 20 /******/ var moreModules = data[1]; 21 /******/ var executeModules = data[2]; 22 /******/ 23 /******/ // add "moreModules" to the modules object, 24 /******/ // then flag all "chunkIds" as loaded and fire callback 25 /******/ var moduleId, chunkId, i = 0, resolves = []; 26 /******/ for(;i < chunkIds.length; i++) { 27 /******/ chunkId = chunkIds[i]; 28 /******/ if(Object.prototype.hasOwnProperty.call(installedChunks, chunkId) && installedChunks[chunkId]) { 29 /******/ resolves.push(installedChunks[chunkId][0]); 30 /******/ } 31 /******/ installedChunks[chunkId] = 0; 32 /******/ } 33 /******/ for(moduleId in moreModules) { 34 /******/ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) { 35 /******/ modules[moduleId] = moreModules[moduleId]; 36 /******/ } 37 /******/ } 38 /******/ if(parentJsonpFunction) parentJsonpFunction(data); 39 /******/ 40 /******/ while(resolves.length) { 41 /******/ resolves.shift()(); 42 /******/ } 43 /******/ 44 /******/ // add entry modules from loaded chunk to deferred list 45 /******/ deferredModules.push.apply(deferredModules, executeModules || []); 46 /******/ 47 /******/ // run deferred modules when all chunks ready 48 /******/ return checkDeferredModules(); 49 /******/ }; 50 /******/ function checkDeferredModules() { 51 /******/ var result; 52 /******/ for(var i = 0; i < deferredModules.length; i++) { 53 /******/ var deferredModule = deferredModules[i]; 54 /******/ var fulfilled = true; 55 /******/ for(var j = 1; j < deferredModule.length; j++) { 56 /******/ var depId = deferredModule[j]; 57 /******/ if(installedChunks[depId] !== 0) fulfilled = false; 58 /******/ } 59 /******/ if(fulfilled) { 60 /******/ deferredModules.splice(i--, 1); 61 /******/ result = __webpack_require__(__webpack_require__.s = deferredModule[0]); 62 /******/ } 63 /******/ } 64 /******/ 65 /******/ return result; 66 /******/ } 67 /******/ 68 /******/ // The module cache 69 /******/ var installedModules = {}; 70 /******/ 71 /******/ // object to store loaded and loading chunks 72 /******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched 73 /******/ // Promise = chunk loading, 0 = chunk loaded 74 /******/ var installedChunks = { 75 /******/ "index": 0 76 /******/ }; 77 /******/ 78 /******/ var deferredModules = []; 79 /******/ 80 /******/ // The require function 81 /******/ function __webpack_require__(moduleId) { 82 /******/ 83 /******/ // Check if module is in cache 84 /******/ if(installedModules[moduleId]) { 85 /******/ return installedModules[moduleId].exports; 86 /******/ } 87 /******/ // Create a new module (and put it into the cache) 88 /******/ var module = installedModules[moduleId] = { 89 /******/ i: moduleId, 90 /******/ l: false, 91 /******/ exports: {} 92 /******/ }; 93 /******/ 94 /******/ // Execute the module function 95 /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 96 /******/ 97 /******/ // Flag the module as loaded 98 /******/ module.l = true; 99 /******/ 100 /******/ // Return the exports of the module 101 /******/ return module.exports; 102 /******/ } 103 /******/ 104 /******/ 105 /******/ // expose the modules object (__webpack_modules__) 106 /******/ __webpack_require__.m = modules; 107 /******/ 108 /******/ // expose the module cache 109 /******/ __webpack_require__.c = installedModules; 110 /******/ 111 /******/ // define getter function for harmony exports 112 /******/ __webpack_require__.d = function(exports, name, getter) { 113 /******/ if(!__webpack_require__.o(exports, name)) { 114 /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); 115 /******/ } 116 /******/ }; 117 /******/ 118 /******/ // define __esModule on exports 119 /******/ __webpack_require__.r = function(exports) { 120 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 121 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 122 /******/ } 123 /******/ Object.defineProperty(exports, '__esModule', { value: true }); 124 /******/ }; 125 /******/ 126 /******/ // create a fake namespace object 127 /******/ // mode & 1: value is a module id, require it 128 /******/ // mode & 2: merge all properties of value into the ns 129 /******/ // mode & 4: return value when already ns object 130 /******/ // mode & 8|1: behave like require 131 /******/ __webpack_require__.t = function(value, mode) { 132 /******/ if(mode & 1) value = __webpack_require__(value); 133 /******/ if(mode & 8) return value; 134 /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; 135 /******/ var ns = Object.create(null); 136 /******/ __webpack_require__.r(ns); 137 /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); 138 /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); 139 /******/ return ns; 140 /******/ }; 141 /******/ 142 /******/ // getDefaultExport function for compatibility with non-harmony modules 143 /******/ __webpack_require__.n = function(module) { 144 /******/ var getter = module && module.__esModule ? 145 /******/ function getDefault() { return module['default']; } : 146 /******/ function getModuleExports() { return module; }; 147 /******/ __webpack_require__.d(getter, 'a', getter); 148 /******/ return getter; 149 /******/ }; 150 /******/ 151 /******/ // Object.prototype.hasOwnProperty.call 152 /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 153 /******/ 154 /******/ // __webpack_public_path__ 155 /******/ __webpack_require__.p = ""; 156 /******/ 157 /******/ var jsonpArray = window["webpackJsonp"] = window["webpackJsonp"] || []; 158 /******/ var oldJsonpFunction = jsonpArray.push.bind(jsonpArray); 159 /******/ jsonpArray.push = webpackJsonpCallback; 160 /******/ jsonpArray = jsonpArray.slice(); 161 /******/ for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]); 162 /******/ var parentJsonpFunction = oldJsonpFunction; 163 /******/ 164 /******/ 165 /******/ // add entry module to deferred list 166 /******/ deferredModules.push(["./src/index.js","style-index"]); 167 /******/ // run deferred modules when ready 168 /******/ return checkDeferredModules(); 169 /******/ }) 170 /************************************************************************/ 171 /******/ ({ 172 173 /***/ "./node_modules/@babel/runtime/helpers/arrayLikeToArray.js": 174 /*!*****************************************************************!*\ 175 !*** ./node_modules/@babel/runtime/helpers/arrayLikeToArray.js ***! 176 \*****************************************************************/ 177 /*! no static exports found */ 178 /***/ (function(module, exports) { 179 180 function _arrayLikeToArray(arr, len) { 181 if (len == null || len > arr.length) len = arr.length; 182 183 for (var i = 0, arr2 = new Array(len); i < len; i++) { 184 arr2[i] = arr[i]; 185 } 186 187 return arr2; 188 } 189 190 module.exports = _arrayLikeToArray; 191 192 /***/ }), 193 194 /***/ "./node_modules/@babel/runtime/helpers/arrayWithHoles.js": 195 /*!***************************************************************!*\ 196 !*** ./node_modules/@babel/runtime/helpers/arrayWithHoles.js ***! 197 \***************************************************************/ 198 /*! no static exports found */ 199 /***/ (function(module, exports) { 200 201 function _arrayWithHoles(arr) { 202 if (Array.isArray(arr)) return arr; 203 } 204 205 module.exports = _arrayWithHoles; 206 207 /***/ }), 208 209 /***/ "./node_modules/@babel/runtime/helpers/iterableToArrayLimit.js": 210 /*!*********************************************************************!*\ 211 !*** ./node_modules/@babel/runtime/helpers/iterableToArrayLimit.js ***! 212 \*********************************************************************/ 213 /*! no static exports found */ 214 /***/ (function(module, exports) { 215 216 function _iterableToArrayLimit(arr, i) { 217 if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; 218 var _arr = []; 219 var _n = true; 220 var _d = false; 221 var _e = undefined; 222 223 try { 224 for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { 225 _arr.push(_s.value); 226 227 if (i && _arr.length === i) break; 228 } 229 } catch (err) { 230 _d = true; 231 _e = err; 232 } finally { 233 try { 234 if (!_n && _i["return"] != null) _i["return"](); 235 } finally { 236 if (_d) throw _e; 237 } 238 } 239 240 return _arr; 241 } 242 243 module.exports = _iterableToArrayLimit; 244 245 /***/ }), 246 247 /***/ "./node_modules/@babel/runtime/helpers/nonIterableRest.js": 248 /*!****************************************************************!*\ 249 !*** ./node_modules/@babel/runtime/helpers/nonIterableRest.js ***! 250 \****************************************************************/ 251 /*! no static exports found */ 252 /***/ (function(module, exports) { 253 254 function _nonIterableRest() { 255 throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); 256 } 257 258 module.exports = _nonIterableRest; 259 260 /***/ }), 261 262 /***/ "./node_modules/@babel/runtime/helpers/slicedToArray.js": 263 /*!**************************************************************!*\ 264 !*** ./node_modules/@babel/runtime/helpers/slicedToArray.js ***! 265 \**************************************************************/ 266 /*! no static exports found */ 267 /***/ (function(module, exports, __webpack_require__) { 268 269 var arrayWithHoles = __webpack_require__(/*! ./arrayWithHoles */ "./node_modules/@babel/runtime/helpers/arrayWithHoles.js"); 270 271 var iterableToArrayLimit = __webpack_require__(/*! ./iterableToArrayLimit */ "./node_modules/@babel/runtime/helpers/iterableToArrayLimit.js"); 272 273 var unsupportedIterableToArray = __webpack_require__(/*! ./unsupportedIterableToArray */ "./node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js"); 274 275 var nonIterableRest = __webpack_require__(/*! ./nonIterableRest */ "./node_modules/@babel/runtime/helpers/nonIterableRest.js"); 276 277 function _slicedToArray(arr, i) { 278 return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest(); 279 } 280 281 module.exports = _slicedToArray; 282 283 /***/ }), 284 285 /***/ "./node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js": 286 /*!***************************************************************************!*\ 287 !*** ./node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js ***! 288 \***************************************************************************/ 289 /*! no static exports found */ 290 /***/ (function(module, exports, __webpack_require__) { 291 292 var arrayLikeToArray = __webpack_require__(/*! ./arrayLikeToArray */ "./node_modules/@babel/runtime/helpers/arrayLikeToArray.js"); 293 294 function _unsupportedIterableToArray(o, minLen) { 295 if (!o) return; 296 if (typeof o === "string") return arrayLikeToArray(o, minLen); 297 var n = Object.prototype.toString.call(o).slice(8, -1); 298 if (n === "Object" && o.constructor) n = o.constructor.name; 299 if (n === "Map" || n === "Set") return Array.from(o); 300 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen); 301 } 302 303 module.exports = _unsupportedIterableToArray; 304 305 /***/ }), 306 307 /***/ "./src/edit.js": 308 /*!*********************!*\ 309 !*** ./src/edit.js ***! 310 \*********************/ 311 /*! exports provided: default */ 312 /***/ (function(module, __webpack_exports__, __webpack_require__) { 313 314 "use strict"; 315 __webpack_require__.r(__webpack_exports__); 316 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Edit; }); 317 /* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/slicedToArray */ "./node_modules/@babel/runtime/helpers/slicedToArray.js"); 318 /* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__); 319 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); 320 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__); 321 /* harmony import */ var _editor_scss__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./editor.scss */ "./src/editor.scss"); 322 /* harmony import */ var _editor_scss__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_editor_scss__WEBPACK_IMPORTED_MODULE_2__); 323 /* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/api-fetch */ "@wordpress/api-fetch"); 324 /* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3__); 325 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); 326 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__); 327 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); 328 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_5__); 329 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); 330 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_6__); 331 332 333 334 335 336 337 338 339 /** 340 * This function formats the prompt to OpenAI. 341 * In this case, it gets all the blocks in the editor BEFORE the current blocks, extracts text and creates a continous prompt. 342 * But other modes are possible - for example get first sentence from every block and only prompt this way. 343 * 344 * @see https://beta.openai.com/docs/introduction/prompt-design-101 345 * @param {Object} editor - reference to GB block editor instance. @see https://developer.wordpress.org/block-editor/data/data-core-editor/. 346 */ 347 348 function formatPromptToOpenAI(editor) { 349 var index = editor.getBlockInsertionPoint().index - 1; 350 var allBlocksBefore = editor.getBlocks().slice(0, index); 351 return allBlocksBefore.filter(function (block) { 352 return block && block.attributes && block.attributes.content; 353 }).map(function (block) { 354 return block.attributes.content.replaceAll('<br>', '\n\n'); 355 }).join('\n\n'); 356 } 357 358 function getSuggestionFromOpenAI(setAttributes, token, setPromptedForToken, formattedPrompt) { 359 var data = { 360 content: formattedPrompt 361 }; 362 363 if (token) { 364 data.token = token; 365 setPromptedForToken(false); 366 } 367 368 _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3___default()({ 369 path: '/writers-block/prompt', 370 method: 'POST', 371 data: data 372 }).then(function (res) { 373 setAttributes({ 374 content: res.prompts[0].text 375 }); 376 }).catch(function (res) { 377 // We have not yet submitted a token. 378 if (res.code === 'openai_token_missing') { 379 setPromptedForToken(true); 380 } 381 }); 382 } 383 /** 384 * The edit function describes the structure of your block in the context of the 385 * editor. This represents what the editor will render when the block is used. 386 * 387 * @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#edit 388 * 389 * @return {WPElement} Element to render. 390 */ 391 392 393 function Edit(_ref) { 394 var attributes = _ref.attributes, 395 setAttributes = _ref.setAttributes; 396 397 var _useState = Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["useState"])(false), 398 _useState2 = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default()(_useState, 2), 399 promptedForToken = _useState2[0], 400 setPromptedForToken = _useState2[1]; 401 402 var _useState3 = Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["useState"])(''), 403 _useState4 = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default()(_useState3, 2), 404 tokenField = _useState4[0], 405 setTokenField = _useState4[1]; 406 407 var formattedPrompt = Object(_wordpress_data__WEBPACK_IMPORTED_MODULE_6__["useSelect"])(function (select) { 408 return formatPromptToOpenAI(select('core/block-editor')); 409 }, []); 410 411 function submitToken() { 412 getSuggestionFromOpenAI(setAttributes, tokenField, setPromptedForToken, formattedPrompt); 413 } //useEffect hook is called only once when block is first rendered. 414 415 416 Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["useEffect"])(function () { 417 //Theoretically useEffect would ensure we only fire this once, but I don't want to fire it when we get data to edit either. 418 setAttributes({ 419 requestedPrompt: true 420 }); 421 422 if (!attributes.requestedPrompt) { 423 getSuggestionFromOpenAI(setAttributes, false, setPromptedForToken, formattedPrompt); 424 } 425 }, []); 426 return Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])("div", Object(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__["useBlockProps"])(), promptedForToken && Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])("div", null, Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])(_wordpress_components__WEBPACK_IMPORTED_MODULE_5__["TextControl"], { 427 label: "Please provide the OpenAI token to continue:", 428 value: tokenField, 429 onChange: function onChange(val) { 430 return setTokenField(val); 431 } 432 }), Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])(_wordpress_components__WEBPACK_IMPORTED_MODULE_5__["Button"], { 433 isPrimary: true, 434 onClick: function onClick() { 435 return submitToken(); 436 } 437 }, 'Submit')), !promptedForToken && Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])("div", null, Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])("div", { 438 className: "disclaimer" 439 }, "GPT-3 says:"), Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])("div", { 440 className: "content" 441 }, Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["RawHTML"], null, attributes.content.trim().replaceAll('\n', '<br/>'))))); 442 } 443 444 /***/ }), 445 446 /***/ "./src/editor.scss": 447 /*!*************************!*\ 448 !*** ./src/editor.scss ***! 449 \*************************/ 450 /*! no static exports found */ 451 /***/ (function(module, exports, __webpack_require__) { 452 453 // extracted by mini-css-extract-plugin 454 455 /***/ }), 456 457 /***/ "./src/index.js": 458 /*!**********************!*\ 459 !*** ./src/index.js ***! 460 \**********************/ 461 /*! no exports provided */ 462 /***/ (function(module, __webpack_exports__, __webpack_require__) { 463 464 "use strict"; 465 __webpack_require__.r(__webpack_exports__); 466 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks"); 467 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__); 468 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); 469 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__); 470 /* harmony import */ var _style_scss__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./style.scss */ "./src/style.scss"); 471 /* harmony import */ var _style_scss__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_style_scss__WEBPACK_IMPORTED_MODULE_2__); 472 /* harmony import */ var _edit__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./edit */ "./src/edit.js"); 473 /* harmony import */ var _save__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./save */ "./src/save.js"); 474 475 476 477 478 479 /** 480 * Every block starts by registering a new block type definition. 481 * 482 * @see https://developer.wordpress.org/block-editor/developers/block-api/#registering-a-block 483 */ 484 485 Object(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__["registerBlockType"])('writers-block-block/generate-suggestion', { 486 apiVersion: 2, 487 title: Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__["__"])('Writers Block Block', 'writers-block-block'), 488 description: Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__["__"])('Automatically generate new paragraphs using your existing content, GPT-3 and robots.', 'writers-block-block'), 489 category: 'common', 490 icon: 'welcome-write-blog', 491 supports: { 492 html: false 493 }, 494 attributes: { 495 content: { 496 type: 'string', 497 source: 'text', 498 default: Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__["__"])('Please wait, consulting robots about your content… 🤖', 'writers-block-block') 499 }, 500 requestedPrompt: { 501 type: 'boolean', 502 default: false 503 } 504 }, 505 // We are allowing transform to a paragraph to use the generated content. 506 // Maybe we should provide a button inside the block that triggers the transform? 507 transforms: { 508 to: [{ 509 type: 'block', 510 blocks: ['core/paragraph'], 511 transform: function transform(_ref) { 512 var content = _ref.content; 513 return Object(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__["createBlock"])('core/paragraph', { 514 content: content 515 }); 516 } 517 }] 518 }, 519 520 /** 521 * @see ./edit.js 522 */ 523 edit: _edit__WEBPACK_IMPORTED_MODULE_3__["default"], 524 525 /** 526 * @see ./save.js 527 */ 528 save: _save__WEBPACK_IMPORTED_MODULE_4__["default"] 529 }); 530 531 /***/ }), 532 533 /***/ "./src/save.js": 534 /*!*********************!*\ 535 !*** ./src/save.js ***! 536 \*********************/ 537 /*! exports provided: default */ 538 /***/ (function(module, __webpack_exports__, __webpack_require__) { 539 540 "use strict"; 541 __webpack_require__.r(__webpack_exports__); 542 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return save; }); 543 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); 544 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__); 545 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); 546 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__); 547 548 549 /** 550 * Retrieves the translation of text. 551 * 552 * @see https://developer.wordpress.org/block-editor/packages/packages-i18n/ 553 */ 554 555 /** 556 * The save function defines the way in which the different attributes should 557 * be combined into the final markup, which is then serialized by the block 558 * editor into `post_content`. 559 * 560 * @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save 561 * 562 * @return {WPElement} Element to render. 563 */ 564 565 function save(_ref) { 566 var attributes = _ref.attributes; 567 var blockProps = _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__["useBlockProps"].save(); 568 return Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__["createElement"])("div", blockProps, attributes.content); 569 } 570 571 /***/ }), 572 573 /***/ "@wordpress/api-fetch": 574 /*!**********************************!*\ 575 !*** external ["wp","apiFetch"] ***! 576 \**********************************/ 577 /*! no static exports found */ 578 /***/ (function(module, exports) { 579 580 (function() { module.exports = window["wp"]["apiFetch"]; }()); 581 582 /***/ }), 583 584 /***/ "@wordpress/block-editor": 585 /*!*************************************!*\ 586 !*** external ["wp","blockEditor"] ***! 587 \*************************************/ 588 /*! no static exports found */ 589 /***/ (function(module, exports) { 590 591 (function() { module.exports = window["wp"]["blockEditor"]; }()); 592 593 /***/ }), 594 595 /***/ "@wordpress/blocks": 596 /*!********************************!*\ 597 !*** external ["wp","blocks"] ***! 598 \********************************/ 599 /*! no static exports found */ 600 /***/ (function(module, exports) { 601 602 (function() { module.exports = window["wp"]["blocks"]; }()); 603 604 /***/ }), 605 606 /***/ "@wordpress/components": 607 /*!************************************!*\ 608 !*** external ["wp","components"] ***! 609 \************************************/ 610 /*! no static exports found */ 611 /***/ (function(module, exports) { 612 613 (function() { module.exports = window["wp"]["components"]; }()); 614 615 /***/ }), 616 617 /***/ "@wordpress/data": 618 /*!******************************!*\ 619 !*** external ["wp","data"] ***! 620 \******************************/ 621 /*! no static exports found */ 622 /***/ (function(module, exports) { 623 624 (function() { module.exports = window["wp"]["data"]; }()); 625 626 /***/ }), 627 628 /***/ "@wordpress/element": 629 /*!*********************************!*\ 630 !*** external ["wp","element"] ***! 631 \*********************************/ 632 /*! no static exports found */ 633 /***/ (function(module, exports) { 634 635 (function() { module.exports = window["wp"]["element"]; }()); 636 637 /***/ }), 638 639 /***/ "@wordpress/i18n": 640 /*!******************************!*\ 641 !*** external ["wp","i18n"] ***! 642 \******************************/ 643 /*! no static exports found */ 644 /***/ (function(module, exports) { 645 646 (function() { module.exports = window["wp"]["i18n"]; }()); 647 648 /***/ }) 649 650 /******/ }); 651 //# sourceMappingURL=index.js.map 1 !function(){"use strict";var e,t={75:function(e,t,n){var o=window.wp.blocks,r=window.wp.i18n,a=window.wp.element,c=window.wp.apiFetch,i=n.n(c),l=window.wp.blockEditor,s=window.wp.components,u=window.wp.data;function p(e,t,n,o,r){const a={content:o};t&&(a.token=t,n(!1)),r(!0),e({requestedPrompt:!0}),i()({path:"/coauthor/prompt",method:"POST",data:a}).then((t=>{r(!1);const n=t.prompts[0].text.split(" ");for(let t=0;t<n.length;t++){const o=n.slice(0,t).join(" ");setTimeout((()=>e({content:o})),50*t)}})).catch((t=>{"openai_token_missing"===t.code&&(n(!0),r(!1),e({requestedPrompt:!1}))}))}(0,o.registerBlockType)("coauthor/paragraph",{apiVersion:2,title:(0,r.__)("Coauthor Paragraph","coauthor"),description:(0,r.__)("Automatically generate new paragraphs using your existing content, GPT-3 and robots.","coauthor"),category:"common",icon:"welcome-write-blog",supports:{html:!1},attributes:{content:{type:"string",source:"text"},requestedPrompt:{type:"boolean",default:!1}},transforms:{to:[{type:"block",blocks:["core/paragraph"],transform:e=>{let{content:t}=e;return(0,o.createBlock)("core/paragraph",{content:t})}}]},edit:function(e){let{attributes:t,setAttributes:n}=e;const[o,r]=(0,a.useState)(!1),[c,i]=(0,a.useState)(!1),[m,d]=(0,a.useState)(""),g=(0,u.useSelect)((e=>function(e){const t=e.getBlockInsertionPoint().index-1;return e.getBlocks().slice(0,t).filter((function(e){return e&&e.attributes&&e.attributes.content})).map((function(e){return e.attributes.content.replaceAll("<br>","\n\n")})).join("\n\n")}(e("core/block-editor"))),[]);return(0,a.useEffect)((()=>{t.content||t.requestedPrompt||p(n,!1,r,g,i)}),[]),(0,a.createElement)("div",(0,l.useBlockProps)(),o&&(0,a.createElement)("div",null,(0,a.createElement)(s.TextControl,{label:"Please provide the OpenAI token to continue:",value:m,onChange:e=>d(e)}),(0,a.createElement)(s.Button,{isPrimary:!0,onClick:()=>{p(n,m,r,g,i)}},"Submit")),t.content&&!c&&(0,a.createElement)("div",null,(0,a.createElement)("div",{className:"content"},(0,a.createElement)(a.RawHTML,null,t.content.trim().replaceAll("\n","<br/>")))),c&&(0,a.createElement)("div",{style:{padding:"10px",textAlign:"center"}},(0,a.createElement)(s.Spinner,{style:{height:"calc(4px * 20)",width:"calc(4px * 20)"}})))},saveParagraph:function(e){let{attributes:t}=e;const n=l.useBlockProps.save();return(0,a.createElement)("div",n,t.content)}}),(0,o.registerBlockType)("coauthor/image",{apiVersion:2,title:(0,r.__)("Coauthor Image","coauthor"),description:(0,r.__)("Automatically generate an illustration for your post","coauthor"),category:"common",icon:"welcome-write-blog",supports:{html:!1},attributes:{content:{type:"string",source:"text"},requestedPrompt:{type:"string",default:!1}},edit:function(e){let{attributes:t,setAttributes:n,clientId:r}=e;const[c,p]=(0,a.useState)(!1),[m,d]=(0,a.useState)([]),[g,h]=(0,a.useState)(""),{replaceBlock:f}=(0,u.useDispatch)(l.store),{mediaUpload:b}=(0,u.useSelect)((e=>{const{getSettings:t}=e(l.store);return{mediaUpload:t().mediaUpload}}),[]);return(0,a.createElement)("div",(0,l.useBlockProps)(),(0,a.createElement)(s.Placeholder,{label:"Coauthor Image"},!t.requestedPrompt&&(0,a.createElement)("div",null,(0,a.createElement)(s.TextControl,{label:"What would you like to see?",onChange:h}),(0,a.createElement)(s.Button,{isPrimary:!0,onClick:()=>function(e,t,n,o){n(!0),t({requestedPrompt:e}),i()({path:"/coauthor/image",method:"POST",data:{prompt:e}}).then((e=>{n(!1);const t=e.data.map((e=>"data:image/png;base64,"+e.b64_json));o(t)})).catch((e=>{"openai_token_missing"===e.code&&(setPromptedForToken(!0),n(!1),t({requestedPrompt:""}))}))}(g,n,p,d)},"Submit")),!c&&m.length>0&&(0,a.createElement)("div",null,(0,a.createElement)("div",{style:{textAlign:"center",margin:"12px",fontStyle:"italic"}},t.requestedPrompt),(0,a.createElement)("div",{style:{fontSize:"20px",lineHeight:"38px"}},"Please choose your image"),(0,a.createElement)("div",{style:{flexDirection:"row",justifyContent:"space-between",textAlign:"center"}},m.map((e=>(0,a.createElement)("img",{style:{width:"128px",padding:"8px"},src:e,key:e,onClick:async()=>{const n=await fetch(e),a=await n.blob(),c=new File([a],"coauthor_image.png",{type:"image/png"});b({filesList:[c],onFileChange:e=>{let[n]=e;f(r,(0,o.createBlock)("core/image",{url:n.url,caption:t.requestedPrompt,alt:t.requestedPrompt}))},allowedTypes:["image"],onError:e=>{console.error(e)}})}}))))),t.content&&!c&&(0,a.createElement)("div",null,(0,a.createElement)("div",{className:"content"},t.content)),c&&(0,a.createElement)("div",{style:{padding:"10px",textAlign:"center"}},(0,a.createElement)(s.Spinner,{style:{height:"calc(4px * 20)",width:"calc(4px * 20)"}}))))},save:function(e){let{attributes:t}=e;const n=l.useBlockProps.save();return(0,a.createElement)("div",n,t.content)}})}},n={};function o(e){var r=n[e];if(void 0!==r)return r.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,o),a.exports}o.m=t,e=[],o.O=function(t,n,r,a){if(!n){var c=1/0;for(u=0;u<e.length;u++){n=e[u][0],r=e[u][1],a=e[u][2];for(var i=!0,l=0;l<n.length;l++)(!1&a||c>=a)&&Object.keys(o.O).every((function(e){return o.O[e](n[l])}))?n.splice(l--,1):(i=!1,a<c&&(c=a));if(i){e.splice(u--,1);var s=r();void 0!==s&&(t=s)}}return t}a=a||0;for(var u=e.length;u>0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,r,a]},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={826:0,431:0};o.O.j=function(t){return 0===e[t]};var t=function(t,n){var r,a,c=n[0],i=n[1],l=n[2],s=0;if(c.some((function(t){return 0!==e[t]}))){for(r in i)o.o(i,r)&&(o.m[r]=i[r]);if(l)var u=l(o)}for(t&&t(n);s<c.length;s++)a=c[s],o.o(e,a)&&e[a]&&e[a][0](),e[a]=0;return o.O(u)},n=self.webpackChunkcoauthor=self.webpackChunkcoauthor||[];n.forEach(t.bind(null,0)),n.push=t.bind(null,n.push.bind(n))}();var r=o.O(void 0,[431],(function(){return o(75)}));r=o.O(r)}(); -
writers-block-block/trunk/build/style-index.css
r2447227 r2830213 1 /** 2 * The following styles get applied both on the front of your site 3 * and in the editor. 4 * 5 * Replace them with your own styles or remove the file completely. 6 */ 7 .wp-block-create-block-writers-block-block { 8 padding: 2px; } 9 10 11 /*# sourceMappingURL=style-index.css.map*/ 1 .wp-block-create-block-coauthor{padding:2px} -
writers-block-block/trunk/readme.txt
r2450614 r2830213 1 === Writer's Block Block===1 === Coauthor - AI Writing Assistant and Artist === 2 2 Contributors: artpi 3 Tags: block, openai, gpt -3, writing3 Tags: block, openai, gpt3, ai, dalle 4 4 Requires at least: 5.3.1 5 Tested up to: 5.3.16 Stable tag: 0. 1.15 Tested up to: 6.1.1 6 Stable tag: 0.3.1 7 7 Requires PHP: 7.0.0 8 8 License: GPL-2.0-or-later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 A block generating writing prompts using OpenAI's GPT-3. **You will need OpenAI token to use this block**. 11 12 Coauthor helps you write with GPT-3 and illustrate your posts with DALL-e. You will need an OpenAI token to use this block. 12 13 13 14 == Description == 14 15 16 Coauthor brings the power of AI to help you focus on your best writing: 17 - Coauthor Paragraph completes your post using GPT-3 18 - Coauthor Image lets you conjure beautiful images painted by AI 19 15 20 GPT-3 is a text-completion algorithm developed by OpenAI - [read more here](https://deliber.at/2020/gpt-3/). 16 21 It can generate text using a provided sample. And so - it can help you get out of the writer's block! 17 18 Writer's Block Block provides a Gutenberg block that completes your content for you. Simply write few paragraphs and insert writer's block block into your post to see what robots can write for you.19 22 20 23 == Installation == … … 23 26 1. Install this plugin, activate 24 27 1. Go to the block editor, write some content 25 1. Search for " Writing Block Block" block, insert into your content28 1. Search for "Coauthor Paragraph" block, insert into your content 26 29 1. First time you use it, it will ask you for the OpenAI token 27 30 1. When you submit the token or use it next time - it will auto-complete the writing for you. … … 29 32 == How does it work == 30 33 34 === Coauthor Paragraph === 35 31 36 * You write some content 32 * Insert ` Writer's Block Block` block into your post37 * Insert `Coauthor Paragraph` block into your post 33 38 * It grabs the content of your post, calls OpenAI to generate a completion 34 39 * Inserts that completion to your post 35 40 * If you like it, you can transform that block into a Paragraph block. If you don't like it - you can delete it. 36 41 * This plugin is automatically limiting the requests to one per 60s to protect your OpenAI quota. If you call the suggestion endpoint in succession, you will get the same answer. 42 43 === Coauthor Image === 44 45 * Insert `Coauthor Image` block into your post 46 * Fill in the prompt to generate an image you would like to see 47 * It calls OpenAI api to generate 4 images 48 * You choose one that you like best 49 * That image gets uploaded to your media gallery and inserted into your post 50 * Image generations are cached for a month. If you ask for images using the same prompt, you will get the same result. 37 51 38 52 == Frequently Asked Questions == … … 63 77 == Screenshots == 64 78 65 1. Auto-completed poetry 79 1. Auto-completed poetry with Coauthor Paragraph 80 2. Coauthor Image showing image selection 66 81 67 82 == Changelog == … … 74 89 75 90 * Fix WP Version preventing installation on WP 5.6 91 92 = 0.3.1 = 93 94 * Rename to Coauthor 95 * Introduce another block - Coauthor Image to generate images using DALL-e
Note: See TracChangeset
for help on using the changeset viewer.