@creopse/react 0.0.11 → 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.
@@ -1,50 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("../index-C3UpNpqk.cjs");
4
- const React = require("react");
3
+ const index = require("../index-hI__ihu3.cjs");
5
4
  const react = require("@inertiajs/react");
6
- const useProps = () => {
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
- () => page.props.pageData,
31
- [page.props.pageData]
13
+ () => props.pageData,
14
+ [props.pageData]
32
15
  );
33
16
  const newsArticle = React.useMemo(
34
- () => page.props.article,
35
- [page.props.article]
17
+ () => props.article,
18
+ [props.article]
36
19
  );
37
20
  const newsCategory = React.useMemo(
38
- () => page.props.category,
39
- [page.props.category]
21
+ () => props.category,
22
+ [props.category]
40
23
  );
41
24
  const newsTag = React.useMemo(
42
- () => page.props.tag,
43
- [page.props.tag]
25
+ () => props.tag,
26
+ [props.tag]
44
27
  );
45
28
  const contentModelItem = React.useMemo(
46
- () => page.props.contentModelItem,
47
- [page.props.contentModelItem]
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 page.props.pageData?.sections?.find(
38
+ return props.pageData?.sections?.find(
56
39
  (section) => section.slug === slug && section.pivot?.linkId === linkId
57
40
  )?.pivot?.data || null;
58
41
  },
59
- [page.props.pageData?.sections]
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 page.props.pageData?.sections?.find(
54
+ return props.pageData?.sections?.find(
72
55
  (section) => section.slug === slug && section.pivot?.linkId === linkId
73
56
  )?.pivot?.settings || null;
74
57
  },
75
- [page.props.pageData?.sections]
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 page.props?.contentModels?.find(
129
+ return props?.contentModels?.find(
147
130
  (contentModel) => contentModel.name === name
148
131
  );
149
132
  },
150
- [page.props?.contentModels]
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 = page.props?.menus?.find((menu2) => menu2.name === name);
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
- [page.props?.menus]
197
+ [props?.menus]
215
198
  );
216
199
  const getMenuByLocation = React.useCallback(
217
200
  (name, filterByIsActive = true) => {
218
- const menu = page.props?.menus?.find(
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
- [page.props?.menus]
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 = page.props?.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
- [page.props?.menus]
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 = page.props?.menuItemGroups?.find(
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, page.props?.menuItemGroups]
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 = page.props.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
- [page.props.appInformation]
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;
@@ -1,49 +1,32 @@
1
- import { P as PropsContext, b as useApi, u as useHelper, a as ResolveSectionsContext, c as cloneDeep } from "../index-B7GqfDTJ.js";
2
- import { d } from "../index-B7GqfDTJ.js";
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
- const useProps = () => {
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
- () => page.props.pageData,
30
- [page.props.pageData]
12
+ () => props.pageData,
13
+ [props.pageData]
31
14
  );
32
15
  const newsArticle = useMemo(
33
- () => page.props.article,
34
- [page.props.article]
16
+ () => props.article,
17
+ [props.article]
35
18
  );
36
19
  const newsCategory = useMemo(
37
- () => page.props.category,
38
- [page.props.category]
20
+ () => props.category,
21
+ [props.category]
39
22
  );
40
23
  const newsTag = useMemo(
41
- () => page.props.tag,
42
- [page.props.tag]
24
+ () => props.tag,
25
+ [props.tag]
43
26
  );
44
27
  const contentModelItem = useMemo(
45
- () => page.props.contentModelItem,
46
- [page.props.contentModelItem]
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 page.props.pageData?.sections?.find(
37
+ return props.pageData?.sections?.find(
55
38
  (section) => section.slug === slug && section.pivot?.linkId === linkId
56
39
  )?.pivot?.data || null;
57
40
  },
58
- [page.props.pageData?.sections]
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 page.props.pageData?.sections?.find(
53
+ return props.pageData?.sections?.find(
71
54
  (section) => section.slug === slug && section.pivot?.linkId === linkId
72
55
  )?.pivot?.settings || null;
73
56
  },
74
- [page.props.pageData?.sections]
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 page.props?.contentModels?.find(
128
+ return props?.contentModels?.find(
146
129
  (contentModel) => contentModel.name === name
147
130
  );
148
131
  },
149
- [page.props?.contentModels]
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 = page.props?.menus?.find((menu2) => menu2.name === name);
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
- [page.props?.menus]
196
+ [props?.menus]
214
197
  );
215
198
  const getMenuByLocation = useCallback(
216
199
  (name, filterByIsActive = true) => {
217
- const menu = page.props?.menus?.find(
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
- [page.props?.menus]
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 = page.props?.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
- [page.props?.menus]
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 = page.props?.menuItemGroups?.find(
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, page.props?.menuItemGroups]
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 = page.props.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
- [page.props.appInformation]
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
- d as useConfig,
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,6 +6970,7 @@ 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
6976
  const { apiBaseUrl, langKey } = useConfig();
@@ -7082,15 +7105,15 @@ const useHelper = () => {
7082
7105
  const updateLang = React.useCallback(
7083
7106
  async (val, reload = true, updateUserPrefs = true) => {
7084
7107
  localStorage.setItem(langKey, val);
7085
- if (page.props.isUserLoggedIn && updateUserPrefs) {
7086
- const userPrefs = page.props.userData?.preferences || {
7108
+ if (props.isUserLoggedIn && updateUserPrefs) {
7109
+ const userPrefs = props.userData?.preferences || {
7087
7110
  inAppNotifEnabled: Bool.TRUE,
7088
7111
  emailNotifEnabled: Bool.TRUE,
7089
7112
  locale: val
7090
7113
  };
7091
7114
  userPrefs.locale = val;
7092
7115
  await request({
7093
- url: `/users/self/${page.props.userData?.id}`,
7116
+ url: `/users/self/${props.userData?.id}`,
7094
7117
  method: "put",
7095
7118
  data: {
7096
7119
  preferences: userPrefs
@@ -7099,7 +7122,7 @@ const useHelper = () => {
7099
7122
  }
7100
7123
  if (reload) location.reload();
7101
7124
  },
7102
- [langKey, page.props, request]
7125
+ [langKey, props, request]
7103
7126
  );
7104
7127
  const displayFormErrors = React.useCallback(
7105
7128
  (errors, displayError) => {
@@ -7790,3 +7813,4 @@ exports.slideToId = slideToId;
7790
7813
  exports.useApi = useApi;
7791
7814
  exports.useConfig = useConfig;
7792
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,6 +6969,7 @@ 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
6975
  const { apiBaseUrl, langKey } = useConfig();
@@ -7081,15 +7104,15 @@ const useHelper = () => {
7081
7104
  const updateLang = useCallback(
7082
7105
  async (val, reload = true, updateUserPrefs = true) => {
7083
7106
  localStorage.setItem(langKey, val);
7084
- if (page.props.isUserLoggedIn && updateUserPrefs) {
7085
- const userPrefs = page.props.userData?.preferences || {
7107
+ if (props.isUserLoggedIn && updateUserPrefs) {
7108
+ const userPrefs = props.userData?.preferences || {
7086
7109
  inAppNotifEnabled: Bool.TRUE,
7087
7110
  emailNotifEnabled: Bool.TRUE,
7088
7111
  locale: val
7089
7112
  };
7090
7113
  userPrefs.locale = val;
7091
7114
  await request({
7092
- url: `/users/self/${page.props.userData?.id}`,
7115
+ url: `/users/self/${props.userData?.id}`,
7093
7116
  method: "put",
7094
7117
  data: {
7095
7118
  preferences: userPrefs
@@ -7098,7 +7121,7 @@ const useHelper = () => {
7098
7121
  }
7099
7122
  if (reload) location.reload();
7100
7123
  },
7101
- [langKey, page.props, request]
7124
+ [langKey, props, request]
7102
7125
  );
7103
7126
  const displayFormErrors = useCallback(
7104
7127
  (errors, displayError) => {
@@ -7785,10 +7808,11 @@ export {
7785
7808
  EditorMessageType as E,
7786
7809
  PropsContext as P,
7787
7810
  RouterContext as R,
7788
- ResolveSectionsContext as a,
7789
- useApi as b,
7790
- cloneDeep as c,
7791
- useConfig as d,
7811
+ useProps as a,
7812
+ ResolveSectionsContext as b,
7813
+ useApi as c,
7814
+ cloneDeep as d,
7815
+ useConfig as e,
7792
7816
  slideToId as s,
7793
7817
  useHelper as u
7794
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-C3UpNpqk.cjs");
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, a as ResolveSectionsContext, P as PropsContext } from "./index-B7GqfDTJ.js";
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@creopse/react",
3
3
  "description": "Creopse React Toolkit",
4
- "version": "0.0.11",
4
+ "version": "0.0.12",
5
5
  "private": false,
6
6
  "author": "Noé Gnanih <noegnanih@gmail.com>",
7
7
  "license": "MIT",
@@ -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
- declare class PropsManager {
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: Record<string, any>);
5
- update(payload: Record<string, any>): void;
5
+ constructor(initialProps: T);
6
+ update(payload: T): void;
6
7
  getState(): {
7
- props: Record<string, any>;
8
+ props: T;
8
9
  };
9
- sync(newProps: Record<string, any>): void;
10
- subscribe(callback: (props: Record<string, any>) => void): () => void;
10
+ sync(newProps: T): void;
11
+ subscribe(callback: (props: T) => void): () => void;
11
12
  private notify;
12
13
  private deepMerge;
13
14
  private isObject;
@@ -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;
@@ -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 {Record<string, any>} the props of the page
8
+ * @returns {T} the props of the page
8
9
  */
9
- export declare const useProps: <T = Record<string, any>>() => T;
10
+ export declare const useProps: <T extends Props = Props>() => T;
@@ -1,4 +1,9 @@
1
- import type { Router } from '@inertiajs/core';
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;
@@ -7,7 +12,7 @@ export interface PluginConfig {
7
12
  langKey: string;
8
13
  }
9
14
  export interface PluginOptions {
10
- initialProps: Record<string, any>;
15
+ initialProps: Props;
11
16
  router?: Router;
12
17
  resolveSections: () => Record<string, unknown>;
13
18
  config: PluginConfig;