@creopse/react 0.0.10 → 0.0.12
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/hooks/index.cjs +30 -50
- package/dist/hooks/index.mjs +31 -51
- package/dist/{index-ZewuA4XM.cjs → index-hI__ihu3.cjs} +45 -16
- package/dist/{index-4XGApE5d.js → index-jw_2nhs3.js} +50 -21
- package/dist/index.cjs +18 -1
- package/dist/index.mjs +18 -1
- package/package.json +1 -1
- package/types/core/contexts.d.ts +1 -1
- package/types/core/props-manager.d.ts +7 -6
- package/types/hooks/config.d.ts +1 -0
- package/types/hooks/content.d.ts +0 -4
- package/types/hooks/helper.d.ts +5 -5
- package/types/hooks/props.d.ts +3 -2
- package/types/types/plugin.d.ts +8 -2
package/dist/hooks/index.cjs
CHANGED
|
@@ -1,50 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const index = require("../index-
|
|
4
|
-
const React = require("react");
|
|
3
|
+
const index = require("../index-hI__ihu3.cjs");
|
|
5
4
|
const react = require("@inertiajs/react");
|
|
6
|
-
const
|
|
7
|
-
const manager = React.useContext(index.PropsContext);
|
|
8
|
-
if (!manager) {
|
|
9
|
-
throw new Error("[@creopse/react] CreopseProvider not found in tree");
|
|
10
|
-
}
|
|
11
|
-
const [props, setProps] = React.useState(manager.getState().props);
|
|
12
|
-
React.useEffect(() => {
|
|
13
|
-
const unsubscribe = manager.subscribe((newProps) => {
|
|
14
|
-
setProps(newProps);
|
|
15
|
-
});
|
|
16
|
-
return unsubscribe;
|
|
17
|
-
}, [manager]);
|
|
18
|
-
return props;
|
|
19
|
-
};
|
|
5
|
+
const React = require("react");
|
|
20
6
|
const useContent = () => {
|
|
21
7
|
const { request } = index.useApi();
|
|
22
8
|
const { fileUrl } = index.useHelper();
|
|
9
|
+
const props = index.useProps();
|
|
23
10
|
const page = react.usePage();
|
|
24
11
|
const resolveSections = React.useContext(index.ResolveSectionsContext);
|
|
25
|
-
const getProps = React.useCallback(
|
|
26
|
-
() => page.props,
|
|
27
|
-
[page.props]
|
|
28
|
-
);
|
|
29
12
|
const pageData = React.useMemo(
|
|
30
|
-
() =>
|
|
31
|
-
[
|
|
13
|
+
() => props.pageData,
|
|
14
|
+
[props.pageData]
|
|
32
15
|
);
|
|
33
16
|
const newsArticle = React.useMemo(
|
|
34
|
-
() =>
|
|
35
|
-
[
|
|
17
|
+
() => props.article,
|
|
18
|
+
[props.article]
|
|
36
19
|
);
|
|
37
20
|
const newsCategory = React.useMemo(
|
|
38
|
-
() =>
|
|
39
|
-
[
|
|
21
|
+
() => props.category,
|
|
22
|
+
[props.category]
|
|
40
23
|
);
|
|
41
24
|
const newsTag = React.useMemo(
|
|
42
|
-
() =>
|
|
43
|
-
[
|
|
25
|
+
() => props.tag,
|
|
26
|
+
[props.tag]
|
|
44
27
|
);
|
|
45
28
|
const contentModelItem = React.useMemo(
|
|
46
|
-
() =>
|
|
47
|
-
[
|
|
29
|
+
() => props.contentModelItem,
|
|
30
|
+
[props.contentModelItem]
|
|
48
31
|
);
|
|
49
32
|
const getSectionData = React.useCallback(
|
|
50
33
|
(key) => {
|
|
@@ -52,11 +35,11 @@ const useContent = () => {
|
|
|
52
35
|
const keyParts = key.split("__");
|
|
53
36
|
const slug = keyParts.length ? keyParts[0] : "";
|
|
54
37
|
const linkId = keyParts.length > 1 ? keyParts[1] : "";
|
|
55
|
-
return
|
|
38
|
+
return props.pageData?.sections?.find(
|
|
56
39
|
(section) => section.slug === slug && section.pivot?.linkId === linkId
|
|
57
40
|
)?.pivot?.data || null;
|
|
58
41
|
},
|
|
59
|
-
[
|
|
42
|
+
[props.pageData?.sections]
|
|
60
43
|
);
|
|
61
44
|
const getSectionRootData = React.useCallback(
|
|
62
45
|
(key) => getSectionData(key)?.index,
|
|
@@ -68,11 +51,11 @@ const useContent = () => {
|
|
|
68
51
|
const keyParts = key.split("__");
|
|
69
52
|
const slug = keyParts.length ? keyParts[0] : "";
|
|
70
53
|
const linkId = keyParts.length > 1 ? keyParts[1] : "";
|
|
71
|
-
return
|
|
54
|
+
return props.pageData?.sections?.find(
|
|
72
55
|
(section) => section.slug === slug && section.pivot?.linkId === linkId
|
|
73
56
|
)?.pivot?.settings || null;
|
|
74
57
|
},
|
|
75
|
-
[
|
|
58
|
+
[props.pageData?.sections]
|
|
76
59
|
);
|
|
77
60
|
const getSectionSettingsGroup = React.useCallback(
|
|
78
61
|
(key, group) => {
|
|
@@ -143,11 +126,11 @@ const useContent = () => {
|
|
|
143
126
|
}, [resolveSections]);
|
|
144
127
|
const getContentModel = React.useCallback(
|
|
145
128
|
(name) => {
|
|
146
|
-
return
|
|
129
|
+
return props?.contentModels?.find(
|
|
147
130
|
(contentModel) => contentModel.name === name
|
|
148
131
|
);
|
|
149
132
|
},
|
|
150
|
-
[
|
|
133
|
+
[props?.contentModels]
|
|
151
134
|
);
|
|
152
135
|
const formatContentModelItemData = React.useCallback(
|
|
153
136
|
(item) => {
|
|
@@ -203,7 +186,7 @@ const useContent = () => {
|
|
|
203
186
|
);
|
|
204
187
|
const getMenu = React.useCallback(
|
|
205
188
|
(name, filterByIsActive = true) => {
|
|
206
|
-
const menu =
|
|
189
|
+
const menu = props?.menus?.find((menu2) => menu2.name === name);
|
|
207
190
|
if (menu) {
|
|
208
191
|
menu.items = index.cloneDeep(
|
|
209
192
|
menu.items?.filter((item) => !filterByIsActive || item.isActive)?.sort((a, b) => a.position - b.position)
|
|
@@ -211,13 +194,11 @@ const useContent = () => {
|
|
|
211
194
|
}
|
|
212
195
|
return menu;
|
|
213
196
|
},
|
|
214
|
-
[
|
|
197
|
+
[props?.menus]
|
|
215
198
|
);
|
|
216
199
|
const getMenuByLocation = React.useCallback(
|
|
217
200
|
(name, filterByIsActive = true) => {
|
|
218
|
-
const menu =
|
|
219
|
-
(menu2) => menu2.location?.name === name
|
|
220
|
-
);
|
|
201
|
+
const menu = props?.menus?.find((menu2) => menu2.location?.name === name);
|
|
221
202
|
if (menu) {
|
|
222
203
|
menu.items = index.cloneDeep(
|
|
223
204
|
menu.items?.filter((item) => !filterByIsActive || item.isActive)?.sort((a, b) => a.position - b.position)
|
|
@@ -225,7 +206,7 @@ const useContent = () => {
|
|
|
225
206
|
}
|
|
226
207
|
return menu;
|
|
227
208
|
},
|
|
228
|
-
[
|
|
209
|
+
[props?.menus]
|
|
229
210
|
);
|
|
230
211
|
const getMenuItems = React.useCallback(
|
|
231
212
|
(name, filterByIsVisible = true) => {
|
|
@@ -236,13 +217,13 @@ const useContent = () => {
|
|
|
236
217
|
const getMenuItemById = React.useCallback(
|
|
237
218
|
(id) => {
|
|
238
219
|
const menuItems = [];
|
|
239
|
-
const menus =
|
|
220
|
+
const menus = props?.menus || [];
|
|
240
221
|
menus.forEach((menu) => {
|
|
241
222
|
if (Array.isArray(menu.items)) menuItems.push(...menu.items);
|
|
242
223
|
});
|
|
243
224
|
return menuItems.find((item) => item.id === id);
|
|
244
225
|
},
|
|
245
|
-
[
|
|
226
|
+
[props?.menus]
|
|
246
227
|
);
|
|
247
228
|
const getMenuItemsByLocation = React.useCallback(
|
|
248
229
|
(name, filterByIsVisible = true) => {
|
|
@@ -260,7 +241,7 @@ const useContent = () => {
|
|
|
260
241
|
(group) => group.id === item.menuItemGroupId
|
|
261
242
|
);
|
|
262
243
|
if (!groupAlreadyExists) {
|
|
263
|
-
const group =
|
|
244
|
+
const group = props?.menuItemGroups?.find(
|
|
264
245
|
(group2) => group2.id === item.menuItemGroupId
|
|
265
246
|
);
|
|
266
247
|
if (group) groups.push(group);
|
|
@@ -269,7 +250,7 @@ const useContent = () => {
|
|
|
269
250
|
}
|
|
270
251
|
return groups;
|
|
271
252
|
},
|
|
272
|
-
[getMenuItems, getMenuItemsByLocation,
|
|
253
|
+
[getMenuItems, getMenuItemsByLocation, props?.menuItemGroups]
|
|
273
254
|
);
|
|
274
255
|
const getMenuItemsByGroup = React.useCallback(
|
|
275
256
|
(name, groupId, byLocation = false, filterByIsVisible = true) => {
|
|
@@ -302,7 +283,7 @@ const useContent = () => {
|
|
|
302
283
|
);
|
|
303
284
|
const getAppInformationValue = React.useCallback(
|
|
304
285
|
(key, type = "string") => {
|
|
305
|
-
const appInformation =
|
|
286
|
+
const appInformation = props.appInformation;
|
|
306
287
|
const setting = appInformation.find((s) => s.key === key);
|
|
307
288
|
let value = "";
|
|
308
289
|
switch (type) {
|
|
@@ -324,7 +305,7 @@ const useContent = () => {
|
|
|
324
305
|
}
|
|
325
306
|
return value;
|
|
326
307
|
},
|
|
327
|
-
[
|
|
308
|
+
[props.appInformation]
|
|
328
309
|
);
|
|
329
310
|
const appPrimaryColor = React.useMemo(() => {
|
|
330
311
|
const primaryColor = getAppInformationValue(
|
|
@@ -359,7 +340,6 @@ const useContent = () => {
|
|
|
359
340
|
newsCategory,
|
|
360
341
|
newsTag,
|
|
361
342
|
contentModelItem,
|
|
362
|
-
getProps,
|
|
363
343
|
getMenu,
|
|
364
344
|
getMenuByLocation,
|
|
365
345
|
getMenuItems,
|
|
@@ -433,6 +413,6 @@ const useNewsletter = () => {
|
|
|
433
413
|
exports.useApi = index.useApi;
|
|
434
414
|
exports.useConfig = index.useConfig;
|
|
435
415
|
exports.useHelper = index.useHelper;
|
|
416
|
+
exports.useProps = index.useProps;
|
|
436
417
|
exports.useContent = useContent;
|
|
437
418
|
exports.useNewsletter = useNewsletter;
|
|
438
|
-
exports.useProps = useProps;
|
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,49 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { useContext, useState, useEffect, useCallback, useMemo } from "react";
|
|
1
|
+
import { c as useApi, u as useHelper, a as useProps, b as ResolveSectionsContext, d as cloneDeep } from "../index-jw_2nhs3.js";
|
|
2
|
+
import { e } from "../index-jw_2nhs3.js";
|
|
4
3
|
import { usePage } from "@inertiajs/react";
|
|
5
|
-
|
|
6
|
-
const manager = useContext(PropsContext);
|
|
7
|
-
if (!manager) {
|
|
8
|
-
throw new Error("[@creopse/react] CreopseProvider not found in tree");
|
|
9
|
-
}
|
|
10
|
-
const [props, setProps] = useState(manager.getState().props);
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
const unsubscribe = manager.subscribe((newProps) => {
|
|
13
|
-
setProps(newProps);
|
|
14
|
-
});
|
|
15
|
-
return unsubscribe;
|
|
16
|
-
}, [manager]);
|
|
17
|
-
return props;
|
|
18
|
-
};
|
|
4
|
+
import { useContext, useMemo, useCallback, useState } from "react";
|
|
19
5
|
const useContent = () => {
|
|
20
6
|
const { request } = useApi();
|
|
21
7
|
const { fileUrl } = useHelper();
|
|
8
|
+
const props = useProps();
|
|
22
9
|
const page = usePage();
|
|
23
10
|
const resolveSections = useContext(ResolveSectionsContext);
|
|
24
|
-
const getProps = useCallback(
|
|
25
|
-
() => page.props,
|
|
26
|
-
[page.props]
|
|
27
|
-
);
|
|
28
11
|
const pageData = useMemo(
|
|
29
|
-
() =>
|
|
30
|
-
[
|
|
12
|
+
() => props.pageData,
|
|
13
|
+
[props.pageData]
|
|
31
14
|
);
|
|
32
15
|
const newsArticle = useMemo(
|
|
33
|
-
() =>
|
|
34
|
-
[
|
|
16
|
+
() => props.article,
|
|
17
|
+
[props.article]
|
|
35
18
|
);
|
|
36
19
|
const newsCategory = useMemo(
|
|
37
|
-
() =>
|
|
38
|
-
[
|
|
20
|
+
() => props.category,
|
|
21
|
+
[props.category]
|
|
39
22
|
);
|
|
40
23
|
const newsTag = useMemo(
|
|
41
|
-
() =>
|
|
42
|
-
[
|
|
24
|
+
() => props.tag,
|
|
25
|
+
[props.tag]
|
|
43
26
|
);
|
|
44
27
|
const contentModelItem = useMemo(
|
|
45
|
-
() =>
|
|
46
|
-
[
|
|
28
|
+
() => props.contentModelItem,
|
|
29
|
+
[props.contentModelItem]
|
|
47
30
|
);
|
|
48
31
|
const getSectionData = useCallback(
|
|
49
32
|
(key) => {
|
|
@@ -51,11 +34,11 @@ const useContent = () => {
|
|
|
51
34
|
const keyParts = key.split("__");
|
|
52
35
|
const slug = keyParts.length ? keyParts[0] : "";
|
|
53
36
|
const linkId = keyParts.length > 1 ? keyParts[1] : "";
|
|
54
|
-
return
|
|
37
|
+
return props.pageData?.sections?.find(
|
|
55
38
|
(section) => section.slug === slug && section.pivot?.linkId === linkId
|
|
56
39
|
)?.pivot?.data || null;
|
|
57
40
|
},
|
|
58
|
-
[
|
|
41
|
+
[props.pageData?.sections]
|
|
59
42
|
);
|
|
60
43
|
const getSectionRootData = useCallback(
|
|
61
44
|
(key) => getSectionData(key)?.index,
|
|
@@ -67,11 +50,11 @@ const useContent = () => {
|
|
|
67
50
|
const keyParts = key.split("__");
|
|
68
51
|
const slug = keyParts.length ? keyParts[0] : "";
|
|
69
52
|
const linkId = keyParts.length > 1 ? keyParts[1] : "";
|
|
70
|
-
return
|
|
53
|
+
return props.pageData?.sections?.find(
|
|
71
54
|
(section) => section.slug === slug && section.pivot?.linkId === linkId
|
|
72
55
|
)?.pivot?.settings || null;
|
|
73
56
|
},
|
|
74
|
-
[
|
|
57
|
+
[props.pageData?.sections]
|
|
75
58
|
);
|
|
76
59
|
const getSectionSettingsGroup = useCallback(
|
|
77
60
|
(key, group) => {
|
|
@@ -142,11 +125,11 @@ const useContent = () => {
|
|
|
142
125
|
}, [resolveSections]);
|
|
143
126
|
const getContentModel = useCallback(
|
|
144
127
|
(name) => {
|
|
145
|
-
return
|
|
128
|
+
return props?.contentModels?.find(
|
|
146
129
|
(contentModel) => contentModel.name === name
|
|
147
130
|
);
|
|
148
131
|
},
|
|
149
|
-
[
|
|
132
|
+
[props?.contentModels]
|
|
150
133
|
);
|
|
151
134
|
const formatContentModelItemData = useCallback(
|
|
152
135
|
(item) => {
|
|
@@ -202,7 +185,7 @@ const useContent = () => {
|
|
|
202
185
|
);
|
|
203
186
|
const getMenu = useCallback(
|
|
204
187
|
(name, filterByIsActive = true) => {
|
|
205
|
-
const menu =
|
|
188
|
+
const menu = props?.menus?.find((menu2) => menu2.name === name);
|
|
206
189
|
if (menu) {
|
|
207
190
|
menu.items = cloneDeep(
|
|
208
191
|
menu.items?.filter((item) => !filterByIsActive || item.isActive)?.sort((a, b) => a.position - b.position)
|
|
@@ -210,13 +193,11 @@ const useContent = () => {
|
|
|
210
193
|
}
|
|
211
194
|
return menu;
|
|
212
195
|
},
|
|
213
|
-
[
|
|
196
|
+
[props?.menus]
|
|
214
197
|
);
|
|
215
198
|
const getMenuByLocation = useCallback(
|
|
216
199
|
(name, filterByIsActive = true) => {
|
|
217
|
-
const menu =
|
|
218
|
-
(menu2) => menu2.location?.name === name
|
|
219
|
-
);
|
|
200
|
+
const menu = props?.menus?.find((menu2) => menu2.location?.name === name);
|
|
220
201
|
if (menu) {
|
|
221
202
|
menu.items = cloneDeep(
|
|
222
203
|
menu.items?.filter((item) => !filterByIsActive || item.isActive)?.sort((a, b) => a.position - b.position)
|
|
@@ -224,7 +205,7 @@ const useContent = () => {
|
|
|
224
205
|
}
|
|
225
206
|
return menu;
|
|
226
207
|
},
|
|
227
|
-
[
|
|
208
|
+
[props?.menus]
|
|
228
209
|
);
|
|
229
210
|
const getMenuItems = useCallback(
|
|
230
211
|
(name, filterByIsVisible = true) => {
|
|
@@ -235,13 +216,13 @@ const useContent = () => {
|
|
|
235
216
|
const getMenuItemById = useCallback(
|
|
236
217
|
(id) => {
|
|
237
218
|
const menuItems = [];
|
|
238
|
-
const menus =
|
|
219
|
+
const menus = props?.menus || [];
|
|
239
220
|
menus.forEach((menu) => {
|
|
240
221
|
if (Array.isArray(menu.items)) menuItems.push(...menu.items);
|
|
241
222
|
});
|
|
242
223
|
return menuItems.find((item) => item.id === id);
|
|
243
224
|
},
|
|
244
|
-
[
|
|
225
|
+
[props?.menus]
|
|
245
226
|
);
|
|
246
227
|
const getMenuItemsByLocation = useCallback(
|
|
247
228
|
(name, filterByIsVisible = true) => {
|
|
@@ -259,7 +240,7 @@ const useContent = () => {
|
|
|
259
240
|
(group) => group.id === item.menuItemGroupId
|
|
260
241
|
);
|
|
261
242
|
if (!groupAlreadyExists) {
|
|
262
|
-
const group =
|
|
243
|
+
const group = props?.menuItemGroups?.find(
|
|
263
244
|
(group2) => group2.id === item.menuItemGroupId
|
|
264
245
|
);
|
|
265
246
|
if (group) groups.push(group);
|
|
@@ -268,7 +249,7 @@ const useContent = () => {
|
|
|
268
249
|
}
|
|
269
250
|
return groups;
|
|
270
251
|
},
|
|
271
|
-
[getMenuItems, getMenuItemsByLocation,
|
|
252
|
+
[getMenuItems, getMenuItemsByLocation, props?.menuItemGroups]
|
|
272
253
|
);
|
|
273
254
|
const getMenuItemsByGroup = useCallback(
|
|
274
255
|
(name, groupId, byLocation = false, filterByIsVisible = true) => {
|
|
@@ -301,7 +282,7 @@ const useContent = () => {
|
|
|
301
282
|
);
|
|
302
283
|
const getAppInformationValue = useCallback(
|
|
303
284
|
(key, type = "string") => {
|
|
304
|
-
const appInformation =
|
|
285
|
+
const appInformation = props.appInformation;
|
|
305
286
|
const setting = appInformation.find((s) => s.key === key);
|
|
306
287
|
let value = "";
|
|
307
288
|
switch (type) {
|
|
@@ -323,7 +304,7 @@ const useContent = () => {
|
|
|
323
304
|
}
|
|
324
305
|
return value;
|
|
325
306
|
},
|
|
326
|
-
[
|
|
307
|
+
[props.appInformation]
|
|
327
308
|
);
|
|
328
309
|
const appPrimaryColor = useMemo(() => {
|
|
329
310
|
const primaryColor = getAppInformationValue(
|
|
@@ -358,7 +339,6 @@ const useContent = () => {
|
|
|
358
339
|
newsCategory,
|
|
359
340
|
newsTag,
|
|
360
341
|
contentModelItem,
|
|
361
|
-
getProps,
|
|
362
342
|
getMenu,
|
|
363
343
|
getMenuByLocation,
|
|
364
344
|
getMenuItems,
|
|
@@ -431,7 +411,7 @@ const useNewsletter = () => {
|
|
|
431
411
|
};
|
|
432
412
|
export {
|
|
433
413
|
useApi,
|
|
434
|
-
|
|
414
|
+
e as useConfig,
|
|
435
415
|
useContent,
|
|
436
416
|
useHelper,
|
|
437
417
|
useNewsletter,
|
|
@@ -6934,6 +6934,28 @@ const useApi = () => {
|
|
|
6934
6934
|
handleError
|
|
6935
6935
|
};
|
|
6936
6936
|
};
|
|
6937
|
+
const useProps = () => {
|
|
6938
|
+
const manager = React.useContext(PropsContext);
|
|
6939
|
+
const page = react.usePage();
|
|
6940
|
+
const [props, setProps] = React.useState(
|
|
6941
|
+
manager ? manager.getState().props : {}
|
|
6942
|
+
);
|
|
6943
|
+
React.useEffect(() => {
|
|
6944
|
+
if (!manager) return;
|
|
6945
|
+
setProps(manager.getState().props);
|
|
6946
|
+
const unsubscribe = manager.subscribe((newProps) => {
|
|
6947
|
+
setProps(newProps);
|
|
6948
|
+
});
|
|
6949
|
+
return unsubscribe;
|
|
6950
|
+
}, [manager]);
|
|
6951
|
+
if (!manager) {
|
|
6952
|
+
console.warn(
|
|
6953
|
+
"[@creopse/react] Using native Inertia props - live preview disabled"
|
|
6954
|
+
);
|
|
6955
|
+
return page.props;
|
|
6956
|
+
}
|
|
6957
|
+
return props;
|
|
6958
|
+
};
|
|
6937
6959
|
const useMediaQuery = (query) => {
|
|
6938
6960
|
const [matches, setMatches] = React.useState(false);
|
|
6939
6961
|
React.useEffect(() => {
|
|
@@ -6948,9 +6970,10 @@ const useMediaQuery = (query) => {
|
|
|
6948
6970
|
return matches;
|
|
6949
6971
|
};
|
|
6950
6972
|
const useHelper = () => {
|
|
6973
|
+
const props = useProps();
|
|
6951
6974
|
const page = react.usePage();
|
|
6952
6975
|
const { request } = useApi();
|
|
6953
|
-
const { apiBaseUrl } = useConfig();
|
|
6976
|
+
const { apiBaseUrl, langKey } = useConfig();
|
|
6954
6977
|
const currentRoutePath = React.useMemo(() => page.url, [page.url]);
|
|
6955
6978
|
const resolveUrl = React.useCallback(
|
|
6956
6979
|
(path) => {
|
|
@@ -6991,15 +7014,19 @@ const useHelper = () => {
|
|
|
6991
7014
|
},
|
|
6992
7015
|
[fileUrl]
|
|
6993
7016
|
);
|
|
6994
|
-
const getTranslation = React.useCallback(
|
|
6995
|
-
|
|
6996
|
-
|
|
6997
|
-
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7001
|
-
|
|
7002
|
-
|
|
7017
|
+
const getTranslation = React.useCallback(
|
|
7018
|
+
(data, lang2) => {
|
|
7019
|
+
let parsedData;
|
|
7020
|
+
if (!lang2) lang2 = localStorage.getItem(langKey) || "en";
|
|
7021
|
+
try {
|
|
7022
|
+
parsedData = JSON.parse(data);
|
|
7023
|
+
} catch (e) {
|
|
7024
|
+
parsedData = {};
|
|
7025
|
+
}
|
|
7026
|
+
return parsedData ? parsedData[lang2.toUpperCase()] || parsedData[lang2] || parsedData["en"] || "" : "";
|
|
7027
|
+
},
|
|
7028
|
+
[langKey]
|
|
7029
|
+
);
|
|
7003
7030
|
const tr = React.useCallback(
|
|
7004
7031
|
(data, lang2) => {
|
|
7005
7032
|
return getTranslation(data, lang2);
|
|
@@ -7075,17 +7102,18 @@ const useHelper = () => {
|
|
|
7075
7102
|
(label) => languages.find((l) => l.label === label)?.value,
|
|
7076
7103
|
[languages]
|
|
7077
7104
|
);
|
|
7078
|
-
const
|
|
7105
|
+
const updateLang = React.useCallback(
|
|
7079
7106
|
async (val, reload = true, updateUserPrefs = true) => {
|
|
7080
|
-
|
|
7081
|
-
|
|
7107
|
+
localStorage.setItem(langKey, val);
|
|
7108
|
+
if (props.isUserLoggedIn && updateUserPrefs) {
|
|
7109
|
+
const userPrefs = props.userData?.preferences || {
|
|
7082
7110
|
inAppNotifEnabled: Bool.TRUE,
|
|
7083
7111
|
emailNotifEnabled: Bool.TRUE,
|
|
7084
7112
|
locale: val
|
|
7085
7113
|
};
|
|
7086
7114
|
userPrefs.locale = val;
|
|
7087
7115
|
await request({
|
|
7088
|
-
url: `/users/self/${
|
|
7116
|
+
url: `/users/self/${props.userData?.id}`,
|
|
7089
7117
|
method: "put",
|
|
7090
7118
|
data: {
|
|
7091
7119
|
preferences: userPrefs
|
|
@@ -7094,7 +7122,7 @@ const useHelper = () => {
|
|
|
7094
7122
|
}
|
|
7095
7123
|
if (reload) location.reload();
|
|
7096
7124
|
},
|
|
7097
|
-
[
|
|
7125
|
+
[langKey, props, request]
|
|
7098
7126
|
);
|
|
7099
7127
|
const displayFormErrors = React.useCallback(
|
|
7100
7128
|
(errors, displayError) => {
|
|
@@ -7184,7 +7212,7 @@ const useHelper = () => {
|
|
|
7184
7212
|
displayFormErrors,
|
|
7185
7213
|
resolveHtmlLinks,
|
|
7186
7214
|
resolveUrl,
|
|
7187
|
-
|
|
7215
|
+
updateLang,
|
|
7188
7216
|
languages,
|
|
7189
7217
|
getImage,
|
|
7190
7218
|
fileUrl,
|
|
@@ -7785,3 +7813,4 @@ exports.slideToId = slideToId;
|
|
|
7785
7813
|
exports.useApi = useApi;
|
|
7786
7814
|
exports.useConfig = useConfig;
|
|
7787
7815
|
exports.useHelper = useHelper;
|
|
7816
|
+
exports.useProps = useProps;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { usePage, router } from "@inertiajs/react";
|
|
2
|
-
import React__default, { createContext, useContext, useMemo, useCallback } from "react";
|
|
2
|
+
import React__default, { createContext, useContext, useMemo, useCallback, useState, useEffect } from "react";
|
|
3
3
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
4
4
|
function getDefaultExportFromCjs(x) {
|
|
5
5
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
@@ -6933,6 +6933,28 @@ const useApi = () => {
|
|
|
6933
6933
|
handleError
|
|
6934
6934
|
};
|
|
6935
6935
|
};
|
|
6936
|
+
const useProps = () => {
|
|
6937
|
+
const manager = useContext(PropsContext);
|
|
6938
|
+
const page = usePage();
|
|
6939
|
+
const [props, setProps] = useState(
|
|
6940
|
+
manager ? manager.getState().props : {}
|
|
6941
|
+
);
|
|
6942
|
+
useEffect(() => {
|
|
6943
|
+
if (!manager) return;
|
|
6944
|
+
setProps(manager.getState().props);
|
|
6945
|
+
const unsubscribe = manager.subscribe((newProps) => {
|
|
6946
|
+
setProps(newProps);
|
|
6947
|
+
});
|
|
6948
|
+
return unsubscribe;
|
|
6949
|
+
}, [manager]);
|
|
6950
|
+
if (!manager) {
|
|
6951
|
+
console.warn(
|
|
6952
|
+
"[@creopse/react] Using native Inertia props - live preview disabled"
|
|
6953
|
+
);
|
|
6954
|
+
return page.props;
|
|
6955
|
+
}
|
|
6956
|
+
return props;
|
|
6957
|
+
};
|
|
6936
6958
|
const useMediaQuery = (query) => {
|
|
6937
6959
|
const [matches, setMatches] = React__default.useState(false);
|
|
6938
6960
|
React__default.useEffect(() => {
|
|
@@ -6947,9 +6969,10 @@ const useMediaQuery = (query) => {
|
|
|
6947
6969
|
return matches;
|
|
6948
6970
|
};
|
|
6949
6971
|
const useHelper = () => {
|
|
6972
|
+
const props = useProps();
|
|
6950
6973
|
const page = usePage();
|
|
6951
6974
|
const { request } = useApi();
|
|
6952
|
-
const { apiBaseUrl } = useConfig();
|
|
6975
|
+
const { apiBaseUrl, langKey } = useConfig();
|
|
6953
6976
|
const currentRoutePath = useMemo(() => page.url, [page.url]);
|
|
6954
6977
|
const resolveUrl = useCallback(
|
|
6955
6978
|
(path) => {
|
|
@@ -6990,15 +7013,19 @@ const useHelper = () => {
|
|
|
6990
7013
|
},
|
|
6991
7014
|
[fileUrl]
|
|
6992
7015
|
);
|
|
6993
|
-
const getTranslation = useCallback(
|
|
6994
|
-
|
|
6995
|
-
|
|
6996
|
-
|
|
6997
|
-
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7001
|
-
|
|
7016
|
+
const getTranslation = useCallback(
|
|
7017
|
+
(data, lang2) => {
|
|
7018
|
+
let parsedData;
|
|
7019
|
+
if (!lang2) lang2 = localStorage.getItem(langKey) || "en";
|
|
7020
|
+
try {
|
|
7021
|
+
parsedData = JSON.parse(data);
|
|
7022
|
+
} catch (e) {
|
|
7023
|
+
parsedData = {};
|
|
7024
|
+
}
|
|
7025
|
+
return parsedData ? parsedData[lang2.toUpperCase()] || parsedData[lang2] || parsedData["en"] || "" : "";
|
|
7026
|
+
},
|
|
7027
|
+
[langKey]
|
|
7028
|
+
);
|
|
7002
7029
|
const tr = useCallback(
|
|
7003
7030
|
(data, lang2) => {
|
|
7004
7031
|
return getTranslation(data, lang2);
|
|
@@ -7074,17 +7101,18 @@ const useHelper = () => {
|
|
|
7074
7101
|
(label) => languages.find((l) => l.label === label)?.value,
|
|
7075
7102
|
[languages]
|
|
7076
7103
|
);
|
|
7077
|
-
const
|
|
7104
|
+
const updateLang = useCallback(
|
|
7078
7105
|
async (val, reload = true, updateUserPrefs = true) => {
|
|
7079
|
-
|
|
7080
|
-
|
|
7106
|
+
localStorage.setItem(langKey, val);
|
|
7107
|
+
if (props.isUserLoggedIn && updateUserPrefs) {
|
|
7108
|
+
const userPrefs = props.userData?.preferences || {
|
|
7081
7109
|
inAppNotifEnabled: Bool.TRUE,
|
|
7082
7110
|
emailNotifEnabled: Bool.TRUE,
|
|
7083
7111
|
locale: val
|
|
7084
7112
|
};
|
|
7085
7113
|
userPrefs.locale = val;
|
|
7086
7114
|
await request({
|
|
7087
|
-
url: `/users/self/${
|
|
7115
|
+
url: `/users/self/${props.userData?.id}`,
|
|
7088
7116
|
method: "put",
|
|
7089
7117
|
data: {
|
|
7090
7118
|
preferences: userPrefs
|
|
@@ -7093,7 +7121,7 @@ const useHelper = () => {
|
|
|
7093
7121
|
}
|
|
7094
7122
|
if (reload) location.reload();
|
|
7095
7123
|
},
|
|
7096
|
-
[
|
|
7124
|
+
[langKey, props, request]
|
|
7097
7125
|
);
|
|
7098
7126
|
const displayFormErrors = useCallback(
|
|
7099
7127
|
(errors, displayError) => {
|
|
@@ -7183,7 +7211,7 @@ const useHelper = () => {
|
|
|
7183
7211
|
displayFormErrors,
|
|
7184
7212
|
resolveHtmlLinks,
|
|
7185
7213
|
resolveUrl,
|
|
7186
|
-
|
|
7214
|
+
updateLang,
|
|
7187
7215
|
languages,
|
|
7188
7216
|
getImage,
|
|
7189
7217
|
fileUrl,
|
|
@@ -7780,10 +7808,11 @@ export {
|
|
|
7780
7808
|
EditorMessageType as E,
|
|
7781
7809
|
PropsContext as P,
|
|
7782
7810
|
RouterContext as R,
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
7786
|
-
|
|
7811
|
+
useProps as a,
|
|
7812
|
+
ResolveSectionsContext as b,
|
|
7813
|
+
useApi as c,
|
|
7814
|
+
cloneDeep as d,
|
|
7815
|
+
useConfig as e,
|
|
7787
7816
|
slideToId as s,
|
|
7788
7817
|
useHelper as u
|
|
7789
7818
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
|
-
const index = require("./index-
|
|
4
|
+
const index = require("./index-hI__ihu3.cjs");
|
|
5
5
|
require("@inertiajs/react");
|
|
6
6
|
const reactDom = require("react-dom");
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
@@ -8105,6 +8105,8 @@ const RootContainer = ({
|
|
|
8105
8105
|
}, [page, sections]);
|
|
8106
8106
|
const sectionsStateRef = React.useRef({});
|
|
8107
8107
|
const sectionsRef = React.useRef(sections);
|
|
8108
|
+
const pageProps = index.useProps();
|
|
8109
|
+
console.log(pageProps);
|
|
8108
8110
|
React.useEffect(() => {
|
|
8109
8111
|
const deselectAllSections = () => {
|
|
8110
8112
|
Object.keys(sectionsStateRef.current).forEach((key) => {
|
|
@@ -8183,14 +8185,29 @@ const RootContainer = ({
|
|
|
8183
8185
|
break;
|
|
8184
8186
|
}
|
|
8185
8187
|
case index.EditorMessageType.SEND_BASE_SECTION_SETTINGS:
|
|
8188
|
+
{
|
|
8189
|
+
console.log(event.data);
|
|
8190
|
+
}
|
|
8186
8191
|
break;
|
|
8187
8192
|
case index.EditorMessageType.SEND_BASE_SECTION_DATA:
|
|
8193
|
+
{
|
|
8194
|
+
console.log(event.data);
|
|
8195
|
+
}
|
|
8188
8196
|
break;
|
|
8189
8197
|
case index.EditorMessageType.SEND_SECTION_SETTINGS:
|
|
8198
|
+
{
|
|
8199
|
+
console.log(event.data);
|
|
8200
|
+
}
|
|
8190
8201
|
break;
|
|
8191
8202
|
case index.EditorMessageType.SEND_SECTION_DATA:
|
|
8203
|
+
{
|
|
8204
|
+
console.log(event.data);
|
|
8205
|
+
}
|
|
8192
8206
|
break;
|
|
8193
8207
|
case index.EditorMessageType.SEND_PAGE_SECTIONS:
|
|
8208
|
+
{
|
|
8209
|
+
console.log(event.data);
|
|
8210
|
+
}
|
|
8194
8211
|
break;
|
|
8195
8212
|
}
|
|
8196
8213
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import React__default, { useState, useEffect, createContext, useRef, useLayoutEffect, useId, useContext, useInsertionEffect, useMemo, useCallback, Children, isValidElement, Fragment, createElement, forwardRef, Component } from "react";
|
|
3
|
-
import { u as useHelper, s as slideToId, E as EditorMessageType, R as RouterContext, C as ConfigContext,
|
|
3
|
+
import { u as useHelper, s as slideToId, a as useProps, E as EditorMessageType, R as RouterContext, C as ConfigContext, b as ResolveSectionsContext, P as PropsContext } from "./index-jw_2nhs3.js";
|
|
4
4
|
import "@inertiajs/react";
|
|
5
5
|
import { createPortal } from "react-dom";
|
|
6
6
|
var jsxRuntime = { exports: {} };
|
|
@@ -8087,6 +8087,8 @@ const RootContainer = ({
|
|
|
8087
8087
|
}, [page, sections]);
|
|
8088
8088
|
const sectionsStateRef = useRef({});
|
|
8089
8089
|
const sectionsRef = useRef(sections);
|
|
8090
|
+
const pageProps = useProps();
|
|
8091
|
+
console.log(pageProps);
|
|
8090
8092
|
useEffect(() => {
|
|
8091
8093
|
const deselectAllSections = () => {
|
|
8092
8094
|
Object.keys(sectionsStateRef.current).forEach((key) => {
|
|
@@ -8165,14 +8167,29 @@ const RootContainer = ({
|
|
|
8165
8167
|
break;
|
|
8166
8168
|
}
|
|
8167
8169
|
case EditorMessageType.SEND_BASE_SECTION_SETTINGS:
|
|
8170
|
+
{
|
|
8171
|
+
console.log(event.data);
|
|
8172
|
+
}
|
|
8168
8173
|
break;
|
|
8169
8174
|
case EditorMessageType.SEND_BASE_SECTION_DATA:
|
|
8175
|
+
{
|
|
8176
|
+
console.log(event.data);
|
|
8177
|
+
}
|
|
8170
8178
|
break;
|
|
8171
8179
|
case EditorMessageType.SEND_SECTION_SETTINGS:
|
|
8180
|
+
{
|
|
8181
|
+
console.log(event.data);
|
|
8182
|
+
}
|
|
8172
8183
|
break;
|
|
8173
8184
|
case EditorMessageType.SEND_SECTION_DATA:
|
|
8185
|
+
{
|
|
8186
|
+
console.log(event.data);
|
|
8187
|
+
}
|
|
8174
8188
|
break;
|
|
8175
8189
|
case EditorMessageType.SEND_PAGE_SECTIONS:
|
|
8190
|
+
{
|
|
8191
|
+
console.log(event.data);
|
|
8192
|
+
}
|
|
8176
8193
|
break;
|
|
8177
8194
|
}
|
|
8178
8195
|
};
|
package/package.json
CHANGED
package/types/core/contexts.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PluginConfig } from '@/types/plugin';
|
|
2
2
|
import type PropsManager from './props-manager';
|
|
3
|
-
declare const PropsContext: import("react").Context<PropsManager | null>;
|
|
3
|
+
declare const PropsContext: import("react").Context<PropsManager<import("@/types/plugin").Props> | null>;
|
|
4
4
|
declare const ConfigContext: import("react").Context<PluginConfig | null>;
|
|
5
5
|
declare const RouterContext: import("react").Context<any>;
|
|
6
6
|
declare const ResolveSectionsContext: import("react").Context<any>;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Props } from '@/types/plugin';
|
|
2
|
+
declare class PropsManager<T extends Props = Props> {
|
|
2
3
|
private state;
|
|
3
4
|
private listeners;
|
|
4
|
-
constructor(initialProps:
|
|
5
|
-
update(payload:
|
|
5
|
+
constructor(initialProps: T);
|
|
6
|
+
update(payload: T): void;
|
|
6
7
|
getState(): {
|
|
7
|
-
props:
|
|
8
|
+
props: T;
|
|
8
9
|
};
|
|
9
|
-
sync(newProps:
|
|
10
|
-
subscribe(callback: (props:
|
|
10
|
+
sync(newProps: T): void;
|
|
11
|
+
subscribe(callback: (props: T) => void): () => void;
|
|
11
12
|
private notify;
|
|
12
13
|
private deepMerge;
|
|
13
14
|
private isObject;
|
package/types/hooks/config.d.ts
CHANGED
package/types/hooks/content.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AppInformationKey, ContentModelItemModel, ContentModelModel, MenuItemGroupModel, MenuItemModel, MenuModel, NewsArticleModel, NewsCategoryModel, NewsTagModel, PageModel, SectionModel, SettingType, SharedProps } from '@creopse/utils';
|
|
2
|
-
import type { ErrorBag, Errors, PageProps } from '@inertiajs/core';
|
|
3
2
|
/**
|
|
4
3
|
* A hook that provides a set of functions and properties for
|
|
5
4
|
* easily accessing and manipulating page data, content models, menus,
|
|
@@ -16,9 +15,6 @@ export declare const useContent: () => {
|
|
|
16
15
|
newsCategory: NewsCategoryModel | undefined;
|
|
17
16
|
newsTag: NewsTagModel | undefined;
|
|
18
17
|
contentModelItem: ContentModelItemModel | undefined;
|
|
19
|
-
getProps: () => PageProps & SharedProps & {
|
|
20
|
-
errors: Errors & ErrorBag;
|
|
21
|
-
};
|
|
22
18
|
getMenu: (name: string, filterByIsActive?: boolean) => MenuModel | undefined;
|
|
23
19
|
getMenuByLocation: (name: string, filterByIsActive?: boolean) => MenuModel | undefined;
|
|
24
20
|
getMenuItems: (name: string, filterByIsVisible?: boolean) => MenuItemModel[] | undefined;
|
package/types/hooks/helper.d.ts
CHANGED
|
@@ -10,14 +10,14 @@ export declare const useHelper: () => {
|
|
|
10
10
|
isLgScreen: boolean;
|
|
11
11
|
isMdScreen: boolean;
|
|
12
12
|
isSmScreen: boolean;
|
|
13
|
-
getTranslation: (data: any, lang
|
|
13
|
+
getTranslation: (data: any, lang?: string) => string;
|
|
14
14
|
getLangageLabel: (value: string) => string | undefined;
|
|
15
15
|
getLanguageValue: (label: string) => string | undefined;
|
|
16
16
|
ckEditorToolbarItems: string[];
|
|
17
17
|
displayFormErrors: (errors: any, displayError: (message: string) => void) => void;
|
|
18
|
-
resolveHtmlLinks: (data: string | null | undefined, lang
|
|
18
|
+
resolveHtmlLinks: (data: string | null | undefined, lang?: string) => string;
|
|
19
19
|
resolveUrl: (path: string) => string;
|
|
20
|
-
|
|
20
|
+
updateLang: (val: string, reload?: boolean, updateUserPrefs?: boolean) => Promise<void>;
|
|
21
21
|
languages: Language[];
|
|
22
22
|
getImage: (path: string, size?: "small" | "medium" | "large" | "original") => Promise<string>;
|
|
23
23
|
fileUrl: (path: string) => string;
|
|
@@ -25,6 +25,6 @@ export declare const useHelper: () => {
|
|
|
25
25
|
openLink: (str: string) => void;
|
|
26
26
|
openMenu: (menu?: MenuItemModel) => void;
|
|
27
27
|
getMenuHref: (menu: MenuItemModel) => string;
|
|
28
|
-
rHtml: (data: string | null | undefined, lang
|
|
29
|
-
tr: (data: any, lang
|
|
28
|
+
rHtml: (data: string | null | undefined, lang?: string) => string;
|
|
29
|
+
tr: (data: any, lang?: string) => string;
|
|
30
30
|
};
|
package/types/hooks/props.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import type { Props } from '@/types/plugin';
|
|
1
2
|
/**
|
|
2
3
|
* A hook that returns the props of the page.
|
|
3
4
|
*
|
|
4
5
|
* It subscribes to the PropsManager and updates when props change.
|
|
5
6
|
*
|
|
6
7
|
* @throws {Error} if the CreopseProvider is not found in tree
|
|
7
|
-
* @returns {
|
|
8
|
+
* @returns {T} the props of the page
|
|
8
9
|
*/
|
|
9
|
-
export declare const useProps: <T =
|
|
10
|
+
export declare const useProps: <T extends Props = Props>() => T;
|
package/types/types/plugin.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SharedProps } from '@creopse/utils';
|
|
2
|
+
import type { ErrorBag, Errors, PageProps, Router } from '@inertiajs/core';
|
|
3
|
+
export type Props = SharedProps & PageProps & {
|
|
4
|
+
errors: Errors & ErrorBag;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
};
|
|
2
7
|
export interface PluginConfig {
|
|
3
8
|
debug: boolean;
|
|
4
9
|
appUrl: string;
|
|
5
10
|
xApiKey: string;
|
|
6
11
|
encryptionKey: string;
|
|
12
|
+
langKey: string;
|
|
7
13
|
}
|
|
8
14
|
export interface PluginOptions {
|
|
9
|
-
initialProps:
|
|
15
|
+
initialProps: Props;
|
|
10
16
|
router?: Router;
|
|
11
17
|
resolveSections: () => Record<string, unknown>;
|
|
12
18
|
config: PluginConfig;
|