@frontify/guideline-blocks-settings 0.34.3 → 0.34.5
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/dist/components/RichTextEditor/RichTextEditor.es.js +53 -39
- package/dist/components/RichTextEditor/RichTextEditor.es.js.map +1 -1
- package/dist/hooks/useIsInViewport.es.js +22 -0
- package/dist/hooks/useIsInViewport.es.js.map +1 -0
- package/dist/index.cjs.js +3 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.umd.js +3 -3
- package/dist/index.umd.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +3 -3
|
@@ -1,45 +1,59 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
1
|
+
import { jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import { memo as x, useState as h, useCallback as a, useEffect as p, useRef as R } from "react";
|
|
3
3
|
import { RichTextEditor as v } from "@frontify/fondue";
|
|
4
|
-
import { SerializedText as
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
4
|
+
import { SerializedText as P } from "./SerializedText.es.js";
|
|
5
|
+
import { useIsInViewport as I } from "../../hooks/useIsInViewport.es.js";
|
|
6
|
+
import { floatingButtonSelectors as L, floatingButtonActions as S } from "./plugins/ButtonPlugin/components/FloatingButton/floatingButtonStore.es.js";
|
|
7
|
+
const E = x(
|
|
8
|
+
({
|
|
9
|
+
id: d = "rte",
|
|
10
|
+
isEnabled: o,
|
|
11
|
+
value: t,
|
|
12
|
+
columns: n,
|
|
13
|
+
gap: i,
|
|
14
|
+
placeholder: f,
|
|
15
|
+
plugins: s,
|
|
16
|
+
onTextChange: r,
|
|
17
|
+
showSerializedText: w
|
|
18
|
+
}) => {
|
|
19
|
+
const [c, u] = h(!1), b = a(
|
|
20
|
+
(e) => {
|
|
21
|
+
e !== t && (r == null || r(e), u(!1));
|
|
22
|
+
},
|
|
23
|
+
[r, t]
|
|
24
|
+
), g = a(() => u(!0), []), V = a((e) => {
|
|
25
|
+
L.isOpen(e) && S.reset();
|
|
26
|
+
}, []);
|
|
27
|
+
return p(() => {
|
|
28
|
+
const e = (m) => {
|
|
29
|
+
m.preventDefault(), m.returnValue = "Unprocessed changes";
|
|
30
|
+
};
|
|
31
|
+
return c && window.addEventListener("beforeunload", e), () => window.removeEventListener("beforeunload", e);
|
|
32
|
+
}, [c]), o ? /* @__PURE__ */ l(
|
|
33
|
+
v,
|
|
34
|
+
{
|
|
35
|
+
id: d,
|
|
36
|
+
value: t,
|
|
37
|
+
border: !1,
|
|
38
|
+
placeholder: f,
|
|
39
|
+
plugins: s,
|
|
40
|
+
onValueChanged: g,
|
|
41
|
+
onTextChange: b,
|
|
42
|
+
hideExternalFloatingModals: V
|
|
43
|
+
}
|
|
44
|
+
) : /* @__PURE__ */ l(P, { value: t, columns: n, gap: i, show: w, plugins: s });
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
E.displayName = "InternalRichTextEditor";
|
|
48
|
+
const M = (d) => {
|
|
49
|
+
const o = R(null), [t, n] = h(!1), { isEditing: i, ...f } = d, s = a((r) => {
|
|
50
|
+
r && n(!0);
|
|
24
51
|
}, []);
|
|
25
|
-
return
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}, [a]), f ? /* @__PURE__ */ d(
|
|
29
|
-
v,
|
|
30
|
-
{
|
|
31
|
-
id: l,
|
|
32
|
-
value: t,
|
|
33
|
-
border: !1,
|
|
34
|
-
placeholder: h,
|
|
35
|
-
plugins: n,
|
|
36
|
-
onValueChanged: p,
|
|
37
|
-
onTextChange: g,
|
|
38
|
-
hideExternalFloatingModals: x
|
|
39
|
-
}
|
|
40
|
-
) : /* @__PURE__ */ d(w, { value: t, columns: u, gap: c, show: m, plugins: n });
|
|
52
|
+
return I({ ref: o, disabled: !i, onChange: s }), p(() => {
|
|
53
|
+
n(!1);
|
|
54
|
+
}, []), /* @__PURE__ */ l("div", { className: "tw-block tw-w-full", ref: o, children: /* @__PURE__ */ l(E, { ...f, isEnabled: i && t }) });
|
|
41
55
|
};
|
|
42
56
|
export {
|
|
43
|
-
|
|
57
|
+
M as RichTextEditor
|
|
44
58
|
};
|
|
45
59
|
//# sourceMappingURL=RichTextEditor.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextEditor.es.js","sources":["../../../src/components/RichTextEditor/RichTextEditor.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useCallback, useEffect, useState } from 'react';\n\nimport { RichTextEditor as FondueRichTextEditor } from '@frontify/fondue';\nimport { RichTextEditorProps } from './types';\nimport { SerializedText } from './SerializedText';\nimport { floatingButtonActions, floatingButtonSelectors } from './plugins/ButtonPlugin/components';\n\
|
|
1
|
+
{"version":3,"file":"RichTextEditor.es.js","sources":["../../../src/components/RichTextEditor/RichTextEditor.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { memo, useCallback, useEffect, useRef, useState } from 'react';\n\nimport { RichTextEditor as FondueRichTextEditor } from '@frontify/fondue';\nimport { RichTextEditorProps } from './types';\nimport { SerializedText } from './SerializedText';\nimport { floatingButtonActions, floatingButtonSelectors } from './plugins/ButtonPlugin/components';\nimport { useIsInViewport } from '../../hooks/useIsInViewport';\n\nconst InternalRichTextEditor = memo(\n ({\n id = 'rte',\n isEnabled,\n value,\n columns,\n gap,\n placeholder,\n plugins,\n onTextChange,\n showSerializedText,\n }: Omit<RichTextEditorProps, 'isEditing'> & { isEnabled: boolean }) => {\n const [shouldPreventPageLeave, setShouldPreventPageLeave] = useState(false);\n\n const handleTextChange = useCallback(\n (newContent: string) => {\n if (newContent !== value) {\n onTextChange?.(newContent);\n setShouldPreventPageLeave(false);\n }\n },\n [onTextChange, value],\n );\n\n const handleValueChange = useCallback(() => setShouldPreventPageLeave(true), []);\n\n const handleHideExternalFloatingModals = useCallback((editorId: string) => {\n if (floatingButtonSelectors.isOpen(editorId)) {\n floatingButtonActions.reset();\n }\n }, []);\n\n useEffect(() => {\n const unloadHandler = (event: BeforeUnloadEvent) => {\n event.preventDefault();\n event.returnValue = 'Unprocessed changes';\n };\n\n if (shouldPreventPageLeave) {\n window.addEventListener('beforeunload', unloadHandler);\n }\n\n return () => window.removeEventListener('beforeunload', unloadHandler);\n }, [shouldPreventPageLeave]);\n\n if (isEnabled) {\n return (\n <FondueRichTextEditor\n id={id}\n value={value}\n border={false}\n placeholder={placeholder}\n plugins={plugins}\n onValueChanged={handleValueChange}\n onTextChange={handleTextChange}\n hideExternalFloatingModals={handleHideExternalFloatingModals}\n />\n );\n }\n return <SerializedText value={value} columns={columns} gap={gap} show={showSerializedText} plugins={plugins} />;\n },\n);\nInternalRichTextEditor.displayName = 'InternalRichTextEditor';\n\nexport const RichTextEditor = (props: RichTextEditorProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const [hasEnteredViewport, setHasEnteredViewport] = useState(false);\n\n const { isEditing, ...internalRteProps } = props;\n\n const onViewportVisibilityChange = useCallback((isInViewport: boolean) => {\n if (isInViewport) {\n setHasEnteredViewport(true);\n }\n }, []);\n\n useIsInViewport({ ref, disabled: !isEditing, onChange: onViewportVisibilityChange });\n\n useEffect(() => {\n setHasEnteredViewport(false);\n }, []);\n\n return (\n <div className=\"tw-block tw-w-full\" ref={ref}>\n <InternalRichTextEditor {...internalRteProps} isEnabled={isEditing && hasEnteredViewport} />\n </div>\n );\n};\n"],"names":["InternalRichTextEditor","memo","id","isEnabled","value","columns","gap","placeholder","plugins","onTextChange","showSerializedText","shouldPreventPageLeave","setShouldPreventPageLeave","useState","handleTextChange","useCallback","newContent","handleValueChange","handleHideExternalFloatingModals","editorId","floatingButtonSelectors","floatingButtonActions","useEffect","unloadHandler","event","jsx","FondueRichTextEditor","SerializedText","RichTextEditor","props","ref","useRef","hasEnteredViewport","setHasEnteredViewport","isEditing","internalRteProps","onViewportVisibilityChange","isInViewport","useIsInViewport"],"mappings":";;;;;;AAUA,MAAMA,IAAyBC;AAAA,EAC3B,CAAC;AAAA,IACG,IAAAC,IAAK;AAAA,IACL,WAAAC;AAAA,IACA,OAAAC;AAAA,IACA,SAAAC;AAAA,IACA,KAAAC;AAAA,IACA,aAAAC;AAAA,IACA,SAAAC;AAAA,IACA,cAAAC;AAAA,IACA,oBAAAC;AAAA,EAAA,MACmE;AACnE,UAAM,CAACC,GAAwBC,CAAyB,IAAIC,EAAS,EAAK,GAEpEC,IAAmBC;AAAA,MACrB,CAACC,MAAuB;AACpB,QAAIA,MAAeZ,MACfK,KAAA,QAAAA,EAAeO,IACfJ,EAA0B,EAAK;AAAA,MAEvC;AAAA,MACA,CAACH,GAAcL,CAAK;AAAA,IAAA,GAGlBa,IAAoBF,EAAY,MAAMH,EAA0B,EAAI,GAAG,CAAA,CAAE,GAEzEM,IAAmCH,EAAY,CAACI,MAAqB;AACnE,MAAAC,EAAwB,OAAOD,CAAQ,KACvCE,EAAsB,MAAM;AAAA,IAEpC,GAAG,CAAE,CAAA;AAeL,WAbAC,EAAU,MAAM;AACN,YAAAC,IAAgB,CAACC,MAA6B;AAChD,QAAAA,EAAM,eAAe,GACrBA,EAAM,cAAc;AAAA,MAAA;AAGxB,aAAIb,KACO,OAAA,iBAAiB,gBAAgBY,CAAa,GAGlD,MAAM,OAAO,oBAAoB,gBAAgBA,CAAa;AAAA,IAAA,GACtE,CAACZ,CAAsB,CAAC,GAEvBR,IAEI,gBAAAsB;AAAA,MAACC;AAAAA,MAAA;AAAA,QACG,IAAAxB;AAAA,QACA,OAAAE;AAAA,QACA,QAAQ;AAAA,QACR,aAAAG;AAAA,QACA,SAAAC;AAAA,QACA,gBAAgBS;AAAA,QAChB,cAAcH;AAAA,QACd,4BAA4BI;AAAA,MAAA;AAAA,IAAA,sBAIhCS,GAAe,EAAA,OAAAvB,GAAc,SAAAC,GAAkB,KAAAC,GAAU,MAAMI,GAAoB,SAAAF,EAAkB,CAAA;AAAA,EACjH;AACJ;AACAR,EAAuB,cAAc;AAExB,MAAA4B,IAAiB,CAACC,MAA+B;AACpD,QAAAC,IAAMC,EAAuB,IAAI,GACjC,CAACC,GAAoBC,CAAqB,IAAIpB,EAAS,EAAK,GAE5D,EAAE,WAAAqB,GAAW,GAAGC,EAAA,IAAqBN,GAErCO,IAA6BrB,EAAY,CAACsB,MAA0B;AACtE,IAAIA,KACAJ,EAAsB,EAAI;AAAA,EAElC,GAAG,CAAE,CAAA;AAEL,SAAAK,EAAgB,EAAE,KAAAR,GAAK,UAAU,CAACI,GAAW,UAAUE,GAA4B,GAEnFd,EAAU,MAAM;AACZ,IAAAW,EAAsB,EAAK;AAAA,EAC/B,GAAG,CAAE,CAAA,GAGA,gBAAAR,EAAA,OAAA,EAAI,WAAU,sBAAqB,KAAAK,GAChC,UAAA,gBAAAL,EAACzB,GAAwB,EAAA,GAAGmC,GAAkB,WAAWD,KAAaF,EAAA,CAAoB,EAC9F,CAAA;AAER;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useEffect as c } from "react";
|
|
2
|
+
const I = ({
|
|
3
|
+
ref: e,
|
|
4
|
+
disabled: r,
|
|
5
|
+
onChange: s
|
|
6
|
+
}) => {
|
|
7
|
+
c(() => {
|
|
8
|
+
if (r || !e.current)
|
|
9
|
+
return;
|
|
10
|
+
let n = !1;
|
|
11
|
+
const i = new IntersectionObserver(([t]) => {
|
|
12
|
+
t.isIntersecting !== n && (n = t.isIntersecting, s(t.isIntersecting));
|
|
13
|
+
});
|
|
14
|
+
return i.observe(e.current), () => {
|
|
15
|
+
i.disconnect();
|
|
16
|
+
};
|
|
17
|
+
}, [e, r, s]);
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
I as useIsInViewport
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=useIsInViewport.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIsInViewport.es.js","sources":["../../src/hooks/useIsInViewport.ts"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { RefObject, useEffect } from 'react';\n\nexport const useIsInViewport = <T extends Element>({\n ref,\n disabled,\n onChange,\n}: {\n ref: RefObject<T>;\n disabled: boolean;\n onChange: (isInViewport: boolean) => void;\n}) => {\n useEffect(() => {\n if (disabled || !ref.current) {\n return;\n }\n\n let isInViewport = false;\n\n const intersectionObserver = new IntersectionObserver(([entry]) => {\n if (entry.isIntersecting !== isInViewport) {\n isInViewport = entry.isIntersecting;\n onChange(entry.isIntersecting);\n }\n });\n\n intersectionObserver.observe(ref.current);\n\n return () => {\n intersectionObserver.disconnect();\n };\n }, [ref, disabled, onChange]);\n};\n"],"names":["useIsInViewport","ref","disabled","onChange","useEffect","isInViewport","intersectionObserver","entry"],"mappings":";AAIO,MAAMA,IAAkB,CAAoB;AAAA,EAC/C,KAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AACJ,MAIM;AACF,EAAAC,EAAU,MAAM;AACR,QAAAF,KAAY,CAACD,EAAI;AACjB;AAGJ,QAAII,IAAe;AAEnB,UAAMC,IAAuB,IAAI,qBAAqB,CAAC,CAACC,CAAK,MAAM;AAC3D,MAAAA,EAAM,mBAAmBF,MACzBA,IAAeE,EAAM,gBACrBJ,EAASI,EAAM,cAAc;AAAA,IACjC,CACH;AAEoB,WAAAD,EAAA,QAAQL,EAAI,OAAO,GAEjC,MAAM;AACT,MAAAK,EAAqB,WAAW;AAAA,IAAA;AAAA,EAErC,GAAA,CAACL,GAAKC,GAAUC,CAAQ,CAAC;AAChC;"}
|