@liferay-editor-custom-fields/framework 7.4.3 → 7.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,28 +1,50 @@
1
1
  # Liferay Custom Fields Framework
2
2
 
3
- The engine behind Liferay Custom Fields. You only need this if you are creating a Liferay Editor Custom Fields package. Otherwise you can just install the package.
3
+ The engine behind Liferay Editor Custom Fields.
4
4
 
5
- You can read more about how it works [Creating a Liferay global JS client extension with TypeScript and Webpack](https://xtivia.com/blog/creating-a-liferay-global-js-client-extension-with-typescript-and-webpack).
5
+ ## Before You Start
6
+
7
+ Any client extension using this framework should not run on a production or pre-prod staging environment. It is only intended for the fragment and web content editors. Any JS that will end up on the page should be elsewhere, either in a separate client extension or in the fragment/web content template.
8
+
9
+ You only need this if you are creating a new Liferay Editor Custom Fields package, otherwise it is provided as a dependency on existing ones.
6
10
 
7
11
  ## Getting Started
8
12
 
9
-
13
+ - Install @liferay-editor-custom-fields/framework
14
+ - Make sure the version matches the minor version of Liferay you are using
15
+ - For example `yarn add @liferay-editor-custom-fields/framework@~7.4.0` for Liferay 7.4.
16
+ - In the index.ts of your app:
17
+ - Declare the Liferay global object
18
+ - Import the default exported function from @liferay-editor-custom-fields/framework. You can call it something short like initFramework();
19
+ - Create a default exported function of your own and call that function
20
+ - Write a Liferay.on event subscriber for each event that your app will be using. See the Events section of this document for a list of events.
10
21
 
22
+ ```
23
+ declare const Liferay;
11
24
 
12
- ## Events and Helpers
25
+ import initFramework from '@liferay-editor-custom-fields/framework';
13
26
 
14
- The framework profides the Liferay events and exposed functions below to use in your implementation.
27
+ const initImageTools: () => void = () => {
28
+ initFramework();
29
+ Liferay.on('EditorCustomFields_WebContentFields_OnLoad', ()=>{});
30
+ Liferay.on('EditorCustomFields_FragmenConfig_OnLoad', ()=>{});
31
+ Liferay.on('EditorCustomFields_Image_OnChange', ()=>{});
32
+ }
33
+ export default initImageTools;
34
+ ```
15
35
 
16
- ### Events
36
+ ## Events
17
37
 
18
38
  Use Liferay.on to subscribe to these events:
39
+
19
40
  - `EditorCustomFields_WebContentFields_OnLoad` - Fires when web content field DOM is loaded.
20
41
  - `EditorCustomFields_FragmenConfig_OnLoad` - Fires when a new Fragment config is loaded on the right pane of a page editor.
21
42
  - `EditorCustomFields_Image_OnChange` - Fires when an lfr-editable image or Web Content image is changed.
22
43
 
23
- ### Helper functions
44
+ ## Helper functions
45
+
46
+ The helper functions below are available for import in any file. For example, to use the getFieldByLabel helper you would use `import { getFieldByLabel } from "@liferay-editor-custom-fields/framework";`
24
47
 
25
- The helper functions below are children of Liferay.editorCustomFields
26
48
  - `debounce(callback:function, wait:number)` - A simple callback function
27
49
  - `getContentImageInput(label:string)` - Gets the metadata input field associated with the web content image.
28
50
  - `getFieldByLabel(label:string)` - Uses Xpath to get an input field by its label. Usually used to append a GUI element.
@@ -31,4 +53,4 @@ The helper functions below are children of Liferay.editorCustomFields
31
53
 
32
54
  ## License
33
55
 
34
- MIT Licensed. Copyright (c) Xtivia 2026.
56
+ MIT Licensed. Copyright (c) Xtivia 2026.
@@ -1,2 +1,3 @@
1
+ export { debounce, getContentImageInput, getFieldByLabel, getPreviewImage, setReactDomInputValue, } from "./util";
1
2
  declare const initFramework: () => void;
2
3
  export default initFramework;
@@ -1 +1 @@
1
- var e={d:(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{c:()=>d});const r=(e,t)=>{let r=null;return(...o)=>{window.clearTimeout(r),r=window.setTimeout(()=>{e(...o)},t)}},o=()=>{Liferay.fire("EditorCustomFields_Image_OnChange")},i=()=>{const e=document?.querySelector("#portlet_com_liferay_journal_web_portlet_JournalPortlet, .page-editor__topper.active"),t=e?.querySelector(".page-editor__topper.active img.page-editor__editable, .image-picker-preview>img");return t},n=()=>document.querySelector('input[name^="_com_liferay_journal_web_portlet_JournalPortlet_ddm$$Image"]'),s=e=>{Liferay.editorCustomFields.imageObserver&&Liferay.editorCustomFields.imageObserver.disconnect?.();const t="fragment"===e?i():n();if(e&&t&&!Liferay.editorCustomFields.imageObserver){const e=r(()=>o(),500);Liferay.editorCustomFields.imageObserver=new MutationObserver(e);const i={attributes:!0,childList:!1,subtree:!1};Liferay.editorCustomFields.imageObserver.observe(t,i)}o()},a=()=>{const e=document.querySelector(".page-editor__item-configuration-sidebar");if(e){Liferay.editorCustomFields.fragmentObserver&&Liferay.editorCustomFields.fragmentObserver.disconnect?.();const t=r(()=>{s("fragment"),Liferay.fire("EditorCustomFields_FragmenConfig_OnLoad")},500);Liferay.editorCustomFields.fragmentObserver=new MutationObserver(t);const o={attributes:!1,childList:!0,subtree:!1};Liferay.editorCustomFields.fragmentObserver.observe(e,o)}},l=e=>{const t=document.querySelector("#portlet_com_liferay_journal_web_portlet_JournalPortlet, .page-editor__item-configuration-sidebar"),r=document.evaluate(`//label[text()='${e}']`,t,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;return r?.closest(".form-group, .field-wrapper")?.querySelector("input")||r?.nextElementSibling?.querySelector("input")||r?.nextSibling},u=(e,t)=>{e.focus(),Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"value").set.call(e,t),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})),document.body.focus(),e.dispatchEvent(new Event("blur",{bubbles:!0}))},d=()=>{const e=()=>{(()=>{const e=document.querySelector("#_com_liferay_journal_web_portlet_JournalPortlet_fieldsContent");if(e){Liferay.editorCustomFields.webContentObserver&&Liferay.editorCustomFields.webContentObserver.disconnect?.();const t=r(()=>{s("content"),Liferay.fire("EditorCustomFields_WebContentFields_OnLoad")},500);Liferay.editorCustomFields.webContentObserver=new MutationObserver(t);const o={attributes:!1,childList:!0,subtree:!0};Liferay.editorCustomFields.webContentObserver.observe(e,o)}})(),setTimeout(a,500)};Liferay&&!Liferay?.editorCustomFields&&(Liferay.editorCustomFields={debounce:r,getFieldByLabel:l,setReactDomInputValue:u,getContentImageInput:n,getPreviewImage:i},Liferay.on("allPortletsReady",()=>{e()}),Liferay.on("endNavigate",()=>{e()}))};var c=t.c;export{c as default};
1
+ var e={d:(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{Cu:()=>r,cp:()=>d,s9:()=>n,qC:()=>l,Un:()=>i,S6:()=>u});const r=(e,t)=>{let r=null;return(...o)=>{window.clearTimeout(r),r=window.setTimeout(()=>{e(...o)},t)}},o=()=>{Liferay.fire("EditorCustomFields_Image_OnChange")},i=()=>{const e=document?.querySelector("#portlet_com_liferay_journal_web_portlet_JournalPortlet, .page-editor__topper.active"),t=e?.querySelector(".page-editor__topper.active img.page-editor__editable, .image-picker-preview>img");return t},n=()=>document.querySelector('input[name^="_com_liferay_journal_web_portlet_JournalPortlet_ddm$$Image"]'),s=e=>{Liferay.editorCustomFields.imageObserver&&Liferay.editorCustomFields.imageObserver.disconnect?.();const t="fragment"===e?i():n();if(e&&t&&!Liferay.editorCustomFields.imageObserver){const e=r(()=>o(),500);Liferay.editorCustomFields.imageObserver=new MutationObserver(e);const i={attributes:!0,childList:!1,subtree:!1};Liferay.editorCustomFields.imageObserver.observe(t,i)}o()},a=()=>{const e=document.querySelector(".page-editor__item-configuration-sidebar");if(e){Liferay.editorCustomFields.fragmentObserver&&Liferay.editorCustomFields.fragmentObserver.disconnect?.();const t=r(()=>{s("fragment"),Liferay.fire("EditorCustomFields_FragmenConfig_OnLoad")},500);Liferay.editorCustomFields.fragmentObserver=new MutationObserver(t);const o={attributes:!1,childList:!0,subtree:!1};Liferay.editorCustomFields.fragmentObserver.observe(e,o)}},l=e=>{const t=document.querySelector("#portlet_com_liferay_journal_web_portlet_JournalPortlet, .page-editor__item-configuration-sidebar"),r=document.evaluate(`//label[text()='${e}']`,t,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;return r?.closest(".form-group, .field-wrapper")?.querySelector("input")||r?.nextElementSibling?.querySelector("input")||r?.nextSibling},u=(e,t)=>{e.focus(),Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"value").set.call(e,t),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})),document.body.focus(),e.dispatchEvent(new Event("blur",{bubbles:!0}))},d=()=>{const e=()=>{(()=>{const e=document.querySelector("#_com_liferay_journal_web_portlet_JournalPortlet_fieldsContent");if(e){Liferay.editorCustomFields.webContentObserver&&Liferay.editorCustomFields.webContentObserver.disconnect?.();const t=r(()=>{s("content"),Liferay.fire("EditorCustomFields_WebContentFields_OnLoad")},500);Liferay.editorCustomFields.webContentObserver=new MutationObserver(t);const o={attributes:!1,childList:!0,subtree:!0};Liferay.editorCustomFields.webContentObserver.observe(e,o)}})(),setTimeout(a,500)};Liferay&&!Liferay?.editorCustomFieldsInitialized&&(Liferay.editorCustomFieldsInitialized=!0,Liferay.on("allPortletsReady",()=>{e()}),Liferay.on("endNavigate",()=>{e()}))};var c=t.Cu,m=t.cp,b=t.s9,f=t.qC,_=t.Un,p=t.S6;export{c as debounce,m as default,b as getContentImageInput,f as getFieldByLabel,_ as getPreviewImage,p as setReactDomInputValue};
package/package.json CHANGED
@@ -25,5 +25,5 @@
25
25
  "start": "webpack serve",
26
26
  "watch": "tsc --watch"
27
27
  },
28
- "version": "7.4.3"
28
+ "version": "7.4.6"
29
29
  }