@perses-dev/plugin-system 0.51.0-beta.0 → 0.51.0-rc.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.
Files changed (107) hide show
  1. package/dist/cjs/components/DatasourceSelect.js +155 -71
  2. package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +2 -2
  3. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +91 -1
  4. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +11 -7
  5. package/dist/cjs/constants/user-interface-text.js +3 -1
  6. package/dist/cjs/remote/PluginRuntime.js +168 -162
  7. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +13 -0
  8. package/dist/cjs/runtime/plugin-registry.js +13 -4
  9. package/dist/cjs/runtime/time-series-queries.js +3 -13
  10. package/dist/cjs/runtime/trace-queries.js +46 -16
  11. package/dist/cjs/{stories/shared-utils/index.js → runtime/utils.js} +21 -12
  12. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  13. package/dist/components/DatasourceSelect.d.ts +8 -3
  14. package/dist/components/DatasourceSelect.d.ts.map +1 -1
  15. package/dist/components/DatasourceSelect.js +148 -72
  16. package/dist/components/DatasourceSelect.js.map +1 -1
  17. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js.map +1 -1
  18. package/dist/components/MultiQueryEditor/QueryEditorContainer.js +1 -1
  19. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
  20. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js.map +1 -1
  21. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js.map +1 -1
  22. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
  23. package/dist/components/PluginRegistry/plugin-indexes.d.ts +1 -1
  24. package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
  25. package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
  26. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +2 -1
  27. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
  28. package/dist/components/TimeRangeControls/TimeRangeControls.js +94 -2
  29. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  30. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  31. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +11 -7
  32. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  33. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  34. package/dist/components/Variables/variable-model.js.map +1 -1
  35. package/dist/constants/user-interface-text.d.ts +2 -0
  36. package/dist/constants/user-interface-text.d.ts.map +1 -1
  37. package/dist/constants/user-interface-text.js +3 -1
  38. package/dist/constants/user-interface-text.js.map +1 -1
  39. package/dist/model/trace-queries.d.ts +13 -1
  40. package/dist/model/trace-queries.d.ts.map +1 -1
  41. package/dist/model/trace-queries.js.map +1 -1
  42. package/dist/remote/PluginLoaderComponent.js.map +1 -1
  43. package/dist/remote/PluginRuntime.d.ts +0 -1
  44. package/dist/remote/PluginRuntime.d.ts.map +1 -1
  45. package/dist/remote/PluginRuntime.js +169 -160
  46. package/dist/remote/PluginRuntime.js.map +1 -1
  47. package/dist/remote/remotePluginLoader.js.map +1 -1
  48. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  49. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  50. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts +7 -0
  51. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts.map +1 -1
  52. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +13 -0
  53. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js.map +1 -1
  54. package/dist/runtime/plugin-registry.d.ts +2 -2
  55. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  56. package/dist/runtime/plugin-registry.js +13 -4
  57. package/dist/runtime/plugin-registry.js.map +1 -1
  58. package/dist/runtime/time-series-queries.d.ts.map +1 -1
  59. package/dist/runtime/time-series-queries.js +1 -11
  60. package/dist/runtime/time-series-queries.js.map +1 -1
  61. package/dist/runtime/trace-queries.d.ts.map +1 -1
  62. package/dist/runtime/trace-queries.js +47 -17
  63. package/dist/runtime/trace-queries.js.map +1 -1
  64. package/dist/runtime/utils.d.ts +7 -0
  65. package/dist/runtime/utils.d.ts.map +1 -0
  66. package/dist/{stories/shared-utils/index.js → runtime/utils.js} +12 -2
  67. package/dist/runtime/utils.js.map +1 -0
  68. package/dist/test-utils/mock-plugin-registry.js.map +1 -1
  69. package/package.json +7 -9
  70. package/dist/cjs/stories/shared-utils/decorators/WithDataQueries.js +0 -41
  71. package/dist/cjs/stories/shared-utils/decorators/WithPluginRegistry.js +0 -34
  72. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js +0 -42
  73. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +0 -101
  74. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemVariables.js +0 -42
  75. package/dist/cjs/stories/shared-utils/decorators/WithTimeRange.js +0 -41
  76. package/dist/cjs/stories/shared-utils/decorators/index.js +0 -35
  77. package/dist/stories/shared-utils/decorators/WithDataQueries.d.ts +0 -13
  78. package/dist/stories/shared-utils/decorators/WithDataQueries.d.ts.map +0 -1
  79. package/dist/stories/shared-utils/decorators/WithDataQueries.js +0 -33
  80. package/dist/stories/shared-utils/decorators/WithDataQueries.js.map +0 -1
  81. package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts +0 -4
  82. package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts.map +0 -1
  83. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js +0 -26
  84. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js.map +0 -1
  85. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.d.ts +0 -13
  86. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.d.ts.map +0 -1
  87. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js +0 -39
  88. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js.map +0 -1
  89. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts +0 -13
  90. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts.map +0 -1
  91. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +0 -95
  92. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js.map +0 -1
  93. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.d.ts +0 -13
  94. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.d.ts.map +0 -1
  95. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.js +0 -39
  96. package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.js.map +0 -1
  97. package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts +0 -13
  98. package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts.map +0 -1
  99. package/dist/stories/shared-utils/decorators/WithTimeRange.js +0 -33
  100. package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +0 -1
  101. package/dist/stories/shared-utils/decorators/index.d.ts +0 -7
  102. package/dist/stories/shared-utils/decorators/index.d.ts.map +0 -1
  103. package/dist/stories/shared-utils/decorators/index.js +0 -20
  104. package/dist/stories/shared-utils/decorators/index.js.map +0 -1
  105. package/dist/stories/shared-utils/index.d.ts +0 -2
  106. package/dist/stories/shared-utils/index.d.ts.map +0 -1
  107. package/dist/stories/shared-utils/index.js.map +0 -1
@@ -14,168 +14,177 @@ import { init, loadRemote } from '@module-federation/enhanced/runtime';
14
14
  import * as ReactQuery from '@tanstack/react-query';
15
15
  import React from 'react';
16
16
  import ReactDOM from 'react-dom';
17
- import * as ReactRouterDOM from 'react-router-dom';
18
17
  import * as ReactHookForm from 'react-hook-form';
19
- export const pluginRuntime = init({
20
- name: '@perses/perses-ui-host',
21
- remotes: [],
22
- shared: {
23
- react: {
24
- version: React.version,
25
- lib: ()=>React,
26
- shareConfig: {
27
- singleton: true,
28
- requiredVersion: `^${React.version}`
29
- }
30
- },
31
- 'react-dom': {
32
- version: '18.3.1',
33
- lib: ()=>ReactDOM,
34
- shareConfig: {
35
- singleton: true,
36
- requiredVersion: `^18.3.1`
37
- }
38
- },
39
- 'react-router-dom': {
40
- version: '6.26.0',
41
- lib: ()=>ReactRouterDOM,
42
- shareConfig: {
43
- singleton: true,
44
- requiredVersion: '^6.26.0'
45
- }
46
- },
47
- '@tanstack/react-query': {
48
- version: '4.36.1',
49
- lib: ()=>ReactQuery,
50
- shareConfig: {
51
- singleton: true,
52
- requiredVersion: '^4.36.1'
53
- }
54
- },
55
- 'react-hook-form': {
56
- version: '7.52.2',
57
- lib: ()=>ReactHookForm,
58
- shareConfig: {
59
- singleton: true,
60
- requiredVersion: '^7.52.2'
61
- }
62
- },
63
- echarts: {
64
- version: '5.5.0',
65
- lib: ()=>require('echarts'),
66
- shareConfig: {
67
- singleton: true,
68
- requiredVersion: '^5.5.0'
69
- }
70
- },
71
- '@perses-dev/components': {
72
- version: '0.50.0',
73
- lib: ()=>require('@perses-dev/components'),
74
- shareConfig: {
75
- singleton: true,
76
- requiredVersion: '^0.50.0'
77
- }
78
- },
79
- '@perses-dev/plugin-system': {
80
- version: '0.50.0',
81
- lib: ()=>require('@perses-dev/plugin-system'),
82
- shareConfig: {
83
- singleton: true,
84
- requiredVersion: '^0.50.0'
85
- }
86
- },
87
- '@perses-dev/explore': {
88
- version: '0.50.0',
89
- lib: ()=>require('@perses-dev/explore'),
90
- shareConfig: {
91
- singleton: true,
92
- requiredVersion: '^0.50.0'
93
- }
94
- },
95
- '@perses-dev/dashboards': {
96
- version: '0.50.0',
97
- lib: ()=>require('@perses-dev/dashboards'),
98
- shareConfig: {
99
- singleton: true,
100
- requiredVersion: '^0.50.0'
101
- }
102
- },
103
- // Below are the shared modules that are used by the plugins, this can be part of the SDK
104
- 'date-fns': {
105
- version: '2.29.3',
106
- lib: ()=>require('date-fns'),
107
- shareConfig: {
108
- singleton: true,
109
- requiredVersion: '^2.29.3'
110
- }
111
- },
112
- 'date-fns-tz': {
113
- version: '1.3.8',
114
- lib: ()=>require('date-fns-tz'),
115
- shareConfig: {
116
- singleton: true,
117
- requiredVersion: '^1.3.8'
118
- }
119
- },
120
- lodash: {
121
- version: '4.17.21',
122
- lib: ()=>require('lodash'),
123
- shareConfig: {
124
- singleton: true,
125
- requiredVersion: '^4.17.21'
126
- }
127
- },
128
- '@emotion/react': {
129
- version: '11.11.3',
130
- lib: ()=>require('@emotion/react'),
131
- shareConfig: {
132
- singleton: true,
133
- requiredVersion: '^11.11.3'
134
- }
135
- },
136
- '@emotion/styled': {
137
- version: '11.11.0',
138
- lib: ()=>require('@emotion/styled'),
139
- shareConfig: {
140
- singleton: true,
141
- requiredVersion: '^11.11.0'
142
- }
143
- },
144
- '@hookform/resolvers/zod': {
145
- version: '3.3.4',
146
- lib: ()=>require('@hookform/resolvers/zod'),
147
- shareConfig: {
148
- singleton: true,
149
- requiredVersion: '^3.3.4'
150
- }
151
- },
152
- 'use-resize-observer': {
153
- version: '9.1.0',
154
- lib: ()=>require('use-resize-observer'),
155
- shareConfig: {
156
- singleton: true,
157
- requiredVersion: '^9.1.0'
158
- }
159
- },
160
- 'mdi-material-ui': {
161
- version: '7.4.0',
162
- lib: ()=>require('mdi-material-ui'),
163
- shareConfig: {
164
- singleton: true,
165
- requiredVersion: '^7.4.0'
166
- }
167
- },
168
- immer: {
169
- version: '9.0.15',
170
- lib: ()=>require('immer'),
171
- shareConfig: {
172
- singleton: true,
173
- requiredVersion: '^9.0.15'
174
- }
175
- }
18
+ import * as ReactRouterDOM from 'react-router-dom';
19
+ let instance = null;
20
+ const getPluginRuntime = ()=>{
21
+ if (instance === null) {
22
+ const pluginRuntime = init({
23
+ name: '@perses/perses-ui-host',
24
+ remotes: [],
25
+ shared: {
26
+ react: {
27
+ version: React.version,
28
+ lib: ()=>React,
29
+ shareConfig: {
30
+ singleton: true,
31
+ requiredVersion: `^${React.version}`
32
+ }
33
+ },
34
+ 'react-dom': {
35
+ version: '18.3.1',
36
+ lib: ()=>ReactDOM,
37
+ shareConfig: {
38
+ singleton: true,
39
+ requiredVersion: `^18.3.1`
40
+ }
41
+ },
42
+ 'react-router-dom': {
43
+ version: '6.26.0',
44
+ lib: ()=>ReactRouterDOM,
45
+ shareConfig: {
46
+ singleton: true,
47
+ requiredVersion: '^6.26.0'
48
+ }
49
+ },
50
+ '@tanstack/react-query': {
51
+ version: '5.64.2',
52
+ lib: ()=>ReactQuery,
53
+ shareConfig: {
54
+ singleton: true,
55
+ requiredVersion: '^5.64.2'
56
+ }
57
+ },
58
+ 'react-hook-form': {
59
+ version: '7.52.2',
60
+ lib: ()=>ReactHookForm,
61
+ shareConfig: {
62
+ singleton: true,
63
+ requiredVersion: '^7.52.2'
64
+ }
65
+ },
66
+ echarts: {
67
+ version: '5.5.0',
68
+ lib: ()=>require('echarts'),
69
+ shareConfig: {
70
+ singleton: true,
71
+ requiredVersion: '^5.5.0'
72
+ }
73
+ },
74
+ '@perses-dev/components': {
75
+ version: '0.51.0-beta.0',
76
+ lib: ()=>require('@perses-dev/components'),
77
+ shareConfig: {
78
+ singleton: true,
79
+ requiredVersion: '^0.51.0-beta.0'
80
+ }
81
+ },
82
+ '@perses-dev/plugin-system': {
83
+ version: '0.51.0-beta.0',
84
+ lib: ()=>require('@perses-dev/plugin-system'),
85
+ shareConfig: {
86
+ singleton: true,
87
+ requiredVersion: '^0.51.0-beta.0'
88
+ }
89
+ },
90
+ '@perses-dev/explore': {
91
+ version: '0.51.0-beta.0',
92
+ lib: ()=>require('@perses-dev/explore'),
93
+ shareConfig: {
94
+ singleton: true,
95
+ requiredVersion: '^0.51.0-beta.0'
96
+ }
97
+ },
98
+ '@perses-dev/dashboards': {
99
+ version: '0.51.0-beta.0',
100
+ lib: ()=>require('@perses-dev/dashboards'),
101
+ shareConfig: {
102
+ singleton: true,
103
+ requiredVersion: '^0.51.0-beta.0'
104
+ }
105
+ },
106
+ // Below are the shared modules that are used by the plugins, this can be part of the SDK
107
+ 'date-fns': {
108
+ version: '4.1.0',
109
+ lib: ()=>require('date-fns'),
110
+ shareConfig: {
111
+ singleton: true,
112
+ requiredVersion: '^4.1.0'
113
+ }
114
+ },
115
+ 'date-fns-tz': {
116
+ version: '3.2.0',
117
+ lib: ()=>require('date-fns-tz'),
118
+ shareConfig: {
119
+ singleton: true,
120
+ requiredVersion: '^3.2.0'
121
+ }
122
+ },
123
+ lodash: {
124
+ version: '4.17.21',
125
+ lib: ()=>require('lodash'),
126
+ shareConfig: {
127
+ singleton: true,
128
+ requiredVersion: '^4.17.21'
129
+ }
130
+ },
131
+ '@emotion/react': {
132
+ version: '11.11.3',
133
+ lib: ()=>require('@emotion/react'),
134
+ shareConfig: {
135
+ singleton: true,
136
+ requiredVersion: '^11.11.3'
137
+ }
138
+ },
139
+ '@emotion/styled': {
140
+ version: '11.11.0',
141
+ lib: ()=>require('@emotion/styled'),
142
+ shareConfig: {
143
+ singleton: true,
144
+ requiredVersion: '^11.11.0'
145
+ }
146
+ },
147
+ '@hookform/resolvers/zod': {
148
+ version: '3.3.4',
149
+ lib: ()=>require('@hookform/resolvers/zod'),
150
+ shareConfig: {
151
+ singleton: true,
152
+ requiredVersion: '^3.3.4'
153
+ }
154
+ },
155
+ 'use-resize-observer': {
156
+ version: '9.1.0',
157
+ lib: ()=>require('use-resize-observer'),
158
+ shareConfig: {
159
+ singleton: true,
160
+ requiredVersion: '^9.1.0'
161
+ }
162
+ },
163
+ 'mdi-material-ui': {
164
+ version: '7.4.0',
165
+ lib: ()=>require('mdi-material-ui'),
166
+ shareConfig: {
167
+ singleton: true,
168
+ requiredVersion: '^7.4.0'
169
+ }
170
+ },
171
+ immer: {
172
+ version: '10.1.1',
173
+ lib: ()=>require('immer'),
174
+ shareConfig: {
175
+ singleton: true,
176
+ requiredVersion: '^10.1.1'
177
+ }
178
+ }
179
+ }
180
+ });
181
+ instance = pluginRuntime;
182
+ return instance;
176
183
  }
177
- });
184
+ return instance;
185
+ };
178
186
  const registerRemote = (name, baseURL)=>{
187
+ const pluginRuntime = getPluginRuntime();
179
188
  const existingRemote = pluginRuntime.options.remotes.find((remote)=>remote.name === name);
180
189
  if (!existingRemote) {
181
190
  const remoteEntryURL = baseURL ? `${baseURL}/${name}/mf-manifest.json` : `/plugins/${name}/mf-manifest.json`;
@@ -194,7 +203,7 @@ export const loadPlugin = async (moduleName, pluginName, baseURL)=>{
194
203
  };
195
204
  export function usePluginRuntime({ plugin }) {
196
205
  return {
197
- pluginRuntime,
206
+ pluginRuntime: getPluginRuntime(),
198
207
  loadPlugin: ()=>loadPlugin(plugin.moduleName, plugin.name, plugin.baseURL)
199
208
  };
200
209
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/remote/PluginRuntime.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-require-imports */\n// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { FederationHost, init, loadRemote } from '@module-federation/enhanced/runtime';\nimport * as ReactQuery from '@tanstack/react-query';\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport * as ReactRouterDOM from 'react-router-dom';\nimport * as ReactHookForm from 'react-hook-form';\nimport { PersesPlugin, RemotePluginModule } from './PersesPlugin.types';\n\nexport const pluginRuntime = init({\n name: '@perses/perses-ui-host',\n remotes: [], // all remotes are loaded dynamically\n shared: {\n react: {\n version: React.version,\n lib: () => React,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n version: '18.3.1',\n lib: () => ReactDOM,\n shareConfig: {\n singleton: true,\n requiredVersion: `^18.3.1`,\n },\n },\n 'react-router-dom': {\n version: '6.26.0',\n lib: () => ReactRouterDOM,\n shareConfig: {\n singleton: true,\n requiredVersion: '^6.26.0',\n },\n },\n '@tanstack/react-query': {\n version: '4.36.1',\n lib: () => ReactQuery,\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.36.1',\n },\n },\n 'react-hook-form': {\n version: '7.52.2',\n lib: () => ReactHookForm,\n shareConfig: {\n singleton: true,\n requiredVersion: '^7.52.2',\n },\n },\n echarts: {\n version: '5.5.0',\n lib: () => require('echarts'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^5.5.0',\n },\n },\n '@perses-dev/components': {\n version: '0.50.0',\n lib: () => require('@perses-dev/components'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.50.0',\n },\n },\n '@perses-dev/plugin-system': {\n version: '0.50.0',\n lib: () => require('@perses-dev/plugin-system'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.50.0',\n },\n },\n '@perses-dev/explore': {\n version: '0.50.0',\n lib: () => require('@perses-dev/explore'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.50.0',\n },\n },\n '@perses-dev/dashboards': {\n version: '0.50.0',\n lib: () => require('@perses-dev/dashboards'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.50.0',\n },\n },\n // Below are the shared modules that are used by the plugins, this can be part of the SDK\n 'date-fns': {\n version: '2.29.3',\n lib: () => require('date-fns'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^2.29.3',\n },\n },\n 'date-fns-tz': {\n version: '1.3.8',\n lib: () => require('date-fns-tz'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^1.3.8',\n },\n },\n lodash: {\n version: '4.17.21',\n lib: () => require('lodash'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.17.21',\n },\n },\n '@emotion/react': {\n version: '11.11.3',\n lib: () => require('@emotion/react'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^11.11.3',\n },\n },\n '@emotion/styled': {\n version: '11.11.0',\n lib: () => require('@emotion/styled'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^11.11.0',\n },\n },\n '@hookform/resolvers/zod': {\n version: '3.3.4',\n lib: () => require('@hookform/resolvers/zod'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^3.3.4',\n },\n },\n 'use-resize-observer': {\n version: '9.1.0',\n lib: () => require('use-resize-observer'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^9.1.0',\n },\n },\n 'mdi-material-ui': {\n version: '7.4.0',\n lib: () => require('mdi-material-ui'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^7.4.0',\n },\n },\n immer: {\n version: '9.0.15',\n lib: () => require('immer'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^9.0.15',\n },\n },\n },\n});\n\nconst registerRemote = (name: string, baseURL?: string): void => {\n const existingRemote = pluginRuntime.options.remotes.find((remote) => remote.name === name);\n if (!existingRemote) {\n const remoteEntryURL = baseURL ? `${baseURL}/${name}/mf-manifest.json` : `/plugins/${name}/mf-manifest.json`;\n pluginRuntime.registerRemotes([\n {\n name,\n entry: remoteEntryURL,\n alias: name,\n },\n ]);\n }\n};\n\nexport const loadPlugin = async (\n moduleName: string,\n pluginName: string,\n baseURL?: string\n): Promise<RemotePluginModule | null> => {\n registerRemote(moduleName, baseURL);\n\n return loadRemote<RemotePluginModule>(`${moduleName}/${pluginName}`);\n};\n\nexport function usePluginRuntime({ plugin }: { plugin: PersesPlugin }): {\n pluginRuntime: FederationHost;\n loadPlugin: () => Promise<RemotePluginModule | null>;\n} {\n return {\n pluginRuntime,\n loadPlugin: () => loadPlugin(plugin.moduleName, plugin.name, plugin.baseURL),\n };\n}\n"],"names":["init","loadRemote","ReactQuery","React","ReactDOM","ReactRouterDOM","ReactHookForm","pluginRuntime","name","remotes","shared","react","version","lib","shareConfig","singleton","requiredVersion","echarts","require","lodash","immer","registerRemote","baseURL","existingRemote","options","find","remote","remoteEntryURL","registerRemotes","entry","alias","loadPlugin","moduleName","pluginName","usePluginRuntime","plugin"],"mappings":"AAAA,wDAAwD,GACxD,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAyBA,IAAI,EAAEC,UAAU,QAAQ,sCAAsC;AACvF,YAAYC,gBAAgB,wBAAwB;AACpD,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,cAAc,YAAY;AACjC,YAAYC,oBAAoB,mBAAmB;AACnD,YAAYC,mBAAmB,kBAAkB;AAGjD,OAAO,MAAMC,gBAAgBP,KAAK;IAChCQ,MAAM;IACNC,SAAS,EAAE;IACXC,QAAQ;QACNC,OAAO;YACLC,SAAST,MAAMS,OAAO;YACtBC,KAAK,IAAMV;YACXW,aAAa;gBACXC,WAAW;gBACXC,iBAAiB,CAAC,CAAC,EAAEb,MAAMS,OAAO,CAAC,CAAC;YACtC;QACF;QACA,aAAa;YACXA,SAAS;YACTC,KAAK,IAAMT;YACXU,aAAa;gBACXC,WAAW;gBACXC,iBAAiB,CAAC,OAAO,CAAC;YAC5B;QACF;QACA,oBAAoB;YAClBJ,SAAS;YACTC,KAAK,IAAMR;YACXS,aAAa;gBACXC,WAAW;gBACXC,iBAAiB;YACnB;QACF;QACA,yBAAyB;YACvBJ,SAAS;YACTC,KAAK,IAAMX;YACXY,aAAa;gBACXC,WAAW;gBACXC,iBAAiB;YACnB;QACF;QACA,mBAAmB;YACjBJ,SAAS;YACTC,KAAK,IAAMP;YACXQ,aAAa;gBACXC,WAAW;gBACXC,iBAAiB;YACnB;QACF;QACAC,SAAS;YACPL,SAAS;YACTC,KAAK,IAAMK,QAAQ;YACn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AiB;YACnB;QACF;QACA,mBAAmB;YACjBJ,SAAS;YACTC,KAAK,IAAMK,QAAQ;YACnBJ,aAAa;gBACXC,WAAW;gBACXC,iBAAiB;YACnB;QACF;QACAI,OAAO;YACLR,SAAS;YACTC,KAAK,IAAMK,QAAQ;YACnBJ,aAAa;gBACXC,WAAW;gBACXC,iBAAiB;YACnB;QACF;IACF;AACF,GAAG;AAEH,MAAMK,iBAAiB,CAACb,MAAcc;IACpC,MAAMC,iBAAiBhB,cAAciB,OAAO,CAACf,OAAO,CAACgB,IAAI,CAAC,CAACC,SAAWA,OAAOlB,IAAI,KAAKA;IACtF,IAAI,CAACe,gBAAgB;QACnB,MAAMI,iBAAiBL,UAAU,CAAC,EAAEA,QAAQ,CAAC,EAAEd,KAAK,iBAAiB,CAAC,GAAG,CAAC,SAAS,EAAEA,KAAK,iBAAiB,CAAC;QAC5GD,cAAcqB,eAAe,CAAC;YAC5B;gBACEpB;gBACAqB,OAAOF;gBACPG,OAAOtB;YACT;SACD;IACH;AACF;AAEA,OAAO,MAAMuB,aAAa,OACxBC,YACAC,YACAX;IAEAD,eAAeW,YAAYV;IAE3B,OAAOrB,WAA+B,CAAC,EAAE+B,WAAW,CAAC,EAAEC,WAAW,CAAC;AACrE,EAAE;AAEF,OAAO,SAASC,iBAAiB,EAAEC,MAAM,EAA4B;IAInE,OAAO;QACL5B;QACAwB,YAAY,IAAMA,WAAWI,OAAOH,UAAU,EAAEG,OAAO3B,IAAI,EAAE2B,OAAOb,OAAO;IAC7E;AACF"}
1
+ {"version":3,"sources":["../../src/remote/PluginRuntime.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-require-imports */\n// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { FederationHost, init, loadRemote } from '@module-federation/enhanced/runtime';\nimport * as ReactQuery from '@tanstack/react-query';\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport * as ReactHookForm from 'react-hook-form';\nimport * as ReactRouterDOM from 'react-router-dom';\nimport { PersesPlugin, RemotePluginModule } from './PersesPlugin.types';\n\nlet instance: FederationHost | null = null;\n\nconst getPluginRuntime = (): FederationHost => {\n if (instance === null) {\n const pluginRuntime = init({\n name: '@perses/perses-ui-host',\n remotes: [], // all remotes are loaded dynamically\n shared: {\n react: {\n version: React.version,\n lib: () => React,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n version: '18.3.1',\n lib: () => ReactDOM,\n shareConfig: {\n singleton: true,\n requiredVersion: `^18.3.1`,\n },\n },\n 'react-router-dom': {\n version: '6.26.0',\n lib: () => ReactRouterDOM,\n shareConfig: {\n singleton: true,\n requiredVersion: '^6.26.0',\n },\n },\n '@tanstack/react-query': {\n version: '5.64.2',\n lib: () => ReactQuery,\n shareConfig: {\n singleton: true,\n requiredVersion: '^5.64.2',\n },\n },\n 'react-hook-form': {\n version: '7.52.2',\n lib: () => ReactHookForm,\n shareConfig: {\n singleton: true,\n requiredVersion: '^7.52.2',\n },\n },\n echarts: {\n version: '5.5.0',\n lib: () => require('echarts'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^5.5.0',\n },\n },\n '@perses-dev/components': {\n version: '0.51.0-beta.0',\n lib: () => require('@perses-dev/components'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.51.0-beta.0',\n },\n },\n '@perses-dev/plugin-system': {\n version: '0.51.0-beta.0',\n lib: () => require('@perses-dev/plugin-system'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.51.0-beta.0',\n },\n },\n '@perses-dev/explore': {\n version: '0.51.0-beta.0',\n lib: () => require('@perses-dev/explore'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.51.0-beta.0',\n },\n },\n '@perses-dev/dashboards': {\n version: '0.51.0-beta.0',\n lib: () => require('@perses-dev/dashboards'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.51.0-beta.0',\n },\n },\n // Below are the shared modules that are used by the plugins, this can be part of the SDK\n 'date-fns': {\n version: '4.1.0',\n lib: () => require('date-fns'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.1.0',\n },\n },\n 'date-fns-tz': {\n version: '3.2.0',\n lib: () => require('date-fns-tz'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^3.2.0',\n },\n },\n lodash: {\n version: '4.17.21',\n lib: () => require('lodash'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.17.21',\n },\n },\n '@emotion/react': {\n version: '11.11.3',\n lib: () => require('@emotion/react'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^11.11.3',\n },\n },\n '@emotion/styled': {\n version: '11.11.0',\n lib: () => require('@emotion/styled'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^11.11.0',\n },\n },\n '@hookform/resolvers/zod': {\n version: '3.3.4',\n lib: () => require('@hookform/resolvers/zod'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^3.3.4',\n },\n },\n 'use-resize-observer': {\n version: '9.1.0',\n lib: () => require('use-resize-observer'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^9.1.0',\n },\n },\n 'mdi-material-ui': {\n version: '7.4.0',\n lib: () => require('mdi-material-ui'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^7.4.0',\n },\n },\n immer: {\n version: '10.1.1',\n lib: () => require('immer'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^10.1.1',\n },\n },\n },\n });\n\n instance = pluginRuntime;\n\n return instance;\n }\n return instance;\n};\n\nconst registerRemote = (name: string, baseURL?: string): void => {\n const pluginRuntime = getPluginRuntime();\n const existingRemote = pluginRuntime.options.remotes.find((remote) => remote.name === name);\n if (!existingRemote) {\n const remoteEntryURL = baseURL ? `${baseURL}/${name}/mf-manifest.json` : `/plugins/${name}/mf-manifest.json`;\n pluginRuntime.registerRemotes([\n {\n name,\n entry: remoteEntryURL,\n alias: name,\n },\n ]);\n }\n};\n\nexport const loadPlugin = async (\n moduleName: string,\n pluginName: string,\n baseURL?: string\n): Promise<RemotePluginModule | null> => {\n registerRemote(moduleName, baseURL);\n\n return loadRemote<RemotePluginModule>(`${moduleName}/${pluginName}`);\n};\n\nexport function usePluginRuntime({ plugin }: { plugin: PersesPlugin }): {\n pluginRuntime: FederationHost;\n loadPlugin: () => Promise<RemotePluginModule | null>;\n} {\n return {\n pluginRuntime: getPluginRuntime(),\n loadPlugin: () => loadPlugin(plugin.moduleName, plugin.name, plugin.baseURL),\n };\n}\n"],"names":["init","loadRemote","ReactQuery","React","ReactDOM","ReactHookForm","ReactRouterDOM","instance","getPluginRuntime","pluginRuntime","name","remotes","shared","react","version","lib","shareConfig","singleton","requiredVersion","echarts","require","lodash","immer","registerRemote","baseURL","existingRemote","options","find","remote","remoteEntryURL","registerRemotes","entry","alias","loadPlugin","moduleName","pluginName","usePluginRuntime","plugin"],"mappings":"AAAA,wDAAwD,GACxD,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAyBA,IAAI,EAAEC,UAAU,QAAQ,sCAAsC;AACvF,YAAYC,gBAAgB,wBAAwB;AACpD,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,cAAc,YAAY;AACjC,YAAYC,mBAAmB,kBAAkB;AACjD,YAAYC,oBAAoB,mBAAmB;AAGnD,IAAIC,WAAkC;AAEtC,MAAMC,mBAAmB;IACvB,IAAID,aAAa,MAAM;QACrB,MAAME,gBAAgBT,KAAK;YACzBU,MAAM;YACNC,SAAS,EAAE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e,gBAAgB;QACnB,MAAMI,iBAAiBL,UAAU,GAAGA,QAAQ,CAAC,EAAEd,KAAK,iBAAiB,CAAC,GAAG,CAAC,SAAS,EAAEA,KAAK,iBAAiB,CAAC;QAC5GD,cAAcqB,eAAe,CAAC;YAC5B;gBACEpB;gBACAqB,OAAOF;gBACPG,OAAOtB;YACT;SACD;IACH;AACF;AAEA,OAAO,MAAMuB,aAAa,OACxBC,YACAC,YACAX;IAEAD,eAAeW,YAAYV;IAE3B,OAAOvB,WAA+B,GAAGiC,WAAW,CAAC,EAAEC,YAAY;AACrE,EAAE;AAEF,OAAO,SAASC,iBAAiB,EAAEC,MAAM,EAA4B;IAInE,OAAO;QACL5B,eAAeD;QACfyB,YAAY,IAAMA,WAAWI,OAAOH,UAAU,EAAEG,OAAO3B,IAAI,EAAE2B,OAAOb,OAAO;IAC7E;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/remote/remotePluginLoader.ts"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PluginLoader, PluginMetadata, PluginModuleResource } from '@perses-dev/plugin-system';\nimport { RemotePluginModule } from './PersesPlugin.types';\nimport { loadPlugin } from './PluginRuntime';\n\nconst isPluginMetadata = (plugin: unknown): plugin is PluginMetadata => {\n return (\n typeof plugin === 'object' &&\n plugin !== null &&\n 'kind' in plugin &&\n 'spec' in plugin &&\n typeof plugin.spec === 'object' &&\n plugin.spec !== null &&\n 'name' in plugin.spec\n );\n};\n\nconst isPluginModuleResource = (pluginModule: unknown): pluginModule is PluginModuleResource => {\n return (\n typeof pluginModule === 'object' &&\n pluginModule !== null &&\n 'metadata' in pluginModule &&\n 'spec' in pluginModule &&\n typeof pluginModule.spec === 'object' &&\n pluginModule.spec !== null &&\n 'plugins' in pluginModule.spec &&\n Array.isArray(pluginModule.spec.plugins) &&\n pluginModule.spec.plugins.every(isPluginMetadata)\n );\n};\n\nexport const remotePluginLoader = (baseURL?: string): PluginLoader => {\n return {\n getInstalledPlugins: async (): Promise<PluginModuleResource[]> => {\n const pluginsResponse = await fetch(`${baseURL ? baseURL : ''}/api/v1/plugins`);\n\n const plugins = await pluginsResponse.json();\n\n let pluginModules: PluginModuleResource[] = [];\n\n if (Array.isArray(plugins)) {\n pluginModules = plugins.filter(isPluginModuleResource);\n } else {\n console.error('RemotePluginLoader: Error loading plugins, response is not an array');\n }\n\n if (!pluginModules.length) {\n console.error('RemotePluginLoader: No valid plugins found');\n }\n\n return pluginModules;\n },\n importPluginModule: async (resource): Promise<RemotePluginModule> => {\n const pluginModuleName = resource.metadata.name;\n\n const pluginModule: RemotePluginModule = {};\n\n for (const plugin of resource.spec.plugins) {\n const remotePluginModule = await loadPlugin(pluginModuleName, plugin.spec.name);\n\n const remotePlugin = remotePluginModule?.[plugin.spec.name];\n if (remotePlugin) {\n pluginModule[plugin.spec.name] = remotePlugin;\n } else {\n console.error(`RemotePluginLoader: Error loading plugin ${plugin.spec.name}`);\n }\n }\n\n return pluginModule;\n },\n };\n};\n"],"names":["loadPlugin","isPluginMetadata","plugin","spec","isPluginModuleResource","pluginModule","Array","isArray","plugins","every","remotePluginLoader","baseURL","getInstalledPlugins","pluginsResponse","fetch","json","pluginModules","filter","console","error","length","importPluginModule","resource","pluginModuleName","metadata","name","remotePluginModule","remotePlugin"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAAS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;gBAC3D,IAAIE,cAAc;oBAChBtB,YAAY,CAACH,OAAOC,IAAI,CAACsB,IAAI,CAAC,GAAGE;gBACnC,OAAO;oBACLT,QAAQC,KAAK,CAAC,CAAC,yCAAyC,EAAEjB,OAAOC,IAAI,CAACsB,IAAI,CAAC,CAAC;gBAC9E;YACF;YAEA,OAAOpB;QACT;IACF;AACF,EAAE"}
1
+ {"version":3,"sources":["../../src/remote/remotePluginLoader.ts"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PluginLoader, PluginMetadata, PluginModuleResource } from '@perses-dev/plugin-system';\nimport { RemotePluginModule } from './PersesPlugin.types';\nimport { loadPlugin } from './PluginRuntime';\n\nconst isPluginMetadata = (plugin: unknown): plugin is PluginMetadata => {\n return (\n typeof plugin === 'object' &&\n plugin !== null &&\n 'kind' in plugin &&\n 'spec' in plugin &&\n typeof plugin.spec === 'object' &&\n plugin.spec !== null &&\n 'name' in plugin.spec\n );\n};\n\nconst isPluginModuleResource = (pluginModule: unknown): pluginModule is PluginModuleResource => {\n return (\n typeof pluginModule === 'object' &&\n pluginModule !== null &&\n 'metadata' in pluginModule &&\n 'spec' in pluginModule &&\n typeof pluginModule.spec === 'object' &&\n pluginModule.spec !== null &&\n 'plugins' in pluginModule.spec &&\n Array.isArray(pluginModule.spec.plugins) &&\n pluginModule.spec.plugins.every(isPluginMetadata)\n );\n};\n\nexport const remotePluginLoader = (baseURL?: string): PluginLoader => {\n return {\n getInstalledPlugins: async (): Promise<PluginModuleResource[]> => {\n const pluginsResponse = await fetch(`${baseURL ? baseURL : ''}/api/v1/plugins`);\n\n const plugins = await pluginsResponse.json();\n\n let pluginModules: PluginModuleResource[] = [];\n\n if (Array.isArray(plugins)) {\n pluginModules = plugins.filter(isPluginModuleResource);\n } else {\n console.error('RemotePluginLoader: Error loading plugins, response is not an array');\n }\n\n if (!pluginModules.length) {\n console.error('RemotePluginLoader: No valid plugins found');\n }\n\n return pluginModules;\n },\n importPluginModule: async (resource): Promise<RemotePluginModule> => {\n const pluginModuleName = resource.metadata.name;\n\n const pluginModule: RemotePluginModule = {};\n\n for (const plugin of resource.spec.plugins) {\n const remotePluginModule = await loadPlugin(pluginModuleName, plugin.spec.name);\n\n const remotePlugin = remotePluginModule?.[plugin.spec.name];\n if (remotePlugin) {\n pluginModule[plugin.spec.name] = remotePlugin;\n } else {\n console.error(`RemotePluginLoader: Error loading plugin ${plugin.spec.name}`);\n }\n }\n\n return pluginModule;\n },\n };\n};\n"],"names":["loadPlugin","isPluginMetadata","plugin","spec","isPluginModuleResource","pluginModule","Array","isArray","plugins","every","remotePluginLoader","baseURL","getInstalledPlugins","pluginsResponse","fetch","json","pluginModules","filter","console","error","length","importPluginModule","resource","pluginModuleName","metadata","name","remotePluginModule","remotePlugin"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,UAAU,QAAQ,kBAAkB;AAE7C,MAAMC,mBAAmB,CAACC;IACxB,OACE,OAAOA,WAAW,YAClBA,WAAW,QACX,UAAUA,UACV,UAAUA,UACV,OAAOA,OAAOC,IAAI,KAAK,YACvBD,OAAOC,IAAI,KAAK,QAChB,UAAUD,OAAOC,IAAI;AAEzB;AAEA,MAAMC,yBAAyB,CAACC;IAC9B,OACE,OAAOA,iBAAiB,YACxBA,iBAAiB,QACjB,cAAcA,gBACd,UAAUA,gBACV,OAAOA,aAAaF,IAAI,KAAK,YAC7BE,aAAaF,IAAI,KAAK,QACtB,aAAaE,aAAaF,IAAI,IAC9BG,MAAMC,OAAO,CAACF,aAAaF,IAAI,CAACK,OAAO,KACvCH,aAAaF,IAAI,CAACK,OAAO,CAACC,KAAK,CAACR;AAEpC;AAEA,OAAO,MAAMS,qBAAqB,CAACC;IACjC,OAAO;QACLC,qBAAqB;YACnB,MAAMC,kBAAkB,MAAMC,MAAM,GAAGH,UAAUA,UAAU,GAAG,eAAe,CAAC;YAE9E,MAAMH,UAAU,MAAMK,gBAAgBE,IAAI;YAE1C,IAAIC,gBAAwC,EAAE;YAE9C,IAAIV,MAAMC,OAAO,CAACC,UAAU;gBAC1BQ,gBAAgBR,QAAQS,MAAM,CAACb;YACjC,OAAO;gBACLc,QAAQC,KAAK,CAAC;YAChB;YAEA,IAAI,CAACH,cAAcI,MAAM,EAAE;gBACzBF,QAAQC,KAAK,CAAC;YAChB;YAEA,OAAOH;QACT;QACAK,oBAAoB,OAAOC;YACzB,MAAMC,mBAAmBD,SAASE,QAAQ,CAACC,IAAI;YAE/C,MAAMpB,eAAmC,CAAC;YAE1C,KAAK,MAAMH,UAAUoB,SAASnB,IAAI,CAACK,OAAO,CAAE;gBAC1C,MAAMkB,qBAAqB,MAAM1B,WAAWuB,kBAAkBrB,OAAOC,IAAI,CAACsB,IAAI;gBAE9E,MAAME,eAAeD,oBAAoB,CAACxB,OAAOC,IAAI,CAACsB,IAAI,CAAC;gBAC3D,IAAIE,cAAc;oBAChBtB,YAAY,CAACH,OAAOC,IAAI,CAACsB,IAAI,CAAC,GAAGE;gBACnC,OAAO;oBACLT,QAAQC,KAAK,CAAC,CAAC,yCAAyC,EAAEjB,OAAOC,IAAI,CAACsB,IAAI,EAAE;gBAC9E;YACF;YAEA,OAAOpB;QACT;IACF;AACF,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/DataQueriesProvider/model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, QueryDefinition, UnknownSpec, QueryDataType } from '@perses-dev/core';\nimport { QueryObserverOptions, UseQueryResult } from '@tanstack/react-query';\nimport { ReactNode, useCallback, useMemo } from 'react';\nimport { useListPluginMetadata } from '../plugin-registry';\n\nexport type QueryOptions = Record<string, unknown>;\nexport interface DataQueriesProviderProps<QueryPluginSpec = UnknownSpec> {\n definitions: Array<Definition<QueryPluginSpec>>;\n children?: ReactNode;\n options?: QueryOptions;\n queryOptions?: Omit<QueryObserverOptions, 'queryKey'>;\n}\n\nexport interface DataQueriesContextType {\n queryResults: QueryData[];\n refetchAll: () => void;\n isFetching: boolean;\n isLoading: boolean;\n errors: unknown[];\n}\n\nexport interface UseDataQueryResults<T> extends Omit<DataQueriesContextType, 'queryResults'> {\n queryResults: Array<QueryData<T>>;\n}\n\nexport type QueryData<T = QueryDataType> = {\n data?: T;\n definition: QueryDefinition;\n error: unknown;\n isFetching: boolean;\n isLoading: boolean;\n refetch?: () => void;\n};\n\nexport function transformQueryResults(results: UseQueryResult[], definitions: QueryDefinition[]): QueryData[] {\n return results.map(({ data, isFetching, isLoading, refetch, error }, i) => {\n return {\n definition: definitions[i],\n data,\n isFetching,\n isLoading,\n refetch,\n error,\n } as QueryData;\n });\n}\n\nexport function useQueryType(): (pluginKind: string) => string | undefined {\n const { data: timeSeriesQueryPlugins, isLoading: isTimeSeriesQueryLoading } = useListPluginMetadata([\n 'TimeSeriesQuery',\n ]);\n const { data: traceQueryPlugins, isLoading: isTraceQueryPluginLoading } = useListPluginMetadata(['TraceQuery']);\n\n // For example, `map: {\"TimeSeriesQuery\":[\"PrometheusTimeSeriesQuery\"],\"TraceQuery\":[\"TempoTraceQuery\"]}`\n const queryTypeMap = useMemo(() => {\n const map: Record<string, string[]> = {\n TimeSeriesQuery: [],\n TraceQuery: [],\n };\n\n if (timeSeriesQueryPlugins) {\n timeSeriesQueryPlugins.forEach((plugin) => {\n map[plugin.kind]?.push(plugin.spec.name);\n });\n }\n\n if (traceQueryPlugins) {\n traceQueryPlugins.forEach((plugin) => {\n map[plugin.kind]?.push(plugin.spec.name);\n });\n }\n return map;\n }, [timeSeriesQueryPlugins, traceQueryPlugins]);\n\n const getQueryType = useCallback(\n (pluginKind: string) => {\n const isLoading = (pluginKind: string): boolean => {\n switch (pluginKind) {\n case 'PrometheusTimeSeriesQuery':\n return isTimeSeriesQueryLoading;\n case 'TempoTraceQuery':\n return isTraceQueryPluginLoading;\n }\n\n return isTraceQueryPluginLoading || isTimeSeriesQueryLoading;\n };\n\n if (isLoading(pluginKind)) {\n return undefined;\n }\n\n for (const queryType in queryTypeMap) {\n if (queryTypeMap[queryType]?.includes(pluginKind)) {\n return queryType;\n }\n }\n\n throw new Error(`Unable to determine the query type: ${pluginKind}`);\n },\n [queryTypeMap, isTimeSeriesQueryLoading, isTraceQueryPluginLoading]\n );\n\n return getQueryType;\n}\n"],"names":["useCallback","useMemo","useListPluginMetadata","transformQueryResults","results","definitions","map","data","isFetching","isLoading","refetch","error","i","definition","useQueryType","timeSeriesQueryPlugins","isTimeSeriesQueryLoading","traceQueryPlugins","isTraceQueryPluginLoading","queryTypeMap","TimeSeriesQuery","TraceQuery","forEach","plugin","kind","push","spec","name","getQueryType","pluginKind","undefined","queryType","includes","Error"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAAoBA,WAAW,E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IA,YAAY,CAACY,UAAU,EAAEC,SAASH,aAAa;gBACjD,OAAOE;YACT;QACF;QAEA,MAAM,IAAIE,MAAM,CAAC,oCAAoC,EAAEJ,WAAW,CAAC;IACrE,GACA;QAACV;QAAcH;QAA0BE;KAA0B;IAGrE,OAAOU;AACT"}
1
+ {"version":3,"sources":["../../../src/runtime/DataQueriesProvider/model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, QueryDefinition, UnknownSpec, QueryDataType } from '@perses-dev/core';\nimport { QueryObserverOptions, UseQueryResult } from '@tanstack/react-query';\nimport { ReactNode, useCallback, useMemo } from 'react';\nimport { useListPluginMetadata } from '../plugin-registry';\n\nexport type QueryOptions = Record<string, unknown>;\nexport interface DataQueriesProviderProps<QueryPluginSpec = UnknownSpec> {\n definitions: Array<Definition<QueryPluginSpec>>;\n children?: ReactNode;\n options?: QueryOptions;\n queryOptions?: Omit<QueryObserverOptions, 'queryKey'>;\n}\n\nexport interface DataQueriesContextType {\n queryResults: QueryData[];\n refetchAll: () => void;\n isFetching: boolean;\n isLoading: boolean;\n errors: unknown[];\n}\n\nexport interface UseDataQueryResults<T> extends Omit<DataQueriesContextType, 'queryResults'> {\n queryResults: Array<QueryData<T>>;\n}\n\nexport type QueryData<T = QueryDataType> = {\n data?: T;\n definition: QueryDefinition;\n error: unknown;\n isFetching: boolean;\n isLoading: boolean;\n refetch?: () => void;\n};\n\nexport function transformQueryResults(results: UseQueryResult[], definitions: QueryDefinition[]): QueryData[] {\n return results.map(({ data, isFetching, isLoading, refetch, error }, i) => {\n return {\n definition: definitions[i],\n data,\n isFetching,\n isLoading,\n refetch,\n error,\n } as QueryData;\n });\n}\n\nexport function useQueryType(): (pluginKind: string) => string | undefined {\n const { data: timeSeriesQueryPlugins, isLoading: isTimeSeriesQueryLoading } = useListPluginMetadata([\n 'TimeSeriesQuery',\n ]);\n const { data: traceQueryPlugins, isLoading: isTraceQueryPluginLoading } = useListPluginMetadata(['TraceQuery']);\n\n // For example, `map: {\"TimeSeriesQuery\":[\"PrometheusTimeSeriesQuery\"],\"TraceQuery\":[\"TempoTraceQuery\"]}`\n const queryTypeMap = useMemo(() => {\n const map: Record<string, string[]> = {\n TimeSeriesQuery: [],\n TraceQuery: [],\n };\n\n if (timeSeriesQueryPlugins) {\n timeSeriesQueryPlugins.forEach((plugin) => {\n map[plugin.kind]?.push(plugin.spec.name);\n });\n }\n\n if (traceQueryPlugins) {\n traceQueryPlugins.forEach((plugin) => {\n map[plugin.kind]?.push(plugin.spec.name);\n });\n }\n return map;\n }, [timeSeriesQueryPlugins, traceQueryPlugins]);\n\n const getQueryType = useCallback(\n (pluginKind: string) => {\n const isLoading = (pluginKind: string): boolean => {\n switch (pluginKind) {\n case 'PrometheusTimeSeriesQuery':\n return isTimeSeriesQueryLoading;\n case 'TempoTraceQuery':\n return isTraceQueryPluginLoading;\n }\n\n return isTraceQueryPluginLoading || isTimeSeriesQueryLoading;\n };\n\n if (isLoading(pluginKind)) {\n return undefined;\n }\n\n for (const queryType in queryTypeMap) {\n if (queryTypeMap[queryType]?.includes(pluginKind)) {\n return queryType;\n }\n }\n\n throw new Error(`Unable to determine the query type: ${pluginKind}`);\n },\n [queryTypeMap, isTimeSeriesQueryLoading, isTraceQueryPluginLoading]\n );\n\n return getQueryType;\n}\n"],"names":["useCallback","useMemo","useListPluginMetadata","transformQueryResults","results","definitions","map","data","isFetching","isLoading","refetch","error","i","definition","useQueryType","timeSeriesQueryPlugins","isTimeSeriesQueryLoading","traceQueryPlugins","isTraceQueryPluginLoading","queryTypeMap","TimeSeriesQuery","TraceQuery","forEach","plugin","kind","push","spec","name","getQueryType","pluginKind","undefined","queryType","includes","Error"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAAoBA,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AACxD,SAASC,qBAAqB,QAAQ,qBAAqB;AA+B3D,OAAO,SAASC,sBAAsBC,OAAyB,EAAEC,WAA8B;IAC7F,OAAOD,QAAQE,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,KAAK,EAAE,EAAEC;QACnE,OAAO;YACLC,YAAYR,WAAW,CAACO,EAAE;YAC1BL;YACAC;YACAC;YACAC;YACAC;QACF;IACF;AACF;AAEA,OAAO,SAASG;IACd,MAAM,EAAEP,MAAMQ,sBAAsB,EAAEN,WAAWO,wBAAwB,EAAE,GAAGd,sBAAsB;QAClG;KACD;IACD,MAAM,EAAEK,MAAMU,iBAAiB,EAAER,WAAWS,yBAAyB,EAAE,GAAGhB,sBAAsB;QAAC;KAAa;IAE9G,yGAAyG;IACzG,MAAMiB,eAAelB,QAAQ;QAC3B,MAAMK,MAAgC;YACpCc,iBAAiB,EAAE;YACnBC,YAAY,EAAE;QAChB;QAEA,IAAIN,wBAAwB;YAC1BA,uBAAuBO,OAAO,CAAC,CAACC;gBAC9BjB,GAAG,CAACiB,OAAOC,IAAI,CAAC,EAAEC,KAAKF,OAAOG,IAAI,CAACC,IAAI;YACzC;QACF;QAEA,IAAIV,mBAAmB;YACrBA,kBAAkBK,OAAO,CAAC,CAACC;gBACzBjB,GAAG,CAACiB,OAAOC,IAAI,CAAC,EAAEC,KAAKF,OAAOG,IAAI,CAACC,IAAI;YACzC;QACF;QACA,OAAOrB;IACT,GAAG;QAACS;QAAwBE;KAAkB;IAE9C,MAAMW,eAAe5B,YACnB,CAAC6B;QACC,MAAMpB,YAAY,CAACoB;YACjB,OAAQA;gBACN,KAAK;oBACH,OAAOb;gBACT,KAAK;oBACH,OAAOE;YACX;YAEA,OAAOA,6BAA6BF;QACtC;QAEA,IAAIP,UAAUoB,aAAa;YACzB,OAAOC;QACT;QAEA,IAAK,MAAMC,aAAaZ,aAAc;YACpC,IAAIA,YAAY,CAACY,UAAU,EAAEC,SAASH,aAAa;gBACjD,OAAOE;YACT;QACF;QAEA,MAAM,IAAIE,MAAM,CAAC,oCAAoC,EAAEJ,YAAY;IACrE,GACA;QAACV;QAAcH;QAA0BE;KAA0B;IAGrE,OAAOU;AACT"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProvider.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { createContext, ReactElement, useCallback, useContext, useEffect, useMemo, useState } from 'react';\nimport {\n AbsoluteTimeRange,\n DurationString,\n TimeRangeValue,\n isRelativeTimeRange,\n toAbsoluteTimeRange,\n getSuggestedStepMs,\n} from '@perses-dev/core';\nimport { getRefreshIntervalInMs } from './refresh-interval';\n\nexport interface TimeRangeProviderProps {\n timeRange: TimeRangeValue;\n refreshInterval?: DurationString;\n setTimeRange?: (value: TimeRangeValue) => void;\n setRefreshInterval?: (value: DurationString) => void;\n children?: React.ReactNode;\n}\n\nexport interface TimeRange {\n timeRange: TimeRangeValue;\n absoluteTimeRange: AbsoluteTimeRange; // resolved absolute time for plugins to use\n setTimeRange: (value: TimeRangeValue) => void;\n refresh: () => void;\n refreshKey: string;\n refreshInterval?: DurationString;\n refreshIntervalInMs: number;\n setRefreshInterval: (value: DurationString) => void;\n}\n\nexport const TimeRangeContext = createContext<TimeRange | undefined>(undefined);\n\nexport function useTimeRangeContext(): TimeRange {\n const ctx = useContext(TimeRangeContext);\n if (ctx === undefined) {\n throw new Error('No TimeRangeContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Get and set the current resolved time range at runtime.\n */\nexport function useTimeRange(): TimeRange {\n return useTimeRangeContext();\n}\n\n/**\n * Gets the suggested step for a graph query in ms for the currently selected time range.\n */\nexport function useSuggestedStepMs(width?: number): number {\n const { absoluteTimeRange } = useTimeRange();\n if (width === undefined) return 0;\n return getSuggestedStepMs(absoluteTimeRange, width);\n}\n\n/**\n * Provider implementation that supplies the time range state at runtime.\n */\nexport function TimeRangeProvider(props: TimeRangeProviderProps): ReactElement {\n const { timeRange, refreshInterval, children, setTimeRange, setRefreshInterval } = props;\n\n const [localTimeRange, setLocalTimeRange] = useState<TimeRangeValue>(timeRange);\n const [localRefreshInterval, setLocalRefreshInterval] = useState<DurationString | undefined>(refreshInterval);\n\n const [refreshCounter, setRefreshCounter] = useState(0);\n\n useEffect(() => {\n setLocalTimeRange(timeRange);\n }, [timeRange, refreshCounter]);\n\n useEffect(() => {\n setLocalRefreshInterval(refreshInterval);\n }, [refreshInterval]);\n\n const refresh = useCallback(() => {\n setRefreshCounter((counter) => counter + 1);\n }, [setRefreshCounter]);\n\n const refreshIntervalInMs = getRefreshIntervalInMs(localRefreshInterval);\n useEffect(() => {\n if (refreshIntervalInMs > 0) {\n const interval = setInterval(() => {\n refresh();\n }, refreshIntervalInMs);\n\n return (): void => clearInterval(interval);\n }\n }, [refresh, refreshIntervalInMs]);\n\n const ctx = useMemo(() => {\n const absoluteTimeRange = isRelativeTimeRange(localTimeRange)\n ? toAbsoluteTimeRange(localTimeRange)\n : localTimeRange;\n return {\n timeRange: localTimeRange,\n setTimeRange: setTimeRange ?? setLocalTimeRange,\n absoluteTimeRange,\n refresh,\n refreshKey: `${absoluteTimeRange.start}:${absoluteTimeRange.end}:${localRefreshInterval}:${refreshCounter}`,\n refreshInterval: localRefreshInterval,\n refreshIntervalInMs: refreshIntervalInMs,\n setRefreshInterval: setRefreshInterval ?? setLocalRefreshInterval,\n };\n }, [\n localTimeRange,\n setTimeRange,\n refresh,\n localRefreshInterval,\n refreshCounter,\n refreshIntervalInMs,\n setRefreshInterval,\n ]);\n\n return <TimeRangeContext.Provider value={ctx}>{children}</TimeRangeContext.Provider>;\n}\n"],"names":["React","createContext","useCallback","useContext","useEffect","useMemo","useState","isRelativeTimeRange","toAbsoluteTimeRange","getSuggestedStepMs","getRefreshIntervalInMs","TimeRangeContext","undefined","useTimeRangeContext","ctx","Error","useTimeRange","useSuggestedStepMs","width","absoluteTimeRange","TimeRangeProvider","props","timeRange","refreshInterval","children","setTimeRange","setRefreshInterval","localTimeRange","setLocalTimeRange","localRefreshInterval","setLocalRefreshInterval","refreshCounter","setRefreshCounter","refresh","counter","refreshIntervalInMs","interval","setInterval","clearInterval","refreshKey","start","end","Provider","value"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,OAAOA,SAASC,aAAa,EAAgBC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAClH,SAIEC,mBAAmB,EACnBC,mBAAmB,EACnBC,kBAAkB,QACb,mBAAmB;AAC1B,SAASC,sBAAsB,QAAQ,qBAAqB;AAqB5D,OAAO,MAAMC,iCAAmBV,cAAqCW,WAAW;AAEhF,OAAO,SAASC;IACd,MAAMC,MAAMX,WAAWQ;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,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,eAAe,CAAC;YAC3GR,iBAAiBM;YACjBM,qBAAqBA;YACrBT,oBAAoBA,sBAAsBI;QAC5C;IACF,GAAG;QACDH;QACAF;QACAQ;QACAJ;QACAE;QACAI;QACAT;KACD;IAED,qBAAO,KAACf,iBAAiB+B,QAAQ;QAACC,OAAO7B;kBAAMU;;AACjD"}
1
+ {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProvider.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { createContext, ReactElement, useCallback, useContext, useEffect, useMemo, useState } from 'react';\nimport {\n AbsoluteTimeRange,\n DurationString,\n TimeRangeValue,\n isRelativeTimeRange,\n toAbsoluteTimeRange,\n getSuggestedStepMs,\n} from '@perses-dev/core';\nimport { getRefreshIntervalInMs } from './refresh-interval';\n\nexport interface TimeRangeProviderProps {\n timeRange: TimeRangeValue;\n refreshInterval?: DurationString;\n setTimeRange?: (value: TimeRangeValue) => void;\n setRefreshInterval?: (value: DurationString) => void;\n children?: React.ReactNode;\n}\n\nexport interface TimeRange {\n timeRange: TimeRangeValue;\n absoluteTimeRange: AbsoluteTimeRange; // resolved absolute time for plugins to use\n setTimeRange: (value: TimeRangeValue) => void;\n refresh: () => void;\n refreshKey: string;\n refreshInterval?: DurationString;\n refreshIntervalInMs: number;\n setRefreshInterval: (value: DurationString) => void;\n}\n\nexport const TimeRangeContext = createContext<TimeRange | undefined>(undefined);\n\nexport function useTimeRangeContext(): TimeRange {\n const ctx = useContext(TimeRangeContext);\n if (ctx === undefined) {\n throw new Error('No TimeRangeContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Get and set the current resolved time range at runtime.\n */\nexport function useTimeRange(): TimeRange {\n return useTimeRangeContext();\n}\n\n/**\n * Gets the suggested step for a graph query in ms for the currently selected time range.\n */\nexport function useSuggestedStepMs(width?: number): number {\n const { absoluteTimeRange } = useTimeRange();\n if (width === undefined) return 0;\n return getSuggestedStepMs(absoluteTimeRange, width);\n}\n\n/**\n * Provider implementation that supplies the time range state at runtime.\n */\nexport function TimeRangeProvider(props: TimeRangeProviderProps): ReactElement {\n const { timeRange, refreshInterval, children, setTimeRange, setRefreshInterval } = props;\n\n const [localTimeRange, setLocalTimeRange] = useState<TimeRangeValue>(timeRange);\n const [localRefreshInterval, setLocalRefreshInterval] = useState<DurationString | undefined>(refreshInterval);\n\n const [refreshCounter, setRefreshCounter] = useState(0);\n\n useEffect(() => {\n setLocalTimeRange(timeRange);\n }, [timeRange, refreshCounter]);\n\n useEffect(() => {\n setLocalRefreshInterval(refreshInterval);\n }, [refreshInterval]);\n\n const refresh = useCallback(() => {\n setRefreshCounter((counter) => counter + 1);\n }, [setRefreshCounter]);\n\n const refreshIntervalInMs = getRefreshIntervalInMs(localRefreshInterval);\n useEffect(() => {\n if (refreshIntervalInMs > 0) {\n const interval = setInterval(() => {\n refresh();\n }, refreshIntervalInMs);\n\n return (): void => clearInterval(interval);\n }\n }, [refresh, refreshIntervalInMs]);\n\n const ctx = useMemo(() => {\n const absoluteTimeRange = isRelativeTimeRange(localTimeRange)\n ? toAbsoluteTimeRange(localTimeRange)\n : localTimeRange;\n return {\n timeRange: localTimeRange,\n setTimeRange: setTimeRange ?? setLocalTimeRange,\n absoluteTimeRange,\n refresh,\n refreshKey: `${absoluteTimeRange.start}:${absoluteTimeRange.end}:${localRefreshInterval}:${refreshCounter}`,\n refreshInterval: localRefreshInterval,\n refreshIntervalInMs: refreshIntervalInMs,\n setRefreshInterval: setRefreshInterval ?? setLocalRefreshInterval,\n };\n }, [\n localTimeRange,\n setTimeRange,\n refresh,\n localRefreshInterval,\n refreshCounter,\n refreshIntervalInMs,\n setRefreshInterval,\n ]);\n\n return <TimeRangeContext.Provider value={ctx}>{children}</TimeRangeContext.Provider>;\n}\n"],"names":["React","createContext","useCallback","useContext","useEffect","useMemo","useState","isRelativeTimeRange","toAbsoluteTimeRange","getSuggestedStepMs","getRefreshIntervalInMs","TimeRangeContext","undefined","useTimeRangeContext","ctx","Error","useTimeRange","useSuggestedStepMs","width","absoluteTimeRange","TimeRangeProvider","props","timeRange","refreshInterval","children","setTimeRange","setRefreshInterval","localTimeRange","setLocalTimeRange","localRefreshInterval","setLocalRefreshInterval","refreshCounter","setRefreshCounter","refresh","counter","refreshIntervalInMs","interval","setInterval","clearInterval","refreshKey","start","end","Provider","value"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,OAAOA,SAASC,aAAa,EAAgBC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAClH,SAIEC,mBAAmB,EACnBC,mBAAmB,EACnBC,kBAAkB,QACb,mBAAmB;AAC1B,SAASC,sBAAsB,QAAQ,qBAAqB;AAqB5D,OAAO,MAAMC,iCAAmBV,cAAqCW,WAAW;AAEhF,OAAO,SAASC;IACd,MAAMC,MAAMX,WAAWQ;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA;;CAEC,GACD,OAAO,SAASE;IACd,OAAOH;AACT;AAEA;;CAEC,GACD,OAAO,SAASI,mBAAmBC,KAAc;IAC/C,MAAM,EAAEC,iBAAiB,EAAE,GAAGH;IAC9B,IAAIE,UAAUN,WAAW,OAAO;IAChC,OAAOH,mBAAmBU,mBAAmBD;AAC/C;AA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2
  import { TimeOption } from '@perses-dev/components';
3
3
  export interface TimeRangeSettingsProviderProps {
4
4
  showCustom?: boolean;
5
+ showZoomButtons?: boolean;
5
6
  options?: TimeOption[];
6
7
  children: ReactNode;
7
8
  }
8
9
  export interface TimeRangeSettings {
9
10
  showCustom: boolean;
11
+ showZoomButtons: boolean;
10
12
  options: TimeOption[];
11
13
  }
12
14
  export declare const TimeRangeSettingsContext: import("react").Context<TimeRangeSettings>;
@@ -20,6 +22,11 @@ export declare function useTimeRangeSettings(): TimeRangeSettings;
20
22
  * @param override If set, the value of the provider will be overridden by this value.
21
23
  */
22
24
  export declare function useShowCustomTimeRangeSetting(override?: boolean): boolean;
25
+ /**
26
+ * Get the current value of the showZoomButtons setting.
27
+ * @param override If set, the value of the provider will be overridden by this value.
28
+ */
29
+ export declare function useShowZoomRangeSetting(override?: boolean): boolean;
23
30
  /**
24
31
  * Get the current value of the options setting.
25
32
  * @param override If set, the value of the provider will be overridden by this value.
@@ -1 +1 @@
1
- {"version":3,"file":"TimeRangeSettingsProvider.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/TimeRangeSettingsProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAiB,YAAY,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AACpF,OAAO,EAA2B,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAS7E,MAAM,WAAW,8BAA8B;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;IACvB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAED,eAAO,MAAM,wBAAwB,4CAA6D,CAAC;AAEnG,wBAAgB,2BAA2B,IAAI,iBAAiB,CAM/D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,iBAAiB,CAExD;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAMzE;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,CAMhF;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,8BAA8B,GAAG,YAAY,CAS7F"}
1
+ {"version":3,"file":"TimeRangeSettingsProvider.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/TimeRangeSettingsProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAiB,YAAY,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AACpF,OAAO,EAA2B,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAU7E,MAAM,WAAW,8BAA8B;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;IACvB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,OAAO,CAAC;IACpB,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAED,eAAO,MAAM,wBAAwB,4CAA6D,CAAC;AAEnG,wBAAgB,2BAA2B,IAAI,iBAAiB,CAM/D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,iBAAiB,CAExD;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAMzE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAMnE;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,CAMhF;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,8BAA8B,GAAG,YAAY,CAW7F"}
@@ -26,6 +26,7 @@ const DEFAULT_OPTIONS = [
26
26
  ];
27
27
  const defaultTimeRangeSettings = {
28
28
  showCustom: true,
29
+ showZoomButtons: true,
29
30
  options: DEFAULT_OPTIONS.map((duration)=>buildRelativeTimeOption(duration))
30
31
  };
31
32
  export const TimeRangeSettingsContext = /*#__PURE__*/ createContext(defaultTimeRangeSettings);
@@ -51,6 +52,16 @@ export function useTimeRangeSettingsContext() {
51
52
  }
52
53
  return showCustomTimeRange;
53
54
  }
55
+ /**
56
+ * Get the current value of the showZoomButtons setting.
57
+ * @param override If set, the value of the provider will be overridden by this value.
58
+ */ export function useShowZoomRangeSetting(override) {
59
+ const showZoomTimeRange = useTimeRangeSettings().showZoomButtons;
60
+ if (override !== undefined) {
61
+ return override;
62
+ }
63
+ return showZoomTimeRange;
64
+ }
54
65
  /**
55
66
  * Get the current value of the options setting.
56
67
  * @param override If set, the value of the provider will be overridden by this value.
@@ -67,10 +78,12 @@ export function useTimeRangeSettingsContext() {
67
78
  const ctx = useMemo(()=>{
68
79
  return {
69
80
  showCustom: props.showCustom === undefined ? defaultTimeRangeSettings.showCustom : props.showCustom,
81
+ showZoomButtons: props.showZoomButtons === undefined ? defaultTimeRangeSettings.showZoomButtons : props.showZoomButtons,
70
82
  options: props.options === undefined ? defaultTimeRangeSettings.options : props.options
71
83
  };
72
84
  }, [
73
85
  props.showCustom,
86
+ props.showZoomButtons,
74
87
  props.options
75
88
  ]);
76
89
  return /*#__PURE__*/ _jsx(TimeRangeSettingsContext.Provider, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeSettingsProvider.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createContext, ReactElement, ReactNode, useContext, useMemo } from 'react';\nimport { buildRelativeTimeOption, TimeOption } from '@perses-dev/components';\nimport { DurationString } from '@perses-dev/core';\n\nconst DEFAULT_OPTIONS: DurationString[] = ['5m', '15m', '30m', '1h', '6h', '12h', '24h', '7d', '14d'];\nconst defaultTimeRangeSettings: TimeRangeSettings = {\n showCustom: true,\n options: DEFAULT_OPTIONS.map((duration) => buildRelativeTimeOption(duration)),\n};\n\nexport interface TimeRangeSettingsProviderProps {\n showCustom?: boolean;\n options?: TimeOption[];\n children: ReactNode;\n}\n\nexport interface TimeRangeSettings {\n showCustom: boolean;\n options: TimeOption[];\n}\n\nexport const TimeRangeSettingsContext = createContext<TimeRangeSettings>(defaultTimeRangeSettings);\n\nexport function useTimeRangeSettingsContext(): TimeRangeSettings {\n const ctx = useContext(TimeRangeSettingsContext);\n if (ctx === undefined) {\n throw new Error('No TimeRangeContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Get and set the current resolved time range at runtime.\n */\nexport function useTimeRangeSettings(): TimeRangeSettings {\n return useTimeRangeSettingsContext();\n}\n\n/**\n * Get the current value of the showCustom setting.\n * @param override If set, the value of the provider will be overridden by this value.\n */\nexport function useShowCustomTimeRangeSetting(override?: boolean): boolean {\n const showCustomTimeRange = useTimeRangeSettings().showCustom;\n if (override !== undefined) {\n return override;\n }\n return showCustomTimeRange;\n}\n\n/**\n * Get the current value of the options setting.\n * @param override If set, the value of the provider will be overridden by this value.\n */\nexport function useTimeRangeOptionsSetting(override?: TimeOption[]): TimeOption[] {\n const showCustomTimeRange = useTimeRangeSettings().options;\n if (override !== undefined) {\n return override;\n }\n return showCustomTimeRange;\n}\n\n/**\n * Provider implementation that supplies the time range state at runtime.\n */\nexport function TimeRangeSettingsProvider(props: TimeRangeSettingsProviderProps): ReactElement {\n const ctx = useMemo(() => {\n return {\n showCustom: props.showCustom === undefined ? defaultTimeRangeSettings.showCustom : props.showCustom,\n options: props.options === undefined ? defaultTimeRangeSettings.options : props.options,\n };\n }, [props.showCustom, props.options]);\n\n return <TimeRangeSettingsContext.Provider value={ctx}>{props.children}</TimeRangeSettingsContext.Provider>;\n}\n"],"names":["createContext","useContext","useMemo","buildRelativeTimeOption","DEFAULT_OPTIONS","defaultTimeRangeSettings","showCustom","options","map","duration","TimeRangeSettingsContext","useTimeRangeSettingsContext","ctx","undefined","Error","useTimeRangeSettings","useShowCustomTimeRangeSetting","override","showCustomTimeRange","useTimeRangeOptionsSetting","TimeRangeSettingsProvider","props","Provider","value","children"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,aAAa,EAA2BC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AACpF,SAASC,uBAAuB,QAAoB,yBAAyB;AAG7E,MAAMC,kBAAoC;IAAC;IAAM;IAAO;IAAO;IAAM;IAAM;IAAO;IAAO;IAAM;CAAM;AACrG,MAAMC,2BAA8C;IAClDC,YAAY;IACZC,SAASH,gBAAgBI,GAAG,CAAC,CAACC,WAAaN,wBAAwBM;AACrE;AAaA,OAAO,MAAMC,yCAA2BV,cAAiCK,0BAA0B;AAEnG,OAAO,SAASM;IACd,MAAMC,MAAMX,WAAWS;IACvB,IAAIE,QAAQC,WAAW;QACrB,MAAM,IAAIC,MAAM;IAClB;IACA,OAAOF;AACT;AAEA;;CAEC,GACD,OAAO,SAASG;IACd,OAAOJ;AACT;AAEA;;;CAGC,GACD,OAAO,SAASK,8BAA8BC,QAAkB;IAC9D,MAAMC,sBAAsBH,uBAAuBT,UAAU;IAC7D,IAAIW,aAAaJ,WAAW;QAC1B,OAAOI;IACT;IACA,OAAOC;AACT;AAEA;;;CAGC,GACD,OAAO,SAASC,2BAA2BF,QAAuB;IAChE,MAAMC,sBAAsBH,uBAAuBR,OAAO;IAC1D,IAAIU,aAAaJ,WAAW;QAC1B,OAAOI;IACT;IACA,OAAOC;AACT;AAEA;;CAEC,GACD,OAAO,SAASE,0BAA0BC,KAAqC;IAC7E,MAAMT,MAAMV,QAAQ;QAClB,OAAO;YACLI,YAAYe,MAAMf,UAAU,KAAKO,YAAYR,yBAAyBC,UAAU,GAAGe,MAAMf,UAAU;YACnGC,SAASc,MAAMd,OAAO,KAAKM,YAAYR,yBAAyBE,OAAO,GAAGc,MAAMd,OAAO;QACzF;IACF,GAAG;QAACc,MAAMf,UAAU;QAAEe,MAAMd,OAAO;KAAC;IAEpC,qBAAO,KAACG,yBAAyBY,QAAQ;QAACC,OAAOX;kBAAMS,MAAMG,QAAQ;;AACvE"}
1
+ {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeSettingsProvider.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createContext, ReactElement, ReactNode, useContext, useMemo } from 'react';\nimport { buildRelativeTimeOption, TimeOption } from '@perses-dev/components';\nimport { DurationString } from '@perses-dev/core';\n\nconst DEFAULT_OPTIONS: DurationString[] = ['5m', '15m', '30m', '1h', '6h', '12h', '24h', '7d', '14d'];\nconst defaultTimeRangeSettings: TimeRangeSettings = {\n showCustom: true,\n showZoomButtons: true,\n options: DEFAULT_OPTIONS.map((duration) => buildRelativeTimeOption(duration)),\n};\n\nexport interface TimeRangeSettingsProviderProps {\n showCustom?: boolean;\n showZoomButtons?: boolean;\n options?: TimeOption[];\n children: ReactNode;\n}\n\nexport interface TimeRangeSettings {\n showCustom: boolean;\n showZoomButtons: boolean;\n options: TimeOption[];\n}\n\nexport const TimeRangeSettingsContext = createContext<TimeRangeSettings>(defaultTimeRangeSettings);\n\nexport function useTimeRangeSettingsContext(): TimeRangeSettings {\n const ctx = useContext(TimeRangeSettingsContext);\n if (ctx === undefined) {\n throw new Error('No TimeRangeContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Get and set the current resolved time range at runtime.\n */\nexport function useTimeRangeSettings(): TimeRangeSettings {\n return useTimeRangeSettingsContext();\n}\n\n/**\n * Get the current value of the showCustom setting.\n * @param override If set, the value of the provider will be overridden by this value.\n */\nexport function useShowCustomTimeRangeSetting(override?: boolean): boolean {\n const showCustomTimeRange = useTimeRangeSettings().showCustom;\n if (override !== undefined) {\n return override;\n }\n return showCustomTimeRange;\n}\n\n/**\n * Get the current value of the showZoomButtons setting.\n * @param override If set, the value of the provider will be overridden by this value.\n */\nexport function useShowZoomRangeSetting(override?: boolean): boolean {\n const showZoomTimeRange = useTimeRangeSettings().showZoomButtons;\n if (override !== undefined) {\n return override;\n }\n return showZoomTimeRange;\n}\n\n/**\n * Get the current value of the options setting.\n * @param override If set, the value of the provider will be overridden by this value.\n */\nexport function useTimeRangeOptionsSetting(override?: TimeOption[]): TimeOption[] {\n const showCustomTimeRange = useTimeRangeSettings().options;\n if (override !== undefined) {\n return override;\n }\n return showCustomTimeRange;\n}\n\n/**\n * Provider implementation that supplies the time range state at runtime.\n */\nexport function TimeRangeSettingsProvider(props: TimeRangeSettingsProviderProps): ReactElement {\n const ctx = useMemo(() => {\n return {\n showCustom: props.showCustom === undefined ? defaultTimeRangeSettings.showCustom : props.showCustom,\n showZoomButtons:\n props.showZoomButtons === undefined ? defaultTimeRangeSettings.showZoomButtons : props.showZoomButtons,\n options: props.options === undefined ? defaultTimeRangeSettings.options : props.options,\n };\n }, [props.showCustom, props.showZoomButtons, props.options]);\n\n return <TimeRangeSettingsContext.Provider value={ctx}>{props.children}</TimeRangeSettingsContext.Provider>;\n}\n"],"names":["createContext","useContext","useMemo","buildRelativeTimeOption","DEFAULT_OPTIONS","defaultTimeRangeSettings","showCustom","showZoomButtons","options","map","duration","TimeRangeSettingsContext","useTimeRangeSettingsContext","ctx","undefined","Error","useTimeRangeSettings","useShowCustomTimeRangeSetting","override","showCustomTimeRange","useShowZoomRangeSetting","showZoomTimeRange","useTimeRangeOptionsSetting","TimeRangeSettingsProvider","props","Provider","value","children"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,aAAa,EAA2BC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AACpF,SAASC,uBAAuB,QAAoB,yBAAyB;AAG7E,MAAMC,kBAAoC;IAAC;IAAM;IAAO;IAAO;IAAM;IAAM;IAAO;IAAO;IAAM;CAAM;AACrG,MAAMC,2BAA8C;IAClDC,YAAY;IACZC,iBAAiB;IACjBC,SAASJ,gBAAgBK,GAAG,CAAC,CAACC,WAAaP,wBAAwBO;AACrE;AAeA,OAAO,MAAMC,yCAA2BX,cAAiCK,0BAA0B;AAEnG,OAAO,SAASO;IACd,MAAMC,MAAMZ,WAAWU;IACvB,IAAIE,QAAQC,WAAW;QACrB,MAAM,IAAIC,MAAM;IAClB;IACA,OAAOF;AACT;AAEA;;CAEC,GACD,OAAO,SAASG;IACd,OAAOJ;AACT;AAEA;;;CAGC,GACD,OAAO,SAASK,8BAA8BC,QAAkB;IAC9D,MAAMC,sBAAsBH,uBAAuBV,UAAU;IAC7D,IAAIY,aAAaJ,WAAW;QAC1B,OAAOI;IACT;IACA,OAAOC;AACT;AA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