wx-svelte-grid 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wx-svelte-grid",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "A powerful and flexible DataGrid component written in Svelte",
5
5
  "productTag": "grid",
6
6
  "needsTrial": true,
@@ -36,9 +36,9 @@
36
36
  "wx-lib-svelte": "0.4.0",
37
37
  "wx-svelte-menu": "1.3.0",
38
38
  "wx-svelte-core": "1.3.1",
39
- "wx-grid-data-provider": "1.3.1",
40
- "wx-grid-locales": "1.3.1",
41
- "wx-grid-store": "1.3.1"
39
+ "wx-grid-data-provider": "1.3.3",
40
+ "wx-grid-locales": "1.3.3",
41
+ "wx-grid-store": "1.3.3"
42
42
  },
43
43
  "files": [
44
44
  "src",
@@ -1,6 +1,6 @@
1
1
  <script>
2
2
  // svelte core
3
- import { createEventDispatcher, getContext } from "svelte";
3
+ import { createEventDispatcher, getContext, setContext } from "svelte";
4
4
  import { writable } from "svelte/store";
5
5
  const dispatch = createEventDispatcher();
6
6
 
@@ -31,7 +31,6 @@
31
31
  export let header = true;
32
32
  export let footer = false;
33
33
  export let dynamic = null;
34
- export let editor = null;
35
34
  export let filter = null;
36
35
  export let overlay = null;
37
36
  export let autoRowHeight = false;
@@ -72,7 +71,6 @@
72
71
  $: {
73
72
  dataStore.init({
74
73
  data,
75
- editor,
76
74
  columns,
77
75
  split,
78
76
  sizes,
@@ -95,10 +93,6 @@
95
93
  let lastInRoute = new EventBusRouter(dispatch);
96
94
  firstInRoute.setNext(lastInRoute);
97
95
 
98
- const actions = ev => {
99
- firstInRoute.exec(ev.detail.action, ev.detail.data);
100
- };
101
-
102
96
  // public API
103
97
  export const api = {
104
98
  // state
@@ -117,12 +111,17 @@
117
111
  getRow: id => dataStore.getRow(id),
118
112
  getColumn: id => dataStore.getColumn(id),
119
113
  };
114
+
115
+ // common API available in components
116
+ setContext("grid-store", {
117
+ getReactiveState: dataStore.getReactive.bind(dataStore),
118
+ exec: firstInRoute.exec.bind(firstInRoute),
119
+ getRow: dataStore.getRow.bind(dataStore),
120
+ });
120
121
  </script>
121
122
 
122
123
  <Locale words={en} optional={true}>
123
124
  <Layout
124
- store={dataStore}
125
- {api}
126
125
  {header}
127
126
  {footer}
128
127
  {overlay}
@@ -132,7 +131,5 @@
132
131
  {select}
133
132
  {multiselect}
134
133
  {autoRowHeight}
135
- on:action={actions}
136
- on:data-request
137
134
  />
138
135
  </Locale>
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import { createEventDispatcher } from "svelte";
2
+ import { getContext } from "svelte";
3
3
  import { resize } from "../helpers/actions/resize";
4
4
  import { getCssName, getStyle } from "../helpers/columnWidth";
5
5
 
@@ -9,7 +9,8 @@
9
9
  export let lastRow;
10
10
  export let columnStyle;
11
11
 
12
- const dispatch = createEventDispatcher();
12
+ const api = getContext("grid-store");
13
+
13
14
  let start;
14
15
 
15
16
  function down(node) {
@@ -17,23 +18,17 @@
17
18
  }
18
19
 
19
20
  function move(dx) {
20
- dispatch("action", {
21
- action: "resize-column",
22
- data: { id: cell.id, width: Math.max(1, start + dx) },
21
+ api.exec("resize-column", {
22
+ id: cell.id,
23
+ width: Math.max(1, start + dx),
23
24
  });
24
25
  }
25
26
 
26
27
  function sort(ev) {
27
- dispatch("action", {
28
- action: "sort-rows",
29
- data: { key: cell.id, add: ev.ctrlKey },
30
- });
28
+ api.exec("sort-rows", { key: cell.id, add: ev.ctrlKey });
31
29
  }
32
30
  function collapse() {
33
- dispatch("action", {
34
- action: "collapse-column",
35
- data: { id: cell.id, row },
36
- });
31
+ api.exec("collapse-column", { id: cell.id, row });
37
32
  }
38
33
 
39
34
  let style;
@@ -1,15 +1,19 @@
1
1
  <script>
2
+ import { getContext } from "svelte";
2
3
  import HeaderCell from "./HeaderCell.svelte";
3
4
  import FooterCell from "./FooterCell.svelte";
4
5
 
5
6
  export let deltaLeft;
6
7
  export let contentWidth;
7
- export let rowHeights;
8
8
  export let columns;
9
9
  export let type = "header";
10
10
 
11
11
  export let columnStyle;
12
12
 
13
+ const api = getContext("grid-store");
14
+ const { _sizes: sizes } = api.getReactiveState();
15
+ $: rowHeights = $sizes[`${type}RowHeights`];
16
+
13
17
  let renderedHeader = [];
14
18
  $: {
15
19
  if (columns.length) {
@@ -58,7 +62,6 @@
58
62
  column={getColumn(cell.id)}
59
63
  row={i}
60
64
  lastRow={isLast(cell, i)}
61
- on:action
62
65
  />
63
66
  {:else}
64
67
  <FooterCell
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import { createEventDispatcher, afterUpdate } from "svelte";
2
+ import { afterUpdate, getContext } from "svelte";
3
3
  import { onresize } from "../helpers/actions/onresize";
4
4
  import { delegateClick, locateAttr, clickOutside } from "wx-lib-dom";
5
5
  import { hotkeys } from "wx-grid-store";
@@ -10,12 +10,8 @@
10
10
  import Overlay from "./Overlay.svelte";
11
11
  import Editor from "./inlineEditors/Editor.svelte";
12
12
 
13
- const dispatch = createEventDispatcher();
14
-
15
13
  const SCROLLSIZE = getScrollSize();
16
14
 
17
- export let store;
18
- export let api;
19
15
  export let header;
20
16
  export let footer;
21
17
  export let overlay;
@@ -27,6 +23,8 @@
27
23
  export let cellStyle;
28
24
  export let autoRowHeight;
29
25
 
26
+ const api = getContext("grid-store");
27
+
30
28
  const {
31
29
  dynamic,
32
30
  flatData: data,
@@ -37,7 +35,7 @@
37
35
  editor,
38
36
  filter,
39
37
  scroll,
40
- } = store.getReactive();
38
+ } = api.getReactiveState();
41
39
 
42
40
  $: defaultRowHeight = $_sizes.rowHeight;
43
41
  let clientWidth = 0,
@@ -161,7 +159,7 @@
161
159
  if (start != requestData.row.start || end != requestData.row.end) {
162
160
  requestData = { row: { start, end } };
163
161
  if ($dynamic) {
164
- dispatch("data-request", { requestData });
162
+ api.exec("data-request", { requestData });
165
163
  }
166
164
  }
167
165
  }
@@ -272,26 +270,18 @@
272
270
  const bodyClickHandlers = {
273
271
  dblclick: (id, ev) => {
274
272
  const data = { id, column: locateAttr(ev, "data-col-id") };
275
- dispatch("action", { action: "open-editor", data });
273
+ api.exec("open-editor", data);
276
274
  },
277
275
  click: (id, ev) => {
278
276
  if (select === false) return;
279
277
 
280
278
  const toggle = multiselect && ev.ctrlKey;
281
279
  const range = multiselect && ev.shiftKey;
282
- dispatch("action", {
283
- action: "select-row",
284
- data: { id, toggle, range },
285
- });
280
+ api.exec("select-row", { id, toggle, range });
286
281
  },
287
282
  "toggle-row": id => {
288
- const row = store.getRow(id);
289
- dispatch("action", {
290
- action: row.open !== false ? "close-row" : "open-row",
291
- data: {
292
- id,
293
- },
294
- });
283
+ const row = api.getRow(id);
284
+ api.exec(row.open !== false ? "close-row" : "open-row", { id });
295
285
  },
296
286
  "ignore-click": () => {
297
287
  return false;
@@ -420,10 +410,8 @@
420
410
  <HeaderFooter
421
411
  {contentWidth}
422
412
  deltaLeft={deltaLeftH}
423
- rowHeights={$_sizes.headerRowHeights}
424
413
  columns={renderColumnsH}
425
414
  {columnStyle}
426
- on:action
427
415
  />
428
416
  </div>
429
417
  {/if}
@@ -434,7 +422,7 @@
434
422
  use:delegateClick={bodyClickHandlers}
435
423
  >
436
424
  {#if overlay}
437
- <Overlay {overlay} on:action />
425
+ <Overlay {overlay} />
438
426
  {/if}
439
427
  <div
440
428
  bind:this={dataEl}
@@ -456,7 +444,7 @@
456
444
  {#if col.collapsed}
457
445
  <div class="wx-cell wx-collapsed" />
458
446
  {:else if $editor?.id === row.id && $editor.column == col.id}
459
- <Editor editor={$editor} {col} on:action />
447
+ <Editor {col} />
460
448
  {:else if col.cell}
461
449
  <svelte:component
462
450
  this={col.cell}
@@ -465,7 +453,11 @@
465
453
  {col}
466
454
  {columnStyle}
467
455
  {cellStyle}
468
- on:action
456
+ on:action={({ detail }) =>
457
+ api.exec(
458
+ detail.action,
459
+ detail.data
460
+ )}
469
461
  />
470
462
  {:else}
471
463
  <Cell
@@ -473,7 +465,6 @@
473
465
  {col}
474
466
  {columnStyle}
475
467
  {cellStyle}
476
- on:action
477
468
  />
478
469
  {/if}
479
470
  {/each}
@@ -486,10 +477,8 @@
486
477
  type={"footer"}
487
478
  {contentWidth}
488
479
  deltaLeft={deltaLeftF}
489
- rowHeights={$_sizes.footerRowHeights}
490
480
  columns={renderColumnsF}
491
481
  {columnStyle}
492
- on:action
493
482
  />
494
483
  {/if}
495
484
  </div>
@@ -1,6 +1,8 @@
1
1
  <script>
2
+ import { getContext } from "svelte";
2
3
  export let overlay;
3
4
 
5
+ const api = getContext("grid-store");
4
6
  function isComponent(prop) {
5
7
  return typeof prop === "function";
6
8
  }
@@ -8,7 +10,10 @@
8
10
 
9
11
  <div class="wx-overlay">
10
12
  {#if isComponent(overlay)}
11
- <svelte:component this={overlay} on:action />
13
+ <svelte:component
14
+ this={overlay}
15
+ on:action={({ detail }) => api.exec(detail.action, detail.data)}
16
+ />
12
17
  {:else}{overlay}{/if}
13
18
  </div>
14
19
 
@@ -1,36 +1,24 @@
1
1
  <script>
2
- import { createEventDispatcher } from "svelte";
2
+ import { getContext } from "svelte";
3
3
  import { getStyle } from "../../helpers/columnWidth";
4
4
  import { clickOutside } from "wx-lib-dom";
5
-
6
5
  import { editors } from "./editors";
7
6
 
8
7
  export let col;
9
- export let editor;
10
8
 
11
- const dispatch = createEventDispatcher();
9
+ const api = getContext("grid-store");
10
+ const { editor } = api.getReactiveState();
12
11
 
13
12
  function save() {
14
- dispatch("action", {
15
- action: "close-editor",
16
- data: { ignore: false },
17
- });
13
+ api.exec("close-editor", { ignore: false });
18
14
  }
19
15
 
20
16
  function cancel() {
21
- dispatch("action", {
22
- action: "close-editor",
23
- data: { ignore: true },
24
- });
17
+ api.exec("close-editor", { ignore: true });
25
18
  }
26
19
 
27
20
  function updateValue(value) {
28
- dispatch("action", {
29
- action: "editor",
30
- data: {
31
- value,
32
- },
33
- });
21
+ api.exec("editor", { value });
34
22
  }
35
23
 
36
24
  let style;
@@ -45,9 +33,9 @@
45
33
  >
46
34
  <svelte:component
47
35
  this={editors[col.editor.type]}
48
- {editor}
36
+ editor={$editor}
49
37
  actions={{ save, cancel, updateValue }}
50
- on:action
38
+ on:action={({ detail }) => api.exec(detail.action, detail.data)}
51
39
  />
52
40
  </div>
53
41
 
package/whatsnew.md CHANGED
@@ -1,4 +1,10 @@
1
- ### 1.3.1
1
+ ### 1.3.3
2
+
3
+ - [fix] treetable data is not fully shown in some cases
4
+ - [fix] too narrow column width if autowidth is set
5
+ - [fix] typos in type definitions
6
+
7
+ ### 1.3.2
2
8
 
3
9
  - [fix] editors in tree mode are not applied correctly
4
10
  - [fix] ts definitions are not precise