matsuri-ui 9.7.2 → 9.8.0

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 (40) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/DateTextField/DateTextField.js +176 -0
  3. package/dist/cjs/DateTextField/DateTextField.js.map +1 -0
  4. package/dist/cjs/DateTextField/index.js +19 -0
  5. package/dist/cjs/DateTextField/index.js.map +1 -0
  6. package/dist/cjs/Pagination/makePagination.js +47 -0
  7. package/dist/cjs/Pagination/makePagination.js.map +1 -0
  8. package/dist/cjs/Pagination/makePagination.test.js +31 -0
  9. package/dist/cjs/Pagination/makePagination.test.js.map +1 -0
  10. package/dist/cjs/SelectField/Select.js +12 -4
  11. package/dist/cjs/SelectField/Select.js.map +1 -1
  12. package/dist/cjs/Table/Table.js +11 -11
  13. package/dist/cjs/Table/Table.js.map +1 -1
  14. package/dist/cjs/hooks/useOnClickOutside.js +12 -2
  15. package/dist/cjs/hooks/useOnClickOutside.js.map +1 -1
  16. package/dist/cjs/index.js +13 -0
  17. package/dist/cjs/index.js.map +1 -1
  18. package/dist/esm/DateTextField/DateTextField.js +161 -0
  19. package/dist/esm/DateTextField/DateTextField.js.map +1 -0
  20. package/dist/esm/DateTextField/index.js +2 -0
  21. package/dist/esm/DateTextField/index.js.map +1 -0
  22. package/dist/esm/Pagination/makePagination.js +40 -0
  23. package/dist/esm/Pagination/makePagination.js.map +1 -0
  24. package/dist/esm/Pagination/makePagination.test.js +28 -0
  25. package/dist/esm/Pagination/makePagination.test.js.map +1 -0
  26. package/dist/esm/SelectField/Select.js +11 -4
  27. package/dist/esm/SelectField/Select.js.map +1 -1
  28. package/dist/esm/Table/Table.js +11 -11
  29. package/dist/esm/Table/Table.js.map +1 -1
  30. package/dist/esm/hooks/useOnClickOutside.js +12 -2
  31. package/dist/esm/hooks/useOnClickOutside.js.map +1 -1
  32. package/dist/esm/index.js +1 -0
  33. package/dist/esm/index.js.map +1 -1
  34. package/dist/types/DateTextField/DateTextField.d.ts +13 -0
  35. package/dist/types/DateTextField/index.d.ts +1 -0
  36. package/dist/types/Pagination/makePagination.d.ts +7 -0
  37. package/dist/types/Pagination/makePagination.test.d.ts +1 -0
  38. package/dist/types/hooks/useOnClickOutside.d.ts +1 -1
  39. package/dist/types/index.d.ts +1 -0
  40. package/package.json +24 -24
package/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [9.8.0](https://github.com/matsuri-tech/matsuri-ui/compare/v9.7.2...v9.8.0) (2021-10-26)
6
+
7
+
8
+ ### Features
9
+
10
+ * **components:** add DateTextField ([96d2d4a](https://github.com/matsuri-tech/matsuri-ui/commit/96d2d4a7bdeb25537a5c1359ef1afe09fc272a0a))
11
+ * **DateTextField:** custom delimiter ([a42c99d](https://github.com/matsuri-tech/matsuri-ui/commit/a42c99dbc38c963e584ba5d2fb2843b03776a4d3))
12
+ * **hooks/useOnClickOutside:** allow multiple elements to be targeted ([830689d](https://github.com/matsuri-tech/matsuri-ui/commit/830689d574efecacc895579d99a992d95b47daf1))
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * nth-of-type instead of nth-child ([aae0ac9](https://github.com/matsuri-tech/matsuri-ui/commit/aae0ac9d7205aa8d38f2e3d63f5a188864e5dbc8))
18
+ * **DateTextField:** regexp to unformat ([216a00d](https://github.com/matsuri-tech/matsuri-ui/commit/216a00da49da377fe2d6cadb0467887f1943552a))
19
+
5
20
  ### [9.7.2](https://github.com/matsuri-tech/matsuri-ui/compare/v9.7.2-alpha.0...v9.7.2) (2021-09-24)
6
21
 
7
22
  ### [9.7.2-alpha.0](https://github.com/matsuri-tech/matsuri-ui/compare/v9.7.1...v9.7.2-alpha.0) (2021-09-24)
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DateTextField = void 0;
7
+
8
+ var _FormControl = require("../FormControl");
9
+
10
+ var _FormHelperText = require("../FormHelperText");
11
+
12
+ var _InputBase = require("../InputBase");
13
+
14
+ var _InputLabel = require("../InputLabel");
15
+
16
+ var _useDitectInputTouched = require("../TextField/useDitectInputTouched");
17
+
18
+ var _useValidation = require("../TextField/useValidation");
19
+
20
+ var _react = _interopRequireWildcard(require("react"));
21
+
22
+ var _dayjs = _interopRequireDefault(require("dayjs"));
23
+
24
+ var _react2 = require("@emotion/react");
25
+
26
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
+
28
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
29
+
30
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
31
+
32
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
33
+
34
+ const validateDate = (date, format) => {
35
+ return (0, _dayjs.default)(date, format).format(format) === date;
36
+ };
37
+
38
+ const DateTextField = ({
39
+ className,
40
+ style,
41
+ label,
42
+ onChange,
43
+ validationMessages,
44
+ customValidations: propsCustomValidations = [],
45
+ value: propsValue,
46
+ defaultValue,
47
+ min,
48
+ max,
49
+ readOnly,
50
+ disabled,
51
+ bottomGutter,
52
+ helperText,
53
+ invalid,
54
+ delimiter = "/",
55
+ ...props
56
+ }) => {
57
+ const ref = (0, _react.useRef)(null);
58
+ const template = (0, _react.useMemo)(() => ["YYYY", "MM", "DD"].join(delimiter), [delimiter]);
59
+ const formater = (0, _react.useCallback)(value => {
60
+ const format = /([\d*]{0,4})([\d*]{0,2})?([\d*]{0,2})?/;
61
+ const execResult = format.exec(value.split(delimiter).join(""));
62
+ const validValues = (execResult === null || execResult === void 0 ? void 0 : execResult.splice(1, 3).filter(x => x)) || [];
63
+ return validValues.join(delimiter) + (value.length === 4 || value.length === 6 ? delimiter : "");
64
+ }, [delimiter]);
65
+ const [value, setValue] = (0, _react.useState)(() => {
66
+ const value = propsValue || defaultValue;
67
+ return value ? formater(value.replace(/[^0-9]/g, "")) : "";
68
+ });
69
+ const customValidations = (0, _react.useMemo)(() => {
70
+ const pattern = new RegExp(["[0-9]{4}", "(0[1-9]|1[012])", "(0[1-9]|[12][0-9]|3[01])"].join(delimiter));
71
+ const lightPattern = new RegExp(["[\\d*]{4}", "[\\d*]{2}", "[\\d*]{2}"].join(delimiter));
72
+
73
+ const patternMismatchValidation = value => {
74
+ if (!lightPattern.test(value)) {
75
+ return false;
76
+ }
77
+
78
+ return !validateDate(value, template) && ((validationMessages === null || validationMessages === void 0 ? void 0 : validationMessages.patternMismatch) || `有効な日付を${template}形式で入力してください`);
79
+ };
80
+
81
+ const rangeUnderflowValidation = value => {
82
+ if (!min) {
83
+ return false;
84
+ }
85
+
86
+ if (!pattern.test(value)) {
87
+ return false;
88
+ }
89
+
90
+ return (0, _dayjs.default)(value).isBefore((0, _dayjs.default)(min)) && ((validationMessages === null || validationMessages === void 0 ? void 0 : validationMessages.rangeUnderflow) || `${(0, _dayjs.default)(min).format(template)} 以降の値を指定する必要があります。`);
91
+ };
92
+
93
+ const rangeOverflowValidation = value => {
94
+ if (!max) {
95
+ return false;
96
+ }
97
+
98
+ if (!pattern.test(value)) {
99
+ return false;
100
+ }
101
+
102
+ return (0, _dayjs.default)(value).isAfter((0, _dayjs.default)(max)) && ((validationMessages === null || validationMessages === void 0 ? void 0 : validationMessages.rangeOverflow) || `${(0, _dayjs.default)(max).format(template)} 以前の値を指定する必要があります。`);
103
+ };
104
+
105
+ return [...propsCustomValidations, patternMismatchValidation, rangeUnderflowValidation, rangeOverflowValidation];
106
+ }, [delimiter, max, min, propsCustomValidations, template, validationMessages === null || validationMessages === void 0 ? void 0 : validationMessages.patternMismatch, validationMessages === null || validationMessages === void 0 ? void 0 : validationMessages.rangeOverflow, validationMessages === null || validationMessages === void 0 ? void 0 : validationMessages.rangeUnderflow]);
107
+ const validation = (0, _useValidation.useValidation)({
108
+ ref,
109
+ validationMessages,
110
+ customValidations,
111
+ value
112
+ });
113
+ /**
114
+ * Handling
115
+ */
116
+
117
+ const handleChange = (0, _react.useCallback)(event => {
118
+ const formatedValue = event.currentTarget.value || "";
119
+ const value = formatedValue.replace(new RegExp(delimiter, "g"), "");
120
+ setValue(formater(value));
121
+
122
+ if (onChange) {
123
+ onChange(formater(value), event);
124
+ }
125
+
126
+ const element = event.currentTarget;
127
+ let cursorPosition = element === null || element === void 0 ? void 0 : element.selectionStart;
128
+ requestAnimationFrame(() => {
129
+ if (document.activeElement !== element) return;
130
+ if (cursorPosition === null) return;
131
+
132
+ if (element.value[cursorPosition - 1] === delimiter) {
133
+ cursorPosition = cursorPosition + 1;
134
+ }
135
+
136
+ element.setSelectionRange(cursorPosition, cursorPosition);
137
+ });
138
+ }, [delimiter, formater, onChange]);
139
+ /**
140
+ * External Update Value
141
+ */
142
+
143
+ (0, _react.useEffect)(() => {
144
+ if (propsValue) {
145
+ setValue(propsValue);
146
+ }
147
+ }, [propsValue]);
148
+ const [touched, additionalProps] = (0, _useDitectInputTouched.useDitectInputTouched)();
149
+ return (0, _react2.jsx)(_FormControl.FormControl, {
150
+ style: style,
151
+ className: className
152
+ }, (0, _react2.jsx)(_InputLabel.InputLabel, {
153
+ "aria-disabled": disabled,
154
+ required: props.required
155
+ }, label), (0, _react2.jsx)(_InputBase.InputBase, _extends({
156
+ ref: ref,
157
+ onChange: handleChange,
158
+ type: "text",
159
+ readOnly: readOnly
160
+ }, props, {
161
+ disabled: disabled,
162
+ value: value,
163
+ "data-invalid": !validation.valid
164
+ }, additionalProps)), touched && validation.message ? (0, _react2.jsx)(_FormHelperText.FormHelperText, {
165
+ bottomGutter: bottomGutter,
166
+ invalid: !validation.valid
167
+ }, validation.message) : (0, _react2.jsx)(_FormHelperText.FormHelperText, {
168
+ bottomGutter: bottomGutter,
169
+ invalid: invalid
170
+ }, typeof helperText === "function" ? helperText({
171
+ value
172
+ }) : helperText));
173
+ };
174
+
175
+ exports.DateTextField = DateTextField;
176
+ //# sourceMappingURL=DateTextField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/DateTextField/DateTextField.tsx"],"names":["validateDate","date","format","DateTextField","className","style","label","onChange","validationMessages","customValidations","propsCustomValidations","value","propsValue","defaultValue","min","max","readOnly","disabled","bottomGutter","helperText","invalid","delimiter","props","ref","template","join","formater","execResult","exec","split","validValues","splice","filter","x","length","setValue","replace","pattern","RegExp","lightPattern","patternMismatchValidation","test","patternMismatch","rangeUnderflowValidation","isBefore","rangeUnderflow","rangeOverflowValidation","isAfter","rangeOverflow","validation","handleChange","event","formatedValue","currentTarget","element","cursorPosition","selectionStart","requestAnimationFrame","document","activeElement","setSelectionRange","touched","additionalProps","required","valid","message"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;AAcA,MAAMA,YAAY,GAAG,CAACC,IAAD,EAAeC,MAAf,KAAkC;AACnD,SAAO,oBAAMD,IA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EK,KAAK,CAACyC;AAArD,KACKzD,KADL,CADJ,EAII,iBAAC,oBAAD;AACI,IAAA,GAAG,EAAEiB,GADT;AAEI,IAAA,QAAQ,EAAE2B,YAFd;AAGI,IAAA,IAAI,EAAC,MAHT;AAII,IAAA,QAAQ,EAAElC;AAJd,KAKQM,KALR;AAMI,IAAA,QAAQ,EAAEL,QANd;AAOI,IAAA,KAAK,EAAEN,KAPX;AAQI,oBAAc,CAACsC,UAAU,CAACe;AAR9B,KASQF,eATR,EAJJ,EAeKD,OAAO,IAAIZ,UAAU,CAACgB,OAAtB,GACG,iBAAC,8BAAD;AAAgB,IAAA,YAAY,EAAE/C,YAA9B;AAA4C,IAAA,OAAO,EAAE,CAAC+B,UAAU,CAACe;AAAjE,KACKf,UAAU,CAACgB,OADhB,CADH,GAKG,iBAAC,8BAAD;AAAgB,IAAA,YAAY,EAAE/C,YAA9B;AAA4C,IAAA,OAAO,EAAEE;AAArD,KACK,OAAOD,UAAP,KAAsB,UAAtB,GAAmCA,UAAU,CAAC;AAAER,IAAAA;AAAF,GAAD,CAA7C,GAA2DQ,UADhE,CApBR,CADJ;AA2BH,CAhKM","sourcesContent":["import { FieldProps } from \"../TextField\"\nimport { FormControl } from \"../FormControl\"\nimport { FormHelperText, InputBottomGutterProps } from \"../FormHelperText\"\nimport { InputBase, InputBaseProps } from \"../InputBase\"\nimport { InputLabel } from \"../InputLabel\"\nimport { useDitectInputTouched } from \"../TextField/useDitectInputTouched\"\nimport { useValidation } from \"../TextField/useValidation\"\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from \"react\"\nimport dayjs from \"dayjs\"\n\nexport interface DateTextFieldProps\n extends FieldProps<string>,\n Omit<InputBaseProps, \"defaultValue\" | \"value\" | \"onChange\">,\n InputBottomGutterProps {\n type?: never\n /**\n * @default \"/\"\n * @description 日付を区切るための文字列。\n */\n delimiter?: string\n}\n\nconst validateDate = (date: string, format: string) => {\n return dayjs(date, format).format(format) === date\n}\n\nexport const DateTextField = ({\n className,\n style,\n label,\n onChange,\n validationMessages,\n customValidations: propsCustomValidations = [],\n value: propsValue,\n defaultValue,\n min,\n max,\n readOnly,\n disabled,\n bottomGutter,\n helperText,\n invalid,\n delimiter = \"/\",\n ...props\n}: DateTextFieldProps) => {\n const ref = useRef<HTMLInputElement>(null)\n\n const template = useMemo(() => [\"YYYY\", \"MM\", \"DD\"].join(delimiter), [delimiter])\n\n const formater = useCallback(\n (value: string) => {\n const format = /([\\d*]{0,4})([\\d*]{0,2})?([\\d*]{0,2})?/\n const execResult = format.exec(value.split(delimiter).join(\"\"))\n const validValues = execResult?.splice(1, 3).filter((x) => x) || []\n return validValues.join(delimiter) + (value.length === 4 || value.length === 6 ? delimiter : \"\")\n },\n [delimiter]\n )\n\n const [value, setValue] = useState(() => {\n const value = propsValue || defaultValue\n return value ? formater(value.replace(/[^0-9]/g, \"\")) : \"\"\n })\n\n const customValidations = useMemo(() => {\n const pattern = new RegExp([\"[0-9]{4}\", \"(0[1-9]|1[012])\", \"(0[1-9]|[12][0-9]|3[01])\"].join(delimiter))\n const lightPattern = new RegExp([\"[\\\\d*]{4}\", \"[\\\\d*]{2}\", \"[\\\\d*]{2}\"].join(delimiter))\n\n const patternMismatchValidation = (value: string) => {\n if (!lightPattern.test(value)) {\n return false\n }\n return (\n !validateDate(value, template) &&\n (validationMessages?.patternMismatch || `有効な日付を${template}形式で入力してください`)\n )\n }\n const rangeUnderflowValidation = (value: string) => {\n if (!min) {\n return false\n }\n if (!pattern.test(value)) {\n return false\n }\n return (\n dayjs(value).isBefore(dayjs(min)) &&\n (validationMessages?.rangeUnderflow ||\n `${dayjs(min).format(template)} 以降の値を指定する必要があります。`)\n )\n }\n const rangeOverflowValidation = (value: string) => {\n if (!max) {\n return false\n }\n if (!pattern.test(value)) {\n return false\n }\n return (\n dayjs(value).isAfter(dayjs(max)) &&\n (validationMessages?.rangeOverflow ||\n `${dayjs(max).format(template)} 以前の値を指定する必要があります。`)\n )\n }\n return [...propsCustomValidations, patternMismatchValidation, rangeUnderflowValidation, rangeOverflowValidation]\n }, [\n delimiter,\n max,\n min,\n propsCustomValidations,\n template,\n validationMessages?.patternMismatch,\n validationMessages?.rangeOverflow,\n validationMessages?.rangeUnderflow\n ])\n\n const validation = useValidation<string>({\n ref,\n validationMessages,\n customValidations,\n value\n })\n\n /**\n * Handling\n */\n const handleChange = useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n const formatedValue = event.currentTarget.value || \"\"\n const value = formatedValue.replace(new RegExp(delimiter, \"g\"), \"\")\n setValue(formater(value))\n if (onChange) {\n onChange(formater(value), event)\n }\n const element = event.currentTarget\n let cursorPosition = element?.selectionStart\n\n requestAnimationFrame(() => {\n if (document.activeElement !== element) return\n if (cursorPosition === null) return\n if (element.value[cursorPosition - 1] === delimiter) {\n cursorPosition = cursorPosition + 1\n }\n element.setSelectionRange(cursorPosition, cursorPosition)\n })\n },\n [delimiter, formater, onChange]\n )\n\n /**\n * External Update Value\n */\n useEffect(() => {\n if (propsValue) {\n setValue(propsValue)\n }\n }, [propsValue])\n\n const [touched, additionalProps] = useDitectInputTouched()\n\n return (\n <FormControl style={style} className={className}>\n <InputLabel aria-disabled={disabled} required={props.required}>\n {label}\n </InputLabel>\n <InputBase\n ref={ref}\n onChange={handleChange}\n type=\"text\"\n readOnly={readOnly}\n {...props}\n disabled={disabled}\n value={value}\n data-invalid={!validation.valid}\n {...additionalProps}\n />\n {touched && validation.message ? (\n <FormHelperText bottomGutter={bottomGutter} invalid={!validation.valid}>\n {validation.message}\n </FormHelperText>\n ) : (\n <FormHelperText bottomGutter={bottomGutter} invalid={invalid}>\n {typeof helperText === \"function\" ? helperText({ value }) : helperText}\n </FormHelperText>\n )}\n </FormControl>\n )\n}\n"],"file":"DateTextField.js"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _DateTextField = require("./DateTextField");
8
+
9
+ Object.keys(_DateTextField).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _DateTextField[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _DateTextField[key];
16
+ }
17
+ });
18
+ });
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/DateTextField/index.tsx"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from \"./DateTextField\"\n"],"file":"index.js"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.makePagination = void 0;
5
+ // first, ..., prev, current, next, ..., last
6
+ const MINIMAL_PAGE_ITEM_COUNT = 7;
7
+
8
+ const makePagination = (current, option) => {
9
+ const {
10
+ width,
11
+ total
12
+ } = option;
13
+
14
+ if (width < MINIMAL_PAGE_ITEM_COUNT) {
15
+ throw new Error(`Must allow at least ${MINIMAL_PAGE_ITEM_COUNT} page items`);
16
+ }
17
+
18
+ if (width % 2 === 0) {
19
+ throw new Error(`Must allow odd number of page items`);
20
+ }
21
+
22
+ if (total < width) {
23
+ return Array.from({
24
+ length: total
25
+ }, (_, i) => i);
26
+ }
27
+
28
+ const left = Math.max(0, Math.min(total - width, current - Math.floor(width / 2)));
29
+ const items = Array.from({
30
+ length: width
31
+ }, (_, i) => i + left);
32
+
33
+ if (items[0] > 0) {
34
+ items[0] = 0;
35
+ items[1] = "prev-more";
36
+ }
37
+
38
+ if (items[items.length - 1] < total - 1) {
39
+ items[items.length - 1] = total - 1;
40
+ items[items.length - 2] = "next-more";
41
+ }
42
+
43
+ return items;
44
+ };
45
+
46
+ exports.makePagination = makePagination;
47
+ //# sourceMappingURL=makePagination.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/Pagination/makePagination.ts"],"names":["MINIMAL_PAGE_ITEM_COUNT","makePagination","current","option","width","total","Error","Array","from","length","_","i","left","Math","max","min","floor","items"],"mappings":";;;;AAAA;AACA,MAAMA,uBAAuB,GAAG,CAAhC;;AASO,MAAMC,cAAc,GAAG,CAACC,OAAD,EAAkBC,MAAlB,KAA0D;AACpF,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,MAAmBF,MAAzB;;AACA,MAAIC,KAAK,GAAGJ,uBAAZ,EAAqC;AACjC,UAAM,IAAIM,KAAJ,CAAW,uBAAsBN,uBAAwB,aAAzD,CAAN;AACH;;AACD,MAAII,KAAK,GAAG,CAAR,KAAc,CAAlB,EAAqB;AACjB,UAAM,IAAIE,KAAJ,CAAW,qCAAX,CAAN;AACH;;AACD,MAAID,KAAK,GAAGD,KAAZ,EAAmB;AACf,WAAOG,KAAK,CAACC,IAAN,CAAW;AAAEC,MAAAA,MAAM,EAAEJ;AAAV,KAAX,EAA8B,CAACK,CAAD,EAAIC,CAAJ,KAAUA,CAAxC,CAAP;AACH;;AACD,QAAMC,IAAI,GAAGC,IAAI,CAACC,GAAL,CAAS,CAAT,EAAYD,IAAI,CAACE,GAAL,CAASV,KAAK,GAAGD,KAAjB,EAAwBF,OAAO,GAAGW,IAAI,CAACG,KAAL,CAAWZ,KAAK,GAAG,CAAnB,CAAlC,CAAZ,CAAb;AACA,QAAMa,KAAY,GAAGV,KAAK,CAACC,IAAN,CAAW;AAAEC,IAAAA,MAAM,EAAEL;AAAV,GAAX,EAA8B,CAACM,CAAD,EAAIC,CAAJ,KAAUA,CAAC,GAAGC,IAA5C,CAArB;;AACA,MAAIK,KAAK,CAAC,CAAD,CAAL,GAAW,CAAf,EAAkB;AACdA,IAAAA,KAAK,CAAC,CAAD,CAAL,GAAW,CAAX;AACAA,IAAAA,KAAK,CAAC,CAAD,CAAL,GAAW,WAAX;AACH;;AACD,MAAIA,KAAK,CAACA,KAAK,CAACR,MAAN,GAAe,CAAhB,CAAL,GAA0BJ,KAAK,GAAG,CAAtC,EAAyC;AACrCY,IAAAA,KAAK,CAACA,KAAK,CAACR,MAAN,GAAe,CAAhB,CAAL,GAA0BJ,KAAK,GAAG,CAAlC;AACAY,IAAAA,KAAK,CAACA,KAAK,CAACR,MAAN,GAAe,CAAhB,CAAL,GAA0B,WAA1B;AACH;;AACD,SAAOQ,KAAP;AACH,CAtBM","sourcesContent":["// first, ..., prev, current, next, ..., last\nconst MINIMAL_PAGE_ITEM_COUNT = 7\n\ninterface MakePaginationOption {\n total: number\n width: number\n}\n\ntype Items = (number | \"next-more\" | \"prev-more\")[]\n\nexport const makePagination = (current: number, option: MakePaginationOption): Items => {\n const { width, total } = option\n if (width < MINIMAL_PAGE_ITEM_COUNT) {\n throw new Error(`Must allow at least ${MINIMAL_PAGE_ITEM_COUNT} page items`)\n }\n if (width % 2 === 0) {\n throw new Error(`Must allow odd number of page items`)\n }\n if (total < width) {\n return Array.from({ length: total }, (_, i) => i)\n }\n const left = Math.max(0, Math.min(total - width, current - Math.floor(width / 2)))\n const items: Items = Array.from({ length: width }, (_, i) => i + left)\n if (items[0] > 0) {\n items[0] = 0\n items[1] = \"prev-more\"\n }\n if (items[items.length - 1] < total - 1) {\n items[items.length - 1] = total - 1\n items[items.length - 2] = \"next-more\"\n }\n return items\n}\n"],"file":"makePagination.js"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ var _makePagination = require("./makePagination");
4
+
5
+ describe("makePagination", () => {
6
+ describe.each([[0, {
7
+ total: 20,
8
+ width: 7
9
+ }, [0, 1, 2, 3, 4, "next-more", 19]], [10, {
10
+ total: 20,
11
+ width: 7
12
+ }, [0, "prev-more", 9, 10, 11, "next-more", 19]], [20, {
13
+ total: 20,
14
+ width: 7
15
+ }, [0, "prev-more", 15, 16, 17, 18, 19]], [0, {
16
+ total: 5,
17
+ width: 7
18
+ }, [0, 1, 2, 3, 4]], [2, {
19
+ total: 5,
20
+ width: 7
21
+ }, [0, 1, 2, 3, 4]], [4, {
22
+ total: 5,
23
+ width: 7
24
+ }, [0, 1, 2, 3, 4]]])("current:%o, option:%o", (current, option, expected) => {
25
+ test(`f(${current})=[${expected}]`, () => {
26
+ const result = (0, _makePagination.makePagination)(current, option);
27
+ expect(result).toEqual(expected);
28
+ });
29
+ });
30
+ });
31
+ //# sourceMappingURL=makePagination.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/Pagination/makePagination.test.ts"],"names":["describe","each","total","width","current","option","expected","test","result","expect","toEqual"],"mappings":";;AAAA;;AAEAA,QAAQ,CAAC,gBAAD,EAAmB,MAAM;AAC7BA,EAAAA,QAAQ,CAACC,IAAT,CAAc,CACV,CAAC,CAAD,EAAI;AAAEC,IAAAA,KAAK,EAAE,EAAT;AAAaC,IAAAA,KAAK,EAAE;AAApB,GAAJ,EAA6B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,WAAhB,EAA6B,EAA7B,CAA7B,CADU,EAEV,CAAC,EAAD,EAAK;AAAED,IAAAA,KAAK,EAAE,EAAT;AAAaC,IAAAA,KAAK,EAAE;AAApB,GAAL,EAA8B,CAAC,CAAD,EAAI,WAAJ,EAAiB,CAAjB,EAAoB,EAApB,EAAwB,EAAxB,EAA4B,WAA5B,EAAyC,EAAzC,CAA9B,CAFU,EAGV,CAAC,EAAD,EAAK;AAAED,IAAAA,KAAK,EAAE,EAAT;AAAaC,IAAAA,KAAK,EAAE;AAApB,GAAL,EAA8B,CAAC,CAAD,EAAI,WAAJ,EAAiB,EAAjB,EAAqB,EAArB,EAAyB,EAAzB,EAA6B,EAA7B,EAAiC,EAAjC,CAA9B,CAHU,EAIV,CAAC,CAAD,EAAI;AAAED,IAAAA,KAAK,EAAE,CAAT;AAAYC,IAAAA,KAAK,EAAE;AAAnB,GAAJ,EAA4B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,CAA5B,CAJU,EAKV,CAAC,CAAD,EAAI;AAAED,IAAAA,KAAK,EAAE,CAAT;AAAYC,IAAAA,KAAK,EAAE;AAAnB,GAAJ,EAA4B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,CAA5B,CALU,EAMV,CAAC,CAAD,EAAI;AAAED,IAAAA,KAAK,EAAE,CAAT;AAAYC,IAAAA,KAAK,EAAE;AAAnB,GAAJ,EAA4B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,CAA5B,CANU,CAAd,EAOG,uBAPH,EAO4B,CAACC,OAAD,EAAUC,MAAV,EAAkBC,QAAlB,KAA+B;AACvDC,IAAAA,IAAI,CAAE,KAAIH,OAAQ,MAAKE,QAAS,GAA5B,EAAgC,MAAM;AACtC,YAAME,MAAM,GAAG,oCAAeJ,OAAf,EAAwBC,MAAxB,CAAf;AACAI,MAAAA,MAAM,CAACD,MAAD,CAAN,CAAeE,OAAf,CAAuBJ,QAAvB;AACH,KAHG,CAAJ;AAIH,GAZD;AAaH,CAdO,CAAR","sourcesContent":["import { makePagination } from \"./makePagination\"\n\ndescribe(\"makePagination\", () => {\n describe.each([\n [0, { total: 20, width: 7 }, [0, 1, 2, 3, 4, \"next-more\", 19]],\n [10, { total: 20, width: 7 }, [0, \"prev-more\", 9, 10, 11, \"next-more\", 19]],\n [20, { total: 20, width: 7 }, [0, \"prev-more\", 15, 16, 17, 18, 19]],\n [0, { total: 5, width: 7 }, [0, 1, 2, 3, 4]],\n [2, { total: 5, width: 7 }, [0, 1, 2, 3, 4]],\n [4, { total: 5, width: 7 }, [0, 1, 2, 3, 4]]\n ])(\"current:%o, option:%o\", (current, option, expected) => {\n test(`f(${current})=[${expected}]`, () => {\n const result = makePagination(current, option)\n expect(result).toEqual(expected)\n })\n })\n})\n"],"file":"makePagination.test.js"}