@apia/dashboard-controller 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/basicAction.d.ts +15 -0
- package/dist/actions/basicAction.d.ts.map +1 -0
- package/dist/actions/basicAction.js +40 -0
- package/dist/actions/basicAction.js.map +1 -0
- package/dist/actions/externalFirePanelAction.d.ts +6 -0
- package/dist/actions/externalFirePanelAction.d.ts.map +1 -0
- package/dist/actions/externalFirePanelAction.js +12 -0
- package/dist/actions/externalFirePanelAction.js.map +1 -0
- package/dist/actions/firePanelAction.d.ts +6 -0
- package/dist/actions/firePanelAction.d.ts.map +1 -0
- package/dist/actions/firePanelAction.js +75 -0
- package/dist/actions/firePanelAction.js.map +1 -0
- package/dist/actions/usePanelActions.d.ts +63 -0
- package/dist/actions/usePanelActions.d.ts.map +1 -0
- package/dist/actions/usePanelActions.js +55 -0
- package/dist/actions/usePanelActions.js.map +1 -0
- package/dist/actions/usePanelIsLoading.d.ts +4 -0
- package/dist/actions/usePanelIsLoading.d.ts.map +1 -0
- package/dist/actions/usePanelIsLoading.js +14 -0
- package/dist/actions/usePanelIsLoading.js.map +1 -0
- package/dist/actions/usePanelNetworkState.d.ts +8 -0
- package/dist/actions/usePanelNetworkState.d.ts.map +1 -0
- package/dist/actions/usePanelNetworkState.js +21 -0
- package/dist/actions/usePanelNetworkState.js.map +1 -0
- package/dist/common/usePanelIdentity.d.ts +10 -0
- package/dist/common/usePanelIdentity.d.ts.map +1 -0
- package/dist/common/usePanelIdentity.js +12 -0
- package/dist/common/usePanelIdentity.js.map +1 -0
- package/dist/config/parametersStore.d.ts +15 -0
- package/dist/config/parametersStore.d.ts.map +1 -0
- package/dist/config/parametersStore.js +25 -0
- package/dist/config/parametersStore.js.map +1 -0
- package/dist/config/saveParameters.d.ts +11 -0
- package/dist/config/saveParameters.d.ts.map +1 -0
- package/dist/config/saveParameters.js +16 -0
- package/dist/config/saveParameters.js.map +1 -0
- package/dist/config/usePanelConfig.js +22 -0
- package/dist/config/usePanelConfig.js.map +1 -0
- package/dist/config/usePanelParametersSelector.d.ts +25 -0
- package/dist/config/usePanelParametersSelector.d.ts.map +1 -0
- package/dist/config/usePanelParametersSelector.js +17 -0
- package/dist/config/usePanelParametersSelector.js.map +1 -0
- package/dist/dashboard/DashboardContext.d.ts +6 -0
- package/dist/dashboard/DashboardContext.d.ts.map +1 -0
- package/dist/dashboard/DashboardContext.js +12 -0
- package/dist/dashboard/DashboardContext.js.map +1 -0
- package/dist/dashboard/DashboardPanel.d.ts +45 -0
- package/dist/dashboard/DashboardPanel.d.ts.map +1 -0
- package/dist/dashboard/DashboardPanel.js +236 -0
- package/dist/dashboard/DashboardPanel.js.map +1 -0
- package/dist/dashboard/DashboardPanelContext.d.ts +6 -0
- package/dist/dashboard/DashboardPanelContext.d.ts.map +1 -0
- package/dist/dashboard/DashboardPanelContext.js +12 -0
- package/dist/dashboard/DashboardPanelContext.js.map +1 -0
- package/dist/dashboard/DashboardPanelsBootstraper.d.ts +33 -0
- package/dist/dashboard/DashboardPanelsBootstraper.d.ts.map +1 -0
- package/dist/dashboard/DashboardPanelsBootstraper.js +135 -0
- package/dist/dashboard/DashboardPanelsBootstraper.js.map +1 -0
- package/dist/dashboard/DashboardRouter.d.ts +30 -0
- package/dist/dashboard/DashboardRouter.d.ts.map +1 -0
- package/dist/dashboard/DashboardRouter.js +74 -0
- package/dist/dashboard/DashboardRouter.js.map +1 -0
- package/dist/dashboard/PanelNotFound.js +14 -0
- package/dist/dashboard/PanelNotFound.js.map +1 -0
- package/dist/dashboard/dashboard.d.ts +26 -0
- package/dist/dashboard/dashboard.d.ts.map +1 -0
- package/dist/dashboard/dashboard.js +167 -0
- package/dist/dashboard/dashboard.js.map +1 -0
- package/dist/eventsController/eventsController.d.ts +11 -0
- package/dist/eventsController/eventsController.d.ts.map +1 -0
- package/dist/eventsController/eventsController.js +57 -0
- package/dist/eventsController/eventsController.js.map +1 -0
- package/dist/eventsController/types.d.ts +21 -0
- package/dist/eventsController/types.d.ts.map +1 -0
- package/dist/eventsController/usePanelFireEvent.d.ts +13 -0
- package/dist/eventsController/usePanelFireEvent.d.ts.map +1 -0
- package/dist/eventsController/usePanelFireEvent.js +21 -0
- package/dist/eventsController/usePanelFireEvent.js.map +1 -0
- package/dist/eventsController/usePanelOnEvent.d.ts +12 -0
- package/dist/eventsController/usePanelOnEvent.d.ts.map +1 -0
- package/dist/eventsController/usePanelOnEvent.js +14 -0
- package/dist/eventsController/usePanelOnEvent.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/panelsStore/createPanelStore.d.ts +16 -0
- package/dist/panelsStore/createPanelStore.d.ts.map +1 -0
- package/dist/panelsStore/createPanelStore.js +58 -0
- package/dist/panelsStore/createPanelStore.js.map +1 -0
- package/dist/panelsStore/panelsStore.js +59 -0
- package/dist/panelsStore/panelsStore.js.map +1 -0
- package/dist/panelsStore/usePanelSelector.js +32 -0
- package/dist/panelsStore/usePanelSelector.js.map +1 -0
- package/dist/panelsUtil/usePanelChangeTitle.d.ts +5 -0
- package/dist/panelsUtil/usePanelChangeTitle.d.ts.map +1 -0
- package/dist/panelsUtil/usePanelChangeTitle.js +23 -0
- package/dist/panelsUtil/usePanelChangeTitle.js.map +1 -0
- package/dist/panelsUtil/usePanelTitleAction.js +34 -0
- package/dist/panelsUtil/usePanelTitleAction.js.map +1 -0
- package/dist/position/usePanelPosition.d.ts +13 -0
- package/dist/position/usePanelPosition.d.ts.map +1 -0
- package/dist/position/usePanelPosition.js +40 -0
- package/dist/position/usePanelPosition.js.map +1 -0
- package/dist/splash/events/Dragleave.js +15 -0
- package/dist/splash/events/Dragleave.js.map +1 -0
- package/dist/splash/events/Dragover.js +120 -0
- package/dist/splash/events/Dragover.js.map +1 -0
- package/dist/splash/events/Dragstart.js +65 -0
- package/dist/splash/events/Dragstart.js.map +1 -0
- package/dist/splash/events/Drop.js +60 -0
- package/dist/splash/events/Drop.js.map +1 -0
- package/dist/splash/panels/DefaultPanelWrapper/NetworkState.js +28 -0
- package/dist/splash/panels/DefaultPanelWrapper/NetworkState.js.map +1 -0
- package/dist/splash/panels/DefaultPanelWrapper/PanelButtons.js +16 -0
- package/dist/splash/panels/DefaultPanelWrapper/PanelButtons.js.map +1 -0
- package/dist/splash/panels/DefaultPanelWrapper/RefreshButton.js +35 -0
- package/dist/splash/panels/DefaultPanelWrapper/RefreshButton.js.map +1 -0
- package/dist/splash/panels/DefaultPanelWrapper/SettingsButton.js +45 -0
- package/dist/splash/panels/DefaultPanelWrapper/SettingsButton.js.map +1 -0
- package/dist/splash/panels/DefaultPanelWrapper/defaultPanelWrapperStyles.js +103 -0
- package/dist/splash/panels/DefaultPanelWrapper/defaultPanelWrapperStyles.js.map +1 -0
- package/dist/splash/panels/DefaultPanelWrapper/index.js +57 -0
- package/dist/splash/panels/DefaultPanelWrapper/index.js.map +1 -0
- package/dist/splash/panels/LandingPagePanelWrapper.d.ts +6 -0
- package/dist/splash/panels/LandingPagePanelWrapper.d.ts.map +1 -0
- package/dist/splash/panels/LandingPagePanelWrapper.js +52 -0
- package/dist/splash/panels/LandingPagePanelWrapper.js.map +1 -0
- package/dist/splash/panels/PanelContext/PanelFooter.js +70 -0
- package/dist/splash/panels/PanelContext/PanelFooter.js.map +1 -0
- package/dist/splash/panels/PanelContext/index.d.ts +26 -0
- package/dist/splash/panels/PanelContext/index.d.ts.map +1 -0
- package/dist/splash/panels/PanelContext/index.js +73 -0
- package/dist/splash/panels/PanelContext/index.js.map +1 -0
- package/dist/splash/panels/PanelContext/usePanelContextLayout.d.ts +6 -0
- package/dist/splash/panels/PanelContext/usePanelContextLayout.d.ts.map +1 -0
- package/dist/splash/panels/PanelContext/usePanelContextLayout.js +38 -0
- package/dist/splash/panels/PanelContext/usePanelContextLayout.js.map +1 -0
- package/dist/splash/panels/PanelContext/usePanelFooter.js +38 -0
- package/dist/splash/panels/PanelContext/usePanelFooter.js.map +1 -0
- package/dist/splash/panels/PanelContext/useYieldPanelIsReady.d.ts +45 -0
- package/dist/splash/panels/PanelContext/useYieldPanelIsReady.d.ts.map +1 -0
- package/dist/splash/panels/PanelContext/useYieldPanelIsReady.js +12 -0
- package/dist/splash/panels/PanelContext/useYieldPanelIsReady.js.map +1 -0
- package/dist/splash/panels/PanelErrorBoundary.js +53 -0
- package/dist/splash/panels/PanelErrorBoundary.js.map +1 -0
- package/dist/splash/panels/PanelIdentifier.d.ts +16 -0
- package/dist/splash/panels/PanelIdentifier.d.ts.map +1 -0
- package/dist/splash/panels/PanelIdentifier.js +19 -0
- package/dist/splash/panels/PanelIdentifier.js.map +1 -0
- package/dist/splash/util/DragAndDrop.js +243 -0
- package/dist/splash/util/DragAndDrop.js.map +1 -0
- package/dist/splash/util/getColumnAreas.js +19 -0
- package/dist/splash/util/getColumnAreas.js.map +1 -0
- package/dist/splash/util/isCursorInArea.js +13 -0
- package/dist/splash/util/isCursorInArea.js.map +1 -0
- package/dist/types.d.ts +27 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/util.d.ts +8 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +30 -0
- package/dist/util.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { shallowEqual } from '@apia/store';
|
|
2
|
+
import { useLatest } from '@apia/util';
|
|
3
|
+
import { useMemo, useEffect } from 'react';
|
|
4
|
+
import { registerReducers, panelsStore, panelsActions } from './panelsStore.js';
|
|
5
|
+
import { usePanelSelector } from './usePanelSelector.js';
|
|
6
|
+
import { usePanelIdentity } from '../common/usePanelIdentity.js';
|
|
7
|
+
import { useDashboardContext } from '../dashboard/DashboardContext.js';
|
|
8
|
+
|
|
9
|
+
function createPanelStore(panelType, initialState, reducers) {
|
|
10
|
+
const useSelector = (panelName, selector, comparator = shallowEqual) => {
|
|
11
|
+
const dashboard = useDashboardContext();
|
|
12
|
+
const props = useMemo(
|
|
13
|
+
() => dashboard.getPanelByName(panelName)?.props,
|
|
14
|
+
[dashboard, panelName]
|
|
15
|
+
);
|
|
16
|
+
const propsRef = useLatest(props);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
panelsStore.dispatch(
|
|
19
|
+
panelsActions.initState({
|
|
20
|
+
panelType,
|
|
21
|
+
panelId: propsRef.current.id,
|
|
22
|
+
initialState
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
}, []);
|
|
26
|
+
return usePanelSelector(
|
|
27
|
+
panelType,
|
|
28
|
+
panelName,
|
|
29
|
+
initialState,
|
|
30
|
+
selector,
|
|
31
|
+
comparator
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
registerReducers(panelType, reducers);
|
|
35
|
+
const usePanelDispatcher = () => {
|
|
36
|
+
const { panelName: contextPanelName } = usePanelIdentity();
|
|
37
|
+
const dispatchers = {};
|
|
38
|
+
const dashboard = useDashboardContext();
|
|
39
|
+
Object.entries(reducers).forEach(([name]) => {
|
|
40
|
+
dispatchers[name] = (payload, panelName) => {
|
|
41
|
+
const props = dashboard.getPanelByName(panelName ?? contextPanelName)?.props;
|
|
42
|
+
panelsStore.dispatch(
|
|
43
|
+
panelsActions.updatePanelStore({
|
|
44
|
+
panelId: props.id,
|
|
45
|
+
panelType,
|
|
46
|
+
data: { payload },
|
|
47
|
+
reducer: name
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
return dispatchers;
|
|
53
|
+
};
|
|
54
|
+
return [usePanelDispatcher, useSelector];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { createPanelStore };
|
|
58
|
+
//# sourceMappingURL=createPanelStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createPanelStore.js","sources":["../../src/panelsStore/createPanelStore.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { SliceCaseReducers, shallowEqual } from '@apia/store';\nimport { useLatest } from '@apia/util';\nimport { useEffect, useMemo } from 'react';\nimport { TLoadedPanelProps, TPanelName, TPanelType } from '../types';\nimport { panelsActions, panelsStore, registerReducers } from './panelsStore';\nimport { usePanelSelector } from './usePanelSelector';\nimport { usePanelIdentity } from '../common';\nimport { useDashboardContext } from '../dashboard';\n\ndeclare type ActionCreatorForCaseReducer<CR> = CR extends (\n state: any,\n action: infer Action,\n) => any\n ? Action extends {\n payload: infer P;\n }\n ? (payload: P, panelName?: string) => unknown\n : () => unknown\n : () => unknown;\n\ntype CaseReducerActions<CaseReducers extends SliceCaseReducers<any>> = {\n [Type in keyof CaseReducers]: ActionCreatorForCaseReducer<CaseReducers[Type]>;\n};\n\nexport function createPanelStore<\n PanelState = any,\n Reducers extends SliceCaseReducers<PanelState> = SliceCaseReducers<PanelState>,\n>(\n panelType: TPanelType,\n initialState: PanelState,\n reducers: Reducers,\n): [\n () => CaseReducerActions<Reducers>,\n <Selected>(\n panelName: TPanelName,\n selector: (state: PanelState) => Selected,\n comparator?: (a: Selected, b: Selected) => boolean,\n ) => Selected,\n] {\n const useSelector = <Selected>(\n panelName: TPanelName,\n selector: (state: PanelState) => Selected,\n comparator: (a: Selected, b: Selected) => boolean = shallowEqual,\n ): Selected => {\n const dashboard = useDashboardContext();\n const props = useMemo(\n () => dashboard.getPanelByName(panelName)?.props as TLoadedPanelProps,\n [dashboard, panelName],\n );\n\n const propsRef = useLatest(props);\n\n useEffect(() => {\n panelsStore.dispatch(\n panelsActions.initState({\n panelType,\n panelId: propsRef.current.id,\n initialState,\n }),\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return usePanelSelector<PanelState, Selected>(\n panelType,\n panelName,\n initialState,\n selector,\n comparator,\n );\n };\n\n registerReducers<PanelState>(panelType, reducers);\n\n /**\n * Devuelve un objeto de dispatchers asociados al panel. Este hook puede ser\n * exportado pero es importante comprender su funcionamiento: cuando es usado\n * acepta un segundo parámetro opcional panelName que en caso de no ser\n * pasado, utilizará el del contexto del panel desde el que se ejecuta.\n */\n const usePanelDispatcher = () => {\n const { panelName: contextPanelName } = usePanelIdentity();\n const dispatchers: CaseReducerActions<Reducers> =\n {} as CaseReducerActions<Reducers>;\n const dashboard = useDashboardContext();\n\n Object.entries(reducers).forEach(([name]) => {\n dispatchers[name as keyof typeof dispatchers] = ((\n payload: any,\n panelName?: TPanelName,\n ) => {\n const props = dashboard.getPanelByName(panelName ?? contextPanelName)\n ?.props as TLoadedPanelProps;\n\n panelsStore.dispatch(\n panelsActions.updatePanelStore({\n panelId: props.id,\n panelType,\n data: { payload },\n reducer: name,\n }),\n );\n }) as any;\n });\n\n return dispatchers;\n };\n\n return [usePanelDispatcher, useSelector];\n}\n"],"names":[],"mappings":";;;;;;;;AA0BgB,SAAA,gBAAA,CAId,SACA,EAAA,YAAA,EACA,QAQA,EAAA;AACA,EAAA,MAAM,WAAc,GAAA,CAClB,SACA,EAAA,QAAA,EACA,aAAoD,YACvC,KAAA;AACb,IAAA,MAAM,YAAY,mBAAoB,EAAA,CAAA;AACtC,IAAA,MAAM,KAAQ,GAAA,OAAA;AAAA,MACZ,MAAM,SAAA,CAAU,cAAe,CAAA,SAAS,CAAG,EAAA,KAAA;AAAA,MAC3C,CAAC,WAAW,SAAS,CAAA;AAAA,KACvB,CAAA;AAEA,IAAM,MAAA,QAAA,GAAW,UAAU,KAAK,CAAA,CAAA;AAEhC,IAAA,SAAA,CAAU,MAAM;AACd,MAAY,WAAA,CAAA,QAAA;AAAA,QACV,cAAc,SAAU,CAAA;AAAA,UACtB,SAAA;AAAA,UACA,OAAA,EAAS,SAAS,OAAQ,CAAA,EAAA;AAAA,UAC1B,YAAA;AAAA,SACD,CAAA;AAAA,OACH,CAAA;AAAA,KAEF,EAAG,EAAE,CAAA,CAAA;AAEL,IAAO,OAAA,gBAAA;AAAA,MACL,SAAA;AAAA,MACA,SAAA;AAAA,MACA,YAAA;AAAA,MACA,QAAA;AAAA,MACA,UAAA;AAAA,KACF,CAAA;AAAA,GACF,CAAA;AAEA,EAAA,gBAAA,CAA6B,WAAW,QAAQ,CAAA,CAAA;AAQhD,EAAA,MAAM,qBAAqB,MAAM;AAC/B,IAAA,MAAM,EAAE,SAAA,EAAW,gBAAiB,EAAA,GAAI,gBAAiB,EAAA,CAAA;AACzD,IAAA,MAAM,cACJ,EAAC,CAAA;AACH,IAAA,MAAM,YAAY,mBAAoB,EAAA,CAAA;AAEtC,IAAA,MAAA,CAAO,QAAQ,QAAQ,CAAA,CAAE,QAAQ,CAAC,CAAC,IAAI,CAAM,KAAA;AAC3C,MAAA,WAAA,CAAY,IAAgC,CAAA,GAAK,CAC/C,OAAA,EACA,SACG,KAAA;AACH,QAAA,MAAM,KAAQ,GAAA,SAAA,CAAU,cAAe,CAAA,SAAA,IAAa,gBAAgB,CAChE,EAAA,KAAA,CAAA;AAEJ,QAAY,WAAA,CAAA,QAAA;AAAA,UACV,cAAc,gBAAiB,CAAA;AAAA,YAC7B,SAAS,KAAM,CAAA,EAAA;AAAA,YACf,SAAA;AAAA,YACA,IAAA,EAAM,EAAE,OAAQ,EAAA;AAAA,YAChB,OAAS,EAAA,IAAA;AAAA,WACV,CAAA;AAAA,SACH,CAAA;AAAA,OACF,CAAA;AAAA,KACD,CAAA,CAAA;AAED,IAAO,OAAA,WAAA,CAAA;AAAA,GACT,CAAA;AAEA,EAAO,OAAA,CAAC,oBAAoB,WAAW,CAAA,CAAA;AACzC;;;;"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createSlice, injectReducers } from '@apia/store';
|
|
2
|
+
|
|
3
|
+
const reducers = {};
|
|
4
|
+
function initPanelTypeUpdater(panelType) {
|
|
5
|
+
if (!reducers[panelType]) {
|
|
6
|
+
reducers[panelType] = {
|
|
7
|
+
defaultReducer: (panelsState, payload) => {
|
|
8
|
+
Object.assign(panelsState, payload);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function registerReducers(panelType, newReducers) {
|
|
14
|
+
initPanelTypeUpdater(panelType);
|
|
15
|
+
Object.assign(reducers[panelType], newReducers);
|
|
16
|
+
}
|
|
17
|
+
function initPanelState(state, panelType, panelId, initialState) {
|
|
18
|
+
if (!state[panelType]) {
|
|
19
|
+
state[panelType] = {};
|
|
20
|
+
}
|
|
21
|
+
if (!state[panelType][panelId])
|
|
22
|
+
state[panelType][panelId] = {};
|
|
23
|
+
state[panelType][panelId] = initialState;
|
|
24
|
+
}
|
|
25
|
+
const panelsSlice = createSlice({
|
|
26
|
+
name: "panelsSlice",
|
|
27
|
+
initialState: {},
|
|
28
|
+
reducers: {
|
|
29
|
+
initState(state, {
|
|
30
|
+
payload: { panelId, panelType, initialState }
|
|
31
|
+
}) {
|
|
32
|
+
if (!state[panelType]?.[panelId]) {
|
|
33
|
+
initPanelState(state, panelType, panelId, initialState);
|
|
34
|
+
state[panelType][panelId] = initialState;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
updatePanelStore(state, {
|
|
38
|
+
payload: { data, panelId, panelType, reducer, initialState }
|
|
39
|
+
}) {
|
|
40
|
+
if (!state[panelType]?.[panelId]) {
|
|
41
|
+
initPanelState(state, panelType, panelId, initialState ?? {});
|
|
42
|
+
}
|
|
43
|
+
const panelsStore2 = state[panelType][panelId];
|
|
44
|
+
initPanelTypeUpdater(panelType);
|
|
45
|
+
if (!reducers[panelType][reducer ?? "default"]) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const currentReducer = reducers[panelType][reducer ?? "default"];
|
|
49
|
+
currentReducer(panelsStore2, data);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const { useSelector: usePanelStoreSelector, store: panelsStore } = injectReducers({
|
|
54
|
+
panelsSlice: panelsSlice.reducer
|
|
55
|
+
});
|
|
56
|
+
const panelsActions = panelsSlice.actions;
|
|
57
|
+
|
|
58
|
+
export { initPanelState, initPanelTypeUpdater, panelsActions, panelsSlice, panelsStore, reducers, registerReducers, usePanelStoreSelector };
|
|
59
|
+
//# sourceMappingURL=panelsStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panelsStore.js","sources":["../../src/panelsStore/panelsStore.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-types */\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable no-restricted-imports */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport {\n createSlice,\n injectReducers,\n PayloadAction,\n Draft,\n SliceCaseReducers,\n CaseReducer,\n} from '@apia/store';\nimport { TPanelId, TPanelType } from '../types';\n\ntype ValidateSliceCaseReducers<S, ACR extends SliceCaseReducers<S>> = ACR & {\n [T in keyof ACR]: ACR[T] extends {\n reducer(s: S, action?: infer A): any;\n }\n ? {\n prepare(...a: never[]): Omit<A, 'type'>;\n }\n : {};\n};\n\nexport type TPanelsSliceState = Record<string, Record<string, unknown>>;\n\nexport type TReducers<\n State = any,\n CR extends SliceCaseReducers<State> = SliceCaseReducers<State>,\n> = ValidateSliceCaseReducers<State, CR>;\n\ntype TPanelsReducers<\n State = any,\n CR extends SliceCaseReducers<State> = SliceCaseReducers<State>,\n> = Record<string, TReducers<State, CR>>;\n\n/**\n * Los updaters son funciones que permiten modificar la forma en la que un\n * panel modifica su estado, se puede pensar como un análogo del reducer\n *\n * {\n * panelTypeA: {\n * updaterA: (state, data) => { ...update panel store },\n * updaterB: (state, data) => { ...update panel store },\n * }\n * }\n */\nexport const reducers: TPanelsReducers<Record<string, unknown>> = {};\n\nexport function initPanelTypeUpdater(panelType: TPanelType) {\n if (!reducers[panelType]) {\n reducers[panelType] = {\n defaultReducer: (\n panelsState,\n payload: PayloadAction<{ name: string }>,\n ) => {\n Object.assign(panelsState, payload);\n },\n };\n }\n}\n\n/**\n * Permite registrar nuevas formas de actualizar el estado de un tipo de panel\n */\nexport function registerReducers<\n State = any,\n CR extends SliceCaseReducers<State> = SliceCaseReducers<State>,\n>(panelType: TPanelType, newReducers: TReducers<State, CR>) {\n initPanelTypeUpdater(panelType);\n Object.assign(reducers[panelType], newReducers);\n}\n\nexport function initPanelState(\n state: Draft<TPanelsSliceState>,\n panelType: TPanelType,\n panelId: TPanelId,\n initialState: any,\n) {\n if (!state[panelType]) {\n state[panelType] = {};\n }\n if (!state[panelType][panelId]) state[panelType][panelId] = {};\n state[panelType][panelId] = initialState;\n}\n\nexport const panelsSlice = createSlice({\n name: 'panelsSlice',\n initialState: {} as TPanelsSliceState,\n reducers: {\n initState(\n state,\n {\n payload: { panelId, panelType, initialState },\n }: PayloadAction<{\n panelType: TPanelType;\n panelId: TPanelId;\n reducer?: string; // reducer will be used to customize the way the slice is updated\n initialState: any;\n }>,\n ) {\n if (!state[panelType]?.[panelId]) {\n initPanelState(state, panelType, panelId, initialState);\n state[panelType][panelId] = initialState;\n }\n },\n updatePanelStore(\n state,\n {\n payload: { data, panelId, panelType, reducer, initialState },\n }: PayloadAction<{\n panelType: TPanelType;\n panelId: TPanelId;\n reducer?: string; // Updater will be used to customize the way the slice is updated\n data: any;\n initialState?: any;\n }>,\n ) {\n if (!state[panelType]?.[panelId]) {\n initPanelState(state, panelType, panelId, initialState ?? {});\n }\n const panelsStore = state[panelType][panelId];\n initPanelTypeUpdater(panelType);\n\n if (!reducers[panelType][reducer ?? 'default']) {\n return;\n }\n\n const currentReducer = reducers[panelType][\n reducer ?? 'default'\n ] as CaseReducer;\n currentReducer(panelsStore, data);\n },\n },\n});\n\nexport const { useSelector: usePanelStoreSelector, store: panelsStore } =\n injectReducers({\n panelsSlice: panelsSlice.reducer,\n });\n\nexport const panelsActions = panelsSlice.actions;\n"],"names":["panelsStore"],"mappings":";;AAgDO,MAAM,WAAqD,GAAC;AAE5D,SAAS,qBAAqB,SAAuB,EAAA;AAC1D,EAAI,IAAA,CAAC,QAAS,CAAA,SAAS,CAAG,E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,CAAA;AAAA,OAC9B;AAAA,KACF;AAAA,IACA,iBACE,KACA,EAAA;AAAA,MACE,SAAS,EAAE,IAAA,EAAM,OAAS,EAAA,SAAA,EAAW,SAAS,YAAa,EAAA;AAAA,KAQ7D,EAAA;AACA,MAAA,IAAI,CAAC,KAAA,CAAM,SAAS,CAAA,GAAI,OAAO,CAAG,EAAA;AAChC,QAAA,cAAA,CAAe,KAAO,EAAA,SAAA,EAAW,OAAS,EAAA,YAAA,IAAgB,EAAE,CAAA,CAAA;AAAA,OAC9D;AACA,MAAA,MAAMA,YAAc,GAAA,KAAA,CAAM,SAAS,CAAA,CAAE,OAAO,CAAA,CAAA;AAC5C,MAAA,oBAAA,CAAqB,SAAS,CAAA,CAAA;AAE9B,MAAA,IAAI,CAAC,QAAS,CAAA,SAAS,CAAE,CAAA,OAAA,IAAW,SAAS,CAAG,EAAA;AAC9C,QAAA,OAAA;AAAA,OACF;AAEA,MAAA,MAAM,cAAiB,GAAA,QAAA,CAAS,SAAS,CAAA,CACvC,WAAW,SACb,CAAA,CAAA;AACA,MAAA,cAAA,CAAeA,cAAa,IAAI,CAAA,CAAA;AAAA,KAClC;AAAA,GACF;AACF,CAAC,EAAA;AAEM,MAAM,EAAE,WAAa,EAAA,qBAAA,EAAuB,KAAO,EAAA,WAAA,KACxD,cAAe,CAAA;AAAA,EACb,aAAa,WAAY,CAAA,OAAA;AAC3B,CAAC,EAAA;AAEI,MAAM,gBAAgB,WAAY,CAAA;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { shallowEqual } from '@apia/store';
|
|
2
|
+
import { useState, useRef } from 'react';
|
|
3
|
+
import { panelsStore, usePanelStoreSelector } from './panelsStore.js';
|
|
4
|
+
import { usePanelIdentity } from '../common/usePanelIdentity.js';
|
|
5
|
+
|
|
6
|
+
const undefinedObject = {};
|
|
7
|
+
function usePanelSelector(panelType, panelName, initialState, selector, comparator = shallowEqual) {
|
|
8
|
+
const { panelId } = usePanelIdentity();
|
|
9
|
+
if (!panelId)
|
|
10
|
+
throw new Error(`Cannot find panel with name ${panelName}`);
|
|
11
|
+
const storeState = panelsStore.getState().panelsSlice[panelType];
|
|
12
|
+
const [selection, setSelection] = useState(
|
|
13
|
+
initialState ? selector(storeState?.[panelId] ?? initialState) : {}
|
|
14
|
+
);
|
|
15
|
+
const previousSelected = useRef(
|
|
16
|
+
selection ?? undefinedObject
|
|
17
|
+
);
|
|
18
|
+
usePanelStoreSelector((global) => {
|
|
19
|
+
const newState = global.panelsSlice[panelType]?.[panelId];
|
|
20
|
+
if (newState !== void 0) {
|
|
21
|
+
const newSelected = selector(newState);
|
|
22
|
+
if (previousSelected.current === undefinedObject || !comparator(previousSelected.current, newSelected)) {
|
|
23
|
+
previousSelected.current = newSelected;
|
|
24
|
+
setSelection(newSelected);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return selection;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { undefinedObject, usePanelSelector };
|
|
32
|
+
//# sourceMappingURL=usePanelSelector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePanelSelector.js","sources":["../../src/panelsStore/usePanelSelector.ts"],"sourcesContent":["import { shallowEqual } from '@apia/store';\nimport { useRef, useState } from 'react';\nimport { TPanelName, TPanelType } from '../types';\nimport { panelsStore, usePanelStoreSelector } from './panelsStore';\nimport { usePanelIdentity } from '../common';\n\nexport const undefinedObject = {};\n\n/**\n * Permite escuchar el store de un panel al igual que se haría con un\n * useSelector de redux.\n *\n * @param selector Una función selectora que recibe el estado del panel y devuelve la selección deseada\n * @param comparator Opcionalmente se puede pasar un comparador para determinar si el estado debe actualizarse o no, dependiendo de la selección actual y la selección previa. Por defecto se usa shallowEqual de redux.\n * @returns La selección determinada en el selector, siempre que haya cambiado de acuerdo al comparador.\n *\n * @example\n *\n import { TRecordsPanelStore } from '..../recordsPanel';\n\n // Assume TRecordsPanelStore = { peopleNames: string[] }\n\n const firstName = usePanelSelector<TRecordsPanelStore>(\n 'RecordsPanel',\n 'RecordThisYear',\n (state) => { return state.peopleNames[0] }\n );\n */\nexport function usePanelSelector<StoreType, Selected>(\n panelType: TPanelType,\n panelName: TPanelName,\n initialState: StoreType,\n selector: (state: StoreType) => Selected,\n comparator: (a: Selected, b: Selected) => boolean = shallowEqual,\n): Selected {\n const { panelId } = usePanelIdentity();\n if (!panelId) throw new Error(`Cannot find panel with name ${panelName}`);\n\n const storeState = panelsStore.getState().panelsSlice[panelType];\n const [selection, setSelection] = useState<Selected>(\n initialState\n ? selector((storeState?.[panelId] as StoreType) ?? initialState)\n : ({} as Selected),\n );\n\n const previousSelected = useRef<Selected>(\n selection ?? (undefinedObject as Selected),\n );\n\n usePanelStoreSelector((global) => {\n const newState = global.panelsSlice[panelType]?.[panelId] as\n | StoreType\n | undefined;\n if (newState !== undefined) {\n const newSelected = selector(newState);\n if (\n previousSelected.current === undefinedObject ||\n !comparator(previousSelected.current as Selected, newSelected)\n ) {\n previousSelected.current = newSelected;\n setSelection(newSelected);\n }\n }\n });\n\n return selection;\n}\n"],"names":[],"mappings":";;;;;AAMO,MAAM,kBAAkB,GAAC;AAsBzB,SAAS,iBACd,SACA,EAAA,SAAA,EACA,YACA,EAAA,QAAA,EACA,aAAoD,YAC1C,EAAA;AACV,EAAM,MAAA,EAAE,OAAQ,EAAA,GAAI,gBAAiB,EAAA,CAAA;AACrC,EAAA,IAAI,CAAC,OAAA;AAAS,IAAA,MAAM,IAAI,KAAA,CAAM,CAA+B,4BAAA,EAAA,SAAS,CAAE,CAAA,CAAA,CAAA;AAExE,EAAA,MAAM,UAAa,GAAA,WAAA,CAAY,QAAS,EAAA,CAAE,YAAY,SAAS,CAAA,CAAA;AAC/D,EAAM,MAAA,CAAC,SAAW,EAAA,YAAY,CAAI,GAAA,QAAA;AAAA,IAChC,eACI,QAAU,CAAA,UAAA,GAAa,OAAO,CAAmB,IAAA,YAAY,IAC5D,EAAC;AAAA,GACR,CAAA;AAEA,EAAA,MAAM,gBAAmB,GAAA,MAAA;AAAA,IACvB,SAAc,IAAA,eAAA;AAAA,GAChB,CAAA;AAEA,EAAA,qBAAA,CAAsB,CAAC,MAAW,KAAA;AAChC,IAAA,MAAM,QAAW,GAAA,MAAA,CAAO,WAAY,CAAA,SAAS,IAAI,OAAO,CAAA,CAAA;AAGxD,IAAA,IAAI,aAAa,KAAW,CAAA,EAAA;AAC1B,MAAM,MAAA,WAAA,GAAc,SAAS,QAAQ,CAAA,CAAA;AACrC,MACE,IAAA,gBAAA,CAAiB,YAAY,eAC7B,IAAA,CAAC,WAAW,gBAAiB,CAAA,OAAA,EAAqB,WAAW,CAC7D,EAAA;AACA,QAAA,gBAAA,CAAiB,OAAU,GAAA,WAAA,CAAA;AAC3B,QAAA,YAAA,CAAa,WAAW,CAAA,CAAA;AAAA,OAC1B;AAAA,KACF;AAAA,GACD,CAAA,CAAA;AAED,EAAO,OAAA,SAAA,CAAA;AACT;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePanelChangeTitle.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { eventsController } from '../eventsController/eventsController.js';
|
|
3
|
+
import { usePanelFireEvent } from '../eventsController/usePanelFireEvent.js';
|
|
4
|
+
|
|
5
|
+
function changePanelTitle(panelId, newTitle) {
|
|
6
|
+
eventsController.fireEvent(
|
|
7
|
+
{ panelId },
|
|
8
|
+
"changeTitle",
|
|
9
|
+
newTitle
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
function usePanelChangeTitle() {
|
|
13
|
+
const fireEvent = usePanelFireEvent();
|
|
14
|
+
return useCallback(
|
|
15
|
+
(newTitle) => {
|
|
16
|
+
fireEvent("changeTitle", newTitle);
|
|
17
|
+
},
|
|
18
|
+
[fireEvent]
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { changePanelTitle, usePanelChangeTitle };
|
|
23
|
+
//# sourceMappingURL=usePanelChangeTitle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePanelChangeTitle.js","sources":["../../src/panelsUtil/usePanelChangeTitle.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport {\n TPanelIdentifier,\n eventsController,\n usePanelFireEvent,\n} from '../eventsController';\n\nexport function changePanelTitle(panelId: string, newTitle: string) {\n eventsController.fireEvent(\n { panelId } as TPanelIdentifier,\n 'changeTitle',\n newTitle,\n );\n}\n\nexport function usePanelChangeTitle() {\n const fireEvent = usePanelFireEvent();\n\n return useCallback(\n (newTitle: string) => {\n fireEvent('changeTitle', newTitle);\n },\n [fireEvent],\n );\n}\n"],"names":[],"mappings":";;;;AAOgB,SAAA,gBAAA,CAAiB,SAAiB,QAAkB,EAAA;AAClE,EAAiB,gBAAA,CAAA,SAAA;AAAA,IACf,EAAE,OAAQ,EAAA;AAAA,IACV,aAAA;AAAA,IACA,QAAA;AAAA,GACF,CAAA;AACF,CAAA;AAEO,SAAS,mBAAsB,GAAA;AACpC,EAAA,MAAM,YAAY,iBAAkB,EAAA,CAAA;AAEpC,EAAO,OAAA,WAAA;AAAA,IACL,CAAC,QAAqB,KAAA;AACpB,MAAA,SAAA,CAAU,eAAe,QAAQ,CAAA,CAAA;AAAA,KACnC;AAAA,IACA,CAAC,SAAS,CAAA;AAAA,GACZ,CAAA;AACF;;;;"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { usePanelParametersSelector } from '../config/usePanelParametersSelector.js';
|
|
2
|
+
import { parametersStore as store, parametersActions } from '../config/parametersStore.js';
|
|
3
|
+
|
|
4
|
+
const panelActionParameterName = "__panelTitleAction";
|
|
5
|
+
const panelDescriptionParameterName = "__panelTitleDescription";
|
|
6
|
+
function setPanelTitleAction(panelId, newAction) {
|
|
7
|
+
store.dispatch(
|
|
8
|
+
parametersActions.udpate({
|
|
9
|
+
panelId,
|
|
10
|
+
parameters: { [panelActionParameterName]: newAction }
|
|
11
|
+
})
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
function setPanelTitleDescritpion(panelId, newDescription) {
|
|
15
|
+
store.dispatch(
|
|
16
|
+
parametersActions.udpate({
|
|
17
|
+
panelId,
|
|
18
|
+
parameters: { [panelDescriptionParameterName]: newDescription }
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
function usePanelTitleAction() {
|
|
23
|
+
return usePanelParametersSelector(
|
|
24
|
+
(current) => current[panelActionParameterName]
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
function usePanelTitleDescription() {
|
|
28
|
+
return usePanelParametersSelector(
|
|
29
|
+
(current) => current[panelDescriptionParameterName]
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { setPanelTitleAction, setPanelTitleDescritpion, usePanelTitleAction, usePanelTitleDescription };
|
|
34
|
+
//# sourceMappingURL=usePanelTitleAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePanelTitleAction.js","sources":["../../src/panelsUtil/usePanelTitleAction.ts"],"sourcesContent":["import { parametersStore, usePanelParametersSelector } from '../config';\nimport { parametersActions } from '../config/parametersStore';\n\nconst panelActionParameterName = '__panelTitleAction';\nconst panelDescriptionParameterName = '__panelTitleDescription';\n\nexport function setPanelTitleAction(panelId: string, newAction: string) {\n parametersStore.dispatch(\n parametersActions.udpate({\n panelId,\n parameters: { [panelActionParameterName]: newAction },\n }),\n );\n}\nexport function setPanelTitleDescritpion(\n panelId: string,\n newDescription: string,\n) {\n parametersStore.dispatch(\n parametersActions.udpate({\n panelId,\n parameters: { [panelDescriptionParameterName]: newDescription },\n }),\n );\n}\n\nexport function usePanelTitleAction() {\n return usePanelParametersSelector(\n (current) => current[panelActionParameterName] as string,\n );\n}\n\nexport function usePanelTitleDescription() {\n return usePanelParametersSelector(\n (current) => current[panelDescriptionParameterName] as string,\n );\n}\n"],"names":["parametersStore"],"mappings":";;;AAGA,MAAM,wBAA2B,GAAA,oBAAA,CAAA;AACjC,MAAM,6BAAgC,GAAA,yBAAA,CAAA;AAEtB,SAAA,mBAAA,CAAoB,SAAiB,SAAmB,EAAA;AACtE,EAAgBA,KAAA,CAAA,QAAA;AAAA,IACd,kBAAkB,MAAO,CAAA;AAAA,MACvB,OAAA;AAAA,MACA,UAAY,EAAA,EAAE,CAAC,wBAAwB,GAAG,SAAU,EAAA;AAAA,KACrD,CAAA;AAAA,GACH,CAAA;AACF,CAAA;AACgB,SAAA,wBAAA,CACd,SACA,cACA,EAAA;AACA,EAAgBA,KAAA,CAAA,QAAA;AAAA,IACd,kBAAkB,MAAO,CAAA;AAAA,MACvB,OAAA;AAAA,MACA,UAAY,EAAA,EAAE,CAAC,6BAA6B,GAAG,cAAe,EAAA;AAAA,KAC/D,CAAA;AAAA,GACH,CAAA;AACF,CAAA;AAEO,SAAS,mBAAsB,GAAA;AACpC,EAAO,OAAA,0BAAA;AAAA,IACL,CAAC,OAAY,KAAA,OAAA,CAAQ,wBAAwB,CAAA;AAAA,GAC/C,CAAA;AACF,CAAA;AAEO,SAAS,wBAA2B,GAAA;AACzC,EAAO,OAAA,0BAAA;AAAA,IACL,CAAC,OAAY,KAAA,OAAA,CAAQ,6BAA6B,CAAA;AAAA,GACpD,CAAA;AACF;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TId } from '@apia/util';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Permite conocer la posición del panel, se actualiza automáticamente cuando
|
|
5
|
+
* ésta cambia provocando un renderizado en el padre
|
|
6
|
+
*/
|
|
7
|
+
declare function usePanelPosition(): {
|
|
8
|
+
containerId: TId;
|
|
9
|
+
position: number;
|
|
10
|
+
} | undefined;
|
|
11
|
+
|
|
12
|
+
export { usePanelPosition };
|
|
13
|
+
//# sourceMappingURL=usePanelPosition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePanelPosition.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ApiaApi, makeApiaUrl } from '@apia/api';
|
|
2
|
+
import { EventEmitter } from '@apia/util';
|
|
3
|
+
import { usePanelIdentity } from '../common/usePanelIdentity.js';
|
|
4
|
+
import { useState, useEffect } from 'react';
|
|
5
|
+
|
|
6
|
+
class PanelPositionEmitter extends EventEmitter {
|
|
7
|
+
}
|
|
8
|
+
const panelPositionEmitter = new PanelPositionEmitter();
|
|
9
|
+
function usePanelPosition() {
|
|
10
|
+
const { panelId } = usePanelIdentity();
|
|
11
|
+
const [position, setPosition] = useState();
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
return panelPositionEmitter.on("panelUpdate", (ev) => {
|
|
14
|
+
if (ev.panelId === panelId)
|
|
15
|
+
setPosition({ containerId: ev.containerId, position: ev.newPosition });
|
|
16
|
+
});
|
|
17
|
+
}, [panelId]);
|
|
18
|
+
return position;
|
|
19
|
+
}
|
|
20
|
+
async function updatePanelPosition(panelId, containerId, newPosition) {
|
|
21
|
+
const result = await ApiaApi.post(
|
|
22
|
+
makeApiaUrl({
|
|
23
|
+
action: "panelMove",
|
|
24
|
+
pnlId: panelId,
|
|
25
|
+
containerId,
|
|
26
|
+
newPosition
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
const hasUpdated = result?.data && !result.hasError && !result.hasMessages;
|
|
30
|
+
if (hasUpdated)
|
|
31
|
+
panelPositionEmitter.emit("panelUpdate", {
|
|
32
|
+
panelId,
|
|
33
|
+
containerId,
|
|
34
|
+
newPosition
|
|
35
|
+
});
|
|
36
|
+
return hasUpdated;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { panelPositionEmitter, updatePanelPosition, usePanelPosition };
|
|
40
|
+
//# sourceMappingURL=usePanelPosition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePanelPosition.js","sources":["../../src/position/usePanelPosition.ts"],"sourcesContent":["import { ApiaApi, makeApiaUrl } from '@apia/api';\nimport { EventEmitter, TId } from '@apia/util';\nimport { usePanelIdentity } from '../common';\nimport { useEffect, useState } from 'react';\n\nclass PanelPositionEmitter extends EventEmitter<{\n panelUpdate: {\n panelId: TId;\n containerId: TId;\n newPosition: number;\n };\n}> {}\n\nexport const panelPositionEmitter = new PanelPositionEmitter();\n\n/**\n * Permite conocer la posición del panel, se actualiza automáticamente cuando\n * ésta cambia provocando un renderizado en el padre\n */\nexport function usePanelPosition() {\n const { panelId } = usePanelIdentity();\n\n const [position, setPosition] = useState<{\n containerId: TId;\n position: number;\n }>();\n\n useEffect(() => {\n return panelPositionEmitter.on('panelUpdate', (ev) => {\n if (ev.panelId === panelId)\n setPosition({ containerId: ev.containerId, position: ev.newPosition });\n });\n }, [panelId]);\n\n return position;\n}\n\nexport async function updatePanelPosition(\n panelId: TId,\n containerId: TId,\n newPosition: number,\n) {\n const result = await ApiaApi.post(\n makeApiaUrl({\n action: 'panelMove',\n pnlId: panelId,\n containerId,\n newPosition,\n }),\n );\n\n const hasUpdated = result?.data && !result.hasError && !result.hasMessages;\n\n if (hasUpdated)\n panelPositionEmitter.emit('panelUpdate', {\n panelId,\n containerId,\n newPosition,\n });\n\n return hasUpdated;\n}\n\nexport function useUpdatePanelPosition() {\n const { panelId } = usePanelIdentity();\n return async function updatePosition(containerId: TId, newPosition: number) {\n return updatePanelPosition(panelId, containerId, newPosition);\n };\n}\n"],"names":[],"mappings":";;;;;AAKA,MAAM,6BAA6B,YAMhC,CAAA;AAAC,CAAA;AAES,MAAA,oBAAA,GAAuB,IAAI,oBAAqB,GAAA;AAMtD,SAAS,gBAAmB,GAAA;AACjC,EAAM,MAAA,EAAE,OAAQ,EAAA,GAAI,gBAAiB,EAAA,CAAA;AAErC,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAI,QAG7B,EAAA,CAAA;AAEH,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,OAAO,oBAAqB,CAAA,EAAA,CAAG,aAAe,EAAA,CAAC,EAAO,KAAA;AACpD,MAAA,IAAI,GAAG,OAAY,KAAA,OAAA;AACjB,QAAA,WAAA,CAAY,EAAE,WAAa,EAAA,EAAA,CAAG,aAAa,QAAU,EAAA,EAAA,CAAG,aAAa,CAAA,CAAA;AAAA,KACxE,CAAA,CAAA;AAAA,GACH,EAAG,CAAC,OAAO,CAAC,CAAA,CAAA;AAEZ,EAAO,OAAA,QAAA,CAAA;AACT,CAAA;AAEsB,eAAA,mBAAA,CACpB,OACA,EAAA,WAAA,EACA,WACA,EAAA;AACA,EAAM,MAAA,MAAA,GAAS,MAAM,OAAQ,CAAA,IAAA;AAAA,IAC3B,WAAY,CAAA;AAAA,MACV,MAAQ,EAAA,WAAA;AAAA,MACR,KAAO,EAAA,OAAA;AAAA,MACP,WAAA;AAAA,MACA,WAAA;AAAA,KACD,CAAA;AAAA,GACH,CAAA;AAEA,EAAA,MAAM,aAAa,MAAQ,EAAA,IAAA,IAAQ,CAAC,MAAO,CAAA,QAAA,IAAY,CAAC,MAAO,CAAA,WAAA,CAAA;AAE/D,EAAI,IAAA,UAAA;AACF,IAAA,oBAAA,CAAqB,KAAK,aAAe,EAAA;AAAA,MACvC,OAAA;AAAA,MACA,WAAA;AAAA,MACA,WAAA;AAAA,KACD,CAAA,CAAA;AAEH,EAAO,OAAA,UAAA,CAAA;AACT;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isChild } from '@apia/util';
|
|
2
|
+
|
|
3
|
+
function dragleave(_ev, DragAndDrop2) {
|
|
4
|
+
const ev = _ev;
|
|
5
|
+
if (ev.relatedTarget === null || isChild(ev.relatedTarget, (current) => {
|
|
6
|
+
return current.parentElement === null && current === document.getRootNode() && current.dataset.splash === void 0;
|
|
7
|
+
})) {
|
|
8
|
+
const shadows = document.querySelectorAll(".apia_panel_falseDiv");
|
|
9
|
+
shadows.forEach((el) => el.remove());
|
|
10
|
+
DragAndDrop2.draggingPanel?.setAttribute("style", "");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { dragleave };
|
|
15
|
+
//# sourceMappingURL=Dragleave.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dragleave.js","sources":["../../../src/splash/events/Dragleave.ts"],"sourcesContent":["import { isChild } from '@apia/util';\nimport { DragAndDrop } from '../util/DragAndDrop';\n\nexport function dragleave(_ev: Event, DragAndDrop: DragAndDrop) {\n const ev = _ev as DragEvent;\n\n if (\n ev.relatedTarget === null ||\n isChild(ev.relatedTarget as HTMLElement, (current) => {\n return (\n current.parentElement === null &&\n current === document.getRootNode() &&\n current.dataset.splash === undefined\n );\n })\n ) {\n const shadows = document.querySelectorAll('.apia_panel_falseDiv');\n\n shadows.forEach((el) => el.remove());\n DragAndDrop.draggingPanel?.setAttribute('style', '');\n }\n}\n"],"names":["DragAndDrop"],"mappings":";;AAGgB,SAAA,SAAA,CAAU,KAAYA,YAA0B,EAAA;AAC9D,EAAA,MAAM,EAAK,GAAA,GAAA,CAAA;AAEX,EAAA,IACE,GAAG,aAAkB,KAAA,IAAA,IACrB,QAAQ,EAAG,CAAA,aAAA,EAA8B,CAAC,OAAY,KAAA;AACpD,IACE,OAAA,OAAA,CAAQ,kBAAkB,IAC1B,IAAA,OAAA,KAAY,SAAS,WAAY,EAAA,IACjC,OAAQ,CAAA,OAAA,CAAQ,MAAW,KAAA,KAAA,CAAA,CAAA;AAAA,GAE9B,CACD,EAAA;AACA,IAAM,MAAA,OAAA,GAAU,QAAS,CAAA,gBAAA,CAAiB,sBAAsB,CAAA,CAAA;AAEhE,IAAA,OAAA,CAAQ,OAAQ,CAAA,CAAC,EAAO,KAAA,EAAA,CAAG,QAAQ,CAAA,CAAA;AACnC,IAAAA,YAAY,CAAA,aAAA,EAAe,YAAa,CAAA,OAAA,EAAS,EAAE,CAAA,CAAA;AAAA,GACrD;AACF;;;;"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { isCursorInArea } from '../util/isCursorInArea.js';
|
|
2
|
+
import { getColumnAreas } from '../util/getColumnAreas.js';
|
|
3
|
+
|
|
4
|
+
function dragover(event, DragAndDrop2) {
|
|
5
|
+
const ev = event;
|
|
6
|
+
ev.preventDefault();
|
|
7
|
+
DragAndDrop2.timeout = -1;
|
|
8
|
+
if ((ev.clientX !== DragAndDrop2.dragoverPosition.x || ev.clientY !== DragAndDrop2.dragoverPosition.y) && DragAndDrop2.draggingPanelId !== "" && DragAndDrop2.shadowDiv) {
|
|
9
|
+
DragAndDrop2.clearTimeout();
|
|
10
|
+
DragAndDrop2.currentBottomPanel = DragAndDrop2.findBottomPanel(
|
|
11
|
+
ev.clientX,
|
|
12
|
+
ev.clientY + DragAndDrop2.currentScroll
|
|
13
|
+
);
|
|
14
|
+
DragAndDrop2.dragoverPosition.x = ev.clientX;
|
|
15
|
+
DragAndDrop2.dragoverPosition.y = ev.clientY;
|
|
16
|
+
const snapshotSection = DragAndDrop2.findBottomSection(
|
|
17
|
+
ev.clientX,
|
|
18
|
+
ev.clientY + DragAndDrop2.currentScroll
|
|
19
|
+
);
|
|
20
|
+
if (DragAndDrop2.shadowDivData && isCursorInArea({
|
|
21
|
+
cursorX: ev.clientX,
|
|
22
|
+
cursorY: ev.clientY + DragAndDrop2.currentScroll,
|
|
23
|
+
bottom: DragAndDrop2.shadowDivData?.panelBottom,
|
|
24
|
+
top: DragAndDrop2.shadowDivData?.panelTop,
|
|
25
|
+
left: DragAndDrop2.shadowDivData?.panelLeft,
|
|
26
|
+
right: DragAndDrop2.shadowDivData?.panelRight
|
|
27
|
+
})) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (DragAndDrop2.currentBottomPanel && snapshotSection) {
|
|
31
|
+
const bottomPanel = DragAndDrop2.splash.querySelector(
|
|
32
|
+
`[data-panel][data-id='${DragAndDrop2.currentBottomPanel.id}']`
|
|
33
|
+
);
|
|
34
|
+
const draggingPanel = DragAndDrop2.splash.querySelector(
|
|
35
|
+
`[data-panel][data-id='${DragAndDrop2.draggingPanelId}']`
|
|
36
|
+
);
|
|
37
|
+
const bottomSection = DragAndDrop2.splash.querySelector(
|
|
38
|
+
`[data-locationid='${snapshotSection.sectionId}']`
|
|
39
|
+
);
|
|
40
|
+
if (bottomSection) {
|
|
41
|
+
if (isCursorInArea({
|
|
42
|
+
cursorX: ev.clientX,
|
|
43
|
+
cursorY: ev.clientY + DragAndDrop2.currentScroll,
|
|
44
|
+
...getColumnAreas({
|
|
45
|
+
...DragAndDrop2.currentBottomPanel,
|
|
46
|
+
panelLeft: bottomSection?.getBoundingClientRect().left ?? 0,
|
|
47
|
+
panelRight: bottomSection?.getBoundingClientRect().right ?? 0
|
|
48
|
+
}).top
|
|
49
|
+
})) {
|
|
50
|
+
if (draggingPanel) {
|
|
51
|
+
draggingPanel.setAttribute("style", "display: none; height: 0;");
|
|
52
|
+
}
|
|
53
|
+
if (bottomPanel && snapshotSection) {
|
|
54
|
+
if (bottomSection) {
|
|
55
|
+
DragAndDrop2.shadowDiv.setAttribute("style", "opacity: 50%;");
|
|
56
|
+
DragAndDrop2.debounceBefore(
|
|
57
|
+
bottomPanel,
|
|
58
|
+
DragAndDrop2.shadowDiv,
|
|
59
|
+
bottomSection
|
|
60
|
+
);
|
|
61
|
+
DragAndDrop2.snapshot();
|
|
62
|
+
DragAndDrop2.clearTimeout();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} else if (isCursorInArea({
|
|
66
|
+
cursorX: ev.clientX,
|
|
67
|
+
cursorY: ev.clientY + DragAndDrop2.currentScroll,
|
|
68
|
+
...getColumnAreas({
|
|
69
|
+
...DragAndDrop2.currentBottomPanel,
|
|
70
|
+
panelLeft: bottomSection?.getBoundingClientRect().left ?? 0,
|
|
71
|
+
panelRight: bottomSection?.getBoundingClientRect().right ?? 0
|
|
72
|
+
}).bottom
|
|
73
|
+
})) {
|
|
74
|
+
const bottomPanel2 = DragAndDrop2.splash.querySelector(
|
|
75
|
+
`[data-panel][data-id='${DragAndDrop2.currentBottomPanel.id}']`
|
|
76
|
+
);
|
|
77
|
+
const draggingPanel2 = DragAndDrop2.splash.querySelector(
|
|
78
|
+
`[data-panel][data-id='${DragAndDrop2.draggingPanelId}']`
|
|
79
|
+
);
|
|
80
|
+
if (draggingPanel2) {
|
|
81
|
+
draggingPanel2.setAttribute("style", "display: none;");
|
|
82
|
+
}
|
|
83
|
+
if (bottomPanel2 && snapshotSection) {
|
|
84
|
+
const bottomSection2 = DragAndDrop2.splash.querySelector(
|
|
85
|
+
`[data-locationid='${snapshotSection.sectionId}']`
|
|
86
|
+
);
|
|
87
|
+
if (bottomSection2) {
|
|
88
|
+
DragAndDrop2.shadowDiv.setAttribute("style", "opacity: 50%;");
|
|
89
|
+
DragAndDrop2.debounceAfter(DragAndDrop2.shadowDiv, bottomPanel2);
|
|
90
|
+
DragAndDrop2.snapshot();
|
|
91
|
+
DragAndDrop2.clearTimeout();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} else if (!DragAndDrop2.currentBottomPanel && snapshotSection) {
|
|
97
|
+
const bottomSection = DragAndDrop2.splash.querySelector(
|
|
98
|
+
`[data-locationid='${snapshotSection.sectionId}']`
|
|
99
|
+
);
|
|
100
|
+
if (bottomSection) {
|
|
101
|
+
const draggingPanel = DragAndDrop2.splash.querySelector(
|
|
102
|
+
`[data-panel][data-id='${DragAndDrop2.draggingPanelId}']`
|
|
103
|
+
);
|
|
104
|
+
if (draggingPanel) {
|
|
105
|
+
draggingPanel.setAttribute("style", "display: none;");
|
|
106
|
+
}
|
|
107
|
+
DragAndDrop2.shadowDiv.setAttribute("style", "opacity: 50%;");
|
|
108
|
+
DragAndDrop2.debounceAppend(
|
|
109
|
+
bottomSection,
|
|
110
|
+
DragAndDrop2.shadowDiv
|
|
111
|
+
);
|
|
112
|
+
DragAndDrop2.snapshot();
|
|
113
|
+
DragAndDrop2.clearTimeout();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { dragover };
|
|
120
|
+
//# sourceMappingURL=Dragover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dragover.js","sources":["../../../src/splash/events/Dragover.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport { isCursorInArea } from '../util/isCursorInArea';\nimport { getColumnAreas } from '../util/getColumnAreas';\nimport { DragAndDrop } from '../util/DragAndDrop';\n\nexport function dragover(event: Event, DragAndDrop: DragAndDrop) {\n const ev = event as DragEvent;\n ev.preventDefault();\n\n DragAndDrop.timeout = -1;\n if (\n (ev.clientX !== DragAndDrop.dragoverPosition.x ||\n ev.clientY !== DragAndDrop.dragoverPosition.y) &&\n DragAndDrop.draggingPanelId !== '' &&\n DragAndDrop.shadowDiv\n ) {\n DragAndDrop.clearTimeout();\n DragAndDrop.currentBottomPanel = DragAndDrop.findBottomPanel(\n ev.clientX,\n ev.clientY + DragAndDrop.currentScroll,\n );\n\n DragAndDrop.dragoverPosition.x = ev.clientX;\n DragAndDrop.dragoverPosition.y = ev.clientY;\n\n const snapshotSection = DragAndDrop.findBottomSection(\n ev.clientX,\n ev.clientY + DragAndDrop.currentScroll,\n );\n\n if (\n DragAndDrop.shadowDivData &&\n isCursorInArea({\n cursorX: ev.clientX,\n cursorY: ev.clientY + DragAndDrop.currentScroll,\n bottom: DragAndDrop.shadowDivData?.panelBottom,\n top: DragAndDrop.shadowDivData?.panelTop,\n left: DragAndDrop.shadowDivData?.panelLeft,\n right: DragAndDrop.shadowDivData?.panelRight,\n })\n ) {\n return;\n }\n\n if (DragAndDrop.currentBottomPanel && snapshotSection) {\n const bottomPanel = DragAndDrop.splash.querySelector(\n `[data-panel][data-id='${DragAndDrop.currentBottomPanel.id}']`,\n );\n const draggingPanel = DragAndDrop.splash.querySelector(\n `[data-panel][data-id='${DragAndDrop.draggingPanelId}']`,\n );\n const bottomSection = DragAndDrop.splash.querySelector(\n `[data-locationid='${snapshotSection.sectionId}']`,\n );\n\n if (bottomSection) {\n if (\n isCursorInArea({\n cursorX: ev.clientX,\n cursorY: ev.clientY + DragAndDrop.currentScroll,\n ...getColumnAreas({\n ...DragAndDrop.currentBottomPanel,\n panelLeft: bottomSection?.getBoundingClientRect().left ?? 0,\n panelRight: bottomSection?.getBoundingClientRect().right ?? 0,\n }).top,\n })\n ) {\n if (draggingPanel) {\n draggingPanel.setAttribute('style', 'display: none; height: 0;');\n }\n if (bottomPanel && snapshotSection) {\n if (bottomSection) {\n DragAndDrop.shadowDiv.setAttribute('style', 'opacity: 50%;');\n DragAndDrop.debounceBefore(\n bottomPanel,\n DragAndDrop.shadowDiv,\n bottomSection as HTMLElement,\n );\n DragAndDrop.snapshot();\n DragAndDrop.clearTimeout();\n }\n }\n } else if (\n isCursorInArea({\n cursorX: ev.clientX,\n cursorY: ev.clientY + DragAndDrop.currentScroll,\n ...getColumnAreas({\n ...DragAndDrop.currentBottomPanel,\n panelLeft: bottomSection?.getBoundingClientRect().left ?? 0,\n panelRight: bottomSection?.getBoundingClientRect().right ?? 0,\n }).bottom,\n })\n ) {\n const bottomPanel = DragAndDrop.splash.querySelector(\n `[data-panel][data-id='${DragAndDrop.currentBottomPanel.id}']`,\n );\n const draggingPanel = DragAndDrop.splash.querySelector(\n `[data-panel][data-id='${DragAndDrop.draggingPanelId}']`,\n );\n if (draggingPanel) {\n draggingPanel.setAttribute('style', 'display: none;');\n }\n if (bottomPanel && snapshotSection) {\n const bottomSection = DragAndDrop.splash.querySelector(\n `[data-locationid='${snapshotSection.sectionId}']`,\n );\n if (bottomSection) {\n DragAndDrop.shadowDiv.setAttribute('style', 'opacity: 50%;');\n DragAndDrop.debounceAfter(DragAndDrop.shadowDiv, bottomPanel);\n DragAndDrop.snapshot();\n DragAndDrop.clearTimeout();\n }\n }\n }\n }\n } else if (!DragAndDrop.currentBottomPanel && snapshotSection) {\n const bottomSection = DragAndDrop.splash.querySelector(\n `[data-locationid='${snapshotSection.sectionId}']`,\n );\n if (bottomSection) {\n const draggingPanel = DragAndDrop.splash.querySelector(\n `[data-panel][data-id='${DragAndDrop.draggingPanelId}']`,\n );\n if (draggingPanel) {\n draggingPanel.setAttribute('style', 'display: none;');\n }\n DragAndDrop.shadowDiv.setAttribute('style', 'opacity: 50%;');\n DragAndDrop.debounceAppend(\n bottomSection as HTMLElement,\n DragAndDrop.shadowDiv,\n );\n DragAndDrop.snapshot();\n DragAndDrop.clearTimeout();\n }\n }\n }\n}\n"],"names":["DragAndDrop","bottomPanel","draggingPanel","bottomSection"],"mappings":";;;AAKgB,SAAA,QAAA,CAAS,OAAcA,YAA0B,EAAA;AAC/D,EAAA,MAAM,EAAK,GAAA,KAAA,CAAA;AACX,EAAA,EAAA,CAAG,cAAe,EAAA,CAAA;AAElB,EAAAA,aAAY,OAAU,GAAA,CAAA,CAAA,CAAA;AACtB,EAAA,IAAA,CACG,EAAG,CAAA,OAAA,KAAYA,YAAY,CAAA,gBAAA,CAAiB,KAC3C,EAAG,CAAA,OAAA,KAAYA,YAAY,CAAA,gBAAA,CAAiB,CAC9CA,KAAAA,YAAAA,CAAY,eAAoB,KAAA,EAAA,IAChCA,aAAY,SACZ,EAAA;AACA,IAAAA,aAAY,YAAa,EAAA,CAAA;AACzB,IAAAA,YAAAA,CAAY,qBAAqBA,YAAY,CAAA,eAAA;AAAA,MAC3C,EAAG,CAAA,OAAA;AAAA,MACH,EAAA,CAAG,UAAUA,YAAY,CAAA,aAAA;AAAA,KAC3B,CAAA;AAEA,IAAAA,YAAAA,CAAY,gBAAiB,CAAA,CAAA,GAAI,EAAG,CAAA,OAAA,CAAA;AACpC,IAAAA,YAAAA,CAAY,gBAAiB,CAAA,CAAA,GAAI,EAAG,CAAA,OAAA,CAAA;AAEpC,IAAA,MAAM,kBAAkBA,YAAY,CAAA,iBAAA;AAAA,MAClC,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AU,YAAa,CAAA,OAAA,EAAS,eAAe,CAAA,CAAA;AAC3D,QAAAA,YAAY,CAAA,cAAA;AAAA,UACV,aAAA;AAAA,UACAA,YAAY,CAAA,SAAA;AAAA,SACd,CAAA;AACA,QAAAA,aAAY,QAAS,EAAA,CAAA;AACrB,QAAAA,aAAY,YAAa,EAAA,CAAA;AAAA,OAC3B;AAAA,KACF;AAAA,GACF;AACF;;;;"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { getSpecificParent } from '@apia/util';
|
|
2
|
+
|
|
3
|
+
function dragstart(ev, el, DragAndDrop2) {
|
|
4
|
+
if (!(el instanceof HTMLElement))
|
|
5
|
+
return;
|
|
6
|
+
DragAndDrop2.drawMinimap();
|
|
7
|
+
DragAndDrop2.sectionData = [];
|
|
8
|
+
const targetPanel = getSpecificParent(
|
|
9
|
+
ev.target,
|
|
10
|
+
(current) => !!current.dataset?.id && !!current.dataset?.panel
|
|
11
|
+
);
|
|
12
|
+
ev?.dataTransfer?.setData("text", targetPanel?.dataset.id);
|
|
13
|
+
if (targetPanel) {
|
|
14
|
+
DragAndDrop2.placeholderImage = targetPanel.cloneNode(true);
|
|
15
|
+
DragAndDrop2.placeholderImage.style.position = "fixed";
|
|
16
|
+
DragAndDrop2.placeholderImage.style.top = "-10000000.45px";
|
|
17
|
+
const children = DragAndDrop2.placeholderImage.querySelectorAll("*");
|
|
18
|
+
children.forEach((current) => current.style.overflow = "hidden");
|
|
19
|
+
document.body.append(DragAndDrop2.placeholderImage);
|
|
20
|
+
ev?.dataTransfer?.setDragImage(DragAndDrop2.placeholderImage, 0, 0);
|
|
21
|
+
}
|
|
22
|
+
if (ev.dataTransfer) {
|
|
23
|
+
ev.dataTransfer.effectAllowed = "move";
|
|
24
|
+
}
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
const targetSection = getSpecificParent(
|
|
27
|
+
ev.target,
|
|
28
|
+
(current) => !!current.dataset?.locationid
|
|
29
|
+
);
|
|
30
|
+
const sections = DragAndDrop2.body?.querySelectorAll("[data-locationid]");
|
|
31
|
+
const emptySectionsId = [];
|
|
32
|
+
sections?.forEach((sec) => {
|
|
33
|
+
if (sec.children.length === 0) {
|
|
34
|
+
emptySectionsId.push(sec.dataset.locationid ?? "");
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
emptySectionsId.forEach((emptySecId) => {
|
|
38
|
+
const section = DragAndDrop2.body?.querySelector(
|
|
39
|
+
`[data-locationid="${emptySecId}"]`
|
|
40
|
+
);
|
|
41
|
+
if (section) {
|
|
42
|
+
section.setAttribute("style", "padding: 10px; border:2px dashed #ccc");
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
DragAndDrop2.snapshot();
|
|
46
|
+
if (targetPanel) {
|
|
47
|
+
DragAndDrop2.draggingPanelSectionId = targetSection?.dataset.locationid ?? "";
|
|
48
|
+
DragAndDrop2.draggingPanelId = targetPanel.dataset.id;
|
|
49
|
+
DragAndDrop2.draggingPanel = targetPanel;
|
|
50
|
+
}
|
|
51
|
+
if (DragAndDrop2.draggingPanelId === "") {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const falseDiv = targetPanel?.cloneNode(true);
|
|
55
|
+
falseDiv.style.opacity = `50%`;
|
|
56
|
+
falseDiv.style.width = `100%`;
|
|
57
|
+
falseDiv.style.height = `auto`;
|
|
58
|
+
falseDiv.style.backgroundColor = `rgba(0,0,0,0.1)`;
|
|
59
|
+
falseDiv.className = "apia_panel_falseDiv";
|
|
60
|
+
DragAndDrop2.shadowDiv = falseDiv;
|
|
61
|
+
}, 0);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { dragstart };
|
|
65
|
+
//# sourceMappingURL=Dragstart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dragstart.js","sources":["../../../src/splash/events/Dragstart.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport { getSpecificParent } from '@apia/util';\nimport { DragAndDrop } from '../util/DragAndDrop';\n\nexport function dragstart(\n ev: DragEvent,\n el: Element,\n DragAndDrop: DragAndDrop,\n) {\n if (!(el instanceof HTMLElement)) return;\n DragAndDrop.drawMinimap();\n DragAndDrop.sectionData = [];\n\n const targetPanel = getSpecificParent(\n ev.target as HTMLElement,\n (current) => !!current.dataset?.id && !!current.dataset?.panel,\n );\n\n ev?.dataTransfer?.setData('text', targetPanel?.dataset.id as string);\n if (targetPanel) {\n DragAndDrop.placeholderImage = targetPanel.cloneNode(true) as HTMLElement;\n DragAndDrop.placeholderImage.style.position = 'fixed';\n DragAndDrop.placeholderImage.style.top = '-10000000.45px';\n\n const children =\n DragAndDrop.placeholderImage.querySelectorAll<HTMLElement>('*');\n children.forEach((current) => (current.style.overflow = 'hidden'));\n document.body.append(DragAndDrop.placeholderImage);\n ev?.dataTransfer?.setDragImage(DragAndDrop.placeholderImage, 0, 0);\n }\n if (ev.dataTransfer) {\n // eslint-disable-next-line no-param-reassign\n ev.dataTransfer.effectAllowed = 'move';\n }\n\n setTimeout(() => {\n const targetSection = getSpecificParent(\n ev.target as HTMLElement,\n (current) => !!current.dataset?.locationid,\n );\n\n const sections = DragAndDrop.body?.querySelectorAll('[data-locationid]');\n\n const emptySectionsId: string[] = [];\n\n sections?.forEach((sec) => {\n if (sec.children.length === 0) {\n emptySectionsId.push((sec as HTMLElement).dataset.locationid ?? '');\n }\n });\n\n emptySectionsId.forEach((emptySecId) => {\n const section = DragAndDrop.body?.querySelector(\n `[data-locationid=\"${emptySecId}\"]`,\n );\n if (section) {\n section.setAttribute('style', 'padding: 10px; border:2px dashed #ccc');\n }\n });\n\n DragAndDrop.snapshot();\n\n if (targetPanel) {\n DragAndDrop.draggingPanelSectionId =\n targetSection?.dataset.locationid ?? '';\n DragAndDrop.draggingPanelId = targetPanel.dataset.id as string;\n DragAndDrop.draggingPanel = targetPanel;\n }\n if (DragAndDrop.draggingPanelId === '') {\n return;\n }\n const falseDiv = targetPanel?.cloneNode(true) as HTMLDivElement;\n falseDiv.style.opacity = `50%`;\n falseDiv.style.width = `100%`;\n falseDiv.style.height = `auto`;\n falseDiv.style.backgroundColor = `rgba(0,0,0,0.1)`;\n falseDiv.className = 'apia_panel_falseDiv';\n DragAndDrop.shadowDiv = falseDiv;\n }, 0);\n}\n"],"names":["DragAndDrop"],"mappings":";;AAIgB,SAAA,SAAA,CACd,EACA,EAAA,EAAA,EACAA,YACA,EAAA;AACA,EAAA,IAAI,EAAE,EAAc,YAAA,WAAA,CAAA;AAAc,IAAA,OAAA;AAClC,EAAAA,aAAY,WAAY,EAAA,CAAA;AACxB,EAAAA,YAAAA,CAAY,cAAc,EAAC,CAAA;AAE3B,EAAA,MAAM,WAAc,GAAA,iBAAA;AAAA,IAClB,EAAG,CAAA,MAAA;AAAA,IACH,CAAC,OAAY,KAAA,CAAC,CAAC,OAAA,CAAQ,SAAS,EAAM,IAAA,CAAC,CAAC,OAAA,CAAQ,OAAS,EAAA,KAAA;AAAA,GAC3D,CAAA;AAEA,EAAA,EAAA,EAAI,YAAc,EAAA,OAAA,CAAQ,MAAQ,EAAA,WAAA,EAAa,QAAQ,EAAY,CAAA,CAAA;AACnE,EAAA,IAAI,WAAa,EAAA;AACf,IAAAA,YAAY,CAAA,gBAAA,GAAmB,WAAY,CAAA,SAAA,CAAU,IAAI,CAAA,CAAA;AACzD,IAAAA,YAAAA,CAAY,gBAAiB,CAAA,KAAA,CAAM,QAAW,GAAA,OAAA,CAAA;AAC9C,IAAAA,YAAAA,CAAY,gBAAiB,CAAA,KAAA,CAAM,GAAM,GAAA,gBAAA,CAAA;AAEzC,IAAA,MAAM,QACJA,GAAAA,YAAAA,CAAY,gBAAiB,CAAA,gBAAA,CAA8B,GAAG,CAAA,CAAA;AAChE,IAAA,QAAA,CAAS,QAAQ,CAAC,OAAA,KAAa,OAAQ,CAAA,KAAA,CAAM,WAAW,QAAS,CAAA,CAAA;AACjE,IAAS,QAAA,CAAA,IAAA,CAAK,MAAOA,CAAAA,YAAAA,CAAY,gB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c,IAAA,EAAA,CAAA;AACvC,MAAAA,YAAAA,CAAY,eAAkB,GAAA,WAAA,CAAY,OAAQ,CAAA,EAAA,CAAA;AAClD,MAAAA,aAAY,aAAgB,GAAA,WAAA,CAAA;AAAA,KAC9B;AACA,IAAIA,IAAAA,YAAAA,CAAY,oBAAoB,EAAI,EAAA;AACtC,MAAA,OAAA;AAAA,KACF;AACA,IAAM,MAAA,QAAA,GAAW,WAAa,EAAA,SAAA,CAAU,IAAI,CAAA,CAAA;AAC5C,IAAA,QAAA,CAAS,MAAM,OAAU,GAAA,CAAA,GAAA,CAAA,CAAA;AACzB,IAAA,QAAA,CAAS,MAAM,KAAQ,GAAA,CAAA,IAAA,CAAA,CAAA;AACvB,IAAA,QAAA,CAAS,MAAM,MAAS,GAAA,CAAA,IAAA,CAAA,CAAA;AACxB,IAAA,QAAA,CAAS,MAAM,eAAkB,GAAA,CAAA,eAAA,CAAA,CAAA;AACjC,IAAA,QAAA,CAAS,SAAY,GAAA,qBAAA,CAAA;AACrB,IAAAA,aAAY,SAAY,GAAA,QAAA,CAAA;AAAA,KACvB,CAAC,CAAA,CAAA;AACN;;;;"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { getSpecificParent } from '@apia/util';
|
|
2
|
+
import { updatePanelPosition } from '../../position/usePanelPosition.js';
|
|
3
|
+
|
|
4
|
+
function Drop(event, DragAndDrop2) {
|
|
5
|
+
if (DragAndDrop2.body) {
|
|
6
|
+
const ev = event;
|
|
7
|
+
const data = ev?.dataTransfer?.getData("text");
|
|
8
|
+
const sections = DragAndDrop2.body?.querySelectorAll("[data-locationid]");
|
|
9
|
+
sections.forEach((sec) => {
|
|
10
|
+
sec.setAttribute("style", "");
|
|
11
|
+
});
|
|
12
|
+
const draggingPanel = DragAndDrop2.body.querySelector(
|
|
13
|
+
`[data-panel][data-id="${DragAndDrop2.draggingPanelId}"]:not(.apia_panel_falseDiv)`
|
|
14
|
+
);
|
|
15
|
+
if (draggingPanel) {
|
|
16
|
+
draggingPanel.setAttribute("style", "");
|
|
17
|
+
}
|
|
18
|
+
const falseDiv = document.querySelector(".apia_panel_falseDiv");
|
|
19
|
+
if (data) {
|
|
20
|
+
const child = document.querySelector(
|
|
21
|
+
`[data-panel][data-id="${data}"]:not(.apia_panel_falseDiv)`
|
|
22
|
+
);
|
|
23
|
+
sections.forEach((sec) => {
|
|
24
|
+
if (sec.children.length === 1) {
|
|
25
|
+
sec.setAttribute("style", "");
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
if (falseDiv) {
|
|
29
|
+
const newSection = getSpecificParent(
|
|
30
|
+
falseDiv,
|
|
31
|
+
(current) => !!current.dataset.locationid
|
|
32
|
+
);
|
|
33
|
+
if (newSection) {
|
|
34
|
+
const panelsArray = Array.from(newSection.children);
|
|
35
|
+
const childId = child.dataset.id;
|
|
36
|
+
if (childId) {
|
|
37
|
+
const index = panelsArray.findIndex(
|
|
38
|
+
(panel) => panel.dataset.id === childId
|
|
39
|
+
);
|
|
40
|
+
if (typeof index === "number" && newSection.dataset.locationid) {
|
|
41
|
+
void updatePanelPosition(
|
|
42
|
+
childId,
|
|
43
|
+
newSection.dataset.locationid,
|
|
44
|
+
index + 1
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
falseDiv.replaceWith(child);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
DragAndDrop2.draggingPanelId = "";
|
|
53
|
+
DragAndDrop2.panelData = [];
|
|
54
|
+
DragAndDrop2.drawMinimap();
|
|
55
|
+
DragAndDrop2.removePlaceholder();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { Drop };
|
|
60
|
+
//# sourceMappingURL=Drop.js.map
|