@leav/ui 0.4.0-2a1719c → 0.4.0-2c820e6

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 (104) hide show
  1. package/dist/__mocks__/common/form.js +5 -1
  2. package/dist/__mocks__/common/form.js.map +1 -1
  3. package/dist/_gqlTypes/index.d.ts +39 -0
  4. package/dist/_gqlTypes/index.js +15 -0
  5. package/dist/_gqlTypes/index.js.map +1 -1
  6. package/dist/_queries/attributes/attributeDetailsFragment.js +1 -0
  7. package/dist/_queries/attributes/attributeDetailsFragment.js.map +1 -1
  8. package/dist/_queries/records/getRecordFormQuery.js +4 -0
  9. package/dist/_queries/records/getRecordFormQuery.js.map +1 -1
  10. package/dist/components/CreateDirectory/CreateDirectory.js +3 -3
  11. package/dist/components/CreateDirectory/CreateDirectory.js.map +1 -1
  12. package/dist/components/EditLibraryModal/EditLibrary/EditLibraryAttributes/AttributesList/DeleteButton/DeleteButton.js +3 -2
  13. package/dist/components/EditLibraryModal/EditLibrary/EditLibraryAttributes/AttributesList/DeleteButton/DeleteButton.js.map +1 -1
  14. package/dist/components/EditTreeModal/EditTree/EditTreeInfo/EditTreeInfoForm/TreeLibrariesForm/TreeLibrariesForm.js +8 -1
  15. package/dist/components/EditTreeModal/EditTree/EditTreeInfo/EditTreeInfoForm/TreeLibrariesForm/TreeLibrariesForm.js.map +1 -1
  16. package/dist/components/Explorer/DataView.js +7 -1
  17. package/dist/components/Explorer/DataView.js.map +1 -1
  18. package/dist/components/Explorer/Explorer.d.ts +1 -0
  19. package/dist/components/Explorer/Explorer.js +5 -4
  20. package/dist/components/Explorer/Explorer.js.map +1 -1
  21. package/dist/components/Explorer/TableCell.js +22 -11
  22. package/dist/components/Explorer/TableCell.js.map +1 -1
  23. package/dist/components/Explorer/_types.d.ts +1 -0
  24. package/dist/components/Explorer/actions-item/useEditItemAction.d.ts +2 -1
  25. package/dist/components/Explorer/actions-item/useEditItemAction.js +2 -1
  26. package/dist/components/Explorer/actions-item/useEditItemAction.js.map +1 -1
  27. package/dist/components/Explorer/manage-view-settings/store-view-settings/viewSettingsInitialState.js +1 -1
  28. package/dist/components/Explorer/manage-view-settings/store-view-settings/viewSettingsInitialState.js.map +1 -1
  29. package/dist/components/Explorer/useColumnWidth.js +2 -1
  30. package/dist/components/Explorer/useColumnWidth.js.map +1 -1
  31. package/dist/components/Explorer/usePagination.d.ts +2 -1
  32. package/dist/components/Explorer/usePagination.js.map +1 -1
  33. package/dist/components/Explorer/useSearchInput.d.ts +3 -1
  34. package/dist/components/Explorer/useSearchInput.js +2 -1
  35. package/dist/components/Explorer/useSearchInput.js.map +1 -1
  36. package/dist/components/Explorer/useViewSettingsReducer.d.ts +1 -1
  37. package/dist/components/Explorer/useViewSettingsReducer.js +25 -14
  38. package/dist/components/Explorer/useViewSettingsReducer.js.map +1 -1
  39. package/dist/components/ImportModal/ImportModalConfigStep/ImportModalConfigStep.js +1 -1
  40. package/dist/components/ImportModal/ImportModalConfigStep/ImportModalConfigStep.js.map +1 -1
  41. package/dist/components/LibraryItemsList/CreateNewRecordButton/CreateNewRecordButton.js +1 -0
  42. package/dist/components/LibraryItemsList/CreateNewRecordButton/CreateNewRecordButton.js.map +1 -1
  43. package/dist/components/LibraryItemsList/FiltersPanel/Filter/Filter.js +2 -2
  44. package/dist/components/LibraryItemsList/FiltersPanel/Filter/Filter.js.map +1 -1
  45. package/dist/components/LibraryItemsList/shared/DeactivateRecordBtn/DeactivateRecordBtn.js +3 -3
  46. package/dist/components/LibraryItemsList/shared/DeactivateRecordBtn/DeactivateRecordBtn.js.map +1 -1
  47. package/dist/components/RecordEdition/EditRecord/EditRecord.d.ts +1 -4
  48. package/dist/components/RecordEdition/EditRecord/EditRecord.js +15 -28
  49. package/dist/components/RecordEdition/EditRecord/EditRecord.js.map +1 -1
  50. package/dist/components/RecordEdition/EditRecordButtons/EditRecordButtons.d.ts +2 -0
  51. package/dist/components/RecordEdition/EditRecordButtons/EditRecordButtons.js +43 -0
  52. package/dist/components/RecordEdition/EditRecordButtons/EditRecordButtons.js.map +1 -0
  53. package/dist/components/RecordEdition/EditRecordButtons/SidebarButton.d.ts +2 -0
  54. package/dist/components/RecordEdition/EditRecordButtons/SidebarButton.js +25 -0
  55. package/dist/components/RecordEdition/EditRecordButtons/SidebarButton.js.map +1 -0
  56. package/dist/components/RecordEdition/EditRecordButtons/index.d.ts +2 -0
  57. package/dist/components/RecordEdition/EditRecordButtons/index.js +6 -0
  58. package/dist/components/RecordEdition/EditRecordButtons/index.js.map +1 -0
  59. package/dist/components/RecordEdition/EditRecordContent/EditRecordContent.js +9 -0
  60. package/dist/components/RecordEdition/EditRecordContent/EditRecordContent.js.map +1 -1
  61. package/dist/components/RecordEdition/EditRecordContent/uiElements/LinkField/link-record-in-edition/useLinkRecordsInEdition.js +1 -2
  62. package/dist/components/RecordEdition/EditRecordContent/uiElements/LinkField/link-record-in-edition/useLinkRecordsInEdition.js.map +1 -1
  63. package/dist/components/RecordEdition/EditRecordModal/EditRecordModal.d.ts +2 -0
  64. package/dist/components/RecordEdition/EditRecordModal/EditRecordModal.js +5 -10
  65. package/dist/components/RecordEdition/EditRecordModal/EditRecordModal.js.map +1 -1
  66. package/dist/components/RecordEdition/EditRecordPage/EditRecordPage.d.ts +3 -1
  67. package/dist/components/RecordEdition/EditRecordPage/EditRecordPage.js +6 -6
  68. package/dist/components/RecordEdition/EditRecordPage/EditRecordPage.js.map +1 -1
  69. package/dist/components/RecordEdition/EditRecordSidebar/Breacrumb/Breadcrumb.js +2 -2
  70. package/dist/components/RecordEdition/EditRecordSidebar/Breacrumb/Breadcrumb.js.map +1 -1
  71. package/dist/components/RecordEdition/EditRecordSidebar/EditRecordSidebar.d.ts +0 -1
  72. package/dist/components/RecordEdition/EditRecordSidebar/EditRecordSidebar.js +13 -12
  73. package/dist/components/RecordEdition/EditRecordSidebar/EditRecordSidebar.js.map +1 -1
  74. package/dist/components/RecordEdition/EditRecordSidebar/ValuesVersions/ValuesVersions.js +2 -2
  75. package/dist/components/RecordEdition/EditRecordSidebar/ValuesVersions/ValuesVersions.js.map +1 -1
  76. package/dist/components/RecordEdition/constants.d.ts +2 -0
  77. package/dist/components/RecordEdition/constants.js +6 -0
  78. package/dist/components/RecordEdition/constants.js.map +1 -0
  79. package/dist/components/RecordEdition/editRecordReducer/editRecordReducer.d.ts +27 -1
  80. package/dist/components/RecordEdition/editRecordReducer/editRecordReducer.js +43 -2
  81. package/dist/components/RecordEdition/editRecordReducer/editRecordReducer.js.map +1 -1
  82. package/dist/components/RecordEdition/index.d.ts +2 -0
  83. package/dist/components/RecordEdition/index.js +2 -0
  84. package/dist/components/RecordEdition/index.js.map +1 -1
  85. package/dist/components/SimpleErrorBoundary/SimpleErrorBoundary.d.ts +1 -1
  86. package/dist/components/SimpleErrorBoundary/SimpleErrorBoundary.js.map +1 -1
  87. package/dist/components/UploadFiles/UploadFiles.js +3 -3
  88. package/dist/components/UploadFiles/UploadFiles.js.map +1 -1
  89. package/dist/hooks/index.d.ts +1 -0
  90. package/dist/hooks/index.js +1 -0
  91. package/dist/hooks/index.js.map +1 -1
  92. package/dist/hooks/useAppLang/useAppLang.js.map +1 -1
  93. package/dist/hooks/useIFrameMessenger/messageHandlers.d.ts +13 -0
  94. package/dist/hooks/useIFrameMessenger/messageHandlers.js +111 -0
  95. package/dist/hooks/useIFrameMessenger/messageHandlers.js.map +1 -0
  96. package/dist/hooks/useIFrameMessenger/types.d.ts +78 -0
  97. package/dist/hooks/useIFrameMessenger/types.js +2 -0
  98. package/dist/hooks/useIFrameMessenger/types.js.map +1 -0
  99. package/dist/hooks/useIFrameMessenger/useIFrameMessenger.d.ts +9 -0
  100. package/dist/hooks/useIFrameMessenger/useIFrameMessenger.js +53 -0
  101. package/dist/hooks/useIFrameMessenger/useIFrameMessenger.js.map +1 -0
  102. package/dist/locales/en/shared.json +4 -1
  103. package/dist/locales/fr/shared.json +4 -1
  104. package/package.json +4 -4
@@ -0,0 +1,111 @@
1
+ import { packetId } from './types';
2
+ export const encodeMessage = (message) => JSON.stringify({
3
+ payload: JSON.stringify(message),
4
+ [packetId]: true
5
+ });
6
+ export const decodeMessage = (raw) => {
7
+ try {
8
+ const decoded = JSON.parse(raw);
9
+ if (packetId in decoded && decoded[packetId] === true) {
10
+ const message = JSON.parse(decoded.payload);
11
+ return message;
12
+ }
13
+ }
14
+ catch (e) {
15
+ return undefined;
16
+ }
17
+ return undefined;
18
+ };
19
+ const getCallback = (path, callbacksList) => {
20
+ if (!callbacksList?.current) {
21
+ return null;
22
+ }
23
+ const pathArray = path.split('.');
24
+ let callback = callbacksList.current;
25
+ pathArray.forEach(part => (callback = callback?.[part]));
26
+ return typeof callback === 'function' ? callback : null;
27
+ };
28
+ const setCallbacks = (id, frameId, data, callCb, overrides) => {
29
+ if (!overrides) {
30
+ return data;
31
+ }
32
+ const nextData = { ...data };
33
+ overrides.forEach((key) => {
34
+ nextData[key] = (...args) => {
35
+ callCb(`${id}.${key}`, args, frameId);
36
+ };
37
+ });
38
+ return nextData;
39
+ };
40
+ export const initClientHandlers = (callCb, options, callbacksList) => (message, dispatch) => {
41
+ switch (message.type) {
42
+ case 'sidepanel-form':
43
+ options?.handlers?.onSidePanelForm?.(setCallbacks(message.id, message.__frameId, message.data, callCb, message.overrides), dispatch, callCb);
44
+ break;
45
+ case 'modal-confirm':
46
+ options?.handlers?.onModalConfirm?.(setCallbacks(message.id, message.__frameId, message.data, callCb, message.overrides), message.id, dispatch, callCb);
47
+ break;
48
+ case 'modal-form':
49
+ options?.handlers?.onModalForm?.(setCallbacks(message.id, message.__frameId, message.data, callCb, message.overrides), message.id, dispatch, callCb);
50
+ break;
51
+ case 'alert':
52
+ options?.handlers?.onAlert?.(setCallbacks(message.id, message.__frameId, message.data, callCb, message.overrides), message.id, dispatch, callCb);
53
+ break;
54
+ case 'notification':
55
+ options?.handlers?.onNotification?.(setCallbacks(message.id, message.__frameId, message.data, callCb, message.overrides), message.id, dispatch, callCb);
56
+ break;
57
+ case 'message':
58
+ options?.handlers?.onMessage?.(message.data, message.id, dispatch, callCb);
59
+ break;
60
+ case 'on-call-callback':
61
+ // TODO How to know if handler can be removed from callbacksList ?
62
+ getCallback(message.path, callbacksList)?.(message.data);
63
+ break;
64
+ default:
65
+ break;
66
+ }
67
+ };
68
+ const storeCallbacks = (data, id, callbacksStore) => {
69
+ const nextData = { ...data };
70
+ const overrides = [];
71
+ Object.entries(nextData).forEach(([key, value]) => {
72
+ if (typeof value === 'function') {
73
+ callbacksStore.current[id] = {
74
+ ...callbacksStore.current[id],
75
+ [key]: value
76
+ };
77
+ overrides.push(key);
78
+ }
79
+ });
80
+ return { data: nextData, overrides };
81
+ };
82
+ export const getExposedMethods = (callbacksStore, dispatch) => ({
83
+ showSidePanelForm: (data) => {
84
+ dispatch?.({ type: 'sidepanel-form', data, id: Date.now().toString() });
85
+ },
86
+ showModalConfirm: (data) => {
87
+ const id = Date.now().toString();
88
+ const { data: nextData, overrides } = storeCallbacks(data, id, callbacksStore);
89
+ dispatch?.({ type: 'modal-confirm', data: nextData, id, overrides });
90
+ },
91
+ showModalForm: (data) => {
92
+ const id = Date.now().toString();
93
+ const { data: nextData, overrides } = storeCallbacks(data, id, callbacksStore);
94
+ dispatch?.({ type: 'modal-form', data: nextData, id, overrides });
95
+ },
96
+ showAlert: (data) => {
97
+ const id = Date.now().toString();
98
+ const { data: nextData, overrides } = storeCallbacks(data, id, callbacksStore);
99
+ dispatch?.({ type: 'alert', data: nextData, id, overrides });
100
+ },
101
+ showNotification: (data) => {
102
+ const id = Date.now().toString();
103
+ const { data: nextData, overrides } = storeCallbacks(data, id, callbacksStore);
104
+ dispatch?.({ type: 'notification', data: nextData, id, overrides });
105
+ },
106
+ messageToParent: (data) => {
107
+ const id = Date.now().toString();
108
+ dispatch?.({ type: 'message', data, id });
109
+ }
110
+ });
111
+ //# sourceMappingURL=messageHandlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messageHandlers.js","sourceRoot":"","sources":["../../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1
+ import { EditRecordPage } from '../../components/RecordEdition/EditRecordPage';
2
+ import { type KitNotification, type KitAlert } from 'aristid-ds';
3
+ import { type IKitConfirmDialog } from 'aristid-ds/dist/Kit/Feedback/Modal/types';
4
+ import { type RefObject, type ComponentProps, type Key, type JSXElementConstructor } from 'react';
5
+ export declare const packetId = "__fromIframeMessenger";
6
+ export interface IEncodedMessage {
7
+ payload: string;
8
+ [packetId]: boolean;
9
+ }
10
+ export type ComponentPropsWithKey<T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>> = ComponentProps<T> & {
11
+ key?: Key;
12
+ };
13
+ export interface IMessageBase {
14
+ __frameId?: string;
15
+ }
16
+ export type SidePanelFormMessage = IMessageBase & {
17
+ type: 'sidepanel-form';
18
+ id: string;
19
+ data: ComponentPropsWithKey<typeof EditRecordPage>;
20
+ overrides?: string[];
21
+ };
22
+ export type ModalConfirmMessage = IMessageBase & {
23
+ type: 'modal-confirm';
24
+ id: string;
25
+ data: IKitConfirmDialog;
26
+ overrides?: string[];
27
+ };
28
+ export type ModalFormMessage = IMessageBase & {
29
+ type: 'modal-form';
30
+ id: string;
31
+ data: ComponentPropsWithKey<typeof EditRecordPage>;
32
+ overrides?: string[];
33
+ };
34
+ export type AlertMessage = IMessageBase & {
35
+ type: 'alert';
36
+ id: string;
37
+ data: ComponentPropsWithKey<typeof KitAlert>;
38
+ overrides?: string[];
39
+ };
40
+ export type NotificationMessage = IMessageBase & {
41
+ type: 'notification';
42
+ id: string;
43
+ data: ComponentPropsWithKey<typeof KitNotification>;
44
+ overrides?: string[];
45
+ };
46
+ export type SimpleMessage = IMessageBase & {
47
+ type: 'message';
48
+ id: string;
49
+ data: unknown;
50
+ };
51
+ export type RegisterMessage = IMessageBase & {
52
+ type: 'register';
53
+ id: string;
54
+ };
55
+ export type MessageToParent = SidePanelFormMessage | ModalConfirmMessage | ModalFormMessage | AlertMessage | NotificationMessage | SimpleMessage | RegisterMessage;
56
+ export type MessageFromParent = IMessageBase & {
57
+ type: 'on-call-callback';
58
+ path: string;
59
+ data: unknown;
60
+ };
61
+ export type Message = MessageToParent | MessageFromParent;
62
+ export type MessageHandler<T = Message> = (message: T, dispatch: MessageDispatcher<T>) => void;
63
+ export type MessageDispatcher<T = Message> = (message: T, frameId?: string) => void;
64
+ export type CallCbFunction = (path: string, data: unknown, frameId: string) => void;
65
+ export type CallbackFunction = (...args: never[]) => void;
66
+ export type Callbacks = Record<string, Record<string, CallbackFunction>>;
67
+ export interface IUseIFrameMessengerOptions {
68
+ ref?: RefObject<HTMLIFrameElement>;
69
+ id?: string;
70
+ handlers?: {
71
+ onSidePanelForm?: (data: SidePanelFormMessage['data'], dispatch: MessageDispatcher, callCb: CallCbFunction) => void;
72
+ onModalConfirm?: (data: ModalConfirmMessage['data'], id: string, dispatch: MessageDispatcher, callCb: CallCbFunction) => void;
73
+ onModalForm?: (data: ModalFormMessage['data'], id: string, dispatch: MessageDispatcher, callCb: CallCbFunction) => void;
74
+ onAlert?: (data: AlertMessage['data'], id: string, dispatch: MessageDispatcher, callCb: CallCbFunction) => void;
75
+ onNotification?: (data: NotificationMessage['data'], id: string, dispatch: MessageDispatcher, callCb: CallCbFunction) => void;
76
+ onMessage?: (data: unknown, id: string, dispatch: MessageDispatcher, callCb: CallCbFunction) => void;
77
+ };
78
+ }
@@ -0,0 +1,2 @@
1
+ export const packetId = '__fromIframeMessenger';
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/types.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,QAAQ,GAAG,uBAAuB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { type IUseIFrameMessengerOptions } from './types';
2
+ export declare const useIFrameMessenger: (options?: IUseIFrameMessengerOptions) => {
3
+ showSidePanelForm: (data: import("./types").SidePanelFormMessage["data"]) => void;
4
+ showModalConfirm: (data: import("./types").ModalConfirmMessage["data"]) => void;
5
+ showModalForm: (data: import("./types").ModalFormMessage["data"]) => void;
6
+ showAlert: (data: import("./types").AlertMessage["data"]) => void;
7
+ showNotification: (data: import("./types").NotificationMessage["data"]) => void;
8
+ messageToParent: (data: import("./types").SimpleMessage["data"]) => void;
9
+ };
@@ -0,0 +1,53 @@
1
+ import { useCallback, useEffect, useRef } from 'react';
2
+ import { encodeMessage, decodeMessage, getExposedMethods, initClientHandlers } from './messageHandlers';
3
+ import { v4 as uuid } from 'uuid';
4
+ export const useIFrameMessenger = (options) => {
5
+ const registry = useRef({});
6
+ const selfId = useRef(options?.id ?? uuid());
7
+ const dispatch = useCallback((message, frameId) => {
8
+ if (window !== window.top) {
9
+ window.parent.postMessage(encodeMessage({ ...message, __frameId: selfId.current }), '*');
10
+ }
11
+ else if (frameId && registry.current[frameId]) {
12
+ registry.current[frameId].postMessage(encodeMessage({ ...message, __frameId: selfId.current }), '*');
13
+ }
14
+ }, [registry.current]);
15
+ const callCb = useCallback((path, data, frameId) => {
16
+ dispatch({ type: 'on-call-callback', path, data }, frameId);
17
+ }, [dispatch]);
18
+ const callbacksStore = useRef({});
19
+ const methods = useRef(getExposedMethods(callbacksStore, dispatch));
20
+ useEffect(() => {
21
+ const clientHandlers = initClientHandlers(callCb, { ...options, id: selfId.current }, callbacksStore);
22
+ const onMessage = (event) => {
23
+ const message = decodeMessage(event.data);
24
+ if (!message) {
25
+ return;
26
+ }
27
+ if (message && message.type === 'register') {
28
+ const frames = window.frames;
29
+ if (window.frames.length) {
30
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
31
+ for (let i = 0; i < frames.length; i++) {
32
+ if (event.source === frames[i]) {
33
+ registry.current[message.id] = frames[i];
34
+ }
35
+ }
36
+ }
37
+ }
38
+ else {
39
+ clientHandlers(message, dispatch);
40
+ }
41
+ };
42
+ window.addEventListener('message', onMessage);
43
+ if (window !== window.top) {
44
+ // Register the message handler for the parent window
45
+ dispatch({ type: 'register', id: selfId.current });
46
+ }
47
+ return () => {
48
+ window.removeEventListener('message', onMessage);
49
+ };
50
+ }, []);
51
+ return methods.current;
52
+ };
53
+ //# sourceMappingURL=useIFrameMessenger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIFrameMessenger.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/useIFrameMessenger.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AACrD,OAAO,EAAC,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;AACtG,OAAO,EAAC,EAAE,IAAI,IAAI,EAAC,MAAM,MAAM,CAAC;AAEhC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAoC,EAAE,EAAE;IACvE,MAAM,QAAQ,GAAG,MAAM,CAAyB,EAAE,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG,MAAM,CAAS,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;IAErD,MAAM,QAAQ,GAAG,WAAW,CACxB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QACjB,IAAI,MAAM,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC;YACxB,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,EAAC,GAAG,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,OAAO,EAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAC3F,CAAC;aAAM,IAAI,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAY,CAAC,WAAW,CAC7C,aAAa,CAAC,EAAC,GAAG,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,OAAO,EAAC,CAAC,EACtD,GAAG,CACN,CAAC;QACN,CAAC;IACL,CAAC,EACD,CAAC,QAAQ,CAAC,OAAO,CAAC,CACrB,CAAC;I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AAC;gBACJ,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YACtC,CAAC;QACL,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAE9C,IAAI,MAAM,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC;YACxB,qDAAqD;YACrD,QAAQ,CAAC,EAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,CAAC,OAAO,EAAC,CAAC,CAAC;QACrD,CAAC;QAED,OAAO,GAAG,EAAE;YACR,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QACrD,CAAC,CAAC;IACN,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,OAAO,CAAC,OAAO,CAAC;AAC3B,CAAC,CAAC"}
@@ -76,6 +76,7 @@
76
76
  "behavior_standard": "Standard",
77
77
  "behavior_files": "Files",
78
78
  "behavior_directories": "Directories",
79
+ "behavior_join": "Join",
79
80
  "record_identity": "ID card of records",
80
81
  "preview": "Preview",
81
82
  "color": "Color",
@@ -485,7 +486,9 @@
485
486
  "end_date": "End date",
486
487
  "select_an_option": "Select an option"
487
488
  },
488
- "replace-by-existing-item": "Replace by an existing item"
489
+ "replace-by-existing-item": "Replace by an existing item",
490
+ "open_sidebar": "Open sidebar",
491
+ "close_sidebar": "Close sidebar"
489
492
  },
490
493
  "record_summary": {
491
494
  "preview_title": "Click here to visualize preview.",
@@ -76,6 +76,7 @@
76
76
  "behavior_standard": "Standard",
77
77
  "behavior_files": "Fichiers",
78
78
  "behavior_directories": "Dossiers",
79
+ "behavior_join": "Jointure",
79
80
  "record_identity": "Carte d'identité des éléments",
80
81
  "preview": "Aperçu",
81
82
  "color": "Couleur",
@@ -485,7 +486,9 @@
485
486
  "end_date": "Date de fin",
486
487
  "select_an_option": "Sélectionner une option"
487
488
  },
488
- "replace-by-existing-item": "Remplacer par un élément existant"
489
+ "replace-by-existing-item": "Remplacer par un élément existant",
490
+ "open_sidebar": "Ouvrir le panneau latéral",
491
+ "close_sidebar": "Fermer le panneau latéral"
489
492
  },
490
493
  "record_summary": {
491
494
  "preview_title": "Cliquez ici pour voir l’aperçu.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leav/ui",
3
- "version": "0.4.0-2a1719c",
3
+ "version": "0.4.0-2c820e6",
4
4
  "description": "Shared React components and hooks",
5
5
  "scripts": {
6
6
  "prepublishOnly": "yarn build",
@@ -52,15 +52,15 @@
52
52
  "@ant-design/icons": ">=5.2",
53
53
  "@apollo/client": ">=3.8.1",
54
54
  "antd": "5.22.2",
55
- "aristid-ds": "13.0.0-a482bfb",
55
+ "aristid-ds": "13.0.0-d4d9bc3",
56
56
  "dayjs": "^1.11.13",
57
57
  "i18next": "22.5",
58
58
  "react": "18.2.0",
59
59
  "react-dom": "18.2.0",
60
60
  "react-i18next": "12",
61
61
  "react-icons": ">=4",
62
- "styled-components": ">=5.3",
63
- "react-router-dom": "^6.22.0"
62
+ "react-router-dom": "6.22.0",
63
+ "styled-components": ">=5.3"
64
64
  },
65
65
  "dependencies": {
66
66
  "@ckeditor/ckeditor5-build-inline": "39.0.1",