Plugin Directory

Changeset 3447778


Ignore:
Timestamp:
01/27/2026 11:01:55 AM (2 months ago)
Author:
mrinal013
Message:

multiple word switching feature add

Location:
word-switch
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • word-switch/trunk/build/js/register-format-type.asset.php

    r3446267 r3447778  
    1 <?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-rich-text'), 'version' => '2adfc67cdf12d2a50f14');
     1<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-data', 'wp-rich-text'), 'version' => '517faf736bf2550d7948');
  • word-switch/trunk/build/js/register-format-type.js

    r3446267 r3447778  
    1 (()=>{"use strict";const t=window.wp.richText,e=window.wp.blockEditor,i=window.ReactJSXRuntime,a="word-switch/format-type-delimiter",r="word-switch/format-type-wrap";(0,t.registerFormatType)(a,{title:"Content",tagName:"span",className:"word-switch",edit:({isActive:o,value:s,onChange:n})=>{const c={words:s.text.substring(s.start,s.end).split(","),currentIndex:0,isFading:!1},d=JSON.stringify(c);return(0,i.jsx)(e.RichTextToolbarButton,{icon:"editor-code",onClick:()=>{let e=(0,t.toggleFormat)(s,{type:r,attributes:{"data-wp-interactive":"wpdevagent/word-switch","data-wp-init":"callbacks.init","data-wp-context":d}});e=(0,t.toggleFormat)(e,{type:a,attributes:{"data-wp-text":"state.currentWord","data-wp-class--fade":"context.isFading"}}),n(e)},title:"Word Switch",isActive:o})}}),(0,t.registerFormatType)(r,{title:"Wrap",tagName:"span",className:"word-switch-wrap",edit:null})})();
     1(()=>{"use strict";const t=window.wp.richText,e=window.wp.blockEditor,o=window.wp.data,i=window.ReactJSXRuntime,r="word-switch/format-type-delimiter",a="word-switch/format-type-wrap";(0,t.registerFormatType)(r,{title:"Content",tagName:"span",className:"word-switch",edit:({isActive:c,value:l,onChange:n})=>{const w=(0,o.useSelect)(t=>t("core/block-editor").getSelectedBlock(),[]);return w&&!1===["core/paragraph","core/heading"].includes(w.name)?null:(0,i.jsx)(e.RichTextToolbarButton,{icon:"editor-code",onClick:()=>{let e=(0,t.toggleFormat)(l,{type:a});e=(0,t.toggleFormat)(e,{type:r}),n(e)},title:"Word Switch",isActive:c})}}),(0,t.registerFormatType)(a,{title:"Wrap",tagName:"span",className:"word-switch-wrap",edit:null})})();
  • word-switch/trunk/build/js/register-format-type.js.map

    r3446267 r3447778  
    1 {"version":3,"file":"js/register-format-type.js","mappings":";;;;;;;;;;AAAA,6C;;;;;;;;;;ACAA,0C;;;;;;;;;;ACAA,2C;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WC5BA;WACA;WACA;WACA;WACA;WACA,iCAAiC,WAAW;WAC5C;WACA,E;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA,E;;;;;WCPA,wF;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D,E;;;;;;;;;;;;;;;;;ACNwE;AACR;AAAA;AAEhE,MAAMK,uBAAuB,GAAG,mCAAmC;AACnE,MAAMC,4BAA4B,GAAG,8BAA8B;AAEnE,MAAMC,gBAAgB,GAAGA,CAAC;EAAEC,QAAQ;EAAEC,KAAK;EAAEC;AAAS,CAAC,KAAK;EAC1D,MAAMC,cAAc,GAAGF,KAAK,CAACG,IAAI,CAACC,SAAS,CAACJ,KAAK,CAACK,KAAK,EAAEL,KAAK,CAACM,GAAG,CAAC;EACnE,MAAMC,UAAU,GAAGL,cAAc,CAACM,KAAK,CAAC,GAAG,CAAC;EAC5C,MAAMC,GAAG,GAAG;IACVC,KAAK,EAAEH,UAAU;IACjBI,YAAY,EAAE,CAAC;IACfC,QAAQ,EAAE;EACZ,CAAC;EAED,MAAMC,SAAS,GAAGC,IAAI,CAACC,SAAS,CAACN,GAAG,CAAC;EAErC,MAAMO,QAAQ,GAAGA,CAAA,KAAM;IACrB;IACA,IAAIC,SAAS,GAAG1B,kEAAY,CAACS,KAAK,EAAE;MAClCkB,IAAI,EAAErB,4BAA4B;MAClCsB,UAAU,EAAE;QACV,qBAAqB,EAAE,wBAAwB;QAC/C,cAAc,EAAE,gBAAgB;QAChC,iBAAiB,EAAEN;MACrB;IACF,CAAC,CAAC;IACF;IACAI,SAAS,GAAG1B,kEAAY,CAAC0B,SAAS,EAAE;MAClCC,IAAI,EAAEtB,uBAAuB;MAC7BuB,UAAU,EAAE;QACV,cAAc,EAAE,mBAAmB;QACnC,qBAAqB,EAAE;MACzB;IACF,CAAC,CAAC;IAEFlB,QAAQ,CAACgB,SAAS,CAAC;EACrB,CAAC;EAED,oBACEtB,sDAAA,CAACF,0EAAqB;IACpB2B,IAAI,EAAC,aAAa;IAClBC,OAAO,EAAEL,QAAS;IAClBM,KAAK,EAAC,aAAa;IACnBvB,QAAQ,EAAEA;EAAS,CACpB,CAAC;AAEN,CAAC;AAEDP,wEAAkB,CAACI,uBAAuB,EAAE;EAC1C0B,KAAK,EAAE,SAAS;EAChBC,OAAO,EAAE,MAAM;EACfC,SAAS,EAAE,aAAa;EACxBC,IAAI,EAAE3B;AACR,CAAC,CAAC;AAEFN,wEAAkB,CAACK,4BAA4B,EAAE;EAC/CyB,KAAK,EAAE,MAAM;EACbC,OAAO,EAAE,MAAM;EACfC,SAAS,EAAE,kBAAkB;EAC7BC,IAAI,EAAE;AACR,CAAC,CAAC,C","sources":["webpack://word-switch/external window [\"wp\",\"blockEditor\"]","webpack://word-switch/external window [\"wp\",\"richText\"]","webpack://word-switch/external window \"ReactJSXRuntime\"","webpack://word-switch/webpack/bootstrap","webpack://word-switch/webpack/runtime/compat get default export","webpack://word-switch/webpack/runtime/define property getters","webpack://word-switch/webpack/runtime/hasOwnProperty shorthand","webpack://word-switch/webpack/runtime/make namespace object","webpack://word-switch/./resources/js/register-format-type.js"],"sourcesContent":["module.exports = window[\"wp\"][\"blockEditor\"];","module.exports = window[\"wp\"][\"richText\"];","module.exports = window[\"ReactJSXRuntime\"];","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Check if module exists (development only)\n\tif (__webpack_modules__[moduleId] === undefined) {\n\t\tvar e = new Error(\"Cannot find module '\" + moduleId + \"'\");\n\t\te.code = 'MODULE_NOT_FOUND';\n\t\tthrow e;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { toggleFormat, registerFormatType } from \"@wordpress/rich-text\";\nimport { RichTextToolbarButton } from \"@wordpress/block-editor\";\n\nconst WORD_SWITCH_FORMAT_TYPE = \"word-switch/format-type-delimiter\";\nconst WORD_SWITCH_FORMAT_TYPE_WRAP = \"word-switch/format-type-wrap\";\n\nconst MyMultiTagButton = ({ isActive, value, onChange }) => {\n  const selectedString = value.text.substring(value.start, value.end);\n  const wordsArray = selectedString.split(\",\");\n  const obj = {\n    words: wordsArray,\n    currentIndex: 0,\n    isFading: false,\n  };\n\n  const objString = JSON.stringify(obj);\n\n  const onToggle = () => {\n    // Apply the first format\n    let nextValue = toggleFormat(value, {\n      type: WORD_SWITCH_FORMAT_TYPE_WRAP,\n      attributes: {\n        \"data-wp-interactive\": \"wpdevagent/word-switch\",\n        \"data-wp-init\": \"callbacks.init\",\n        \"data-wp-context\": objString,\n      },\n    });\n    // Apply the second format to the result of the first\n    nextValue = toggleFormat(nextValue, {\n      type: WORD_SWITCH_FORMAT_TYPE,\n      attributes: {\n        \"data-wp-text\": \"state.currentWord\",\n        \"data-wp-class--fade\": \"context.isFading\",\n      },\n    });\n\n    onChange(nextValue);\n  };\n\n  return (\n    <RichTextToolbarButton\n      icon=\"editor-code\"\n      onClick={onToggle}\n      title=\"Word Switch\"\n      isActive={isActive}\n    />\n  );\n};\n\nregisterFormatType(WORD_SWITCH_FORMAT_TYPE, {\n  title: \"Content\",\n  tagName: \"span\",\n  className: \"word-switch\",\n  edit: MyMultiTagButton,\n});\n\nregisterFormatType(WORD_SWITCH_FORMAT_TYPE_WRAP, {\n  title: \"Wrap\",\n  tagName: \"span\",\n  className: \"word-switch-wrap\",\n  edit: null,\n});\n"],"names":["toggleFormat","registerFormatType","RichTextToolbarButton","jsx","_jsx","WORD_SWITCH_FORMAT_TYPE","WORD_SWITCH_FORMAT_TYPE_WRAP","MyMultiTagButton","isActive","value","onChange","selectedString","text","substring","start","end","wordsArray","split","obj","words","currentIndex","isFading","objString","JSON","stringify","onToggle","nextValue","type","attributes","icon","onClick","title","tagName","className","edit"],"ignoreList":[],"sourceRoot":""}
     1{"version":3,"file":"js/register-format-type.js","mappings":";;;;;;;;;;AAAA,6C;;;;;;;;;;ACAA,sC;;;;;;;;;;ACAA,0C;;;;;;;;;;ACAA,2C;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WC5BA;WACA;WACA;WACA;WACA;WACA,iCAAiC,WAAW;WAC5C;WACA,E;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA,E;;;;;WCPA,wF;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D,E;;;;;;;;;;;;;;;;;;;ACNA;AACA;AACA;AACA;AACA;AACA;AACA;AACwE;;AAExE;AACA;AACA;AACA;AACA;AACgE;;AAEhE;AACA;AACA;AACA;AACA;AAC4C;AAAA;AAE5C,MAAMM,uBAAuB,GAAG,mCAAmC;AACnE,MAAMC,4BAA4B,GAAG,8BAA8B;AAEnE,MAAMC,gBAAgB,GAAGA,CAAC;EAAEC,QAAQ;EAAEC,KAAK;EAAEC;AAAS,CAAC,KAAK;EAC1D,MAAMC,aAAa,GAAGT,0DAAS,CAAEU,MAAM,IAAK;IAC1C,OAAOA,MAAM,CAAC,mBAAmB,CAAC,CAACC,gBAAgB,CAAC,CAAC;EACvD,CAAC,EAAE,EAAE,CAAC;EAEN,MAAMC,cAAc,GAAG,CAAC,gBAAgB,EAAE,cAAc,CAAC;EAEzD,IAAIH,aAAa,IAAIG,cAAc,CAACC,QAAQ,CAACJ,aAAa,CAACK,IAAI,CAAC,KAAK,KAAK,EAAE;IAC1E,OAAO,IAAI;EACb;EAEA,MAAMC,QAAQ,GAAGA,CAAA,KAAM;IACrB;IACA,IAAIC,SAAS,GAAGnB,kEAAY,CAACU,KAAK,EAAE;MAClCU,IAAI,EAAEb;IACR,CAAC,CAAC;IACF;IACAY,SAAS,GAAGnB,kEAAY,CAACmB,SAAS,EAAE;MAClCC,IAAI,EAAEd;IACR,CAAC,CAAC;IAEFK,QAAQ,CAACQ,SAAS,CAAC;EACrB,CAAC;EAED,oBACEd,sDAAA,CAACH,0EAAqB;IACpBmB,IAAI,EAAC,aAAa;IAClBC,OAAO,EAAEJ,QAAS;IAClBK,KAAK,EAAC,aAAa;IACnBd,QAAQ,EAAEA;EAAS,CACpB,CAAC;AAEN,CAAC;AAEDR,wEAAkB,CAACK,uBAAuB,EAAE;EAC1CiB,KAAK,EAAE,SAAS;EAChBC,OAAO,EAAE,MAAM;EACfC,SAAS,EAAE,aAAa;EACxBC,IAAI,EAAElB;AACR,CAAC,CAAC;AAEFP,wEAAkB,CAACM,4BAA4B,EAAE;EAC/CgB,KAAK,EAAE,MAAM;EACbC,OAAO,EAAE,MAAM;EACfC,SAAS,EAAE,kBAAkB;EAC7BC,IAAI,EAAE;AACR,CAAC,CAAC,C","sources":["webpack://word-switch/external window [\"wp\",\"blockEditor\"]","webpack://word-switch/external window [\"wp\",\"data\"]","webpack://word-switch/external window [\"wp\",\"richText\"]","webpack://word-switch/external window \"ReactJSXRuntime\"","webpack://word-switch/webpack/bootstrap","webpack://word-switch/webpack/runtime/compat get default export","webpack://word-switch/webpack/runtime/define property getters","webpack://word-switch/webpack/runtime/hasOwnProperty shorthand","webpack://word-switch/webpack/runtime/make namespace object","webpack://word-switch/./resources/js/register-format-type.js"],"sourcesContent":["module.exports = window[\"wp\"][\"blockEditor\"];","module.exports = window[\"wp\"][\"data\"];","module.exports = window[\"wp\"][\"richText\"];","module.exports = window[\"ReactJSXRuntime\"];","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Check if module exists (development only)\n\tif (__webpack_modules__[moduleId] === undefined) {\n\t\tvar e = new Error(\"Cannot find module '\" + moduleId + \"'\");\n\t\te.code = 'MODULE_NOT_FOUND';\n\t\tthrow e;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/**\n * Toggles a format object to a Rich Text value at the current selection.\n * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-rich-text/#toggleformat\n *\n * Registers a new format provided a unique name and an object defining its behavior.\n * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-rich-text/#registerformattype\n */\nimport { toggleFormat, registerFormatType } from \"@wordpress/rich-text\";\n\n/**\n * Add a format button to the rich text\n *\n * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#richtexttoolbarbutton\n */\nimport { RichTextToolbarButton } from \"@wordpress/block-editor\";\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-data/#useselect\n */\nimport { useSelect } from \"@wordpress/data\";\n\nconst WORD_SWITCH_FORMAT_TYPE = \"word-switch/format-type-delimiter\";\nconst WORD_SWITCH_FORMAT_TYPE_WRAP = \"word-switch/format-type-wrap\";\n\nconst MyMultiTagButton = ({ isActive, value, onChange }) => {\n  const selectedBlock = useSelect((select) => {\n    return select(\"core/block-editor\").getSelectedBlock();\n  }, []);\n\n  const permittedBlock = [\"core/paragraph\", \"core/heading\"];\n\n  if (selectedBlock && permittedBlock.includes(selectedBlock.name) === false) {\n    return null;\n  }\n\n  const onToggle = () => {\n    // Apply the first format\n    let nextValue = toggleFormat(value, {\n      type: WORD_SWITCH_FORMAT_TYPE_WRAP,\n    });\n    // Apply the second format to the result of the first\n    nextValue = toggleFormat(nextValue, {\n      type: WORD_SWITCH_FORMAT_TYPE,\n    });\n\n    onChange(nextValue);\n  };\n\n  return (\n    <RichTextToolbarButton\n      icon=\"editor-code\"\n      onClick={onToggle}\n      title=\"Word Switch\"\n      isActive={isActive}\n    />\n  );\n};\n\nregisterFormatType(WORD_SWITCH_FORMAT_TYPE, {\n  title: \"Content\",\n  tagName: \"span\",\n  className: \"word-switch\",\n  edit: MyMultiTagButton,\n});\n\nregisterFormatType(WORD_SWITCH_FORMAT_TYPE_WRAP, {\n  title: \"Wrap\",\n  tagName: \"span\",\n  className: \"word-switch-wrap\",\n  edit: null,\n});\n"],"names":["toggleFormat","registerFormatType","RichTextToolbarButton","useSelect","jsx","_jsx","WORD_SWITCH_FORMAT_TYPE","WORD_SWITCH_FORMAT_TYPE_WRAP","MyMultiTagButton","isActive","value","onChange","selectedBlock","select","getSelectedBlock","permittedBlock","includes","name","onToggle","nextValue","type","icon","onClick","title","tagName","className","edit"],"ignoreList":[],"sourceRoot":""}
  • word-switch/trunk/build/js/word-switch-store.js.map

    r3442402 r3447778  
    1 {"version":3,"file":"js/word-switch-store.js","mappings":";;;;;;;;;AAAA,+E;;;;;;SCAA;SACA;;SAEA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;;SAEA;SACA;;SAEA;SACA;SACA;;;;;UC5BA;UACA;UACA;UACA,uDAAuD,iBAAiB;UACxE;UACA,gDAAgD,aAAa;UAC7D,E;;;;;;;;;;;;ACN6D;AAE7DA,+DAAK,CAAC,wBAAwB,EAAE;EAC9BE,KAAK,EAAE;IACL,IAAIC,WAAWA,CAAA,EAAG;MAChB,MAAMC,OAAO,GAAGH,oEAAU,CAAC,CAAC;MAC5B,OAAOG,OAAO,CAACC,KAAK,CAACD,OAAO,CAACE,YAAY,CAAC;IAC5C;EACF,CAAC;EACDC,SAAS,EAAE;IACTC,IAAIA,CAAA,EAAG;MACL,MAAMJ,OAAO,GAAGH,oEAAU,CAAC,CAAC;MAC5BQ,WAAW,CAAC,MAAM;QAChBL,OAAO,CAACM,QAAQ,GAAG,IAAI;QACvBC,UAAU,CAAC,MAAM;UACfP,OAAO,CAACM,QAAQ,GAAG,KAAK;UACxBN,OAAO,CAACE,YAAY,GAClB,CAACF,OAAO,CAACE,YAAY,GAAG,CAAC,IAAIF,OAAO,CAACC,KAAK,CAACO,MAAM;QACrD,CAAC,EAAE,GAAG,CAAC;MACT,CAAC,EAAE,IAAI,CAAC;IACV;EACF;AACF,CAAC,CAAC,C","sources":["webpack://word-switch/external module \"@wordpress/interactivity\"","webpack://word-switch/webpack/bootstrap","webpack://word-switch/webpack/runtime/make namespace object","webpack://word-switch/./resources/js/word-switch-store.js"],"sourcesContent":["module.exports = __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Check if module exists (development only)\n\tif (__webpack_modules__[moduleId] === undefined) {\n\t\tvar e = new Error(\"Cannot find module '\" + moduleId + \"'\");\n\t\te.code = 'MODULE_NOT_FOUND';\n\t\tthrow e;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { store, getContext } from \"@wordpress/interactivity\";\n\nstore(\"wpdevagent/word-switch\", {\n  state: {\n    get currentWord() {\n      const context = getContext();\n      return context.words[context.currentIndex];\n    },\n  },\n  callbacks: {\n    init() {\n      const context = getContext();\n      setInterval(() => {\n        context.isFading = true;\n        setTimeout(() => {\n          context.isFading = false;\n          context.currentIndex =\n            (context.currentIndex + 1) % context.words.length;\n        }, 500);\n      }, 5000);\n    },\n  },\n});\n"],"names":["store","getContext","state","currentWord","context","words","currentIndex","callbacks","init","setInterval","isFading","setTimeout","length"],"ignoreList":[],"sourceRoot":""}
     1{"version":3,"file":"js/word-switch-store.js","mappings":";;;;;;;;;AAAA,+E;;;;;;SCAA;SACA;;SAEA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;;SAEA;SACA;;SAEA;SACA;SACA;;;;;UC5BA;UACA;UACA;UACA,uDAAuD,iBAAiB;UACxE;UACA,gDAAgD,aAAa;UAC7D,E;;;;;;;;;;;;ACN6D;AAE7DA,+DAAK,CAAC,wBAAwB,EAAE;EAC9BE,KAAK,EAAE;IACL,IAAIC,WAAWA,CAAA,EAAG;MAChB,MAAMC,OAAO,GAAGH,oEAAU,CAAC,CAAC;MAC5B,OAAOG,OAAO,CAACC,KAAK,CAACD,OAAO,CAACE,YAAY,CAAC;IAC5C;EACF,CAAC;EACDC,SAAS,EAAE;IACTC,IAAIA,CAAA,EAAG;MACL,MAAMJ,OAAO,GAAGH,oEAAU,CAAC,CAAC;MAE5BQ,WAAW,CAAC,MAAM;QAChBL,OAAO,CAACM,QAAQ,GAAG,IAAI;QACvBC,UAAU,CAAC,MAAM;UACfP,OAAO,CAACM,QAAQ,GAAG,KAAK;UACxBN,OAAO,CAACE,YAAY,GAClB,CAACF,OAAO,CAACE,YAAY,GAAG,CAAC,IAAIF,OAAO,CAACC,KAAK,CAACO,MAAM;QACrD,CAAC,EAAE,GAAG,CAAC;MACT,CAAC,EAAE,IAAI,CAAC;IACV;EACF;AACF,CAAC,CAAC,C","sources":["webpack://word-switch/external module \"@wordpress/interactivity\"","webpack://word-switch/webpack/bootstrap","webpack://word-switch/webpack/runtime/make namespace object","webpack://word-switch/./resources/js/word-switch-store.js"],"sourcesContent":["module.exports = __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Check if module exists (development only)\n\tif (__webpack_modules__[moduleId] === undefined) {\n\t\tvar e = new Error(\"Cannot find module '\" + moduleId + \"'\");\n\t\te.code = 'MODULE_NOT_FOUND';\n\t\tthrow e;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { store, getContext } from \"@wordpress/interactivity\";\n\nstore(\"wpdevagent/word-switch\", {\n  state: {\n    get currentWord() {\n      const context = getContext();\n      return context.words[context.currentIndex];\n    },\n  },\n  callbacks: {\n    init() {\n      const context = getContext();\n\n      setInterval(() => {\n        context.isFading = true;\n        setTimeout(() => {\n          context.isFading = false;\n          context.currentIndex =\n            (context.currentIndex + 1) % context.words.length;\n        }, 500);\n      }, 5000);\n    },\n  },\n});\n"],"names":["store","getContext","state","currentWord","context","words","currentIndex","callbacks","init","setInterval","isFading","setTimeout","length"],"ignoreList":[],"sourceRoot":""}
  • word-switch/trunk/readme.txt

    r3446267 r3447778  
    44Requires at least: 6.7
    55Tested up to: 6.9
    6 Stable tag: 1.0.2
     6Stable tag: 1.1.0
    77Requires PHP: 7.4
    88License: GPLv2 or later
     
    1111== Description ==
    1212
    13 A lightweight WordPress plugin that adds word-switching functionality to Gutenberg’s Paragraph and Heading blocks, allowing users to dynamically replace or rotate selected words for more engaging and flexible content presentation.
     13A lightweight WordPress plugin that adds word-switching functionality to Gutenberg editor's
     14Paragraph and Heading blocks, allowing users to dynamically replace or rotate
     15selected words for more engaging and flexible content presentation.
     16
     17With this plugin, WordPress gutenberg editor’s paragraph and heading block get an extra format named ‘word switch’.
    1418
    1519== Changelog ==
    16 
     20== 1.1.0 ==
     21- Multiple seperate word switching feature
    1722== 1.0.2 ==
    1823- Change prefix WS to WORD_SWITCH
    1924- Made zip for wordpress.org
    20 
    2125== 1.0.1 ==
    2226- Change prefix WS to WORD_SWITCH
    2327- Made zip for wordpress.org
    24 
    2528== 1.0.0 ==
    2629* Add word switching functionality in Gutenberg
  • word-switch/trunk/word-switch.php

    r3446267 r3447778  
    33 * Plugin Name:         Word Switch
    44 * Description:         Add word switching capability.
    5  * Version:             1.0.2
     5 * Version:             1.1.0
    66 * Requires at least:   6.7
    77 * Requires PHP:        7.4
     
    2828}
    2929
     30/**
     31 * Register assets.
     32 *
     33 * @since 1.0
     34 */
    3035function word_switch_register_assets() {
    3136    $dir = plugin_dir_path( __FILE__ );
     
    6065add_action( 'init', 'word_switch_register_assets' );
    6166
     67/**
     68 * Enqueue editor site scrpts.
     69 *
     70 * @since 1.0
     71 */
    6272function word_switch_enqueue_block_editor_assets() {
    6373    wp_enqueue_script( WORD_SWITCH_SCRIPT );
     
    6777add_action( 'enqueue_block_editor_assets', 'word_switch_enqueue_block_editor_assets' );
    6878
     79/**
     80 * Render paragraph and heading tags output.
     81 *
     82 * @param string $block_content The block content.
     83 * @param array  $block The full block, including name and attributes.
     84 *
     85 * @since 1.0
     86 */
    6987function word_switch_render_block( $block_content, $block ) {
    7088    if ( strpos( $block_content, 'class="word-switch-wrap' ) === false ) {
     
    7391
    7492    $processor = new WP_HTML_Tag_Processor( $block_content );
     93
     94    while ( $processor->next_tag(
     95        array(
     96            'tag_name'   => 'span',
     97            'class_name' => 'word-switch-wrap',
     98        )
     99    ) ) {
     100
     101        $processor->set_bookmark( 'parent' );
     102        $words = array();
     103
     104        // Find all spans with word-switch class.
     105        if ( $processor->next_tag(
     106            array(
     107                'tag_name'   => 'span',
     108                'class_name' => 'word-switch',
     109            )
     110        ) ) {
     111            // Add Interactivity API directives .
     112            $processor->set_attribute( 'data-wp-text', 'state.currentWord' );
     113            $processor->set_attribute( 'data-wp-class--fade', 'context.isFading' );
     114
     115            // Extract the comma - separated words .
     116            if ( $processor->next_token() ) {
     117                $text_content = $processor->get_modifiable_text();
     118                if ( $text_content ) {
     119                    $words = array_filter( array_map( 'trim', explode( ',', $text_content ) ) );
     120                }
     121            }
     122        }
     123
     124        $processor->seek( 'parent' );
     125        $processor->set_attribute( 'data-wp-interactive', 'wpdevagent/word-switch' );
     126        $processor->set_attribute( 'data-wp-init', 'callbacks.init' );
     127        $processor->set_attribute(
     128            'data-wp-context',
     129            wp_json_encode(
     130                array(
     131                    'words'        => $words,
     132                    'currentIndex' => 0,
     133                    'isFading'     => false,
     134                )
     135            )
     136        );
     137    }
    75138
    76139    if ( ! is_admin() ) {
Note: See TracChangeset for help on using the changeset viewer.