slice-machine-ui 1.22.2 → 1.22.3-alpha.chore-introduce-css-modules.1

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 (168) hide show
  1. package/.depcheckrc +4 -1
  2. package/.eslintignore +1 -0
  3. package/components/DeleteVariationModal/index.tsx +12 -11
  4. package/components/Forms/CreateSliceModal/CreateSliceModal.tsx +2 -5
  5. package/components/Forms/RenameCustomTypeModal/RenameCustomTypeModal.tsx +9 -5
  6. package/components/Forms/RenameVariationModal/RenameVariationModal.tsx +12 -11
  7. package/components/ItemHeader/index.tsx +1 -0
  8. package/components/ListItem/index.tsx +5 -2
  9. package/components/ScreenshotChangesModal/VariationDropZone.tsx +31 -9
  10. package/components/ScreenshotChangesModal/index.tsx +3 -0
  11. package/components/ScreenshotChangesModal/useCustomScreenshot.tsx +5 -5
  12. package/components/Simulator/index.tsx +9 -3
  13. package/lib/builders/CustomTypeBuilder/SliceZone/SlicesTemplatesModal.tsx +2 -2
  14. package/lib/builders/CustomTypeBuilder/SliceZone/UpdateSliceZoneModal.tsx +2 -2
  15. package/lib/builders/CustomTypeBuilder/SliceZone/index.tsx +12 -20
  16. package/lib/builders/CustomTypeBuilder/TabModal/update.tsx +3 -1
  17. package/lib/builders/CustomTypeBuilder/TabZone/index.tsx +119 -52
  18. package/lib/builders/CustomTypeBuilder/index.tsx +39 -42
  19. package/lib/builders/SliceBuilder/FieldZones/index.tsx +81 -56
  20. package/lib/builders/SliceBuilder/Sidebar/AddVariationModal.tsx +24 -16
  21. package/lib/builders/SliceBuilder/Sidebar/index.tsx +44 -46
  22. package/lib/builders/SliceBuilder/SimulatorButton/index.tsx +4 -28
  23. package/lib/builders/SliceBuilder/index.tsx +10 -96
  24. package/lib/builders/common/Zone/Card/components/Hints/CodeBlock.tsx +5 -1
  25. package/lib/builders/common/Zone/Card/components/NewField.tsx +16 -15
  26. package/lib/builders/common/Zone/Card/index.jsx +2 -0
  27. package/lib/builders/common/Zone/index.jsx +3 -1
  28. package/lib/models/common/ComponentUI.ts +0 -14
  29. package/lib/models/common/CustomType/sliceZone.ts +0 -29
  30. package/lib/models/common/CustomType/tab.ts +10 -142
  31. package/lib/models/common/widgets/Group/ListItem/index.jsx +61 -23
  32. package/out/404.html +1 -1
  33. package/out/_next/static/QLcban0JdGEoFu6NgapR9/_buildManifest.js +1 -0
  34. package/out/_next/static/chunks/065a3ddb-9a38ca0d60f0bf2f.js +1 -0
  35. package/out/_next/static/chunks/183-4feb6bb3eddbc768.js +1 -0
  36. package/out/_next/static/chunks/18539003-7b2711e6c51d6fac.js +97 -0
  37. package/out/_next/static/chunks/1cc2734a-2c5b6c0367fcde86.js +1 -0
  38. package/out/_next/static/chunks/25-8fedd33ad9b6de5b.js +1 -0
  39. package/out/_next/static/chunks/286-ed90373e9a469944.js +1 -0
  40. package/out/_next/static/chunks/318-541db69860d31138.js +1 -0
  41. package/out/_next/static/chunks/{505-3f1cf09a086dcba8.js → 376-0ed5822f8afcaa7c.js} +3 -3
  42. package/out/_next/static/chunks/4c744e84-e3161d754618373f.js +1 -0
  43. package/out/_next/static/chunks/50-cfc2514205b86001.js +1 -0
  44. package/out/_next/static/chunks/543-f8766685f7f451e2.js +1 -0
  45. package/out/_next/static/chunks/59b4e022-7a3b5554b806349f.js +1 -0
  46. package/out/_next/static/chunks/696-b12edad30a3617e5.js +31 -0
  47. package/out/_next/static/chunks/727-15cf3f2fea9a37e5.js +1 -0
  48. package/out/_next/static/chunks/731-501990ebe6a71b32.js +1 -0
  49. package/out/_next/static/chunks/904-ccd8ca3368ce29fc.js +1 -0
  50. package/out/_next/static/chunks/{918-38d08f1e885b222d.js → 918-5bb55fb464e34768.js} +1 -1
  51. package/out/_next/static/chunks/f36c6662-03bb5e9d9aa0b0aa.js +1 -0
  52. package/out/_next/static/chunks/pages/_app-3bb7f58b43c87166.js +430 -0
  53. package/out/_next/static/chunks/pages/changelog-68d115a14f1423d7.js +1 -0
  54. package/out/_next/static/chunks/pages/{changes-52c9d917808d1461.js → changes-1cf9e7888029f113.js} +1 -1
  55. package/out/_next/static/chunks/pages/custom-types/{[customTypeId]-3a37eb3373bb8823.js → [customTypeId]-3f862ad6111a1fc0.js} +1 -1
  56. package/out/_next/static/chunks/pages/{custom-types-2f5664d9492b13fb.js → custom-types-94b8f8dbf7727412.js} +1 -1
  57. package/out/_next/static/chunks/pages/{index-d8e3a2c0d712904f.js → index-64cfb8b0948ba8ef.js} +1 -1
  58. package/out/_next/static/chunks/pages/page-types/{[pageTypeId]-733f3890c0466a05.js → [pageTypeId]-d1ffca11c42f2603.js} +1 -1
  59. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-897ca93c114a1435.js +1 -0
  60. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-73dd999915509965.js +1 -0
  61. package/out/_next/static/chunks/pages/slices-7b09cb5130c63bb3.js +1 -0
  62. package/out/_next/static/css/37153180c3b0dd66.css +1 -0
  63. package/out/_next/static/css/538ecf581b0e7c11.css +1 -0
  64. package/out/_next/static/css/{5da5d3cd7a87c3cf.css → 72465cc1225f28a2.css} +1 -1
  65. package/out/_next/static/css/{77abb01eee0e43a7.css → b22c0750c14cc089.css} +1 -1
  66. package/out/_next/static/css/f8eb526e10bc2441.css +1 -0
  67. package/out/changelog.html +1 -1
  68. package/out/changes.html +1 -1
  69. package/out/custom-types/[customTypeId].html +1 -1
  70. package/out/custom-types.html +1 -1
  71. package/out/index.html +1 -1
  72. package/out/labs.html +1 -1
  73. package/out/page-types/[pageTypeId].html +1 -1
  74. package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
  75. package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
  76. package/out/slices.html +1 -1
  77. package/package.json +21 -11
  78. package/pages/slices/[lib]/[sliceName]/[variation]/index.tsx +25 -11
  79. package/pages/slices/[lib]/[sliceName]/[variation]/simulator.tsx +12 -9
  80. package/src/apiClient.ts +7 -6
  81. package/src/components/CodeBlock/CodeBlock.tsx +1 -0
  82. package/src/components/Kbd/Kbd.module.css +10 -0
  83. package/src/components/Kbd/Kbd.module.css.d.ts +5 -0
  84. package/src/components/Kbd/Kbd.tsx +1 -1
  85. package/src/components/Window/Window.tsx +7 -1
  86. package/src/domain/__tests__/customType.test.ts +785 -0
  87. package/src/domain/customType.ts +519 -6
  88. package/src/domain/slice.ts +166 -1
  89. package/src/features/autoSave/AutoSaveStatusIndicator.tsx +43 -0
  90. package/src/features/autoSave/useAutoSave.tsx +177 -0
  91. package/src/features/customTypes/EditDropdown.tsx +3 -0
  92. package/src/features/customTypes/actions/convertCustomToPageType.ts +2 -4
  93. package/src/features/customTypes/customTypesBuilder/CustomTypeProvider.tsx +90 -0
  94. package/src/features/customTypes/customTypesBuilder/CustomTypesBuilderPage.tsx +46 -79
  95. package/src/features/customTypes/customTypesMessages.ts +4 -0
  96. package/src/features/slices/actions/addSlicesToSliceZone.ts +2 -7
  97. package/src/features/slices/actions/uploadSliceScreenshot.ts +45 -0
  98. package/src/features/slices/convertLegacySlice/ConvertLegacySliceAsNewVariationDialog.tsx +5 -5
  99. package/src/features/slices/convertLegacySlice/ConvertLegacySliceButton.tsx +4 -10
  100. package/src/features/slices/sliceBuilder/SliceBuilderProvider.tsx +110 -0
  101. package/src/features/slices/sliceBuilder/actions/deleteVariation.ts +8 -24
  102. package/src/features/slices/sliceBuilder/actions/renameVariation.ts +8 -24
  103. package/src/features/slices/sliceCards/SharedSliceCard.tsx +1 -0
  104. package/src/hooks/useCurrentSlice.tsx +4 -16
  105. package/src/hooks/useScreenshotChangesModal.ts +1 -0
  106. package/src/hooks/useServerState.ts +1 -58
  107. package/src/modules/availableCustomTypes/index.ts +8 -3
  108. package/src/modules/simulator/index.ts +0 -2
  109. package/src/modules/slices/index.ts +32 -25
  110. package/src/modules/slices/selector.ts +30 -0
  111. package/src/modules/useSliceMachineActions.ts +20 -270
  112. package/src/redux/reducer.ts +0 -4
  113. package/src/redux/saga.ts +0 -6
  114. package/src/redux/type.ts +0 -4
  115. package/stylelint.config.js +17 -0
  116. package/test/src/modules/availableCustomTypes/index.test.ts +8 -10
  117. package/test/src/modules/simulator.test.ts +0 -2
  118. package/lib/models/common/CustomType/group.ts +0 -80
  119. package/lib/models/common/Variation.ts +0 -100
  120. package/out/_next/static/3vLhj_JZ10e4rwC2sTZNQ/_buildManifest.js +0 -1
  121. package/out/_next/static/chunks/18539003-4460ccbfe3109578.js +0 -97
  122. package/out/_next/static/chunks/482-49264466566eac99.js +0 -1
  123. package/out/_next/static/chunks/550-c80fd46fb64d1eef.js +0 -1
  124. package/out/_next/static/chunks/80-7b8a97d0122ff74a.js +0 -1
  125. package/out/_next/static/chunks/840-163f8a1040e6820d.js +0 -1
  126. package/out/_next/static/chunks/904-fe1af089657fb0cc.js +0 -1
  127. package/out/_next/static/chunks/958-3d829456f4f5632c.js +0 -1
  128. package/out/_next/static/chunks/pages/_app-f88a66f6532a8e87.js +0 -458
  129. package/out/_next/static/chunks/pages/changelog-4d0f2f1222e403fe.js +0 -1
  130. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-7b17cb59d0db03b5.js +0 -1
  131. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-ef11594ce026b650.js +0 -1
  132. package/out/_next/static/chunks/pages/slices-884a936a9a062a65.js +0 -1
  133. package/out/_next/static/css/1bbf650dfd37ce69.css +0 -1
  134. package/out/_next/static/css/7d650bca12dc4061.css +0 -1
  135. package/out/_next/static/css/cb33580e45d01b59.css +0 -1
  136. package/postcss.config.js +0 -2
  137. package/src/components/Kbd/Kbd.css.ts +0 -16
  138. package/src/domain/__tests__/CustomTypeModel.test.ts +0 -247
  139. package/src/layouts/WithSlice.tsx +0 -26
  140. package/src/modules/screenshots/actions.ts +0 -21
  141. package/src/modules/screenshots/sagas.ts +0 -70
  142. package/src/modules/selectedCustomType/actions.ts +0 -147
  143. package/src/modules/selectedCustomType/index.ts +0 -11
  144. package/src/modules/selectedCustomType/reducer.ts +0 -287
  145. package/src/modules/selectedCustomType/sagas.ts +0 -72
  146. package/src/modules/selectedCustomType/selectors.ts +0 -33
  147. package/src/modules/selectedCustomType/stateHelpers.ts +0 -42
  148. package/src/modules/selectedCustomType/types.ts +0 -9
  149. package/src/modules/selectedSlice/actions.ts +0 -106
  150. package/src/modules/selectedSlice/reducer.ts +0 -175
  151. package/src/modules/selectedSlice/sagas.ts +0 -72
  152. package/src/modules/selectedSlice/selectors.ts +0 -55
  153. package/src/modules/selectedSlice/types.ts +0 -3
  154. package/src/modules/toaster/utils.tsx +0 -23
  155. package/test/lib/models/common/CustomType/sliceZone.test.ts +0 -49
  156. package/test/pages/custom-types.test.tsx +0 -625
  157. package/test/src/modules/selectedCustomType/__fixtures__/model.json +0 -119
  158. package/test/src/modules/selectedCustomType/reducer.test.ts +0 -322
  159. package/test/src/modules/selectedCustomType/sagas.test.ts +0 -89
  160. package/test/src/modules/selectedCustomType/selectors.test.ts +0 -54
  161. package/test/src/modules/selectedSlice/__fixtures__/mocks.json +0 -171
  162. package/test/src/modules/selectedSlice/__fixtures__/model.json +0 -35
  163. package/test/src/modules/selectedSlice/__testutils__/getRefreshStateCreatorPayloadData.ts +0 -72
  164. package/test/src/modules/selectedSlice/__testutils__/getSelectedSliceDummyData.ts +0 -30
  165. package/test/src/modules/selectedSlice/reducer.test.ts +0 -170
  166. package/test/src/modules/selectedSlice/sagas.test.ts +0 -82
  167. package/test/src/modules/toaster/utils.test.ts +0 -50
  168. /package/out/_next/static/{3vLhj_JZ10e4rwC2sTZNQ → QLcban0JdGEoFu6NgapR9}/_ssgManifest.js +0 -0
@@ -1,287 +0,0 @@
1
- import { Reducer } from "redux";
2
- import { SelectedCustomTypeStoreType } from "./types";
3
- import { getType } from "typesafe-actions";
4
- import {
5
- createTabCreator,
6
- updateTabCreator,
7
- SelectedCustomTypeActions,
8
- initCustomTypeStoreCreator,
9
- cleanupCustomTypeStoreCreator,
10
- addFieldCreator,
11
- deleteTabCreator,
12
- renameSelectedCustomTypeLabel,
13
- createSliceZoneCreator,
14
- deleteSliceZoneCreator,
15
- deleteFieldCreator,
16
- deleteSharedSliceCreator,
17
- reorderFieldCreator,
18
- replaceFieldCreator,
19
- addFieldIntoGroupCreator,
20
- deleteFieldIntoGroupCreator,
21
- reorderFieldIntoGroupCreator,
22
- replaceFieldIntoGroupCreator,
23
- saveCustomTypeCreator,
24
- } from "./actions";
25
- import { Tab } from "@models/common/CustomType/tab";
26
- import { SliceZone } from "@models/common/CustomType/sliceZone";
27
- import { AnyWidget } from "@models/common/widgets/Widget";
28
- import * as Widgets from "@models/common/widgets/withGroup";
29
- import StateHelpers from "./stateHelpers";
30
- import { CustomType } from "@models/common/CustomType";
31
- import { SlicesSM } from "@lib/models/common/Slices";
32
- import { GroupSM } from "@lib/models/common/Group";
33
- import { Group } from "@lib/models/common/CustomType/group";
34
-
35
- // Reducer
36
- export const selectedCustomTypeReducer: Reducer<
37
- SelectedCustomTypeStoreType,
38
- SelectedCustomTypeActions
39
- > = (state = null, action) => {
40
- switch (action.type) {
41
- case getType(cleanupCustomTypeStoreCreator):
42
- return null;
43
- case getType(initCustomTypeStoreCreator):
44
- return {
45
- ...state,
46
- model: action.payload.model,
47
- initialModel: action.payload.model,
48
- remoteModel: action.payload.remoteModel,
49
- };
50
- case getType(saveCustomTypeCreator.success): {
51
- if (!state) return state;
52
-
53
- return {
54
- ...state,
55
- initialModel: state.model,
56
- };
57
- }
58
- case getType(createTabCreator):
59
- if (!state) return state;
60
- const { tabId } = action.payload;
61
- if (state.model.tabs.find((e) => e.key === tabId)) {
62
- return state;
63
- }
64
- return {
65
- ...state,
66
- model: {
67
- ...state.model,
68
- tabs: [...state.model.tabs, Tab.init(tabId)],
69
- },
70
- };
71
- case getType(updateTabCreator): {
72
- if (!state) return state;
73
- const { tabId, newTabId } = action.payload;
74
- if (newTabId === tabId) {
75
- return state;
76
- }
77
- return {
78
- ...state,
79
- model: {
80
- ...state.model,
81
- tabs: state.model.tabs.map((t) => {
82
- if (t.key === tabId) {
83
- return {
84
- ...t,
85
- key: newTabId,
86
- };
87
- }
88
- return t;
89
- }),
90
- },
91
- };
92
- }
93
- case getType(renameSelectedCustomTypeLabel): {
94
- if (!state) return state;
95
- return {
96
- ...state,
97
- model: {
98
- ...state.model,
99
- label: action.payload.newLabel,
100
- },
101
- };
102
- }
103
- case getType(deleteTabCreator): {
104
- if (!state) return state;
105
- const { tabId } = action.payload;
106
- return StateHelpers.deleteTab(state, tabId);
107
- }
108
- case getType(addFieldCreator): {
109
- const { tabId, field, fieldId } = action.payload;
110
- try {
111
- if (
112
- field.type === "Range" ||
113
- field.type === "IntegrationFields" ||
114
- field.type === "Separator"
115
- ) {
116
- throw new Error("Unsupported Field Type.");
117
- }
118
- const CurrentWidget: AnyWidget = Widgets[field.type];
119
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
120
- CurrentWidget.schema.validateSync(field, { stripUnknown: false });
121
- return StateHelpers.updateTab(
122
- state,
123
- tabId,
124
- )((tab) => Tab.addWidget(tab, fieldId, field));
125
- } catch (err) {
126
- console.error(
127
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
128
- `[store/addWidget] Model is invalid for widget "${field.type}".\nFull error: ${err}`,
129
- );
130
- return state;
131
- }
132
- }
133
- case getType(deleteFieldCreator): {
134
- const { tabId, fieldId } = action.payload;
135
- return StateHelpers.updateTab(
136
- state,
137
- tabId,
138
- )((tab) => Tab.removeWidget(tab, fieldId));
139
- }
140
- case getType(replaceFieldCreator): {
141
- const { tabId, previousFieldId, newFieldId, value } = action.payload;
142
- try {
143
- if (
144
- value.type === "Range" ||
145
- value.type === "IntegrationFields" ||
146
- value.type === "Separator"
147
- ) {
148
- throw new Error("Unsupported Field Type.");
149
- }
150
- const CurrentWidget: AnyWidget = Widgets[value.type];
151
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
152
- CurrentWidget.schema.validateSync(value, { stripUnknown: false });
153
- return StateHelpers.updateTab(
154
- state,
155
- tabId,
156
- )((tab) => Tab.replaceWidget(tab, previousFieldId, newFieldId, value));
157
- } catch (err) {
158
- return state;
159
- }
160
- }
161
- case getType(reorderFieldCreator): {
162
- const { tabId, start, end } = action.payload;
163
- return StateHelpers.updateTab(
164
- state,
165
- tabId,
166
- )((tab) => Tab.reorderWidget(tab, start, end));
167
- }
168
- case getType(createSliceZoneCreator): {
169
- if (!state) return state;
170
- const { tabId } = action.payload;
171
- const tabIndex = state.model.tabs.findIndex((t) => t.key === tabId);
172
-
173
- if (tabIndex === -1) {
174
- console.error(`No tabId ${tabId} found in tabs`);
175
- return state;
176
- }
177
-
178
- const existingSliceZones = CustomType.getSliceZones(state.model).filter(
179
- (e) => e,
180
- );
181
- return StateHelpers.updateTab(
182
- state,
183
- tabId,
184
- )((tab) => {
185
- const i = findAvailableKey(tabIndex, existingSliceZones);
186
- return Tab.createSliceZone(tab, `slices${i !== 0 ? i.toString() : ""}`);
187
- });
188
- }
189
- case getType(deleteSliceZoneCreator): {
190
- if (!state) return state;
191
- const { tabId } = action.payload;
192
- const tabIndex = state.model.tabs.findIndex((t) => t.key === tabId);
193
-
194
- if (tabIndex === -1) {
195
- console.error(`No tabId ${tabId} found in tabs`);
196
- return state;
197
- }
198
-
199
- return StateHelpers.updateTab(
200
- state,
201
- tabId,
202
- )((tab) => {
203
- return Tab.deleteSliceZone(tab);
204
- });
205
- }
206
- case getType(deleteSharedSliceCreator): {
207
- const { tabId, sliceId } = action.payload;
208
- return StateHelpers.updateTab(
209
- state,
210
- tabId,
211
- )((tab) =>
212
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
213
- Tab.updateSliceZone(tab)((sliceZone: SlicesSM) =>
214
- SliceZone.removeSharedSlice(sliceZone, sliceId),
215
- ),
216
- );
217
- }
218
- case getType(addFieldIntoGroupCreator): {
219
- const { tabId, groupId, fieldId, field } = action.payload;
220
- return StateHelpers.updateTab(
221
- state,
222
- tabId,
223
- )((tab) =>
224
- Tab.updateGroup(
225
- tab,
226
- groupId,
227
- )((group: GroupSM) =>
228
- Group.addWidget(group, { key: fieldId, value: field }),
229
- ),
230
- );
231
- }
232
- case getType(replaceFieldIntoGroupCreator): {
233
- const { tabId, groupId, previousFieldId, newFieldId, value } =
234
- action.payload;
235
- return StateHelpers.updateTab(
236
- state,
237
- tabId,
238
- )((tab) =>
239
- Tab.updateGroup(
240
- tab,
241
- groupId,
242
- )((group: GroupSM) =>
243
- Group.replaceWidget(group, previousFieldId, newFieldId, value),
244
- ),
245
- );
246
- }
247
- case getType(deleteFieldIntoGroupCreator): {
248
- const { tabId, groupId, fieldId } = action.payload;
249
- return StateHelpers.updateTab(
250
- state,
251
- tabId,
252
- )((tab) =>
253
- Tab.updateGroup(
254
- tab,
255
- groupId,
256
- )((group: GroupSM) => Group.deleteWidget(group, fieldId)),
257
- );
258
- }
259
- case getType(reorderFieldIntoGroupCreator): {
260
- const { tabId, groupId, start, end } = action.payload;
261
- return StateHelpers.updateTab(
262
- state,
263
- tabId,
264
- )((tab) =>
265
- Tab.updateGroup(
266
- tab,
267
- groupId,
268
- )((group: GroupSM) => Group.reorderWidget(group, start, end)),
269
- );
270
- }
271
- default:
272
- return state;
273
- }
274
- };
275
-
276
- const findAvailableKey = (
277
- startI: number,
278
- existingSliceZones: (SlicesSM | null)[],
279
- ) => {
280
- for (let i = startI; i < Infinity; i++) {
281
- const key = `slices${i.toString()}`;
282
- if (!existingSliceZones.find((e) => e?.key === key)) {
283
- return i;
284
- }
285
- }
286
- return -1;
287
- };
@@ -1,72 +0,0 @@
1
- import { call, fork, put, select, takeLatest } from "redux-saga/effects";
2
- import { openToasterCreator, ToasterType } from "../toaster";
3
- import { getType } from "typesafe-actions";
4
- import { withLoader } from "../loading";
5
- import { LoadingKeysEnum } from "../loading/types";
6
- import { saveCustomTypeCreator } from "./actions";
7
- import { selectCurrentCustomType } from "./index";
8
- import { saveCustomType, telemetry } from "@src/apiClient";
9
- import { ToastMessageWithPath } from "@components/ToasterContainer";
10
- import { CUSTOM_TYPES_MESSAGES } from "@src/features/customTypes/customTypesMessages";
11
-
12
- export function* saveCustomTypeSaga() {
13
- try {
14
- const currentCustomType = (yield select(
15
- selectCurrentCustomType,
16
- )) as ReturnType<typeof selectCurrentCustomType>;
17
-
18
- if (!currentCustomType) {
19
- return;
20
- }
21
-
22
- const { errors } = (yield call(
23
- saveCustomType,
24
- currentCustomType,
25
- )) as Awaited<ReturnType<typeof saveCustomType>>;
26
- if (errors.length) {
27
- throw errors;
28
- }
29
- void telemetry.track({
30
- event: "custom-type:saved",
31
- id: currentCustomType.id,
32
- name: currentCustomType.label ?? currentCustomType.id,
33
- format: currentCustomType.format,
34
- type: currentCustomType.repeatable ? "repeatable" : "single",
35
- });
36
- yield put(saveCustomTypeCreator.success({ customType: currentCustomType }));
37
- const formatName = CUSTOM_TYPES_MESSAGES[currentCustomType.format].name({
38
- start: true,
39
- plural: false,
40
- });
41
- yield put(
42
- openToasterCreator({
43
- content: ToastMessageWithPath({
44
- message: `${formatName} saved successfully at `,
45
- path: `./customtypes/${currentCustomType.id}/index.json`,
46
- }),
47
- type: ToasterType.SUCCESS,
48
- }),
49
- );
50
- } catch (e) {
51
- // Unknown errors
52
- yield put(
53
- openToasterCreator({
54
- content: "Internal Error: Custom type not saved",
55
- type: ToasterType.ERROR,
56
- }),
57
- );
58
- }
59
- }
60
-
61
- // Saga watchers
62
- function* watchSaveCustomType() {
63
- yield takeLatest(
64
- getType(saveCustomTypeCreator.request),
65
- withLoader(saveCustomTypeSaga, LoadingKeysEnum.SAVE_CUSTOM_TYPE),
66
- );
67
- }
68
-
69
- // Saga Exports
70
- export function* watchSelectedCustomTypeSagas() {
71
- yield fork(watchSaveCustomType);
72
- }
@@ -1,33 +0,0 @@
1
- import { SliceMachineStoreType } from "@src/redux/type";
2
- import equal from "fast-deep-equal";
3
- import { PoolOfFields } from "@src/modules/selectedCustomType/types";
4
- import { CustomTypeSM, TabSM } from "@lib/models/common/CustomType";
5
-
6
- // Selectors
7
- export const selectCurrentCustomType = (
8
- store: SliceMachineStoreType,
9
- ): CustomTypeSM | null => {
10
- if (!store.selectedCustomType) return null;
11
- return store.selectedCustomType.model;
12
- };
13
-
14
- export const selectCurrentPoolOfFields = (
15
- store: SliceMachineStoreType,
16
- ): PoolOfFields => {
17
- if (!store.selectedCustomType) return [];
18
- return store.selectedCustomType.model.tabs.reduce<PoolOfFields>(
19
- (acc: PoolOfFields, curr: TabSM) => {
20
- return [...acc, ...curr.value];
21
- },
22
- [],
23
- );
24
- };
25
-
26
- export const isSelectedCustomTypeTouched = (store: SliceMachineStoreType) => {
27
- if (!store.selectedCustomType) return false;
28
-
29
- return !equal(
30
- store.selectedCustomType.initialModel,
31
- store.selectedCustomType.model,
32
- );
33
- };
@@ -1,42 +0,0 @@
1
- import { TabSM } from "@lib/models/common/CustomType";
2
- import { SelectedCustomTypeStoreType } from "@src/modules/selectedCustomType/types";
3
-
4
- const updateTab =
5
- (state: SelectedCustomTypeStoreType, tabId: string) =>
6
- (mutate: (v: TabSM) => TabSM): SelectedCustomTypeStoreType => {
7
- if (!state) return state;
8
-
9
- const tabs = state.model.tabs.map((tab) => {
10
- if (tab.key === tabId) return mutate(tab);
11
- else return tab;
12
- });
13
-
14
- return {
15
- ...state,
16
- model: {
17
- ...state.model,
18
- tabs,
19
- },
20
- };
21
- };
22
-
23
- const deleteTab = (
24
- state: SelectedCustomTypeStoreType,
25
- tabId: string,
26
- ): SelectedCustomTypeStoreType => {
27
- if (!state) return state;
28
- const tabs = state.model.tabs.filter((v) => v.key !== tabId);
29
-
30
- return {
31
- ...state,
32
- model: {
33
- ...state.model,
34
- tabs,
35
- },
36
- };
37
- };
38
-
39
- export default {
40
- deleteTab,
41
- updateTab,
42
- };
@@ -1,9 +0,0 @@
1
- import { CustomTypeSM, TabField } from "@lib/models/common/CustomType";
2
-
3
- export type PoolOfFields = ReadonlyArray<{ key: string; value: TabField }>;
4
-
5
- export type SelectedCustomTypeStoreType = {
6
- model: CustomTypeSM;
7
- initialModel: CustomTypeSM;
8
- remoteModel: CustomTypeSM | undefined;
9
- } | null;
@@ -1,106 +0,0 @@
1
- import { ActionType, createAction, createAsyncAction } from "typesafe-actions";
2
- import { NestableWidget } from "@prismicio/types-internal/lib/customtypes";
3
- import type { SliceBuilderState } from "@builders/SliceBuilder";
4
- import { ComponentUI } from "@lib/models/common/ComponentUI";
5
- import { renameSliceCreator } from "../slices";
6
- import { SelectedSliceStoreType } from "./types";
7
- import { refreshStateCreator } from "../environment";
8
- import { generateSliceCustomScreenshotCreator } from "../screenshots/actions";
9
- import { VariationSM, WidgetsArea } from "@lib/models/common/Slice";
10
- import { SharedSliceContent } from "@prismicio/types-internal/lib/content";
11
-
12
- export type SelectedSliceActions =
13
- | ActionType<typeof initSliceStoreCreator>
14
- | ActionType<typeof addSliceWidgetCreator>
15
- | ActionType<typeof replaceSliceWidgetCreator>
16
- | ActionType<typeof reorderSliceWidgetCreator>
17
- | ActionType<typeof removeSliceWidgetCreator>
18
- | ActionType<typeof updateSliceWidgetMockCreator>
19
- | ActionType<typeof deleteSliceWidgetMockCreator>
20
- | ActionType<typeof updateSliceCreator>
21
- | ActionType<typeof updateAndSaveSliceCreator>
22
- | ActionType<typeof copyVariationSliceCreator>
23
- | ActionType<typeof renameSliceCreator>
24
- | ActionType<typeof refreshStateCreator>
25
- | ActionType<typeof generateSliceCustomScreenshotCreator>
26
- | ActionType<typeof updateSelectedSliceMocks>;
27
-
28
- export const updateSelectedSliceMocks = createAction(
29
- "SELECTED_SLICE/UPDATE_MOCKS",
30
- )<{
31
- mocks: SharedSliceContent[];
32
- }>();
33
-
34
- export const initSliceStoreCreator =
35
- createAction("SLICE/INIT")<SelectedSliceStoreType>();
36
-
37
- export const addSliceWidgetCreator = createAction("SLICE/ADD_WIDGET")<{
38
- variationId: string;
39
- widgetsArea: WidgetsArea;
40
- key: string;
41
- value: NestableWidget;
42
- }>();
43
-
44
- export const replaceSliceWidgetCreator = createAction("SLICE/REPLACE_WIDGET")<{
45
- variationId: string;
46
- widgetsArea: WidgetsArea;
47
- previousKey: string;
48
- newKey: string;
49
- value: NestableWidget;
50
- }>();
51
-
52
- export const reorderSliceWidgetCreator = createAction("SLICE/REORDER_WIDGET")<{
53
- variationId: string;
54
- widgetsArea: WidgetsArea;
55
- start: number;
56
- end: number | undefined;
57
- }>();
58
-
59
- export const removeSliceWidgetCreator = createAction("SLICE/REMOVE_WIDGET")<{
60
- variationId: string;
61
- widgetsArea: WidgetsArea;
62
- key: string;
63
- }>();
64
-
65
- export const updateSliceWidgetMockCreator = createAction(
66
- "SLICE/UPDATE_WIDGET_MOCK",
67
- )<{
68
- variationId: string;
69
- widgetArea: WidgetsArea;
70
- previousKey: string;
71
- newKey: string;
72
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
- mockValue: any;
74
- }>();
75
-
76
- export const deleteSliceWidgetMockCreator = createAction(
77
- "SLICE/DELETE_WIDGET_MOCK",
78
- )<{
79
- variationId: string;
80
- widgetArea: WidgetsArea;
81
- newKey: string;
82
- }>();
83
-
84
- export const updateSliceCreator = createAsyncAction(
85
- "SLICE/UPDATE.REQUEST",
86
- "SLICE/UPDATE.RESPONSE",
87
- "SLICE/UPDATE.FAILURE",
88
- )<
89
- {
90
- component: ComponentUI;
91
- setSliceBuilderState: (sliceBuilderState: SliceBuilderState) => void;
92
- },
93
- {
94
- component: ComponentUI;
95
- }
96
- >();
97
-
98
- export const updateAndSaveSliceCreator = createAction("SLICE/UPDATE_AND_SAVE")<{
99
- component: ComponentUI;
100
- }>();
101
-
102
- export const copyVariationSliceCreator = createAction("SLICE/COPY_VARIATION")<{
103
- key: string;
104
- name: string;
105
- copied: VariationSM;
106
- }>();