@vuu-ui/vuu-data-react 0.13.5 → 0.13.6

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.
@@ -12,19 +12,23 @@ const useSessionDataSource = ({
12
12
  const { id, load, save, loadSession, saveSession, title } = vuuLayout.useViewContext();
13
13
  const { VuuDataSource } = vuuUtils.useData();
14
14
  const { "datasource-config": dataSourceConfigFromState } = react.useMemo(() => load?.() ?? NO_CONFIG, [load]);
15
+ const dataSourceConfigRef = react.useRef(
16
+ dataSourceConfigFromState
17
+ );
15
18
  const handleDataSourceConfigChange = react.useCallback(
16
19
  (config, _range, confirmed) => {
17
20
  if (confirmed !== false) {
18
21
  const { noChanges } = vuuUtils.isConfigChanged(
19
- dataSourceConfigFromState,
22
+ dataSourceConfigRef.current,
20
23
  config
21
24
  );
22
25
  if (noChanges === false) {
26
+ dataSourceConfigRef.current = config;
23
27
  save?.(config, "datasource-config");
24
28
  }
25
29
  }
26
30
  },
27
- [dataSourceConfigFromState, save]
31
+ [save]
28
32
  );
29
33
  const dataSource = react.useMemo(() => {
30
34
  let ds = loadSession?.(dataSourceSessionKey);
@@ -42,7 +46,7 @@ const useSessionDataSource = ({
42
46
  // bufferSize: 0,
43
47
  viewport: id,
44
48
  table: tableSchema.table,
45
- ...dataSourceConfigFromState,
49
+ ...dataSourceConfigRef.current,
46
50
  columns,
47
51
  title
48
52
  });
@@ -1 +1 @@
1
- {"version":3,"file":"useSessionDataSource.js","sources":["../../src/hooks/useSessionDataSource.ts"],"sourcesContent":["import type {\n DataSource,\n DataSourceConfig,\n DataSourceConfigChangeHandler,\n TableSchema,\n} from \"@vuu-ui/vuu-data-types\";\nimport { useViewContext } from \"@vuu-ui/vuu-layout\";\nimport type { VuuRange } from \"@vuu-ui/vuu-protocol-types\";\nimport { isConfigChanged, useData } from \"@vuu-ui/vuu-utils\";\nimport { useCallback, useMemo } from \"react\";\n\ntype SessionDataSourceConfig = {\n \"datasource-config\"?: DataSourceConfig;\n};\n\nconst NO_CONFIG: SessionDataSourceConfig = {};\n\nexport const useSessionDataSource = ({\n dataSourceSessionKey = \"data-source\",\n tableSchema,\n}: {\n dataSourceSessionKey?: string;\n tableSchema: TableSchema;\n}) => {\n const { id, load, save, loadSession, saveSession, title } = useViewContext();\n const { VuuDataSource } = useData();\n\n const { \"datasource-config\": dataSourceConfigFromState } =\n useMemo<SessionDataSourceConfig>(() => load?.() ?? NO_CONFIG, [load]);\n\n const handleDataSourceConfigChange =\n useCallback<DataSourceConfigChangeHandler>(\n (\n config: DataSourceConfig | undefined,\n _range: VuuRange,\n confirmed?: boolean,\n ) => {\n if (confirmed !== false) {\n const { noChanges } = isConfigChanged(\n dataSourceConfigFromState,\n config,\n );\n if (noChanges === false) {\n save?.(config, \"datasource-config\");\n }\n }\n },\n [dataSourceConfigFromState, save],\n );\n\n const dataSource: DataSource = useMemo(() => {\n let ds = loadSession?.(dataSourceSessionKey) as DataSource;\n if (ds) {\n if (dataSourceConfigFromState) {\n // this won't do anything if dataSource config already matches this\n // This is only really used when injecting a dataSource into session\n // state in Showcase examples\n // DO we definitely need this ? If not apply config can be provate\n ds.applyConfig(dataSourceConfigFromState, true);\n }\n\n if (ds.range.from > 0) {\n // UI does not currently restore scroll position, so always reset to top of dataset\n ds.range = ds.range.reset;\n }\n\n return ds;\n }\n\n const columns =\n dataSourceConfigFromState?.columns ??\n tableSchema.columns.map((col) => col.name);\n\n ds = new VuuDataSource({\n // bufferSize: 0,\n viewport: id,\n table: tableSchema.table,\n ...dataSourceConfigFromState,\n columns,\n title,\n });\n ds.on(\"config\", handleDataSourceConfigChange);\n saveSession?.(ds, \"data-source\");\n return ds;\n }, [\n VuuDataSource,\n dataSourceConfigFromState,\n dataSourceSessionKey,\n handleDataSourceConfigChange,\n id,\n loadSession,\n saveSession,\n tableSchema.columns,\n tableSchema.table,\n title,\n ]);\n\n return dataSource;\n};\n"],"names":["useViewContext","useData","useMemo","useCallback","isConfigChanged"],"mappings":";;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AAA,CAAC,GAAQ,KAAA,GAAA,CAAI,IAAI,CAAA;AAE3C,IAAA,EAAA,GAAK,IAAI,aAAc,CAAA;AAAA;AAAA,MAErB,QAAU,EAAA,EAAA;AAAA,MACV,OAAO,WAAY,CAAA,KAAA;AAAA,MACnB,GAAG,yBAAA;AAAA,MACH,OAAA;AAAA,MACA;AAAA,KACD,CAAA;AACD,IAAG,EAAA,CAAA,EAAA,CAAG,UAAU,4BAA4B,CAAA;AAC5C,IAAA,WAAA,GAAc,IAAI,aAAa,CAAA;AAC/B,IAAO,OAAA,EAAA;AAAA,GACN,EAAA;AAAA,IACD,aAAA;AAAA,IACA,yBAAA;AAAA,IACA,oBAAA;AAAA,IACA,4BAAA;AAAA,IACA,EAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAY,CAAA,OAAA;AAAA,IACZ,WAAY,CAAA,KAAA;AAAA,IACZ;AAAA,GACD,CAAA;AAED,EAAO,OAAA,UAAA;AACT;;;;"}
1
+ {"version":3,"file":"useSessionDataSource.js","sources":["../../src/hooks/useSessionDataSource.ts"],"sourcesContent":["import type {\n DataSource,\n DataSourceConfig,\n DataSourceConfigChangeHandler,\n TableSchema,\n} from \"@vuu-ui/vuu-data-types\";\nimport { useViewContext } from \"@vuu-ui/vuu-layout\";\nimport type { VuuRange } from \"@vuu-ui/vuu-protocol-types\";\nimport { isConfigChanged, useData } from \"@vuu-ui/vuu-utils\";\nimport { useCallback, useMemo, useRef } from \"react\";\n\ntype SessionState = {\n \"datasource-config\"?: DataSourceConfig;\n};\n\nconst NO_CONFIG: SessionState = {};\n\nexport const useSessionDataSource = ({\n dataSourceSessionKey = \"data-source\",\n tableSchema,\n}: {\n dataSourceSessionKey?: string;\n tableSchema: TableSchema;\n}) => {\n const { id, load, save, loadSession, saveSession, title } = useViewContext();\n const { VuuDataSource } = useData();\n\n const { \"datasource-config\": dataSourceConfigFromState } =\n useMemo<SessionState>(() => load?.() ?? NO_CONFIG, [load]);\n\n const dataSourceConfigRef = useRef<DataSourceConfig | undefined>(\n dataSourceConfigFromState,\n );\n\n const handleDataSourceConfigChange =\n useCallback<DataSourceConfigChangeHandler>(\n (\n config: DataSourceConfig | undefined,\n _range: VuuRange,\n confirmed?: boolean,\n ) => {\n if (confirmed !== false) {\n const { noChanges } = isConfigChanged(\n dataSourceConfigRef.current,\n config,\n );\n if (noChanges === false) {\n dataSourceConfigRef.current = config;\n save?.(config, \"datasource-config\");\n }\n }\n },\n [save],\n );\n\n const dataSource: DataSource = useMemo(() => {\n let ds = loadSession?.(dataSourceSessionKey) as DataSource;\n if (ds) {\n if (dataSourceConfigFromState) {\n // this won't do anything if dataSource config already matches this\n // This is only really used when injecting a dataSource into session\n // state in Showcase examples\n // DO we definitely need this ? If not apply config can be provate\n ds.applyConfig(dataSourceConfigFromState, true);\n }\n\n if (ds.range.from > 0) {\n // UI does not currently restore scroll position, so always reset to top of dataset\n ds.range = ds.range.reset;\n }\n\n return ds;\n }\n\n const columns =\n dataSourceConfigFromState?.columns ??\n tableSchema.columns.map((col) => col.name);\n\n ds = new VuuDataSource({\n // bufferSize: 0,\n viewport: id,\n table: tableSchema.table,\n ...dataSourceConfigRef.current,\n columns,\n title,\n });\n ds.on(\"config\", handleDataSourceConfigChange);\n saveSession?.(ds, \"data-source\");\n return ds;\n }, [\n VuuDataSource,\n dataSourceConfigFromState,\n dataSourceSessionKey,\n handleDataSourceConfigChange,\n id,\n loadSession,\n saveSession,\n tableSchema.columns,\n tableSchema.table,\n title,\n ]);\n\n return dataSource;\n};\n"],"names":["useViewContext","useData","useMemo","useRef","useCallback","isConfigChanged"],"mappings":";;;;;;AAeA,MAAM,YAA0B,EAAC;AAE1B,MAAM,uBAAuB,CAAC;AAAA,EACnC,oBAAuB,GAAA,aAAA;AAAA,EACvB;AACF,CAGM,KAAA;AACJ,EAAM,MAAA,EAAE,IAAI,IAAM,EAAA,IAAA,EAAM,aAAa,WAAa,EAAA,KAAA,KAAUA,wBAAe,EAAA;AAC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ErB,QAAU,EAAA,EAAA;AAAA,MACV,OAAO,WAAY,CAAA,KAAA;AAAA,MACnB,GAAG,mBAAoB,CAAA,OAAA;AAAA,MACvB,OAAA;AAAA,MACA;AAAA,KACD,CAAA;AACD,IAAG,EAAA,CAAA,EAAA,CAAG,UAAU,4BAA4B,CAAA;AAC5C,IAAA,WAAA,GAAc,IAAI,aAAa,CAAA;AAC/B,IAAO,OAAA,EAAA;AAAA,GACN,EAAA;AAAA,IACD,aAAA;AAAA,IACA,yBAAA;AAAA,IACA,oBAAA;AAAA,IACA,4BAAA;AAAA,IACA,EAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAY,CAAA,OAAA;AAAA,IACZ,WAAY,CAAA,KAAA;AAAA,IACZ;AAAA,GACD,CAAA;AAED,EAAO,OAAA,UAAA;AACT;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { useViewContext } from '@vuu-ui/vuu-layout';
2
2
  import { useData, isConfigChanged } from '@vuu-ui/vuu-utils';
3
- import { useMemo, useCallback } from 'react';
3
+ import { useMemo, useRef, useCallback } from 'react';
4
4
 
5
5
  const NO_CONFIG = {};
6
6
  const useSessionDataSource = ({
@@ -10,19 +10,23 @@ const useSessionDataSource = ({
10
10
  const { id, load, save, loadSession, saveSession, title } = useViewContext();
11
11
  const { VuuDataSource } = useData();
12
12
  const { "datasource-config": dataSourceConfigFromState } = useMemo(() => load?.() ?? NO_CONFIG, [load]);
13
+ const dataSourceConfigRef = useRef(
14
+ dataSourceConfigFromState
15
+ );
13
16
  const handleDataSourceConfigChange = useCallback(
14
17
  (config, _range, confirmed) => {
15
18
  if (confirmed !== false) {
16
19
  const { noChanges } = isConfigChanged(
17
- dataSourceConfigFromState,
20
+ dataSourceConfigRef.current,
18
21
  config
19
22
  );
20
23
  if (noChanges === false) {
24
+ dataSourceConfigRef.current = config;
21
25
  save?.(config, "datasource-config");
22
26
  }
23
27
  }
24
28
  },
25
- [dataSourceConfigFromState, save]
29
+ [save]
26
30
  );
27
31
  const dataSource = useMemo(() => {
28
32
  let ds = loadSession?.(dataSourceSessionKey);
@@ -40,7 +44,7 @@ const useSessionDataSource = ({
40
44
  // bufferSize: 0,
41
45
  viewport: id,
42
46
  table: tableSchema.table,
43
- ...dataSourceConfigFromState,
47
+ ...dataSourceConfigRef.current,
44
48
  columns,
45
49
  title
46
50
  });
@@ -1 +1 @@
1
- {"version":3,"file":"useSessionDataSource.js","sources":["../../src/hooks/useSessionDataSource.ts"],"sourcesContent":["import type {\n DataSource,\n DataSourceConfig,\n DataSourceConfigChangeHandler,\n TableSchema,\n} from \"@vuu-ui/vuu-data-types\";\nimport { useViewContext } from \"@vuu-ui/vuu-layout\";\nimport type { VuuRange } from \"@vuu-ui/vuu-protocol-types\";\nimport { isConfigChanged, useData } from \"@vuu-ui/vuu-utils\";\nimport { useCallback, useMemo } from \"react\";\n\ntype SessionDataSourceConfig = {\n \"datasource-config\"?: DataSourceConfig;\n};\n\nconst NO_CONFIG: SessionDataSourceConfig = {};\n\nexport const useSessionDataSource = ({\n dataSourceSessionKey = \"data-source\",\n tableSchema,\n}: {\n dataSourceSessionKey?: string;\n tableSchema: TableSchema;\n}) => {\n const { id, load, save, loadSession, saveSession, title } = useViewContext();\n const { VuuDataSource } = useData();\n\n const { \"datasource-config\": dataSourceConfigFromState } =\n useMemo<SessionDataSourceConfig>(() => load?.() ?? NO_CONFIG, [load]);\n\n const handleDataSourceConfigChange =\n useCallback<DataSourceConfigChangeHandler>(\n (\n config: DataSourceConfig | undefined,\n _range: VuuRange,\n confirmed?: boolean,\n ) => {\n if (confirmed !== false) {\n const { noChanges } = isConfigChanged(\n dataSourceConfigFromState,\n config,\n );\n if (noChanges === false) {\n save?.(config, \"datasource-config\");\n }\n }\n },\n [dataSourceConfigFromState, save],\n );\n\n const dataSource: DataSource = useMemo(() => {\n let ds = loadSession?.(dataSourceSessionKey) as DataSource;\n if (ds) {\n if (dataSourceConfigFromState) {\n // this won't do anything if dataSource config already matches this\n // This is only really used when injecting a dataSource into session\n // state in Showcase examples\n // DO we definitely need this ? If not apply config can be provate\n ds.applyConfig(dataSourceConfigFromState, true);\n }\n\n if (ds.range.from > 0) {\n // UI does not currently restore scroll position, so always reset to top of dataset\n ds.range = ds.range.reset;\n }\n\n return ds;\n }\n\n const columns =\n dataSourceConfigFromState?.columns ??\n tableSchema.columns.map((col) => col.name);\n\n ds = new VuuDataSource({\n // bufferSize: 0,\n viewport: id,\n table: tableSchema.table,\n ...dataSourceConfigFromState,\n columns,\n title,\n });\n ds.on(\"config\", handleDataSourceConfigChange);\n saveSession?.(ds, \"data-source\");\n return ds;\n }, [\n VuuDataSource,\n dataSourceConfigFromState,\n dataSourceSessionKey,\n handleDataSourceConfigChange,\n id,\n loadSession,\n saveSession,\n tableSchema.columns,\n tableSchema.table,\n title,\n ]);\n\n return dataSource;\n};\n"],"names":[],"mappings":";;;;AAeA,MAAM,YAAqC,EAAC;AAErC,MAAM,uBAAuB,CAAC;AAAA,EACnC,oBAAuB,GAAA,aAAA;AAAA,EACvB;AACF,CAGM,KAAA;AACJ,EAAM,MAAA,EAAE,IAAI,IAAM,EAAA,IAAA,EAAM,aAAa,WAAa,EAAA,KAAA,KAAU,cAAe,EAAA;AAC3E,EAAM,MAAA,EAAE,aAAc,EAAA,GAAI,OAAQ,EAAA;AAElC,EAAM,MAAA,EAAE,mBAAqB,EAAA,yBAAA,EAC3B,GAAA,OAAA,CAAiC,MAAM,IAAA,IAAY,IAAA,SAAA,EAAW,CAAC,IAAI,CAAC,CAAA;AAEtE,EAAA,MAAM,4BACJ,GAAA,WAAA;AAAA,IACE,CACE,MACA,EAAA,MAAA,EACA,SACG,KAAA;AACH,MAAA,IAAI,cAAc,KAAO,EAAA;AACvB,QAAM,MAAA,EAAE,WAAc,GAAA,eAAA;AAAA,UACpB,yBAAA;AAAA,UACA;AAAA,SACF;AACA,QAAA,IAAI,cAAc,KAAO,EAAA;AACvB,UAAA,IAAA,GAAO,QAAQ,mBAAmB,CAAA;AAAA;AACpC;AACF,KACF;AAAA,IACA,CAAC,2BAA2B,IAAI;AAAA,GAClC;AAEF,EAAM,MAAA,UAAA,GAAyB,QAAQ,MAAM;AAC3C,IAAI,IAAA,EAAA,GAAK,cAAc,oBAAoB,CAAA;AAC3C,IAAA,IAAI,EAAI,EAAA;AACN,MAAA,IAAI,yBAA2B,EAAA;AAK7B,QAAG,EAAA,CAAA,WAAA,CAAY,2BAA2B,IAAI,CAAA;AAAA;AAGhD,MAAI,IAAA,EAAA,CAAG,KAAM,CAAA,IAAA,GAAO,CAAG,EAAA;AAErB,QAAG,EAAA,CAAA,KAAA,GAAQ,GAAG,KAAM,CAAA,KAAA;AAAA;AAGtB,MAAO,OAAA,EAAA;AAAA;AAGT,IAAM,MAAA,OAAA,GACJ,2BAA2B,OAC3B,IAAA,WAAA,CAAY,QAAQ,GAAI,CAAA,CAAC,GAAQ,KAAA,GAAA,CAAI,IAAI,CAAA;AAE3C,IAAA,EAAA,GAAK,IAAI,aAAc,CAAA;AAAA;AAAA,MAErB,QAAU,EAAA,EAAA;AAAA,MACV,OAAO,WAAY,CAAA,KAAA;AAAA,MACnB,GAAG,yBAAA;AAAA,MACH,OAAA;AAAA,MACA;AAAA,KACD,CAAA;AACD,IAAG,EAAA,CAAA,EAAA,CAAG,UAAU,4BAA4B,CAAA;AAC5C,IAAA,WAAA,GAAc,IAAI,aAAa,CAAA;AAC/B,IAAO,OAAA,EAAA;AAAA,GACN,EAAA;AAAA,IACD,aAAA;AAAA,IACA,yBAAA;AAAA,IACA,oBAAA;AAAA,IACA,4BAAA;AAAA,IACA,EAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAY,CAAA,OAAA;AAAA,IACZ,WAAY,CAAA,KAAA;AAAA,IACZ;AAAA,GACD,CAAA;AAED,EAAO,OAAA,UAAA;AACT;;;;"}
1
+ {"version":3,"file":"useSessionDataSource.js","sources":["../../src/hooks/useSessionDataSource.ts"],"sourcesContent":["import type {\n DataSource,\n DataSourceConfig,\n DataSourceConfigChangeHandler,\n TableSchema,\n} from \"@vuu-ui/vuu-data-types\";\nimport { useViewContext } from \"@vuu-ui/vuu-layout\";\nimport type { VuuRange } from \"@vuu-ui/vuu-protocol-types\";\nimport { isConfigChanged, useData } from \"@vuu-ui/vuu-utils\";\nimport { useCallback, useMemo, useRef } from \"react\";\n\ntype SessionState = {\n \"datasource-config\"?: DataSourceConfig;\n};\n\nconst NO_CONFIG: SessionState = {};\n\nexport const useSessionDataSource = ({\n dataSourceSessionKey = \"data-source\",\n tableSchema,\n}: {\n dataSourceSessionKey?: string;\n tableSchema: TableSchema;\n}) => {\n const { id, load, save, loadSession, saveSession, title } = useViewContext();\n const { VuuDataSource } = useData();\n\n const { \"datasource-config\": dataSourceConfigFromState } =\n useMemo<SessionState>(() => load?.() ?? NO_CONFIG, [load]);\n\n const dataSourceConfigRef = useRef<DataSourceConfig | undefined>(\n dataSourceConfigFromState,\n );\n\n const handleDataSourceConfigChange =\n useCallback<DataSourceConfigChangeHandler>(\n (\n config: DataSourceConfig | undefined,\n _range: VuuRange,\n confirmed?: boolean,\n ) => {\n if (confirmed !== false) {\n const { noChanges } = isConfigChanged(\n dataSourceConfigRef.current,\n config,\n );\n if (noChanges === false) {\n dataSourceConfigRef.current = config;\n save?.(config, \"datasource-config\");\n }\n }\n },\n [save],\n );\n\n const dataSource: DataSource = useMemo(() => {\n let ds = loadSession?.(dataSourceSessionKey) as DataSource;\n if (ds) {\n if (dataSourceConfigFromState) {\n // this won't do anything if dataSource config already matches this\n // This is only really used when injecting a dataSource into session\n // state in Showcase examples\n // DO we definitely need this ? If not apply config can be provate\n ds.applyConfig(dataSourceConfigFromState, true);\n }\n\n if (ds.range.from > 0) {\n // UI does not currently restore scroll position, so always reset to top of dataset\n ds.range = ds.range.reset;\n }\n\n return ds;\n }\n\n const columns =\n dataSourceConfigFromState?.columns ??\n tableSchema.columns.map((col) => col.name);\n\n ds = new VuuDataSource({\n // bufferSize: 0,\n viewport: id,\n table: tableSchema.table,\n ...dataSourceConfigRef.current,\n columns,\n title,\n });\n ds.on(\"config\", handleDataSourceConfigChange);\n saveSession?.(ds, \"data-source\");\n return ds;\n }, [\n VuuDataSource,\n dataSourceConfigFromState,\n dataSourceSessionKey,\n handleDataSourceConfigChange,\n id,\n loadSession,\n saveSession,\n tableSchema.columns,\n tableSchema.table,\n title,\n ]);\n\n return dataSource;\n};\n"],"names":[],"mappings":";;;;AAeA,MAAM,YAA0B,EAAC;AAE1B,MAAM,uBAAuB,CAAC;AAAA,EACnC,oBAAuB,GAAA,aAAA;AAAA,EACvB;AACF,CAGM,KAAA;AACJ,EAAM,MAAA,EAAE,IAAI,IAAM,EAAA,IAAA,EAAM,aAAa,WAAa,EAAA,KAAA,KAAU,cAAe,EAAA;AAC3E,EAAM,MAAA,EAAE,aAAc,EAAA,GAAI,OAAQ,EAAA;AAElC,EAAM,MAAA,EAAE,mBAAqB,EAAA,yBAAA,EAC3B,GAAA,OAAA,CAAsB,MAAM,IAAA,IAAY,IAAA,SAAA,EAAW,CAAC,IAAI,CAAC,CAAA;AAE3D,EAAA,MAAM,mBAAsB,GAAA,MAAA;AAAA,IAC1B;AAAA,GACF;AAEA,EAAA,MAAM,4BACJ,GAAA,WAAA;AAAA,IACE,CACE,MACA,EAAA,MAAA,EACA,SACG,KAAA;AACH,MAAA,IAAI,cAAc,KAAO,EAAA;AACvB,QAAM,MAAA,EAAE,WAAc,GAAA,eAAA;AAAA,UACpB,mBAAoB,CAAA,OAAA;AAAA,UACpB;AAAA,SACF;AACA,QAAA,IAAI,cAAc,KAAO,EAAA;AACvB,UAAA,mBAAA,CAAoB,OAAU,GAAA,MAAA;AAC9B,UAAA,IAAA,GAAO,QAAQ,mBAAmB,CAAA;AAAA;AACpC;AACF,KACF;AAAA,IACA,CAAC,IAAI;AAAA,GACP;AAEF,EAAM,MAAA,UAAA,GAAyB,QAAQ,MAAM;AAC3C,IAAI,IAAA,EAAA,GAAK,cAAc,oBAAoB,CAAA;AAC3C,IAAA,IAAI,EAAI,EAAA;AACN,MAAA,IAAI,yBAA2B,EAAA;AAK7B,QAAG,EAAA,CAAA,WAAA,CAAY,2BAA2B,IAAI,CAAA;AAAA;AAGhD,MAAI,IAAA,EAAA,CAAG,KAAM,CAAA,IAAA,GAAO,CAAG,EAAA;AAErB,QAAG,EAAA,CAAA,KAAA,GAAQ,GAAG,KAAM,CAAA,KAAA;AAAA;AAGtB,MAAO,OAAA,EAAA;AAAA;AAGT,IAAM,MAAA,OAAA,GACJ,2BAA2B,OAC3B,IAAA,WAAA,CAAY,QAAQ,GAAI,CAAA,CAAC,GAAQ,KAAA,GAAA,CAAI,IAAI,CAAA;AAE3C,IAAA,EAAA,GAAK,IAAI,aAAc,CAAA;AAAA;AAAA,MAErB,QAAU,EAAA,EAAA;AAAA,MACV,OAAO,WAAY,CAAA,KAAA;AAAA,MACnB,GAAG,mBAAoB,CAAA,OAAA;AAAA,MACvB,OAAA;AAAA,MACA;AAAA,KACD,CAAA;AACD,IAAG,EAAA,CAAA,EAAA,CAAG,UAAU,4BAA4B,CAAA;AAC5C,IAAA,WAAA,GAAc,IAAI,aAAa,CAAA;AAC/B,IAAO,OAAA,EAAA;AAAA,GACN,EAAA;AAAA,IACD,aAAA;AAAA,IACA,yBAAA;AAAA,IACA,oBAAA;AAAA,IACA,4BAAA;AAAA,IACA,EAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAY,CAAA,OAAA;AAAA,IACZ,WAAY,CAAA,KAAA;AAAA,IACZ;AAAA,GACD,CAAA;AAED,EAAO,OAAA,UAAA;AACT;;;;"}
package/package.json CHANGED
@@ -1,23 +1,23 @@
1
1
  {
2
- "version": "0.13.5",
2
+ "version": "0.13.6",
3
3
  "author": "heswell",
4
4
  "license": "Apache-2.0",
5
5
  "devDependencies": {
6
- "@vuu-ui/vuu-data-types": "0.13.5",
7
- "@vuu-ui/vuu-filter-types": "0.13.5",
8
- "@vuu-ui/vuu-popups": "0.13.5",
9
- "@vuu-ui/vuu-protocol-types": "0.13.5",
10
- "@vuu-ui/vuu-table-types": "0.13.5"
6
+ "@vuu-ui/vuu-data-types": "0.13.6",
7
+ "@vuu-ui/vuu-filter-types": "0.13.6",
8
+ "@vuu-ui/vuu-popups": "0.13.6",
9
+ "@vuu-ui/vuu-protocol-types": "0.13.6",
10
+ "@vuu-ui/vuu-table-types": "0.13.6"
11
11
  },
12
12
  "dependencies": {
13
- "@vuu-ui/vuu-context-menu": "0.13.5",
14
- "@vuu-ui/vuu-data-remote": "0.13.5",
15
- "@vuu-ui/vuu-filter-parser": "0.13.5",
16
- "@vuu-ui/vuu-layout": "0.13.5",
17
- "@vuu-ui/vuu-popups": "0.13.5",
18
- "@vuu-ui/vuu-ui-controls": "0.13.5",
19
- "@vuu-ui/vuu-utils": "0.13.5",
20
- "@vuu-ui/vuu-table": "0.13.5",
13
+ "@vuu-ui/vuu-context-menu": "0.13.6",
14
+ "@vuu-ui/vuu-data-remote": "0.13.6",
15
+ "@vuu-ui/vuu-filter-parser": "0.13.6",
16
+ "@vuu-ui/vuu-layout": "0.13.6",
17
+ "@vuu-ui/vuu-popups": "0.13.6",
18
+ "@vuu-ui/vuu-ui-controls": "0.13.6",
19
+ "@vuu-ui/vuu-utils": "0.13.6",
20
+ "@vuu-ui/vuu-table": "0.13.6",
21
21
  "@salt-ds/core": "1.43.0",
22
22
  "@salt-ds/styles": "0.2.1",
23
23
  "@salt-ds/window": "0.1.1"