@liferay-editor-custom-fields/framework 7.4.2 → 7.4.3
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/build/static/index.d.ts +2 -0
- package/build/static/index.js +1 -0
- package/build/static/messagingEvents/fireFragmentConfigOnLoad.d.ts +1 -0
- package/build/static/messagingEvents/fireImageOnChange.d.ts +1 -0
- package/build/static/messagingEvents/fireWebContentFieldsOnLoad.d.ts +1 -0
- package/{src/observers/index.ts → build/static/observers/index.d.ts} +1 -2
- package/build/static/observers/observeFragmentConfig.d.ts +1 -0
- package/build/static/observers/observePreviewImage.d.ts +2 -0
- package/build/static/observers/observeWebContentFields.d.ts +1 -0
- package/build/static/types/ContentType.type.d.ts +1 -0
- package/build/static/util/debounce.d.ts +1 -0
- package/build/static/util/getContentImageInput.d.ts +1 -0
- package/build/static/util/getFieldByLabel.d.ts +8 -0
- package/build/static/util/getPreviewImage.d.ts +1 -0
- package/{src/util/index.ts → build/static/util/index.d.ts} +1 -2
- package/build/static/util/setReactDomInputValue.d.ts +8 -0
- package/package.json +6 -3
- package/eslint.config.mjs +0 -11
- package/src/index.ts +0 -34
- package/src/messagingEvents/fireFragmentConfigOnLoad.ts +0 -2
- package/src/messagingEvents/fireImageOnChange.ts +0 -4
- package/src/messagingEvents/fireWebContentFieldsOnLoad.ts +0 -2
- package/src/observers/observeFragmentConfig.ts +0 -27
- package/src/observers/observePreviewImage.ts +0 -22
- package/src/observers/observeWebContentFields.ts +0 -24
- package/src/types/ContentType.type.ts +0 -1
- package/src/util/debounce.ts +0 -9
- package/src/util/getContentImageInput.ts +0 -5
- package/src/util/getFieldByLabel.ts +0 -25
- package/src/util/getPreviewImage.ts +0 -10
- package/src/util/setReactDomInputValue.ts +0 -22
- package/tsconfig.json +0 -21
- package/webpack.config.js +0 -62
|
@@ -0,0 +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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const fireFragmentConfigOnLoad: () => any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const fireImageOnChange: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const fireWebContentFieldsOnLoad: () => any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const observeFragmentConfig: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const observeWebContentFields: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ContentType = 'fragment' | 'content';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const debounce: (callback: any, wait: any) => (...args: any[]) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getContentImageInput: () => HTMLInputElement;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getPreviewImage: () => HTMLImageElement;
|
|
@@ -3,5 +3,4 @@ import { getContentImageInput } from "./getContentImageInput";
|
|
|
3
3
|
import { getFieldByLabel } from "./getFieldByLabel";
|
|
4
4
|
import { getPreviewImage } from "./getPreviewImage";
|
|
5
5
|
import { setReactDomInputValue } from "./setReactDomInputValue";
|
|
6
|
-
|
|
7
|
-
export { debounce, getContentImageInput, getFieldByLabel, getPreviewImage, setReactDomInputValue };
|
|
6
|
+
export { debounce, getContentImageInput, getFieldByLabel, getPreviewImage, setReactDomInputValue };
|
package/package.json
CHANGED
|
@@ -15,12 +15,15 @@
|
|
|
15
15
|
"webpack-cli": "5.1.4",
|
|
16
16
|
"webpack-dev-server": "4.15.1"
|
|
17
17
|
},
|
|
18
|
-
"
|
|
19
|
-
|
|
18
|
+
"files": [
|
|
19
|
+
"build"
|
|
20
|
+
],
|
|
21
|
+
"module": "./build/static/index.js",
|
|
22
|
+
"types": "./build/static/index.d.ts",
|
|
20
23
|
"scripts": {
|
|
21
24
|
"build": "webpack",
|
|
22
25
|
"start": "webpack serve",
|
|
23
26
|
"watch": "tsc --watch"
|
|
24
27
|
},
|
|
25
|
-
"version": "7.4.
|
|
28
|
+
"version": "7.4.3"
|
|
26
29
|
}
|
package/eslint.config.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import eslint from "@eslint/js";
|
|
4
|
-
import { defineConfig, globalIgnores } from "eslint/config";
|
|
5
|
-
import tseslint from "typescript-eslint";
|
|
6
|
-
|
|
7
|
-
export default defineConfig(
|
|
8
|
-
eslint.configs.recommended,
|
|
9
|
-
tseslint.configs.recommended,
|
|
10
|
-
[globalIgnores(["**/*.js", "**/*.cjs", "**/*.mjs"])],
|
|
11
|
-
);
|
package/src/index.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
declare const Liferay;
|
|
2
|
-
|
|
3
|
-
import { observeFragmentConfig, observeWebContentFields } from "./observers";
|
|
4
|
-
import {
|
|
5
|
-
debounce,
|
|
6
|
-
getContentImageInput,
|
|
7
|
-
getFieldByLabel,
|
|
8
|
-
getPreviewImage,
|
|
9
|
-
setReactDomInputValue,
|
|
10
|
-
} from "./util";
|
|
11
|
-
|
|
12
|
-
const initFramework:()=>void = () => {
|
|
13
|
-
const startObservers = () => {
|
|
14
|
-
observeWebContentFields();
|
|
15
|
-
// Fragment element we are watching is loaded client-side, and AFAIK there is no event fired when client-side is loaded.
|
|
16
|
-
setTimeout(observeFragmentConfig, 500);
|
|
17
|
-
};
|
|
18
|
-
if (Liferay && !Liferay?.editorCustomFields) {
|
|
19
|
-
Liferay.editorCustomFields = {
|
|
20
|
-
debounce,
|
|
21
|
-
getFieldByLabel,
|
|
22
|
-
setReactDomInputValue,
|
|
23
|
-
getContentImageInput,
|
|
24
|
-
getPreviewImage,
|
|
25
|
-
};
|
|
26
|
-
Liferay.on("allPortletsReady", () => {
|
|
27
|
-
startObservers();
|
|
28
|
-
});
|
|
29
|
-
Liferay.on("endNavigate", () => {
|
|
30
|
-
startObservers();
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
export default initFramework;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
declare const Liferay;
|
|
2
|
-
|
|
3
|
-
import { fireFragmentConfigOnLoad } from "../messagingEvents/fireFragmentConfigOnLoad";
|
|
4
|
-
import { debounce } from "../util";
|
|
5
|
-
|
|
6
|
-
import { observePreviewImage } from "./observePreviewImage";
|
|
7
|
-
|
|
8
|
-
export const observeFragmentConfig = () => {
|
|
9
|
-
const sidePanelQuery = ".page-editor__item-configuration-sidebar";
|
|
10
|
-
const sidePanelEl: HTMLDivElement = document.querySelector(
|
|
11
|
-
sidePanelQuery
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
if (sidePanelEl) {
|
|
15
|
-
if (Liferay.editorCustomFields.fragmentObserver) {
|
|
16
|
-
Liferay.editorCustomFields.fragmentObserver.disconnect?.();
|
|
17
|
-
}
|
|
18
|
-
const debouncedAddButton = debounce(() => {
|
|
19
|
-
observePreviewImage('fragment');
|
|
20
|
-
fireFragmentConfigOnLoad();
|
|
21
|
-
}, 500);
|
|
22
|
-
Liferay.editorCustomFields.fragmentObserver = new MutationObserver(debouncedAddButton);
|
|
23
|
-
const observer = Liferay.editorCustomFields.fragmentObserver;
|
|
24
|
-
const config = { attributes: false, childList: true, subtree: false };
|
|
25
|
-
observer.observe(sidePanelEl, config);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
declare const Liferay;
|
|
2
|
-
|
|
3
|
-
import { fireImageOnChange } from "../messagingEvents/fireImageOnChange";
|
|
4
|
-
import { ContentType } from "../types/ContentType.type";
|
|
5
|
-
import { debounce, getContentImageInput, getPreviewImage } from "../util";
|
|
6
|
-
|
|
7
|
-
export const observePreviewImage = (contentType: ContentType) => {
|
|
8
|
-
if(Liferay.editorCustomFields.imageObserver){
|
|
9
|
-
Liferay.editorCustomFields.imageObserver.disconnect?.();
|
|
10
|
-
}
|
|
11
|
-
// For when image changes
|
|
12
|
-
const elToObserve = contentType === 'fragment' ? getPreviewImage() : getContentImageInput();
|
|
13
|
-
if (contentType && elToObserve && !Liferay.editorCustomFields.imageObserver) {
|
|
14
|
-
const debouncedAddContentBlurhash = debounce(() => fireImageOnChange(), 500);
|
|
15
|
-
Liferay.editorCustomFields.imageObserver = new MutationObserver(debouncedAddContentBlurhash);
|
|
16
|
-
const observer = Liferay.editorCustomFields.imageObserver
|
|
17
|
-
const config = { attributes: true, childList: false, subtree: false };
|
|
18
|
-
observer.observe(elToObserve, config);
|
|
19
|
-
}
|
|
20
|
-
// For when image is already present on load
|
|
21
|
-
fireImageOnChange();
|
|
22
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
declare const Liferay;
|
|
2
|
-
|
|
3
|
-
import { fireWebContentFieldsOnLoad } from "../messagingEvents/fireWebContentFieldsOnLoad";
|
|
4
|
-
import { debounce } from "../util";
|
|
5
|
-
import { observePreviewImage } from "./observePreviewImage";
|
|
6
|
-
|
|
7
|
-
export const observeWebContentFields = () => {
|
|
8
|
-
const fieldsContainerEl: HTMLDivElement = document.querySelector(
|
|
9
|
-
"#_com_liferay_journal_web_portlet_JournalPortlet_fieldsContent",
|
|
10
|
-
);
|
|
11
|
-
if (fieldsContainerEl) {
|
|
12
|
-
if (Liferay.editorCustomFields.webContentObserver) {
|
|
13
|
-
Liferay.editorCustomFields.webContentObserver.disconnect?.();
|
|
14
|
-
}
|
|
15
|
-
const debouncedFieldEvent = debounce(() => {
|
|
16
|
-
observePreviewImage('content');
|
|
17
|
-
fireWebContentFieldsOnLoad();
|
|
18
|
-
}, 500);
|
|
19
|
-
Liferay.editorCustomFields.webContentObserver = new MutationObserver(debouncedFieldEvent);
|
|
20
|
-
const observer = Liferay.editorCustomFields.webContentObserver
|
|
21
|
-
const config = { attributes: false, childList: true, subtree: true };
|
|
22
|
-
observer.observe(fieldsContainerEl, config);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type ContentType = 'fragment' | 'content';
|
package/src/util/debounce.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export const getContentImageInput = () => {
|
|
2
|
-
const contentImageInputQuery = 'input[name^="_com_liferay_journal_web_portlet_JournalPortlet_ddm$$Image"]';
|
|
3
|
-
const contentImageInput: HTMLInputElement = document.querySelector(contentImageInputQuery);
|
|
4
|
-
return contentImageInput;
|
|
5
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Uses xpath to get a LR field by label
|
|
3
|
-
* since there is no attribute that corresponds with field name or key
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
type GetFieldByLabel = (label:string) => HTMLInputElement;
|
|
7
|
-
export const getFieldByLabel:GetFieldByLabel = (label) => {
|
|
8
|
-
const parentEl = document.querySelector(
|
|
9
|
-
"#portlet_com_liferay_journal_web_portlet_JournalPortlet, .page-editor__item-configuration-sidebar",
|
|
10
|
-
);
|
|
11
|
-
const match = document.evaluate(
|
|
12
|
-
`//label[text()='${label}']`,
|
|
13
|
-
parentEl,
|
|
14
|
-
null,
|
|
15
|
-
XPathResult.FIRST_ORDERED_NODE_TYPE,
|
|
16
|
-
null,
|
|
17
|
-
).singleNodeValue as HTMLElement;
|
|
18
|
-
|
|
19
|
-
const inputEl =
|
|
20
|
-
match?.closest(".form-group, .field-wrapper")?.querySelector("input") ||
|
|
21
|
-
match?.nextElementSibling?.querySelector("input") ||
|
|
22
|
-
match?.nextSibling;
|
|
23
|
-
|
|
24
|
-
return inputEl as HTMLInputElement;
|
|
25
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export const getPreviewImage = () => {
|
|
2
|
-
const parentEl:HTMLDivElement = document?.querySelector(
|
|
3
|
-
"#portlet_com_liferay_journal_web_portlet_JournalPortlet, .page-editor__topper.active",
|
|
4
|
-
);
|
|
5
|
-
const previewImage:HTMLImageElement = parentEl?.querySelector(
|
|
6
|
-
".page-editor__topper.active img.page-editor__editable, .image-picker-preview>img",
|
|
7
|
-
) as HTMLImageElement;
|
|
8
|
-
|
|
9
|
-
return previewImage;
|
|
10
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The fragment editor config inputs use react DOM
|
|
3
|
-
* So setting input element value doesn't work
|
|
4
|
-
*
|
|
5
|
-
* @param {element} inputEl
|
|
6
|
-
* @param {string} value
|
|
7
|
-
*/
|
|
8
|
-
export const setReactDomInputValue = (inputEl:HTMLInputElement, value:string) => {
|
|
9
|
-
inputEl.focus();
|
|
10
|
-
const nativeValueSetter = Object.getOwnPropertyDescriptor(
|
|
11
|
-
window.HTMLInputElement.prototype,
|
|
12
|
-
"value",
|
|
13
|
-
).set;
|
|
14
|
-
nativeValueSetter.call(inputEl, value);
|
|
15
|
-
|
|
16
|
-
inputEl.dispatchEvent(new Event("input", { bubbles: true }));
|
|
17
|
-
inputEl.dispatchEvent(new Event("change", { bubbles: true }));
|
|
18
|
-
|
|
19
|
-
document.body.focus();
|
|
20
|
-
|
|
21
|
-
inputEl.dispatchEvent(new Event("blur", { bubbles: true }));
|
|
22
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"declaration": true,
|
|
4
|
-
"esModuleInterop": true,
|
|
5
|
-
"lib": [
|
|
6
|
-
"DOM",
|
|
7
|
-
"ES2020"
|
|
8
|
-
],
|
|
9
|
-
"module": "ES2020",
|
|
10
|
-
"moduleResolution": "node",
|
|
11
|
-
"outDir": "./build/static",
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"sourceMap": false,
|
|
14
|
-
"target": "ES2020",
|
|
15
|
-
"types": [
|
|
16
|
-
]
|
|
17
|
-
},
|
|
18
|
-
"include": [
|
|
19
|
-
"./src/**/*"
|
|
20
|
-
]
|
|
21
|
-
}
|
package/webpack.config.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
|
|
3
|
-
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const path = require("path");
|
|
7
|
-
const webpack = require("webpack");
|
|
8
|
-
const ESLintPlugin = require("eslint-webpack-plugin");
|
|
9
|
-
|
|
10
|
-
const DEVELOPMENT = process.env.NODE_ENV === "development";
|
|
11
|
-
const WEBPACK_SERVE = !!process.env.WEBPACK_SERVE;
|
|
12
|
-
|
|
13
|
-
module.exports = {
|
|
14
|
-
devServer: {
|
|
15
|
-
headers: {
|
|
16
|
-
"Access-Control-Allow-Origin": "*",
|
|
17
|
-
},
|
|
18
|
-
port: 3000,
|
|
19
|
-
},
|
|
20
|
-
devtool: DEVELOPMENT ? "source-map" : false,
|
|
21
|
-
entry: {
|
|
22
|
-
index: "./src/index.ts",
|
|
23
|
-
},
|
|
24
|
-
experiments: {
|
|
25
|
-
outputModule: true,
|
|
26
|
-
},
|
|
27
|
-
mode: DEVELOPMENT ? "development" : "production",
|
|
28
|
-
module: {
|
|
29
|
-
rules: [
|
|
30
|
-
{
|
|
31
|
-
test: /\.ts$/i,
|
|
32
|
-
use: ["ts-loader"],
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
},
|
|
36
|
-
optimization: {
|
|
37
|
-
minimize: !DEVELOPMENT,
|
|
38
|
-
},
|
|
39
|
-
output: {
|
|
40
|
-
clean: true,
|
|
41
|
-
environment: {
|
|
42
|
-
dynamicImport: true,
|
|
43
|
-
},
|
|
44
|
-
filename: WEBPACK_SERVE ? "[name].js" : "[name].js",
|
|
45
|
-
library: {
|
|
46
|
-
type: "module",
|
|
47
|
-
},
|
|
48
|
-
path: path.resolve("build", "static"),
|
|
49
|
-
},
|
|
50
|
-
plugins: [
|
|
51
|
-
new ESLintPlugin({
|
|
52
|
-
files: "src/**/*.ts",
|
|
53
|
-
overrideConfigFile: `eslint.config.mjs`,
|
|
54
|
-
}),
|
|
55
|
-
new webpack.optimize.LimitChunkCountPlugin({
|
|
56
|
-
maxChunks: 1,
|
|
57
|
-
}),
|
|
58
|
-
],
|
|
59
|
-
resolve: {
|
|
60
|
-
extensions: [".js", ".ts"],
|
|
61
|
-
},
|
|
62
|
-
};
|