@rolster/react-components 19.6.3 → 19.6.7

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.
Files changed (37) hide show
  1. package/LICENSE +21 -21
  2. package/dist/cjs/index.cjs +103 -39
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/es/index.mjs +4576 -0
  5. package/dist/es/index.mjs.map +1 -0
  6. package/dist/esm/components/atoms/Breadcrumb/Breadcrumb.d.ts +2 -3
  7. package/dist/esm/components/atoms/Breadcrumb/Breadcrumb.js.map +1 -1
  8. package/dist/esm/components/atoms/ProgressCircular/ProgressCircular.d.ts +2 -6
  9. package/dist/esm/components/atoms/ProgressCircular/ProgressCircular.js.map +1 -1
  10. package/dist/esm/components/definitions.d.ts +1 -1
  11. package/dist/esm/components/molecules/ButtonProgress/ButtonProgress.d.ts +2 -3
  12. package/dist/esm/components/molecules/ButtonProgress/ButtonProgress.js.map +1 -1
  13. package/dist/esm/components/molecules/FieldFile/FieldFile.d.ts +1 -1
  14. package/dist/esm/components/molecules/FieldFile/FieldFile.js +3 -3
  15. package/dist/esm/components/molecules/FieldFile/FieldFile.js.map +1 -1
  16. package/dist/esm/components/organisms/Confirmation/Confirmation.d.ts +4 -7
  17. package/dist/esm/components/organisms/Confirmation/Confirmation.js.map +1 -1
  18. package/dist/esm/components/organisms/ImageEditor/ImageEditor.js +17 -9
  19. package/dist/esm/components/organisms/ImageEditor/ImageEditor.js.map +1 -1
  20. package/dist/esm/components/organisms/Notifications/Notifications.d.ts +17 -0
  21. package/dist/esm/components/organisms/Notifications/Notifications.js +59 -0
  22. package/dist/esm/components/organisms/Notifications/Notifications.js.map +1 -0
  23. package/dist/esm/components/organisms/Snackbar/Snackbar.d.ts +2 -3
  24. package/dist/esm/components/organisms/Snackbar/Snackbar.js.map +1 -1
  25. package/dist/esm/context.d.ts +4 -1
  26. package/dist/esm/context.js +14 -12
  27. package/dist/esm/context.js.map +1 -1
  28. package/dist/esm/helpers/color.d.ts +1 -1
  29. package/dist/esm/helpers/color.js +1 -10
  30. package/dist/esm/helpers/color.js.map +1 -1
  31. package/dist/esm/index.d.ts +1 -0
  32. package/dist/esm/index.js +1 -0
  33. package/dist/esm/index.js.map +1 -1
  34. package/dist/esm/types.d.ts +7 -0
  35. package/dist/esm/types.js +1 -1
  36. package/dist/esm/types.js.map +1 -1
  37. package/package.json +77 -91
@@ -0,0 +1,4576 @@
1
+ import require$$0, { useMemo, useState, useRef, useCallback, useEffect, useEffectEvent, createContext, useContext } from 'react';
2
+ import { currencyFormat, BigDecimal, valueIsDefined, SealedPartial } from '@rolster/commons';
3
+ import { i18n, i18nSubscribe } from '@rolster/i18n';
4
+ import { PaginationController, verifyDayPicker, createDayPicker, createDayRangePicker, verifyMonthPicker, createMonthPicker, monthLimitTemplate, createYearPicker, verifyYearPicker, ListCollection, navigationListFromInput, navigationListFromElement, createAutocompleteStore, PickerListenerEvent, dateOutRange, verifyDateRange } from '@rolster/components';
5
+ import { DAY_LABELS, DateRange, normalizeMinTime, assignDayInDate, dateIsBefore, MONTH_NAMES, Month, Time, dateFormatTemplate, assignYearInDate, assignMonthInDate } from '@rolster/dates';
6
+ import ReactDOM from 'react-dom';
7
+ import { useReactControl } from '@rolster/react-forms';
8
+
9
+ var jsxRuntime = {exports: {}};
10
+
11
+ var reactJsxRuntime_production = {};
12
+
13
+ /**
14
+ * @license React
15
+ * react-jsx-runtime.production.js
16
+ *
17
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
18
+ *
19
+ * This source code is licensed under the MIT license found in the
20
+ * LICENSE file in the root directory of this source tree.
21
+ */
22
+
23
+ var hasRequiredReactJsxRuntime_production;
24
+
25
+ function requireReactJsxRuntime_production () {
26
+ if (hasRequiredReactJsxRuntime_production) return reactJsxRuntime_production;
27
+ hasRequiredReactJsxRuntime_production = 1;
28
+ var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
29
+ REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
30
+ function jsxProd(type, config, maybeKey) {
31
+ var key = null;
32
+ void 0 !== maybeKey && (key = "" + maybeKey);
33
+ void 0 !== config.key && (key = "" + config.key);
34
+ if ("key" in config) {
35
+ maybeKey = {};
36
+ for (var propName in config)
37
+ "key" !== propName && (maybeKey[propName] = config[propName]);
38
+ } else maybeKey = config;
39
+ config = maybeKey.ref;
40
+ return {
41
+ $$typeof: REACT_ELEMENT_TYPE,
42
+ type: type,
43
+ key: key,
44
+ ref: void 0 !== config ? config : null,
45
+ props: maybeKey
46
+ };
47
+ }
48
+ reactJsxRuntime_production.Fragment = REACT_FRAGMENT_TYPE;
49
+ reactJsxRuntime_production.jsx = jsxProd;
50
+ reactJsxRuntime_production.jsxs = jsxProd;
51
+ return reactJsxRuntime_production;
52
+ }
53
+
54
+ var reactJsxRuntime_development = {};
55
+
56
+ /**
57
+ * @license React
58
+ * react-jsx-runtime.development.js
59
+ *
60
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
61
+ *
62
+ * This source code is licensed under the MIT license found in the
63
+ * LICENSE file in the root directory of this source tree.
64
+ */
65
+
66
+ var hasRequiredReactJsxRuntime_development;
67
+
68
+ function requireReactJsxRuntime_development () {
69
+ if (hasRequiredReactJsxRuntime_development) return reactJsxRuntime_development;
70
+ hasRequiredReactJsxRuntime_development = 1;
71
+ "production" !== process.env.NODE_ENV &&
72
+ (function () {
73
+ function getComponentNameFromType(type) {
74
+ if (null == type) return null;
75
+ if ("function" === typeof type)
76
+ return type.$$typeof === REACT_CLIENT_REFERENCE
77
+ ? null
78
+ : type.displayName || type.name || null;
79
+ if ("string" === typeof type) return type;
80
+ switch (type) {
81
+ case REACT_FRAGMENT_TYPE:
82
+ return "Fragment";
83
+ case REACT_PROFILER_TYPE:
84
+ return "Profiler";
85
+ case REACT_STRICT_MODE_TYPE:
86
+ return "StrictMode";
87
+ case REACT_SUSPENSE_TYPE:
88
+ return "Suspense";
89
+ case REACT_SUSPENSE_LIST_TYPE:
90
+ return "SuspenseList";
91
+ case REACT_ACTIVITY_TYPE:
92
+ return "Activity";
93
+ }
94
+ if ("object" === typeof type)
95
+ switch (
96
+ ("number" === typeof type.tag &&
97
+ console.error(
98
+ "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
99
+ ),
100
+ type.$$typeof)
101
+ ) {
102
+ case REACT_PORTAL_TYPE:
103
+ return "Portal";
104
+ case REACT_CONTEXT_TYPE:
105
+ return type.displayName || "Context";
106
+ case REACT_CONSUMER_TYPE:
107
+ return (type._context.displayName || "Context") + ".Consumer";
108
+ case REACT_FORWARD_REF_TYPE:
109
+ var innerType = type.render;
110
+ type = type.displayName;
111
+ type ||
112
+ ((type = innerType.displayName || innerType.name || ""),
113
+ (type = "" !== type ? "ForwardRef(" + type + ")" : "ForwardRef"));
114
+ return type;
115
+ case REACT_MEMO_TYPE:
116
+ return (
117
+ (innerType = type.displayName || null),
118
+ null !== innerType
119
+ ? innerType
120
+ : getComponentNameFromType(type.type) || "Memo"
121
+ );
122
+ case REACT_LAZY_TYPE:
123
+ innerType = type._payload;
124
+ type = type._init;
125
+ try {
126
+ return getComponentNameFromType(type(innerType));
127
+ } catch (x) {}
128
+ }
129
+ return null;
130
+ }
131
+ function testStringCoercion(value) {
132
+ return "" + value;
133
+ }
134
+ function checkKeyStringCoercion(value) {
135
+ try {
136
+ testStringCoercion(value);
137
+ var JSCompiler_inline_result = !1;
138
+ } catch (e) {
139
+ JSCompiler_inline_result = true;
140
+ }
141
+ if (JSCompiler_inline_result) {
142
+ JSCompiler_inline_result = console;
143
+ var JSCompiler_temp_const = JSCompiler_inline_result.error;
144
+ var JSCompiler_inline_result$jscomp$0 =
145
+ ("function" === typeof Symbol &&
146
+ Symbol.toStringTag &&
147
+ value[Symbol.toStringTag]) ||
148
+ value.constructor.name ||
149
+ "Object";
150
+ JSCompiler_temp_const.call(
151
+ JSCompiler_inline_result,
152
+ "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
153
+ JSCompiler_inline_result$jscomp$0
154
+ );
155
+ return testStringCoercion(value);
156
+ }
157
+ }
158
+ function getTaskName(type) {
159
+ if (type === REACT_FRAGMENT_TYPE) return "<>";
160
+ if (
161
+ "object" === typeof type &&
162
+ null !== type &&
163
+ type.$$typeof === REACT_LAZY_TYPE
164
+ )
165
+ return "<...>";
166
+ try {
167
+ var name = getComponentNameFromType(type);
168
+ return name ? "<" + name + ">" : "<...>";
169
+ } catch (x) {
170
+ return "<...>";
171
+ }
172
+ }
173
+ function getOwner() {
174
+ var dispatcher = ReactSharedInternals.A;
175
+ return null === dispatcher ? null : dispatcher.getOwner();
176
+ }
177
+ function UnknownOwner() {
178
+ return Error("react-stack-top-frame");
179
+ }
180
+ function hasValidKey(config) {
181
+ if (hasOwnProperty.call(config, "key")) {
182
+ var getter = Object.getOwnPropertyDescriptor(config, "key").get;
183
+ if (getter && getter.isReactWarning) return false;
184
+ }
185
+ return void 0 !== config.key;
186
+ }
187
+ function defineKeyPropWarningGetter(props, displayName) {
188
+ function warnAboutAccessingKey() {
189
+ specialPropKeyWarningShown ||
190
+ ((specialPropKeyWarningShown = true),
191
+ console.error(
192
+ "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
193
+ displayName
194
+ ));
195
+ }
196
+ warnAboutAccessingKey.isReactWarning = true;
197
+ Object.defineProperty(props, "key", {
198
+ get: warnAboutAccessingKey,
199
+ configurable: true
200
+ });
201
+ }
202
+ function elementRefGetterWithDeprecationWarning() {
203
+ var componentName = getComponentNameFromType(this.type);
204
+ didWarnAboutElementRef[componentName] ||
205
+ ((didWarnAboutElementRef[componentName] = true),
206
+ console.error(
207
+ "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
208
+ ));
209
+ componentName = this.props.ref;
210
+ return void 0 !== componentName ? componentName : null;
211
+ }
212
+ function ReactElement(type, key, props, owner, debugStack, debugTask) {
213
+ var refProp = props.ref;
214
+ type = {
215
+ $$typeof: REACT_ELEMENT_TYPE,
216
+ type: type,
217
+ key: key,
218
+ props: props,
219
+ _owner: owner
220
+ };
221
+ null !== (void 0 !== refProp ? refProp : null)
222
+ ? Object.defineProperty(type, "ref", {
223
+ enumerable: false,
224
+ get: elementRefGetterWithDeprecationWarning
225
+ })
226
+ : Object.defineProperty(type, "ref", { enumerable: false, value: null });
227
+ type._store = {};
228
+ Object.defineProperty(type._store, "validated", {
229
+ configurable: false,
230
+ enumerable: false,
231
+ writable: true,
232
+ value: 0
233
+ });
234
+ Object.defineProperty(type, "_debugInfo", {
235
+ configurable: false,
236
+ enumerable: false,
237
+ writable: true,
238
+ value: null
239
+ });
240
+ Object.defineProperty(type, "_debugStack", {
241
+ configurable: false,
242
+ enumerable: false,
243
+ writable: true,
244
+ value: debugStack
245
+ });
246
+ Object.defineProperty(type, "_debugTask", {
247
+ configurable: false,
248
+ enumerable: false,
249
+ writable: true,
250
+ value: debugTask
251
+ });
252
+ Object.freeze && (Object.freeze(type.props), Object.freeze(type));
253
+ return type;
254
+ }
255
+ function jsxDEVImpl(
256
+ type,
257
+ config,
258
+ maybeKey,
259
+ isStaticChildren,
260
+ debugStack,
261
+ debugTask
262
+ ) {
263
+ var children = config.children;
264
+ if (void 0 !== children)
265
+ if (isStaticChildren)
266
+ if (isArrayImpl(children)) {
267
+ for (
268
+ isStaticChildren = 0;
269
+ isStaticChildren < children.length;
270
+ isStaticChildren++
271
+ )
272
+ validateChildKeys(children[isStaticChildren]);
273
+ Object.freeze && Object.freeze(children);
274
+ } else
275
+ console.error(
276
+ "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
277
+ );
278
+ else validateChildKeys(children);
279
+ if (hasOwnProperty.call(config, "key")) {
280
+ children = getComponentNameFromType(type);
281
+ var keys = Object.keys(config).filter(function (k) {
282
+ return "key" !== k;
283
+ });
284
+ isStaticChildren =
285
+ 0 < keys.length
286
+ ? "{key: someKey, " + keys.join(": ..., ") + ": ...}"
287
+ : "{key: someKey}";
288
+ didWarnAboutKeySpread[children + isStaticChildren] ||
289
+ ((keys =
290
+ 0 < keys.length ? "{" + keys.join(": ..., ") + ": ...}" : "{}"),
291
+ console.error(
292
+ 'A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',
293
+ isStaticChildren,
294
+ children,
295
+ keys,
296
+ children
297
+ ),
298
+ (didWarnAboutKeySpread[children + isStaticChildren] = true));
299
+ }
300
+ children = null;
301
+ void 0 !== maybeKey &&
302
+ (checkKeyStringCoercion(maybeKey), (children = "" + maybeKey));
303
+ hasValidKey(config) &&
304
+ (checkKeyStringCoercion(config.key), (children = "" + config.key));
305
+ if ("key" in config) {
306
+ maybeKey = {};
307
+ for (var propName in config)
308
+ "key" !== propName && (maybeKey[propName] = config[propName]);
309
+ } else maybeKey = config;
310
+ children &&
311
+ defineKeyPropWarningGetter(
312
+ maybeKey,
313
+ "function" === typeof type
314
+ ? type.displayName || type.name || "Unknown"
315
+ : type
316
+ );
317
+ return ReactElement(
318
+ type,
319
+ children,
320
+ maybeKey,
321
+ getOwner(),
322
+ debugStack,
323
+ debugTask
324
+ );
325
+ }
326
+ function validateChildKeys(node) {
327
+ isValidElement(node)
328
+ ? node._store && (node._store.validated = 1)
329
+ : "object" === typeof node &&
330
+ null !== node &&
331
+ node.$$typeof === REACT_LAZY_TYPE &&
332
+ ("fulfilled" === node._payload.status
333
+ ? isValidElement(node._payload.value) &&
334
+ node._payload.value._store &&
335
+ (node._payload.value._store.validated = 1)
336
+ : node._store && (node._store.validated = 1));
337
+ }
338
+ function isValidElement(object) {
339
+ return (
340
+ "object" === typeof object &&
341
+ null !== object &&
342
+ object.$$typeof === REACT_ELEMENT_TYPE
343
+ );
344
+ }
345
+ var React = require$$0,
346
+ REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
347
+ REACT_PORTAL_TYPE = Symbol.for("react.portal"),
348
+ REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
349
+ REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"),
350
+ REACT_PROFILER_TYPE = Symbol.for("react.profiler"),
351
+ REACT_CONSUMER_TYPE = Symbol.for("react.consumer"),
352
+ REACT_CONTEXT_TYPE = Symbol.for("react.context"),
353
+ REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"),
354
+ REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"),
355
+ REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list"),
356
+ REACT_MEMO_TYPE = Symbol.for("react.memo"),
357
+ REACT_LAZY_TYPE = Symbol.for("react.lazy"),
358
+ REACT_ACTIVITY_TYPE = Symbol.for("react.activity"),
359
+ REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"),
360
+ ReactSharedInternals =
361
+ React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
362
+ hasOwnProperty = Object.prototype.hasOwnProperty,
363
+ isArrayImpl = Array.isArray,
364
+ createTask = console.createTask
365
+ ? console.createTask
366
+ : function () {
367
+ return null;
368
+ };
369
+ React = {
370
+ react_stack_bottom_frame: function (callStackForError) {
371
+ return callStackForError();
372
+ }
373
+ };
374
+ var specialPropKeyWarningShown;
375
+ var didWarnAboutElementRef = {};
376
+ var unknownOwnerDebugStack = React.react_stack_bottom_frame.bind(
377
+ React,
378
+ UnknownOwner
379
+ )();
380
+ var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
381
+ var didWarnAboutKeySpread = {};
382
+ reactJsxRuntime_development.Fragment = REACT_FRAGMENT_TYPE;
383
+ reactJsxRuntime_development.jsx = function (type, config, maybeKey) {
384
+ var trackActualOwner =
385
+ 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
386
+ return jsxDEVImpl(
387
+ type,
388
+ config,
389
+ maybeKey,
390
+ false,
391
+ trackActualOwner
392
+ ? Error("react-stack-top-frame")
393
+ : unknownOwnerDebugStack,
394
+ trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
395
+ );
396
+ };
397
+ reactJsxRuntime_development.jsxs = function (type, config, maybeKey) {
398
+ var trackActualOwner =
399
+ 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
400
+ return jsxDEVImpl(
401
+ type,
402
+ config,
403
+ maybeKey,
404
+ true,
405
+ trackActualOwner
406
+ ? Error("react-stack-top-frame")
407
+ : unknownOwnerDebugStack,
408
+ trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
409
+ );
410
+ };
411
+ })();
412
+ return reactJsxRuntime_development;
413
+ }
414
+
415
+ var hasRequiredJsxRuntime;
416
+
417
+ function requireJsxRuntime () {
418
+ if (hasRequiredJsxRuntime) return jsxRuntime.exports;
419
+ hasRequiredJsxRuntime = 1;
420
+
421
+ if (process.env.NODE_ENV === 'production') {
422
+ jsxRuntime.exports = requireReactJsxRuntime_production();
423
+ } else {
424
+ jsxRuntime.exports = requireReactJsxRuntime_development();
425
+ }
426
+ return jsxRuntime.exports;
427
+ }
428
+
429
+ var jsxRuntimeExports = requireJsxRuntime();
430
+
431
+ function renderClassStatus(base, status = {}, additionals) {
432
+ const _classElement = [base];
433
+ Object.entries(status).forEach(([key, state]) => {
434
+ state &&
435
+ (typeof state === 'string'
436
+ ? _classElement.push(`${base}--${state}`)
437
+ : _classElement.push(`${base}--${key}`));
438
+ });
439
+ additionals && _classElement.push(additionals);
440
+ return _classElement.join(' ').trim();
441
+ }
442
+
443
+ const className = 'rls-tabular-text';
444
+ const pointers = ['.', ','];
445
+ function getCharClass(char) {
446
+ return pointers.includes(char)
447
+ ? `${className}__pointer`
448
+ : `${className}__char`;
449
+ }
450
+ function RlsTabularText({ className, value }) {
451
+ const codes = useMemo(() => {
452
+ return (jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: value?.split('').map((char, index) => (jsxRuntimeExports.jsx("span", { className: getCharClass(char), children: char }, index))) }));
453
+ }, [value]);
454
+ const _className = useMemo(() => {
455
+ return renderClassStatus('rls-tabular-text', {}, className);
456
+ }, [className]);
457
+ return jsxRuntimeExports.jsx("div", { className: _className, children: codes });
458
+ }
459
+
460
+ function RlsAmount({ value, className, decimals, rlsTheme, symbol }) {
461
+ const classNameAmount = useMemo(() => {
462
+ return renderClassStatus('rls-amount', {}, className);
463
+ }, [className]);
464
+ const { decimal, integer } = useMemo(() => {
465
+ const currency = currencyFormat({ value, decimals });
466
+ if (!currency.includes(',')) {
467
+ return { integer: currency, decimal: '' };
468
+ }
469
+ const currencySplit = currency.split(',');
470
+ return {
471
+ integer: currencySplit[0] + (currencySplit[1] ? ',' : ''),
472
+ decimal: currencySplit[1] || ''
473
+ };
474
+ }, [value, decimals]);
475
+ return (jsxRuntimeExports.jsxs("div", { className: classNameAmount, "rls-theme": rlsTheme, children: [symbol && jsxRuntimeExports.jsx("span", { className: "rls-amount__symbol", children: symbol }), jsxRuntimeExports.jsxs("div", { className: "rls-amount__content", children: [jsxRuntimeExports.jsx(RlsTabularText, { className: "rls-amount__integer", value: integer }), decimal && (jsxRuntimeExports.jsx(RlsTabularText, { className: "rls-amount__decimal", value: decimal }))] })] }));
476
+ }
477
+
478
+ function RlsAreaText({ autoComplete, disabled, formControl, identifier, onBlur, onEnter, onFocus, onKeyDown, onKeyUp, onValue, placeholder, readOnly, resize, rows = 1, value }) {
479
+ const valueInitial = String(formControl?.value ?? value ?? '');
480
+ const [valueArea, setValueArea] = useState(valueInitial);
481
+ const [focused, setFocused] = useState(false);
482
+ const elementRef = useRef(null);
483
+ const areaRef = formControl?.elementRef ?? elementRef;
484
+ const changeIsInternal = useRef(false);
485
+ const refreshHeight = useCallback(() => {
486
+ const element = areaRef.current;
487
+ if (element) {
488
+ element.style.height = 'auto';
489
+ element.style.height = `${element.scrollHeight}px`;
490
+ }
491
+ }, [areaRef]);
492
+ useEffect(() => {
493
+ if (!changeIsInternal.current) {
494
+ const nextValue = String(formControl?.value ?? value ?? '');
495
+ valueArea !== nextValue && setValueArea(nextValue);
496
+ }
497
+ changeIsInternal.current = false;
498
+ }, [formControl?.value, value, valueArea]);
499
+ useEffect(() => {
500
+ refreshHeight();
501
+ }, [refreshHeight, valueArea]);
502
+ const onChangeArea = useCallback((event) => {
503
+ const nextValue = event.target.value;
504
+ changeIsInternal.current = true;
505
+ onValue?.(nextValue);
506
+ setValueArea(nextValue);
507
+ formControl?.setValue(nextValue);
508
+ event.target.style.height = 'auto';
509
+ event.target.style.height = `${event.target.scrollHeight}px`;
510
+ }, [formControl, onValue]);
511
+ const onKeyDownArea = useCallback((event) => {
512
+ onKeyDown?.(event);
513
+ event.key === 'Enter' && onEnter?.();
514
+ }, [onKeyDown, onEnter]);
515
+ const onKeyUpArea = useCallback((event) => {
516
+ onKeyUp?.(event);
517
+ }, [onKeyUp]);
518
+ const onFocusArea = useCallback(() => {
519
+ formControl?.focus();
520
+ setFocused(() => true);
521
+ onFocus?.();
522
+ }, [formControl, onFocus]);
523
+ const onBlurArea = useCallback(() => {
524
+ formControl?.blur();
525
+ setFocused(() => false);
526
+ onBlur?.();
527
+ }, [formControl, onBlur]);
528
+ const className = useMemo(() => {
529
+ return renderClassStatus('rls-area-text', {
530
+ disabled: formControl?.disabled || disabled,
531
+ focused: formControl?.focused ?? focused,
532
+ readonly: readOnly
533
+ });
534
+ }, [
535
+ formControl?.disabled,
536
+ formControl?.focused,
537
+ disabled,
538
+ focused,
539
+ readOnly
540
+ ]);
541
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, children: [jsxRuntimeExports.jsx("textarea", { ref: areaRef, className: "rls-area-text__component", autoComplete: autoComplete ?? 'off', placeholder: placeholder, disabled: formControl?.disabled || disabled, readOnly: readOnly, rows: rows, style: { resize }, onFocus: onFocusArea, onBlur: onBlurArea, onChange: onChangeArea, onKeyDown: onKeyDownArea, onKeyUp: onKeyUpArea, value: valueArea }), jsxRuntimeExports.jsx("span", { className: "rls-area-text__value", children: valueArea })] }));
542
+ }
543
+
544
+ function RlsAvatar({ children, contrasted, rounded, skeleton, rlsTheme }) {
545
+ const className = useMemo(() => {
546
+ return renderClassStatus('rls-avatar', { contrasted, rounded, skeleton });
547
+ }, [contrasted, rounded, skeleton]);
548
+ return (jsxRuntimeExports.jsx("div", { className: className, "rls-theme": rlsTheme, children: children }));
549
+ }
550
+
551
+ function RlsBadge({ children, contrasted, rlsTheme }) {
552
+ const className = useMemo(() => {
553
+ return renderClassStatus('rls-badge', { contrasted });
554
+ }, [contrasted]);
555
+ return (jsxRuntimeExports.jsx("span", { className: className, "rls-theme": rlsTheme, children: children }));
556
+ }
557
+
558
+ function RlsBreadcrumbLabel({ label }) {
559
+ const className = useMemo(() => {
560
+ return renderClassStatus('rls-breadcrumb__label__a', {
561
+ actionable: !!label.onClick
562
+ });
563
+ }, [label.onClick]);
564
+ return (jsxRuntimeExports.jsx("span", { className: "rls-breadcrumb__label", onClick: label.onClick, children: jsxRuntimeExports.jsx("a", { className: className, "rls-theme": label.rlsTheme, children: label.label }) }));
565
+ }
566
+ function RlsBreadcrumb({ labels }) {
567
+ const children = useMemo(() => {
568
+ return labels.map((label, index) => (jsxRuntimeExports.jsx(RlsBreadcrumbLabel, { label: label }, index)));
569
+ }, [labels]);
570
+ return jsxRuntimeExports.jsx("div", { className: "rls-breadcrumb", children: children });
571
+ }
572
+
573
+ function RlsIcon({ value, className, rlsTheme, skeleton }) {
574
+ const classNameIcon = useMemo(() => {
575
+ return renderClassStatus('rls-icon', { skeleton }, className);
576
+ }, [className, skeleton]);
577
+ return (jsxRuntimeExports.jsx("div", { className: classNameIcon, "rls-theme": rlsTheme, children: jsxRuntimeExports.jsx("i", { className: `rls-icon-${value}` }) }));
578
+ }
579
+
580
+ function RlsSpinner() {
581
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-spinner", children: [jsxRuntimeExports.jsx("svg", { className: "rls-spinner__svg rls-spinner__svg--1", viewBox: "0 0 64 64", children: jsxRuntimeExports.jsx("circle", {}) }), jsxRuntimeExports.jsx("svg", { className: "rls-spinner__svg rls-spinner__svg--2", viewBox: "0 0 64 64", children: jsxRuntimeExports.jsx("circle", {}) }), jsxRuntimeExports.jsx("svg", { className: "rls-spinner__svg rls-spinner__svg--3", viewBox: "0 0 64 64", children: jsxRuntimeExports.jsx("circle", {}) }), jsxRuntimeExports.jsx("svg", { className: "rls-spinner__svg rls-spinner__svg--4", viewBox: "0 0 64 64", children: jsxRuntimeExports.jsx("circle", {}) }), jsxRuntimeExports.jsx("svg", { className: "rls-spinner__svg rls-spinner__svg--5", viewBox: "0 0 64 64", children: jsxRuntimeExports.jsx("circle", {}) }), jsxRuntimeExports.jsx("svg", { className: "rls-spinner__svg rls-spinner__svg--6", viewBox: "0 0 64 64", children: jsxRuntimeExports.jsx("circle", {}) }), jsxRuntimeExports.jsx("svg", { className: "rls-spinner__svg rls-spinner__svg--7", viewBox: "0 0 64 64", children: jsxRuntimeExports.jsx("circle", {}) }), jsxRuntimeExports.jsx("svg", { className: "rls-spinner__svg rls-spinner__svg--8", viewBox: "0 0 64 64", children: jsxRuntimeExports.jsx("circle", {}) }), jsxRuntimeExports.jsx("svg", { className: "rls-spinner__svg rls-spinner__svg--9", viewBox: "0 0 64 64", children: jsxRuntimeExports.jsx("circle", {}) })] }));
582
+ }
583
+
584
+ function RlsButton({ type, children, disabled, identifier, onClick, prefixIcon, requesting, rlsTheme, suffixIcon }) {
585
+ const className = useMemo(() => {
586
+ return renderClassStatus('rls-button__content', { type });
587
+ }, [type]);
588
+ return (jsxRuntimeExports.jsx("button", { id: identifier, className: "rls-button", onClick: onClick, "rls-theme": rlsTheme, disabled: disabled, children: jsxRuntimeExports.jsxs("div", { className: className, children: [requesting && jsxRuntimeExports.jsx(RlsSpinner, {}), prefixIcon && jsxRuntimeExports.jsx(RlsIcon, { value: prefixIcon }), children && jsxRuntimeExports.jsx("div", { className: "rls-button__description", children: children }), suffixIcon && jsxRuntimeExports.jsx(RlsIcon, { value: suffixIcon })] }) }));
589
+ }
590
+
591
+ function RlsButtonAction({ icon, disabled, identifier, onClick, rlsTheme, tooltip, type }) {
592
+ const className = useMemo(() => {
593
+ return renderClassStatus('rls-button-action', { type });
594
+ }, [type]);
595
+ return (jsxRuntimeExports.jsxs("button", { id: identifier, className: className, onClick: onClick, disabled: disabled, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-button-action__content", children: jsxRuntimeExports.jsx(RlsIcon, { value: icon }) }), tooltip && (jsxRuntimeExports.jsx("div", { className: "rls-button-action__tooltip rls-overline-font-medium", children: jsxRuntimeExports.jsx("span", { children: tooltip }) }))] }));
596
+ }
597
+
598
+ function RlsButtonIcon({ icon, className, disabled, onClick, skeleton }) {
599
+ const classNameButton = useMemo(() => {
600
+ return renderClassStatus('rls-button-icon', { skeleton }, className);
601
+ }, [className, skeleton]);
602
+ return (jsxRuntimeExports.jsx("button", { className: classNameButton, onClick: onClick, disabled: disabled, children: !skeleton && jsxRuntimeExports.jsx(RlsIcon, { value: icon }) }));
603
+ }
604
+
605
+ function useFormSingleSelectionController({ disabled, formControl, onValue, value }) {
606
+ const [checked, setChecked] = useState(formControl?.value === value);
607
+ useEffect(() => {
608
+ setChecked(formControl?.value === value);
609
+ }, [formControl?.value]);
610
+ const onSelect = useCallback(() => {
611
+ if (!disabled) {
612
+ formControl?.setValue(value);
613
+ onValue?.(value);
614
+ }
615
+ }, [formControl, value, onValue, disabled]);
616
+ return { checked, onSelect };
617
+ }
618
+
619
+ function RlsButtonOption({ icon, children, disabled, formControl, identifier, onClick, onValue, value }) {
620
+ const { checked, onSelect } = useFormSingleSelectionController({
621
+ disabled,
622
+ formControl,
623
+ onValue,
624
+ value
625
+ });
626
+ const className = useMemo(() => {
627
+ return renderClassStatus('rls-button-option', { checked });
628
+ }, [checked]);
629
+ const onAction = useCallback(() => {
630
+ onSelect();
631
+ onClick?.();
632
+ }, [onSelect, onClick]);
633
+ return (jsxRuntimeExports.jsxs("button", { id: identifier, className: className, onClick: onAction, disabled: disabled, children: [jsxRuntimeExports.jsx(RlsIcon, { value: icon }), children] }));
634
+ }
635
+
636
+ function RlsCheckBox({ checked, disabled, identifier, onClick, rlsTheme }) {
637
+ const className = useMemo(() => {
638
+ return renderClassStatus('rls-checkbox', { checked, disabled });
639
+ }, [checked, disabled]);
640
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: className, onClick: onClick, "rls-theme": rlsTheme, children: jsxRuntimeExports.jsx(RlsIcon, { value: "checkmark" }) }));
641
+ }
642
+ function RlsCheckBoxControl({ formControl, disabled, identifier, rlsTheme }) {
643
+ const onClick = useCallback(() => {
644
+ formControl.setValue(!formControl.value);
645
+ }, [formControl.value]);
646
+ return (jsxRuntimeExports.jsx(RlsCheckBox, { identifier: identifier, checked: !!formControl.value, disabled: disabled, onClick: onClick, rlsTheme: rlsTheme }));
647
+ }
648
+
649
+ function RlsSkeleton({ rlsTheme }) {
650
+ return jsxRuntimeExports.jsx("div", { className: "rls-skeleton", "rls-theme": rlsTheme });
651
+ }
652
+
653
+ function RlsImage({ src, rlsTheme }) {
654
+ const [srcIsComplet, setSrcIsComplet] = useState(false);
655
+ const refImage = useRef(null);
656
+ const className = useMemo(() => {
657
+ return renderClassStatus('rls-image', { complet: srcIsComplet });
658
+ }, [srcIsComplet]);
659
+ useEffect(() => {
660
+ setSrcIsComplet(!!(src && refImage.current?.complete));
661
+ }, [src]);
662
+ const onLoad = useCallback(() => {
663
+ setSrcIsComplet(true);
664
+ }, []);
665
+ return (jsxRuntimeExports.jsxs("div", { className: className, "rls-theme": rlsTheme, children: [!srcIsComplet && jsxRuntimeExports.jsx(RlsSkeleton, { rlsTheme: rlsTheme }), jsxRuntimeExports.jsx("img", { ref: refImage, src: src, onLoad: onLoad })] }));
666
+ }
667
+
668
+ function RlsInput({ children, decimals, disabled, formControl, identifier, onBlur, onEnter, onFocus, onKeyDown, onKeyUp, onValue, placeholder, readOnly, type, value }) {
669
+ const valueInitial = (formControl?.value ?? value) ? String(value) : '';
670
+ const [valueInput, setValueInput] = useState(valueInitial);
671
+ const [focused, setFocused] = useState(false);
672
+ const changeIsInternal = useRef(false);
673
+ useEffect(() => {
674
+ if (!changeIsInternal.current && formControl) {
675
+ const valueControl = formControl.value ? String(formControl.value) : '';
676
+ valueInput !== valueControl && setValueInput(valueControl);
677
+ }
678
+ changeIsInternal.current = false;
679
+ }, [formControl?.value]);
680
+ const onChangeInput = useCallback((event) => {
681
+ const valueInput = event.target.value;
682
+ const value = type === 'number'
683
+ ? parseFloat((+valueInput).toFixed(decimals))
684
+ : valueInput;
685
+ changeIsInternal.current = true;
686
+ onValue?.(value);
687
+ setValueInput(valueInput);
688
+ formControl?.setValue(value);
689
+ }, [formControl, onValue, type, decimals]);
690
+ const onKeyDownInput = useCallback((event) => {
691
+ onKeyDown?.(event);
692
+ event.key === 'Enter' && onEnter?.();
693
+ }, [onKeyDown, onEnter]);
694
+ const onKeyUpInput = useCallback((event) => {
695
+ onKeyUp?.(event);
696
+ }, [onKeyUp]);
697
+ const onFocusInput = useCallback(() => {
698
+ formControl?.focus();
699
+ setFocused(() => true);
700
+ onFocus?.();
701
+ }, [formControl, onFocus]);
702
+ const onBlurInput = useCallback(() => {
703
+ formControl?.blur();
704
+ setFocused(() => false);
705
+ onBlur?.();
706
+ }, [formControl, onBlur]);
707
+ const className = useMemo(() => {
708
+ return renderClassStatus('rls-input', {
709
+ disabled: formControl?.disabled || disabled,
710
+ focused: formControl?.focused ?? focused
711
+ });
712
+ }, [formControl?.focused, formControl?.disabled, focused, disabled]);
713
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, children: [jsxRuntimeExports.jsx("input", { ref: formControl?.elementRef, className: "rls-input__component", autoComplete: "off", type: type ?? 'text', placeholder: placeholder, disabled: formControl?.disabled || disabled, readOnly: readOnly, onFocus: onFocusInput, onBlur: onBlurInput, onChange: onChangeInput, onKeyDown: onKeyDownInput, onKeyUp: onKeyUpInput, value: valueInput }), jsxRuntimeExports.jsx("span", { className: "rls-input__value", children: children })] }));
714
+ }
715
+
716
+ function RlsInputCounter({ className, disabled, formControl, identifier, max, min, onBlur, onFocus, onValue, readOnly, rlsTheme, step = 1, value: valueProp }) {
717
+ const changeIsInternal = useRef(false);
718
+ const [value, setValue] = useState(formControl?.value ?? valueProp ?? 0);
719
+ const [focused, setFocused] = useState(false);
720
+ const _disabled = useMemo(() => formControl?.disabled || disabled, [formControl?.disabled, disabled]);
721
+ const classNameCounter = useMemo(() => {
722
+ return renderClassStatus('rls-input-counter', {
723
+ disabled: _disabled,
724
+ focused: formControl?.focused ?? focused,
725
+ readonly: readOnly
726
+ }, className);
727
+ }, [_disabled, formControl?.focused, focused, readOnly, className]);
728
+ useEffect(() => {
729
+ if (!changeIsInternal.current && formControl) {
730
+ const counterValue = formControl.value;
731
+ counterValue !== undefined &&
732
+ counterValue !== value &&
733
+ setValue(counterValue);
734
+ }
735
+ changeIsInternal.current = false;
736
+ }, [formControl?.value]);
737
+ const onUpdate = useCallback((nextValue) => {
738
+ const clamped = Math.min(max ?? Infinity, Math.max(min ?? -Infinity, nextValue));
739
+ changeIsInternal.current = true;
740
+ setValue(clamped);
741
+ formControl?.setValue(clamped);
742
+ onValue?.(clamped);
743
+ }, [formControl, max, min, onValue]);
744
+ const onDecrement = useCallback(() => {
745
+ onUpdate(value - step);
746
+ }, [onUpdate, value, step]);
747
+ const onIncrement = useCallback(() => {
748
+ onUpdate(value + step);
749
+ }, [onUpdate, value, step]);
750
+ const decrementIsAllowed = useMemo(() => min !== undefined && value <= min, [min, value]);
751
+ const incrementIsAllowed = useMemo(() => max !== undefined && value >= max, [max, value]);
752
+ const onChangeInput = useCallback((event) => {
753
+ const parsed = parseFloat(event.target.value);
754
+ !isNaN(parsed) && onUpdate(parsed);
755
+ }, [onUpdate]);
756
+ const onFocusInput = useCallback(() => {
757
+ setFocused(true);
758
+ formControl?.focus();
759
+ onFocus?.();
760
+ }, [formControl, onFocus]);
761
+ const onBlurInput = useCallback(() => {
762
+ setFocused(false);
763
+ formControl?.blur();
764
+ onBlur?.();
765
+ }, [formControl, onBlur]);
766
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: classNameCounter, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx(RlsButtonIcon, { className: "rls-input-counter__down", icon: "minus", onClick: onDecrement, disabled: _disabled || decrementIsAllowed }), jsxRuntimeExports.jsx("div", { className: "rls-input-counter__body", children: jsxRuntimeExports.jsx("input", { ref: formControl?.elementRef, className: "rls-input-counter__control", type: "text", inputMode: "numeric", value: value, disabled: _disabled, readOnly: readOnly, onChange: onChangeInput, onFocus: onFocusInput, onBlur: onBlurInput }) }), jsxRuntimeExports.jsx(RlsButtonIcon, { className: "rls-input-counter__up", icon: "plus", onClick: onIncrement, disabled: _disabled || incrementIsAllowed })] }));
767
+ }
768
+
769
+ function RlsInputDecimal(props) {
770
+ const { decimals, formControl, identifier, onValue, symbol, value } = props;
771
+ const [valueInput, setValueInput] = useState((formControl?.value ?? value ?? BigDecimal.zero()).rounded);
772
+ const amount = useMemo(() => {
773
+ return formControl?.value?.rounded ?? valueInput;
774
+ }, [formControl?.value, valueInput]);
775
+ const onValueInput = useCallback((value) => {
776
+ const valueDecimal = BigDecimal.create(value);
777
+ formControl ? formControl.setValue(valueDecimal) : setValueInput(value);
778
+ onValue?.(valueDecimal);
779
+ }, [formControl, onValue]);
780
+ const decimalProps = { ...props, formControl: undefined };
781
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: "rls-input-decimal", children: jsxRuntimeExports.jsx(RlsInput, { ...decimalProps, type: "number", value: valueInput, onValue: onValueInput, children: jsxRuntimeExports.jsx(RlsAmount, { value: amount, symbol: symbol, decimals: decimals }) }) }));
782
+ }
783
+
784
+ function RlsInputMoney(props) {
785
+ const { decimals, formControl, identifier, onValue, symbol, value } = props;
786
+ const [valueInput, setValueInput] = useState(formControl?.value ?? value ?? 0);
787
+ const onValueInput = useCallback((value) => {
788
+ !formControl && setValueInput(value);
789
+ onValue?.(value);
790
+ }, [formControl, onValue]);
791
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: "rls-input-money", children: jsxRuntimeExports.jsx(RlsInput, { ...props, type: "number", value: valueInput, onValue: onValueInput, children: jsxRuntimeExports.jsx(RlsAmount, { value: formControl?.value ?? valueInput, symbol: symbol, decimals: decimals }) }) }));
792
+ }
793
+
794
+ function RlsInputNumber(props) {
795
+ const { formControl, identifier, onValue, value } = props;
796
+ const [valueInput, setValueInput] = useState(formControl?.value ?? value ?? 0);
797
+ const onValueInput = useCallback((value) => {
798
+ !formControl && setValueInput(value);
799
+ onValue?.(value);
800
+ }, [formControl, onValue]);
801
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: "rls-input-number", children: jsxRuntimeExports.jsx(RlsInput, { ...props, type: "number", value: valueInput, onValue: onValueInput, children: formControl?.value ?? valueInput }) }));
802
+ }
803
+
804
+ function RlsInputPassword({ disabled, formControl, identifier, onEnter, onKeyDown, onKeyUp, onValue, placeholder, readOnly, type }) {
805
+ const [focused, setFocused] = useState(false);
806
+ const _onChange = useCallback((event) => {
807
+ formControl?.setValue(event.target.value);
808
+ onValue?.(event.target.value);
809
+ }, [formControl, onValue]);
810
+ const _onKeyDown = useCallback((event) => {
811
+ onKeyDown?.(event);
812
+ event.key === 'Enter' && onEnter?.();
813
+ }, [onKeyDown, onEnter]);
814
+ const _onKeyUp = useCallback((event) => {
815
+ onKeyUp?.(event);
816
+ }, [onKeyUp]);
817
+ const _onFocus = useCallback(() => {
818
+ formControl?.focus();
819
+ setFocused(() => true);
820
+ }, [formControl]);
821
+ const _onBlur = useCallback(() => {
822
+ formControl?.blur();
823
+ setFocused(() => false);
824
+ }, [formControl]);
825
+ const className = useMemo(() => {
826
+ return renderClassStatus('rls-input-password', {
827
+ disabled: formControl?.disabled || disabled,
828
+ focused: formControl?.focused ?? focused
829
+ });
830
+ }, [formControl?.focused, formControl?.disabled, focused, disabled]);
831
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: className, children: jsxRuntimeExports.jsx("input", { className: "rls-input-password__component", autoComplete: "off", type: type ?? 'password', placeholder: placeholder, disabled: disabled, readOnly: readOnly, onFocus: _onFocus, onBlur: _onBlur, onChange: _onChange, onKeyDown: _onKeyDown, onKeyUp: _onKeyUp }) }));
832
+ }
833
+
834
+ function RlsInputPercentage(props) {
835
+ const { formControl, identifier, onValue, value } = props;
836
+ const [valueInput, setValueInput] = useState(formControl?.value ?? value ?? 0);
837
+ const onValueInput = useCallback((value) => {
838
+ !formControl && setValueInput(value);
839
+ onValue?.(value);
840
+ }, [formControl, onValue]);
841
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: "rls-input-percentage", children: jsxRuntimeExports.jsxs(RlsInput, { ...props, type: "number", value: valueInput, onValue: onValueInput, children: [formControl?.value ?? valueInput, "%"] }) }));
842
+ }
843
+
844
+ function RlsInputSearch({ formControl, disabled, identifier, onEnter, onSearch, placeholder }) {
845
+ const [value, setValue] = useState('');
846
+ const className = useMemo(() => {
847
+ return renderClassStatus('rls-input-search', { disabled });
848
+ }, [disabled]);
849
+ const onValue = useCallback((value) => {
850
+ !formControl && setValue(() => value);
851
+ }, [formControl]);
852
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, children: [jsxRuntimeExports.jsx(RlsInput, { formControl: formControl, placeholder: placeholder, onEnter: onEnter, onValue: onValue, disabled: disabled, children: formControl?.value ?? value }), onSearch && (jsxRuntimeExports.jsx(RlsButtonAction, { icon: "search", onClick: onSearch, disabled: disabled }))] }));
853
+ }
854
+
855
+ function RlsInputText(props) {
856
+ const { formControl, identifier, onValue, value } = props;
857
+ const [valueInput, setValueInput] = useState(formControl?.value ?? value ?? '');
858
+ const onValueInput = useCallback((value) => {
859
+ !formControl && setValueInput(value);
860
+ onValue?.(value);
861
+ }, [formControl, onValue]);
862
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: "rls-input-text", children: jsxRuntimeExports.jsx(RlsInput, { ...props, type: "text", value: valueInput, onValue: onValueInput, children: formControl?.value ?? valueInput }) }));
863
+ }
864
+
865
+ function RlsLabel({ children, rlsTheme }) {
866
+ return (jsxRuntimeExports.jsx("span", { className: "rls-label", "rls-theme": rlsTheme, children: children }));
867
+ }
868
+
869
+ function msgInvalidColor(color) {
870
+ return `Invalid color: "${color}". Use format "#FF6600".`;
871
+ }
872
+ function clamp(value, min, max) {
873
+ return Math.min(max, Math.max(min, value));
874
+ }
875
+ function computeHue(max, r, g, b, d) {
876
+ if (d === 0) {
877
+ return 0;
878
+ }
879
+ switch (max) {
880
+ case r:
881
+ return ((g - b) / d + (g < b ? 6 : 0)) / 6;
882
+ case g:
883
+ return ((b - r) / d + 2) / 6;
884
+ case b:
885
+ return ((r - g) / d + 4) / 6;
886
+ default:
887
+ return 0;
888
+ }
889
+ }
890
+ function hsvToRgb({ h, s, v }) {
891
+ const _h = h / 360;
892
+ const _s = s / 100;
893
+ const _v = v / 100;
894
+ const i = Math.floor(_h * 6);
895
+ const f = _h * 6 - i;
896
+ const p = _v * (1 - _s);
897
+ const q = _v * (1 - f * _s);
898
+ const t = _v * (1 - (1 - f) * _s);
899
+ let r;
900
+ let g;
901
+ let b;
902
+ switch (i % 6) {
903
+ case 0:
904
+ r = _v;
905
+ g = t;
906
+ b = p;
907
+ break;
908
+ case 1:
909
+ r = q;
910
+ g = _v;
911
+ b = p;
912
+ break;
913
+ case 2:
914
+ r = p;
915
+ g = _v;
916
+ b = t;
917
+ break;
918
+ case 3:
919
+ r = p;
920
+ g = q;
921
+ b = _v;
922
+ break;
923
+ case 4:
924
+ r = t;
925
+ g = p;
926
+ b = _v;
927
+ break;
928
+ case 5:
929
+ r = _v;
930
+ g = p;
931
+ b = q;
932
+ break;
933
+ default:
934
+ r = 0;
935
+ g = 0;
936
+ b = 0;
937
+ }
938
+ return {
939
+ r: Math.round(r * 255),
940
+ g: Math.round(g * 255),
941
+ b: Math.round(b * 255)
942
+ };
943
+ }
944
+ function rgbToHsv({ r, g, b }) {
945
+ const _r = r / 255;
946
+ const _g = g / 255;
947
+ const _b = b / 255;
948
+ const max = Math.max(_r, _g, _b);
949
+ const min = Math.min(_r, _g, _b);
950
+ const d = max - min;
951
+ const s = max === 0 ? 0 : d / max;
952
+ const v = max;
953
+ const h = computeHue(max, _r, _g, _b, d);
954
+ return {
955
+ h: Math.round(h * 360),
956
+ s: Math.round(s * 100),
957
+ v: Math.round(v * 100)
958
+ };
959
+ }
960
+ function rgbToHex({ r, g, b }) {
961
+ const toHex = (channel) => clamp(Math.round(channel), 0, 255).toString(16).padStart(2, '0');
962
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`.toUpperCase();
963
+ }
964
+ function hexToRgb(hex) {
965
+ const normalized = normalizeHex(hex);
966
+ if (!normalized) {
967
+ return null;
968
+ }
969
+ return {
970
+ r: parseInt(normalized.slice(1, 3), 16),
971
+ g: parseInt(normalized.slice(3, 5), 16),
972
+ b: parseInt(normalized.slice(5, 7), 16)
973
+ };
974
+ }
975
+ function hexToHsv(hex) {
976
+ const rgb = hexToRgb(hex);
977
+ return rgb ? rgbToHsv(rgb) : null;
978
+ }
979
+ function hsvToHex(hsv) {
980
+ return rgbToHex(hsvToRgb(hsv));
981
+ }
982
+ function hexIsValid(hex) {
983
+ return /^#?([a-f\d]{3}){1,2}$/i.test(hex);
984
+ }
985
+ function normalizeHex(hex) {
986
+ let value = hex.replace(/[^a-fA-F\d]/g, '');
987
+ if (value.length === 3) {
988
+ value = value
989
+ .split('')
990
+ .map((c) => c + c)
991
+ .join('');
992
+ }
993
+ return value.length === 6 ? `#${value.toUpperCase()}` : '';
994
+ }
995
+ function hslToHex({ h, s, l }) {
996
+ const _s = s / 100;
997
+ const _l = l / 100;
998
+ const a = _s * Math.min(_l, 1 - _l);
999
+ const f = (n) => {
1000
+ const k = (n + h / 30) % 12;
1001
+ return clamp(Math.round(255 * (_l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1))), 0, 255)
1002
+ .toString(16)
1003
+ .padStart(2, '0');
1004
+ };
1005
+ return `#${f(0)}${f(8)}${f(4)}`.toUpperCase();
1006
+ }
1007
+ function rgbToHsl({ r, g, b }) {
1008
+ const _r = r / 255;
1009
+ const _g = g / 255;
1010
+ const _b = b / 255;
1011
+ const max = Math.max(_r, _g, _b);
1012
+ const min = Math.min(_r, _g, _b);
1013
+ const d = max - min;
1014
+ const l = (max + min) / 2;
1015
+ const s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1));
1016
+ const h = computeHue(max, _r, _g, _b, d);
1017
+ return {
1018
+ h: Math.round(h * 360),
1019
+ s: Math.round(s * 100),
1020
+ l: Math.round(l * 100)
1021
+ };
1022
+ }
1023
+ function hexToHsl(hex) {
1024
+ const rgb = hexToRgb(hex);
1025
+ return rgb ? rgbToHsl(rgb) : null;
1026
+ }
1027
+ const SHADE_LABELS = [
1028
+ '950',
1029
+ '900',
1030
+ '800',
1031
+ '700',
1032
+ '600',
1033
+ '500',
1034
+ '400',
1035
+ '300',
1036
+ '200',
1037
+ '100',
1038
+ '050'
1039
+ ];
1040
+ /**
1041
+ * Target perceptual lightness (OKLab L, expressed as a 0–100 percentage) for
1042
+ * each shade level. OKLab lightness is perceptually uniform, so equal numeric
1043
+ * steps look like equal visual steps regardless of hue.
1044
+ */
1045
+ const STANDARD_LUMINANCE = {
1046
+ '950': 16,
1047
+ '900': 24,
1048
+ '800': 28,
1049
+ '700': 33,
1050
+ '600': 40,
1051
+ '500': 48,
1052
+ '400': 58,
1053
+ '300': 72,
1054
+ '200': 84,
1055
+ '100': 92,
1056
+ '050': 97
1057
+ };
1058
+ const SKELETON_OPACITY = {
1059
+ '500': 0.5,
1060
+ '400': 0.325,
1061
+ '300': 0.25,
1062
+ '200': 0.175,
1063
+ '100': 0.1
1064
+ };
1065
+ const GRADIENT_LABELS = ['700', '600', '500', '400', '300'];
1066
+ const BACKDROP_LABELS = [
1067
+ '900',
1068
+ '800',
1069
+ '700',
1070
+ '600',
1071
+ '500',
1072
+ '400',
1073
+ '300',
1074
+ '200',
1075
+ '100'
1076
+ ];
1077
+ function parseHex(color) {
1078
+ const rgb = hexToRgb(color);
1079
+ if (!rgb) {
1080
+ throw new Error(msgInvalidColor(color));
1081
+ }
1082
+ return rgb;
1083
+ }
1084
+ function rgbChannels({ r, g, b }) {
1085
+ return `${r}, ${g}, ${b}`;
1086
+ }
1087
+ function generateThemeCSS(colors, theme) {
1088
+ const prop = (suffix, value) => ({
1089
+ name: `--rls-${theme}-${suffix}`,
1090
+ value
1091
+ });
1092
+ const rgb900 = rgbChannels(parseHex(colors['900']));
1093
+ const rgb700 = rgbChannels(parseHex(colors['700']));
1094
+ const rgb500 = rgbChannels(parseHex(colors['500']));
1095
+ const colorProps = SHADE_LABELS.map((label) => prop(`color-${label}`, colors[label]));
1096
+ const gradientProps = GRADIENT_LABELS.map((label) => {
1097
+ const darker = SHADE_LABELS[SHADE_LABELS.indexOf(label) - 1];
1098
+ return prop(`gradient-${label}`, `linear-gradient(180deg, ${colors[label]} 15%, ${colors[darker]} 85%)`);
1099
+ });
1100
+ const backdropProps = BACKDROP_LABELS.map((label) => prop(`backdrop-${label}`, `rgba(${rgb900}, ${Number(label) / 1000})`));
1101
+ const skeletonProps = Object.entries(SKELETON_OPACITY).map(([label, opacity]) => prop(`skeleton-${label}`, `rgba(${rgb700}, ${opacity})`));
1102
+ const shadowProps = [
1103
+ prop('shadow-color-500', `rgba(${rgb500}, 0.24)`),
1104
+ prop('shadow-500', `0px 0px 0px 3px rgba(${rgb500}, 0.24)`)
1105
+ ];
1106
+ return [
1107
+ ...colorProps,
1108
+ ...gradientProps,
1109
+ ...backdropProps,
1110
+ ...skeletonProps,
1111
+ ...shadowProps
1112
+ ];
1113
+ }
1114
+ const srgbToLinear = (channel) => {
1115
+ const x = channel / 255;
1116
+ return x <= 0.04045 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;
1117
+ };
1118
+ const linearToSrgb = (channel) => {
1119
+ const v = channel <= 0.0031308
1120
+ ? 12.92 * channel
1121
+ : 1.055 * channel ** (1 / 2.4) - 0.055;
1122
+ return clamp(Math.round(v * 255), 0, 255);
1123
+ };
1124
+ function rgbToOklch({ r, g, b }) {
1125
+ const lr = srgbToLinear(r);
1126
+ const lg = srgbToLinear(g);
1127
+ const lb = srgbToLinear(b);
1128
+ const l = Math.cbrt(0.4122214708 * lr + 0.5363325363 * lg + 0.0514459929 * lb);
1129
+ const m = Math.cbrt(0.2119034982 * lr + 0.6806995451 * lg + 0.1073969566 * lb);
1130
+ const s = Math.cbrt(0.0883024619 * lr + 0.2817188376 * lg + 0.6299787005 * lb);
1131
+ const okL = 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
1132
+ const okA = 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s;
1133
+ const okB = 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s;
1134
+ return { l: okL, c: Math.hypot(okA, okB), h: Math.atan2(okB, okA) };
1135
+ }
1136
+ function oklabToLinearRgb(l, a, b) {
1137
+ const l_ = (l + 0.3963377774 * a + 0.2158037573 * b) ** 3;
1138
+ const m_ = (l - 0.1055613458 * a - 0.0638541728 * b) ** 3;
1139
+ const s_ = (l - 0.0894841775 * a - 1.291485548 * b) ** 3;
1140
+ return [
1141
+ 4.0767416621 * l_ - 3.3077115913 * m_ + 0.2309699292 * s_,
1142
+ -1.2684380046 * l_ + 2.6097574011 * m_ - 0.3413193965 * s_,
1143
+ -0.0041960863 * l_ - 0.7034186147 * m_ + 1.707614701 * s_
1144
+ ];
1145
+ }
1146
+ const inGamut = ([r, g, b]) => {
1147
+ const e = 1e-4;
1148
+ return (r >= -e && r <= 1 + e && g >= -e && g <= 1 + e && b >= -e && b <= 1 + e);
1149
+ };
1150
+ function oklchToRgb({ l, c, h }) {
1151
+ const a = Math.cos(h);
1152
+ const b = Math.sin(h);
1153
+ const linearAt = (chroma) => oklabToLinearRgb(l, a * chroma, b * chroma);
1154
+ if (!inGamut(linearAt(c))) {
1155
+ let lo = 0;
1156
+ let hi = c;
1157
+ for (let i = 0; i < 20; i++) {
1158
+ const mid = (lo + hi) / 2;
1159
+ if (inGamut(linearAt(mid))) {
1160
+ lo = mid;
1161
+ }
1162
+ else {
1163
+ hi = mid;
1164
+ }
1165
+ }
1166
+ c = lo;
1167
+ }
1168
+ const [lr, lg, lb] = linearAt(c);
1169
+ return { r: linearToSrgb(lr), g: linearToSrgb(lg), b: linearToSrgb(lb) };
1170
+ }
1171
+ const chromaFactor = (lightness) => 0.4 + 0.6 * (1 - Math.abs(lightness - 0.5) * 2);
1172
+ function detectShadeLevel(lightness) {
1173
+ let bestLevel = '500';
1174
+ let minDiff = Infinity;
1175
+ SHADE_LABELS.forEach((level) => {
1176
+ const diff = Math.abs(lightness - STANDARD_LUMINANCE[level]);
1177
+ if (diff < minDiff) {
1178
+ minDiff = diff;
1179
+ bestLevel = level;
1180
+ }
1181
+ });
1182
+ return bestLevel;
1183
+ }
1184
+ function generateThemePalette(baseColor, theme = 'primary') {
1185
+ const rgb = hexToRgb(baseColor);
1186
+ if (!rgb) {
1187
+ throw new Error(msgInvalidColor(baseColor));
1188
+ }
1189
+ const base = rgbToOklch(rgb);
1190
+ const matchedLevel = detectShadeLevel(base.l * 100);
1191
+ const colors = {};
1192
+ SHADE_LABELS.forEach((label) => {
1193
+ if (label === matchedLevel) {
1194
+ colors[label] = rgbToHex(rgb); // preserve the base color exactly
1195
+ return;
1196
+ }
1197
+ const lightness = STANDARD_LUMINANCE[label] / 100;
1198
+ colors[label] = rgbToHex(oklchToRgb({
1199
+ l: lightness,
1200
+ c: base.c * chromaFactor(lightness),
1201
+ h: base.h
1202
+ }));
1203
+ });
1204
+ const properties = generateThemeCSS(colors, theme);
1205
+ return {
1206
+ theme,
1207
+ colors,
1208
+ css: properties.map((p) => `${p.name}: ${p.value};`).join('\n'),
1209
+ properties
1210
+ };
1211
+ }
1212
+ function setThemeColor(baseColor, theme = 'primary') {
1213
+ if (typeof document === 'undefined') {
1214
+ return;
1215
+ }
1216
+ const { properties } = generateThemePalette(baseColor, theme);
1217
+ const target = document.body || document.documentElement;
1218
+ properties.forEach(({ name, value }) => {
1219
+ target.style.setProperty(name, value);
1220
+ });
1221
+ }
1222
+ const DEFAULT_COLOR = '#1780e0';
1223
+
1224
+ const CONTENT_BACKGROUND = '--pvt-content-background';
1225
+ function RlsLed({ color, rlsTheme }) {
1226
+ const refLed = useRef(null);
1227
+ const refColor = useRef(undefined);
1228
+ useEffect(() => {
1229
+ if (color && hexIsValid(color)) {
1230
+ refColor.current = normalizeHex(color);
1231
+ refLed.current?.style.setProperty(CONTENT_BACKGROUND, refColor.current);
1232
+ }
1233
+ else if (refColor.current) {
1234
+ refColor.current = undefined;
1235
+ refLed.current?.style.setProperty(CONTENT_BACKGROUND, 'var(--rls-app-color-500)');
1236
+ }
1237
+ }, [color]);
1238
+ return jsxRuntimeExports.jsx("div", { ref: refLed, className: "rls-led", "rls-theme": rlsTheme });
1239
+ }
1240
+
1241
+ function RlsMessageIcon({ icon, children, rlsTheme }) {
1242
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-message-icon", "rls-theme": rlsTheme, children: [icon && jsxRuntimeExports.jsx(RlsIcon, { value: icon }), jsxRuntimeExports.jsx("span", { className: "truncate", children: children })] }));
1243
+ }
1244
+
1245
+ function RlsPoster({ children, contrasted, rlsTheme }) {
1246
+ const className = useMemo(() => {
1247
+ return renderClassStatus('rls-poster', { contrasted });
1248
+ }, [contrasted]);
1249
+ return (jsxRuntimeExports.jsx("div", { className: className, "rls-theme": rlsTheme, children: children }));
1250
+ }
1251
+
1252
+ function RlsProgressBar({ indeterminate, percentage, rlsTheme }) {
1253
+ const className = useMemo(() => {
1254
+ return renderClassStatus('rls-progress-bar', { indeterminate });
1255
+ }, [indeterminate]);
1256
+ return (jsxRuntimeExports.jsx("div", { className: className, "rls-theme": rlsTheme, children: jsxRuntimeExports.jsx("div", { className: "rls-progress-bar__component", style: { width: `${percentage ?? 0}%` } }) }));
1257
+ }
1258
+
1259
+ function RlsProgressCircular({ rlsTheme }) {
1260
+ return (jsxRuntimeExports.jsx("div", { className: "rls-progress-circular", "rls-theme": rlsTheme, children: jsxRuntimeExports.jsx("svg", { className: "rls-progress-circular__svg", viewBox: "0 0 36 36", children: jsxRuntimeExports.jsx("circle", { className: "rls-progress-circular__circle", cx: "18", cy: "18", r: "12" }) }) }));
1261
+ }
1262
+
1263
+ function RlsRadioButton({ checked, disabled, identifier, rlsTheme, onClick }) {
1264
+ const className = useMemo(() => {
1265
+ return renderClassStatus('rls-radiobutton', { checked, disabled });
1266
+ }, [checked, disabled]);
1267
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: className, onClick: onClick, "rls-theme": rlsTheme, children: jsxRuntimeExports.jsx("div", { className: "rls-radiobutton__component" }) }));
1268
+ }
1269
+
1270
+ function RlsSkeletonText({ active, children, rlsTheme }) {
1271
+ return (jsxRuntimeExports.jsx("div", { className: "rls-skeleton-text", "rls-theme": rlsTheme, children: active ? (jsxRuntimeExports.jsx(RlsSkeleton, {})) : (jsxRuntimeExports.jsx("div", { className: "rls-skeleton-text__value", children: children })) }));
1272
+ }
1273
+
1274
+ function RlsSwitch({ checked, capsule, disabled, identifier, onClick, rlsTheme }) {
1275
+ const className = useMemo(() => {
1276
+ return renderClassStatus('rls-switch', { checked, capsule, disabled });
1277
+ }, [checked, capsule, disabled]);
1278
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: className, onClick: onClick, "rls-theme": rlsTheme, children: jsxRuntimeExports.jsx("div", { className: "rls-switch__component", children: jsxRuntimeExports.jsx("div", { className: "rls-switch__component__element" }) }) }));
1279
+ }
1280
+ function RlsSwitchControl({ formControl, disabled, identifier, rlsTheme }) {
1281
+ const onClick = useCallback(() => {
1282
+ formControl.setValue(!formControl.value);
1283
+ }, [formControl.value]);
1284
+ return (jsxRuntimeExports.jsx(RlsSwitch, { identifier: identifier, checked: formControl.value, disabled: disabled, onClick: onClick, rlsTheme: rlsTheme }));
1285
+ }
1286
+
1287
+ function RlsAccordion({ bordered, children, className, disabled, identifier, onToggle, opened, rlsTheme, title }) {
1288
+ const [open, setOpen] = useState(opened);
1289
+ const [animating, setAnimating] = useState(false);
1290
+ const contentRef = useRef(null);
1291
+ const initializedRef = useRef(false);
1292
+ const classNameAccordion = useMemo(() => {
1293
+ return renderClassStatus('rls-accordion', { bordered, disabled, open, animating }, className);
1294
+ }, [animating, bordered, className, disabled, open]);
1295
+ const onClickHeader = useCallback(() => {
1296
+ if (!disabled) {
1297
+ setOpen((current) => {
1298
+ const next = !current;
1299
+ onToggle?.(next);
1300
+ return next;
1301
+ });
1302
+ }
1303
+ }, [disabled, onToggle]);
1304
+ useEffect(() => {
1305
+ const element = contentRef.current;
1306
+ if (!element) {
1307
+ return;
1308
+ }
1309
+ if (!initializedRef.current) {
1310
+ initializedRef.current = true;
1311
+ element.style.height = open ? 'auto' : '0px';
1312
+ return;
1313
+ }
1314
+ setAnimating(true);
1315
+ if (open) {
1316
+ const target = element.scrollHeight;
1317
+ element.style.height = '0px';
1318
+ requestAnimationFrame(() => {
1319
+ element.style.height = `${target}px`;
1320
+ });
1321
+ }
1322
+ else {
1323
+ element.style.height = `${element.scrollHeight}px`;
1324
+ requestAnimationFrame(() => {
1325
+ element.style.height = '0px';
1326
+ });
1327
+ }
1328
+ }, [open]);
1329
+ const onTransitionEnd = useCallback((event) => {
1330
+ if (event.propertyName === 'height') {
1331
+ const element = contentRef.current;
1332
+ if (element && open) {
1333
+ element.style.height = 'auto';
1334
+ }
1335
+ setAnimating(false);
1336
+ }
1337
+ }, [open]);
1338
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: classNameAccordion, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("button", { type: "button", className: "rls-accordion__header", "aria-expanded": open, disabled: disabled, onClick: onClickHeader, children: [jsxRuntimeExports.jsx("span", { className: "rls-accordion__title", children: title }), jsxRuntimeExports.jsx("span", { className: "rls-accordion__indicator", children: jsxRuntimeExports.jsx(RlsIcon, { value: "chevron-down" }) })] }), jsxRuntimeExports.jsx("div", { ref: contentRef, className: "rls-accordion__body", "aria-hidden": !open, onTransitionEnd: onTransitionEnd, children: jsxRuntimeExports.jsx("div", { className: "rls-accordion__content", children: children }) })] }));
1339
+ }
1340
+
1341
+ function RlsAlert({ bordered, children, icon, identifier, rlsTheme }) {
1342
+ const className = useMemo(() => {
1343
+ return renderClassStatus('rls-alert', { bordered });
1344
+ }, [bordered]);
1345
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [icon && (jsxRuntimeExports.jsx("div", { className: "rls-alert__icon", children: jsxRuntimeExports.jsx(RlsIcon, { value: icon }) })), jsxRuntimeExports.jsx("div", { className: "rls-alert__content", children: children })] }));
1346
+ }
1347
+
1348
+ function RlsBallot({ bordered, className, children, img, initials, skeleton, subtitle, rlsTheme }) {
1349
+ const classNameBallot = useMemo(() => {
1350
+ return renderClassStatus('rls-ballot', { bordered, skeleton }, className);
1351
+ }, [bordered, skeleton, className]);
1352
+ return (jsxRuntimeExports.jsxs("div", { className: classNameBallot, "rls-theme": rlsTheme, children: [(img || initials) && (jsxRuntimeExports.jsxs(RlsAvatar, { skeleton: skeleton, children: [img && jsxRuntimeExports.jsx("img", { src: img }), initials && jsxRuntimeExports.jsx("span", { children: initials })] })), jsxRuntimeExports.jsxs("div", { className: "rls-ballot__component", children: [jsxRuntimeExports.jsx("div", { className: "rls-ballot__title", children: jsxRuntimeExports.jsx(RlsSkeletonText, { active: skeleton, children: children }) }), subtitle && (jsxRuntimeExports.jsx("div", { className: "rls-ballot__subtitle", children: jsxRuntimeExports.jsx(RlsSkeletonText, { active: skeleton, children: subtitle }) }))] })] }));
1353
+ }
1354
+
1355
+ function RlsBody({ children, identifier, rlsTheme }) {
1356
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: "rls-app__page__body", "rls-theme": rlsTheme, children: children }));
1357
+ }
1358
+
1359
+ function RlsButtonProgress({ icon, disabled, onClick, progressing, rlsTheme }) {
1360
+ const className = useMemo(() => {
1361
+ return renderClassStatus('rls-button-progress', { progressing });
1362
+ }, [progressing]);
1363
+ return (jsxRuntimeExports.jsxs("div", { className: className, "rls-theme": rlsTheme, children: [!progressing && (jsxRuntimeExports.jsx(RlsButtonAction, { icon: icon, onClick: onClick, disabled: disabled })), progressing && jsxRuntimeExports.jsx(RlsProgressCircular, {})] }));
1364
+ }
1365
+
1366
+ function RlsButtonStepper({ disabled, onAction, rlsTheme }) {
1367
+ const onDown = useCallback(() => {
1368
+ onAction?.('down');
1369
+ }, [onAction]);
1370
+ const onUp = useCallback(() => {
1371
+ onAction?.('up');
1372
+ }, [onAction]);
1373
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-button-stepper", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx(RlsButtonIcon, { icon: "arrow-ios-down", disabled: disabled, onClick: onDown }), jsxRuntimeExports.jsx(RlsButtonIcon, { icon: "arrow-ios-up", disabled: disabled, onClick: onUp })] }));
1374
+ }
1375
+
1376
+ function RlsButtonToggle({ onAction, options, type, automatic, disabled, rlsTheme }) {
1377
+ const componentRef = useRef(null);
1378
+ const [action, setAction] = useState(options[0]);
1379
+ const [visible, setVisible] = useState(false);
1380
+ useEffect(() => {
1381
+ function onCloseMenu({ target }) {
1382
+ !componentRef?.current?.contains(target) && setVisible(false);
1383
+ }
1384
+ document.addEventListener('click', onCloseMenu);
1385
+ return () => {
1386
+ document.removeEventListener('click', onCloseMenu);
1387
+ };
1388
+ }, []);
1389
+ const classNameList = useMemo(() => {
1390
+ return renderClassStatus('rls-button-toggle__list', {
1391
+ hide: !visible,
1392
+ visible
1393
+ });
1394
+ }, [visible]);
1395
+ const onClickMenu = useCallback(() => {
1396
+ setVisible((visible) => !visible);
1397
+ }, []);
1398
+ const onSelectAction = useCallback((action) => {
1399
+ setAction(() => action);
1400
+ setVisible(() => false);
1401
+ automatic && onAction(action.value);
1402
+ }, [onAction, automatic]);
1403
+ const onClickAction = useCallback(() => {
1404
+ action && onAction(action.value);
1405
+ }, [action, onAction]);
1406
+ const onClickOption = useCallback((event) => {
1407
+ const index = Number(event.currentTarget.dataset.index);
1408
+ const option = options[index];
1409
+ option && onSelectAction(option);
1410
+ }, [options, onSelectAction]);
1411
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-button-toggle", ref: componentRef, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: "rls-button-toggle__content", children: [action && (jsxRuntimeExports.jsx("div", { className: "rls-button-toggle__action", children: jsxRuntimeExports.jsx(RlsButton, { disabled: disabled, type: type, onClick: onClickAction, children: action.label }) })), jsxRuntimeExports.jsx("div", { className: "rls-button-toggle__icon", children: jsxRuntimeExports.jsx(RlsButton, { type: type, prefixIcon: "arrow-ios-down", disabled: disabled, onClick: onClickMenu }) })] }), jsxRuntimeExports.jsx("div", { className: classNameList, children: jsxRuntimeExports.jsx("ul", { children: options.map((action, index) => (jsxRuntimeExports.jsx("li", { className: "rls-truncate", "data-index": index, onClick: onClickOption, children: action.label }, index))) }) })] }));
1412
+ }
1413
+
1414
+ function RlsContent({ children, identifier, rlsTheme }) {
1415
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: "rls-app__page__content", "rls-theme": rlsTheme, children: children }));
1416
+ }
1417
+
1418
+ const errors = {
1419
+ es: {
1420
+ alphabetic: 'Campo solo permite caracteres',
1421
+ alphanumber: 'Campo solo permite caracteres y número',
1422
+ checked: 'Campo debe ser seleccionado',
1423
+ decimal: 'Campo debe ser número decimal',
1424
+ defined: 'Campo debe estar definido',
1425
+ email: 'Campo debe ser correo electrónico',
1426
+ greaterThanValue: 'Campo debe tener un valor mayor a {thanValue}',
1427
+ greaterOrEqualsThanValue: 'Campo debe tener un valor mayor o igual a {thanValue}',
1428
+ lessThanValue: 'Campo debe tener un valor menor a {thanValue}',
1429
+ lessOrEqualsThanValue: 'Campo debe tener un valor menor o igual a {thanValue}',
1430
+ maxValue: 'Campo debe tener un valor máximo de {thanValue}',
1431
+ minValue: 'Campo debe tener un valor mínimo de {thanValue}',
1432
+ nickname: 'Campo inválido para nombre de usuario',
1433
+ onlyNumber: 'Campo debe ser númerico',
1434
+ password: 'Campo no permitido para password',
1435
+ required: 'Campo es requerido',
1436
+ strMinlength: 'Campo debe tener mínimo {length} caracter(es)',
1437
+ strMaxlength: 'Campo debe tener máximo {length} caracter(es)',
1438
+ strReqLength: 'Campo debe tener {length} caracter(es)',
1439
+ textonly: 'Campo solo permite caracteres (sin espacio)',
1440
+ _unknown: 'Campo inválido {error}'
1441
+ },
1442
+ en: {
1443
+ alphabetic: 'Field only allows characters',
1444
+ alphanumber: 'Field only allows characters and number',
1445
+ checked: 'Field must be selected',
1446
+ decimal: 'Field must be decimal number',
1447
+ defined: 'Field must be defined',
1448
+ email: 'Field must be email',
1449
+ greaterThanValue: 'Field must have a value greater than {thanValue}',
1450
+ greaterOrEqualsThanValue: 'Field must have a value greater than or equal to {thanValue}',
1451
+ lessThanValue: 'Field must have a value less than {thanValue}',
1452
+ lessOrEqualsThanValue: 'Field must have a value less than or equal to {thanValue}',
1453
+ minValue: 'Field must have a minimum value of {thanValue}',
1454
+ maxValue: 'Field must have a maximum value of {thanValue}',
1455
+ nickname: 'Invalid field for username',
1456
+ onlyNumber: 'Field must be numeric',
1457
+ password: 'Field not allowed for password',
1458
+ strReqLength: 'Field must be {length} characters',
1459
+ required: 'Field is required',
1460
+ strMinlength: 'Field must have minimum {length} characters',
1461
+ strMaxlength: 'Field must have maximum {length} characters',
1462
+ textonly: 'Field only allows characters (no space)',
1463
+ _unknown: 'Invalid field {error}'
1464
+ },
1465
+ fr: {
1466
+ alphabetic: 'Field only allows characters',
1467
+ alphanumber: 'Field only allows characters and number',
1468
+ checked: 'Field must be selected',
1469
+ decimal: 'Field must be decimal number',
1470
+ defined: 'Field must be defined',
1471
+ email: 'Field must be email',
1472
+ greaterThanValue: 'Field must have a value greater than {thanValue}',
1473
+ greaterOrEqualsThanValue: 'Field must have a value greater than or equal to {thanValue}',
1474
+ lessThanValue: 'Field must have a value less than {thanValue}',
1475
+ lessOrEqualsThanValue: 'Field must have a value less than or equal to {thanValue}',
1476
+ minValue: 'Field must have a minimum value of {thanValue}',
1477
+ maxValue: 'Field must have a maximum value of {thanValue}',
1478
+ nickname: 'Invalid field for username',
1479
+ onlyNumber: 'Field must be numeric',
1480
+ password: 'Field not allowed for password',
1481
+ strReqLength: 'Field must be {length} characters',
1482
+ required: 'Field is required',
1483
+ strMinlength: 'Field must have minimum {length} characters',
1484
+ strMaxlength: 'Field must have maximum {length} characters',
1485
+ textonly: 'Field only allows characters (no space)',
1486
+ _unknown: 'Invalid field {error}'
1487
+ },
1488
+ pt: {
1489
+ alphabetic: 'Field only allows characters',
1490
+ alphanumber: 'Field only allows characters and number',
1491
+ checked: 'Field must be selected',
1492
+ decimal: 'Field must be decimal number',
1493
+ defined: 'Field must be defined',
1494
+ email: 'Field must be email',
1495
+ greaterThanValue: 'Field must have a value greater than {thanValue}',
1496
+ greaterOrEqualsThanValue: 'Field must have a value greater than or equal to {thanValue}',
1497
+ lessThanValue: 'Field must have a value less than {thanValue}',
1498
+ lessOrEqualsThanValue: 'Field must have a value less than or equal to {thanValue}',
1499
+ minValue: 'Field must have a minimum value of {thanValue}',
1500
+ maxValue: 'Field must have a maximum value of {thanValue}',
1501
+ nickname: 'Invalid field for username',
1502
+ onlyNumber: 'Field must be numeric',
1503
+ password: 'Field not allowed for password',
1504
+ strReqLength: 'Field must be {length} characters',
1505
+ required: 'Field is required',
1506
+ strMinlength: 'Field must have minimum {length} characters',
1507
+ strMaxlength: 'Field must have maximum {length} characters',
1508
+ textonly: 'Field only allows characters (no space)',
1509
+ _unknown: 'Invalid field {error}'
1510
+ }
1511
+ };
1512
+ let _msgErrorsI18n = i18n(errors);
1513
+ function setErrorsI18n(dictionary) {
1514
+ _msgErrorsI18n = i18n(Object.entries(errors).reduce((errors, [key, value]) => {
1515
+ // Merge keys from dictionary in errors i18n
1516
+ errors[key] = {
1517
+ ...value,
1518
+ ...dictionary[key]
1519
+ };
1520
+ return errors;
1521
+ }, {}));
1522
+ }
1523
+ function msgErrorsI18n(key, language, interpolators) {
1524
+ return _msgErrorsI18n(key, { language, interpolators });
1525
+ }
1526
+
1527
+ function RlsMessageFormError({ className, formControl }) {
1528
+ const [language, setLanguage] = useState('es');
1529
+ useEffect(() => {
1530
+ return i18nSubscribe((language) => {
1531
+ setLanguage(language);
1532
+ });
1533
+ }, []);
1534
+ const msgError = useMemo(() => {
1535
+ return (formControl?.error &&
1536
+ (msgErrorsI18n(formControl.error.id, language, formControl.error.data) ||
1537
+ msgErrorsI18n('_unknown', language, { error: formControl.error.id })));
1538
+ }, [formControl?.error, language]);
1539
+ return (jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: formControl?.wrong && (jsxRuntimeExports.jsx("div", { className: className, children: jsxRuntimeExports.jsx(RlsMessageIcon, { icon: "alert-triangle", rlsTheme: "danger", children: msgError }) })) }));
1540
+ }
1541
+
1542
+ function RlsFieldDecimal(props) {
1543
+ const { children, formControl, identifier, rlsTheme } = props;
1544
+ const disabled = useMemo(() => {
1545
+ return formControl?.disabled || props.disabled;
1546
+ }, [formControl?.disabled, props.disabled]);
1547
+ const className = useMemo(() => {
1548
+ return renderClassStatus('rls-field-box', {
1549
+ disabled,
1550
+ error: formControl?.wrong,
1551
+ focused: formControl?.focused && !disabled,
1552
+ readonly: props.readOnly
1553
+ }, 'rls-field-decimal');
1554
+ }, [formControl?.focused, formControl?.wrong, props.readOnly, disabled]);
1555
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsx("div", { className: "rls-field-box__body", children: jsxRuntimeExports.jsx(RlsInputDecimal, { ...props }) }) }), !props.msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }));
1556
+ }
1557
+
1558
+ function RlsFieldArea(props) {
1559
+ const { children, formControl, identifier, rlsTheme } = props;
1560
+ const disabled = useMemo(() => {
1561
+ return formControl?.disabled || props.disabled;
1562
+ }, [formControl?.disabled, props.disabled]);
1563
+ const className = useMemo(() => {
1564
+ return renderClassStatus('rls-field-box', {
1565
+ disabled,
1566
+ error: formControl?.wrong,
1567
+ focused: formControl?.focused && !disabled,
1568
+ readonly: props.readOnly
1569
+ }, 'rls-field-area');
1570
+ }, [formControl?.focused, formControl?.wrong, props.readOnly, disabled]);
1571
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsx("div", { className: "rls-field-box__body", children: jsxRuntimeExports.jsx(RlsAreaText, { ...props }) }) }), !props.msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }));
1572
+ }
1573
+
1574
+ function RlsFieldFile({ accept, children, disabled: _disabled, formControl, identifier, msgErrorDisabled, onValue, placeholder, readOnly, rlsTheme, value }) {
1575
+ const inputRef = useRef(null);
1576
+ const disabled = useMemo(() => formControl?.disabled || _disabled, [formControl?.disabled, _disabled]);
1577
+ const className = useMemo(() => renderClassStatus('rls-field-box', {
1578
+ disabled,
1579
+ error: formControl?.wrong,
1580
+ focused: formControl?.focused && !disabled,
1581
+ readonly: readOnly
1582
+ }, 'rls-field-file'), [formControl?.focused, formControl?.wrong, readOnly, disabled]);
1583
+ const currentFile = useMemo(() => formControl?.value ?? value, [formControl?.value, value]);
1584
+ const displayValue = useMemo(() => {
1585
+ return currentFile?.name ?? '';
1586
+ }, [currentFile]);
1587
+ const onClickAction = useCallback((event) => {
1588
+ if (currentFile) {
1589
+ formControl?.setValue(undefined);
1590
+ onValue?.(undefined);
1591
+ }
1592
+ else {
1593
+ inputRef.current?.click();
1594
+ }
1595
+ event.stopPropagation();
1596
+ }, [currentFile, formControl, onValue]);
1597
+ const onChangeInput = useCallback((event) => {
1598
+ const file = event.target.files?.[0];
1599
+ if (file) {
1600
+ formControl?.setValue(file);
1601
+ onValue?.(file);
1602
+ }
1603
+ event.target.value = '';
1604
+ }, [formControl, onValue]);
1605
+ const onClickControl = useCallback(() => {
1606
+ !readOnly && !disabled && inputRef.current?.click();
1607
+ }, [readOnly, disabled]);
1608
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", onClick: onClickControl, children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { className: "rls-input__component", readOnly: true, type: "text", value: displayValue, placeholder: placeholder }), jsxRuntimeExports.jsx("input", { ref: inputRef, className: "rls-field-file__input", type: "file", accept: accept, disabled: disabled || readOnly, onChange: onChangeInput }), jsxRuntimeExports.jsx(RlsButtonAction, { icon: currentFile ? 'close' : 'attach', disabled: disabled, onClick: onClickAction })] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }));
1609
+ }
1610
+
1611
+ const reactI18n = i18n({
1612
+ es: {
1613
+ confirmationActionApproved: 'Aceptar',
1614
+ dateActionCancel: 'Cancelar',
1615
+ dateActionSelect: 'Establecer',
1616
+ dateActionToday: 'Hoy',
1617
+ chooserImageActionCancel: 'Cancelar',
1618
+ editorImageActionRestore: 'Restaurar',
1619
+ editorImageActionSelect: 'Seleccionar',
1620
+ listEmptyDescription: 'Lo sentimos, en el momento no hay elementos en el listado',
1621
+ listEmptyTitle: 'Selección no disponible',
1622
+ listInputPlaceholder: 'Escriba palabre clave para filtrar...'
1623
+ },
1624
+ en: {
1625
+ confirmationActionApproved: 'Approved',
1626
+ dateActionCancel: 'Cancel',
1627
+ dateActionSelect: 'Select',
1628
+ dateActionToday: 'Today',
1629
+ chooserImageActionCancel: 'Cancel',
1630
+ editorImageActionRestore: 'Restore',
1631
+ editorImageActionSelect: 'Select',
1632
+ listEmptyDescription: 'Sorry, there are currently no items in the list',
1633
+ listEmptyTitle: 'Selection not available',
1634
+ listInputPlaceholder: 'Enter keyword to filter...'
1635
+ }
1636
+ });
1637
+
1638
+ function RlsFieldListLi({ element, onClickElement, onKeydownElement, render }) {
1639
+ const onClick = useMemo(() => {
1640
+ return onClickElement(element);
1641
+ }, [element, onClickElement]);
1642
+ const onKeyDown = useMemo(() => {
1643
+ return onKeydownElement(element);
1644
+ }, [element, onKeydownElement]);
1645
+ return (jsxRuntimeExports.jsx("li", { className: "rls-field-list__element", tabIndex: -1, onClick: onClick, onKeyDown: onKeyDown, children: render(element) }));
1646
+ }
1647
+ function RlsFieldListSuggestions({ elements, action, disabled, higher, render, renderEmpty, searchControl, visible, onClickBackdrop, onClickElement, onKeydownElement, refList, rlsTheme }) {
1648
+ const [labels, setLabels] = useState({
1649
+ listEmptyDescription: reactI18n('listEmptyDescription'),
1650
+ listEmptyTitle: reactI18n('listEmptyTitle')
1651
+ });
1652
+ useEffect(() => {
1653
+ return i18nSubscribe(() => {
1654
+ setLabels({
1655
+ listEmptyDescription: reactI18n('listEmptyDescription'),
1656
+ listEmptyTitle: reactI18n('listEmptyTitle')
1657
+ });
1658
+ });
1659
+ }, []);
1660
+ const className = useMemo(() => {
1661
+ return renderClassStatus('rls-field-list__suggestions', {
1662
+ disabled,
1663
+ higher,
1664
+ visible
1665
+ });
1666
+ }, [disabled, higher, visible]);
1667
+ const onChangePattern = useCallback((event) => {
1668
+ searchControl?.onChange(event.target.value);
1669
+ }, [searchControl?.onChange]);
1670
+ const onClickAction = useCallback((event) => {
1671
+ action?.onClick();
1672
+ if (!action?.keepOpen) {
1673
+ onClickBackdrop(event);
1674
+ }
1675
+ }, [action?.onClick, action?.keepOpen, onClickBackdrop]);
1676
+ const searching = searchControl?.searching ?? false;
1677
+ return (jsxRuntimeExports.jsxs("div", { className: className, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: "rls-field-list__suggestions__body", children: [jsxRuntimeExports.jsxs("ul", { ref: refList, className: "rls-field-list__ul", children: [searchControl && (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__ul__search", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-list__ul__control", ref: searchControl.refInput, type: "text", placeholder: searchControl.placeholder, value: searchControl.pattern, onChange: onChangePattern, onFocus: searchControl.onFocus, onBlur: searchControl.onBlur, onKeyDown: searchControl.onKeyDown, disabled: disabled || searching }), searchControl.onSearch && (jsxRuntimeExports.jsx("button", { disabled: disabled || searching, onClick: searchControl.onSearch, children: jsxRuntimeExports.jsx(RlsIcon, { value: "search" }) }))] })), searching && jsxRuntimeExports.jsx(RlsProgressBar, { indeterminate: true }), elements.map((element, index) => (jsxRuntimeExports.jsx(RlsFieldListLi, { element: element, onClickElement: onClickElement, onKeydownElement: onKeydownElement, render: render }, index))), !elements.length && (jsxRuntimeExports.jsx("li", { className: "rls-field-list__empty", children: renderEmpty ? (renderEmpty()) : (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__empty__description", children: [jsxRuntimeExports.jsx("span", { className: "rls-label-font-bold rls-truncate", children: labels.listEmptyTitle }), jsxRuntimeExports.jsx("p", { className: "rls-caption-font-regular", children: labels.listEmptyDescription })] })) }))] }), action && (jsxRuntimeExports.jsx("div", { className: "rls-field-list__action", children: jsxRuntimeExports.jsxs("button", { type: "button", disabled: disabled || action.disabled, onClick: onClickAction, children: [action.icon && jsxRuntimeExports.jsx(RlsIcon, { value: action.icon }), jsxRuntimeExports.jsx("span", { className: "rls-field-list__action__description", children: action.description })] }) }))] }), jsxRuntimeExports.jsx("div", { className: "rls-field-list__backdrop", onClick: onClickBackdrop })] }));
1678
+ }
1679
+
1680
+ function RlsFieldMoney(props) {
1681
+ const { children, formControl, identifier, rlsTheme } = props;
1682
+ const disabled = useMemo(() => {
1683
+ return formControl?.disabled || props.disabled;
1684
+ }, [formControl?.disabled, props.disabled]);
1685
+ const className = useMemo(() => {
1686
+ return renderClassStatus('rls-field-box', {
1687
+ disabled,
1688
+ error: formControl?.wrong,
1689
+ focused: formControl?.focused && !disabled,
1690
+ readonly: props.readOnly
1691
+ }, 'rls-field-money');
1692
+ }, [formControl?.focused, formControl?.wrong, props.readOnly, disabled]);
1693
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsx("div", { className: "rls-field-box__body", children: jsxRuntimeExports.jsx(RlsInputMoney, { ...props }) }) }), !props.msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }));
1694
+ }
1695
+
1696
+ function RlsFieldNumber(props) {
1697
+ const { children, formControl, identifier, rlsTheme } = props;
1698
+ const disabled = useMemo(() => {
1699
+ return formControl?.disabled || props.disabled;
1700
+ }, [formControl?.disabled, props.disabled]);
1701
+ const className = useMemo(() => {
1702
+ return renderClassStatus('rls-field-box', {
1703
+ disabled,
1704
+ error: formControl?.wrong,
1705
+ focused: formControl?.focused && !disabled,
1706
+ readonly: props.readOnly
1707
+ }, 'rls-field-number');
1708
+ }, [formControl?.focused, formControl?.wrong, props.readOnly, disabled]);
1709
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsx("div", { className: "rls-field-box__body", children: jsxRuntimeExports.jsx(RlsInputNumber, { ...props }) }) }), !props.msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }));
1710
+ }
1711
+
1712
+ function RlsFieldPassword(props) {
1713
+ const { children, formControl, identifier, rlsTheme } = props;
1714
+ const [passwordIsActive, setPasswordIsActive] = useState(true);
1715
+ const disabled = useMemo(() => {
1716
+ return formControl?.disabled || props.disabled;
1717
+ }, [formControl?.disabled, props.disabled]);
1718
+ const className = useMemo(() => {
1719
+ return renderClassStatus('rls-field-box', {
1720
+ disabled,
1721
+ error: formControl?.wrong,
1722
+ focused: formControl?.focused && !disabled,
1723
+ readonly: props.readOnly
1724
+ }, 'rls-field-password');
1725
+ }, [formControl?.focused, formControl?.wrong, props.readOnly, disabled]);
1726
+ const onTogglePassword = useCallback(() => {
1727
+ setPasswordIsActive((password) => !password);
1728
+ }, []);
1729
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx(RlsInputPassword, { ...props, type: passwordIsActive ? 'password' : 'text' }), jsxRuntimeExports.jsx(RlsButtonAction, { icon: passwordIsActive ? 'eye' : 'eye-off', onClick: onTogglePassword })] }) }), !props.msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }));
1730
+ }
1731
+
1732
+ function RlsFieldPercentage(props) {
1733
+ const { children, formControl, identifier, rlsTheme } = props;
1734
+ const disabled = useMemo(() => {
1735
+ return formControl?.disabled || props.disabled;
1736
+ }, [formControl?.disabled, props.disabled]);
1737
+ const className = useMemo(() => {
1738
+ return renderClassStatus('rls-field-box', {
1739
+ disabled,
1740
+ error: formControl?.wrong,
1741
+ focused: formControl?.focused && !disabled,
1742
+ readonly: props.readOnly
1743
+ }, 'rls-field-percentage');
1744
+ }, [formControl?.focused, formControl?.wrong, props.readOnly, disabled]);
1745
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsx("div", { className: "rls-field-box__body", children: jsxRuntimeExports.jsx(RlsInputPercentage, { ...props }) }) }), !props.msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }));
1746
+ }
1747
+
1748
+ function RlsFieldReadonly({ children, identifier, rlsTheme, value }) {
1749
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: "rls-field-readonly rls-field-box", "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsx("div", { className: "rls-field-box__body", children: jsxRuntimeExports.jsx("input", { className: "rls-input__component", autoComplete: "off", type: 'text', readOnly: true, value: value }) }) })] }));
1750
+ }
1751
+
1752
+ function RlsFieldText(props) {
1753
+ const { children, formControl, identifier, rlsTheme } = props;
1754
+ const disabled = useMemo(() => {
1755
+ return formControl?.disabled || props.disabled;
1756
+ }, [formControl?.disabled, props.disabled]);
1757
+ const className = useMemo(() => {
1758
+ return renderClassStatus('rls-field-box', {
1759
+ disabled,
1760
+ error: formControl?.wrong,
1761
+ focused: formControl?.focused && !disabled,
1762
+ readonly: props.readOnly
1763
+ }, 'rls-field-text');
1764
+ }, [formControl?.focused, formControl?.wrong, props.readOnly, disabled]);
1765
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsx("div", { className: "rls-field-box__body", children: jsxRuntimeExports.jsx(RlsInputText, { ...props }) }) }), !props.msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }));
1766
+ }
1767
+
1768
+ function useFormToggleController({ disabled, formControl }) {
1769
+ const [checked, setChecked] = useState(!!formControl?.value);
1770
+ useEffect(() => {
1771
+ setChecked(!!formControl?.value);
1772
+ }, [formControl?.value]);
1773
+ const onToggle = useCallback(() => {
1774
+ if (!disabled) {
1775
+ formControl
1776
+ ? formControl.enabled && formControl.setValue(!formControl.value)
1777
+ : setChecked((checked) => !checked);
1778
+ }
1779
+ }, [formControl, disabled]);
1780
+ return { checked, onToggle };
1781
+ }
1782
+
1783
+ function RlsLabelCheckBox({ children, disabled, extended, identifier, formControl, reverse, rlsTheme }) {
1784
+ const { checked, onToggle } = useFormToggleController({
1785
+ disabled,
1786
+ formControl
1787
+ });
1788
+ const className = useMemo(() => {
1789
+ return renderClassStatus('rls-label-checkbox', {
1790
+ disabled,
1791
+ extended,
1792
+ reverse
1793
+ });
1794
+ }, [disabled, extended, reverse]);
1795
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-label-checkbox__component", onClick: onToggle, children: jsxRuntimeExports.jsx(RlsCheckBox, { checked: checked, disabled: disabled }) }), jsxRuntimeExports.jsx("div", { className: "rls-label-checkbox__text", children: children })] }));
1796
+ }
1797
+
1798
+ function RlsLabelRadioButton({ children, disabled, extended, identifier, formControl, onValue, reverse, rlsTheme, value }) {
1799
+ const { checked, onSelect } = useFormSingleSelectionController({
1800
+ disabled,
1801
+ formControl,
1802
+ onValue,
1803
+ value
1804
+ });
1805
+ const className = useMemo(() => {
1806
+ return renderClassStatus('rls-label-radiobutton', {
1807
+ disabled,
1808
+ extended,
1809
+ reverse
1810
+ });
1811
+ }, [disabled, extended, reverse]);
1812
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-label-radiobutton__component", onClick: onSelect, children: jsxRuntimeExports.jsx(RlsRadioButton, { checked: checked, disabled: disabled }) }), jsxRuntimeExports.jsx("div", { className: "rls-label-radiobutton__text", children: children })] }));
1813
+ }
1814
+
1815
+ function RlsLabelSwitch({ capsule, children, disabled, extended, identifier, formControl, reverse, rlsTheme }) {
1816
+ const { checked, onToggle } = useFormToggleController({
1817
+ disabled,
1818
+ formControl
1819
+ });
1820
+ const className = useMemo(() => {
1821
+ return renderClassStatus('rls-label-switch', {
1822
+ disabled,
1823
+ extended,
1824
+ reverse
1825
+ });
1826
+ }, [disabled, extended, reverse]);
1827
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-label-switch__component", onClick: onToggle, children: jsxRuntimeExports.jsx(RlsSwitch, { checked: checked, capsule: capsule, disabled: disabled }) }), jsxRuntimeExports.jsx("div", { className: "rls-label-switch__text", children: children })] }));
1828
+ }
1829
+
1830
+ function RlsMessageEmpty({ children, className, emoji, icon, identifier, image, rlsTheme, title }) {
1831
+ const classNameMessageEmpty = useMemo(() => {
1832
+ return renderClassStatus('rls-message-empty', {}, className);
1833
+ }, [className]);
1834
+ const logo = useMemo(() => {
1835
+ if (icon) {
1836
+ return (jsxRuntimeExports.jsx("div", { className: "rls-message-empty__logo", children: jsxRuntimeExports.jsx(RlsIcon, { value: icon }) }));
1837
+ }
1838
+ if (emoji) {
1839
+ return (jsxRuntimeExports.jsx("div", { className: "rls-message-empty__logo", children: jsxRuntimeExports.jsx("span", { className: "rls-message-empty__logo--emoji", children: emoji }) }));
1840
+ }
1841
+ if (image) {
1842
+ return (jsxRuntimeExports.jsx("div", { className: "rls-message-empty__logo", children: jsxRuntimeExports.jsx("img", { className: "rls-message-empty__logo--image", src: image }) }));
1843
+ }
1844
+ return null;
1845
+ }, [icon, emoji, image]);
1846
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: classNameMessageEmpty, "rls-theme": rlsTheme, children: [logo, jsxRuntimeExports.jsxs("div", { className: "rls-message-empty__body", children: [title && jsxRuntimeExports.jsx("div", { className: "rls-message-empty__title", children: title }), children && (jsxRuntimeExports.jsx("div", { className: "rls-message-empty__content", children: children }))] })] }));
1847
+ }
1848
+
1849
+ function RlsNavbar({ children, identifier, rlsTheme }) {
1850
+ return (jsxRuntimeExports.jsxs("nav", { id: identifier, className: "rls-app__page__nav", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-app__page__nav__content", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-app__page__nav__backdrop" })] }));
1851
+ }
1852
+
1853
+ function RlsNavbarMenuOption({ option, onOption }) {
1854
+ const onClick = useCallback(() => {
1855
+ onOption?.(option);
1856
+ }, [onOption]);
1857
+ return (jsxRuntimeExports.jsxs("li", { className: "rls-app__page__nav__option", onClick: onClick, children: [jsxRuntimeExports.jsx(RlsIcon, { value: option.icon }), jsxRuntimeExports.jsx("span", { className: "rls-label-font", children: option.label })] }));
1858
+ }
1859
+ function RlsNavbarMenu({ options, onOption }) {
1860
+ return (jsxRuntimeExports.jsx("ul", { className: "rls-app__page__nav__menu", children: options.map((option) => (jsxRuntimeExports.jsx(RlsNavbarMenuOption, { option: option, onOption: onOption }, option.id))) }));
1861
+ }
1862
+
1863
+ function PageButton({ page, onSelect }) {
1864
+ const className = useMemo(() => renderClassStatus('rls-pagination__page', { active: page.active }), [page.active]);
1865
+ const onClick = useCallback(() => {
1866
+ onSelect(page);
1867
+ }, [page, onSelect]);
1868
+ return (jsxRuntimeExports.jsx("button", { type: "button", className: className, onClick: onClick, children: page.label }));
1869
+ }
1870
+ function RlsPagination({ suggestions, count, filter, onPagination }) {
1871
+ const [template, setTemplate] = useState();
1872
+ const controller = useRef(undefined);
1873
+ const refreshTemplate = useCallback((template, suggestions) => {
1874
+ const { firstPage, lastPage } = template;
1875
+ onPagination?.({ firstPage, lastPage, suggestions });
1876
+ setTemplate(template);
1877
+ }, [onPagination]);
1878
+ const refreshPagination = useCallback((pagination) => {
1879
+ pagination &&
1880
+ refreshTemplate(pagination.template, pagination.page.collection);
1881
+ }, [refreshTemplate]);
1882
+ useEffect(() => {
1883
+ const pagination = new PaginationController({
1884
+ suggestions,
1885
+ count,
1886
+ position: template?.currentPage.value
1887
+ });
1888
+ controller.current = pagination;
1889
+ refreshTemplate(pagination.template, pagination.page.collection);
1890
+ }, [suggestions, count, refreshTemplate]);
1891
+ useEffect(() => {
1892
+ refreshPagination(controller.current?.filtrable(filter));
1893
+ }, [filter, refreshPagination]);
1894
+ const goToPagination = useCallback((page) => {
1895
+ refreshPagination(controller.current?.goToPage(page));
1896
+ }, [refreshPagination]);
1897
+ const goFirstPagination = useCallback(() => {
1898
+ refreshPagination(controller.current?.goFirstPage());
1899
+ }, [refreshPagination]);
1900
+ const goPreviousPagination = useCallback(() => {
1901
+ refreshPagination(controller.current?.goPreviousPage());
1902
+ }, [refreshPagination]);
1903
+ const goNextPagination = useCallback(() => {
1904
+ refreshPagination(controller.current?.goNextPage());
1905
+ }, [refreshPagination]);
1906
+ const goLastPagination = useCallback(() => {
1907
+ refreshPagination(controller.current?.goLastPage());
1908
+ }, [refreshPagination]);
1909
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-pagination", children: [jsxRuntimeExports.jsxs("div", { className: "rls-pagination__actions", children: [jsxRuntimeExports.jsx("button", { className: "rls-pagination__action", onClick: goFirstPagination, disabled: template?.firstPage, children: jsxRuntimeExports.jsx(RlsIcon, { value: "arrowhead-left" }) }), jsxRuntimeExports.jsx("button", { className: "rls-pagination__action", onClick: goPreviousPagination, disabled: template?.firstPage, children: jsxRuntimeExports.jsx(RlsIcon, { value: "arrow-ios-left" }) })] }), jsxRuntimeExports.jsxs("div", { className: "rls-pagination__body", children: [jsxRuntimeExports.jsx("div", { className: "rls-pagination__pages", children: template?.pages.map((page) => (jsxRuntimeExports.jsx(PageButton, { page: page, onSelect: goToPagination }, page.value))) }), jsxRuntimeExports.jsx("div", { className: "rls-pagination__description", children: template?.description }), jsxRuntimeExports.jsx("span", { className: "rls-pagination__count", children: suggestions.length })] }), jsxRuntimeExports.jsxs("div", { className: "rls-pagination__actions", children: [jsxRuntimeExports.jsx("button", { className: "rls-pagination__action", onClick: goNextPagination, disabled: template?.lastPage, children: jsxRuntimeExports.jsx(RlsIcon, { value: "arrow-ios-right" }) }), jsxRuntimeExports.jsx("button", { className: "rls-pagination__action", onClick: goLastPagination, disabled: template?.lastPage, children: jsxRuntimeExports.jsx(RlsIcon, { value: "arrowhead-right" }) })] })] }));
1910
+ }
1911
+
1912
+ function RlsPickerDayHeaders() {
1913
+ return (jsxRuntimeExports.jsx("div", { className: "rls-picker-day__header", children: DAY_LABELS().map((title, index) => (jsxRuntimeExports.jsx("span", { className: "rls-picker-day__label", children: title }, index))) }));
1914
+ }
1915
+ function RlsPickerDayElement({ day, onSelect, disabled }) {
1916
+ const className = useMemo(() => {
1917
+ return renderClassStatus('rls-picker-day__element', {
1918
+ disabled: day.disabled || disabled,
1919
+ focused: day.focused,
1920
+ forbidden: day.forbidden,
1921
+ selected: day.selected,
1922
+ today: day.today
1923
+ });
1924
+ }, [day, disabled]);
1925
+ const onClick = useCallback(() => {
1926
+ day.value && !day.disabled && !disabled && onSelect(day.value);
1927
+ }, [day.value, day.disabled, disabled, onSelect]);
1928
+ return (jsxRuntimeExports.jsx("div", { className: className, onClick: onClick, children: jsxRuntimeExports.jsx("span", { className: "rls-picker-day__element__span", children: day.value || '??' }) }));
1929
+ }
1930
+ function RlsPickerDay({ date, disabled, formControl, maxDate, month, minDate, onValue, rlsTheme, year }) {
1931
+ const dateDay = useMemo(() => date ?? new Date(), [date]);
1932
+ const [weeks, setWeeks] = useState([]);
1933
+ const [value, setValue] = useState(formControl?.value ?? dateDay.getDate());
1934
+ const [_, setI18nVersion] = useState(0);
1935
+ const setDayValue = useCallback((value) => {
1936
+ formControl ? formControl.setValue(value) : setValue(value);
1937
+ }, [formControl]);
1938
+ const onSelect = useCallback((value) => {
1939
+ setDayValue(value);
1940
+ onValue?.(value);
1941
+ }, [setDayValue, onValue]);
1942
+ useEffect(() => {
1943
+ return i18nSubscribe(() => {
1944
+ setI18nVersion((value) => value + 1);
1945
+ });
1946
+ }, []);
1947
+ useEffect(() => {
1948
+ const options = createPickerOptions();
1949
+ const day = verifyDayPicker(options);
1950
+ day ? setDayValue(day) : setWeeks(createDayPicker(options));
1951
+ }, [dateDay, month, year, value, minDate, maxDate]);
1952
+ useEffect(() => {
1953
+ const day = verifyDayPicker(createPickerOptions());
1954
+ day
1955
+ ? formControl?.setValue(day)
1956
+ : setValue(formControl?.value || dateDay.getDate());
1957
+ }, [formControl?.value]);
1958
+ const createPickerOptions = useCallback(() => {
1959
+ return {
1960
+ date: dateDay,
1961
+ day: formControl?.value ?? value,
1962
+ month: month ?? dateDay.getMonth(),
1963
+ year: year ?? dateDay.getFullYear(),
1964
+ minDate,
1965
+ maxDate
1966
+ };
1967
+ }, [dateDay, formControl?.value, value, month, year, minDate, maxDate]);
1968
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-picker-day", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx(RlsPickerDayHeaders, {}), jsxRuntimeExports.jsx("div", { className: "rls-picker-day__component", children: weeks.map(({ days }, index) => (jsxRuntimeExports.jsx("div", { className: "rls-picker-day__week", children: days.map((day, index) => (jsxRuntimeExports.jsx(RlsPickerDayElement, { day: day, onSelect: onSelect, disabled: disabled }, index))) }, index))) })] }));
1969
+ }
1970
+
1971
+ function RlsPickerDayRangeHeaders() {
1972
+ return (jsxRuntimeExports.jsx("div", { className: "rls-picker-day__header", children: DAY_LABELS().map((title, index) => (jsxRuntimeExports.jsx("span", { className: "rls-picker-day__label", children: title }, index))) }));
1973
+ }
1974
+ function RlsPickerDayRangeElement({ day, onSelect, disabled }) {
1975
+ const className = useMemo(() => {
1976
+ return renderClassStatus('rls-picker-day-range__element', {
1977
+ disabled: day.disabled || disabled,
1978
+ end: day.end,
1979
+ forbidden: day.forbidden,
1980
+ ranged: day.ranged,
1981
+ source: day.source
1982
+ });
1983
+ }, [day.disabled, day.end, day.forbidden, day.ranged, day.source, disabled]);
1984
+ const onClick = useCallback(() => {
1985
+ day.value && !day.disabled && !disabled && onSelect(day.value);
1986
+ }, [day.value, day.disabled, disabled, onSelect]);
1987
+ return (jsxRuntimeExports.jsx("div", { className: className, onClick: onClick, children: jsxRuntimeExports.jsx("span", { className: "rls-picker-day-range__element__span", children: day.value || '??' }) }));
1988
+ }
1989
+ function RlsPickerDayRange({ date, disabled, formControl, maxDate, minDate, rlsTheme }) {
1990
+ const rangeDay = useMemo(() => {
1991
+ return formControl?.value ?? DateRange.now();
1992
+ }, [formControl?.value]);
1993
+ const dateDayRange = useMemo(() => {
1994
+ return normalizeMinTime(date ?? rangeDay.minDate);
1995
+ }, [date, rangeDay]);
1996
+ const sourceDate = useRef(rangeDay.minDate);
1997
+ const [weeks, setWeeks] = useState([]);
1998
+ const [range, setRange] = useState(rangeDay);
1999
+ const [_, setI18nVersion] = useState(0);
2000
+ const onSelect = useCallback((value) => {
2001
+ const date = assignDayInDate(dateDayRange, value);
2002
+ const range = dateIsBefore(date, sourceDate.current)
2003
+ ? new DateRange(sourceDate.current, date)
2004
+ : new DateRange(date, sourceDate.current);
2005
+ sourceDate.current = date;
2006
+ setRange(range);
2007
+ formControl?.setValue(range);
2008
+ }, [dateDayRange, formControl]);
2009
+ useEffect(() => {
2010
+ return i18nSubscribe(() => {
2011
+ setI18nVersion((value) => value + 1);
2012
+ });
2013
+ }, []);
2014
+ useEffect(() => {
2015
+ setWeeks(createDayRangePicker({
2016
+ date: dateDayRange,
2017
+ range,
2018
+ sourceDate: sourceDate.current,
2019
+ minDate,
2020
+ maxDate
2021
+ }));
2022
+ }, [dateDayRange, range, minDate, maxDate]);
2023
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-picker-day-range", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx(RlsPickerDayRangeHeaders, {}), jsxRuntimeExports.jsx("div", { className: "rls-picker-day-range__component", children: weeks.map(({ days }, index) => (jsxRuntimeExports.jsx("div", { className: "rls-picker-day-range__week", children: days.map((day, index) => (jsxRuntimeExports.jsx(RlsPickerDayRangeElement, { day: day, onSelect: onSelect, disabled: disabled }, index))) }, index))) })] }));
2024
+ }
2025
+
2026
+ function RlsPickerMonthElement({ month, onSelect, disabled }) {
2027
+ const [label, setLabel] = useState(MONTH_NAMES(month.value));
2028
+ useEffect(() => {
2029
+ return i18nSubscribe(() => {
2030
+ setLabel(MONTH_NAMES(month.value));
2031
+ });
2032
+ }, []);
2033
+ const className = useMemo(() => {
2034
+ return renderClassStatus('rls-picker-month__component', {
2035
+ disabled: month.disabled || disabled,
2036
+ focused: month.focused,
2037
+ selected: month.selected
2038
+ });
2039
+ }, [month.disabled, month.focused, month.selected, disabled]);
2040
+ const onClick = useCallback(() => {
2041
+ valueIsDefined(month.value) &&
2042
+ !month.disabled &&
2043
+ !disabled &&
2044
+ onSelect(month.value);
2045
+ }, [month.value, month.disabled, disabled, onSelect]);
2046
+ return (jsxRuntimeExports.jsx("div", { className: className, onClick: onClick, children: jsxRuntimeExports.jsx("span", { className: "rls-picker-month__span", children: label }) }));
2047
+ }
2048
+ function RlsPickerMonth({ date, disabled, formControl, maxDate, minDate, onValue, rlsTheme, year }) {
2049
+ const dateMonth = useMemo(() => date ?? new Date(), [date]);
2050
+ const [months, setMonths] = useState([]);
2051
+ const [value, setValue] = useState(formControl?.value ?? dateMonth.getMonth());
2052
+ const setMonthValue = useCallback((value) => {
2053
+ formControl ? formControl.setValue(value) : setValue(value);
2054
+ }, [formControl]);
2055
+ const onSelect = useCallback((value) => {
2056
+ setMonthValue(value);
2057
+ onValue?.(value);
2058
+ }, [setMonthValue, onValue]);
2059
+ useEffect(() => {
2060
+ const options = {
2061
+ date: dateMonth,
2062
+ month: formControl?.value ?? value,
2063
+ year: year ?? dateMonth.getFullYear(),
2064
+ minDate,
2065
+ maxDate
2066
+ };
2067
+ const month = verifyMonthPicker(options);
2068
+ valueIsDefined(month)
2069
+ ? setMonthValue(month)
2070
+ : setMonths(createMonthPicker(options));
2071
+ }, [dateMonth, year, value, minDate, maxDate]);
2072
+ useEffect(() => {
2073
+ const month = verifyMonthPicker({
2074
+ date: dateMonth,
2075
+ month: formControl?.value ?? value,
2076
+ year: year ?? dateMonth.getFullYear(),
2077
+ minDate,
2078
+ maxDate
2079
+ });
2080
+ valueIsDefined(month)
2081
+ ? formControl?.setValue(month)
2082
+ : setValue(formControl?.value ?? dateMonth.getMonth());
2083
+ }, [formControl?.value]);
2084
+ return (jsxRuntimeExports.jsx("div", { className: "rls-picker-month", "rls-theme": rlsTheme, children: months.map((month, index) => (jsxRuntimeExports.jsx(RlsPickerMonthElement, { month: month, onSelect: onSelect, disabled: disabled }, index))) }));
2085
+ }
2086
+
2087
+ function RlsPickerSelectorTitle({ monthControl, type, yearControl, date, disabled, maxDate, minDate, onClick }) {
2088
+ const { limitNext, limitPrevious } = useMemo(() => {
2089
+ return monthLimitTemplate({
2090
+ date,
2091
+ maxDate,
2092
+ minDate,
2093
+ month: monthControl.value
2094
+ });
2095
+ }, [date, maxDate, minDate, monthControl.value]);
2096
+ const [label, setLabel] = useState(MONTH_NAMES(monthControl.value ?? Month.January));
2097
+ useEffect(() => {
2098
+ return i18nSubscribe(() => {
2099
+ setLabel(MONTH_NAMES(monthControl.value ?? Month.January));
2100
+ });
2101
+ }, []);
2102
+ useEffect(() => {
2103
+ setLabel(MONTH_NAMES(monthControl.value ?? Month.January));
2104
+ }, [monthControl.value]);
2105
+ const onPreviousMonth = useCallback(() => {
2106
+ if (valueIsDefined(monthControl.value) &&
2107
+ valueIsDefined(yearControl.value)) {
2108
+ if (monthControl.value > Month.January) {
2109
+ monthControl.setValue(monthControl.value - 1);
2110
+ }
2111
+ else {
2112
+ monthControl.setValue(Month.December);
2113
+ yearControl.setValue(yearControl.value - 1);
2114
+ }
2115
+ }
2116
+ }, [monthControl.value, yearControl.value]);
2117
+ const onMonth = useCallback(() => {
2118
+ onClick?.('month');
2119
+ }, [onClick]);
2120
+ const onYear = useCallback(() => {
2121
+ onClick?.('year');
2122
+ }, [onClick]);
2123
+ const onPreviousYear = useCallback(() => {
2124
+ valueIsDefined(yearControl.value) &&
2125
+ yearControl.setValue(yearControl.value - 1);
2126
+ }, [yearControl.value]);
2127
+ const onPrevious = useCallback(() => {
2128
+ type === 'month' ? onPreviousMonth() : onPreviousYear();
2129
+ }, [type, onPreviousMonth, onPreviousYear]);
2130
+ const onNextMonth = useCallback(() => {
2131
+ if (valueIsDefined(monthControl.value) &&
2132
+ valueIsDefined(yearControl.value)) {
2133
+ if (monthControl.value < Month.December) {
2134
+ monthControl.setValue(monthControl.value + 1);
2135
+ }
2136
+ else {
2137
+ monthControl.setValue(Month.January);
2138
+ yearControl.setValue(yearControl.value + 1);
2139
+ }
2140
+ }
2141
+ }, [monthControl.value, yearControl.value]);
2142
+ const onNextYear = useCallback(() => {
2143
+ valueIsDefined(yearControl.value) &&
2144
+ yearControl.setValue(yearControl.value + 1);
2145
+ }, [yearControl.value]);
2146
+ const onNext = useCallback(() => {
2147
+ type === 'month' ? onNextMonth() : onNextYear();
2148
+ }, [type, onNextMonth, onNextYear]);
2149
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-picker-selector-title", children: [jsxRuntimeExports.jsx(RlsButtonIcon, { icon: "arrow-ios-left", onClick: onPrevious, disabled: limitPrevious || disabled }), jsxRuntimeExports.jsxs("div", { className: "rls-picker-selector-title__label", children: [jsxRuntimeExports.jsxs("span", { onClick: onMonth, children: [label, ","] }), jsxRuntimeExports.jsx("span", { onClick: onYear, children: yearControl.value })] }), jsxRuntimeExports.jsx(RlsButtonIcon, { icon: "arrow-ios-right", onClick: onNext, disabled: limitNext || disabled })] }));
2150
+ }
2151
+
2152
+ function RlsPickerYearElement({ onSelect, year, disabled }) {
2153
+ const className = useMemo(() => {
2154
+ return renderClassStatus('rls-picker-year__element', {
2155
+ disabled: year.disabled || disabled,
2156
+ focused: year.focused,
2157
+ selected: year.selected
2158
+ });
2159
+ }, [year.disabled, year.focused, year.selected, disabled]);
2160
+ const onClick = useCallback(() => {
2161
+ year.value && !year.disabled && !disabled && onSelect(year.value);
2162
+ }, [year.value, year.disabled, disabled, onSelect]);
2163
+ return (jsxRuntimeExports.jsx("div", { className: className, onClick: onClick, children: jsxRuntimeExports.jsx("span", { className: "rls-picker-year__span", children: year.value || '????' }) }));
2164
+ }
2165
+ function RlsPickerYear({ date, disabled, formControl, maxDate, minDate, onValue, rlsTheme }) {
2166
+ const dateYear = useMemo(() => date ?? new Date(), [date]);
2167
+ const [year, setYear] = useState(formControl?.value ?? dateYear.getFullYear());
2168
+ const createPickerOptions = useCallback(() => {
2169
+ return {
2170
+ date: dateYear,
2171
+ year,
2172
+ minDate,
2173
+ maxDate
2174
+ };
2175
+ }, [dateYear, year, minDate, maxDate]);
2176
+ const [template, setTemplate] = useState(createYearPicker(createPickerOptions()));
2177
+ useEffect(() => {
2178
+ const options = createPickerOptions();
2179
+ const validYear = verifyYearPicker(options);
2180
+ validYear ? setYear(validYear) : setTemplate(createYearPicker(options));
2181
+ }, [dateYear, year, minDate, maxDate]);
2182
+ useEffect(() => {
2183
+ const yearValue = formControl?.value;
2184
+ valueIsDefined(yearValue) && yearValue !== year && setYear(yearValue);
2185
+ }, [formControl?.value]);
2186
+ const onSelect = useCallback((value) => {
2187
+ formControl ? formControl.setValue(value) : setYear(value);
2188
+ onValue?.(value);
2189
+ }, [formControl, onValue]);
2190
+ const onClickPrev = useCallback(() => {
2191
+ setYear((year) => year - 8);
2192
+ }, []);
2193
+ const onClickNext = useCallback(() => {
2194
+ setYear((year) => year + 8);
2195
+ }, []);
2196
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-picker-year", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: "rls-picker-year__header", children: [jsxRuntimeExports.jsx(RlsButtonIcon, { icon: "arrow-ios-left", onClick: onClickPrev, disabled: !template.canPrevious || disabled }), jsxRuntimeExports.jsxs("span", { children: [template.minRange, " - ", template.maxRange] }), jsxRuntimeExports.jsx(RlsButtonIcon, { icon: "arrow-ios-right", onClick: onClickNext, disabled: !template.canNext || disabled })] }), jsxRuntimeExports.jsx("div", { className: "rls-picker-year__component", children: template.years.map((year, index) => (jsxRuntimeExports.jsx(RlsPickerYearElement, { year: year, onSelect: onSelect, disabled: disabled }, index))) })] }));
2197
+ }
2198
+
2199
+ function calculateInitialValue(value, minValue, maxValue) {
2200
+ return minValue > value ? minValue : maxValue < value ? maxValue : value;
2201
+ }
2202
+ function calculateInitialRate(value, minValue, maxValue) {
2203
+ const rateMax = maxValue - minValue;
2204
+ const rateValue = value - minValue;
2205
+ return Math.ceil((rateValue / rateMax) * 100);
2206
+ }
2207
+ function RlsSlider({ children, className, disabled, formControl, identifier, maxValue, minValue, onValue, prefixIcon, rlsTheme, value }) {
2208
+ const minValueSlider = useMemo(() => {
2209
+ return minValue ?? 0;
2210
+ }, [minValue]);
2211
+ const maxValueSlider = useMemo(() => {
2212
+ return maxValue ?? 100;
2213
+ }, [maxValue]);
2214
+ const [valueSlider, setValue] = useState(calculateInitialValue(formControl?.value ?? value ?? 0, minValueSlider, maxValueSlider));
2215
+ const [rate, setRate] = useState(calculateInitialRate(valueSlider, minValueSlider, maxValueSlider));
2216
+ const refComponent = useRef(null);
2217
+ const refTrack = useRef(null);
2218
+ const refTrackOn = useRef(null);
2219
+ const refThumb = useRef(null);
2220
+ const classNameSlider = useMemo(() => {
2221
+ return renderClassStatus('rls-slider', {
2222
+ complet: valueSlider === maxValueSlider,
2223
+ disabled: disabled,
2224
+ empty: valueSlider === minValueSlider
2225
+ }, className);
2226
+ }, [valueSlider, minValueSlider, maxValueSlider, disabled]);
2227
+ useEffect(() => {
2228
+ const valueInitial = formControl?.value ?? value ?? 0;
2229
+ refThumb.current.style.left = `${rate}%`;
2230
+ refTrackOn.current.style.width = `${rate}%`;
2231
+ if (valueInitial !== valueSlider) {
2232
+ formControl?.setValue(valueSlider);
2233
+ onValue?.(valueSlider);
2234
+ }
2235
+ }, []);
2236
+ const calculateValueWithRate = useCallback((rate) => {
2237
+ const value = Math.ceil(((maxValueSlider - minValueSlider) * rate) / 100);
2238
+ refThumb.current.style.left = `${rate}%`;
2239
+ refTrackOn.current.style.width = `${rate}%`;
2240
+ const sliderValue = value + minValueSlider;
2241
+ setRate(rate);
2242
+ setValue(sliderValue);
2243
+ formControl?.setValue(sliderValue);
2244
+ onValue?.(sliderValue);
2245
+ }, [minValueSlider, maxValueSlider, formControl, onValue]);
2246
+ const onClickTrack = useCallback((event) => {
2247
+ const { left, width } = refTrack.current.getBoundingClientRect();
2248
+ const rate = Math.ceil(((event.clientX - left) / width) * 100);
2249
+ calculateValueWithRate(rate);
2250
+ }, [minValueSlider, maxValueSlider]);
2251
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: classNameSlider, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-slider__label", children: children }), jsxRuntimeExports.jsxs("div", { className: "rls-slider__body", children: [prefixIcon && jsxRuntimeExports.jsx(RlsIcon, { value: prefixIcon }), jsxRuntimeExports.jsxs("div", { ref: refComponent, className: "rls-slider__component", children: [jsxRuntimeExports.jsx("div", { ref: refTrack, className: "rls-slider__track", onClick: onClickTrack, children: jsxRuntimeExports.jsx("div", { ref: refTrackOn, className: "rls-slider__track__on" }) }), jsxRuntimeExports.jsxs("div", { ref: refThumb, className: "rls-slider__thumb", children: [rate, "%"] })] })] })] }));
2252
+ }
2253
+
2254
+ function RlsTab({ onSelect, tab, value }) {
2255
+ const className = useMemo(() => {
2256
+ return renderClassStatus('rls-tabs__children', {
2257
+ active: tab.value === value,
2258
+ disabled: tab.disabled
2259
+ });
2260
+ }, [tab, value]);
2261
+ const onClick = useCallback(() => {
2262
+ !tab.disabled && onSelect(tab.value);
2263
+ }, [tab.disabled]);
2264
+ return (jsxRuntimeExports.jsx("div", { className: className, onClick: onClick, children: jsxRuntimeExports.jsx("span", { children: tab.label }) }));
2265
+ }
2266
+ function RlsTabs({ tabs, onValue, rlsTheme }) {
2267
+ const [value, setValue] = useState();
2268
+ const onSelect = useCallback((value) => {
2269
+ setValue(value);
2270
+ onValue?.(value);
2271
+ }, [onValue]);
2272
+ useEffect(() => {
2273
+ const initial = tabs.find((tab) => tab.defaultActive) ?? tabs[0];
2274
+ initial && onSelect(initial.value);
2275
+ }, []);
2276
+ return (jsxRuntimeExports.jsx("div", { className: "rls-tabs", "rls-theme": rlsTheme, children: tabs.map((tab, index) => {
2277
+ return (jsxRuntimeExports.jsx(RlsTab, { tab: tab, value: value, onSelect: onSelect }, index));
2278
+ }) }));
2279
+ }
2280
+
2281
+ function RlsToolbar({ actions, children, subtitle }) {
2282
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-toolbar", children: [jsxRuntimeExports.jsxs("div", { className: "rls-toolbar__description", children: [children && jsxRuntimeExports.jsx("label", { className: "rls-toolbar__title", children: children }), subtitle && (jsxRuntimeExports.jsx("label", { className: "rls-toolbar__subtitle smalltext-semibold", children: subtitle }))] }), actions && (jsxRuntimeExports.jsx("div", { className: "rls-toolbar__actions", children: actions.map((action, index) => (jsxRuntimeExports.jsx("div", { children: action }, index))) }))] }));
2283
+ }
2284
+
2285
+ function RlsBottomSheet({ autoclose, children, className, controller, onBackdrop, visible, rlsTheme }) {
2286
+ const classNameSheet = useMemo(() => {
2287
+ return renderClassStatus('rls-bottom-sheet', { visible: controller?.visible ?? visible }, className);
2288
+ }, [className, visible, controller?.visible]);
2289
+ const onClickBackdrop = useCallback(() => {
2290
+ autoclose && controller?.close();
2291
+ onBackdrop?.();
2292
+ }, [autoclose, controller, onBackdrop]);
2293
+ return ReactDOM.createPortal(jsxRuntimeExports.jsxs("div", { className: classNameSheet, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-bottom-sheet__component", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-bottom-sheet__backdrop", onClick: onClickBackdrop })] }), document.body);
2294
+ }
2295
+
2296
+ function RlsCard({ children, className, outline, rlsTheme }) {
2297
+ const classNameCard = useMemo(() => {
2298
+ return renderClassStatus('rls-card', { outline }, className);
2299
+ }, [outline, className]);
2300
+ return (jsxRuntimeExports.jsx("div", { className: classNameCard, "rls-theme": rlsTheme, children: jsxRuntimeExports.jsx("div", { className: "rls-card__content", children: children }) }));
2301
+ }
2302
+
2303
+ class ConfirmationResult extends SealedPartial {
2304
+ static approved() {
2305
+ return new ConfirmationResult('approved');
2306
+ }
2307
+ static reject() {
2308
+ return new ConfirmationResult('reject');
2309
+ }
2310
+ }
2311
+ function RlsConfirmation({ approved, className, content, reject, rlsTheme, subtitle, title, visible }) {
2312
+ const classConfirmation = useMemo(() => {
2313
+ return renderClassStatus('rls-confirmation', { visible }, className);
2314
+ }, [visible, className]);
2315
+ return (jsxRuntimeExports.jsxs("div", { className: classConfirmation, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: "rls-confirmation__component", children: [jsxRuntimeExports.jsxs("div", { className: "rls-confirmation__header", children: [title && jsxRuntimeExports.jsx("div", { className: "rls-confirmation__title", children: title }), subtitle && (jsxRuntimeExports.jsx("div", { className: "rls-confirmation__subtitle", children: subtitle }))] }), jsxRuntimeExports.jsx("div", { className: "rls-confirmation__body", children: content && (jsxRuntimeExports.jsx("div", { className: "rls-confirmation__content", children: content })) }), (approved || reject) && (jsxRuntimeExports.jsx("div", { className: "rls-confirmation__footer", children: jsxRuntimeExports.jsxs("div", { className: "rls-confirmation__actions", children: [approved && (jsxRuntimeExports.jsx(RlsButton, { identifier: approved.identifier, type: approved.type, onClick: approved.onClick, disabled: approved.disabled, rlsTheme: approved.rlsTheme, children: approved.label })), reject && (jsxRuntimeExports.jsx(RlsButton, { identifier: reject.identifier, type: reject.type, onClick: reject.onClick, disabled: reject.disabled, rlsTheme: reject.rlsTheme, children: reject.label }))] }) }))] }), jsxRuntimeExports.jsx("div", { className: "rls-confirmation__backdrop" })] }));
2316
+ }
2317
+ function useConfirmation() {
2318
+ const [config, setConfig] = useState({});
2319
+ const [visible, setVisible] = useState(false);
2320
+ const component = ReactDOM.createPortal(jsxRuntimeExports.jsx(RlsConfirmation, { ...config, visible: visible }), document.body);
2321
+ const confirmation = useCallback((options) => {
2322
+ return new Promise((resolve) => {
2323
+ setConfig({
2324
+ ...options,
2325
+ approved: {
2326
+ label: options.approved?.label ?? reactI18n('confirmationActionApproved'),
2327
+ onClick: () => {
2328
+ setVisible(false);
2329
+ resolve(ConfirmationResult.approved());
2330
+ },
2331
+ type: options.approved?.type ?? 'raised',
2332
+ disabled: options.approved?.disabled,
2333
+ identifier: options.approved?.identifier,
2334
+ rlsTheme: options.approved?.rlsTheme
2335
+ },
2336
+ reject: options.reject
2337
+ ? {
2338
+ label: options.reject.label,
2339
+ onClick: () => {
2340
+ setVisible(false);
2341
+ resolve(ConfirmationResult.reject());
2342
+ },
2343
+ type: options.reject.type ?? 'outline',
2344
+ disabled: options.reject.disabled,
2345
+ identifier: options.reject.identifier,
2346
+ rlsTheme: options.reject.rlsTheme
2347
+ }
2348
+ : undefined
2349
+ });
2350
+ setVisible(true);
2351
+ });
2352
+ }, []);
2353
+ return {
2354
+ RlsConfirmation: component,
2355
+ confirmation
2356
+ };
2357
+ }
2358
+
2359
+ function createObserver(options) {
2360
+ const { setScrolleable, table } = options;
2361
+ const observer = new ResizeObserver(() => {
2362
+ const scrollHeight = table.scrollHeight || 0;
2363
+ const clientHeight = table.clientHeight || 0;
2364
+ setScrolleable(scrollHeight > clientHeight);
2365
+ });
2366
+ observer.observe(table);
2367
+ return observer;
2368
+ }
2369
+ function useDatatable(table) {
2370
+ const [scrolleable, setScrolleable] = useState(false);
2371
+ const refTable = useRef(table ? table : null);
2372
+ useEffect(() => {
2373
+ const observer = refTable.current &&
2374
+ createObserver({ setScrolleable, table: refTable.current });
2375
+ return () => {
2376
+ observer?.disconnect();
2377
+ };
2378
+ }, []);
2379
+ return { refTable, scrolleable };
2380
+ }
2381
+
2382
+ function RlsDatatable({ children, footer, header, identifier, rlsTheme, resizable, summary, table, toolbar }) {
2383
+ const datatable = useDatatable(table);
2384
+ const className = useMemo(() => {
2385
+ return renderClassStatus('rls-datatable', {
2386
+ resizable,
2387
+ scrolleable: resizable && datatable?.scrolleable
2388
+ });
2389
+ }, [resizable, datatable.scrolleable]);
2390
+ return (jsxRuntimeExports.jsxs("div", { className: className, "rls-theme": rlsTheme, children: [toolbar && jsxRuntimeExports.jsx("div", { className: "rls-datatable__toolbar", children: toolbar }), jsxRuntimeExports.jsx("div", { className: "rls-datatable__table", children: jsxRuntimeExports.jsxs("table", { id: identifier, children: [header && jsxRuntimeExports.jsx("thead", { className: "rls-datatable__head", children: header }), jsxRuntimeExports.jsx("tbody", { ref: datatable?.refTable, className: "rls-datatable__body", children: children })] }) }), summary && jsxRuntimeExports.jsx("div", { className: "rls-datatable__summary", children: summary }), footer && jsxRuntimeExports.jsx("div", { className: "rls-datatable__footer", children: footer })] }));
2391
+ }
2392
+ function RlsDatatableHeader({ children, identifier, rlsTheme }) {
2393
+ return (jsxRuntimeExports.jsx("tr", { id: identifier, className: "rls-datatable__header", "rls-theme": rlsTheme, children: children }));
2394
+ }
2395
+ function RlsDatatableTitle({ children, className, contained, control, identifier, rlsTheme }) {
2396
+ const classNameTitle = useMemo(() => {
2397
+ return renderClassStatus('rls-datatable__title', { contained, control }, className);
2398
+ }, [className, contained, control]);
2399
+ return (jsxRuntimeExports.jsx("th", { id: identifier, className: classNameTitle, "rls-theme": rlsTheme, children: children }));
2400
+ }
2401
+ function RlsDatatableSubheader({ children, className, identifier, rlsTheme }) {
2402
+ const classNameSubheader = useMemo(() => {
2403
+ return renderClassStatus('rls-datatable__subheader', {}, className);
2404
+ }, [className]);
2405
+ return (jsxRuntimeExports.jsx("tr", { id: identifier, className: classNameSubheader, "rls-theme": rlsTheme, children: children }));
2406
+ }
2407
+ function RlsDatatableRecord({ children, className, contained, error, identifier, info, success, warning, rlsTheme }) {
2408
+ const classNameRecord = useMemo(() => {
2409
+ return renderClassStatus('rls-datatable__record', { error, info, contained, success, warning }, className);
2410
+ }, [className, contained, error, info, success, warning]);
2411
+ return (jsxRuntimeExports.jsx("tr", { id: identifier, className: classNameRecord, "rls-theme": rlsTheme, children: children }));
2412
+ }
2413
+ function RlsDatatableTotals({ children, className, contained, error, identifier, info, success, warning, rlsTheme }) {
2414
+ const classNameTotals = useMemo(() => {
2415
+ return renderClassStatus('rls-datatable__totals', { error, info, contained, success, warning }, className);
2416
+ }, [className, contained, error, info, success, warning]);
2417
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: classNameTotals, "rls-theme": rlsTheme, children: children }));
2418
+ }
2419
+ function RlsDatatableCell({ children, className, contained, control, identifier, rlsTheme }) {
2420
+ const classNameCell = useMemo(() => {
2421
+ return renderClassStatus('rls-datatable__cell', { control, contained }, className);
2422
+ }, [className, contained, control]);
2423
+ return (jsxRuntimeExports.jsx("td", { id: identifier, className: classNameCell, "rls-theme": rlsTheme, children: children }));
2424
+ }
2425
+ function RlsDatatableData({ children, className, contained, control, identifier }) {
2426
+ const classNameData = useMemo(() => {
2427
+ return renderClassStatus('rls-datatable__data', { control, contained }, className);
2428
+ }, [className, contained, control]);
2429
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: classNameData, children: children }));
2430
+ }
2431
+ function RlsDatatableFloating({ children, className, identifier, invested, rlsTheme }) {
2432
+ const classNameFloating = useMemo(() => {
2433
+ return renderClassStatus('rls-datatable__floating', { invested }, className);
2434
+ }, [className, invested]);
2435
+ return (jsxRuntimeExports.jsx("td", { id: identifier, className: classNameFloating, "rls-theme": rlsTheme, children: children }));
2436
+ }
2437
+
2438
+ function RlsDropdown({ children, controller, rlsTheme }) {
2439
+ const className = useMemo(() => {
2440
+ return renderClassStatus('rls-dropdown', {
2441
+ visible: controller.visible
2442
+ });
2443
+ }, [controller.visible]);
2444
+ useEffect(() => {
2445
+ function onCloseDropdown({ target }) {
2446
+ !controller.component.current.contains(target) &&
2447
+ controller.close();
2448
+ }
2449
+ document.addEventListener('click', onCloseDropdown);
2450
+ return () => {
2451
+ document.removeEventListener('click', onCloseDropdown);
2452
+ };
2453
+ }, []);
2454
+ return (jsxRuntimeExports.jsx("div", { ref: controller.component, className: className, "rls-theme": rlsTheme, children: jsxRuntimeExports.jsx("div", { className: "rls-dropdown__content", children: children }) }));
2455
+ }
2456
+
2457
+ const MAX_LIST_HEIGHT_REM$1 = 90;
2458
+ const FALLBACK_REM_SIZE$1 = 16;
2459
+ function getRemSize$1() {
2460
+ if (typeof window === 'undefined') {
2461
+ return FALLBACK_REM_SIZE$1;
2462
+ }
2463
+ const fontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
2464
+ return fontSize > 0 ? fontSize : FALLBACK_REM_SIZE$1;
2465
+ }
2466
+ function shouldDisplayHigher$1(content, list) {
2467
+ if (!content) {
2468
+ return false;
2469
+ }
2470
+ const { top, bottom } = content.getBoundingClientRect();
2471
+ const spaceAbove = top;
2472
+ const spaceBelow = window.innerHeight - bottom;
2473
+ const maxHeight = MAX_LIST_HEIGHT_REM$1 * getRemSize$1();
2474
+ const desiredHeight = Math.min(list?.scrollHeight || maxHeight, maxHeight);
2475
+ if (spaceBelow >= desiredHeight) {
2476
+ return false;
2477
+ }
2478
+ if (spaceAbove >= desiredHeight) {
2479
+ return true;
2480
+ }
2481
+ return spaceAbove > spaceBelow;
2482
+ }
2483
+ function useListController(props) {
2484
+ const { suggestions, automatic, formControl, reference } = props;
2485
+ const refContent = useRef(null);
2486
+ const refList = useRef(null);
2487
+ const refInput = useRef(null);
2488
+ const listIsOpen = useRef(false);
2489
+ const [collection, setCollection] = useState(new ListCollection(suggestions));
2490
+ const [state, refreshState] = useState({
2491
+ focused: false,
2492
+ higher: false,
2493
+ listIsVisible: false,
2494
+ value: ''
2495
+ });
2496
+ const changeValueInternal = useRef(false);
2497
+ const position = useRef(0);
2498
+ const valueProtected = useRef(undefined);
2499
+ useEffect(() => {
2500
+ function onCloseSuggestions({ target }) {
2501
+ !refContent?.current?.contains(target) &&
2502
+ refreshState((state) => ({ ...state, listIsVisible: false }));
2503
+ }
2504
+ document.addEventListener('click', onCloseSuggestions);
2505
+ return () => {
2506
+ document.removeEventListener('click', onCloseSuggestions);
2507
+ };
2508
+ }, []);
2509
+ useEffect(() => {
2510
+ if (!listIsOpen.current && state.listIsVisible) {
2511
+ listIsOpen.current = true;
2512
+ }
2513
+ if (listIsOpen.current && !state.listIsVisible) {
2514
+ formControl?.touch();
2515
+ }
2516
+ }, [state.listIsVisible]);
2517
+ useEffect(() => {
2518
+ setCollection(new ListCollection(suggestions, reference));
2519
+ }, [suggestions]);
2520
+ useEffect(() => {
2521
+ if (!changeValueInternal.current) {
2522
+ if (formControl?.value) {
2523
+ const element = collection.find(formControl.value);
2524
+ if (!element) {
2525
+ valueProtected.current = formControl.value;
2526
+ automatic
2527
+ ? setFormValue(collection.value[0], true)
2528
+ : setFormValue(undefined);
2529
+ }
2530
+ else {
2531
+ refreshState((state) => ({ ...state, value: element.description }));
2532
+ }
2533
+ }
2534
+ else if (valueProtected.current) {
2535
+ const element = collection.find(valueProtected.current);
2536
+ element ? setFormValue(element) : refreshState({ ...state, value: '' });
2537
+ }
2538
+ else {
2539
+ automatic
2540
+ ? setFormValue(collection.value[0], true)
2541
+ : refreshState({ ...state, value: '' });
2542
+ }
2543
+ }
2544
+ changeValueInternal.current = false;
2545
+ }, [collection, formControl?.value]);
2546
+ const setState = useCallback((state) => {
2547
+ const _state = state.listIsVisible
2548
+ ? {
2549
+ ...state,
2550
+ higher: shouldDisplayHigher$1(refContent.current, refList.current)
2551
+ }
2552
+ : state;
2553
+ refreshState((state) => ({ ...state, ..._state }));
2554
+ }, []);
2555
+ const setFormValue = useCallback((element, valueIsDefault = false) => {
2556
+ refreshState((state) => ({
2557
+ ...state,
2558
+ value: element?.description || ''
2559
+ }));
2560
+ changeValueInternal.current = true;
2561
+ valueIsDefault
2562
+ ? formControl?.setDefaultValue(element?.value)
2563
+ : formControl?.setValue(element?.value);
2564
+ }, [formControl]);
2565
+ const navigationInput = useCallback((event) => {
2566
+ if (state.listIsVisible) {
2567
+ const _position = navigationListFromInput({
2568
+ content: refContent.current,
2569
+ event: event,
2570
+ list: refList.current
2571
+ });
2572
+ position.current = _position ?? 0;
2573
+ }
2574
+ }, [state.listIsVisible]);
2575
+ const navigationElement = useCallback((event) => {
2576
+ position.current = navigationListFromElement({
2577
+ content: refContent.current,
2578
+ event: event,
2579
+ input: refInput.current,
2580
+ list: refList.current,
2581
+ position: position.current
2582
+ });
2583
+ }, [state.listIsVisible]);
2584
+ return {
2585
+ ...state,
2586
+ navigationElement,
2587
+ navigationInput,
2588
+ refContent,
2589
+ refInput,
2590
+ refList,
2591
+ setFormValue,
2592
+ setState
2593
+ };
2594
+ }
2595
+
2596
+ const DURATION_ANIMATION$2 = 240;
2597
+ const MAX_ELEMENTS = 6;
2598
+ function useFieldAutocomplete(props) {
2599
+ const controller = useListController(props);
2600
+ const [coincidences, setCoincidences] = useState([]);
2601
+ const [pattern, setPattern] = useState('');
2602
+ const _store = useRef({
2603
+ coincidences: [],
2604
+ pattern: '',
2605
+ previous: null
2606
+ });
2607
+ const focusTimeoutId = useRef(undefined);
2608
+ const rebootIsRequired = useRef(true);
2609
+ const prevSuggestions = useRef(props.suggestions);
2610
+ const refreshCoincidences = useCallback((suggestions, pattern, reboot = false) => {
2611
+ const { collection, store } = createAutocompleteStore({
2612
+ pattern,
2613
+ suggestions,
2614
+ reboot,
2615
+ store: _store.current
2616
+ });
2617
+ _store.current = store;
2618
+ const coincidences = collection.slice(0, MAX_ELEMENTS);
2619
+ setCoincidences(coincidences);
2620
+ }, []);
2621
+ useEffect(() => {
2622
+ const reboot = rebootIsRequired.current || prevSuggestions.current !== props.suggestions;
2623
+ rebootIsRequired.current = false;
2624
+ prevSuggestions.current = props.suggestions;
2625
+ refreshCoincidences(props.suggestions, pattern, reboot);
2626
+ }, [props.suggestions, pattern]);
2627
+ useEffect(() => {
2628
+ props.disabled && controller.setState({ focused: false });
2629
+ }, [props.disabled, controller.setState]);
2630
+ const onFocusInput = useCallback(() => {
2631
+ controller.setState({ focused: true });
2632
+ }, [controller.setState]);
2633
+ const onBlurInput = useCallback(() => {
2634
+ controller.setState({ focused: false });
2635
+ }, [controller.setState]);
2636
+ const onKeydownInput = useCallback((event) => {
2637
+ switch (event.code) {
2638
+ case 'Escape':
2639
+ case 'Tab':
2640
+ controller.setState({ listIsVisible: false });
2641
+ break;
2642
+ default:
2643
+ controller.navigationInput(event);
2644
+ break;
2645
+ }
2646
+ }, [controller.setState, controller.navigationInput]);
2647
+ const onClickControl = useCallback(() => {
2648
+ if (!props.readOnly) {
2649
+ controller.setState({ listIsVisible: true });
2650
+ clearTimeout(focusTimeoutId.current);
2651
+ focusTimeoutId.current = setTimeout(() => {
2652
+ controller.refInput?.current?.focus();
2653
+ }, DURATION_ANIMATION$2);
2654
+ }
2655
+ }, [controller.setState, props.readOnly]);
2656
+ useEffect(() => {
2657
+ return () => {
2658
+ clearTimeout(focusTimeoutId.current);
2659
+ };
2660
+ }, []);
2661
+ const onClickAction = useCallback(() => {
2662
+ if (controller.value) {
2663
+ controller.setState({ listIsVisible: false });
2664
+ controller.setFormValue(undefined);
2665
+ props.onValue?.(props.value);
2666
+ }
2667
+ else {
2668
+ onClickControl();
2669
+ }
2670
+ }, [
2671
+ controller.value,
2672
+ controller.setState,
2673
+ controller.setFormValue,
2674
+ props.onValue,
2675
+ props.value,
2676
+ onClickControl
2677
+ ]);
2678
+ const onClickBackdrop = useCallback(() => {
2679
+ controller.setState({ listIsVisible: false });
2680
+ }, [controller.setState]);
2681
+ const onChange = useCallback((element) => {
2682
+ if (props.onSelect) {
2683
+ element.value && props.onSelect(element.value);
2684
+ }
2685
+ else {
2686
+ controller.setFormValue(element);
2687
+ }
2688
+ if (props.keepOpen) {
2689
+ setPattern('');
2690
+ controller.refInput?.current?.focus();
2691
+ }
2692
+ else {
2693
+ controller.setState({ listIsVisible: false });
2694
+ }
2695
+ props.onValue?.(element.value);
2696
+ }, [
2697
+ controller.setState,
2698
+ controller.setFormValue,
2699
+ setPattern,
2700
+ props.keepOpen,
2701
+ props.onSelect,
2702
+ props.onValue
2703
+ ]);
2704
+ const onClickElement = useCallback((element) => {
2705
+ return () => {
2706
+ onChange(element);
2707
+ };
2708
+ }, [onChange]);
2709
+ const onKeydownElement = useCallback((element) => {
2710
+ return (event) => {
2711
+ event.code === 'Enter'
2712
+ ? onChange(element)
2713
+ : controller.navigationElement(event);
2714
+ };
2715
+ }, [onChange, controller.navigationElement]);
2716
+ return {
2717
+ ...controller,
2718
+ coincidences,
2719
+ onBlurInput,
2720
+ onClickAction,
2721
+ onClickBackdrop,
2722
+ onClickControl,
2723
+ onClickElement,
2724
+ onFocusInput,
2725
+ onKeydownElement,
2726
+ onKeydownInput,
2727
+ pattern,
2728
+ setPattern
2729
+ };
2730
+ }
2731
+
2732
+ function RlsFieldAutocompleteTemplate(props) {
2733
+ const autocomplete = useFieldAutocomplete(props);
2734
+ const { render, action, children, formControl, msgErrorDisabled, onSearch, placeholder, rlsTheme, searching } = props;
2735
+ const [listInputPlaceholder, setListInputPlaceholder] = useState(reactI18n('listInputPlaceholder'));
2736
+ useEffect(() => {
2737
+ return i18nSubscribe(() => {
2738
+ setListInputPlaceholder(reactI18n('listInputPlaceholder'));
2739
+ });
2740
+ }, []);
2741
+ useEffect(() => {
2742
+ props.onInput?.(autocomplete.pattern);
2743
+ }, [autocomplete.pattern, props.onInput]);
2744
+ const disabled = useMemo(() => {
2745
+ return formControl?.disabled || props.disabled;
2746
+ }, [formControl?.disabled, props.disabled]);
2747
+ const className = useMemo(() => {
2748
+ return renderClassStatus('rls-field-box', {
2749
+ focused: autocomplete.focused && !disabled,
2750
+ error: formControl?.wrong,
2751
+ disabled,
2752
+ readonly: props.readOnly,
2753
+ selected: !!autocomplete.value
2754
+ }, `rls-field-list rls-field-autocomplete ${props.className ?? ''}`);
2755
+ }, [
2756
+ formControl?.wrong,
2757
+ autocomplete.value,
2758
+ autocomplete.focused,
2759
+ props.className,
2760
+ props.readOnly,
2761
+ disabled
2762
+ ]);
2763
+ const onClickPattern = useCallback(() => {
2764
+ onSearch?.(autocomplete.pattern);
2765
+ }, [onSearch, autocomplete.pattern]);
2766
+ const onKeyDownPattern = useCallback((event) => {
2767
+ event.key === 'Enter' && onSearch?.(autocomplete.pattern);
2768
+ autocomplete.onKeydownInput(event);
2769
+ }, [autocomplete.onKeydownInput, onSearch, autocomplete.pattern]);
2770
+ const searchControl = useMemo(() => ({
2771
+ pattern: autocomplete.pattern,
2772
+ placeholder: listInputPlaceholder,
2773
+ searching,
2774
+ refInput: autocomplete.refInput,
2775
+ onChange: autocomplete.setPattern,
2776
+ onFocus: autocomplete.onFocusInput,
2777
+ onBlur: autocomplete.onBlurInput,
2778
+ onKeyDown: onKeyDownPattern,
2779
+ onSearch: onSearch ? onClickPattern : undefined
2780
+ }), [
2781
+ autocomplete.pattern,
2782
+ autocomplete.refInput,
2783
+ autocomplete.setPattern,
2784
+ autocomplete.onFocusInput,
2785
+ autocomplete.onBlurInput,
2786
+ listInputPlaceholder,
2787
+ searching,
2788
+ onKeyDownPattern,
2789
+ onClickPattern,
2790
+ onSearch
2791
+ ]);
2792
+ return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: autocomplete.refContent, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-list__control", readOnly: true, disabled: disabled, placeholder: placeholder, value: autocomplete.value, onClick: autocomplete.onClickControl }), !props.readOnly && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: autocomplete.value ? 'trash-2' : 'arrow-ios-down', onClick: autocomplete.onClickAction, disabled: disabled }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl })), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: autocomplete.coincidences, visible: autocomplete.listIsVisible, action: action, disabled: disabled, higher: autocomplete.higher, render: render, refList: autocomplete.refList, searchControl: searchControl, onClickElement: autocomplete.onClickElement, onKeydownElement: autocomplete.onKeydownElement, onClickBackdrop: autocomplete.onClickBackdrop })] }));
2793
+ }
2794
+ function RlsFieldAutocomplete(props) {
2795
+ const render = useCallback((element) => (jsxRuntimeExports.jsx(RlsBallot, { className: "rls-field-list__ballot", subtitle: element.subtitle, img: element.img, initials: element.initials, children: jsxRuntimeExports.jsx("span", { children: element.title }) })), []);
2796
+ return jsxRuntimeExports.jsx(RlsFieldAutocompleteTemplate, { ...props, render: render });
2797
+ }
2798
+
2799
+ function RlsModal({ autoclose, children, className, controller, onBackdrop, visible, rlsTheme }) {
2800
+ const classNameModal = useMemo(() => {
2801
+ return renderClassStatus('rls-modal', { visible: controller?.visible ?? visible }, className);
2802
+ }, [className, visible, controller?.visible]);
2803
+ const onClickBackdrop = useCallback(() => {
2804
+ autoclose && controller?.close();
2805
+ onBackdrop?.();
2806
+ }, [autoclose, controller, onBackdrop]);
2807
+ return ReactDOM.createPortal(jsxRuntimeExports.jsxs("div", { className: classNameModal, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-modal__component", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-modal__backdrop", onClick: onClickBackdrop })] }), document.body);
2808
+ }
2809
+
2810
+ function formatTime(value) {
2811
+ return String(value).padStart(2, '0');
2812
+ }
2813
+ const CLOCK_VALUES = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
2814
+ const RADIUS = 48;
2815
+ const DIAL_RADIUS = 60;
2816
+ const TICK_RADIUS = 7;
2817
+ function RlsPickerClockTick({ onValue, selectionIsHours, value }) {
2818
+ const styleTick = useMemo(() => {
2819
+ const radian = (value / 6) * Math.PI;
2820
+ const x = Math.sin(radian) * RADIUS;
2821
+ const y = Math.cos(radian) * RADIUS;
2822
+ return {
2823
+ left: `${DIAL_RADIUS + x - TICK_RADIUS - 1}rem`,
2824
+ top: `${DIAL_RADIUS - y - TICK_RADIUS - 1}rem`
2825
+ };
2826
+ }, []);
2827
+ const label = useMemo(() => {
2828
+ if (selectionIsHours) {
2829
+ return formatTime(value);
2830
+ }
2831
+ if (value === 12) {
2832
+ return formatTime(0);
2833
+ }
2834
+ return formatTime(value * 5);
2835
+ }, [selectionIsHours]);
2836
+ const onClick = useCallback((event) => {
2837
+ event.preventDefault();
2838
+ onValue(value);
2839
+ }, [onValue]);
2840
+ return (jsxRuntimeExports.jsx("div", { className: "rls-picker-clock__tick", style: styleTick, onClick: onClick, children: label }));
2841
+ }
2842
+ function RlsPickerClock({ formControl, onListener, rlsTheme, time }) {
2843
+ const timeInitial = useMemo(() => {
2844
+ return formControl?.value ?? time ?? Time.now();
2845
+ }, [formControl?.value, time]);
2846
+ const plateElement = useRef(null);
2847
+ const lineElement = useRef(null);
2848
+ const centerElement = useRef(null);
2849
+ const indicatorElement = useRef(null);
2850
+ const pointElement = useRef(null);
2851
+ const [labels, setLabels] = useState({
2852
+ timeActionCancel: reactI18n('dateActionCancel'),
2853
+ timeActionSelect: reactI18n('dateActionSelect')
2854
+ });
2855
+ const [zoneIsPM, setZoneIsPM] = useState(timeInitial.hour >= 12);
2856
+ const [hour, setHour] = useState(zoneIsPM ? timeInitial.hour - 12 : timeInitial.hour);
2857
+ const [minute, setMinute] = useState(timeInitial.minute);
2858
+ const [selectionIsHours, setSelectionIsHours] = useState(true);
2859
+ const changeIsInternal = useRef(true);
2860
+ const selectionIsActive = useRef(false);
2861
+ const radianUnit = useMemo(() => {
2862
+ return Math.PI / (selectionIsHours ? 6 : 30);
2863
+ }, [selectionIsHours]);
2864
+ const hourFormat = useMemo(() => {
2865
+ return formatTime(hour === 0 ? 12 : hour);
2866
+ }, [hour]);
2867
+ const minuteFormat = useMemo(() => {
2868
+ return formatTime(minute);
2869
+ }, [minute]);
2870
+ const classNameHour = useMemo(() => {
2871
+ return renderClassStatus('rls-picker-clock__title__value', {
2872
+ active: selectionIsHours
2873
+ });
2874
+ }, [selectionIsHours]);
2875
+ const classNameMinute = useMemo(() => {
2876
+ return renderClassStatus('rls-picker-clock__title__value', {
2877
+ active: !selectionIsHours
2878
+ });
2879
+ }, [selectionIsHours]);
2880
+ const classNameAM = useMemo(() => {
2881
+ return renderClassStatus('rls-picker-clock__zone__value', {
2882
+ active: !zoneIsPM
2883
+ });
2884
+ }, [zoneIsPM]);
2885
+ const classNamePM = useMemo(() => {
2886
+ return renderClassStatus('rls-picker-clock__zone__value', {
2887
+ active: zoneIsPM
2888
+ });
2889
+ }, [zoneIsPM]);
2890
+ const refreshClockHour = useEffectEvent(() => {
2891
+ refreshClock(hour > 12 ? hour - 12 : hour);
2892
+ });
2893
+ const refreshClockMinute = useEffectEvent(() => {
2894
+ refreshClock(minute);
2895
+ });
2896
+ useEffect(() => {
2897
+ return i18nSubscribe(() => {
2898
+ setLabels({
2899
+ timeActionCancel: reactI18n('dateActionCancel'),
2900
+ timeActionSelect: reactI18n('dateActionSelect')
2901
+ });
2902
+ });
2903
+ }, []);
2904
+ useEffect(() => {
2905
+ selectionIsHours ? refreshClockHour() : refreshClockMinute();
2906
+ }, [selectionIsHours]);
2907
+ useEffect(() => {
2908
+ if (!changeIsInternal.current && formControl?.value) {
2909
+ const zoneIsPM = formControl.value.hour >= 12;
2910
+ setZoneIsPM(zoneIsPM);
2911
+ setHour(zoneIsPM ? formControl.value.hour - 12 : formControl.value.hour);
2912
+ setMinute(formControl.value.minute);
2913
+ }
2914
+ changeIsInternal.current = false;
2915
+ }, [formControl?.value]);
2916
+ const refreshComponent = useCallback((clientX, clientY) => {
2917
+ const rectangle = plateElement.current.getBoundingClientRect();
2918
+ const centerX = rectangle.left + rectangle.width / 2;
2919
+ const centerY = rectangle.top + rectangle.height / 2;
2920
+ const positionX = clientX - centerX;
2921
+ const positionY = clientY - centerY;
2922
+ const angle = Math.atan2(-positionX, positionY) + Math.PI;
2923
+ const value = Math.round(angle / radianUnit);
2924
+ refreshClock(value);
2925
+ selectionIsHours ? setHour(value === 0 ? 12 : value) : setMinute(value);
2926
+ }, [selectionIsHours, radianUnit]);
2927
+ const refreshClock = useCallback((value) => {
2928
+ const angle = value * radianUnit;
2929
+ const x2 = Math.sin(angle) * (RADIUS - TICK_RADIUS);
2930
+ const y2 = -Math.cos(angle) * (RADIUS - TICK_RADIUS);
2931
+ const cx = Math.sin(angle) * RADIUS;
2932
+ const cy = -Math.cos(angle) * RADIUS;
2933
+ lineElement.current.setAttribute('x2', `${x2 - 1}rem`);
2934
+ lineElement.current.setAttribute('y2', `${y2 - 1}rem`);
2935
+ indicatorElement.current.setAttribute('cx', `${cx - 1}rem`);
2936
+ indicatorElement.current.setAttribute('cy', `${cy - 1}rem`);
2937
+ pointElement.current.setAttribute('cx', `${cx - 1}rem`);
2938
+ pointElement.current.setAttribute('cy', `${cy - 1}rem`);
2939
+ pointElement.current.style.visibility =
2940
+ selectionIsHours || value % 5 === 0 ? 'hidden' : 'visible';
2941
+ }, [selectionIsHours, radianUnit]);
2942
+ const onClickHour = useCallback(() => {
2943
+ setSelectionIsHours(true);
2944
+ }, []);
2945
+ const onClickMinute = useCallback(() => {
2946
+ setSelectionIsHours(false);
2947
+ }, []);
2948
+ const onClickAM = useCallback(() => {
2949
+ setZoneIsPM(false);
2950
+ }, []);
2951
+ const onClickPM = useCallback(() => {
2952
+ setZoneIsPM(true);
2953
+ }, []);
2954
+ const onActiveSelection = useCallback(() => {
2955
+ selectionIsActive.current = true;
2956
+ }, []);
2957
+ const onMouseSelection = useCallback((event) => {
2958
+ if (selectionIsActive.current) {
2959
+ event.preventDefault();
2960
+ refreshComponent(event.clientX, event.clientY);
2961
+ }
2962
+ }, [refreshComponent]);
2963
+ const onTouchSelection = useCallback((event) => {
2964
+ const touch = event.touches.item(0);
2965
+ if (selectionIsActive.current && touch) {
2966
+ refreshComponent(touch.clientX, touch.clientY);
2967
+ }
2968
+ }, [refreshComponent]);
2969
+ const onInactiveSelection = useCallback(() => {
2970
+ selectionIsActive.current = false;
2971
+ }, []);
2972
+ const onClickValue = useCallback((value) => {
2973
+ if (selectionIsHours) {
2974
+ setHour(value);
2975
+ refreshClock(value);
2976
+ }
2977
+ else {
2978
+ const minute = value === 12 ? 0 : value * 5;
2979
+ setMinute(minute);
2980
+ refreshClock(minute);
2981
+ }
2982
+ }, [selectionIsHours]);
2983
+ const onCancel = useCallback(() => {
2984
+ onListener?.({ event: PickerListenerEvent.Cancel });
2985
+ }, [onListener]);
2986
+ const onCurrentTime = useCallback(() => {
2987
+ const currentTime = Time.now();
2988
+ changeIsInternal.current = true;
2989
+ formControl?.setValue(currentTime);
2990
+ setHour(currentTime.hour);
2991
+ setMinute(currentTime.minute);
2992
+ onListener?.({
2993
+ event: PickerListenerEvent.Select,
2994
+ value: currentTime
2995
+ });
2996
+ }, [formControl, onListener]);
2997
+ const onSelect = useCallback(() => {
2998
+ const hourValue = zoneIsPM
2999
+ ? hour !== 12
3000
+ ? hour + 12
3001
+ : 12
3002
+ : hour === 12
3003
+ ? 0
3004
+ : hour;
3005
+ const timeValue = new Time(hourValue, minute);
3006
+ changeIsInternal.current = true;
3007
+ formControl?.setValue(timeValue);
3008
+ onListener?.({
3009
+ event: PickerListenerEvent.Select,
3010
+ value: timeValue
3011
+ });
3012
+ }, [formControl, hour, minute, zoneIsPM, onListener]);
3013
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-picker-clock", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: "rls-picker-clock__header", children: [jsxRuntimeExports.jsxs("div", { className: "rls-picker-clock__title", children: [jsxRuntimeExports.jsx("span", { className: classNameHour, onClick: onClickHour, children: hourFormat }), jsxRuntimeExports.jsx("span", { className: "rls-picker-clock__title__separator", children: ":" }), jsxRuntimeExports.jsx("span", { className: classNameMinute, onClick: onClickMinute, children: minuteFormat })] }), jsxRuntimeExports.jsxs("div", { className: "rls-picker-clock__zone", children: [jsxRuntimeExports.jsx("span", { className: classNameAM, onClick: onClickAM, children: "AM" }), jsxRuntimeExports.jsx("span", { className: classNamePM, onClick: onClickPM, children: "PM" })] })] }), jsxRuntimeExports.jsx("div", { className: "rls-picker-clock__body", children: jsxRuntimeExports.jsxs("div", { className: "rls-picker-clock__plate", ref: plateElement, onMouseDown: onActiveSelection, onMouseMove: onMouseSelection, onMouseUp: onInactiveSelection, onMouseLeave: onInactiveSelection, onTouchStart: onActiveSelection, onTouchMove: onTouchSelection, onTouchEnd: onInactiveSelection, children: [jsxRuntimeExports.jsx("div", { className: "rls-picker-clock__canvas", children: jsxRuntimeExports.jsx("svg", { width: "120rem", height: "120rem", children: jsxRuntimeExports.jsxs("g", { style: {
3014
+ transform: `translate(${DIAL_RADIUS}rem, ${DIAL_RADIUS}rem)`
3015
+ }, children: [jsxRuntimeExports.jsx("line", { ref: lineElement, className: "rls-picker-clock__canvas__line", x1: "-1", y1: "-1" }), jsxRuntimeExports.jsx("circle", { ref: centerElement, className: "rls-picker-clock__canvas__center", r: "4", cx: "-1", cy: "-1" }), jsxRuntimeExports.jsx("circle", { ref: indicatorElement, className: "rls-picker-clock__canvas__indicator", r: `${TICK_RADIUS}rem` }), jsxRuntimeExports.jsx("circle", { ref: pointElement, className: "rls-picker-clock__canvas__point", r: "3.5" })] }) }) }), jsxRuntimeExports.jsx("div", { className: "rls-picker-clock__hours", children: CLOCK_VALUES.map((value) => {
3016
+ return (jsxRuntimeExports.jsx(RlsPickerClockTick, { value: value, selectionIsHours: selectionIsHours, onValue: onClickValue }, value));
3017
+ }) })] }) }), jsxRuntimeExports.jsxs("div", { className: "rls-picker-clock__footer", children: [jsxRuntimeExports.jsx("div", { className: "rls-picker-clock__footer--cancel", children: jsxRuntimeExports.jsx(RlsButton, { type: "flat", onClick: onCancel, children: labels.timeActionCancel }) }), jsxRuntimeExports.jsx("div", { className: "rls-picker-clock__footer--today", children: jsxRuntimeExports.jsx(RlsButtonAction, { icon: "timer", onClick: onCurrentTime }) }), jsxRuntimeExports.jsx("div", { className: "rls-picker-clock__footer--ok", children: jsxRuntimeExports.jsx(RlsButton, { type: "gradient", onClick: onSelect, children: labels.timeActionSelect }) })] })] }));
3018
+ }
3019
+
3020
+ function RlsFieldClock({ children, disabled: disabledProps, formControl, identifier, msgErrorDisabled, onValue, placeholder, readOnly, rlsTheme, time, value: valueInitial }) {
3021
+ const [value, setValue] = useState(formControl?.value ?? valueInitial);
3022
+ const [modalIsVisible, setModalIsVisible] = useState(false);
3023
+ const disabled = useMemo(() => {
3024
+ return formControl?.disabled || disabledProps;
3025
+ }, [formControl?.disabled, disabledProps]);
3026
+ const className = useMemo(() => {
3027
+ return renderClassStatus('rls-field-box', {
3028
+ disabled,
3029
+ readonly: readOnly
3030
+ });
3031
+ }, [disabled, readOnly]);
3032
+ const timeValue = useMemo(() => {
3033
+ return formControl ? formControl.value : value;
3034
+ }, [formControl?.value, value]);
3035
+ const status = useMemo(() => {
3036
+ return {
3037
+ icon: timeValue ? 'trash-2' : 'timer',
3038
+ valueInput: timeValue?.normalizeMeridiemFormat || ''
3039
+ };
3040
+ }, [timeValue]);
3041
+ const onClickInput = useCallback(() => {
3042
+ !readOnly && setModalIsVisible(true);
3043
+ }, [readOnly]);
3044
+ const onChange = useCallback((value) => {
3045
+ setValue(value);
3046
+ onValue?.(value);
3047
+ }, [onValue]);
3048
+ const onClickAction = useCallback(() => {
3049
+ if (timeValue) {
3050
+ formControl?.setValue(valueInitial);
3051
+ formControl?.touch();
3052
+ onChange(valueInitial);
3053
+ }
3054
+ else {
3055
+ setModalIsVisible(true);
3056
+ }
3057
+ }, [timeValue, formControl, valueInitial, onChange]);
3058
+ const onListener = useCallback(({ event, value }) => {
3059
+ event !== PickerListenerEvent.Cancel && onChange(value);
3060
+ formControl?.touch();
3061
+ setModalIsVisible(false);
3062
+ }, [formControl, onChange]);
3063
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: "rls-field-clock", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: className, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-clock__control", type: "text", value: status.valueInput, readOnly: true, placeholder: placeholder, onClick: onClickInput, disabled: disabled }), !readOnly && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: status.icon, onClick: onClickAction, disabled: disabled }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }), jsxRuntimeExports.jsx(RlsModal, { className: "rls-field-clock-modal", visible: modalIsVisible, rlsTheme: rlsTheme, children: jsxRuntimeExports.jsx(RlsPickerClock, { formControl: formControl, time: time, disabled: disabled, onListener: onListener }) })] }));
3064
+ }
3065
+
3066
+ const DATE_FORMAT = '{dd}/{mx}/{yy}';
3067
+ const DATE_FORMAT_TITLE = '{dw}, {mx} {dd} de {yy}';
3068
+ const DATE_RANGE_FORMAT = '{dd}/{mx}/{yy}';
3069
+
3070
+ function RlsPickerDate({ automatic, date, disabled, formControl, maxDate, minDate, onListener, rlsTheme }) {
3071
+ const today = useRef(new Date()); // Initial current date in component
3072
+ const _date = useMemo(() => {
3073
+ return formControl?.value ?? date ?? today.current;
3074
+ }, [formControl?.value, date]);
3075
+ const yearControl = useReactControl(_date.getFullYear());
3076
+ const dayControl = useReactControl(_date.getDate());
3077
+ const monthControl = useReactControl(_date.getMonth());
3078
+ const [visibility, setVisibility] = useState('DAY');
3079
+ const [labels, setLabels] = useState({
3080
+ dateActionCancel: reactI18n('dateActionCancel'),
3081
+ dateActionSelect: reactI18n('dateActionSelect'),
3082
+ dateActionToday: reactI18n('dateActionToday')
3083
+ });
3084
+ const value = useMemo(() => {
3085
+ return new Date(yearControl.value, monthControl.value, dayControl.value);
3086
+ }, [yearControl.value, monthControl.value, dayControl.value]);
3087
+ const classNameComponent = useMemo(() => {
3088
+ return renderClassStatus('rls-picker-date__component', {
3089
+ day: visibility === 'DAY',
3090
+ month: visibility === 'MONTH',
3091
+ year: visibility === 'YEAR'
3092
+ });
3093
+ }, [visibility]);
3094
+ const title = useMemo(() => {
3095
+ return dateFormatTemplate(value, DATE_FORMAT_TITLE);
3096
+ }, [value]);
3097
+ const itIsDisabledToday = useMemo(() => dateOutRange({
3098
+ date: today.current,
3099
+ maxDate,
3100
+ minDate
3101
+ }), [maxDate, minDate]);
3102
+ useEffect(() => {
3103
+ const date = verifyDateRange({ date: _date, minDate, maxDate });
3104
+ yearControl.setValue(date.getFullYear());
3105
+ monthControl.setValue(date.getMonth());
3106
+ dayControl.setValue(date.getDate());
3107
+ formControl?.setValue(date);
3108
+ return i18nSubscribe(() => {
3109
+ setLabels({
3110
+ dateActionCancel: reactI18n('dateActionCancel'),
3111
+ dateActionSelect: reactI18n('dateActionSelect'),
3112
+ dateActionToday: reactI18n('dateActionToday')
3113
+ });
3114
+ });
3115
+ }, []);
3116
+ const onVisibilityDay = useCallback(() => {
3117
+ setVisibility('DAY');
3118
+ }, []);
3119
+ const onVisibilityTitle = useCallback((type) => {
3120
+ type === 'month' ? setVisibility('MONTH') : setVisibility('YEAR');
3121
+ }, []);
3122
+ const onCancel = useCallback(() => {
3123
+ onListener?.({ event: PickerListenerEvent.Cancel });
3124
+ }, [onListener]);
3125
+ const onToday = useCallback(() => {
3126
+ yearControl.setValue(today.current.getFullYear());
3127
+ dayControl.setValue(today.current.getDate());
3128
+ monthControl.setValue(today.current.getMonth());
3129
+ formControl?.setValue(today.current);
3130
+ onListener?.({
3131
+ event: PickerListenerEvent.Now,
3132
+ value: today.current
3133
+ });
3134
+ }, [formControl, onListener]);
3135
+ const onSelect = useCallback(() => {
3136
+ formControl?.setValue(value);
3137
+ onListener?.({
3138
+ event: PickerListenerEvent.Select,
3139
+ value: value
3140
+ });
3141
+ }, [formControl, value, onListener]);
3142
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-picker-date", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: "rls-picker-date__header", children: [jsxRuntimeExports.jsx(RlsPickerSelectorTitle, { monthControl: monthControl, yearControl: yearControl, date: value, maxDate: maxDate, minDate: minDate, disabled: visibility === 'YEAR', type: 'month', onClick: onVisibilityTitle }), jsxRuntimeExports.jsx("div", { className: "rls-picker-date__title", children: jsxRuntimeExports.jsx("span", { onClick: onVisibilityDay, children: title }) })] }), jsxRuntimeExports.jsxs("div", { className: classNameComponent, children: [jsxRuntimeExports.jsx(RlsPickerDay, { formControl: dayControl, date: value, month: monthControl.value, year: yearControl.value, maxDate: maxDate, minDate: minDate, disabled: disabled }), jsxRuntimeExports.jsx(RlsPickerMonth, { formControl: monthControl, date: value, year: yearControl.value, maxDate: maxDate, minDate: minDate, disabled: disabled, onValue: onVisibilityDay }), jsxRuntimeExports.jsx(RlsPickerYear, { formControl: yearControl, date: value, maxDate: maxDate, minDate: minDate, disabled: disabled, onValue: onVisibilityDay })] }), !automatic && (jsxRuntimeExports.jsx("div", { className: "rls-picker-date__footer", children: jsxRuntimeExports.jsxs("div", { className: "rls-picker-date__actions", children: [jsxRuntimeExports.jsx("div", { className: "rls-picker-date__actions--cancel", children: jsxRuntimeExports.jsx(RlsButton, { type: "flat", onClick: onCancel, children: labels.dateActionCancel }) }), jsxRuntimeExports.jsx("div", { className: "rls-picker-date__actions--today", children: jsxRuntimeExports.jsx(RlsButtonAction, { icon: "calendar", onClick: onToday, disabled: itIsDisabledToday }) }), jsxRuntimeExports.jsx("div", { className: "rls-picker-date__actions--ok", children: jsxRuntimeExports.jsx(RlsButton, { type: "gradient", onClick: onSelect, children: labels.dateActionSelect }) })] }) }))] }));
3143
+ }
3144
+
3145
+ function RlsFieldDate({ children, date, disabled: disabledProps, formControl, format, identifier, maxDate, minDate, msgErrorDisabled, onValue, placeholder, readOnly, rlsTheme, value: valueInitial }) {
3146
+ const today = useRef(new Date()); // Initial current date in component
3147
+ const [value, setValue] = useState(formControl?.value ?? valueInitial);
3148
+ const [modalIsVisible, setModalIsVisible] = useState(false);
3149
+ const disabled = useMemo(() => {
3150
+ return formControl?.disabled || disabledProps;
3151
+ }, [formControl?.disabled, disabledProps]);
3152
+ const className = useMemo(() => {
3153
+ return renderClassStatus('rls-field-box', {
3154
+ disabled,
3155
+ readonly: readOnly
3156
+ });
3157
+ }, [disabled, readOnly]);
3158
+ const dateValue = useMemo(() => {
3159
+ return formControl ? formControl.value : value;
3160
+ }, [formControl?.value, value]);
3161
+ const status = useMemo(() => {
3162
+ return {
3163
+ icon: dateValue ? 'trash-2' : 'calendar',
3164
+ label: dateValue
3165
+ ? dateFormatTemplate(dateValue, format ?? DATE_FORMAT)
3166
+ : ''
3167
+ };
3168
+ }, [dateValue, format]);
3169
+ useEffect(() => {
3170
+ const dateSecure = verifyDateRange({
3171
+ date: formControl?.value ?? date ?? today.current,
3172
+ minDate,
3173
+ maxDate
3174
+ });
3175
+ setValue(dateSecure);
3176
+ formControl?.setValue(dateSecure);
3177
+ }, []);
3178
+ const onClickInput = useCallback(() => {
3179
+ !readOnly && setModalIsVisible(true);
3180
+ }, [readOnly]);
3181
+ const onChange = useCallback((value) => {
3182
+ setValue(value);
3183
+ onValue?.(value);
3184
+ }, [onValue]);
3185
+ const onClickAction = useCallback(() => {
3186
+ if (dateValue) {
3187
+ formControl?.setValue(valueInitial);
3188
+ formControl?.touch();
3189
+ onChange(valueInitial);
3190
+ }
3191
+ else {
3192
+ setModalIsVisible(true);
3193
+ }
3194
+ }, [dateValue, formControl, valueInitial, onChange]);
3195
+ const onListener = useCallback(({ event, value }) => {
3196
+ event !== PickerListenerEvent.Cancel && onChange(value);
3197
+ formControl?.touch();
3198
+ setModalIsVisible(false);
3199
+ }, [formControl, onChange]);
3200
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: "rls-field-date", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: className, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-date__control", type: "text", value: status.label, readOnly: true, placeholder: placeholder, onClick: onClickInput, disabled: disabled }), !readOnly && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: status.icon, onClick: onClickAction, disabled: disabled }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }), jsxRuntimeExports.jsx(RlsModal, { className: "rls-field-date-modal", visible: modalIsVisible, rlsTheme: rlsTheme, children: jsxRuntimeExports.jsx(RlsPickerDate, { formControl: formControl, date: date, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: onListener }) })] }));
3201
+ }
3202
+
3203
+ function rangeFormatTemplate({ maxDate, minDate }) {
3204
+ const minFormat = dateFormatTemplate(minDate, DATE_RANGE_FORMAT);
3205
+ const maxFormat = dateFormatTemplate(maxDate, DATE_RANGE_FORMAT);
3206
+ return `${minFormat} - ${maxFormat}`;
3207
+ }
3208
+
3209
+ function RlsPickerDateRange({ automatic, date: datePicker, disabled, formControl, maxDate, minDate, onListener, rlsTheme }) {
3210
+ const _date = useMemo(() => normalizeMinTime(datePicker ?? new Date()), [datePicker]);
3211
+ const _range = useMemo(() => formControl?.value ?? DateRange.now(), [formControl?.value]);
3212
+ const yearControl = useReactControl(_date.getFullYear());
3213
+ const monthControl = useReactControl(_date.getMonth());
3214
+ const rangeControl = useReactControl(_range);
3215
+ const [visibility, setVisibility] = useState('DAY');
3216
+ const [labels, setLabels] = useState({
3217
+ dateActionCancel: reactI18n('dateActionCancel'),
3218
+ dateActionSelect: reactI18n('dateActionSelect')
3219
+ });
3220
+ const value = useMemo(() => {
3221
+ return rangeControl.value ?? _range;
3222
+ }, [rangeControl.value, _range]);
3223
+ const date = useMemo(() => {
3224
+ let value = _date;
3225
+ if (valueIsDefined(yearControl.value)) {
3226
+ value = assignYearInDate(value, yearControl.value);
3227
+ }
3228
+ if (valueIsDefined(monthControl.value)) {
3229
+ value = assignMonthInDate(value, monthControl.value);
3230
+ }
3231
+ return value;
3232
+ }, [_date, yearControl.value, monthControl.value]);
3233
+ const classNameComponent = useMemo(() => {
3234
+ return renderClassStatus('rls-picker-date-range__component', {
3235
+ day: visibility === 'DAY',
3236
+ month: visibility === 'MONTH',
3237
+ year: visibility === 'YEAR'
3238
+ });
3239
+ }, [visibility]);
3240
+ const classNameFooter = useMemo(() => {
3241
+ return renderClassStatus('rls-picker-date-range__footer', { automatic });
3242
+ }, [automatic]);
3243
+ const title = useMemo(() => rangeFormatTemplate(value), [value]);
3244
+ useEffect(() => {
3245
+ return i18nSubscribe(() => {
3246
+ setLabels({
3247
+ dateActionCancel: reactI18n('dateActionCancel'),
3248
+ dateActionSelect: reactI18n('dateActionSelect')
3249
+ });
3250
+ });
3251
+ }, []);
3252
+ useEffect(() => {
3253
+ setVisibility('DAY');
3254
+ }, [rangeControl.value]);
3255
+ const onVisibilityDay = useCallback(() => {
3256
+ setVisibility('DAY');
3257
+ }, []);
3258
+ const onVisibilityTitle = useCallback((type) => {
3259
+ type === 'month' ? setVisibility('MONTH') : setVisibility('YEAR');
3260
+ }, []);
3261
+ const onCancel = useCallback(() => {
3262
+ onListener?.({ event: PickerListenerEvent.Cancel });
3263
+ }, [onListener]);
3264
+ const onSelect = useCallback(() => {
3265
+ formControl?.setValue(value);
3266
+ onListener?.({ event: PickerListenerEvent.Select, value });
3267
+ }, [formControl, value, onListener]);
3268
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-picker-date-range", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: "rls-picker-date-range__header", children: [jsxRuntimeExports.jsx(RlsPickerSelectorTitle, { monthControl: monthControl, yearControl: yearControl, date: date, maxDate: maxDate, minDate: minDate, disabled: visibility === 'YEAR', type: visibility === 'MONTH' ? 'year' : 'month', onClick: onVisibilityTitle }), jsxRuntimeExports.jsx("div", { className: "rls-picker-date-range__title", children: jsxRuntimeExports.jsx("span", { onClick: onVisibilityDay, children: title }) })] }), jsxRuntimeExports.jsxs("div", { className: classNameComponent, children: [jsxRuntimeExports.jsx(RlsPickerDayRange, { formControl: rangeControl, date: date, maxDate: maxDate, minDate: minDate, disabled: disabled }), jsxRuntimeExports.jsx(RlsPickerMonth, { formControl: monthControl, year: yearControl.value, maxDate: maxDate, minDate: minDate, disabled: disabled, onValue: onVisibilityDay }), jsxRuntimeExports.jsx(RlsPickerYear, { formControl: yearControl, maxDate: maxDate, minDate: minDate, disabled: disabled, onValue: onVisibilityDay })] }), jsxRuntimeExports.jsx("div", { className: classNameFooter, children: jsxRuntimeExports.jsxs("div", { className: "rls-picker-date-range__actions", children: [jsxRuntimeExports.jsx("div", { className: "rls-picker-date-range__actions--cancel", children: jsxRuntimeExports.jsx(RlsButton, { type: "flat", onClick: onCancel, children: labels.dateActionCancel }) }), jsxRuntimeExports.jsx("div", { className: "rls-picker-date-range__actions--ok", children: jsxRuntimeExports.jsx(RlsButton, { type: "gradient", onClick: onSelect, children: labels.dateActionSelect }) })] }) })] }));
3269
+ }
3270
+
3271
+ function RlsFieldDateRange({ children, date, disabled: disabledProps, formControl, identifier, maxDate, minDate, msgErrorDisabled, onValue, placeholder, readOnly, rlsTheme, value: valueInitial }) {
3272
+ const currentDate = useMemo(() => date ?? new Date(), [date]);
3273
+ const [value, setValue] = useState(formControl?.value || valueInitial);
3274
+ const [modalIsVisible, setModalIsVisible] = useState(false);
3275
+ const disabled = useMemo(() => {
3276
+ return formControl?.disabled || disabledProps;
3277
+ }, [formControl?.disabled, disabledProps]);
3278
+ const className = useMemo(() => {
3279
+ return renderClassStatus('rls-field-box', {
3280
+ disabled,
3281
+ readonly: readOnly
3282
+ });
3283
+ }, [disabled, readOnly]);
3284
+ const dateRangeValue = useMemo(() => {
3285
+ return formControl ? formControl.value : value;
3286
+ }, [formControl?.value, value]);
3287
+ const status = useMemo(() => {
3288
+ return {
3289
+ icon: dateRangeValue ? 'trash-2' : 'calendar',
3290
+ valueInput: dateRangeValue ? rangeFormatTemplate(dateRangeValue) : ''
3291
+ };
3292
+ }, [dateRangeValue]);
3293
+ const onClickInput = useCallback(() => {
3294
+ !readOnly && setModalIsVisible(true);
3295
+ }, [readOnly]);
3296
+ const onChange = useCallback((value) => {
3297
+ setValue(value);
3298
+ onValue?.(value);
3299
+ }, [onValue]);
3300
+ const onClickAction = useCallback(() => {
3301
+ if (dateRangeValue) {
3302
+ formControl?.setValue(valueInitial);
3303
+ formControl?.touch();
3304
+ onChange(valueInitial);
3305
+ }
3306
+ else {
3307
+ setModalIsVisible(true);
3308
+ }
3309
+ }, [dateRangeValue, formControl, valueInitial, onChange]);
3310
+ const onListener = useCallback(({ event, value }) => {
3311
+ event !== PickerListenerEvent.Cancel && onChange(value);
3312
+ formControl?.touch();
3313
+ setModalIsVisible(false);
3314
+ }, [formControl, onChange]);
3315
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: "rls-field-date-range", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: className, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-date-range__control", type: "text", value: status.valueInput, readOnly: true, placeholder: placeholder, onClick: onClickInput, disabled: disabled }), !readOnly && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: status.icon, onClick: onClickAction, disabled: disabled }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }), jsxRuntimeExports.jsx(RlsModal, { className: "rls-field-date-range-modal", visible: modalIsVisible, rlsTheme: rlsTheme, children: jsxRuntimeExports.jsx(RlsPickerDateRange, { formControl: formControl, date: currentDate, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: onListener }) })] }));
3316
+ }
3317
+
3318
+ function useFieldSelect(props) {
3319
+ const controller = useListController(props);
3320
+ useEffect(() => {
3321
+ props.disabled && controller.setState({ focused: false });
3322
+ }, [props.disabled]);
3323
+ const onFocusInput = useCallback(() => {
3324
+ controller.setState({ focused: true });
3325
+ }, [controller.setState]);
3326
+ const onBlurInput = useCallback(() => {
3327
+ controller.setState({ focused: false });
3328
+ }, [controller.setState]);
3329
+ const onClickInput = useCallback(() => {
3330
+ !props.readOnly && controller.setState({ listIsVisible: true });
3331
+ }, [controller.setState, props.readOnly]);
3332
+ const onKeydownInput = useCallback((event) => {
3333
+ switch (event.code) {
3334
+ case 'Space':
3335
+ case 'Enter':
3336
+ controller.setState({ listIsVisible: true });
3337
+ break;
3338
+ case 'Escape':
3339
+ case 'Tab':
3340
+ controller.setState({ listIsVisible: false });
3341
+ break;
3342
+ default:
3343
+ controller.navigationInput(event);
3344
+ break;
3345
+ }
3346
+ }, [controller.setState, controller.navigationInput]);
3347
+ const onClickAction = useCallback(() => {
3348
+ const removable = !props.unremovable && !!controller.value;
3349
+ if (removable) {
3350
+ controller.setState({ listIsVisible: false });
3351
+ controller.setFormValue(undefined);
3352
+ props.onValue?.(props.value);
3353
+ }
3354
+ else {
3355
+ const listIsVisible = !controller.listIsVisible;
3356
+ controller.setState({ listIsVisible });
3357
+ listIsVisible && controller.refInput?.current?.focus();
3358
+ }
3359
+ }, [
3360
+ controller.listIsVisible,
3361
+ controller.value,
3362
+ controller.setState,
3363
+ controller.setFormValue,
3364
+ props.unremovable,
3365
+ props.onValue
3366
+ ]);
3367
+ const onClickBackdrop = useCallback(() => {
3368
+ controller.setState({ listIsVisible: false });
3369
+ }, [controller.setState]);
3370
+ const onChange = useCallback((element) => {
3371
+ !props.disabled && controller.refInput?.current?.focus();
3372
+ if (props.onSelect) {
3373
+ controller.setState({ listIsVisible: false });
3374
+ element.value && props.onSelect(element.value);
3375
+ }
3376
+ else {
3377
+ controller.setFormValue(element);
3378
+ controller.setState({ listIsVisible: false });
3379
+ }
3380
+ props.onValue?.(element.value);
3381
+ }, [
3382
+ controller.setState,
3383
+ controller.setFormValue,
3384
+ props.onSelect,
3385
+ props.onValue,
3386
+ props.disabled
3387
+ ]);
3388
+ const onClickElement = useCallback((element) => {
3389
+ return () => {
3390
+ onChange(element);
3391
+ };
3392
+ }, [onChange]);
3393
+ const onKeydownElement = useCallback((element) => {
3394
+ return (event) => {
3395
+ event.code === 'Enter'
3396
+ ? onChange(element)
3397
+ : controller.navigationElement(event);
3398
+ };
3399
+ }, [onChange, controller.navigationElement]);
3400
+ return {
3401
+ ...controller,
3402
+ onBlurInput,
3403
+ onClickAction,
3404
+ onClickBackdrop,
3405
+ onClickInput,
3406
+ onClickElement,
3407
+ onFocusInput,
3408
+ onKeydownElement,
3409
+ onKeydownInput
3410
+ };
3411
+ }
3412
+
3413
+ function RlsFieldSelectTemplate(props) {
3414
+ const select = useFieldSelect(props);
3415
+ const { render, suggestions, action, children, formControl, msgErrorDisabled, placeholder, rlsTheme, unremovable } = props;
3416
+ const disabled = useMemo(() => {
3417
+ return formControl?.disabled || props.disabled;
3418
+ }, [formControl?.disabled, props.disabled]);
3419
+ const className = useMemo(() => {
3420
+ return renderClassStatus('rls-field-box', {
3421
+ focused: select.focused && !disabled,
3422
+ error: formControl?.wrong,
3423
+ disabled: disabled,
3424
+ readonly: props.readOnly
3425
+ }, `rls-field-list rls-field-select ${props.className ?? ''}`);
3426
+ }, [
3427
+ formControl?.wrong,
3428
+ select.focused,
3429
+ props.className,
3430
+ props.readOnly,
3431
+ disabled
3432
+ ]);
3433
+ return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: select.refContent, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { ref: select.refInput, className: "rls-field-list__control", readOnly: true, placeholder: placeholder, value: select.value, onFocus: select.onFocusInput, onBlur: select.onBlurInput, onClick: select.onClickInput, onKeyDown: select.onKeydownInput, disabled: disabled }), !props.readOnly && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: !unremovable && !!select.value ? 'close' : 'arrow-ios-down', onClick: select.onClickAction, disabled: disabled }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl })), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: suggestions, visible: select.listIsVisible, action: action, disabled: disabled, higher: select.higher, render: render, refList: select.refList, onClickElement: select.onClickElement, onKeydownElement: select.onKeydownElement, onClickBackdrop: select.onClickBackdrop })] }));
3434
+ }
3435
+ function RlsFieldSelect(props) {
3436
+ const render = useCallback((element) => (jsxRuntimeExports.jsx(RlsBallot, { className: "rls-field-list__ballot", subtitle: element.subtitle, img: element.img, initials: element.initials, children: jsxRuntimeExports.jsx("span", { children: element.title }) })), []);
3437
+ return jsxRuntimeExports.jsx(RlsFieldSelectTemplate, { ...props, render: render });
3438
+ }
3439
+
3440
+ function RlsPickerColor({ color, formControl, onListener, rlsTheme }) {
3441
+ const initialColor = useMemo(() => formControl?.value ?? color ?? DEFAULT_COLOR, []);
3442
+ const initialHsv = useMemo(() => hexToHsv(initialColor) ?? { h: 258, s: 100, v: 100 }, []);
3443
+ const canvasRef = useRef(null);
3444
+ const hueRef = useRef(null);
3445
+ const alphaRef = useRef(null);
3446
+ const selectionIsActive = useRef(false);
3447
+ const activeSlider = useRef(null);
3448
+ const hexEditing = useRef(false);
3449
+ const [hsv, setHsv] = useState(initialHsv);
3450
+ const [alpha, setAlpha] = useState(1);
3451
+ const [hexInput, setHexInput] = useState(initialColor);
3452
+ const [labels, setLabels] = useState({
3453
+ colorActionCancel: reactI18n('dateActionCancel'),
3454
+ colorActionSelect: reactI18n('dateActionSelect')
3455
+ });
3456
+ const hexColor = useMemo(() => hsvToHex(hsv), [hsv]);
3457
+ const hexValue = useMemo(() => {
3458
+ return hexInput.replace('#', '');
3459
+ }, [hexInput]);
3460
+ const canvasStyle = useMemo(() => {
3461
+ const { r, g, b } = hsvToRgb({ h: hsv.h, s: 100, v: 100 });
3462
+ return {
3463
+ background: `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent), rgb(${r}, ${g}, ${b})`
3464
+ };
3465
+ }, [hsv.h]);
3466
+ const indicatorPosition = useMemo(() => {
3467
+ return {
3468
+ left: `${(hsv.s / 100) * 100}%`,
3469
+ top: `${100 - (hsv.v / 100) * 100}%`
3470
+ };
3471
+ }, [hsv.s, hsv.v]);
3472
+ const hueSliderStyle = useMemo(() => {
3473
+ return {
3474
+ background: 'linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%)'
3475
+ };
3476
+ }, []);
3477
+ const hueIndicatorStyle = useMemo(() => {
3478
+ return { left: `${(hsv.h / 360) * 100}%`, backgroundColor: hexColor };
3479
+ }, [hsv.h, hexColor]);
3480
+ const alphaSliderStyle = useMemo(() => {
3481
+ return {
3482
+ background: `linear-gradient(to right, transparent, ${hexColor})`
3483
+ };
3484
+ }, [hexColor]);
3485
+ const alphaIndicatorStyle = useMemo(() => {
3486
+ return { left: `${alpha * 100}%`, backgroundColor: hexColor };
3487
+ }, [alpha, hexColor]);
3488
+ useEffect(() => {
3489
+ !hexEditing.current && setHexInput(hexColor);
3490
+ }, [hexColor]);
3491
+ useEffect(() => {
3492
+ return i18nSubscribe(() => {
3493
+ setLabels({
3494
+ colorActionCancel: reactI18n('dateActionCancel'),
3495
+ colorActionSelect: reactI18n('dateActionSelect')
3496
+ });
3497
+ });
3498
+ }, []);
3499
+ const getPositionInElement = useCallback((element, clientX, clientY) => {
3500
+ const rect = element.getBoundingClientRect();
3501
+ return {
3502
+ x: (clientX - rect.left) / rect.width,
3503
+ y: (clientY - rect.top) / rect.height
3504
+ };
3505
+ }, []);
3506
+ const updateColorOnCanvas = useEffectEvent((clientX, clientY) => {
3507
+ if (!canvasRef.current)
3508
+ return;
3509
+ const pos = getPositionInElement(canvasRef.current, clientX, clientY);
3510
+ setHsv((prev) => ({
3511
+ ...prev,
3512
+ s: Math.round(Math.min(1, Math.max(0, pos.x)) * 100),
3513
+ v: Math.round(Math.min(1, Math.max(0, 1 - pos.y)) * 100)
3514
+ }));
3515
+ });
3516
+ const updateHueOnSlider = useEffectEvent((clientX, clientY) => {
3517
+ if (!hueRef.current)
3518
+ return;
3519
+ const pos = getPositionInElement(hueRef.current, clientX, clientY);
3520
+ setHsv((prev) => ({
3521
+ ...prev,
3522
+ h: Math.round(Math.min(1, Math.max(0, pos.x)) * 360)
3523
+ }));
3524
+ });
3525
+ const updateAlphaOnSlider = useEffectEvent((clientX, clientY) => {
3526
+ if (!alphaRef.current)
3527
+ return;
3528
+ const pos = getPositionInElement(alphaRef.current, clientX, clientY);
3529
+ setAlpha(Math.min(1, Math.max(0, pos.x)));
3530
+ });
3531
+ const onMouseDown = useCallback((event) => {
3532
+ const slider = event.currentTarget.dataset.slider;
3533
+ if (!slider)
3534
+ return;
3535
+ event.preventDefault();
3536
+ selectionIsActive.current = true;
3537
+ activeSlider.current = slider;
3538
+ switch (slider) {
3539
+ case 'canvas':
3540
+ updateColorOnCanvas(event.clientX, event.clientY);
3541
+ break;
3542
+ case 'hue':
3543
+ updateHueOnSlider(event.clientX, event.clientY);
3544
+ break;
3545
+ case 'alpha':
3546
+ updateAlphaOnSlider(event.clientX, event.clientY);
3547
+ break;
3548
+ }
3549
+ }, [updateColorOnCanvas, updateHueOnSlider, updateAlphaOnSlider]);
3550
+ const onMouseMove = useCallback((event) => {
3551
+ if (!selectionIsActive.current || !activeSlider.current)
3552
+ return;
3553
+ event.preventDefault();
3554
+ switch (activeSlider.current) {
3555
+ case 'canvas':
3556
+ updateColorOnCanvas(event.clientX, event.clientY);
3557
+ break;
3558
+ case 'hue':
3559
+ updateHueOnSlider(event.clientX, event.clientY);
3560
+ break;
3561
+ case 'alpha':
3562
+ updateAlphaOnSlider(event.clientX, event.clientY);
3563
+ break;
3564
+ }
3565
+ }, [updateColorOnCanvas, updateHueOnSlider, updateAlphaOnSlider]);
3566
+ const onTouchStart = useCallback((event) => {
3567
+ const slider = event.currentTarget.dataset.slider;
3568
+ if (!slider)
3569
+ return;
3570
+ const touch = event.touches.item(0);
3571
+ if (!touch)
3572
+ return;
3573
+ selectionIsActive.current = true;
3574
+ activeSlider.current = slider;
3575
+ switch (slider) {
3576
+ case 'canvas':
3577
+ updateColorOnCanvas(touch.clientX, touch.clientY);
3578
+ break;
3579
+ case 'hue':
3580
+ updateHueOnSlider(touch.clientX, touch.clientY);
3581
+ break;
3582
+ case 'alpha':
3583
+ updateAlphaOnSlider(touch.clientX, touch.clientY);
3584
+ break;
3585
+ }
3586
+ }, [updateColorOnCanvas, updateHueOnSlider, updateAlphaOnSlider]);
3587
+ const onTouchMove = useCallback((event) => {
3588
+ const touch = event.touches.item(0);
3589
+ if (!selectionIsActive.current || !activeSlider.current || !touch)
3590
+ return;
3591
+ switch (activeSlider.current) {
3592
+ case 'canvas':
3593
+ updateColorOnCanvas(touch.clientX, touch.clientY);
3594
+ break;
3595
+ case 'hue':
3596
+ updateHueOnSlider(touch.clientX, touch.clientY);
3597
+ break;
3598
+ case 'alpha':
3599
+ updateAlphaOnSlider(touch.clientX, touch.clientY);
3600
+ break;
3601
+ }
3602
+ }, [updateColorOnCanvas, updateHueOnSlider, updateAlphaOnSlider]);
3603
+ const onInactiveSelection = useCallback(() => {
3604
+ selectionIsActive.current = false;
3605
+ activeSlider.current = null;
3606
+ }, []);
3607
+ const onHexChange = useCallback((value) => {
3608
+ setHexInput(value);
3609
+ const normalized = normalizeHex(value);
3610
+ if (normalized) {
3611
+ const hsv = hexToHsv(normalized);
3612
+ hsv && setHsv(hsv);
3613
+ }
3614
+ }, []);
3615
+ const onHexFocus = useCallback(() => {
3616
+ hexEditing.current = true;
3617
+ }, []);
3618
+ const onHexBlur = useEffectEvent(() => {
3619
+ hexEditing.current = false;
3620
+ const normalized = normalizeHex(hexInput);
3621
+ if (normalized) {
3622
+ setHexInput(normalized);
3623
+ }
3624
+ else {
3625
+ setHexInput(hexColor);
3626
+ }
3627
+ });
3628
+ const onHexKeyDown = useCallback((event) => {
3629
+ event.key === 'Enter' && onHexBlur();
3630
+ }, [onHexBlur]);
3631
+ const onHexInputChange = useCallback((event) => onHexChange(event.target.value ? `#${event.target.value}` : ''), [onHexChange]);
3632
+ const onCancel = useCallback(() => {
3633
+ onListener?.({ event: PickerListenerEvent.Cancel });
3634
+ }, [onListener]);
3635
+ const onSelect = useCallback(() => {
3636
+ formControl?.setValue(hexColor);
3637
+ onListener?.({ event: PickerListenerEvent.Select, value: hexColor });
3638
+ }, [formControl, hexColor, onListener]);
3639
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-picker-color", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-picker-color__preview", children: jsxRuntimeExports.jsx("div", { ref: canvasRef, className: "rls-picker-color__canvas", style: canvasStyle, "data-slider": "canvas", onMouseDown: onMouseDown, onMouseMove: onMouseMove, onMouseUp: onInactiveSelection, onMouseLeave: onInactiveSelection, onTouchStart: onTouchStart, onTouchMove: onTouchMove, onTouchEnd: onInactiveSelection, children: jsxRuntimeExports.jsx("div", { className: "rls-picker-color__indicator", style: {
3640
+ left: indicatorPosition.left,
3641
+ top: indicatorPosition.top
3642
+ }, children: jsxRuntimeExports.jsx("div", { className: "rls-picker-color__indicator__circle", style: { backgroundColor: hexColor } }) }) }) }), jsxRuntimeExports.jsxs("div", { className: "rls-picker-color__controls", children: [jsxRuntimeExports.jsx("div", { className: "rls-picker-color__slider", children: jsxRuntimeExports.jsx("div", { ref: hueRef, className: "rls-picker-color__slider__track", style: hueSliderStyle, "data-slider": "hue", onMouseDown: onMouseDown, onMouseMove: onMouseMove, onMouseUp: onInactiveSelection, onMouseLeave: onInactiveSelection, onTouchStart: onTouchStart, onTouchMove: onTouchMove, onTouchEnd: onInactiveSelection, children: jsxRuntimeExports.jsx("div", { className: "rls-picker-color__slider__thumb", style: hueIndicatorStyle }) }) }), jsxRuntimeExports.jsx("div", { className: "rls-picker-color__slider", children: jsxRuntimeExports.jsx("div", { ref: alphaRef, className: "rls-picker-color__slider__track rls-picker-color__slider__track--alpha", style: alphaSliderStyle, "data-slider": "alpha", onMouseDown: onMouseDown, onMouseMove: onMouseMove, onMouseUp: onInactiveSelection, onMouseLeave: onInactiveSelection, onTouchStart: onTouchStart, onTouchMove: onTouchMove, onTouchEnd: onInactiveSelection, children: jsxRuntimeExports.jsx("div", { className: "rls-picker-color__slider__thumb", style: alphaIndicatorStyle }) }) })] }), jsxRuntimeExports.jsx("div", { className: "rls-picker-color__footer", children: jsxRuntimeExports.jsxs("div", { className: "rls-picker-color__hex", children: [jsxRuntimeExports.jsx("div", { className: "rls-picker-color__hex__swatch", style: { backgroundColor: hexColor } }), jsxRuntimeExports.jsx("span", { className: "rls-picker-color__hex__prefix", children: "#" }), jsxRuntimeExports.jsx("input", { className: "rls-picker-color__hex__input", type: "text", maxLength: 6, value: hexValue, onChange: onHexInputChange, onFocus: onHexFocus, onBlur: onHexBlur, onKeyDown: onHexKeyDown })] }) }), jsxRuntimeExports.jsxs("div", { className: "rls-picker-color__actions", children: [jsxRuntimeExports.jsx("div", { className: "rls-picker-color__actions--cancel", children: jsxRuntimeExports.jsx(RlsButton, { type: "flat", onClick: onCancel, children: labels.colorActionCancel }) }), jsxRuntimeExports.jsx("div", { className: "rls-picker-color__actions--ok", children: jsxRuntimeExports.jsx(RlsButton, { type: "gradient", onClick: onSelect, children: labels.colorActionSelect }) })] })] }));
3643
+ }
3644
+
3645
+ function RlsFieldColor({ children, color, disabled: disabledProps, formControl, identifier, msgErrorDisabled, onValue, placeholder, readOnly, rlsTheme, value: valueInitial }) {
3646
+ const [value, setValue] = useState(formControl?.value ?? valueInitial);
3647
+ const [modalIsVisible, setModalIsVisible] = useState(false);
3648
+ const colorValue = useMemo(() => {
3649
+ return formControl ? formControl.value : value;
3650
+ }, [formControl?.value, value]);
3651
+ const disabled = useMemo(() => {
3652
+ return formControl?.disabled || disabledProps;
3653
+ }, [formControl?.disabled, disabledProps]);
3654
+ const className = useMemo(() => {
3655
+ return renderClassStatus('rls-field-box', {
3656
+ disabled,
3657
+ readonly: readOnly
3658
+ });
3659
+ }, [disabled, readOnly]);
3660
+ const displayHex = useMemo(() => {
3661
+ const hex = colorValue && hexIsValid(colorValue) ? colorValue : '';
3662
+ return normalizeHex(hex);
3663
+ }, [colorValue]);
3664
+ const onClickInput = useCallback(() => {
3665
+ !readOnly && setModalIsVisible(true);
3666
+ }, [readOnly]);
3667
+ const onChange = useCallback((value) => {
3668
+ setValue(value);
3669
+ onValue?.(value);
3670
+ }, [onValue]);
3671
+ const onClickAction = useCallback(() => {
3672
+ if (colorValue) {
3673
+ formControl?.setValue(valueInitial);
3674
+ formControl?.touch();
3675
+ onChange(valueInitial);
3676
+ }
3677
+ else {
3678
+ setModalIsVisible(true);
3679
+ }
3680
+ }, [colorValue, formControl, valueInitial, onChange]);
3681
+ const onListener = useCallback(({ event, value }) => {
3682
+ event !== PickerListenerEvent.Cancel && onChange(value);
3683
+ formControl?.touch();
3684
+ setModalIsVisible(false);
3685
+ }, [formControl, onChange]);
3686
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: "rls-field-color", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: className, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [displayHex && (jsxRuntimeExports.jsx("div", { className: "rls-field-color__swatch", style: { backgroundColor: displayHex } })), jsxRuntimeExports.jsx("input", { className: "rls-field-color__control", type: "text", value: displayHex, readOnly: true, placeholder: placeholder, onClick: onClickInput, disabled: disabled }), !readOnly && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: colorValue ? 'trash-2' : 'color-palette', onClick: onClickAction, disabled: disabled }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }), jsxRuntimeExports.jsx(RlsModal, { className: "rls-field-color-modal", visible: modalIsVisible, rlsTheme: rlsTheme, children: jsxRuntimeExports.jsx(RlsPickerColor, { formControl: formControl, color: color, disabled: disabled, onListener: onListener }) })] }));
3687
+ }
3688
+
3689
+ const MAX_LIST_HEIGHT_REM = 90;
3690
+ const FALLBACK_REM_SIZE = 16;
3691
+ function getRemSize() {
3692
+ if (typeof window === 'undefined') {
3693
+ return FALLBACK_REM_SIZE;
3694
+ }
3695
+ const fontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
3696
+ return fontSize > 0 ? fontSize : FALLBACK_REM_SIZE;
3697
+ }
3698
+ function shouldDisplayHigher(content, list) {
3699
+ if (!content) {
3700
+ return false;
3701
+ }
3702
+ const { top, bottom } = content.getBoundingClientRect();
3703
+ const spaceAbove = top;
3704
+ const spaceBelow = window.innerHeight - bottom;
3705
+ const maxHeight = MAX_LIST_HEIGHT_REM * getRemSize();
3706
+ const desiredHeight = Math.min(list?.scrollHeight || maxHeight, maxHeight);
3707
+ if (spaceBelow >= desiredHeight) {
3708
+ return false;
3709
+ }
3710
+ if (spaceAbove >= desiredHeight) {
3711
+ return true;
3712
+ }
3713
+ return spaceAbove > spaceBelow;
3714
+ }
3715
+ function useFieldList(props) {
3716
+ const { suggestions, disabled } = props;
3717
+ const refContent = useRef(null);
3718
+ const refList = useRef(null);
3719
+ const formControl = props.formControl;
3720
+ const [state, setState] = useState({
3721
+ higher: false,
3722
+ listIsVisible: false
3723
+ });
3724
+ const [selected, setSelected] = useState([]);
3725
+ useEffect(() => {
3726
+ function onCloseSuggestions({ target }) {
3727
+ !refContent?.current?.contains(target) &&
3728
+ setState((state) => ({ ...state, listIsVisible: false }));
3729
+ }
3730
+ document.addEventListener('click', onCloseSuggestions);
3731
+ return () => {
3732
+ document.removeEventListener('click', onCloseSuggestions);
3733
+ };
3734
+ }, []);
3735
+ useEffect(() => {
3736
+ const formValue = formControl?.value;
3737
+ if (formValue !== undefined && formValue !== null && formValue.length) {
3738
+ const selectedElements = suggestions.filter((state) => formValue.some((value) => state.compareTo(value)));
3739
+ setSelected(selectedElements);
3740
+ }
3741
+ else {
3742
+ setSelected([]);
3743
+ }
3744
+ }, [formControl?.value, suggestions]);
3745
+ const setListState = useCallback((updates) => {
3746
+ setState((state) => {
3747
+ const _updates = updates.listIsVisible !== undefined
3748
+ ? {
3749
+ ...updates,
3750
+ ...(updates.listIsVisible
3751
+ ? {
3752
+ higher: shouldDisplayHigher(refContent.current, refList.current)
3753
+ }
3754
+ : {})
3755
+ }
3756
+ : updates;
3757
+ return { ...state, ..._updates };
3758
+ });
3759
+ }, []);
3760
+ const toggleElement = useCallback((element) => {
3761
+ const alreadySelected = selected.some((state) => state.compareTo(element.value));
3762
+ const newSelected = alreadySelected
3763
+ ? selected.filter((state) => !state.compareTo(element.value))
3764
+ : [...selected, element];
3765
+ const newValues = newSelected.map((state) => state.value);
3766
+ setSelected(newSelected);
3767
+ formControl?.setValue(newValues);
3768
+ props.onValue?.(newValues);
3769
+ }, [selected, formControl, props.onValue]);
3770
+ const isSelected = useCallback((element) => {
3771
+ return selected.some((state) => state.compareTo(element.value));
3772
+ }, [selected]);
3773
+ const onClickInput = useCallback(() => {
3774
+ if (!props.readOnly) {
3775
+ setListState({ listIsVisible: true });
3776
+ }
3777
+ }, [setListState, props.readOnly]);
3778
+ const onClickBackdrop = useCallback(() => {
3779
+ setListState({ listIsVisible: false });
3780
+ }, [setListState]);
3781
+ const onClickAction = useCallback(() => {
3782
+ if (!disabled && !props.readOnly) {
3783
+ setListState({ listIsVisible: !state.listIsVisible });
3784
+ }
3785
+ }, [disabled, props.readOnly, setListState, state.listIsVisible]);
3786
+ const onClickElement = useCallback((element) => {
3787
+ return () => {
3788
+ toggleElement(element);
3789
+ };
3790
+ }, [toggleElement]);
3791
+ const onRemoveElement = useCallback((element) => {
3792
+ return (event) => {
3793
+ event.stopPropagation();
3794
+ const newSelected = selected.filter((state) => !state.compareTo(element.value));
3795
+ const newValues = newSelected.map((state) => state.value);
3796
+ setSelected(newSelected);
3797
+ formControl?.setValue(newValues);
3798
+ props.onValue?.(newValues);
3799
+ };
3800
+ }, [selected, formControl, props.onValue]);
3801
+ const onKeydownElement = useCallback((element) => {
3802
+ return (event) => {
3803
+ event.code === 'Enter' && toggleElement(element);
3804
+ };
3805
+ }, [toggleElement]);
3806
+ return {
3807
+ ...state,
3808
+ selected,
3809
+ refContent,
3810
+ refList,
3811
+ isSelected,
3812
+ onClickAction,
3813
+ onClickBackdrop,
3814
+ onClickElement,
3815
+ onClickInput,
3816
+ onKeydownElement,
3817
+ onRemoveElement
3818
+ };
3819
+ }
3820
+
3821
+ function RlsFieldListInner({ render, suggestions, action, children, formControl, fieldList, msgErrorDisabled, placeholder, rlsTheme, ...props }) {
3822
+ const disabled = useMemo(() => {
3823
+ return formControl?.disabled || props.disabled;
3824
+ }, [formControl?.disabled, props.disabled]);
3825
+ const className = useMemo(() => {
3826
+ return renderClassStatus('rls-field-box', {
3827
+ focused: fieldList.listIsVisible && !disabled,
3828
+ error: formControl?.wrong,
3829
+ disabled,
3830
+ readonly: props.readOnly
3831
+ }, `rls-field-list rls-field-list__multi ${props.className ?? ''}`);
3832
+ }, [
3833
+ formControl?.wrong,
3834
+ fieldList.listIsVisible,
3835
+ props.className,
3836
+ props.readOnly,
3837
+ disabled
3838
+ ]);
3839
+ const renderWithCheckbox = useCallback((element) => (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__multi__element", children: [jsxRuntimeExports.jsx(RlsCheckBox, { checked: fieldList.isSelected(element) }), render(element)] })), [fieldList.isSelected, render]);
3840
+ return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: fieldList.refContent, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("div", { className: "rls-field-list__multi__chips", onClick: disabled ? undefined : fieldList.onClickInput, children: !fieldList.selected.length && placeholder ? (jsxRuntimeExports.jsx("span", { className: "rls-field-list__multi__placeholder", children: placeholder })) : (fieldList.selected.map((item, index) => (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__multi__chip", children: [jsxRuntimeExports.jsx("span", { className: "rls-field-list__multi__chip__description", children: item.description }), !props.readOnly && (jsxRuntimeExports.jsx("button", { className: "rls-field-list__multi__chip__remove", onClick: fieldList.onRemoveElement(item), disabled: disabled, children: jsxRuntimeExports.jsx(RlsIcon, { value: "close" }) }))] }, index)))) }), !props.readOnly && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: "arrow-ios-down", onClick: fieldList.onClickAction, disabled: disabled }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl })), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: suggestions, visible: fieldList.listIsVisible, action: action, disabled: disabled, higher: fieldList.higher, render: renderWithCheckbox, refList: fieldList.refList, onClickElement: fieldList.onClickElement, onKeydownElement: fieldList.onKeydownElement, onClickBackdrop: fieldList.onClickBackdrop })] }));
3841
+ }
3842
+ function RlsFieldListTemplate(props) {
3843
+ const fieldList = useFieldList(props);
3844
+ return jsxRuntimeExports.jsx(RlsFieldListInner, { ...props, fieldList: fieldList });
3845
+ }
3846
+ function RlsFieldList(props) {
3847
+ const fieldList = useFieldList(props);
3848
+ const render = useCallback((element) => (jsxRuntimeExports.jsx(RlsBallot, { className: "rls-field-list__ballot", subtitle: element.subtitle, img: element.img, initials: element.initials, children: jsxRuntimeExports.jsx("span", { children: element.title }) })), []);
3849
+ return jsxRuntimeExports.jsx(RlsFieldListInner, { ...props, render: render, fieldList: fieldList });
3850
+ }
3851
+
3852
+ function RlsFormNavigation({ children, className, controller, visible, rlsTheme }) {
3853
+ const classNameForm = useMemo(() => {
3854
+ return renderClassStatus('rls-form-navigation', { visible: controller?.visible ?? visible }, className);
3855
+ }, [className, visible, controller?.visible]);
3856
+ return ReactDOM.createPortal(jsxRuntimeExports.jsx("div", { className: classNameForm, "rls-theme": rlsTheme, children: jsxRuntimeExports.jsx("div", { className: "rls-form-navigation__component", children: children }) }), document.body);
3857
+ }
3858
+
3859
+ function useRelocationOnComponent({ container, element, onDrag }) {
3860
+ const position = useRef({ x: 0, y: 0 });
3861
+ const dragOffset = useRef({ x: 0, y: 0 });
3862
+ const dragging = useRef(false);
3863
+ const getClientX = useCallback((positionX) => {
3864
+ let clientX = position.current.x + positionX - dragOffset.current.x;
3865
+ if (clientX < 0) {
3866
+ clientX = 0;
3867
+ }
3868
+ else {
3869
+ const width = clientX + element.current.offsetWidth;
3870
+ if (width > container.current.offsetWidth) {
3871
+ clientX = container.current.offsetWidth - element.current.offsetWidth;
3872
+ }
3873
+ }
3874
+ return clientX;
3875
+ }, []);
3876
+ const getClientY = useCallback((positionY) => {
3877
+ let clientY = position.current.y + positionY - dragOffset.current.y;
3878
+ if (clientY < 0) {
3879
+ clientY = 0;
3880
+ }
3881
+ else {
3882
+ const height = clientY + element.current.offsetHeight;
3883
+ if (height > container.current.offsetHeight) {
3884
+ clientY = container.current.offsetHeight - element.current.offsetHeight;
3885
+ }
3886
+ }
3887
+ return clientY;
3888
+ }, []);
3889
+ const start = useCallback((positionX, positionY) => {
3890
+ dragOffset.current = {
3891
+ x: positionX,
3892
+ y: positionY
3893
+ };
3894
+ position.current = {
3895
+ x: element.current.offsetLeft,
3896
+ y: element.current.offsetTop
3897
+ };
3898
+ dragging.current = true;
3899
+ }, []);
3900
+ const relocation = useCallback((positionX, positionY) => {
3901
+ const clientX = getClientX(positionX);
3902
+ const clientY = getClientY(positionY);
3903
+ element.current.style.top = `${clientY}px`;
3904
+ element.current.style.left = `${clientX}px`;
3905
+ onDrag?.();
3906
+ }, []);
3907
+ useEffect(() => {
3908
+ const mousedown = (event) => {
3909
+ start(event.clientX, event.clientY);
3910
+ };
3911
+ const mousemove = (event) => {
3912
+ if (dragging.current) {
3913
+ relocation(event.clientX, event.clientY);
3914
+ event.preventDefault();
3915
+ }
3916
+ };
3917
+ const mouseup = () => {
3918
+ dragging.current = false;
3919
+ };
3920
+ const touchstart = (event) => {
3921
+ if (event.touches[0]) {
3922
+ start(event.touches[0].clientX, event.touches[0].clientY);
3923
+ }
3924
+ };
3925
+ const touchmove = (event) => {
3926
+ if (event.touches[0] && dragging.current) {
3927
+ relocation(event.touches[0].clientX, event.touches[0].clientY);
3928
+ event.preventDefault();
3929
+ }
3930
+ };
3931
+ const touchend = () => {
3932
+ dragging.current = false;
3933
+ };
3934
+ element.current.addEventListener('mousedown', mousedown);
3935
+ element.current.addEventListener('mousemove', mousemove);
3936
+ element.current.addEventListener('mouseup', mouseup);
3937
+ element.current.addEventListener('touchstart', touchstart);
3938
+ element.current.addEventListener('touchmove', touchmove);
3939
+ element.current.addEventListener('touchend', touchend);
3940
+ return () => {
3941
+ element.current?.removeEventListener('mousedown', mousedown);
3942
+ element.current?.removeEventListener('mousemove', mousemove);
3943
+ element.current?.removeEventListener('mouseup', mouseup);
3944
+ element.current?.removeEventListener('touchstart', touchstart);
3945
+ element.current?.removeEventListener('touchmove', touchmove);
3946
+ element.current?.removeEventListener('touchend', touchend);
3947
+ };
3948
+ }, []);
3949
+ }
3950
+
3951
+ function useResize(props) {
3952
+ const { refElement, onResize } = props;
3953
+ const dimension = useRef({ height: 0, width: 0 });
3954
+ const observer = useCallback((entries) => {
3955
+ const { height, width } = entries[0].contentRect;
3956
+ onResize &&
3957
+ onResize({
3958
+ current: dimension.current,
3959
+ dimension: {
3960
+ height,
3961
+ width
3962
+ }
3963
+ });
3964
+ dimension.current = { height, width };
3965
+ }, []);
3966
+ useEffect(() => {
3967
+ dimension.current = {
3968
+ height: refElement.current.offsetHeight,
3969
+ width: refElement.current.offsetWidth
3970
+ };
3971
+ const resizeObserver = new ResizeObserver(observer);
3972
+ resizeObserver.observe(refElement.current);
3973
+ return () => {
3974
+ resizeObserver.disconnect();
3975
+ };
3976
+ }, []);
3977
+ }
3978
+
3979
+ const MIN_SLIDER_VALUE = 50;
3980
+ const MAX_SLIDER_VALUE = 100;
3981
+ function getRatioFactor(ratio) {
3982
+ switch (ratio) {
3983
+ case '16:9':
3984
+ return 9 / 16;
3985
+ case '8:5':
3986
+ return 5 / 8;
3987
+ case '4:3':
3988
+ return 3 / 4;
3989
+ case '3:4':
3990
+ return 4 / 3;
3991
+ case '3:2':
3992
+ return 2 / 3;
3993
+ default:
3994
+ return 1;
3995
+ }
3996
+ }
3997
+ function simpleThreeRule(a1, b1, a2) {
3998
+ return (b1 * a2) / a1;
3999
+ }
4000
+ function calculateImgDimension(image, dimension) {
4001
+ let { height, width } = image;
4002
+ if (height > width) {
4003
+ height = height > dimension ? dimension : height;
4004
+ width = simpleThreeRule(image.height, height, width);
4005
+ return { height, width };
4006
+ }
4007
+ width = width > dimension ? dimension : width;
4008
+ height = simpleThreeRule(image.width, width, height);
4009
+ return { height, width };
4010
+ }
4011
+ function RlsImageEditor(props) {
4012
+ const [selection, setSelection] = useState(props.selection ?? 60);
4013
+ const [labels, setLabels] = useState({
4014
+ actionRestore: reactI18n('editorImageActionRestore'),
4015
+ actionSelect: reactI18n('editorImageActionSelect')
4016
+ });
4017
+ const refBody = useRef(null);
4018
+ const refImage = useRef(null);
4019
+ const refSelection = useRef(null);
4020
+ const refOverlayTop = useRef(null);
4021
+ const refOverlayBottom = useRef(null);
4022
+ const refOverlayLeft = useRef(null);
4023
+ const refOverlayRight = useRef(null);
4024
+ const refCanvas = useRef(null);
4025
+ const refPicture = useRef(null);
4026
+ const image = useRef(new Image());
4027
+ const originalImage = useRef(undefined);
4028
+ const hasInteracted = useRef(false);
4029
+ const ratio = useMemo(() => {
4030
+ return props.ratio || '1:1';
4031
+ }, [props.ratio]);
4032
+ const getCropProperties = useCallback(() => {
4033
+ return {
4034
+ height: simpleThreeRule(refImage.current.offsetHeight, image.current.height, refSelection.current.offsetHeight),
4035
+ left: simpleThreeRule(refImage.current.offsetWidth, image.current.width, refSelection.current.offsetLeft),
4036
+ top: simpleThreeRule(refImage.current.offsetHeight, image.current.height, refSelection.current.offsetTop),
4037
+ width: simpleThreeRule(refImage.current.offsetWidth, image.current.width, refSelection.current.offsetWidth)
4038
+ };
4039
+ }, []);
4040
+ const refreshOverlaysStyle = useCallback(() => {
4041
+ const width = refSelection.current.offsetWidth;
4042
+ const height = refSelection.current.offsetHeight;
4043
+ const top = refSelection.current.offsetTop;
4044
+ const left = refSelection.current.offsetLeft;
4045
+ refOverlayTop.current.style.width = `${width}px`;
4046
+ refOverlayTop.current.style.bottom = `calc(100% - ${top}px)`;
4047
+ refOverlayTop.current.style.left = `${left}px`;
4048
+ refOverlayRight.current.style.left = `calc(${width + left}px)`;
4049
+ refOverlayRight.current.style.width = `calc(100% - ${width + left}px)`;
4050
+ refOverlayBottom.current.style.width = `${width}px`;
4051
+ refOverlayBottom.current.style.top = `calc(${height + top}px)`;
4052
+ refOverlayBottom.current.style.left = `${left}px`;
4053
+ refOverlayLeft.current.style.right = `calc(100% - ${left}px)`;
4054
+ refOverlayLeft.current.style.width = `calc(${left}px)`;
4055
+ }, []);
4056
+ const refreshSelectionFromWidth = useCallback((rateSelection) => {
4057
+ const ratioFactor = getRatioFactor(ratio);
4058
+ const _ratio = rateSelection * ratioFactor;
4059
+ const offsetWidth = refImage.current?.offsetWidth || 0;
4060
+ const offsetHeight = refImage.current?.offsetHeight || 0;
4061
+ let width = (offsetWidth * rateSelection) / 100;
4062
+ let height = (offsetWidth * _ratio) / 100;
4063
+ if (height > offsetHeight) {
4064
+ height = offsetHeight;
4065
+ width = height / ratioFactor;
4066
+ }
4067
+ return { height, width };
4068
+ }, [ratio]);
4069
+ const refreshSelectionFromHeight = useCallback((rateSelection) => {
4070
+ const ratioFactor = getRatioFactor(ratio);
4071
+ const _ratio = rateSelection / ratioFactor;
4072
+ const offsetWidth = refImage.current?.offsetWidth || 0;
4073
+ const offsetHeight = refImage.current?.offsetHeight || 0;
4074
+ let height = (offsetHeight * rateSelection) / 100;
4075
+ let width = (offsetHeight * _ratio) / 100;
4076
+ if (width > offsetWidth) {
4077
+ width = offsetWidth;
4078
+ height = width * ratioFactor;
4079
+ }
4080
+ return { height, width };
4081
+ }, [ratio]);
4082
+ const refreshSelectionStyle = useCallback((rateSelection) => {
4083
+ if (refSelection.current &&
4084
+ image.current.width > 0 &&
4085
+ image.current.height > 0) {
4086
+ const { height, width } = image.current.width >= image.current.height
4087
+ ? refreshSelectionFromWidth(rateSelection)
4088
+ : refreshSelectionFromHeight(rateSelection);
4089
+ refSelection.current.style.width = `${width}px`;
4090
+ refSelection.current.style.height = `${height}px`;
4091
+ const left = refImage.current.offsetWidth - width;
4092
+ const top = refImage.current.offsetHeight - height;
4093
+ if (!hasInteracted.current) {
4094
+ refSelection.current.style.left = `${left / 2}px`;
4095
+ refSelection.current.style.top = `${top / 2}px`;
4096
+ }
4097
+ if (refSelection.current.offsetLeft + width >
4098
+ refImage.current.offsetWidth) {
4099
+ refSelection.current.style.left = `${left < 0 ? 0 : left}px`;
4100
+ }
4101
+ if (refSelection.current.offsetTop + height >
4102
+ refImage.current.offsetHeight) {
4103
+ refSelection.current.style.top = `${top < 0 ? 0 : top}px`;
4104
+ }
4105
+ refreshOverlaysStyle();
4106
+ }
4107
+ }, [ratio]);
4108
+ const setImageStyle = useCallback((width, height) => {
4109
+ refImage.current.style.width = width;
4110
+ refImage.current.style.height = height;
4111
+ refCanvas.current.style.width = width;
4112
+ refCanvas.current.style.height = height;
4113
+ }, []);
4114
+ const refreshImageStyle = useCallback(() => {
4115
+ if (image.current.width <= 0 || image.current.height <= 0) {
4116
+ return setImageStyle('0px', '0px');
4117
+ }
4118
+ const height = (refBody.current.offsetWidth * image.current.height) /
4119
+ image.current.width;
4120
+ if (height <= refBody.current.offsetHeight) {
4121
+ return setImageStyle('100%', `${height}px`);
4122
+ }
4123
+ const width = (refBody.current.offsetHeight * image.current.width) /
4124
+ image.current.height;
4125
+ return setImageStyle(`${width}px`, '100%');
4126
+ }, []);
4127
+ useEffect(() => {
4128
+ image.current.onload = () => {
4129
+ const context = refCanvas.current.getContext('2d', {
4130
+ willReadFrequently: true
4131
+ });
4132
+ const width = image.current.width;
4133
+ const height = image.current.height;
4134
+ refCanvas.current.width = width;
4135
+ refCanvas.current.height = height;
4136
+ context?.drawImage(image.current, 0, 0, width, height);
4137
+ originalImage.current = context?.getImageData(0, 0, width, height);
4138
+ refreshImageStyle();
4139
+ refreshSelectionStyle(selection);
4140
+ };
4141
+ const unsubscription = i18nSubscribe(() => {
4142
+ setLabels({
4143
+ actionRestore: reactI18n('editorImageActionRestore'),
4144
+ actionSelect: reactI18n('editorImageActionSelect')
4145
+ });
4146
+ });
4147
+ window.addEventListener('resize', refreshImageStyle);
4148
+ return () => {
4149
+ window.removeEventListener('resize', refreshImageStyle);
4150
+ unsubscription();
4151
+ };
4152
+ }, []);
4153
+ useEffect(() => {
4154
+ image.current.src = props.src || '';
4155
+ }, [props.src]);
4156
+ useEffect(() => {
4157
+ refreshSelectionStyle(selection);
4158
+ }, [ratio, selection]);
4159
+ const onResizeElement = useCallback(() => {
4160
+ refreshSelectionStyle(selection);
4161
+ }, [selection]);
4162
+ useRelocationOnComponent({
4163
+ container: refImage,
4164
+ element: refSelection,
4165
+ onDrag: () => {
4166
+ hasInteracted.current = true;
4167
+ refreshOverlaysStyle();
4168
+ }
4169
+ });
4170
+ useResize({ refElement: refImage, onResize: onResizeElement });
4171
+ const onCropImage = useCallback(() => {
4172
+ const cropProps = getCropProperties();
4173
+ const width = props.maxWidth || cropProps.width;
4174
+ const height = width * getRatioFactor(ratio);
4175
+ refPicture.current.width = width;
4176
+ refPicture.current.height = height;
4177
+ const context = refPicture.current.getContext('2d');
4178
+ context?.drawImage(refCanvas.current, cropProps.left, cropProps.top, cropProps.width, cropProps.height, 0, 0, width, height);
4179
+ refPicture.current.toBlob((blob) => {
4180
+ if (blob) {
4181
+ const reader = new FileReader();
4182
+ reader.readAsDataURL(blob);
4183
+ reader.onloadend = function () {
4184
+ const value = {
4185
+ base64: reader.result,
4186
+ blob
4187
+ };
4188
+ props.onValue?.(value);
4189
+ props.formControl?.setValue(value);
4190
+ };
4191
+ }
4192
+ }, props.mimeType || 'image/jpeg', props.quality || 1);
4193
+ }, [
4194
+ ratio,
4195
+ props.mimeType,
4196
+ props.onValue,
4197
+ props.formControl,
4198
+ props.maxWidth,
4199
+ props.quality
4200
+ ]);
4201
+ const onRestore = useCallback(() => {
4202
+ const context = refCanvas.current.getContext('2d');
4203
+ if (originalImage.current) {
4204
+ context?.putImageData(originalImage.current, 0, 0);
4205
+ }
4206
+ }, []);
4207
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-image-editor", children: [jsxRuntimeExports.jsx("div", { ref: refBody, className: "rls-image-editor__body", children: jsxRuntimeExports.jsxs("div", { ref: refImage, className: "rls-image-editor__body__image", children: [jsxRuntimeExports.jsx("div", { ref: refSelection, className: "rls-image-editor__body__selection" }), jsxRuntimeExports.jsx("div", { ref: refOverlayTop, className: "rls-image-editor__body__overlay--top" }), jsxRuntimeExports.jsx("div", { ref: refOverlayRight, className: "rls-image-editor__body__overlay--right" }), jsxRuntimeExports.jsx("div", { ref: refOverlayBottom, className: "rls-image-editor__body__overlay--bottom" }), jsxRuntimeExports.jsx("div", { ref: refOverlayLeft, className: "rls-image-editor__body__overlay--left" }), jsxRuntimeExports.jsx("canvas", { ref: refCanvas })] }) }), jsxRuntimeExports.jsxs("div", { className: "rls-image-editor__footer", children: [jsxRuntimeExports.jsx("div", { className: "rls-image-editor__sliders", children: jsxRuntimeExports.jsx(RlsSlider, { prefixIcon: "external-link", value: selection, minValue: MIN_SLIDER_VALUE, maxValue: MAX_SLIDER_VALUE, onValue: setSelection, disabled: props.disabled }) }), jsxRuntimeExports.jsxs("div", { className: "rls-image-editor__actions", children: [props.children, jsxRuntimeExports.jsx(RlsButton, { type: "flat", rlsTheme: "standard", prefixIcon: "refresh", onClick: onRestore, disabled: props.disabled, children: labels.actionRestore }), jsxRuntimeExports.jsx(RlsButton, { type: "raised", rlsTheme: "primary", prefixIcon: "crop", onClick: onCropImage, disabled: props.disabled, children: labels.actionSelect })] })] }), jsxRuntimeExports.jsx("canvas", { ref: refPicture })] }));
4208
+ }
4209
+
4210
+ function RlsImageEditorModal(props) {
4211
+ return (jsxRuntimeExports.jsx(RlsModal, { className: "rls-image-editor-modal", visible: props.visible, children: jsxRuntimeExports.jsx(RlsImageEditor, { ...props, children: props.children }) }));
4212
+ }
4213
+
4214
+ const MIME_TYPE_SUPPORTS = [
4215
+ 'image/png',
4216
+ 'image/jpg',
4217
+ 'image/jpeg',
4218
+ 'image/bmp',
4219
+ 'image/webp',
4220
+ 'image/gif',
4221
+ 'image/svg+xml'
4222
+ ];
4223
+
4224
+ function useImageEditorController(options) {
4225
+ const refInput = useRef(null);
4226
+ const [srcEditor, setSrcEditor] = useState();
4227
+ const [labels, setLabels] = useState({
4228
+ actionCancel: reactI18n('chooserImageActionCancel')
4229
+ });
4230
+ const processImage = useCallback((file) => {
4231
+ const reader = new FileReader();
4232
+ reader.onload = function () {
4233
+ setSrcEditor(reader.result);
4234
+ refInput.current.value = '';
4235
+ };
4236
+ reader.readAsDataURL(file);
4237
+ }, []);
4238
+ useEffect(() => {
4239
+ refInput.current = document.createElement('input');
4240
+ refInput.current.type = 'file';
4241
+ refInput.current.onchange = () => {
4242
+ if (refInput.current.files &&
4243
+ MIME_TYPE_SUPPORTS.includes(refInput.current.files[0].type)) {
4244
+ processImage(refInput.current.files[0]);
4245
+ }
4246
+ };
4247
+ return i18nSubscribe(() => {
4248
+ setLabels({
4249
+ actionCancel: reactI18n('chooserImageActionCancel')
4250
+ });
4251
+ });
4252
+ }, []);
4253
+ const onEditorValue = useCallback((image) => {
4254
+ setSrcEditor(undefined);
4255
+ options.onValue && options.onValue(image);
4256
+ }, [options.onValue]);
4257
+ const onCancel = useCallback(() => {
4258
+ setSrcEditor(undefined);
4259
+ }, []);
4260
+ const RlsImageEditorChooser = useMemo(() => {
4261
+ return (srcEditor && (jsxRuntimeExports.jsx(RlsImageEditorModal, { visible: true, src: srcEditor, formControl: options.formControl, maxWidth: options.maxWidth, quality: options.quality, ratio: options.ratio, selection: options.selection, onValue: onEditorValue, children: jsxRuntimeExports.jsx(RlsButton, { type: "flat", rlsTheme: "danger", onClick: onCancel, disabled: options.disabled, children: labels.actionCancel }) })));
4262
+ }, [
4263
+ srcEditor,
4264
+ labels,
4265
+ options.formControl,
4266
+ options.maxWidth,
4267
+ options.quality,
4268
+ options.ratio,
4269
+ options.disabled,
4270
+ onEditorValue,
4271
+ onCancel
4272
+ ]);
4273
+ const onImageChooser = useCallback(() => {
4274
+ !options.disabled && refInput.current.click();
4275
+ }, [options.disabled]);
4276
+ return { onImageChooser, RlsImageEditorChooser };
4277
+ }
4278
+
4279
+ function RlsImageChooser(props) {
4280
+ const [src, setSrc] = useState();
4281
+ const onValue = useCallback((image) => {
4282
+ setSrc(image.base64);
4283
+ props.onValue?.(image);
4284
+ }, [props.onValue]);
4285
+ const controller = useImageEditorController({ ...props, onValue });
4286
+ useEffect(() => {
4287
+ props.src && setSrc(props.src);
4288
+ }, [props.src]);
4289
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-image-chooser", children: [jsxRuntimeExports.jsx("div", { className: "rls-image-chooser__avatar", onClick: controller.onImageChooser, children: src && jsxRuntimeExports.jsx("img", { src: src }) }), controller.RlsImageEditorChooser] }));
4290
+ }
4291
+
4292
+ function RlsModalSheet({ autoclose, children, className, controller, onAutoClose, visible, rlsTheme }) {
4293
+ const classNameModal = useMemo(() => {
4294
+ return renderClassStatus('rls-modal-sheet', { visible: controller?.visible ?? visible }, className);
4295
+ }, [className, visible, controller?.visible]);
4296
+ const onClickBackdrop = useCallback(() => {
4297
+ autoclose && controller?.close();
4298
+ onAutoClose?.();
4299
+ }, [autoclose, controller, onAutoClose]);
4300
+ return ReactDOM.createPortal(jsxRuntimeExports.jsxs("div", { className: classNameModal, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-modal-sheet__component", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-modal-sheet__backdrop", onClick: onClickBackdrop })] }), document.body);
4301
+ }
4302
+
4303
+ const DURATION_ANIMATION$1 = 240;
4304
+ const DURATION_DEFAULT = 4000;
4305
+ let _id = 0;
4306
+ function generateId() {
4307
+ return `rls-notification-${++_id}`;
4308
+ }
4309
+ function RlsNotification({ content, icon, onClose, rlsTheme, title, visible }) {
4310
+ const className = useMemo(() => {
4311
+ return renderClassStatus('rls-notification', { visible });
4312
+ }, [visible]);
4313
+ return (jsxRuntimeExports.jsxs("div", { className: className, "rls-theme": rlsTheme, children: [icon && (jsxRuntimeExports.jsx("div", { className: "rls-notification__avatar", children: jsxRuntimeExports.jsx(RlsIcon, { value: icon }) })), jsxRuntimeExports.jsxs("div", { className: "rls-notification__component", children: [jsxRuntimeExports.jsxs("div", { className: "rls-notification__header", children: [jsxRuntimeExports.jsx("div", { className: "rls-notification__title", children: title }), jsxRuntimeExports.jsx("button", { onClick: onClose, children: jsxRuntimeExports.jsx(RlsIcon, { value: "close" }) })] }), jsxRuntimeExports.jsx("div", { className: "rls-notification__content", children: content })] })] }));
4314
+ }
4315
+ function useNotifications() {
4316
+ const [notifications, setNotifications] = useState([]);
4317
+ const timersRef = useRef(new Map());
4318
+ useEffect(() => {
4319
+ const timers = timersRef.current;
4320
+ return () => {
4321
+ timers.forEach((timer) => clearTimeout(timer));
4322
+ timers.clear();
4323
+ };
4324
+ }, []);
4325
+ const remove = useCallback((id) => {
4326
+ const timer = timersRef.current.get(id);
4327
+ if (timer) {
4328
+ clearTimeout(timer);
4329
+ timersRef.current.delete(id);
4330
+ }
4331
+ setNotifications((notifications) => notifications.map((notification) => notification.id === id
4332
+ ? { ...notification, visible: false }
4333
+ : notification));
4334
+ setTimeout(() => {
4335
+ setNotifications((notifications) => notifications.filter((notification) => notification.id !== id));
4336
+ }, DURATION_ANIMATION$1);
4337
+ }, []);
4338
+ const notify = useCallback((config) => {
4339
+ const id = generateId();
4340
+ const duration = config.duration ?? DURATION_DEFAULT;
4341
+ setNotifications((notifications) => [
4342
+ ...notifications,
4343
+ { id, config, visible: true }
4344
+ ]);
4345
+ const timer = setTimeout(() => {
4346
+ remove(id);
4347
+ }, duration);
4348
+ timersRef.current.set(id, timer);
4349
+ }, [remove]);
4350
+ const RlsNotifications = ReactDOM.createPortal(jsxRuntimeExports.jsx("div", { className: "rls-notifications", children: notifications.map((notification) => (jsxRuntimeExports.jsx(RlsNotification, { ...notification.config, visible: notification.visible, onClose: () => remove(notification.id) }, notification.id))) }), document.body);
4351
+ return {
4352
+ RlsNotifications,
4353
+ notify
4354
+ };
4355
+ }
4356
+
4357
+ const DURATION_ANIMATION = 240;
4358
+ const DURATION_CHAR = 75;
4359
+ const DURATION_MAX = 9000;
4360
+ const DURATION_MIN = 3000;
4361
+ const DURATION_RESET = 480;
4362
+ function calculateDuration({ length }) {
4363
+ let duration = length * DURATION_CHAR;
4364
+ if (duration < DURATION_MIN) {
4365
+ duration = DURATION_MIN;
4366
+ }
4367
+ else if (duration > DURATION_MAX) {
4368
+ duration = DURATION_MAX;
4369
+ }
4370
+ return duration + DURATION_RESET;
4371
+ }
4372
+ function RlsSnackbar({ content, onClose, icon, rlsTheme, title, visible }) {
4373
+ const className = useMemo(() => {
4374
+ return renderClassStatus('rls-snackbar', { visible });
4375
+ }, [visible]);
4376
+ return (jsxRuntimeExports.jsxs("div", { className: className, "rls-theme": rlsTheme, children: [icon && (jsxRuntimeExports.jsx("div", { className: "rls-snackbar__avatar", children: jsxRuntimeExports.jsx(RlsIcon, { value: icon }) })), jsxRuntimeExports.jsxs("div", { className: "rls-snackbar__component", children: [jsxRuntimeExports.jsxs("div", { className: "rls-snackbar__header", children: [jsxRuntimeExports.jsx("div", { className: "rls-snackbar__title", children: title }), jsxRuntimeExports.jsx("button", { onClick: onClose, children: jsxRuntimeExports.jsx(RlsIcon, { value: "close" }) })] }), jsxRuntimeExports.jsx("div", { className: "rls-snackbar__content", children: content })] })] }));
4377
+ }
4378
+ function useSnackbar() {
4379
+ const timeoutId = useRef(undefined);
4380
+ const duration = useRef(4000);
4381
+ const [state, setState] = useState({
4382
+ config: {},
4383
+ visible: false
4384
+ });
4385
+ const onClose = useCallback(() => {
4386
+ timeoutId.current && clearTimeout(timeoutId.current);
4387
+ timeoutId.current = undefined;
4388
+ setState((state) => ({ ...state, visible: false }));
4389
+ }, []);
4390
+ const rlsSnackbar = (jsxRuntimeExports.jsx(RlsSnackbar, { ...state.config, visible: state.visible, onClose: onClose }));
4391
+ useEffect(() => {
4392
+ if (state.visible) {
4393
+ timeoutId.current = setTimeout(() => {
4394
+ timeoutId.current = undefined;
4395
+ setState((state) => ({ ...state, visible: false }));
4396
+ }, duration.current);
4397
+ }
4398
+ else if (timeoutId.current) {
4399
+ clearTimeout(timeoutId.current);
4400
+ timeoutId.current = undefined;
4401
+ setTimeout(() => {
4402
+ snackbar(state.config);
4403
+ }, DURATION_ANIMATION);
4404
+ }
4405
+ }, [state.visible]);
4406
+ const snackbar = useCallback((config) => {
4407
+ duration.current = calculateDuration(String(config.content));
4408
+ setState((state) => ({
4409
+ ...state,
4410
+ config,
4411
+ visible: !state.visible
4412
+ }));
4413
+ }, []);
4414
+ return {
4415
+ RlsSnackbar: rlsSnackbar,
4416
+ snackbar
4417
+ };
4418
+ }
4419
+
4420
+ const RlsContext = createContext(null);
4421
+ function useRlsContext() {
4422
+ const state = useContext(RlsContext);
4423
+ if (!state) {
4424
+ throw new Error('RlsApplication not wrapped in Project');
4425
+ }
4426
+ return state;
4427
+ }
4428
+ function RlsApplication({ children }) {
4429
+ const { RlsConfirmation, confirmation } = useConfirmation();
4430
+ const { RlsNotifications, notify } = useNotifications();
4431
+ const { RlsSnackbar, snackbar } = useSnackbar();
4432
+ const [navbarInApp, setNavbarInApp] = useState(false);
4433
+ const [navbarIsCondense, setNavbarIsCondense] = useState(false);
4434
+ const [appIsMobile, setIsMobile] = useState(false);
4435
+ const className = useMemo(() => {
4436
+ return renderClassStatus('rls-app__body', {
4437
+ mobile: appIsMobile,
4438
+ 'navbar-snackbar': navbarInApp,
4439
+ 'navbar-condense': navbarIsCondense
4440
+ });
4441
+ }, [appIsMobile, navbarInApp, navbarIsCondense]);
4442
+ return (jsxRuntimeExports.jsxs(RlsContext, { value: {
4443
+ confirmation,
4444
+ notify,
4445
+ snackbar,
4446
+ setIsMobile,
4447
+ setNavbarInApp,
4448
+ setNavbarIsCondense
4449
+ }, children: [jsxRuntimeExports.jsxs("div", { className: className, children: [children, RlsSnackbar] }), RlsNotifications, RlsConfirmation] }));
4450
+ }
4451
+
4452
+ const DEFAULT_DESIGN_SYSTEM = 'bordered';
4453
+
4454
+ const DESIGN_SYSTEM_PREFIX = 'rls-design-system';
4455
+ const DESIGN_SYSTEMS = ['bordered', 'filled'];
4456
+ function designSystemClass(designSystem) {
4457
+ return `${DESIGN_SYSTEM_PREFIX}-${designSystem}`;
4458
+ }
4459
+ function setDesignSystem(designSystem = DEFAULT_DESIGN_SYSTEM) {
4460
+ if (typeof document === 'undefined') {
4461
+ return;
4462
+ }
4463
+ const target = document.body || document.documentElement;
4464
+ DESIGN_SYSTEMS.forEach((value) => {
4465
+ target.classList.toggle(designSystemClass(value), value === designSystem);
4466
+ });
4467
+ }
4468
+
4469
+ function useDesingSystemController(primaryDesignSystem = 'bordered', secondaryDesignSystem = 'filled') {
4470
+ const [designSystem, setDesignSystemValue] = useState(() => {
4471
+ setDesignSystem(primaryDesignSystem);
4472
+ return primaryDesignSystem;
4473
+ });
4474
+ const setValue = useCallback((value) => {
4475
+ setDesignSystem(value);
4476
+ setDesignSystemValue(value);
4477
+ }, []);
4478
+ const toggle = useCallback(() => {
4479
+ const nextDesignSystem = designSystem === primaryDesignSystem
4480
+ ? secondaryDesignSystem
4481
+ : primaryDesignSystem;
4482
+ setDesignSystem(nextDesignSystem);
4483
+ setDesignSystemValue(nextDesignSystem);
4484
+ }, [designSystem, primaryDesignSystem, secondaryDesignSystem]);
4485
+ return { setValue, toggle, value: designSystem };
4486
+ }
4487
+
4488
+ function useDropdownController(effect = '0% 0%') {
4489
+ const [visible, setVisible] = useState(false);
4490
+ const component = useRef(null);
4491
+ const open = useCallback((positionX, positionY) => {
4492
+ const content = component.current.querySelector('.rls-dropdown__content');
4493
+ content.style.transformOrigin = effect;
4494
+ component.current.style.top = `${positionY}px`;
4495
+ component.current.style.left = `${positionX}px`;
4496
+ setVisible(true);
4497
+ }, [effect]);
4498
+ const openWithEvent = useCallback((event) => {
4499
+ const rectContent = component.current.getBoundingClientRect();
4500
+ const rectElement = event.target.getBoundingClientRect();
4501
+ let positionX = 0;
4502
+ let positionY = 0;
4503
+ let effect = '0% 0%';
4504
+ let transform = 0;
4505
+ const elementX = rectElement.x + rectElement.width / 2;
4506
+ const elementY = rectElement.y + rectElement.height / 2;
4507
+ if (elementX + rectContent.width <= window.innerWidth) {
4508
+ positionX = elementX;
4509
+ transform += 1;
4510
+ }
4511
+ else if (elementX + rectElement.width - rectContent.width > 0) {
4512
+ positionX = elementX + rectElement.width - rectContent.width;
4513
+ transform += 3;
4514
+ }
4515
+ else {
4516
+ positionX = window.innerWidth - rectContent.width;
4517
+ transform += 1;
4518
+ }
4519
+ if (elementY + rectContent.height <= window.innerHeight) {
4520
+ positionY = elementY;
4521
+ transform += 4;
4522
+ }
4523
+ else if (elementY + rectElement.height - rectContent.height > 0) {
4524
+ positionY = elementY + rectElement.height - rectContent.height;
4525
+ transform += 7;
4526
+ }
4527
+ else {
4528
+ positionY = window.innerHeight - rectContent.height;
4529
+ transform += 4;
4530
+ }
4531
+ switch (transform) {
4532
+ case 7:
4533
+ effect = '100% 0%';
4534
+ break;
4535
+ case 8:
4536
+ effect = '0% 100%';
4537
+ break;
4538
+ case 10:
4539
+ effect = '100% 100%';
4540
+ break;
4541
+ default:
4542
+ effect = '0% 0%';
4543
+ break;
4544
+ }
4545
+ const content = component.current.querySelector('.rls-dropdown__content');
4546
+ content.style.transformOrigin = effect;
4547
+ component.current.style.top = `${positionY}px`;
4548
+ component.current.style.left = `${positionX}px`;
4549
+ setVisible(true);
4550
+ event.stopPropagation();
4551
+ }, []);
4552
+ const close = useCallback(() => {
4553
+ setVisible(false);
4554
+ }, []);
4555
+ return {
4556
+ close,
4557
+ component,
4558
+ open,
4559
+ openWithEvent,
4560
+ visible
4561
+ };
4562
+ }
4563
+
4564
+ function usePortalController() {
4565
+ const [visible, setVisible] = useState(false);
4566
+ const open = useCallback(() => {
4567
+ setVisible(true);
4568
+ }, []);
4569
+ const close = useCallback(() => {
4570
+ setVisible(false);
4571
+ }, []);
4572
+ return { close, open, visible };
4573
+ }
4574
+
4575
+ export { ConfirmationResult, DEFAULT_COLOR, RlsAccordion, RlsAlert, RlsAmount, RlsApplication, RlsAreaText, RlsAvatar, RlsBadge, RlsBallot, RlsBody, RlsBottomSheet, RlsBreadcrumb, RlsButton, RlsButtonAction, RlsButtonIcon, RlsButtonOption, RlsButtonProgress, RlsButtonStepper, RlsButtonToggle, RlsCard, RlsCheckBox, RlsCheckBoxControl, RlsConfirmation, RlsContent, RlsContext, RlsDatatable, RlsDatatableCell, RlsDatatableData, RlsDatatableFloating, RlsDatatableHeader, RlsDatatableRecord, RlsDatatableSubheader, RlsDatatableTitle, RlsDatatableTotals, RlsDropdown, RlsFieldArea, RlsFieldAutocomplete, RlsFieldAutocompleteTemplate, RlsFieldClock, RlsFieldColor, RlsFieldDate, RlsFieldDateRange, RlsFieldDecimal, RlsFieldFile, RlsFieldList, RlsFieldListSuggestions, RlsFieldListTemplate, RlsFieldMoney, RlsFieldNumber, RlsFieldPassword, RlsFieldPercentage, RlsFieldReadonly, RlsFieldSelect, RlsFieldSelectTemplate, RlsFieldText, RlsFormNavigation, RlsIcon, RlsImage, RlsImageChooser, RlsImageEditor, RlsInput, RlsInputCounter, RlsInputDecimal, RlsInputMoney, RlsInputNumber, RlsInputPassword, RlsInputPercentage, RlsInputSearch, RlsInputText, RlsLabel, RlsLabelCheckBox, RlsLabelRadioButton, RlsLabelSwitch, RlsLed, RlsMessageEmpty, RlsMessageFormError, RlsMessageIcon, RlsModal, RlsModalSheet, RlsNavbar, RlsNavbarMenu, RlsPagination, RlsPickerClock, RlsPickerColor, RlsPickerDate, RlsPickerDateRange, RlsPickerDay, RlsPickerDayRange, RlsPickerMonth, RlsPickerSelectorTitle, RlsPickerYear, RlsPoster, RlsProgressBar, RlsProgressCircular, RlsRadioButton, RlsSkeleton, RlsSkeletonText, RlsSlider, RlsSnackbar, RlsSpinner, RlsSwitch, RlsSwitchControl, RlsTabs, RlsTabularText, RlsToolbar, calculateImgDimension, generateThemePalette, hexIsValid, hexToHsl, hexToHsv, hexToRgb, hslToHex, hsvToHex, hsvToRgb, normalizeHex, rangeFormatTemplate, renderClassStatus, rgbToHex, rgbToHsl, rgbToHsv, setDesignSystem, setErrorsI18n, setThemeColor, useConfirmation, useDatatable, useDesingSystemController, useDropdownController, useFieldAutocomplete, useFieldList, useFieldSelect, useFormSingleSelectionController, useFormToggleController, useImageEditorController, useListController, useNotifications, usePortalController, useRelocationOnComponent, useResize, useRlsContext, useSnackbar };
4576
+ //# sourceMappingURL=index.mjs.map