@pushwoosh/dumb-components 1.1.215 → 1.1.217
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Calendar/CalendarMonthSlider/CalendarMonthSlider.js +4 -1
- package/Calendar/__tests__/helpers.test.d.ts +1 -0
- package/Calendar/__tests__/helpers.test.js +124 -0
- package/Calendar/helpers.d.ts +1 -1
- package/Calendar/helpers.js +25 -4
- package/helpers/__tests__/barcodeUrl.test.d.ts +1 -0
- package/helpers/__tests__/barcodeUrl.test.js +43 -0
- package/helpers/barcodeUrl.d.ts +29 -0
- package/helpers/barcodeUrl.js +31 -0
- package/helpers/index.d.ts +1 -0
- package/helpers/index.js +2 -1
- package/index.d.ts +1 -0
- package/index.js +2 -1
- package/package.json +1 -1
|
@@ -24,7 +24,10 @@ export const CalendarMonthSlider = ({
|
|
|
24
24
|
renderAfter,
|
|
25
25
|
...monthProps
|
|
26
26
|
}) => {
|
|
27
|
-
const [anchor, setAnchor] = useState(
|
|
27
|
+
const [anchor, setAnchor] = useState(() => ({
|
|
28
|
+
...startMonth,
|
|
29
|
+
day: 1
|
|
30
|
+
}));
|
|
28
31
|
const [inTransition, setInTransition] = useState(false);
|
|
29
32
|
const [index, setIndex] = useState(0);
|
|
30
33
|
const [panels, setPanels] = useState(() => makeBaseline(anchor, visibleCount));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { addPeriod, setPeriodStruct } from '../helpers';
|
|
2
|
+
describe('addPeriod', () => {
|
|
3
|
+
it('clamps the day when the target month is shorter', () => {
|
|
4
|
+
expect(addPeriod({
|
|
5
|
+
year: 2026,
|
|
6
|
+
month: 8,
|
|
7
|
+
day: 31
|
|
8
|
+
}, 'month', 1)).toEqual({
|
|
9
|
+
year: 2026,
|
|
10
|
+
month: 9,
|
|
11
|
+
day: 30,
|
|
12
|
+
hour: 0,
|
|
13
|
+
minute: 0,
|
|
14
|
+
second: 0,
|
|
15
|
+
millisecond: 0
|
|
16
|
+
});
|
|
17
|
+
expect(addPeriod({
|
|
18
|
+
year: 2026,
|
|
19
|
+
month: 3,
|
|
20
|
+
day: 31
|
|
21
|
+
}, 'month', -1)).toEqual({
|
|
22
|
+
year: 2026,
|
|
23
|
+
month: 2,
|
|
24
|
+
day: 28,
|
|
25
|
+
hour: 0,
|
|
26
|
+
minute: 0,
|
|
27
|
+
second: 0,
|
|
28
|
+
millisecond: 0
|
|
29
|
+
});
|
|
30
|
+
expect(addPeriod({
|
|
31
|
+
year: 2024,
|
|
32
|
+
month: 2,
|
|
33
|
+
day: 29
|
|
34
|
+
}, 'year', 1)).toEqual({
|
|
35
|
+
year: 2025,
|
|
36
|
+
month: 2,
|
|
37
|
+
day: 28,
|
|
38
|
+
hour: 0,
|
|
39
|
+
minute: 0,
|
|
40
|
+
second: 0,
|
|
41
|
+
millisecond: 0
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
it('crosses year boundaries in both directions', () => {
|
|
45
|
+
expect(addPeriod({
|
|
46
|
+
year: 2026,
|
|
47
|
+
month: 12,
|
|
48
|
+
day: 15
|
|
49
|
+
}, 'month', 1)).toMatchObject({
|
|
50
|
+
year: 2027,
|
|
51
|
+
month: 1,
|
|
52
|
+
day: 15
|
|
53
|
+
});
|
|
54
|
+
expect(addPeriod({
|
|
55
|
+
year: 2026,
|
|
56
|
+
month: 1,
|
|
57
|
+
day: 15
|
|
58
|
+
}, 'month', -1)).toMatchObject({
|
|
59
|
+
year: 2025,
|
|
60
|
+
month: 12,
|
|
61
|
+
day: 15
|
|
62
|
+
});
|
|
63
|
+
expect(addPeriod({
|
|
64
|
+
year: 2026,
|
|
65
|
+
month: 5,
|
|
66
|
+
day: 10
|
|
67
|
+
}, 'month', -17)).toMatchObject({
|
|
68
|
+
year: 2024,
|
|
69
|
+
month: 12,
|
|
70
|
+
day: 10
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
it('keeps the time of day on month steps', () => {
|
|
74
|
+
expect(addPeriod({
|
|
75
|
+
year: 2026,
|
|
76
|
+
month: 1,
|
|
77
|
+
day: 31,
|
|
78
|
+
hour: 13,
|
|
79
|
+
minute: 45,
|
|
80
|
+
second: 7,
|
|
81
|
+
millisecond: 0
|
|
82
|
+
}, 'month', 1)).toMatchObject({
|
|
83
|
+
year: 2026,
|
|
84
|
+
month: 2,
|
|
85
|
+
day: 28,
|
|
86
|
+
hour: 13,
|
|
87
|
+
minute: 45,
|
|
88
|
+
second: 7
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
it('still rolls over on day steps', () => {
|
|
92
|
+
expect(addPeriod({
|
|
93
|
+
year: 2026,
|
|
94
|
+
month: 8,
|
|
95
|
+
day: 31
|
|
96
|
+
}, 'day', 1)).toMatchObject({
|
|
97
|
+
year: 2026,
|
|
98
|
+
month: 9,
|
|
99
|
+
day: 1
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
describe('setPeriodStruct', () => {
|
|
104
|
+
it('clamps the day when setting a shorter month', () => {
|
|
105
|
+
expect(setPeriodStruct({
|
|
106
|
+
year: 2026,
|
|
107
|
+
month: 1,
|
|
108
|
+
day: 31
|
|
109
|
+
}, 'month', 2)).toMatchObject({
|
|
110
|
+
year: 2026,
|
|
111
|
+
month: 2,
|
|
112
|
+
day: 28
|
|
113
|
+
});
|
|
114
|
+
expect(setPeriodStruct({
|
|
115
|
+
year: 2024,
|
|
116
|
+
month: 2,
|
|
117
|
+
day: 29
|
|
118
|
+
}, 'year', 2025)).toMatchObject({
|
|
119
|
+
year: 2025,
|
|
120
|
+
month: 2,
|
|
121
|
+
day: 28
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
package/Calendar/helpers.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const createUTCDate: (year: number, month?: number, day?: number,
|
|
|
6
6
|
export declare const parseStringToDate: (date: string) => Date;
|
|
7
7
|
export declare const formatTwoDigitNumber: (value: number) => string;
|
|
8
8
|
export declare const formatStruct: (ds: DateStruct, template: string) => string;
|
|
9
|
-
/** Returns a new struct with `value` units of `period` added (negative to subtract)
|
|
9
|
+
/** Returns a new struct with `value` units of `period` added (negative to subtract). */
|
|
10
10
|
export declare const addPeriod: <T extends DateTimeStruct | DateStruct>(ds: T, period: Period, value: number) => T;
|
|
11
11
|
/** Narrows a {@link DateTimeStruct} to a date-only {@link DateStruct} (drops the time fields). */
|
|
12
12
|
export declare const pickDateStruct: (date: DateTimeStruct) => DateStruct;
|
package/Calendar/helpers.js
CHANGED
|
@@ -32,9 +32,23 @@ export const formatStruct = (ds, template) => {
|
|
|
32
32
|
return value !== undefined ? formatTwoDigitNumber(value) : match;
|
|
33
33
|
});
|
|
34
34
|
};
|
|
35
|
-
|
|
35
|
+
const clampDayToMonth = (year, month, day) => Math.min(day, new Date(Date.UTC(year, month, 0)).getUTCDate());
|
|
36
|
+
/** Moves a struct to the absolute month `monthIndex` (`year * 12 + month - 1`), clamping the day to that month. */
|
|
37
|
+
const moveToMonth = (ds, monthIndex) => {
|
|
38
|
+
const year = Math.floor(monthIndex / 12);
|
|
39
|
+
const month = monthIndex - year * 12 + 1;
|
|
40
|
+
const dts = ds;
|
|
41
|
+
const date = createUTCDate(year, month, clampDayToMonth(year, month, ds.day), dts.hour, dts.minute, dts.second, dts.millisecond);
|
|
42
|
+
return utcDateToStruct(date);
|
|
43
|
+
};
|
|
44
|
+
/** Returns a new struct with `value` units of `period` added (negative to subtract). */
|
|
36
45
|
export const addPeriod = (ds, period, value) => {
|
|
37
|
-
|
|
46
|
+
// Month/year steps clamp the day instead of letting Date overflow: Aug 31 + 1 month is Sep 30, not Oct 1.
|
|
47
|
+
if (period === 'month' || period === 'year') {
|
|
48
|
+
return moveToMonth(ds, ds.year * 12 + ds.month - 1 + (period === 'month' ? value : value * 12));
|
|
49
|
+
}
|
|
50
|
+
const dts = ds;
|
|
51
|
+
const date = createUTCDate(ds.year, ds.month, ds.day, dts.hour, dts.minute, dts.second, dts.millisecond);
|
|
38
52
|
const method = periodMethodMap[period];
|
|
39
53
|
date[`setUTC${method}`](date[`getUTC${method}`]() + value);
|
|
40
54
|
return utcDateToStruct(date);
|
|
@@ -48,9 +62,16 @@ export const pickDateStruct = date => {
|
|
|
48
62
|
};
|
|
49
63
|
};
|
|
50
64
|
export const setPeriodStruct = (ds, period, value) => {
|
|
51
|
-
|
|
65
|
+
if (period === 'month') {
|
|
66
|
+
return moveToMonth(ds, ds.year * 12 + value - 1);
|
|
67
|
+
}
|
|
68
|
+
if (period === 'year') {
|
|
69
|
+
return moveToMonth(ds, value * 12 + ds.month - 1);
|
|
70
|
+
}
|
|
71
|
+
const dts = ds;
|
|
72
|
+
const date = createUTCDate(ds.year, ds.month, ds.day, dts.hour, dts.minute, dts.second, dts.millisecond);
|
|
52
73
|
const method = periodMethodMap[period];
|
|
53
|
-
date[`setUTC${method}`](
|
|
74
|
+
date[`setUTC${method}`](value);
|
|
54
75
|
return utcDateToStruct(date);
|
|
55
76
|
};
|
|
56
77
|
export const extendPeriodStruct = (struct, extend) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { buildBarcodeUrl, barcodePlaceholderSafeEscape, isBarcodePlaceholder } from '../barcodeUrl';
|
|
2
|
+
const BASE = 'https://rag-mcp.svc-nue.pushwoosh.com';
|
|
3
|
+
describe('buildBarcodeUrl', () => {
|
|
4
|
+
it('omits every empty parameter', () => {
|
|
5
|
+
expect(buildBarcodeUrl({
|
|
6
|
+
value: '1234567890123456'
|
|
7
|
+
}, `${BASE}/`)).toBe(`${BASE}/barcode/v1/code.png?sym=code128&v=1234567890123456`);
|
|
8
|
+
});
|
|
9
|
+
// A percent-encoded brace never matches the substituter, on the server or on
|
|
10
|
+
// the device, so the barcode would encode the placeholder text itself.
|
|
11
|
+
it.each(['{{voucher}}', '{Coupon|String|}', 'BR-{{voucher}}'])('keeps the placeholder %s literal', value => {
|
|
12
|
+
expect(buildBarcodeUrl({
|
|
13
|
+
value
|
|
14
|
+
}, BASE).endsWith(`&v=${value}`)).toBe(true);
|
|
15
|
+
});
|
|
16
|
+
it('escapes what is not a placeholder', () => {
|
|
17
|
+
expect(barcodePlaceholderSafeEscape('a b&c={{v}}')).toBe('a+b%26c%3D{{v}}');
|
|
18
|
+
});
|
|
19
|
+
it('carries every set parameter', () => {
|
|
20
|
+
const url = buildBarcodeUrl({
|
|
21
|
+
value: '{Coupon|String|}',
|
|
22
|
+
symbology: 'qr',
|
|
23
|
+
showText: true,
|
|
24
|
+
width: 420,
|
|
25
|
+
height: 460,
|
|
26
|
+
quietModules: 6,
|
|
27
|
+
foregroundColor: '#101010',
|
|
28
|
+
backgroundColor: '#ffffff',
|
|
29
|
+
ecLevel: 'H'
|
|
30
|
+
}, BASE);
|
|
31
|
+
['sym=qr', 'hri=1', 'w=420', 'h=460', 'q=6', 'fg=101010', 'bg=ffffff', 'ec=H'].forEach(part => expect(url).toContain(part));
|
|
32
|
+
});
|
|
33
|
+
it('drops the error-correction level outside QR', () => {
|
|
34
|
+
expect(buildBarcodeUrl({
|
|
35
|
+
value: '1',
|
|
36
|
+
ecLevel: 'H'
|
|
37
|
+
}, BASE)).not.toContain('ec=');
|
|
38
|
+
});
|
|
39
|
+
it('recognizes a value that still needs substituting', () => {
|
|
40
|
+
expect(isBarcodePlaceholder('{Coupon|String|}')).toBe(true);
|
|
41
|
+
expect(isBarcodePlaceholder('4012345678901')).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type BarcodeSymbology = 'code128' | 'ean13' | 'ean8' | 'upca' | 'qr';
|
|
2
|
+
export interface BarcodeUrlParams {
|
|
3
|
+
/** What to encode; normally a placeholder resolved per recipient. */
|
|
4
|
+
value: string;
|
|
5
|
+
symbology?: BarcodeSymbology;
|
|
6
|
+
/** Print the value in digits under the code. */
|
|
7
|
+
showText?: boolean;
|
|
8
|
+
width?: number;
|
|
9
|
+
height?: number;
|
|
10
|
+
/** Hex `#rrggbb`; empty = black on white. */
|
|
11
|
+
foregroundColor?: string;
|
|
12
|
+
backgroundColor?: string;
|
|
13
|
+
/** QR only: L, M, Q or H. */
|
|
14
|
+
ecLevel?: string;
|
|
15
|
+
/** Blank margin per side in modules; 0 = renderer default. */
|
|
16
|
+
quietModules?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Encodes the value but leaves `{`, `}` and `|` literal: a percent-encoded
|
|
20
|
+
* placeholder never matches the substituter, on the server or on the device.
|
|
21
|
+
*/
|
|
22
|
+
export declare function barcodePlaceholderSafeEscape(value: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Builds a URL for the onyx barcode-PNG endpoint, shared by every editor. The
|
|
25
|
+
* value is appended after the encoded query so a `{tag|type|}` stays literal.
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildBarcodeUrl(params: BarcodeUrlParams, baseUrl: string): string;
|
|
28
|
+
/** A value that has to be resolved before the endpoint can encode it. */
|
|
29
|
+
export declare function isBarcodePlaceholder(value: string): boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes the value but leaves `{`, `}` and `|` literal: a percent-encoded
|
|
3
|
+
* placeholder never matches the substituter, on the server or on the device.
|
|
4
|
+
*/
|
|
5
|
+
export function barcodePlaceholderSafeEscape(value) {
|
|
6
|
+
const escaped = new URLSearchParams({
|
|
7
|
+
v: value
|
|
8
|
+
}).toString().slice('v='.length);
|
|
9
|
+
return escaped.replace(/%7B/gi, '{').replace(/%7D/gi, '}').replace(/%7C/gi, '|');
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Builds a URL for the onyx barcode-PNG endpoint, shared by every editor. The
|
|
13
|
+
* value is appended after the encoded query so a `{tag|type|}` stays literal.
|
|
14
|
+
*/
|
|
15
|
+
export function buildBarcodeUrl(params, baseUrl) {
|
|
16
|
+
const q = new URLSearchParams();
|
|
17
|
+
q.set('sym', params.symbology ?? 'code128');
|
|
18
|
+
if (params.showText) q.set('hri', '1');
|
|
19
|
+
const hex = v => v.replace(/^#/, '');
|
|
20
|
+
if (params.foregroundColor) q.set('fg', hex(params.foregroundColor));
|
|
21
|
+
if (params.backgroundColor) q.set('bg', hex(params.backgroundColor));
|
|
22
|
+
if (params.width) q.set('w', String(params.width));
|
|
23
|
+
if (params.height) q.set('h', String(params.height));
|
|
24
|
+
if (params.quietModules) q.set('q', String(params.quietModules));
|
|
25
|
+
if (params.ecLevel && (params.symbology ?? 'code128') === 'qr') q.set('ec', params.ecLevel);
|
|
26
|
+
return `${baseUrl.replace(/\/$/, '')}/barcode/v1/code.png?${q.toString()}&v=${barcodePlaceholderSafeEscape(params.value)}`;
|
|
27
|
+
}
|
|
28
|
+
/** A value that has to be resolved before the endpoint can encode it. */
|
|
29
|
+
export function isBarcodePlaceholder(value) {
|
|
30
|
+
return value.includes('{');
|
|
31
|
+
}
|
package/helpers/index.d.ts
CHANGED
package/helpers/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './assignRef';
|
|
1
|
+
export * from './assignRef';
|
|
2
|
+
export * from './barcodeUrl';
|
package/index.d.ts
CHANGED
|
@@ -57,3 +57,4 @@ export { Alert } from './Alert';
|
|
|
57
57
|
export { ApplicationPreloader, type ApplicationPreloaderProps, } from './ApplicationPreloader';
|
|
58
58
|
export { NotificationInbox, NotificationBar, NotificationBell, type Notification, type NotificationInboxProps, type NotificationSeverity, type NotificationBarType, type NotificationBarProps, type NotificationBellProps, } from './NotificationInbox';
|
|
59
59
|
export { LeafletTheme } from './LeafletTheme';
|
|
60
|
+
export { buildBarcodeUrl, barcodePlaceholderSafeEscape, isBarcodePlaceholder, type BarcodeSymbology, type BarcodeUrlParams, } from './helpers/barcodeUrl';
|
package/index.js
CHANGED
|
@@ -54,4 +54,5 @@ export { SendRateEdit, SendRateReadonly } from './SendRate';
|
|
|
54
54
|
export { Alert } from './Alert';
|
|
55
55
|
export { ApplicationPreloader } from './ApplicationPreloader';
|
|
56
56
|
export { NotificationInbox, NotificationBar, NotificationBell } from './NotificationInbox';
|
|
57
|
-
export { LeafletTheme } from './LeafletTheme';
|
|
57
|
+
export { LeafletTheme } from './LeafletTheme';
|
|
58
|
+
export { buildBarcodeUrl, barcodePlaceholderSafeEscape, isBarcodePlaceholder } from './helpers/barcodeUrl';
|