ar-design 0.2.13 → 0.2.15
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import React, { useRef, useState } from "react";
|
|
2
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
3
3
|
import "../../../assets/css/components/form/switch/styles.css";
|
|
4
4
|
import Utils from "../../../libs/infrastructure/shared/Utils";
|
|
5
5
|
const Switch = ({ label, status = "primary", border = { radius: "pill" }, ...attributes }) => {
|
|
@@ -9,6 +9,10 @@ const Switch = ({ label, status = "primary", border = { radius: "pill" }, ...att
|
|
|
9
9
|
// states
|
|
10
10
|
const [checked, setChecked] = useState(attributes.checked ?? false);
|
|
11
11
|
_switchClassName.push(...Utils.GetClassName("filled", checked ? status : "light", border, undefined, undefined, attributes.className));
|
|
12
|
+
// useEffects
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
setChecked(attributes.checked ?? false);
|
|
15
|
+
}, [attributes.checked]);
|
|
12
16
|
return (React.createElement("div", { className: "ar-switch-wrapper" },
|
|
13
17
|
React.createElement("label", null,
|
|
14
18
|
React.createElement("input", { type: "checkbox", ...attributes, checked: checked, size: 0, onChange: (event) => {
|
|
@@ -6,7 +6,6 @@ import { ARIcon } from "../../icons";
|
|
|
6
6
|
import "../../../assets/css/components/form/text-editor/styles.css";
|
|
7
7
|
const TextEditor = ({ name, value, onChange, placeholder, height, validation }) => {
|
|
8
8
|
// refs
|
|
9
|
-
const _firstLoad = useRef(false);
|
|
10
9
|
const _container = useRef(null);
|
|
11
10
|
const _arIframe = useRef(null);
|
|
12
11
|
// states
|
|
@@ -57,12 +56,22 @@ const TextEditor = ({ name, value, onChange, placeholder, height, validation })
|
|
|
57
56
|
// useEffects
|
|
58
57
|
// Iframe Document yüklendikten sonra çalışacaktır. (Bir defa çalışır.)
|
|
59
58
|
useEffect(() => {
|
|
60
|
-
if (iframeDocument
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
if (!iframeDocument)
|
|
60
|
+
return;
|
|
61
|
+
const selection = iframeDocument.getSelection();
|
|
62
|
+
let range = null;
|
|
63
|
+
// Eğer bir seçim (caret) varsa, konumunu kaydet
|
|
64
|
+
if (selection && selection.rangeCount > 0) {
|
|
65
|
+
range = selection.getRangeAt(0);
|
|
66
|
+
}
|
|
67
|
+
// Eğer içeriği kendimiz değiştirmedikse ve gelen value farklıysa, içeriği güncelle
|
|
68
|
+
if (iframeDocument.body.innerHTML !== value) {
|
|
69
|
+
iframeDocument.body.innerHTML = value || `<p>${placeholder ?? ""}</p>`;
|
|
70
|
+
}
|
|
71
|
+
// Cursor (caret) konumunu geri yükle
|
|
72
|
+
if (range) {
|
|
73
|
+
selection?.removeAllRanges();
|
|
74
|
+
selection?.addRange(range);
|
|
66
75
|
}
|
|
67
76
|
}, [value, iframeDocument]);
|
|
68
77
|
// Iframe yüklendikten sonra çalışacaktır.
|