dirk-cfx-react 1.1.82 → 1.1.84

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/index.cjs CHANGED
@@ -3703,11 +3703,11 @@ function ConfirmModal({
3703
3703
  placeholder: confirmText,
3704
3704
  value: typed,
3705
3705
  onChange: (e) => setTyped(e.currentTarget.value),
3706
- styles: (t) => ({
3706
+ styles: (t2) => ({
3707
3707
  input: {
3708
- backgroundColor: core.alpha(t.colors.dark[7], 0.5),
3708
+ backgroundColor: core.alpha(t2.colors.dark[7], 0.5),
3709
3709
  border: `0.1vh solid ${core.alpha(
3710
- typed === confirmText ? "#ef4444" : t.colors.dark[5],
3710
+ typed === confirmText ? "#ef4444" : t2.colors.dark[5],
3711
3711
  0.5
3712
3712
  )}`,
3713
3713
  color: "rgba(255,255,255,0.85)",
@@ -6933,6 +6933,182 @@ function ScenarioSelect({
6933
6933
  }
6934
6934
  );
6935
6935
  }
6936
+ var t = (key, fallback) => {
6937
+ const v = locale(key);
6938
+ return v === key ? fallback : v;
6939
+ };
6940
+ function decimalToHex(color) {
6941
+ if (!color || color === 0) return null;
6942
+ return "#" + color.toString(16).padStart(6, "0");
6943
+ }
6944
+ function RoleOption({ role }) {
6945
+ const swatch = decimalToHex(role.color) || "rgba(255,255,255,0.25)";
6946
+ return /* @__PURE__ */ jsxRuntime.jsxs(core.Flex, { align: "center", gap: "0.6vh", children: [
6947
+ /* @__PURE__ */ jsxRuntime.jsx(
6948
+ "div",
6949
+ {
6950
+ style: {
6951
+ width: "1vh",
6952
+ height: "1vh",
6953
+ borderRadius: "50%",
6954
+ background: swatch,
6955
+ flexShrink: 0,
6956
+ boxShadow: role.color ? `0 0 0.4vh ${swatch}` : void 0
6957
+ }
6958
+ }
6959
+ ),
6960
+ /* @__PURE__ */ jsxRuntime.jsx(core.Text, { size: "xs", c: "rgba(255,255,255,0.9)", children: role.name })
6961
+ ] });
6962
+ }
6963
+ var NOT_CONFIGURED_TINT = "rgba(255,184,0,0.35)";
6964
+ var NOT_CONFIGURED_FILL = "rgba(255,184,0,0.05)";
6965
+ function DiscordRoleSelect(props) {
6966
+ const { endpoint, label: label2, size = "xs", placeholder, disabled, style, styles } = props;
6967
+ const [roles, setRoles] = React6.useState(null);
6968
+ const [loading, setLoading] = React6.useState(false);
6969
+ const [errorCode, setErrorCode] = React6.useState(null);
6970
+ const refresh = async () => {
6971
+ setLoading(true);
6972
+ try {
6973
+ const res = await fetchNui(endpoint, {}, {
6974
+ // Browser dev fallback so the component renders something useful
6975
+ // outside FiveM.
6976
+ ok: true,
6977
+ roles: [
6978
+ { id: "1", name: "Admin", color: 15548997, position: 5 },
6979
+ { id: "2", name: "VIP Gold", color: 16426522, position: 4 },
6980
+ { id: "3", name: "Member", color: 5763719, position: 3 },
6981
+ { id: "4", name: "Guest", color: 0, position: 2 }
6982
+ ]
6983
+ });
6984
+ if (res?.ok) {
6985
+ setRoles(res.roles ?? []);
6986
+ setErrorCode(null);
6987
+ } else {
6988
+ setRoles(null);
6989
+ setErrorCode(res?._error || "FetchFailed");
6990
+ }
6991
+ } finally {
6992
+ setLoading(false);
6993
+ }
6994
+ };
6995
+ React6.useEffect(() => {
6996
+ refresh();
6997
+ }, [endpoint]);
6998
+ const rolesById = React6.useMemo(() => {
6999
+ const map = {};
7000
+ for (const r of roles ?? []) map[r.id] = r;
7001
+ return map;
7002
+ }, [roles]);
7003
+ if (errorCode === "NotConfigured") {
7004
+ const notConfiguredPlaceholder = t(
7005
+ "DiscordNotConfigured",
7006
+ "Not configured \u2014 set in /dirk_lib"
7007
+ );
7008
+ const notConfiguredStyles = {
7009
+ ...styles,
7010
+ input: {
7011
+ ...styles?.input ?? {},
7012
+ borderColor: NOT_CONFIGURED_TINT,
7013
+ backgroundColor: NOT_CONFIGURED_FILL
7014
+ }
7015
+ };
7016
+ const warnIcon = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.AlertTriangle, { size: "1.2vh", color: NOT_CONFIGURED_TINT.replace(/0\.35\)$/, "0.85)") });
7017
+ if (props.multi) {
7018
+ return /* @__PURE__ */ jsxRuntime.jsx(
7019
+ core.MultiSelect,
7020
+ {
7021
+ label: label2,
7022
+ size,
7023
+ placeholder: notConfiguredPlaceholder,
7024
+ data: [],
7025
+ value: [],
7026
+ onChange: () => {
7027
+ },
7028
+ disabled: true,
7029
+ rightSection: warnIcon,
7030
+ style,
7031
+ styles: notConfiguredStyles
7032
+ }
7033
+ );
7034
+ }
7035
+ return /* @__PURE__ */ jsxRuntime.jsx(
7036
+ core.Select,
7037
+ {
7038
+ label: label2,
7039
+ size,
7040
+ placeholder: notConfiguredPlaceholder,
7041
+ data: [],
7042
+ value: null,
7043
+ onChange: () => {
7044
+ },
7045
+ disabled: true,
7046
+ rightSection: warnIcon,
7047
+ style,
7048
+ styles: notConfiguredStyles
7049
+ }
7050
+ );
7051
+ }
7052
+ const data = (roles ?? []).map((r) => ({
7053
+ value: r.id,
7054
+ label: r.name
7055
+ }));
7056
+ const renderOption = ({ option }) => {
7057
+ const role = rolesById[option.value];
7058
+ return role ? /* @__PURE__ */ jsxRuntime.jsx(RoleOption, { role }) : /* @__PURE__ */ jsxRuntime.jsx(core.Text, { size: "xs", children: option.label });
7059
+ };
7060
+ const refreshButton = /* @__PURE__ */ jsxRuntime.jsx(
7061
+ core.ActionIcon,
7062
+ {
7063
+ size: "xs",
7064
+ variant: "subtle",
7065
+ onClick: refresh,
7066
+ title: t("Refresh", "Refresh"),
7067
+ loading,
7068
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.RefreshCw, { size: "1.2vh" })
7069
+ }
7070
+ );
7071
+ if (props.multi) {
7072
+ return /* @__PURE__ */ jsxRuntime.jsx(
7073
+ core.MultiSelect,
7074
+ {
7075
+ label: label2,
7076
+ size,
7077
+ placeholder: placeholder || t("PickRoles", "Pick roles..."),
7078
+ data,
7079
+ value: props.value || [],
7080
+ onChange: (ids) => props.onChange(ids),
7081
+ renderOption,
7082
+ searchable: true,
7083
+ clearable: true,
7084
+ disabled: disabled || loading && !roles,
7085
+ rightSection: refreshButton,
7086
+ style,
7087
+ styles,
7088
+ nothingFoundMessage: errorCode ? `${t("Error", "Error")} (${errorCode})` : t("NoRoles", "No roles found")
7089
+ }
7090
+ );
7091
+ }
7092
+ return /* @__PURE__ */ jsxRuntime.jsx(
7093
+ core.Select,
7094
+ {
7095
+ label: label2,
7096
+ size,
7097
+ placeholder: placeholder || t("PickRole", "Pick a role..."),
7098
+ data,
7099
+ value: props.value || null,
7100
+ onChange: (id) => props.onChange(id),
7101
+ renderOption,
7102
+ searchable: true,
7103
+ clearable: true,
7104
+ disabled: disabled || loading && !roles,
7105
+ rightSection: refreshButton,
7106
+ style,
7107
+ styles,
7108
+ nothingFoundMessage: errorCode ? `${t("Error", "Error")} (${errorCode})` : t("NoRoles", "No roles found")
7109
+ }
7110
+ );
7111
+ }
6936
7112
  function useTornEdges() {
6937
7113
  const game = useSettings((state) => state.game);
6938
7114
  return game === "rdr3" ? "torn-edge-wrapper" : "";
@@ -7306,6 +7482,7 @@ exports.ControlMultiSelect = ControlMultiSelect;
7306
7482
  exports.ControlSelect = ControlSelect;
7307
7483
  exports.Counter = Counter;
7308
7484
  exports.DirkProvider = DirkProvider;
7485
+ exports.DiscordRoleSelect = DiscordRoleSelect;
7309
7486
  exports.FiveMKeyBindInput = FiveMKeyBindInput;
7310
7487
  exports.FloatingParticles = FloatingParticles;
7311
7488
  exports.FormProvider = FormProvider;