@gravity-ui/dashkit 9.1.4 → 9.2.1-beta

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 (78) hide show
  1. package/README.md +1 -1
  2. package/build/cjs/components/DashKit/DashKit.d.ts +1 -1
  3. package/build/cjs/components/GridLayout/GridLayout.d.ts +51 -65
  4. package/build/cjs/components/GridLayout/GridLayout.js +63 -20
  5. package/build/cjs/components/GridLayout/GridLayout.js.map +1 -1
  6. package/build/cjs/components/GridLayout/types.d.ts +60 -0
  7. package/build/cjs/components/GridLayout/types.js +3 -0
  8. package/build/cjs/components/GridLayout/types.js.map +1 -0
  9. package/build/cjs/components/MobileLayout/MobileLayout.d.ts +4 -4
  10. package/build/cjs/components/MobileLayout/MobileLayout.js +4 -4
  11. package/build/cjs/components/MobileLayout/MobileLayout.js.map +1 -1
  12. package/build/cjs/components/MobileLayout/helpers.d.ts +1 -1
  13. package/build/cjs/components/MobileLayout/helpers.js +2 -2
  14. package/build/cjs/components/MobileLayout/helpers.js.map +1 -1
  15. package/build/cjs/context/DashKitContext.d.ts +15 -6
  16. package/build/cjs/context/DashKitContext.js.map +1 -1
  17. package/build/cjs/hocs/withContext.js +7 -3
  18. package/build/cjs/hocs/withContext.js.map +1 -1
  19. package/build/cjs/hooks/useCalcLayout.d.ts +2 -13
  20. package/build/cjs/hooks/useCalcLayout.js +12 -4
  21. package/build/cjs/hooks/useCalcLayout.js.map +1 -1
  22. package/build/cjs/shared/modules/__tests__/global-items.test.d.ts +1 -0
  23. package/build/cjs/shared/modules/__tests__/global-items.test.js +372 -0
  24. package/build/cjs/shared/modules/__tests__/global-items.test.js.map +1 -0
  25. package/build/cjs/shared/modules/helpers.d.ts +1 -0
  26. package/build/cjs/shared/modules/helpers.js +10 -2
  27. package/build/cjs/shared/modules/helpers.js.map +1 -1
  28. package/build/cjs/shared/modules/state-and-params.js +7 -2
  29. package/build/cjs/shared/modules/state-and-params.js.map +1 -1
  30. package/build/cjs/shared/modules/uniq-id.js +1 -1
  31. package/build/cjs/shared/modules/uniq-id.js.map +1 -1
  32. package/build/cjs/shared/types/config.d.ts +1 -0
  33. package/build/cjs/shared/types/config.js.map +1 -1
  34. package/build/cjs/typings/config.d.ts +3 -2
  35. package/build/cjs/typings/config.js.map +1 -1
  36. package/build/cjs/typings/plugin.d.ts +1 -0
  37. package/build/cjs/typings/plugin.js.map +1 -1
  38. package/build/cjs/utils/update-manager.js +66 -36
  39. package/build/cjs/utils/update-manager.js.map +1 -1
  40. package/build/esm/components/DashKit/DashKit.d.ts +1 -1
  41. package/build/esm/components/GridLayout/GridLayout.d.ts +51 -65
  42. package/build/esm/components/GridLayout/GridLayout.js +63 -20
  43. package/build/esm/components/GridLayout/GridLayout.js.map +1 -1
  44. package/build/esm/components/GridLayout/types.d.ts +60 -0
  45. package/build/esm/components/GridLayout/types.js +2 -0
  46. package/build/esm/components/GridLayout/types.js.map +1 -0
  47. package/build/esm/components/MobileLayout/MobileLayout.d.ts +4 -4
  48. package/build/esm/components/MobileLayout/MobileLayout.js +4 -4
  49. package/build/esm/components/MobileLayout/MobileLayout.js.map +1 -1
  50. package/build/esm/components/MobileLayout/helpers.d.ts +1 -1
  51. package/build/esm/components/MobileLayout/helpers.js +2 -2
  52. package/build/esm/components/MobileLayout/helpers.js.map +1 -1
  53. package/build/esm/context/DashKitContext.d.ts +15 -6
  54. package/build/esm/context/DashKitContext.js.map +1 -1
  55. package/build/esm/hocs/withContext.js +8 -4
  56. package/build/esm/hocs/withContext.js.map +1 -1
  57. package/build/esm/hooks/useCalcLayout.d.ts +2 -13
  58. package/build/esm/hooks/useCalcLayout.js +12 -4
  59. package/build/esm/hooks/useCalcLayout.js.map +1 -1
  60. package/build/esm/shared/modules/__tests__/global-items.test.d.ts +1 -0
  61. package/build/esm/shared/modules/__tests__/global-items.test.js +370 -0
  62. package/build/esm/shared/modules/__tests__/global-items.test.js.map +1 -0
  63. package/build/esm/shared/modules/helpers.d.ts +1 -0
  64. package/build/esm/shared/modules/helpers.js +9 -2
  65. package/build/esm/shared/modules/helpers.js.map +1 -1
  66. package/build/esm/shared/modules/state-and-params.js +8 -3
  67. package/build/esm/shared/modules/state-and-params.js.map +1 -1
  68. package/build/esm/shared/modules/uniq-id.js +2 -2
  69. package/build/esm/shared/modules/uniq-id.js.map +1 -1
  70. package/build/esm/shared/types/config.d.ts +1 -0
  71. package/build/esm/shared/types/config.js.map +1 -1
  72. package/build/esm/typings/config.d.ts +3 -2
  73. package/build/esm/typings/config.js.map +1 -1
  74. package/build/esm/typings/plugin.d.ts +1 -0
  75. package/build/esm/typings/plugin.js.map +1 -1
  76. package/build/esm/utils/update-manager.js +67 -37
  77. package/build/esm/utils/update-manager.js.map +1 -1
  78. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"state-and-params.js","sourceRoot":"../../../../src","sources":["shared/modules/state-and-params.ts"],"names":[],"mappings":";;AAoKA,wCA2FC;AAED,sCAWC;AAED,wDA4CC;;AA1TD,wEAAqC;AAErC,qDAAsC;AAgBtC,0CAamB;AAanB,MAAM,2BAA2B,GAAG,CAAC,EACjC,mBAAmB,EACnB,YAAY,EACZ,IAAI,GAKP,EAAE,EAAE;IACD,MAAM,QAAQ,GAAG,YAAY,IAAI,IAAI,CAAC,EAAE,CAAC;IAEzC,IAAI,CAAC,CAAC,QAAQ,IAAI,mBAAmB,CAAC,EAAE,CAAC;QACrC,OAAO,EAAE,CAAC;IACd,CAAC;IAED,MAAM,cAAc,GAAG,mBAA8C,CAAC;IACtE,MAAM,UAAU,GAAG,YAAY;QAC3B,CAAC,CAAC,MAAM,CAAC,MAAM,CACT,EAAE,EACD,cAAc,CAAC,QAAQ,CAAC,CAAC,MAAuC,CAAC,IAAI,CAAC,EAAE,CAAC,CAC7E;QACH,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC,MAAsB,CAAC,CAAC;IAEzE,OAAO,UAAU,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AAM,IAAI,GAAG,EAAwB,CAAC;QACtC,IAAI,EAAE,IAAI,MAAM,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;QAC7B,CAAC;QACD,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC;YACd,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;QAC3B,CAAC;QACD,uCACO,GAAG,KACN,CAAC,EAAE,CAAC,EAAE,IAAI,IACZ;IACN,CAAC,EACD,EAAE,CACL,CAAC;IACF,MAAM,OAAO,GAAG,IAAA,2BAAiB,EAAC,mBAAmB,CAAC,CAAC;IACvD,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;QAChB,OAAO,MAAM,CAAC;IAClB,CAAC;IACD,MAAM,IAAI,GAAG;QACT,CAAC,oBAAQ,CAAC,EAAE,mBAAmB,CAAC,oBAAQ,CAA2B;KACtE,CAAC;IACF,uCACO,IAAI,GACJ,MAAM,EACX;AACN,CAAC","sourcesContent":["import groupBy from 'lodash/groupBy';\n\nimport {META_KEY} from '../constants';\nimport {\n Config,\n ConfigItem,\n ConfigItemDataWithTabs,\n ConfigItemGroup,\n GlobalParams,\n ItemState,\n ItemStateAndParams,\n ItemsStateAndParams,\n ItemsStateAndParamsBase,\n PluginBase,\n StateAndParamsMetaData,\n StringParams,\n} from '../types';\n\nimport {\n FormedQueueData,\n formQueueData,\n getCurrentVersion,\n getMapItemsIgnores,\n hasActionParam,\n isItemWithGroup,\n isItemWithTabs,\n mergeParamsWithAliases,\n pickActionParamsFromParams,\n pickExceptActionParamsFromParams,\n prerenderItems,\n resolveItemInnerId,\n} from './helpers';\n\nexport interface GetItemsParamsArg {\n defaultGlobalParams: GlobalParams;\n globalParams: GlobalParams;\n config: Config;\n itemsStateAndParams: ItemsStateAndParams;\n plugins: PluginBase[];\n useStateAsInitial?: boolean;\n}\n\ntype GetItemsParamsReturn = Record<string, StringParams | Record<string, StringParams>>;\n\nconst getParamsFromStateAndParams = ({\n itemsStateAndParams,\n parentItemId,\n item,\n}: {\n item: ConfigItem | ConfigItemGroup;\n itemsStateAndParams: ItemsStateAndParams;\n parentItemId?: string;\n}) => {\n const widgetId = parentItemId || item.id;\n\n if (!(widgetId in itemsStateAndParams)) {\n return {};\n }\n\n const stateAndParams = itemsStateAndParams as ItemsStateAndParamsBase;\n const itemParams = parentItemId\n ? Object.assign(\n {},\n (stateAndParams[widgetId].params as Record<string, StringParams>)[item.id],\n )\n : Object.assign({}, stateAndParams[widgetId].params as StringParams);\n\n return itemParams;\n};\n\nfunction getItemParams({\n item,\n itemsStateAndParams,\n mapItemsIgnores,\n itemsWithDefaultsByNamespace,\n getMergedParams,\n defaultGlobalParams,\n globalParams,\n isFirstVersion,\n queueData,\n parentItemId,\n useStateAsInitial,\n}: {\n item: ConfigItem | ConfigItemGroup;\n itemsStateAndParams: ItemsStateAndParams;\n mapItemsIgnores: Record<string, string[]>;\n itemsWithDefaultsByNamespace: Record<string, (ConfigItem | ConfigItemGroup)[]>;\n getMergedParams: (params: StringParams, actionParams?: StringParams) => StringParams;\n defaultGlobalParams: StringParams;\n globalParams: GlobalParams;\n isFirstVersion: boolean;\n queueData: FormedQueueData[];\n parentItemId?: string;\n useStateAsInitial?: boolean;\n}) {\n const {id, namespace} = item;\n\n let defaultWidgetParams: StringParams | Record<string, StringParams> = {};\n if (isItemWithTabs(item)) {\n const currentWidgetTabId = resolveItemInnerId({item, itemsStateAndParams});\n const itemTabs: ConfigItemDataWithTabs['tabs'] = item.data.tabs;\n defaultWidgetParams =\n itemTabs.find((tabItem) => tabItem?.id === currentWidgetTabId)?.params || {};\n } else {\n defaultWidgetParams = item.defaults || {};\n }\n\n const itemIgnores = mapItemsIgnores[id];\n\n const affectingItemsWithDefaults = itemsWithDefaultsByNamespace[namespace].filter(\n (itemWithDefaults) => !itemIgnores.includes(itemWithDefaults.id),\n );\n\n let itemParams: StringParams = Object.assign(\n {},\n getMergedParams(defaultGlobalParams),\n // default parameters to begin with\n affectingItemsWithDefaults.reduceRight((defaultParams: StringParams, itemWithDefaults) => {\n return {\n ...defaultParams,\n ...getMergedParams(itemWithDefaults.defaults || {}),\n };\n }, {}),\n getMergedParams(globalParams),\n useStateAsInitial\n ? getParamsFromStateAndParams({parentItemId, item, itemsStateAndParams})\n : {},\n );\n\n if (isFirstVersion) {\n itemParams = Object.assign(\n itemParams,\n (itemsStateAndParams as ItemsStateAndParamsBase)?.[id]?.params || {},\n );\n } else {\n // params according to queue of its applying\n let queueDataItemsParams: StringParams = {};\n for (const data of queueData) {\n if (data.namespace !== namespace || itemIgnores.includes(data.id)) {\n continue;\n }\n\n let actionParams;\n let params = data.params;\n const needAliasesForActionParams = data.id !== id && hasActionParam(data.params);\n if (needAliasesForActionParams) {\n actionParams = pickActionParamsFromParams(data.params);\n params = pickExceptActionParamsFromParams(data.params);\n }\n\n const mergedParams = getMergedParams(params, actionParams);\n\n queueDataItemsParams = {\n ...queueDataItemsParams,\n ...mergedParams,\n };\n }\n\n itemParams = Object.assign(itemParams, queueDataItemsParams);\n }\n\n return {...defaultWidgetParams, ...itemParams};\n}\n\nexport function getItemsParams({\n defaultGlobalParams = {},\n globalParams = {},\n config,\n itemsStateAndParams,\n plugins,\n useStateAsInitial,\n}: GetItemsParamsArg): GetItemsParamsReturn {\n const {aliases, connections} = config;\n const items = prerenderItems({items: config.items, plugins});\n const isFirstVersion = getCurrentVersion(itemsStateAndParams) === 1;\n\n const allItems = items.reduce((paramsItems: (ConfigItem | ConfigItemGroup)[], item) => {\n if (isItemWithGroup(item)) {\n item.data.group.forEach((groupItem) => {\n paramsItems.push(groupItem);\n });\n\n return paramsItems;\n }\n\n paramsItems.push(item);\n return paramsItems;\n }, []);\n\n const queueData: FormedQueueData[] = isFirstVersion\n ? []\n : formQueueData({items, itemsStateAndParams});\n\n // to consider other kind types in future (not only ignore)\n const mapItemsIgnores = getMapItemsIgnores({\n items: allItems,\n ignores: connections.filter(({kind}) => kind === 'ignore'),\n itemsStateAndParams,\n isFirstVersion,\n });\n const groupByNamespace = groupBy(allItems, 'namespace');\n const itemsWithDefaultsByNamespace = Object.keys(groupByNamespace).reduce(\n (acc, namespace) => {\n return {\n ...acc,\n // there are defaults only in selectors by now, need to get them from item.data.tabs[].defaults for widgets\n // but make a decision about there's order first\n [namespace]: groupByNamespace[namespace].filter((item) => item.defaults),\n };\n },\n {} as Record<string, (ConfigItem | ConfigItemGroup)[]>,\n );\n\n return items.reduce((itemsParams: GetItemsParamsReturn, item: ConfigItem) => {\n const {id, namespace} = item;\n\n const getMergedParams = (params: StringParams, actionParams?: StringParams) =>\n mergeParamsWithAliases({aliases, namespace, params: params || {}, actionParams});\n\n const paramsOptions = {\n itemsStateAndParams,\n mapItemsIgnores,\n itemsWithDefaultsByNamespace,\n getMergedParams,\n defaultGlobalParams,\n globalParams,\n isFirstVersion,\n queueData,\n useStateAsInitial,\n };\n\n if (isItemWithGroup(item)) {\n const groupParams = item.data.group.reduce(\n (groupItemParams: Record<string, StringParams>, groupItem) => {\n groupItemParams[groupItem.id] = getItemParams({\n item: groupItem,\n parentItemId: item.id,\n ...paramsOptions,\n });\n return groupItemParams;\n },\n {},\n );\n\n return {...itemsParams, [id]: groupParams};\n }\n\n return {\n ...itemsParams,\n [id]: getItemParams({\n item,\n ...paramsOptions,\n }),\n };\n }, {});\n}\n\nexport function getItemsState({\n config,\n itemsStateAndParams,\n}: {\n config: Config;\n itemsStateAndParams: ItemsStateAndParams;\n}) {\n return config.items.reduce((acc: Record<string, ItemState>, {id}) => {\n acc[id] = (itemsStateAndParams as ItemsStateAndParamsBase)?.[id]?.state || {};\n return acc;\n }, {});\n}\n\nexport function getItemsStateAndParams({\n defaultGlobalParams = {},\n globalParams = {},\n config,\n itemsStateAndParams,\n plugins,\n}: GetItemsParamsArg): ItemsStateAndParams {\n const params = getItemsParams({\n defaultGlobalParams,\n globalParams,\n config,\n itemsStateAndParams,\n plugins,\n });\n const state = getItemsState({config, itemsStateAndParams});\n const uniqIds = new Set([...Object.keys(params), ...Object.keys(state)]);\n\n const result: ItemsStateAndParams = Array.from(uniqIds).reduce(\n (acc: ItemsStateAndParams, id) => {\n const data = {} as ItemStateAndParams;\n if (id in params) {\n data.params = params[id];\n }\n if (id in state) {\n data.state = state[id];\n }\n return {\n ...acc,\n [id]: data,\n };\n },\n {},\n );\n const version = getCurrentVersion(itemsStateAndParams);\n if (version === 1) {\n return result;\n }\n const meta = {\n [META_KEY]: itemsStateAndParams[META_KEY] as StateAndParamsMetaData,\n };\n return {\n ...meta,\n ...result,\n };\n}\n"]}
1
+ {"version":3,"file":"state-and-params.js","sourceRoot":"../../../../src","sources":["shared/modules/state-and-params.ts"],"names":[],"mappings":";;AAqKA,wCA+FC;AAED,sCAYC;AAED,wDA4CC;;AAhUD,wEAAqC;AAErC,qDAAsC;AAgBtC,0CAcmB;AAanB,MAAM,2BAA2B,GAAG,CAAC,EACjC,mBAAmB,EACnB,YAAY,EACZ,IAAI,GAKP,EAAE,EAAE;IACD,MAAM,QAAQ,GAAG,YAAY,IAAI,IAAI,CAAC,EAAE,CAAC;IAEzC,IAAI,CAAC,CAAC,QAAQ,IAAI,mBAAmB,CAAC,EAAE,CAAC;QACrC,OAAO,EAAE,CAAC;IACd,CAAC;IAED,MAAM,cAAc,GAAG,mBAA8C,CAAC;IACtE,MAAM,UAAU,GAAG,YAAY;QAC3B,CAAC,CAAC,MAAM,CAAC,MAAM,CACT,EAAE,EACD,cAAc,CAAC,QAAQ,CAAC,CAAC,MAAuC,CAAC,IAAI,CAAC,EAAE,CAAC,CAC7E;QACH,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC,MAAsB,CAAC,CAAC;IAEzE,OAAO,UAAU,CAAC;AACtB,CAAC,CAAC;AAEF,SAAS,aAAa,CAAC,EACnB,IAAI,EACJ,mBAAmB,EACnB,eAAe,EACf,4BAA4B,EAC5B,eAAe,EACf,mBAAmB,EACnB,Y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tC,IAAI,EAAE,IAAI,MAAM,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;QAC7B,CAAC;QACD,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC;YACd,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;QAC3B,CAAC;QACD,uCACO,GAAG,KACN,CAAC,EAAE,CAAC,EAAE,IAAI,IACZ;IACN,CAAC,EACD,EAAE,CACL,CAAC;IACF,MAAM,OAAO,GAAG,IAAA,2BAAiB,EAAC,mBAAmB,CAAC,CAAC;IACvD,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;QAChB,OAAO,MAAM,CAAC;IAClB,CAAC;IACD,MAAM,IAAI,GAAG;QACT,CAAC,oBAAQ,CAAC,EAAE,mBAAmB,CAAC,oBAAQ,CAA2B;KACtE,CAAC;IACF,uCACO,IAAI,GACJ,MAAM,EACX;AACN,CAAC","sourcesContent":["import groupBy from 'lodash/groupBy';\n\nimport {META_KEY} from '../constants';\nimport {\n Config,\n ConfigItem,\n ConfigItemDataWithTabs,\n ConfigItemGroup,\n GlobalParams,\n ItemState,\n ItemStateAndParams,\n ItemsStateAndParams,\n ItemsStateAndParamsBase,\n PluginBase,\n StateAndParamsMetaData,\n StringParams,\n} from '../types';\n\nimport {\n FormedQueueData,\n formQueueData,\n getAllConfigItems,\n getCurrentVersion,\n getMapItemsIgnores,\n hasActionParam,\n isItemWithGroup,\n isItemWithTabs,\n mergeParamsWithAliases,\n pickActionParamsFromParams,\n pickExceptActionParamsFromParams,\n prerenderItems,\n resolveItemInnerId,\n} from './helpers';\n\nexport interface GetItemsParamsArg {\n defaultGlobalParams: GlobalParams;\n globalParams: GlobalParams;\n config: Config;\n itemsStateAndParams: ItemsStateAndParams;\n plugins: PluginBase[];\n useStateAsInitial?: boolean;\n}\n\ntype GetItemsParamsReturn = Record<string, StringParams | Record<string, StringParams>>;\n\nconst getParamsFromStateAndParams = ({\n itemsStateAndParams,\n parentItemId,\n item,\n}: {\n item: ConfigItem | ConfigItemGroup;\n itemsStateAndParams: ItemsStateAndParams;\n parentItemId?: string;\n}) => {\n const widgetId = parentItemId || item.id;\n\n if (!(widgetId in itemsStateAndParams)) {\n return {};\n }\n\n const stateAndParams = itemsStateAndParams as ItemsStateAndParamsBase;\n const itemParams = parentItemId\n ? Object.assign(\n {},\n (stateAndParams[widgetId].params as Record<string, StringParams>)[item.id],\n )\n : Object.assign({}, stateAndParams[widgetId].params as StringParams);\n\n return itemParams;\n};\n\nfunction getItemParams({\n item,\n itemsStateAndParams,\n mapItemsIgnores,\n itemsWithDefaultsByNamespace,\n getMergedParams,\n defaultGlobalParams,\n globalParams,\n isFirstVersion,\n queueData,\n parentItemId,\n useStateAsInitial,\n}: {\n item: ConfigItem | ConfigItemGroup;\n itemsStateAndParams: ItemsStateAndParams;\n mapItemsIgnores: Record<string, string[]>;\n itemsWithDefaultsByNamespace: Record<string, (ConfigItem | ConfigItemGroup)[]>;\n getMergedParams: (params: StringParams, actionParams?: StringParams) => StringParams;\n defaultGlobalParams: StringParams;\n globalParams: GlobalParams;\n isFirstVersion: boolean;\n queueData: FormedQueueData[];\n parentItemId?: string;\n useStateAsInitial?: boolean;\n}) {\n const {id, namespace} = item;\n\n let defaultWidgetParams: StringParams | Record<string, StringParams> = {};\n if (isItemWithTabs(item)) {\n const currentWidgetTabId = resolveItemInnerId({item, itemsStateAndParams});\n const itemTabs: ConfigItemDataWithTabs['tabs'] = item.data.tabs;\n defaultWidgetParams =\n itemTabs.find((tabItem) => tabItem?.id === currentWidgetTabId)?.params || {};\n } else {\n defaultWidgetParams = item.defaults || {};\n }\n\n const itemIgnores = mapItemsIgnores[id];\n\n const affectingItemsWithDefaults = itemsWithDefaultsByNamespace[namespace].filter(\n (itemWithDefaults) => !itemIgnores.includes(itemWithDefaults.id),\n );\n\n let itemParams: StringParams = Object.assign(\n {},\n getMergedParams(defaultGlobalParams),\n // default parameters to begin with\n affectingItemsWithDefaults.reduceRight((defaultParams: StringParams, itemWithDefaults) => {\n return {\n ...defaultParams,\n ...getMergedParams(itemWithDefaults.defaults || {}),\n };\n }, {}),\n getMergedParams(globalParams),\n useStateAsInitial\n ? getParamsFromStateAndParams({parentItemId, item, itemsStateAndParams})\n : {},\n );\n\n if (isFirstVersion) {\n itemParams = Object.assign(\n itemParams,\n (itemsStateAndParams as ItemsStateAndParamsBase)?.[id]?.params || {},\n );\n } else {\n // params according to queue of its applying\n let queueDataItemsParams: StringParams = {};\n for (const data of queueData) {\n if (data.namespace !== namespace || itemIgnores.includes(data.id)) {\n continue;\n }\n\n let actionParams;\n let params = data.params;\n const needAliasesForActionParams = data.id !== id && hasActionParam(data.params);\n if (needAliasesForActionParams) {\n actionParams = pickActionParamsFromParams(data.params);\n params = pickExceptActionParamsFromParams(data.params);\n }\n\n const mergedParams = getMergedParams(params, actionParams);\n\n queueDataItemsParams = {\n ...queueDataItemsParams,\n ...mergedParams,\n };\n }\n\n itemParams = Object.assign(itemParams, queueDataItemsParams);\n }\n\n return {...defaultWidgetParams, ...itemParams};\n}\n\nexport function getItemsParams({\n defaultGlobalParams = {},\n globalParams = {},\n config,\n itemsStateAndParams,\n plugins,\n useStateAsInitial,\n}: GetItemsParamsArg): GetItemsParamsReturn {\n const configItems = getAllConfigItems(config);\n const {aliases, connections} = config;\n const items = prerenderItems({\n items: configItems,\n plugins,\n });\n const isFirstVersion = getCurrentVersion(itemsStateAndParams) === 1;\n\n const allItems = items.reduce((paramsItems: (ConfigItem | ConfigItemGroup)[], item) => {\n if (isItemWithGroup(item)) {\n item.data.group.forEach((groupItem) => {\n paramsItems.push(groupItem);\n });\n\n return paramsItems;\n }\n\n paramsItems.push(item);\n return paramsItems;\n }, []);\n\n const queueData: FormedQueueData[] = isFirstVersion\n ? []\n : formQueueData({items, itemsStateAndParams});\n\n // to consider other kind types in future (not only ignore)\n const mapItemsIgnores = getMapItemsIgnores({\n items: allItems,\n ignores: connections.filter(({kind}) => kind === 'ignore'),\n itemsStateAndParams,\n isFirstVersion,\n });\n const groupByNamespace = groupBy(allItems, 'namespace');\n const itemsWithDefaultsByNamespace = Object.keys(groupByNamespace).reduce(\n (acc, namespace) => {\n return {\n ...acc,\n // there are defaults only in selectors by now, need to get them from item.data.tabs[].defaults for widgets\n // but make a decision about there's order first\n [namespace]: groupByNamespace[namespace].filter((item) => item.defaults),\n };\n },\n {} as Record<string, (ConfigItem | ConfigItemGroup)[]>,\n );\n\n return items.reduce((itemsParams: GetItemsParamsReturn, item: ConfigItem) => {\n const {id, namespace} = item;\n\n const getMergedParams = (params: StringParams, actionParams?: StringParams) =>\n mergeParamsWithAliases({aliases, namespace, params: params || {}, actionParams});\n\n const paramsOptions = {\n itemsStateAndParams,\n mapItemsIgnores,\n itemsWithDefaultsByNamespace,\n getMergedParams,\n defaultGlobalParams,\n globalParams,\n isFirstVersion,\n queueData,\n useStateAsInitial,\n };\n\n if (isItemWithGroup(item)) {\n const groupParams = item.data.group.reduce(\n (groupItemParams: Record<string, StringParams>, groupItem) => {\n groupItemParams[groupItem.id] = getItemParams({\n item: groupItem,\n parentItemId: item.id,\n ...paramsOptions,\n });\n return groupItemParams;\n },\n {},\n );\n\n return {...itemsParams, [id]: groupParams};\n }\n\n return {\n ...itemsParams,\n [id]: getItemParams({\n item,\n ...paramsOptions,\n }),\n };\n }, {});\n}\n\nexport function getItemsState({\n config,\n itemsStateAndParams,\n}: {\n config: Config;\n itemsStateAndParams: ItemsStateAndParams;\n}) {\n const configItems = getAllConfigItems(config);\n return configItems.reduce((acc: Record<string, ItemState>, {id}) => {\n acc[id] = (itemsStateAndParams as ItemsStateAndParamsBase)?.[id]?.state || {};\n return acc;\n }, {});\n}\n\nexport function getItemsStateAndParams({\n defaultGlobalParams = {},\n globalParams = {},\n config,\n itemsStateAndParams,\n plugins,\n}: GetItemsParamsArg): ItemsStateAndParams {\n const params = getItemsParams({\n defaultGlobalParams,\n globalParams,\n config,\n itemsStateAndParams,\n plugins,\n });\n const state = getItemsState({config, itemsStateAndParams});\n const uniqIds = new Set([...Object.keys(params), ...Object.keys(state)]);\n\n const result: ItemsStateAndParams = Array.from(uniqIds).reduce(\n (acc: ItemsStateAndParams, id) => {\n const data = {} as ItemStateAndParams;\n if (id in params) {\n data.params = params[id];\n }\n if (id in state) {\n data.state = state[id];\n }\n return {\n ...acc,\n [id]: data,\n };\n },\n {},\n );\n const version = getCurrentVersion(itemsStateAndParams);\n if (version === 1) {\n return result;\n }\n const meta = {\n [META_KEY]: itemsStateAndParams[META_KEY] as StateAndParamsMetaData,\n };\n return {\n ...meta,\n ...result,\n };\n}\n"]}
@@ -7,7 +7,7 @@ const hashids_1 = tslib_1.__importDefault(require("hashids"));
7
7
  const helpers_1 = require("./helpers.js");
8
8
  function extractIdsFromConfig(config) {
9
9
  const ids = [];
10
- const items = config.items || [];
10
+ const items = (0, helpers_1.getAllConfigItems)(config);
11
11
  const connections = config.connections || [];
12
12
  const layout = config.layout || [];
13
13
  items.forEach((item) => {
@@ -1 +1 @@
1
- {"version":3,"file":"uniq-id.js","sourceRoot":"../../../../src","sources":["shared/modules/uniq-id.ts"],"names":[],"mappings":";;AAMA,oDAoBC;AAQD,wCAeC;;AAjDD,8DAA8B;AAI9B,0CAA0D;AAE1D,SAAgB,oBAAoB,CAAC,MAAc;IAC/C,MAAM,GAAG,GAAa,EAAE,CAAC;IAEzB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;IACjC,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC;IAC7C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;IAEnC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACnB,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClB,IAAI,IAAA,wBAAc,EAAC,IAAI,CAAC,EAAE,CAAC;YACvB,IAAI,CAAC,IAAI,CAA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,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAC,CAAC;AAC7C,CAAC","sourcesContent":["import Hashids from 'hashids';\n\nimport type {Config} from '../types';\n\nimport {isItemWithGroup, isItemWithTabs} from './helpers';\n\nexport function extractIdsFromConfig(config: Config): string[] {\n const ids: string[] = [];\n\n const items = config.items || [];\n const connections = config.connections || [];\n const layout = config.layout || [];\n\n items.forEach((item) => {\n ids.push(item.id);\n if (isItemWithTabs(item)) {\n item.data.tabs.forEach((tabItem) => ids.push(tabItem.id));\n }\n if (isItemWithGroup(item)) {\n item.data.group.forEach((groupItem) => ids.push(groupItem.id));\n }\n });\n connections.forEach(({from, to}) => ids.push(from, to));\n layout.forEach(({i}) => ids.push(i));\n\n return Array.from(new Set(ids));\n}\n\ntype GenerateUniqIdArgs = {\n salt: Config['salt'];\n counter: Config['counter'];\n ids: string[];\n};\n\nexport function generateUniqId({salt, counter, ids}: GenerateUniqIdArgs) {\n let newCounter = counter;\n let uniqId: string | null = null;\n\n const idsSet = new Set(ids);\n const hashids = new Hashids(salt);\n\n while (uniqId === null) {\n const id = hashids.encode(++newCounter);\n if (!idsSet.has(id)) {\n uniqId = id;\n }\n }\n\n return {counter: newCounter, id: uniqId};\n}\n"]}
1
+ {"version":3,"file":"uniq-id.js","sourceRoot":"../../../../src","sources":["shared/modules/uniq-id.ts"],"names":[],"mappings":";;AAMA,oDAoBC;AAQD,wCAeC;;AAjDD,8DAA8B;AAI9B,0CAA6E;AAE7E,SAAgB,oBAAoB,CAAC,MAAc;IAC/C,MAAM,GAAG,GAAa,EAAE,CAAC;IAEzB,MAAM,KAAK,GAAG,IAAA,2BAAiB,EAAC,MAAM,CAAC,CAAC;IACxC,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC;IAC7C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;IAEnC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACnB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AC;QACxC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YAClB,MAAM,GAAG,EAAE,CAAC;QAChB,CAAC;IACL,CAAC;IAED,OAAO,EAAC,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAC,CAAC;AAC7C,CAAC","sourcesContent":["import Hashids from 'hashids';\n\nimport type {Config} from '../types';\n\nimport {getAllConfigItems, isItemWithGroup, isItemWithTabs} from './helpers';\n\nexport function extractIdsFromConfig(config: Config): string[] {\n const ids: string[] = [];\n\n const items = getAllConfigItems(config);\n const connections = config.connections || [];\n const layout = config.layout || [];\n\n items.forEach((item) => {\n ids.push(item.id);\n if (isItemWithTabs(item)) {\n item.data.tabs.forEach((tabItem) => ids.push(tabItem.id));\n }\n if (isItemWithGroup(item)) {\n item.data.group.forEach((groupItem) => ids.push(groupItem.id));\n }\n });\n connections.forEach(({from, to}) => ids.push(from, to));\n layout.forEach(({i}) => ids.push(i));\n\n return Array.from(new Set(ids));\n}\n\ntype GenerateUniqIdArgs = {\n salt: Config['salt'];\n counter: Config['counter'];\n ids: string[];\n};\n\nexport function generateUniqId({salt, counter, ids}: GenerateUniqIdArgs) {\n let newCounter = counter;\n let uniqId: string | null = null;\n\n const idsSet = new Set(ids);\n const hashids = new Hashids(salt);\n\n while (uniqId === null) {\n const id = hashids.encode(++newCounter);\n if (!idsSet.has(id)) {\n uniqId = id;\n }\n }\n\n return {counter: newCounter, id: uniqId};\n}\n"]}
@@ -59,6 +59,7 @@ export interface Config {
59
59
  salt: string;
60
60
  counter: number;
61
61
  items: ConfigItem[];
62
+ globalItems?: ConfigItem[];
62
63
  layout: ConfigLayout[];
63
64
  aliases: ConfigAliases;
64
65
  connections: ConfigConnection[];
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"../../../../src","sources":["shared/types/config.ts"],"names":[],"mappings":"","sourcesContent":["import {StringParams} from './common';\n\nexport interface AdditionalWidgetLayout {\n parent?: string;\n}\n\nexport interface ConfigLayout extends AdditionalWidgetLayout {\n i: string;\n h: number;\n w: number;\n x: number;\n y: number;\n}\n\nexport type ConfigItemGroup = {\n id: string;\n defaults?: StringParams;\n namespace: string;\n [key: string]: unknown;\n};\n\nexport interface ConfigItemData {\n _editActive?: boolean;\n tabs?: {\n id: string;\n isDefault?: boolean;\n params?: StringParams;\n [key: string]: unknown;\n }[];\n group?: ConfigItemGroup[];\n [key: string]: unknown;\n}\n\nexport interface ConfigItemDataWithTabs extends Omit<ConfigItemData, 'tabs'> {\n tabs: NonNullable<ConfigItemData['tabs']>;\n}\n\nexport interface ConfigItemDataWithGroup extends Omit<ConfigItemData, 'group'> {\n group: NonNullable<ConfigItemData['group']>;\n}\n\nexport interface ConfigItem {\n id: string;\n data: ConfigItemData;\n type: string;\n namespace: string;\n defaults?: StringParams;\n orderId?: number;\n defaultOrderId?: number;\n}\n\nexport interface ConfigItemWithTabs extends Omit<ConfigItem, 'data'> {\n data: ConfigItemDataWithTabs;\n}\n\nexport interface ConfigItemWithGroup extends Omit<ConfigItem, 'data'> {\n data: ConfigItemDataWithGroup;\n}\n\nexport interface ConfigAliases {\n [namespace: string]: string[][]; // в массивах имена параметров\n}\n\nexport interface ConfigConnection {\n from: string;\n to: string;\n kind: 'ignore'; // пока один kind\n}\n\nexport interface Config {\n salt: string;\n counter: number;\n items: ConfigItem[];\n layout: ConfigLayout[];\n aliases: ConfigAliases;\n connections: ConfigConnection[];\n}\n"]}
1
+ {"version":3,"file":"config.js","sourceRoot":"../../../../src","sources":["shared/types/config.ts"],"names":[],"mappings":"","sourcesContent":["import {StringParams} from './common';\n\nexport interface AdditionalWidgetLayout {\n parent?: string;\n}\n\nexport interface ConfigLayout extends AdditionalWidgetLayout {\n i: string;\n h: number;\n w: number;\n x: number;\n y: number;\n}\n\nexport type ConfigItemGroup = {\n id: string;\n defaults?: StringParams;\n namespace: string;\n [key: string]: unknown;\n};\n\nexport interface ConfigItemData {\n _editActive?: boolean;\n tabs?: {\n id: string;\n isDefault?: boolean;\n params?: StringParams;\n [key: string]: unknown;\n }[];\n group?: ConfigItemGroup[];\n [key: string]: unknown;\n}\n\nexport interface ConfigItemDataWithTabs extends Omit<ConfigItemData, 'tabs'> {\n tabs: NonNullable<ConfigItemData['tabs']>;\n}\n\nexport interface ConfigItemDataWithGroup extends Omit<ConfigItemData, 'group'> {\n group: NonNullable<ConfigItemData['group']>;\n}\n\nexport interface ConfigItem {\n id: string;\n data: ConfigItemData;\n type: string;\n namespace: string;\n defaults?: StringParams;\n orderId?: number;\n defaultOrderId?: number;\n}\n\nexport interface ConfigItemWithTabs extends Omit<ConfigItem, 'data'> {\n data: ConfigItemDataWithTabs;\n}\n\nexport interface ConfigItemWithGroup extends Omit<ConfigItem, 'data'> {\n data: ConfigItemDataWithGroup;\n}\n\nexport interface ConfigAliases {\n [namespace: string]: string[][]; // в массивах имена параметров\n}\n\nexport interface ConfigConnection {\n from: string;\n to: string;\n kind: 'ignore'; // пока один kind\n}\n\nexport interface Config {\n salt: string;\n counter: number;\n items: ConfigItem[];\n globalItems?: ConfigItem[];\n layout: ConfigLayout[];\n aliases: ConfigAliases;\n connections: ConfigConnection[];\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { Layout, Layouts } from 'react-grid-layout';
1
+ import type { Layout } from 'react-grid-layout';
2
2
  import type { Config, ConfigItem, ConfigLayout } from "../shared/index.js";
3
3
  import { GridLayoutSettings } from "./common.js";
4
4
  export interface AddConfigItem extends Omit<ConfigItem, 'id' | 'namespace'> {
@@ -9,6 +9,7 @@ export interface AddConfigItem extends Omit<ConfigItem, 'id' | 'namespace'> {
9
9
  export type SetConfigItem = ConfigItem | AddConfigItem;
10
10
  export type SetItemOptions = {
11
11
  excludeIds?: string[];
12
+ useGlobalItems?: boolean;
12
13
  };
13
14
  export type GridReflowOptions = {
14
15
  cols: number;
@@ -41,7 +42,7 @@ export interface DashKitGroup {
41
42
  gridProperties?: (props: ReactGridLayoutProps) => ReactGridLayoutProps;
42
43
  }
43
44
  export type ItemManipulationCallback = (eventData: {
44
- layout: Layouts;
45
+ layout: Layout[];
45
46
  oldItem: Layout;
46
47
  newItem: Layout;
47
48
  placeholder: Layout;
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"../../../src","sources":["typings/config.ts"],"names":[],"mappings":"","sourcesContent":["import type {Layout, Layouts} from 'react-grid-layout';\n\nimport type {Config, ConfigItem, ConfigLayout} from '../shared';\n\nimport {GridLayoutSettings} from './common';\n\nexport interface AddConfigItem extends Omit<ConfigItem, 'id' | 'namespace'> {\n id?: null;\n namespace?: string;\n layout?: Omit<ConfigLayout, 'i'>;\n}\nexport type SetConfigItem = ConfigItem | AddConfigItem;\n\nexport type SetItemOptions = {\n excludeIds?: string[];\n};\n\nexport type GridReflowOptions = {\n cols: number;\n maxRows?: number;\n compactType?: CompactType;\n};\n\nexport type CompactType = ReactGridLayout.ReactGridLayoutProps['compactType'] | 'horizontal-nowrap';\n\nexport type ReflowLayoutOptions = {\n defaultProps: GridReflowOptions;\n groups?: Record<string, GridReflowOptions>;\n};\n\nexport type AddNewItemOptions = SetItemOptions & {\n updateLayout?: ConfigLayout[];\n reflowLayoutOptions?: ReflowLayoutOptions;\n};\n\nexport interface DashkitGroupRenderProps {\n config: Config;\n editMode: boolean;\n isMobile: boolean;\n items: ConfigItem[];\n layout: ConfigLayout[];\n context: any;\n}\n\nexport type ReactGridLayoutProps = Omit<\n GridLayoutSettings,\n | 'children'\n | 'compactType'\n | 'innerRef'\n | 'key'\n | 'layout'\n | 'onDragStart'\n | 'onDragStop'\n | 'onResizeStart'\n | 'onResizeStop'\n | 'draggableHandle'\n | 'isDroppable'\n | 'onDropDragOver'\n | 'onDrop'\n | 'draggableCancel'\n> & {\n compactType?: CompactType;\n};\n\nexport interface DashKitGroup {\n id?: string;\n render?: (\n id: string,\n children: React.ReactNode,\n props: DashkitGroupRenderProps,\n ) => React.ReactNode;\n gridProperties?: (props: ReactGridLayoutProps) => ReactGridLayoutProps;\n}\n\nexport type ItemManipulationCallback = (eventData: {\n layout: Layouts;\n oldItem: Layout;\n newItem: Layout;\n placeholder: Layout;\n e: MouseEvent;\n element: HTMLElement;\n}) => void;\n"]}
1
+ {"version":3,"file":"config.js","sourceRoot":"../../../src","sources":["typings/config.ts"],"names":[],"mappings":"","sourcesContent":["import type {Layout} from 'react-grid-layout';\n\nimport type {Config, ConfigItem, ConfigLayout} from '../shared';\n\nimport {GridLayoutSettings} from './common';\n\nexport interface AddConfigItem extends Omit<ConfigItem, 'id' | 'namespace'> {\n id?: null;\n namespace?: string;\n layout?: Omit<ConfigLayout, 'i'>;\n}\nexport type SetConfigItem = ConfigItem | AddConfigItem;\n\nexport type SetItemOptions = {\n excludeIds?: string[];\n useGlobalItems?: boolean;\n};\n\nexport type GridReflowOptions = {\n cols: number;\n maxRows?: number;\n compactType?: CompactType;\n};\n\nexport type CompactType = ReactGridLayout.ReactGridLayoutProps['compactType'] | 'horizontal-nowrap';\n\nexport type ReflowLayoutOptions = {\n defaultProps: GridReflowOptions;\n groups?: Record<string, GridReflowOptions>;\n};\n\nexport type AddNewItemOptions = SetItemOptions & {\n updateLayout?: ConfigLayout[];\n reflowLayoutOptions?: ReflowLayoutOptions;\n};\n\nexport interface DashkitGroupRenderProps {\n config: Config;\n editMode: boolean;\n isMobile: boolean;\n items: ConfigItem[];\n layout: ConfigLayout[];\n context: any;\n}\n\nexport type ReactGridLayoutProps = Omit<\n GridLayoutSettings,\n | 'children'\n | 'compactType'\n | 'innerRef'\n | 'key'\n | 'layout'\n | 'onDragStart'\n | 'onDragStop'\n | 'onResizeStart'\n | 'onResizeStop'\n | 'draggableHandle'\n | 'isDroppable'\n | 'onDropDragOver'\n | 'onDrop'\n | 'draggableCancel'\n> & {\n compactType?: CompactType;\n};\n\nexport interface DashKitGroup {\n id?: string;\n render?: (\n id: string,\n children: React.ReactNode,\n props: DashkitGroupRenderProps,\n ) => React.ReactNode;\n gridProperties?: (props: ReactGridLayoutProps) => ReactGridLayoutProps;\n}\n\nexport type ItemManipulationCallback = (eventData: {\n layout: Layout[];\n oldItem: Layout;\n newItem: Layout;\n placeholder: Layout;\n e: MouseEvent;\n element: HTMLElement;\n}) => void;\n"]}
@@ -25,6 +25,7 @@ export interface PluginWidgetProps<T = StringParams> {
25
25
  }) => void;
26
26
  }
27
27
  export type PluginDefaultLayout = Partial<Omit<WidgetLayout, 'i'>>;
28
+ export type PluginRef = React.RefObject<any> | Record<string, unknown>;
28
29
  export interface Plugin<P extends PluginWidgetProps<T> = any, T = StringParams> extends PluginBase {
29
30
  defaultLayout?: PluginDefaultLayout;
30
31
  renderer: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"../../../src","sources":["typings/plugin.ts"],"names":[],"mappings":"","sourcesContent":["import React from 'react';\n\nimport ReactGridLayout from 'react-grid-layout';\n\nimport type {\n ConfigItem,\n ItemState,\n ItemStateAndParams,\n ItemStateAndParamsChangeOptions,\n PluginBase,\n StringParams,\n} from '../shared';\n\nimport type {ContextProps, SettingsProps, WidgetLayout} from './common';\n\nexport interface PluginWidgetProps<T = StringParams> {\n id: string;\n editMode: boolean;\n params: T;\n state: ItemState;\n onStateAndParamsChange: (\n stateAndParams: ItemStateAndParams,\n options?: ItemStateAndParamsChangeOptions,\n ) => void;\n onBeforeLoad: () => () => void;\n width: number;\n height: number;\n data: ConfigItem['data'];\n defaults: ConfigItem['defaults'];\n namespace: ConfigItem['namespace'];\n settings: SettingsProps;\n context: ContextProps;\n layout: WidgetLayout[];\n gridLayout: ReactGridLayout.ReactGridLayoutProps;\n adjustWidgetLayout: (data: {\n widgetId: string;\n needSetDefault?: boolean;\n adjustedWidgetLayout?: WidgetLayout;\n }) => void;\n}\n\nexport type PluginDefaultLayout = Partial<Omit<WidgetLayout, 'i'>>;\n\nexport interface Plugin<P extends PluginWidgetProps<T> = any, T = StringParams> extends PluginBase {\n defaultLayout?: PluginDefaultLayout;\n renderer: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;\n placeholderRenderer?: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;\n}\n"]}
1
+ {"version":3,"file":"plugin.js","sourceRoot":"../../../src","sources":["typings/plugin.ts"],"names":[],"mappings":"","sourcesContent":["import React from 'react';\n\nimport ReactGridLayout from 'react-grid-layout';\n\nimport type {\n ConfigItem,\n ItemState,\n ItemStateAndParams,\n ItemStateAndParamsChangeOptions,\n PluginBase,\n StringParams,\n} from '../shared';\n\nimport type {ContextProps, SettingsProps, WidgetLayout} from './common';\n\nexport interface PluginWidgetProps<T = StringParams> {\n id: string;\n editMode: boolean;\n params: T;\n state: ItemState;\n onStateAndParamsChange: (\n stateAndParams: ItemStateAndParams,\n options?: ItemStateAndParamsChangeOptions,\n ) => void;\n onBeforeLoad: () => () => void;\n width: number;\n height: number;\n data: ConfigItem['data'];\n defaults: ConfigItem['defaults'];\n namespace: ConfigItem['namespace'];\n settings: SettingsProps;\n context: ContextProps;\n layout: WidgetLayout[];\n gridLayout: ReactGridLayout.ReactGridLayoutProps;\n adjustWidgetLayout: (data: {\n widgetId: string;\n needSetDefault?: boolean;\n adjustedWidgetLayout?: WidgetLayout;\n }) => void;\n}\n\nexport type PluginDefaultLayout = Partial<Omit<WidgetLayout, 'i'>>;\n\nexport type PluginRef = React.RefObject<any> | Record<string, unknown>;\n\nexport interface Plugin<P extends PluginWidgetProps<T> = any, T = StringParams> extends PluginBase {\n defaultLayout?: PluginDefaultLayout;\n renderer: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;\n placeholderRenderer?: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;\n}\n"]}
@@ -13,8 +13,9 @@ const grid_layout_1 = require("./grid-layout.js");
13
13
  const group_helpers_1 = require("./group-helpers.js");
14
14
  (0, immutability_helper_1.extend)('$auto', (value, object) => (object ? (0, immutability_helper_1.default)(object, value) : (0, immutability_helper_1.default)({}, value)));
15
15
  function removeItemVersion1({ id, config, itemsStateAndParams }) {
16
- const itemIndex = config.items.findIndex((item) => item.id === id);
17
- const removeItem = config.items[itemIndex];
16
+ const configItems = (0, shared_1.getAllConfigItems)(config);
17
+ const itemIndex = configItems.findIndex((item) => item.id === id);
18
+ const removeItem = configItems[itemIndex];
18
19
  const { defaults = {} } = removeItem;
19
20
  const itemParamsKeys = Object.keys(defaults);
20
21
  const getParams = (excludeId, items) => {
@@ -25,8 +26,8 @@ function removeItemVersion1({ id, config, itemsStateAndParams }) {
25
26
  return acc;
26
27
  }, {}));
27
28
  };
28
- const allParamsKeys = getParams(id, config.items);
29
- const allNamespaceParamsKeys = getParams(id, config.items.filter((item) => item.namespace === removeItem.namespace));
29
+ const allParamsKeys = getParams(id, configItems);
30
+ const allNamespaceParamsKeys = getParams(id, configItems.filter((item) => item.namespace === removeItem.namespace));
30
31
  const uniqParamsKeys = itemParamsKeys.filter((key) => !allParamsKeys.includes(key));
31
32
  const uniqNamespaceParamsKeys = itemParamsKeys.filter((key) => !allNamespaceParamsKeys.includes(key));
32
33
  const withoutUniqItemsParams = Object.keys(itemsStateAndParams)
@@ -34,7 +35,7 @@ function removeItemVersion1({ id, config, itemsStateAndParams }) {
34
35
  .reduce((acc, key) => {
35
36
  const { params } = itemsStateAndParams[key];
36
37
  // в state из урла могут быть элементы, которых нет в config.items
37
- const item = config.items.find((configItem) => configItem.id === key);
38
+ const item = configItems.find((configItem) => configItem.id === key);
38
39
  if (params && item) {
39
40
  const { namespace } = item;
40
41
  const currentUniqParamsKeys = namespace === removeItem.namespace
@@ -109,10 +110,11 @@ function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams, pa
109
110
  return allowedParams;
110
111
  }
111
112
  function changeStateAndParamsVersion1({ id: initiatorId, config, stateAndParams, itemsStateAndParams, }) {
113
+ const allConfigItems = (0, shared_1.getAllConfigItems)(config);
112
114
  const hasState = 'state' in stateAndParams;
113
115
  const { aliases } = config;
114
116
  if ('params' in stateAndParams) {
115
- const initiatorItem = config.items.find(({ id }) => id === initiatorId);
117
+ const initiatorItem = allConfigItems.find(({ id }) => id === initiatorId);
116
118
  const allowableParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams);
117
119
  const allowableParamsWithAliases = (0, shared_1.mergeParamsWithAliases)({
118
120
  aliases,
@@ -122,7 +124,7 @@ function changeStateAndParamsVersion1({ id: initiatorId, config, stateAndParams,
122
124
  const ignoresInitiatorIds = config.connections
123
125
  .filter(({ to }) => to === initiatorId)
124
126
  .map(({ from }) => from);
125
- const updateIds = config.items
127
+ const updateIds = allConfigItems
126
128
  .filter((item) => item.namespace === initiatorItem.namespace &&
127
129
  !ignoresInitiatorIds.includes(item.id) &&
128
130
  (!(0, shared_1.isItemWithTabs)(item) ||
@@ -282,6 +284,9 @@ class UpdateManager {
282
284
  counter = newIdData.counter;
283
285
  const newItem = Object.assign(Object.assign({}, item), { id: newIdData.id, data: newItemData.data, namespace });
284
286
  const saveDefaultLayout = (0, pick_1.default)(layout, ['h', 'w', 'x', 'y', 'parent']);
287
+ const updateActions = Object.assign({ counter: { $set: counter } }, (options.useGlobalItems
288
+ ? { globalItems: config.globalItems ? { $push: [newItem] } : { $set: [newItem] } }
289
+ : { items: { $push: [newItem] } }));
285
290
  if (options.updateLayout) {
286
291
  const byId = options.updateLayout.reduce((memo, t) => {
287
292
  memo[t.i] = t;
@@ -302,11 +307,7 @@ class UpdateManager {
302
307
  Object.assign(Object.assign({}, saveDefaultLayout), { i: newItem.id }),
303
308
  ];
304
309
  }
305
- return (0, immutability_helper_1.default)(config, {
306
- items: { $push: [newItem] },
307
- layout: { $set: newLayout },
308
- counter: { $set: counter },
309
- });
310
+ return (0, immutability_helper_1.default)(config, Object.assign(Object.assign({}, updateActions), { layout: { $set: newLayout } }));
310
311
  }
311
312
  else if (isFinite(layout.y)) {
312
313
  let newLayout;
@@ -321,24 +322,22 @@ class UpdateManager {
321
322
  else {
322
323
  newLayout = [...config.layout, newLayoutItem];
323
324
  }
324
- return (0, immutability_helper_1.default)(config, {
325
- items: { $push: [newItem] },
326
- layout: { $set: newLayout },
327
- counter: { $set: counter },
328
- });
325
+ return (0, immutability_helper_1.default)(config, Object.assign(Object.assign({}, updateActions), { layout: { $set: newLayout } }));
329
326
  }
330
327
  else {
331
328
  const layoutY = (0, grid_layout_1.bottom)(config.layout);
332
329
  const newLayoutItem = Object.assign(Object.assign({}, saveDefaultLayout), { y: layoutY, i: newItem.id });
333
- return (0, immutability_helper_1.default)(config, {
334
- items: { $push: [newItem] },
335
- layout: { $push: [newLayoutItem] },
336
- counter: { $set: counter },
337
- });
330
+ return (0, immutability_helper_1.default)(config, Object.assign(Object.assign({}, updateActions), { layout: { $push: [newLayoutItem] } }));
338
331
  }
339
332
  }
340
333
  static editItem({ item, namespace = constants_1.DEFAULT_NAMESPACE, config, options = {}, }) {
334
+ const globalItemIndex = config.globalItems
335
+ ? config.globalItems.findIndex(({ id }) => item.id === id)
336
+ : -1;
341
337
  const itemIndex = config.items.findIndex(({ id }) => item.id === id);
338
+ const shouldBeGlobalItem = options.useGlobalItems;
339
+ const isCurrentlyInGlobalItems = globalItemIndex !== -1;
340
+ const isCurrentlyInItems = itemIndex !== -1;
342
341
  const { counter, data } = getNewItemData({
343
342
  item,
344
343
  config,
@@ -346,18 +345,43 @@ class UpdateManager {
346
345
  counter: config.counter,
347
346
  options,
348
347
  });
349
- return (0, immutability_helper_1.default)(config, {
350
- items: { [itemIndex]: { $set: Object.assign(Object.assign({}, item), { data, namespace }) } },
351
- counter: { $set: counter },
352
- });
348
+ const updatedItem = Object.assign(Object.assign({}, item), { data, namespace });
349
+ // Determine if we need to move the item between arrays
350
+ if (shouldBeGlobalItem && isCurrentlyInItems) {
351
+ // Move from items to globalItems
352
+ return (0, immutability_helper_1.default)(config, {
353
+ items: { $splice: [[itemIndex, 1]] },
354
+ globalItems: config.globalItems ? { $push: [updatedItem] } : { $set: [updatedItem] },
355
+ counter: { $set: counter },
356
+ });
357
+ }
358
+ else if (!shouldBeGlobalItem && isCurrentlyInGlobalItems) {
359
+ // Move from globalItems to items
360
+ return (0, immutability_helper_1.default)(config, {
361
+ globalItems: { $splice: [[globalItemIndex, 1]] },
362
+ items: { $push: [updatedItem] },
363
+ counter: { $set: counter },
364
+ });
365
+ }
366
+ else {
367
+ // Update in current location
368
+ const updateAction = isCurrentlyInGlobalItems
369
+ ? { globalItems: { [globalItemIndex]: { $set: updatedItem } } }
370
+ : { items: { [itemIndex]: { $set: updatedItem } } };
371
+ return (0, immutability_helper_1.default)(config, Object.assign(Object.assign({}, updateAction), { counter: { $set: counter } }));
372
+ }
353
373
  }
354
374
  static removeItem({ id, config, itemsStateAndParams = {} }) {
375
+ var _a;
355
376
  if ((0, shared_1.getCurrentVersion)(itemsStateAndParams) === 1) {
356
377
  return removeItemVersion1({ id, config, itemsStateAndParams });
357
378
  }
379
+ const globalItemIndex = config.globalItems
380
+ ? config.globalItems.findIndex((item) => item.id === id)
381
+ : -1;
358
382
  const itemIndex = config.items.findIndex((item) => item.id === id);
359
383
  const layoutIndex = config.layout.findIndex((item) => item.i === id);
360
- const item = config.items[itemIndex];
384
+ const item = config.items[itemIndex] || ((_a = config.globalItems) === null || _a === void 0 ? void 0 : _a[globalItemIndex]);
361
385
  let itemIds = [id];
362
386
  if ((0, shared_1.isItemWithTabs)(item)) {
363
387
  itemIds = [id].concat(item.data.tabs.map((tab) => tab.id));
@@ -366,18 +390,19 @@ class UpdateManager {
366
390
  itemIds = [id].concat(item.data.group.map((groupItem) => groupItem.id));
367
391
  }
368
392
  const connections = config.connections.filter(({ from, to }) => !itemIds.includes(from) && !itemIds.includes(to));
369
- return {
370
- config: (0, immutability_helper_1.default)(config, {
393
+ const updateAction = globalItemIndex === -1
394
+ ? {
371
395
  items: {
372
396
  $splice: [[itemIndex, 1]],
373
397
  },
374
- layout: {
398
+ }
399
+ : { globalItems: { $splice: [[globalItemIndex, 1]] } };
400
+ return {
401
+ config: (0, immutability_helper_1.default)(config, Object.assign({ layout: {
375
402
  $splice: [[layoutIndex, 1]],
376
- },
377
- connections: {
403
+ }, connections: {
378
404
  $set: connections,
379
- },
380
- }),
405
+ } }, updateAction)),
381
406
  itemsStateAndParams: (0, immutability_helper_1.default)(itemsStateAndParams, {
382
407
  $unset: [id],
383
408
  [shared_1.META_KEY]: {
@@ -409,7 +434,7 @@ class UpdateManager {
409
434
  }
410
435
  const action = options === null || options === void 0 ? void 0 : options.action;
411
436
  const hasState = 'state' in stateAndParams;
412
- const { items } = config;
437
+ const items = (0, shared_1.getAllConfigItems)(config);
413
438
  const itemsIds = items.map(({ id: itemId }) => itemId);
414
439
  const itemsStateAndParamsIds = Object.keys((0, omit_1.default)(itemsStateAndParams, [shared_1.META_KEY]));
415
440
  const unusedIds = itemsStateAndParamsIds.filter((id) => !itemsIds.includes(id));
@@ -452,7 +477,12 @@ class UpdateManager {
452
477
  const tabId = (0, shared_1.isItemWithTabs)(initiatorItem)
453
478
  ? newTabId || (0, shared_1.resolveItemInnerId)({ item: initiatorItem, itemsStateAndParams })
454
479
  : undefined;
455
- const meta = (0, shared_1.addToQueue)({ id: initiatorId, tabId, config, itemsStateAndParams });
480
+ const meta = (0, shared_1.addToQueue)({
481
+ id: initiatorId,
482
+ tabId,
483
+ config,
484
+ itemsStateAndParams,
485
+ });
456
486
  let commandUpdateParams = ((_b = itemsStateAndParams[initiatorId]) === null || _b === void 0 ? void 0 : _b.params)
457
487
  ? '$merge'
458
488
  : '$set';