@contentful/field-editor-rating 1.1.11 → 1.3.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.
- package/dist/cjs/RatingEditor.js +110 -0
- package/dist/cjs/RatingEditor.spec.js +136 -0
- package/dist/cjs/RatingRibbon.js +133 -0
- package/dist/cjs/index.js +11 -0
- package/dist/esm/RatingEditor.js +56 -0
- package/dist/esm/RatingEditor.spec.js +93 -0
- package/dist/esm/RatingRibbon.js +84 -0
- package/dist/esm/index.js +1 -0
- package/dist/{RatingEditor.d.ts → types/RatingEditor.d.ts} +26 -26
- package/dist/types/RatingEditor.spec.d.ts +1 -0
- package/dist/{RatingRibbon.d.ts → types/RatingRibbon.d.ts} +20 -20
- package/dist/{index.d.ts → types/index.d.ts} +1 -1
- package/package.json +25 -11
- package/CHANGELOG.md +0 -192
- package/dist/field-editor-rating.cjs.development.js +0 -185
- package/dist/field-editor-rating.cjs.development.js.map +0 -1
- package/dist/field-editor-rating.cjs.production.min.js +0 -2
- package/dist/field-editor-rating.cjs.production.min.js.map +0 -1
- package/dist/field-editor-rating.esm.js +0 -179
- package/dist/field-editor-rating.esm.js.map +0 -1
- package/dist/index.js +0 -8
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
disabled: boolean;
|
|
4
|
-
stars: number;
|
|
5
|
-
value: number | null | undefined;
|
|
6
|
-
onSelect: (val: number) => void;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
hovered: null | number;
|
|
10
|
-
};
|
|
11
|
-
export declare class RatingRibbon extends React.Component<RatingRibbonProps, RatingRibbonState> {
|
|
12
|
-
state: {
|
|
13
|
-
hovered: null;
|
|
14
|
-
};
|
|
15
|
-
isSelected: (num: number) => boolean;
|
|
16
|
-
onBlur: () => void;
|
|
17
|
-
onFocus: (num: number) => () => void;
|
|
18
|
-
render(): JSX.Element;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
type RatingRibbonProps = {
|
|
3
|
+
disabled: boolean;
|
|
4
|
+
stars: number;
|
|
5
|
+
value: number | null | undefined;
|
|
6
|
+
onSelect: (val: number) => void;
|
|
7
|
+
};
|
|
8
|
+
type RatingRibbonState = {
|
|
9
|
+
hovered: null | number;
|
|
10
|
+
};
|
|
11
|
+
export declare class RatingRibbon extends React.Component<RatingRibbonProps, RatingRibbonState> {
|
|
12
|
+
state: {
|
|
13
|
+
hovered: null;
|
|
14
|
+
};
|
|
15
|
+
isSelected: (num: number) => boolean;
|
|
16
|
+
onBlur: () => void;
|
|
17
|
+
onFocus: (num: number) => () => void;
|
|
18
|
+
render(): React.JSX.Element;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { RatingEditor } from './RatingEditor';
|
|
1
|
+
export { RatingEditor } from './RatingEditor';
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-rating",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"module": "dist/
|
|
6
|
-
"
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"main": "dist/cjs/index.js",
|
|
5
|
+
"module": "dist/esm/index.js",
|
|
6
|
+
"types": "dist/types/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/types/index.d.ts",
|
|
10
|
+
"require": "./dist/cjs/index.js",
|
|
11
|
+
"default": "./dist/cjs/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
7
15
|
"files": [
|
|
8
16
|
"dist"
|
|
9
17
|
],
|
|
@@ -14,25 +22,31 @@
|
|
|
14
22
|
"url": "https://github.com/contentful/field-editors"
|
|
15
23
|
},
|
|
16
24
|
"scripts": {
|
|
17
|
-
"watch": "
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
25
|
+
"watch": "yarn concurrently \"yarn:watch:*\"",
|
|
26
|
+
"watch:cjs": "yarn build:cjs -w",
|
|
27
|
+
"watch:esm": "yarn build:esm -w",
|
|
28
|
+
"watch:types": "yarn build:types --watch",
|
|
29
|
+
"build": "yarn build:types && yarn build:cjs && yarn build:esm",
|
|
30
|
+
"build:types": "tsc --outDir dist/types --emitDeclarationOnly",
|
|
31
|
+
"build:cjs": "swc src --config-file ../../.swcrc -d dist/cjs -C module.type=commonjs",
|
|
32
|
+
"build:esm": "swc src --config-file ../../.swcrc -d dist/esm",
|
|
33
|
+
"test": "jest --watch",
|
|
34
|
+
"test:ci": "jest --ci",
|
|
21
35
|
"tsc": "tsc -p ./ --noEmit"
|
|
22
36
|
},
|
|
23
37
|
"dependencies": {
|
|
24
38
|
"@contentful/f36-components": "^4.0.27",
|
|
25
39
|
"@contentful/f36-tokens": "^4.0.0",
|
|
26
|
-
"@contentful/field-editor-shared": "^1.
|
|
40
|
+
"@contentful/field-editor-shared": "^1.3.0",
|
|
27
41
|
"emotion": "^10.0.17",
|
|
28
42
|
"lodash": "^4.17.15",
|
|
29
43
|
"lodash-es": "^4.17.15"
|
|
30
44
|
},
|
|
31
45
|
"devDependencies": {
|
|
32
|
-
"@contentful/field-editor-test-utils": "^1.
|
|
46
|
+
"@contentful/field-editor-test-utils": "^1.4.0"
|
|
33
47
|
},
|
|
34
48
|
"peerDependencies": {
|
|
35
49
|
"react": ">=16.8.0"
|
|
36
50
|
},
|
|
37
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "543e02672a8dd4edc810f9f3568d6b69c454e1f9"
|
|
38
52
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
## [1.1.11](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.10...@contentful/field-editor-rating@1.1.11) (2023-03-14)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
9
|
-
|
|
10
|
-
## [1.1.10](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.9...@contentful/field-editor-rating@1.1.10) (2023-03-10)
|
|
11
|
-
|
|
12
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
13
|
-
|
|
14
|
-
## [1.1.9](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.8...@contentful/field-editor-rating@1.1.9) (2023-02-21)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
17
|
-
|
|
18
|
-
## [1.1.8](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.7...@contentful/field-editor-rating@1.1.8) (2023-02-07)
|
|
19
|
-
|
|
20
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
21
|
-
|
|
22
|
-
## [1.1.7](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.6...@contentful/field-editor-rating@1.1.7) (2022-12-08)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
25
|
-
|
|
26
|
-
## [1.1.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.5...@contentful/field-editor-rating@1.1.6) (2022-07-29)
|
|
27
|
-
|
|
28
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
29
|
-
|
|
30
|
-
## [1.1.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.4...@contentful/field-editor-rating@1.1.5) (2022-07-29)
|
|
31
|
-
|
|
32
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
33
|
-
|
|
34
|
-
## [1.1.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.3...@contentful/field-editor-rating@1.1.4) (2022-07-11)
|
|
35
|
-
|
|
36
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
37
|
-
|
|
38
|
-
## [1.1.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.2...@contentful/field-editor-rating@1.1.3) (2022-06-22)
|
|
39
|
-
|
|
40
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
41
|
-
|
|
42
|
-
## [1.1.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.1...@contentful/field-editor-rating@1.1.2) (2022-02-15)
|
|
43
|
-
|
|
44
|
-
### Bug Fixes
|
|
45
|
-
|
|
46
|
-
- bump f36 packages ([#1025](https://github.com/contentful/field-editors/issues/1025)) ([ec37a40](https://github.com/contentful/field-editors/commit/ec37a4000db7cd75c66dd9621136b2272c9feeea))
|
|
47
|
-
|
|
48
|
-
## [1.1.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.0...@contentful/field-editor-rating@1.1.1) (2022-02-14)
|
|
49
|
-
|
|
50
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
51
|
-
|
|
52
|
-
# [1.1.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.0.3...@contentful/field-editor-rating@1.1.0) (2022-01-11)
|
|
53
|
-
|
|
54
|
-
### Features
|
|
55
|
-
|
|
56
|
-
- bump f36 packages to stable v4 [BAU-521] ([#988](https://github.com/contentful/field-editors/issues/988)) ([419cf56](https://github.com/contentful/field-editors/commit/419cf56692179b074fcfa2743469d5265ed98429))
|
|
57
|
-
|
|
58
|
-
## [1.0.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.0.2...@contentful/field-editor-rating@1.0.3) (2021-12-23)
|
|
59
|
-
|
|
60
|
-
### Bug Fixes
|
|
61
|
-
|
|
62
|
-
- markdown buttons ([#968](https://github.com/contentful/field-editors/issues/968)) ([9803b98](https://github.com/contentful/field-editors/commit/9803b98c25d92df6148686ffe2749a77f7efdbb9))
|
|
63
|
-
|
|
64
|
-
## [1.0.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.0.1...@contentful/field-editor-rating@1.0.2) (2021-12-20)
|
|
65
|
-
|
|
66
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
67
|
-
|
|
68
|
-
## [1.0.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.0.0...@contentful/field-editor-rating@1.0.1) (2021-11-17)
|
|
69
|
-
|
|
70
|
-
### Bug Fixes
|
|
71
|
-
|
|
72
|
-
- **card-actions:** update forma 36 to fix card actions click issue ([#927](https://github.com/contentful/field-editors/issues/927)) ([3dfdef2](https://github.com/contentful/field-editors/commit/3dfdef2c2b0045f12ea94ddafca89a8e9f25e7d0))
|
|
73
|
-
|
|
74
|
-
# [1.0.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.13.0...@contentful/field-editor-rating@1.0.0) (2021-11-04)
|
|
75
|
-
|
|
76
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
77
|
-
|
|
78
|
-
# [0.13.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.12.6...@contentful/field-editor-rating@0.13.0) (2021-11-04)
|
|
79
|
-
|
|
80
|
-
### Features
|
|
81
|
-
|
|
82
|
-
- Forma v4 components adoption ([#805](https://github.com/contentful/field-editors/issues/805)) ([526bde6](https://github.com/contentful/field-editors/commit/526bde6e10e0ee3789705ec10fb31489af7ca59e))
|
|
83
|
-
|
|
84
|
-
### BREAKING CHANGES
|
|
85
|
-
|
|
86
|
-
- adopts a new Forma v4 beta
|
|
87
|
-
|
|
88
|
-
## [0.12.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.12.5...@contentful/field-editor-rating@0.12.6) (2021-10-14)
|
|
89
|
-
|
|
90
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
91
|
-
|
|
92
|
-
## [0.12.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.12.4...@contentful/field-editor-rating@0.12.5) (2021-10-06)
|
|
93
|
-
|
|
94
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
95
|
-
|
|
96
|
-
## [0.12.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.12.3...@contentful/field-editor-rating@0.12.4) (2021-09-17)
|
|
97
|
-
|
|
98
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
99
|
-
|
|
100
|
-
## [0.12.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.12.2...@contentful/field-editor-rating@0.12.3) (2021-09-16)
|
|
101
|
-
|
|
102
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
103
|
-
|
|
104
|
-
## [0.12.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.12.1...@contentful/field-editor-rating@0.12.2) (2021-08-19)
|
|
105
|
-
|
|
106
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
107
|
-
|
|
108
|
-
## [0.12.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.12.0...@contentful/field-editor-rating@0.12.1) (2021-07-29)
|
|
109
|
-
|
|
110
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
111
|
-
|
|
112
|
-
# [0.12.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.11.6...@contentful/field-editor-rating@0.12.0) (2021-07-23)
|
|
113
|
-
|
|
114
|
-
### Features
|
|
115
|
-
|
|
116
|
-
- 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
|
|
117
|
-
|
|
118
|
-
## [0.11.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.11.3...@contentful/field-editor-rating@0.11.6) (2021-07-06)
|
|
119
|
-
|
|
120
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
121
|
-
|
|
122
|
-
## [0.11.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.11.3...@contentful/field-editor-rating@0.11.5) (2021-07-06)
|
|
123
|
-
|
|
124
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
125
|
-
|
|
126
|
-
## [0.11.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.11.3...@contentful/field-editor-rating@0.11.4) (2021-06-23)
|
|
127
|
-
|
|
128
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
129
|
-
|
|
130
|
-
## [0.11.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.11.2...@contentful/field-editor-rating@0.11.3) (2021-06-23)
|
|
131
|
-
|
|
132
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
133
|
-
|
|
134
|
-
## [0.11.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.11.1...@contentful/field-editor-rating@0.11.2) (2021-06-22)
|
|
135
|
-
|
|
136
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
137
|
-
|
|
138
|
-
## [0.11.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.11.0...@contentful/field-editor-rating@0.11.1) (2021-03-05)
|
|
139
|
-
|
|
140
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
141
|
-
|
|
142
|
-
# [0.11.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.10.2...@contentful/field-editor-rating@0.11.0) (2021-02-19)
|
|
143
|
-
|
|
144
|
-
### Features
|
|
145
|
-
|
|
146
|
-
- bump min version of forma-36 ([#606](https://github.com/contentful/field-editors/issues/606)) ([fd57c7a](https://github.com/contentful/field-editors/commit/fd57c7a4312766af38c01507f17706ab22992617))
|
|
147
|
-
|
|
148
|
-
## [0.10.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.10.1...@contentful/field-editor-rating@0.10.2) (2021-02-09)
|
|
149
|
-
|
|
150
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
151
|
-
|
|
152
|
-
## [0.10.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.10.0...@contentful/field-editor-rating@0.10.1) (2021-02-01)
|
|
153
|
-
|
|
154
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
155
|
-
|
|
156
|
-
# [0.10.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.9.1...@contentful/field-editor-rating@0.10.0) (2021-01-20)
|
|
157
|
-
|
|
158
|
-
### Features
|
|
159
|
-
|
|
160
|
-
- update minimal forma-36 versions to use updated design ([#565](https://github.com/contentful/field-editors/issues/565)) ([332c734](https://github.com/contentful/field-editors/commit/332c734bfaf54f0e9773fcbb460d743b1f5459ec))
|
|
161
|
-
|
|
162
|
-
## [0.9.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.9.0...@contentful/field-editor-rating@0.9.1) (2021-01-15)
|
|
163
|
-
|
|
164
|
-
### Bug Fixes
|
|
165
|
-
|
|
166
|
-
- 🐛 small layout adjustments ([#555](https://github.com/contentful/field-editors/issues/555)) ([235c594](https://github.com/contentful/field-editors/commit/235c5941db152d2921a9ef134c1a71b0069a4dc2))
|
|
167
|
-
|
|
168
|
-
# [0.9.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.8.5...@contentful/field-editor-rating@0.9.0) (2021-01-12)
|
|
169
|
-
|
|
170
|
-
### Features
|
|
171
|
-
|
|
172
|
-
- update minimal required Forma version to the 3.73.12 ([#552](https://github.com/contentful/field-editors/issues/552)) ([2816fd9](https://github.com/contentful/field-editors/commit/2816fd960c28815faebf49a9ef8f4c4c0d91fc36))
|
|
173
|
-
|
|
174
|
-
## [0.8.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.8.4...@contentful/field-editor-rating@0.8.5) (2020-12-16)
|
|
175
|
-
|
|
176
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
177
|
-
|
|
178
|
-
## [0.8.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.8.3...@contentful/field-editor-rating@0.8.4) (2020-11-06)
|
|
179
|
-
|
|
180
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
181
|
-
|
|
182
|
-
## [0.8.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.8.2...@contentful/field-editor-rating@0.8.3) (2020-11-06)
|
|
183
|
-
|
|
184
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
185
|
-
|
|
186
|
-
## [0.8.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.8.1...@contentful/field-editor-rating@0.8.2) (2020-10-28)
|
|
187
|
-
|
|
188
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
189
|
-
|
|
190
|
-
## [0.8.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.8.0...@contentful/field-editor-rating@0.8.1) (2020-08-24)
|
|
191
|
-
|
|
192
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
-
|
|
7
|
-
var React = require('react');
|
|
8
|
-
var get = _interopDefault(require('lodash/get'));
|
|
9
|
-
var fieldEditorShared = require('@contentful/field-editor-shared');
|
|
10
|
-
var emotion = require('emotion');
|
|
11
|
-
var f36Components = require('@contentful/f36-components');
|
|
12
|
-
var f36Icons = require('@contentful/f36-icons');
|
|
13
|
-
|
|
14
|
-
function _inheritsLoose(subClass, superClass) {
|
|
15
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
16
|
-
subClass.prototype.constructor = subClass;
|
|
17
|
-
|
|
18
|
-
_setPrototypeOf(subClass, superClass);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function _setPrototypeOf(o, p) {
|
|
22
|
-
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
23
|
-
o.__proto__ = p;
|
|
24
|
-
return o;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
return _setPrototypeOf(o, p);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
var RatingRibbon = /*#__PURE__*/function (_React$Component) {
|
|
31
|
-
_inheritsLoose(RatingRibbon, _React$Component);
|
|
32
|
-
|
|
33
|
-
function RatingRibbon() {
|
|
34
|
-
var _this;
|
|
35
|
-
|
|
36
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
37
|
-
args[_key] = arguments[_key];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
41
|
-
_this.state = {
|
|
42
|
-
hovered: null
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
_this.isSelected = function (num) {
|
|
46
|
-
var hovered = _this.state.hovered;
|
|
47
|
-
var value = _this.props.value;
|
|
48
|
-
|
|
49
|
-
if (hovered !== null) {
|
|
50
|
-
return num <= hovered;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (value) {
|
|
54
|
-
return num <= value;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return false;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
_this.onBlur = function () {
|
|
61
|
-
if (!_this.props.disabled) {
|
|
62
|
-
_this.setState({
|
|
63
|
-
hovered: null
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
_this.onFocus = function (num) {
|
|
69
|
-
return function () {
|
|
70
|
-
if (!_this.props.disabled) {
|
|
71
|
-
_this.setState({
|
|
72
|
-
hovered: num
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
return _this;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
var _proto = RatingRibbon.prototype;
|
|
82
|
-
|
|
83
|
-
_proto.render = function render() {
|
|
84
|
-
var _this2 = this;
|
|
85
|
-
|
|
86
|
-
var items = [];
|
|
87
|
-
|
|
88
|
-
for (var i = 1; i <= this.props.stars; i++) {
|
|
89
|
-
items.push(i);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return React.createElement(React.Fragment, null, items.map(function (num) {
|
|
93
|
-
return React.createElement(f36Components.IconButton, {
|
|
94
|
-
variant: "transparent",
|
|
95
|
-
size: "small",
|
|
96
|
-
icon: React.createElement(f36Icons.StarIcon, {
|
|
97
|
-
variant: _this2.isSelected(num) ? 'primary' : 'muted',
|
|
98
|
-
className: emotion.css({
|
|
99
|
-
width: '22px',
|
|
100
|
-
height: '22px'
|
|
101
|
-
})
|
|
102
|
-
}),
|
|
103
|
-
"data-selected": _this2.isSelected(num) ? 'true' : 'false',
|
|
104
|
-
testId: "rating-editor-star",
|
|
105
|
-
isDisabled: _this2.props.disabled,
|
|
106
|
-
key: num,
|
|
107
|
-
onClick: function onClick() {
|
|
108
|
-
_this2.props.onSelect(num);
|
|
109
|
-
},
|
|
110
|
-
onKeyDown: function onKeyDown(e) {
|
|
111
|
-
if (e.keyCode === 13) {
|
|
112
|
-
_this2.props.onSelect(num);
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
onMouseOver: _this2.onFocus(num),
|
|
116
|
-
onMouseLeave: _this2.onBlur,
|
|
117
|
-
onFocus: _this2.onFocus(num),
|
|
118
|
-
onBlur: _this2.onBlur,
|
|
119
|
-
"aria-label": num.toString()
|
|
120
|
-
});
|
|
121
|
-
}));
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
return RatingRibbon;
|
|
125
|
-
}(React.Component);
|
|
126
|
-
|
|
127
|
-
function isValidCount(count) {
|
|
128
|
-
return typeof count === 'number' && !isNaN(count) && count > 0;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function getStarCount(count) {
|
|
132
|
-
var defaultValue = 5;
|
|
133
|
-
|
|
134
|
-
if (isValidCount(count)) {
|
|
135
|
-
return Math.round(count);
|
|
136
|
-
} else if (typeof count === 'string') {
|
|
137
|
-
var parsed = parseInt(count, 10);
|
|
138
|
-
return isValidCount(parsed) ? Math.round(parsed) : defaultValue;
|
|
139
|
-
} else {
|
|
140
|
-
return defaultValue;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function RatingEditor(props) {
|
|
145
|
-
var field = props.field;
|
|
146
|
-
var starsCount = getStarCount(get(props.parameters, ['instance', 'stars']));
|
|
147
|
-
return React.createElement(fieldEditorShared.FieldConnector, {
|
|
148
|
-
throttle: 0,
|
|
149
|
-
field: field,
|
|
150
|
-
isInitiallyDisabled: props.isInitiallyDisabled
|
|
151
|
-
}, function (_ref) {
|
|
152
|
-
var disabled = _ref.disabled,
|
|
153
|
-
value = _ref.value,
|
|
154
|
-
setValue = _ref.setValue;
|
|
155
|
-
|
|
156
|
-
var clearOption = function clearOption() {
|
|
157
|
-
setValue(null);
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
return React.createElement(f36Components.Flex, {
|
|
161
|
-
testId: "rating-editor",
|
|
162
|
-
flexDirection: "row",
|
|
163
|
-
marginTop: "spacingS"
|
|
164
|
-
}, React.createElement(RatingRibbon, {
|
|
165
|
-
disabled: disabled,
|
|
166
|
-
value: value,
|
|
167
|
-
stars: starsCount,
|
|
168
|
-
onSelect: function onSelect(num) {
|
|
169
|
-
setValue(num);
|
|
170
|
-
}
|
|
171
|
-
}), value !== undefined && !disabled && React.createElement(f36Components.Flex, {
|
|
172
|
-
marginLeft: "spacingM"
|
|
173
|
-
}, React.createElement(f36Components.TextLink, {
|
|
174
|
-
as: "button",
|
|
175
|
-
testId: "rating-editor-clear",
|
|
176
|
-
onClick: clearOption
|
|
177
|
-
}, "Clear")));
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
RatingEditor.defaultProps = {
|
|
181
|
-
isInitiallyDisabled: true
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
exports.RatingEditor = RatingEditor;
|
|
185
|
-
//# sourceMappingURL=field-editor-rating.cjs.development.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-rating.cjs.development.js","sources":["../src/RatingRibbon.tsx","../src/RatingEditor.tsx"],"sourcesContent":["import * as React from 'react';\nimport { css } from 'emotion';\n\nimport { IconButton } from '@contentful/f36-components';\n\nimport { StarIcon } from '@contentful/f36-icons';\n\ntype RatingRibbonProps = {\n disabled: boolean;\n stars: number;\n value: number | null | undefined;\n onSelect: (val: number) => void;\n};\n\ntype RatingRibbonState = {\n hovered: null | number;\n};\n\nexport class RatingRibbon extends React.Component<RatingRibbonProps, RatingRibbonState> {\n state = {\n hovered: null,\n };\n\n isSelected = (num: number) => {\n const hovered = this.state.hovered;\n const value = this.props.value;\n\n if (hovered !== null) {\n return num <= hovered;\n }\n if (value) {\n return num <= value;\n }\n return false;\n };\n\n onBlur = () => {\n if (!this.props.disabled) {\n this.setState({ hovered: null });\n }\n };\n\n onFocus = (num: number) => () => {\n if (!this.props.disabled) {\n this.setState({ hovered: num });\n }\n };\n\n render() {\n const items: number[] = [];\n for (let i = 1; i <= this.props.stars; i++) {\n items.push(i);\n }\n\n return (\n <>\n {items.map((num) => (\n <IconButton\n variant=\"transparent\"\n size=\"small\"\n icon={\n <StarIcon\n variant={this.isSelected(num) ? 'primary' : 'muted'}\n className={css({ width: '22px', height: '22px' })}\n />\n }\n data-selected={this.isSelected(num) ? 'true' : 'false'}\n testId=\"rating-editor-star\"\n isDisabled={this.props.disabled}\n key={num}\n onClick={() => {\n this.props.onSelect(num);\n }}\n onKeyDown={(e: React.KeyboardEvent) => {\n if (e.keyCode === 13) {\n this.props.onSelect(num);\n }\n }}\n onMouseOver={this.onFocus(num)}\n onMouseLeave={this.onBlur}\n onFocus={this.onFocus(num)}\n onBlur={this.onBlur}\n aria-label={num.toString()}\n />\n ))}\n </>\n );\n }\n}\n","import * as React from 'react';\nimport get from 'lodash/get';\nimport { FieldAPI, ParametersAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport { RatingRibbon } from './RatingRibbon';\n\nimport { TextLink, Flex } from '@contentful/f36-components';\n\nexport interface RatingEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.parameters\n */\n parameters?: ParametersAPI & {\n instance: {\n stars?: number;\n };\n };\n}\n\nfunction isValidCount(count?: string | number): count is number {\n return typeof count === 'number' && !isNaN(count) && count > 0;\n}\n\nfunction getStarCount(count?: number | string): number {\n const defaultValue = 5;\n\n if (isValidCount(count)) {\n return Math.round(count);\n } else if (typeof count === 'string') {\n const parsed = parseInt(count, 10);\n return isValidCount(parsed) ? Math.round(parsed) : defaultValue;\n } else {\n return defaultValue;\n }\n}\n\nexport function RatingEditor(props: RatingEditorProps) {\n const { field } = props;\n\n const starsCount = getStarCount(get(props.parameters, ['instance', 'stars']));\n\n return (\n <FieldConnector<number>\n throttle={0}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ disabled, value, setValue }) => {\n const clearOption = () => {\n setValue(null);\n };\n\n return (\n <Flex testId=\"rating-editor\" flexDirection=\"row\" marginTop=\"spacingS\">\n <RatingRibbon\n disabled={disabled}\n value={value}\n stars={starsCount}\n onSelect={(num) => {\n setValue(num);\n }}\n />\n {value !== undefined && !disabled && (\n <Flex marginLeft=\"spacingM\">\n <TextLink as=\"button\" testId=\"rating-editor-clear\" onClick={clearOption}>\n Clear\n </TextLink>\n </Flex>\n )}\n </Flex>\n );\n }}\n </FieldConnector>\n );\n}\n\nRatingEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["RatingRibbon","state","hovered","isSelected","num","value","props","onBlur","disabled","setState","onFocus","render","items","i","stars","push","React","map","IconButton","variant","size","icon","StarIcon","className","css","width","height","testId","isDisabled","key","onClick","onSelect","onKeyDown","e","keyCode","onMouseOver","onMouseLeave","toString","isValidCount","count","isNaN","getStarCount","defaultValue","Math","round","parsed","parseInt","RatingEditor","field","starsCount","get","parameters","FieldConnector","throttle","isInitiallyDisabled","setValue","clearOption","Flex","flexDirection","marginTop","undefined","marginLeft","TextLink","as","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAkBaA,YAAb;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA,UACEC,KADF,GACU;AACNC,MAAAA,OAAO,EAAE;AADH,KADV;;AAAA,UAKEC,UALF,GAKe,UAACC,GAAD;AACX,UAAMF,OAAO,GAAG,MAAKD,KAAL,CAAWC,OAA3B;AACA,UAAMG,KAAK,GAAG,MAAKC,KAAL,CAAWD,KAAzB;;AAEA,UAAIH,OAAO,KAAK,IAAhB,EAAsB;AACpB,eAAOE,GAAG,IAAIF,OAAd;AACD;;AACD,UAAIG,KAAJ,EAAW;AACT,eAAOD,GAAG,IAAIC,KAAd;AACD;;AACD,aAAO,KAAP;AACD,KAhBH;;AAAA,UAkBEE,MAlBF,GAkBW;AACP,UAAI,CAAC,MAAKD,KAAL,CAAWE,QAAhB,EAA0B;AACxB,cAAKC,QAAL,CAAc;AAAEP,UAAAA,OAAO,EAAE;AAAX,SAAd;AACD;AACF,KAtBH;;AAAA,UAwBEQ,OAxBF,GAwBY,UAACN,GAAD;AAAA,aAAiB;AACzB,YAAI,CAAC,MAAKE,KAAL,CAAWE,QAAhB,EAA0B;AACxB,gBAAKC,QAAL,CAAc;AAAEP,YAAAA,OAAO,EAAEE;AAAX,WAAd;AACD;AACF,OAJS;AAAA,KAxBZ;;AAAA;AAAA;;AAAA;;AAAA,SA8BEO,MA9BF,GA8BE;;;AACE,QAAMC,KAAK,GAAa,EAAxB;;AACA,SAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,IAAI,KAAKP,KAAL,CAAWQ,KAAhC,EAAuCD,CAAC,EAAxC,EAA4C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,MAAAA,KAAK,EAAEmC;AACPlB,MAAAA,QAAQ,EAAE,kBAAC3B,GAAD;AACRmD,QAAAA,QAAQ,CAACnD,GAAD,CAAR;AACD;KANH,CADF,EASGC,KAAK,KAAKuD,SAAV,IAAuB,CAACpD,QAAxB,IACCQ,mBAAA,CAACyC,kBAAD;AAAMI,MAAAA,UAAU,EAAC;KAAjB,EACE7C,mBAAA,CAAC8C,sBAAD;AAAUC,MAAAA,EAAE,EAAC;AAASpC,MAAAA,MAAM,EAAC;AAAsBG,MAAAA,OAAO,EAAE0B;KAA5D,SAAA,CADF,CAVJ,CADF;AAmBD,GA5BH,CADF;AAgCD;AAEDT,YAAY,CAACiB,YAAb,GAA4B;AAC1BV,EAAAA,mBAAmB,EAAE;AADK,CAA5B;;;;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),r=(e=require("lodash/get"))&&"object"==typeof e&&"default"in e?e.default:e,n=require("@contentful/field-editor-shared"),o=require("emotion"),i=require("@contentful/f36-components"),a=require("@contentful/f36-icons");function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var s=function(e){var r,n;function s(){for(var t,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return(t=e.call.apply(e,[this].concat(n))||this).state={hovered:null},t.isSelected=function(e){var r=t.state.hovered,n=t.props.value;return null!==r?e<=r:!!n&&e<=n},t.onBlur=function(){t.props.disabled||t.setState({hovered:null})},t.onFocus=function(e){return function(){t.props.disabled||t.setState({hovered:e})}},t}return n=e,(r=s).prototype=Object.create(n.prototype),r.prototype.constructor=r,l(r,n),s.prototype.render=function(){for(var e=this,r=[],n=1;n<=this.props.stars;n++)r.push(n);return t.createElement(t.Fragment,null,r.map((function(r){return t.createElement(i.IconButton,{variant:"transparent",size:"small",icon:t.createElement(a.StarIcon,{variant:e.isSelected(r)?"primary":"muted",className:o.css({width:"22px",height:"22px"})}),"data-selected":e.isSelected(r)?"true":"false",testId:"rating-editor-star",isDisabled:e.props.disabled,key:r,onClick:function(){e.props.onSelect(r)},onKeyDown:function(t){13===t.keyCode&&e.props.onSelect(r)},onMouseOver:e.onFocus(r),onMouseLeave:e.onBlur,onFocus:e.onFocus(r),onBlur:e.onBlur,"aria-label":r.toString()})})))},s}(t.Component);function u(e){return"number"==typeof e&&!isNaN(e)&&e>0}function c(e){var o=e.field,a=function(e){if(u(e))return Math.round(e);if("string"==typeof e){var t=parseInt(e,10);return u(t)?Math.round(t):5}return 5}(r(e.parameters,["instance","stars"]));return t.createElement(n.FieldConnector,{throttle:0,field:o,isInitiallyDisabled:e.isInitiallyDisabled},(function(e){var r=e.disabled,n=e.value,o=e.setValue;return t.createElement(i.Flex,{testId:"rating-editor",flexDirection:"row",marginTop:"spacingS"},t.createElement(s,{disabled:r,value:n,stars:a,onSelect:function(e){o(e)}}),void 0!==n&&!r&&t.createElement(i.Flex,{marginLeft:"spacingM"},t.createElement(i.TextLink,{as:"button",testId:"rating-editor-clear",onClick:function(){o(null)}},"Clear")))}))}c.defaultProps={isInitiallyDisabled:!0},exports.RatingEditor=c;
|
|
2
|
-
//# sourceMappingURL=field-editor-rating.cjs.production.min.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-rating.cjs.production.min.js","sources":["../src/RatingRibbon.tsx","../src/RatingEditor.tsx"],"sourcesContent":["import * as React from 'react';\nimport { css } from 'emotion';\n\nimport { IconButton } from '@contentful/f36-components';\n\nimport { StarIcon } from '@contentful/f36-icons';\n\ntype RatingRibbonProps = {\n disabled: boolean;\n stars: number;\n value: number | null | undefined;\n onSelect: (val: number) => void;\n};\n\ntype RatingRibbonState = {\n hovered: null | number;\n};\n\nexport class RatingRibbon extends React.Component<RatingRibbonProps, RatingRibbonState> {\n state = {\n hovered: null,\n };\n\n isSelected = (num: number) => {\n const hovered = this.state.hovered;\n const value = this.props.value;\n\n if (hovered !== null) {\n return num <= hovered;\n }\n if (value) {\n return num <= value;\n }\n return false;\n };\n\n onBlur = () => {\n if (!this.props.disabled) {\n this.setState({ hovered: null });\n }\n };\n\n onFocus = (num: number) => () => {\n if (!this.props.disabled) {\n this.setState({ hovered: num });\n }\n };\n\n render() {\n const items: number[] = [];\n for (let i = 1; i <= this.props.stars; i++) {\n items.push(i);\n }\n\n return (\n <>\n {items.map((num) => (\n <IconButton\n variant=\"transparent\"\n size=\"small\"\n icon={\n <StarIcon\n variant={this.isSelected(num) ? 'primary' : 'muted'}\n className={css({ width: '22px', height: '22px' })}\n />\n }\n data-selected={this.isSelected(num) ? 'true' : 'false'}\n testId=\"rating-editor-star\"\n isDisabled={this.props.disabled}\n key={num}\n onClick={() => {\n this.props.onSelect(num);\n }}\n onKeyDown={(e: React.KeyboardEvent) => {\n if (e.keyCode === 13) {\n this.props.onSelect(num);\n }\n }}\n onMouseOver={this.onFocus(num)}\n onMouseLeave={this.onBlur}\n onFocus={this.onFocus(num)}\n onBlur={this.onBlur}\n aria-label={num.toString()}\n />\n ))}\n </>\n );\n }\n}\n","import * as React from 'react';\nimport get from 'lodash/get';\nimport { FieldAPI, ParametersAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport { RatingRibbon } from './RatingRibbon';\n\nimport { TextLink, Flex } from '@contentful/f36-components';\n\nexport interface RatingEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.parameters\n */\n parameters?: ParametersAPI & {\n instance: {\n stars?: number;\n };\n };\n}\n\nfunction isValidCount(count?: string | number): count is number {\n return typeof count === 'number' && !isNaN(count) && count > 0;\n}\n\nfunction getStarCount(count?: number | string): number {\n const defaultValue = 5;\n\n if (isValidCount(count)) {\n return Math.round(count);\n } else if (typeof count === 'string') {\n const parsed = parseInt(count, 10);\n return isValidCount(parsed) ? Math.round(parsed) : defaultValue;\n } else {\n return defaultValue;\n }\n}\n\nexport function RatingEditor(props: RatingEditorProps) {\n const { field } = props;\n\n const starsCount = getStarCount(get(props.parameters, ['instance', 'stars']));\n\n return (\n <FieldConnector<number>\n throttle={0}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ disabled, value, setValue }) => {\n const clearOption = () => {\n setValue(null);\n };\n\n return (\n <Flex testId=\"rating-editor\" flexDirection=\"row\" marginTop=\"spacingS\">\n <RatingRibbon\n disabled={disabled}\n value={value}\n stars={starsCount}\n onSelect={(num) => {\n setValue(num);\n }}\n />\n {value !== undefined && !disabled && (\n <Flex marginLeft=\"spacingM\">\n <TextLink as=\"button\" testId=\"rating-editor-clear\" onClick={clearOption}>\n Clear\n </TextLink>\n </Flex>\n )}\n </Flex>\n );\n }}\n </FieldConnector>\n );\n}\n\nRatingEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["RatingRibbon","state","hovered","isSelected","num","_this","value","props","onBlur","disabled","setState","onFocus","render","items","i","this","stars","push","React","map","IconButton","variant","size","icon","StarIcon","_this2","className","css","width","height","testId","isDisabled","key","onClick","onSelect","onKeyDown","e","keyCode","onMouseOver","onMouseLeave","toString","isValidCount","count","isNaN","RatingEditor","field","starsCount","Math","round","parsed","parseInt","getStarCount","get","parameters","FieldConnector","throttle","isInitiallyDisabled","setValue","Flex","flexDirection","marginTop","undefined","marginLeft","TextLink","as","defaultProps"],"mappings":"qZAkBaA,8JACXC,MAAQ,CACNC,QAAS,QAGXC,WAAa,SAACC,OACNF,EAAUG,EAAKJ,MAAMC,QACrBI,EAAQD,EAAKE,MAAMD,aAET,OAAZJ,EACKE,GAAOF,IAEZI,GACKF,GAAOE,KAKlBE,OAAS,WACFH,EAAKE,MAAME,YACTC,SAAS,CAAER,QAAS,UAI7BS,QAAU,SAACP,UAAgB,WACpBC,EAAKE,MAAME,YACTC,SAAS,CAAER,QAASE,2GAI7BQ,OAAA,0BACQC,EAAkB,GACfC,EAAI,EAAGA,GAAKC,KAAKR,MAAMS,MAAOF,IACrCD,EAA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