-
Notifications
You must be signed in to change notification settings - Fork 56
/
index.d.ts
699 lines (573 loc) · 19.5 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
// File generated automatically by "@scriptappy/to-dts"; DO NOT EDIT.
/// <reference types="qlik-engineapi" />
/**
* Initiates a new `Embed` instance using the specified enigma `app`.
* @param app
* @param instanceConfig
*/
export function embed(app: EngineAPI.IApp, instanceConfig?: stardust.Configuration): stardust.Embed;
export namespace embed {
/**
* Creates a new `embed` scope bound to the specified `configuration`.
*
* The configuration is merged with all previous scopes.
* @param configuration The configuration object
*/
function createConfiguration(configuration: stardust.Configuration): typeof embed;
}
/**
* Creates a stateful value.
* @param initialState The initial state.
*/
export function useState<S>(initialState: S | (()=>S)): [S, stardust.SetStateFn<S>];
/**
* Triggers a callback function when a dependent value changes.
* @param effect The callback.
* @param deps The dependencies that should trigger the callback.
*/
export function useEffect(effect: stardust.EffectCallback, deps?: any[]): void;
/**
* Creates a stateful value when a dependent changes.
* @param factory The factory function.
* @param deps The dependencies.
*/
export function useMemo<T>(factory: ()=>T, deps: any[]): T;
/**
* Runs a callback function when a dependent changes.
* @param factory The factory function that calls the promise.
* @param deps The dependencies.
*/
export function usePromise<P>(factory: ()=>Promise<P>, deps?: any[]): [P, Error];
/**
* Gets the HTMLElement this visualization is rendered into.
*/
export function useElement(): HTMLElement;
/**
* Gets the size of the HTMLElement the visualization is rendered into.
*/
export function useRect(): stardust.Rect;
/**
* Gets the layout of the generic object associated with this visualization.
*/
export function useLayout(): EngineAPI.IGenericObjectLayout;
/**
* Gets the layout of the generic object associated with this visualization.
*
* Unlike the regular layout, a _stale_ layout is not changed when a generic object enters
* the modal state. This is mostly notable in that `qSelectionInfo.qInSelections` in the layout is
* always `false`.
* The returned value from `useStaleLayout()` and `useLayout()` are identical when the object
* is not in a modal state.
*/
export function useStaleLayout(): EngineAPI.IGenericObjectLayout;
/**
* Gets the layout of the app associated with this visualization.
*/
export function useAppLayout(): EngineAPI.INxAppLayout;
/**
* Gets the generic object API of the generic object connected to this visualization.
*/
export function useModel(): EngineAPI.IGenericObject | undefined;
/**
* Gets the doc API.
*/
export function useApp(): EngineAPI.IApp | undefined;
/**
* Gets the global API.
*/
export function useGlobal(): EngineAPI.IGlobal | undefined;
/**
* Gets the object selections.
*/
export function useSelections(): stardust.ObjectSelections;
/**
* Gets the theme.
*/
export function useTheme(): stardust.Theme;
/**
* Gets the embed instance used.
*/
export function useEmbed(): stardust.Embed;
/**
* Gets the translator.
*/
export function useTranslator(): stardust.Translator;
/**
* Gets the device type. ('touch' or 'desktop')
*/
export function useDeviceType(): string;
/**
* Gets the array of plugins provided when rendering the visualization.
*/
export function usePlugins(): stardust.Plugin[];
/**
* Registers a custom action.
* @param factory
* @param deps
*/
export function useAction<A>(factory: ()=>stardust.ActionDefinition<A>, deps?: any[]): A;
/**
* Gets the desired constraints that should be applied when rendering the visualization.
*
* The constraints are set on the embed configuration before the visualization is rendered
* and should respected by you when implementing the visualization.
*/
export function useConstraints(): stardust.Constraints;
/**
* Gets the options object provided when rendering the visualization.
*
* This is an empty object by default but enables customization of the visualization through this object.
* Options are different from setting properties on the generic object in that options
* are only temporary settings applied to the visualization when rendered.
*
* You have the responsibility to provide documentation of the options you support, if any.
*/
export function useOptions(): object;
/**
* Registers a callback that is called when a snapshot is taken.
* @param snapshotCallback
*/
export function onTakeSnapshot(snapshotCallback: ($: EngineAPI.IGenericObjectLayout)=>Promise<EngineAPI.IGenericObjectLayout>): void;
/**
* Gets render state instance.
*
* Used to update properties and get a new layout without triggering onInitialRender.
*/
export function useRenderState(): stardust.RenderState;
/**
* Gets the desired keyboard settings and status to applied when rendering the visualization.
* A visualization should in general only have tab stops if either `keyboard.enabled` is false or if active is true.
* This means that either Nebula isn't configured to handle keyboard input or the chart is currently focused.
* Enabling or disabling keyboardNavigation are set on the embed configuration and
* should be respected by the visualization.
*/
export function useKeyboard(): stardust.Keyboard;
declare namespace stardust {
interface Context {
disableCellPadding?: boolean;
keyboardNavigation?: boolean;
constraints?: {
active?: boolean;
passive?: boolean;
select?: boolean;
};
theme?: string;
language?: string;
deviceType?: string;
}
interface Configuration {
context?: stardust.Context;
types?: stardust.TypeInfo[];
themes?: stardust.ThemeInfo[];
anything?: object;
}
interface Galaxy {
translator: stardust.Translator;
flags: stardust.Flags;
deviceType: string;
anything: object;
}
class Embed {
constructor();
/**
* Renders a visualization into an HTMLElement.
* @param cfg The render configuration.
*/
render(cfg: stardust.CreateConfig | stardust.GetConfig): Promise<stardust.Viz>;
/**
* Updates the current context of this embed instance.
* Use this when you want to change some part of the current context, like theme.
* @param ctx The context to update.
*/
context(ctx: stardust.Context): Promise<undefined>;
/**
* Gets the app selections of this instance.
*/
selections(): Promise<stardust.AppSelections>;
/**
* Gets the listbox instance of the specified field
* @param fieldIdentifier Fieldname as a string or a Library dimension
*/
field(fieldIdentifier: string | stardust.LibraryField): Promise<stardust.FieldInstance>;
/**
* Gets a list of registered visualization types and versions
*/
getRegisteredTypes(): Object[];
}
/**
* A callback function which receives another function as input.
*/
type ReceiverFunction = ($: ()=>void)=>void;
class FieldInstance {
constructor();
/**
* Mounts the field as a listbox into the provided HTMLElement.
* @param element
* @param options Settings for the embedded listbox
*/
mount(element: HTMLElement, options?: {
title?: string;
direction?: string;
listLayout?: string;
search?: boolean;
toolbar?: boolean;
stateName?: boolean;
properties?: object;
sessionModel?: object;
selectionsApi?: object;
update?: stardust.ReceiverFunction;
}): void;
/**
* Unmounts the field listbox from the DOM.
*/
unmount(): void;
}
type ThemeJSON = any;
interface ThemeInfo {
id: string;
/**
* A function that should return a Promise that resolves to a raw JSON theme.
*/
load(): Promise<stardust.ThemeJSON>;
}
/**
* A controller to further modify a visualization after it has been rendered.
*/
class Viz {
constructor();
id: string;
/**
* Destroys the visualization and removes it from the the DOM.
*/
destroy(): void;
/**
* Converts the visualization to a different registered type
* @param newType Which registered type to convert to.
* @param forceUpdate Whether to run setProperties or not, defaults to true.
*/
convertTo(newType: string, forceUpdate?: boolean): Promise<object>;
}
interface Flags {
/**
* Checks whether the specified flag is enabled.
* @param flag The value flag to check.
*/
isEnabled(flag: string): boolean;
}
class AppSelections {
constructor();
/**
* Mounts the app selection UI into the provided HTMLElement.
* @param element
*/
mount(element: HTMLElement): void;
/**
* Unmounts the app selection UI from the DOM.
*/
unmount(): void;
}
class ObjectSelections {
constructor();
/**
* @param paths
*/
begin(paths: string[]): Promise<undefined>;
clear(): Promise<undefined>;
confirm(): Promise<undefined>;
cancel(): Promise<undefined>;
/**
* @param s
*/
select(s: {
method: string;
params: any[];
}): Promise<boolean>;
canClear(): boolean;
canConfirm(): boolean;
canCancel(): boolean;
isActive(): boolean;
isModal(): boolean;
/**
* @param paths
*/
goModal(paths: string[]): Promise<undefined>;
/**
* @param accept
*/
noModal(accept?: boolean): Promise<undefined>;
}
/**
* An object literal containing meta information about the plugin and a function containing the plugin implementation.
*/
interface Plugin {
info: {
name: string;
};
fn: ()=>void;
}
type Field = string | EngineAPI.INxDimension | EngineAPI.INxMeasure | stardust.LibraryField;
/**
* Rendering configuration for creating and rendering a new object
*/
interface CreateConfig extends stardust.BaseConfig{
type: string;
version?: string;
fields?: stardust.Field[];
properties?: EngineAPI.IGenericObjectProperties;
}
/**
* Basic rendering configuration for rendering an object
*/
interface BaseConfig {
element: HTMLElement;
options?: object;
plugins?: stardust.Plugin[];
}
/**
* Rendering configuration for rendering an existing object
*/
interface GetConfig extends stardust.BaseConfig{
id: string;
}
interface LibraryField {
qLibraryId: string;
type: "dimension" | "measure";
}
interface LoadType {
(type: {
name: string;
version: string;
}): Promise<stardust.Visualization>;
}
interface TypeInfo {
name: string;
version?: string;
load: stardust.LoadType;
meta?: object;
}
type MinMaxResult = {
};
/**
* Returns the min and max indices of elemNumbersOrdered which contains
* all numbers in elementNbrs.
*/
type getMinMax = (elementNbrs: number[], elemNumbersOrdered: number[])=>stardust.MinMaxResult;
interface ActionToolbarElement extends HTMLElement{
className: "njs-action-toolbar-popover";
}
interface ActionElement extends HTMLElement{
className: "njs-cell-action";
}
interface CellElement extends HTMLElement{
className: "njs-cell";
}
interface CellFooter extends HTMLElement{
className: "njs-cell-footer";
}
interface CellTitle extends HTMLElement{
className: "njs-cell-title";
}
interface CellSubTitle extends HTMLElement{
className: "njs-cell-sub-title";
}
interface VizElementAttributes extends NamedNodeMap{
"data-render-count": string;
}
interface VizElement extends HTMLElement{
attributes: stardust.VizElementAttributes;
className: "njs-viz";
}
/**
* The entry point for defining a visualization.
*/
interface Visualization {
(galaxy: stardust.Galaxy): stardust.VisualizationDefinition;
}
interface VisualizationDefinition {
qae: stardust.QAEDefinition;
component(): void;
}
interface SetStateFn<S> {
(newState: S | (($: S)=>S)): void;
}
type EffectCallback = ()=>void | (()=>void);
interface Rect {
top: number;
left: number;
width: number;
height: number;
}
interface ActionDefinition<A> {
action: A;
hidden?: boolean;
disabled?: boolean;
icon?: {
viewBox?: string;
shapes: {
}[];
};
}
interface Constraints {
passive?: boolean;
active?: boolean;
select?: boolean;
}
interface RenderState {
pending: any;
restore: any;
}
interface Keyboard {
enabled: boolean;
active: boolean;
/**
* Function used by the visualization to tell Nebula to it wants to relinquish focus
*/
blur?(): void;
/**
* Function used by the visualization to tell Nebula to it wants focus
*/
focus?(): void;
/**
* Function used by the visualization to tell Nebula to focus the selection toolbar
*/
focusSelection?(): void;
}
/**
* Imports properties for a chart with a hypercube.
*/
type importProperties = (args: {
exportFormat: stardust.ExportFormat;
initialProperties?: Object;
dataDefinition?: Object;
defaultPropertyValues?: Object;
hypercubePath: string;
})=>Object;
/**
* Exports properties for a chart with a hypercube.
*/
type exportProperties = (args: {
propertyTree: Object;
hypercubePath: string;
})=>stardust.ExportFormat;
interface QAEDefinition {
properties?: EngineAPI.IGenericObjectProperties;
data?: {
targets: stardust.DataTarget[];
};
importProperties?: stardust.importProperties;
exportProperties?: stardust.exportProperties;
}
interface DataTarget {
path: string;
dimensions?: stardust.FieldTarget<EngineAPI.INxDimension>;
measures?: stardust.FieldTarget<EngineAPI.INxMeasure>;
}
type fieldTargetAddedCallback<T> = (field: T, properties: EngineAPI.IGenericObjectProperties)=>void;
type fieldTargetRemovedCallback<T> = (field: T, properties: EngineAPI.IGenericObjectProperties, index: number)=>void;
interface FieldTarget<T> {
min?(): number;
max?(): number;
added?: stardust.fieldTargetAddedCallback<T>;
removed?: stardust.fieldTargetRemovedCallback<T>;
}
class Translator {
constructor();
/**
* Registers a string in multiple locales
* @param item
*/
add(item: {
id: string;
locale: object;
}): void;
/**
* Translates a string for current locale.
* @param str ID of the registered string.
* @param args Values passed down for string interpolation.
*/
get(str: string, args?: string[]): string;
}
class Theme {
constructor();
getDataColorScales(): stardust.Theme.ScalePalette[];
getDataColorPalettes(): stardust.Theme.DataPalette[];
getDataColorPickerPalettes(): stardust.Theme.ColorPickerPalette[];
getDataColorSpecials(): stardust.Theme.DataColorSpecials;
/**
* Resolve a color object using the color picker palette from the provided JSON theme.
* @param c
*/
getColorPickerColor(c: {
index?: number;
color?: string;
}): string;
/**
* Get the best contrasting color against the specified `color`.
* This is typically used to find a suitable text color for a label placed on an arbitrarily colored background.
*
* The returned colors are derived from the theme.
* @param color A color to measure the contrast against
*/
getContrastingColorTo(color: string): string;
/**
* Get the value of a style attribute in the theme by searching in the theme's JSON structure.
* The search starts at the specified base path and continues upwards until the value is found.
* If possible it will get the attribute's value using the given path.
* @param basePath Base path in the theme's JSON structure to start the search in (specified as a name path separated by dots).
* @param path Expected path for the attribute (specified as a name path separated by dots).
* @param attribute Name of the style attribute.
*/
getStyle(basePath: string, path: string, attribute: string): string;
}
namespace Theme {
interface ScalePalette {
key: string;
type: "gradient" | "class-pyramid";
colors: string[] | (string[])[];
}
interface DataPalette {
key: string;
type: "pyramid" | "row";
colors: string[] | (string[])[];
}
interface ColorPickerPalette {
key: string;
colors: string[];
}
interface DataColorSpecials {
primary: string;
nil: string;
others: string;
}
}
/**
* Used for exporting and importing properties between backend models. An object that exports to
* ExportFormat should put dimensions and measures inside one data group. If an object has two hypercubes,
* each of the cubes should export dimensions and measures in two separate data groups.
* An object that imports from this structure is responsible for putting the existing properties where they should be
* in the new model.
*/
interface ExportFormat {
data?: stardust.ExportDataDef[];
properties?: object;
}
interface ExportDataDef {
dimensions: EngineAPI.INxDimension[];
measures: EngineAPI.INxMeasure[];
excludedDimensions: EngineAPI.INxDimension[];
excludedMeasures: EngineAPI.INxMeasure[];
interColumnSortOrder: number[];
}
interface ConversionType {
importProperties: stardust.importProperties;
exportProperties: stardust.exportProperties;
}
/**
* Provides conversion functionality to extensions.
*/
interface Conversion {
hypercube: stardust.hyperCubeConversion;
}
interface hyperCubeConversion {
}
}