@kanaries/graphic-walker 0.2.18 → 0.3.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.
@@ -128,7 +128,6 @@ export interface IFilterField extends IViewField {
128
128
  rule: IFilterRule | null;
129
129
  }
130
130
  export interface DraggableFieldState {
131
- fields: IViewField[];
132
131
  dimensions: IViewField[];
133
132
  measures: IViewField[];
134
133
  rows: IViewField[];
package/dist/main.d.ts CHANGED
@@ -1 +1 @@
1
- import "./index.css";
1
+ import './index.css';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanaries/graphic-walker",
3
- "version": "0.2.18",
3
+ "version": "0.3.0",
4
4
  "scripts": {
5
5
  "dev:front_end": "vite --host",
6
6
  "dev": "npm run dev:front_end",
@@ -43,6 +43,7 @@
43
43
  "immer": "^9.0.15",
44
44
  "mobx": "^6.3.3",
45
45
  "mobx-react-lite": "^3.2.1",
46
+ "nanoid": "^4.0.2",
46
47
  "postcss": "^8.3.7",
47
48
  "postinstall-postinstall": "^2.1.0",
48
49
  "re-resizable": "^6.9.8",
@@ -69,8 +70,8 @@
69
70
  "vite": "^4.1.1"
70
71
  },
71
72
  "peerDependencies": {
72
- "react": "^17.0.2",
73
- "react-dom": "^17.0.2",
73
+ "react": ">=17.0.0 <19.0.0",
74
+ "react-dom": ">=17.0.0 <19.0.0",
74
75
  "styled-components": "^5.3.6"
75
76
  }
76
77
  }
@@ -17,7 +17,7 @@ const syntaxHighlight = (json: any) => {
17
17
  .replace(/>/g, "&gt;")
18
18
  .replace(/\n/g, "<br>")
19
19
  .replace(/\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;")
20
- .replace(/\s/g, "&nbsp;&nbsp;");
20
+ .replace(/\s/g, "&nbsp;");
21
21
  return json.replace(
22
22
  /("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,
23
23
  function (match) {
@@ -84,8 +84,8 @@ const CodeExport: React.FC = observer((props) => {
84
84
  }}
85
85
  />
86
86
  {tabKey === "graphic-walker" && (
87
- <div className="text-sm px-6 max-h-56 overflow-auto">
88
- <div dangerouslySetInnerHTML={{ __html: syntaxHighlight(code) }} />
87
+ <div className="text-sm px-6 max-h-96 overflow-auto">
88
+ <code dangerouslySetInnerHTML={{ __html: syntaxHighlight(code) }} />
89
89
  </div>
90
90
  )}
91
91
  <div className="mt-4 flex justify-start">
package/src/config.ts CHANGED
@@ -53,5 +53,4 @@ export const CHANNEL_LIMIT = {
53
53
  export const MetaFieldKeys: Array<keyof DraggableFieldState> = [
54
54
  'dimensions',
55
55
  'measures',
56
- 'fields'
57
56
  ]
@@ -40,7 +40,6 @@ export const FieldsContextWrapper: React.FC = props => {
40
40
  export default FieldsContextWrapper;
41
41
 
42
42
  export const DRAGGABLE_STATE_KEYS: Readonly<IDraggableStateKey[]> = [
43
- { id: 'fields', mode: 0 },
44
43
  { id: 'columns', mode: 0 },
45
44
  { id: 'rows', mode: 0 },
46
45
  { id: 'color', mode: 1 },
package/src/interfaces.ts CHANGED
@@ -149,7 +149,6 @@ export interface IFilterField extends IViewField {
149
149
  }
150
150
 
151
151
  export interface DraggableFieldState {
152
- fields: IViewField[];
153
152
  dimensions: IViewField[];
154
153
  measures: IViewField[];
155
154
  rows: IViewField[];
package/src/main.tsx CHANGED
@@ -1,17 +1,39 @@
1
- import React from "react";
2
- import ReactDOM from "react-dom";
3
- import { GraphicWalker } from "./index";
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import { GraphicWalker } from './index';
4
4
 
5
- import { inject } from "@vercel/analytics";
6
- import "./index.css";
5
+ import { inject } from '@vercel/analytics';
6
+ import './index.css';
7
7
 
8
8
  if (!import.meta.env.DEV) {
9
9
  inject();
10
10
  }
11
11
 
12
- ReactDOM.render(
13
- <React.StrictMode>
14
- <GraphicWalker themeKey="g2" />
15
- </React.StrictMode>,
16
- document.getElementById("root")
17
- );
12
+ // Example: Detect if Concurrent Mode is available
13
+ const isConcurrentModeAvailable = 'createRoot' in ReactDOM;
14
+ console.log(isConcurrentModeAvailable)
15
+
16
+ // Use the new ReactDOM.createRoot API if available, otherwise fall back to the old ReactDOM.render API
17
+ if (isConcurrentModeAvailable) {
18
+ // @ts-ignore
19
+ const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
20
+ root.render(
21
+ <React.StrictMode>
22
+ <GraphicWalker themeKey="g2" />
23
+ </React.StrictMode>
24
+ );
25
+ } else {
26
+ ReactDOM.render(
27
+ <React.StrictMode>
28
+ <GraphicWalker themeKey="g2" />
29
+ </React.StrictMode>,
30
+ document.getElementById('root') as HTMLElement
31
+ );
32
+ }
33
+
34
+ // ReactDOM.render(
35
+ // <React.StrictMode>
36
+ // <GraphicWalker themeKey="g2" />
37
+ // </React.StrictMode>,
38
+ // document.getElementById("root")
39
+ // );
@@ -130,6 +130,7 @@ export class VisSpecWithHistory {
130
130
 
131
131
  public clone () {
132
132
  const nextVSWH = new VisSpecWithHistory(this.frame);
133
+ nextVSWH.snapshots = this.snapshots.slice().map(s => ({ ...s }));
133
134
  nextVSWH.cursor = this.cursor;
134
135
  return nextVSWH;
135
136
  }
@@ -1,18 +1,22 @@
1
1
  import { IReactionDisposer, makeAutoObservable, observable, reaction, toJS } from "mobx";
2
2
  import produce from "immer";
3
- import { v4 as uuidv4 } from "uuid";
4
3
  import { DataSet, DraggableFieldState, IFilterRule, IViewField, IVisSpec, IVisualConfig, Specification } from "../interfaces";
5
4
  import { CHANNEL_LIMIT, GEMO_TYPES, MetaFieldKeys } from "../config";
6
5
  import { VisSpecWithHistory } from "../models/visSpecHistory";
7
6
  import { IStoInfo, dumpsGWPureSpec, parseGWContent, parseGWPureSpec, stringifyGWContent } from "../utils/save";
8
7
  import { CommonStore } from "./commonStore";
9
8
  import { createCountField } from "../utils";
9
+ import { nanoid } from "nanoid";
10
10
 
11
11
  function getChannelSizeLimit(channel: string): number {
12
12
  if (typeof CHANNEL_LIMIT[channel] === "undefined") return Infinity;
13
13
  return CHANNEL_LIMIT[channel];
14
14
  }
15
15
 
16
+ function uniqueId(): string {
17
+ return "gw_" + nanoid(4);
18
+ }
19
+
16
20
  function geomAdapter(geom: string) {
17
21
  switch (geom) {
18
22
  case "interval":
@@ -44,7 +48,6 @@ export function initEncoding(): DraggableFieldState {
44
48
  return {
45
49
  dimensions: [],
46
50
  measures: [],
47
- fields: [],
48
51
  rows: [],
49
52
  columns: [],
50
53
  color: [],
@@ -144,7 +147,7 @@ export class VizSpecStore {
144
147
  this.visList.push(
145
148
  new VisSpecWithHistory({
146
149
  name: 'Chart 1',
147
- visId: uuidv4(),
150
+ visId: uniqueId(),
148
151
  config: this.visualConfig,
149
152
  encodings: this.draggableFieldState,
150
153
  })
@@ -299,7 +302,7 @@ export class VizSpecStore {
299
302
  this.visList.push(
300
303
  new VisSpecWithHistory({
301
304
  name,
302
- visId: uuidv4(),
305
+ visId: uniqueId(),
303
306
  config: initVisualConfig(),
304
307
  encodings: initEncoding(),
305
308
  })
@@ -324,19 +327,10 @@ export class VizSpecStore {
324
327
  public initMetaState(dataset: DataSet) {
325
328
  const countField = createCountField();
326
329
  this.useMutable(({ encodings }) => {
327
- encodings.fields = dataset.rawFields.map((f) => ({
328
- dragId: uuidv4(),
329
- fid: f.fid,
330
- name: f.name || f.fid,
331
- aggName: f.analyticType === "measure" ? "sum" : undefined,
332
- analyticType: f.analyticType,
333
- semanticType: f.semanticType,
334
- }))//.concat(countField);
335
- encodings.fields.push(countField);
336
330
  encodings.dimensions = dataset.rawFields
337
331
  .filter((f) => f.analyticType === "dimension")
338
332
  .map((f) => ({
339
- dragId: uuidv4(),
333
+ dragId: uniqueId(),
340
334
  fid: f.fid,
341
335
  name: f.name || f.fid,
342
336
  semanticType: f.semanticType,
@@ -345,7 +339,7 @@ export class VizSpecStore {
345
339
  encodings.measures = dataset.rawFields
346
340
  .filter((f) => f.analyticType === "measure")
347
341
  .map((f) => ({
348
- dragId: uuidv4(),
342
+ dragId: uniqueId(),
349
343
  fid: f.fid,
350
344
  name: f.name || f.fid,
351
345
  analyticType: f.analyticType,
@@ -436,7 +430,7 @@ export class VizSpecStore {
436
430
  // use a different dragId
437
431
  movingField = {
438
432
  ...toJS(encodings[sourceKey][sourceIndex]), // toJS will NOT shallow copy a object here
439
- dragId: uuidv4(),
433
+ dragId: uniqueId(),
440
434
  };
441
435
  } else {
442
436
  [movingField] = encodings[sourceKey].splice(sourceIndex, 1);
@@ -480,7 +474,7 @@ export class VizSpecStore {
480
474
  this.useMutable(({ encodings }) => {
481
475
  encodings.filters.splice(index, 0, {
482
476
  ...toJS(data),
483
- dragId: uuidv4(),
477
+ dragId: uniqueId(),
484
478
  rule: null,
485
479
  });
486
480
  this.editingFilterIdx = index;
@@ -508,7 +502,7 @@ export class VizSpecStore {
508
502
  public createBinField(stateKey: keyof DraggableFieldState, index: number, binType: 'bin' | 'binCount') {
509
503
  this.useMutable(({ encodings }) => {
510
504
  const originField = encodings[stateKey][index];
511
- const newVarKey = uuidv4();
505
+ const newVarKey = uniqueId();
512
506
  const binField: IViewField = {
513
507
  fid: newVarKey,
514
508
  dragId: newVarKey,
@@ -537,7 +531,7 @@ export class VizSpecStore {
537
531
 
538
532
  this.useMutable(({ encodings }) => {
539
533
  const originField = encodings[stateKey][index];
540
- const newVarKey = uuidv4();
534
+ const newVarKey = uniqueId();
541
535
  const logField: IViewField = {
542
536
  fid: newVarKey,
543
537
  dragId: newVarKey,
@@ -635,7 +629,7 @@ export class VizSpecStore {
635
629
 
636
630
  this.useMutable(({ encodings }) => {
637
631
  const cloneField = { ...toJS(field) };
638
- cloneField.dragId = uuidv4();
632
+ cloneField.dragId = uniqueId();
639
633
  encodings[destinationKey].push(cloneField);
640
634
  });
641
635
  }
@@ -643,7 +637,7 @@ export class VizSpecStore {
643
637
  const tab = this.visList[this.visIndex];
644
638
 
645
639
  if (tab) {
646
- const fields = tab.encodings.fields;
640
+ const fields = tab.encodings.dimensions.concat(tab.encodings.measures);
647
641
  // thi
648
642
  // const [xField, yField, ] = spec.position;
649
643
  this.clearState();