@dineug/erd-editor 3.1.8 → 3.2.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.
package/README.md CHANGED
@@ -43,433 +43,6 @@ document.body.appendChild(editor);
43
43
  </script>
44
44
  ```
45
45
 
46
- # ErdEditorElement
47
-
48
- ```ts
49
- interface ErdEditorElement extends HTMLElement {
50
- readonly: boolean;
51
- systemDarkMode: boolean; // system dark/light auto
52
- enableThemeBuilder: boolean;
53
- value: string;
54
- focus: () => void;
55
- blur: () => void;
56
- clear: () => void;
57
- destroy: () => void;
58
- setInitialValue: (value: string) => void;
59
- setPresetTheme: (themeOptions: Partial<ThemeOptions>) => void;
60
- setTheme: (theme: Partial<Theme>) => void;
61
- setKeyBindingMap: (keyBindingMap: Partial<KeyBindingMap>) => void;
62
- setSchemaSQL: (value: string) => void;
63
- getSchemaSQL: (databaseVendor?: DatabaseVendor) => string;
64
- getSharedStore: (config?: SharedStoreConfig) => SharedStore;
65
- }
66
- ```
67
-
68
- ## readonly
69
-
70
- Sets the editing capability of the editor.
71
-
72
- ```js
73
- editor.readonly = true;
74
- // or
75
- editor.setAttribute('readonly', 'true');
76
- ```
77
-
78
- ```html
79
- <erd-editor readonly></erd-editor>
80
- ```
81
-
82
- ## systemDarkMode
83
-
84
- Determines whether to automatically synchronize with the system's dark/light mode.
85
-
86
- ```js
87
- editor.systemDarkMode = true;
88
- // or
89
- editor.setAttribute('systemDarkMode', 'true');
90
- ```
91
-
92
- ```html
93
- <erd-editor system-dark-mode></erd-editor>
94
- ```
95
-
96
- ## enableThemeBuilder
97
-
98
- Determines if a UI for easily setting preset themes is provided.
99
-
100
- <img src="https://github.com/dineug/erd-editor/blob/main/img/theme-builder.png?raw=true" width="400" />
101
-
102
- ```js
103
- editor.enableThemeBuilder = true;
104
- // or
105
- editor.setAttribute('enableThemeBuilder', 'true');
106
- ```
107
-
108
- ```html
109
- <erd-editor enable-theme-builder></erd-editor>
110
- ```
111
-
112
- Triggers the `changePresetTheme` event upon changing the preset theme.
113
-
114
- ```js
115
- editor.addEventListener('changePresetTheme', event => {
116
- const themeOptions = event.detail;
117
- });
118
- ```
119
-
120
- ## value
121
-
122
- ### getter
123
-
124
- Retrieves the current editor state as JSON data.
125
-
126
- ```js
127
- const data = editor.value;
128
- ```
129
-
130
- ### setter
131
-
132
- Loads a previously saved editor state. It is recorded in the history list, enabling `Undo, Redo`.
133
-
134
- ```js
135
- editor.value = 'json...';
136
- ```
137
-
138
- ## setInitialValue
139
-
140
- Loads a previously saved editor state. It is not recorded in the history list, so `Undo, Redo` is not possible.
141
-
142
- ```js
143
- editor.setInitialValue('json...');
144
- ```
145
-
146
- ## Event
147
-
148
- ### change
149
-
150
- When there are changes in the editor, it emits an event.
151
-
152
- ```js
153
- editor.addEventListener('change', event => {
154
- const data = event.target.value;
155
- });
156
- ```
157
-
158
- ## focus
159
-
160
- Focuses on the editor.
161
-
162
- ```js
163
- editor.focus();
164
- ```
165
-
166
- ## blur
167
-
168
- Removes focus from the editor.
169
-
170
- ```js
171
- editor.blur();
172
- ```
173
-
174
- ## clear
175
-
176
- Resets the editor state.
177
-
178
- ```js
179
- editor.clear();
180
- ```
181
-
182
- ## destroy
183
-
184
- Completely disables reusing the editor instance.
185
-
186
- ```js
187
- editor.destroy();
188
- ```
189
-
190
- ## setKeyBindingMap
191
-
192
- Redefines keyboard shortcuts.
193
-
194
- ```ts
195
- type ShortcutOption = {
196
- shortcut: string;
197
- preventDefault?: boolean;
198
- stopPropagation?: boolean;
199
- };
200
-
201
- const defaultKeyBindingMap: KeyBindingMap = {
202
- addTable: [{ shortcut: 'Alt+KeyN' }],
203
- addColumn: [{ shortcut: 'Alt+Enter' }],
204
- addMemo: [{ shortcut: 'Alt+KeyM' }],
205
- removeTable: [{ shortcut: '$mod+Backspace' }, { shortcut: '$mod+Delete' }],
206
- removeColumn: [{ shortcut: 'Alt+Backspace' }, { shortcut: 'Alt+Delete' }],
207
- primaryKey: [{ shortcut: 'Alt+KeyK' }],
208
- selectAllTable: [{ shortcut: '$mod+Alt+KeyA' }],
209
- selectAllColumn: [{ shortcut: 'Alt+KeyA' }],
210
- relationshipZeroOne: [{ shortcut: '$mod+Alt+Digit1' }],
211
- relationshipZeroN: [{ shortcut: '$mod+Alt+Digit2' }],
212
- relationshipOneOnly: [{ shortcut: '$mod+Alt+Digit3' }],
213
- relationshipOneN: [{ shortcut: '$mod+Alt+Digit4' }],
214
- tableProperties: [{ shortcut: 'Alt+Space' }],
215
- };
216
-
217
- // example
218
- editor.setKeyBindingMap({
219
- addTable: [{ shortcut: '$mod+KeyN', preventDefault: true }];
220
- });
221
- ```
222
-
223
- ### $mod
224
-
225
- Switches `Control` key depending on the environment.
226
-
227
- - Mac: $mod = Meta (⌘)
228
- - Windows/Linux: $mod = Control
229
-
230
- ### Shortcut Table
231
-
232
- Uses keyboard event `key, code` properties.
233
- Use `code` for absolute positions and `key` for input values.
234
-
235
- | Windows | macOS | `key` | `code` |
236
- | ------------- | --------------- | ------------- | ------------------------------ |
237
- | N/A | `Command` / `⌘` | `Meta` | `MetaLeft` / `MetaRight` |
238
- | `Alt` | `Option` / `⌥` | `Alt` | `AltLeft` / `AltRight` |
239
- | `Control` | `Control` / `^` | `Control` | `ControlLeft` / `ControlRight` |
240
- | `Shift` | `Shift` | `Shift` | `ShiftLeft` / `ShiftRight` |
241
- | `Space` | `Space` | N/A | `Space` |
242
- | `Enter` | `Return` | `Enter` | `Enter` |
243
- | `Esc` | `Esc` | `Escape` | `Escape` |
244
- | `1`, `2`, etc | `1`, `2`, etc | `1`, `2`, etc | `Digit1`, `Digit2`, etc |
245
- | `a`, `b`, etc | `a`, `b`, etc | `a`, `b`, etc | `KeyA`, `KeyB`, etc |
246
- | `-` | `-` | `-` | `Minus` |
247
- | `=` | `=` | `=` | `Equal` |
248
- | `+` | `+` | `+` | `Equal`\* |
249
-
250
- ## Theme
251
-
252
- ### setPresetTheme
253
-
254
- Sets a preset theme.
255
-
256
- ```ts
257
- type ThemeOptions = {
258
- appearance: 'dark' | 'light';
259
- grayColor: 'gray' | 'mauve' | 'slate' | 'sage' | 'olive' | 'sand';
260
- accentColor:
261
- | 'gray'
262
- | 'gold'
263
- | 'bronze'
264
- | 'brown'
265
- | 'yellow'
266
- | 'amber'
267
- | 'orange'
268
- | 'tomato'
269
- | 'red'
270
- | 'ruby'
271
- | 'crimson'
272
- | 'pink'
273
- | 'plum'
274
- | 'purple'
275
- | 'violet'
276
- | 'iris'
277
- | 'indigo'
278
- | 'blue'
279
- | 'cyan'
280
- | 'teal'
281
- | 'jade'
282
- | 'green'
283
- | 'grass'
284
- | 'lime'
285
- | 'mint'
286
- | 'sky';
287
- };
288
-
289
- // example
290
- editor.setPresetTheme({ appearance: 'light' });
291
- ```
292
-
293
- ### setTheme
294
-
295
- Allows customizing the theme.
296
-
297
- #### JavaScript
298
-
299
- ```ts
300
- type Theme = {
301
- grayColor1: string;
302
- grayColor2: string;
303
- grayColor3: string;
304
- grayColor4: string;
305
- grayColor5: string;
306
- grayColor6: string;
307
- grayColor7: string;
308
- grayColor8: string;
309
- grayColor9: string;
310
- grayColor10: string;
311
- grayColor11: string;
312
- grayColor12: string;
313
-
314
- accentColor1: string;
315
- accentColor2: string;
316
- accentColor3: string;
317
- accentColor4: string;
318
- accentColor5: string;
319
- accentColor6: string;
320
- accentColor7: string;
321
- accentColor8: string;
322
- accentColor9: string;
323
- accentColor10: string;
324
- accentColor11: string;
325
- accentColor12: string;
326
-
327
- canvasBackground: string;
328
- canvasBoundaryBackground: string;
329
-
330
- tableBackground: string;
331
- tableSelect: string;
332
- tableBorder: string;
333
-
334
- memoBackground: string;
335
- memoSelect: string;
336
- memoBorder: string;
337
-
338
- columnSelect: string;
339
- columnHover: string;
340
-
341
- relationshipHover: string;
342
-
343
- toolbarBackground: string;
344
-
345
- contextMenuBackground: string;
346
- contextMenuSelect: string;
347
- contextMenuHover: string;
348
- contextMenuBorder: string;
349
-
350
- minimapBorder: string;
351
- minimapShadow: string;
352
- minimapViewportBorder: string;
353
- minimapViewportBorderHover: string;
354
-
355
- toastBackground: string;
356
- toastBorder: string;
357
-
358
- dargSelectBackground: string;
359
- dargSelectBorder: string;
360
-
361
- scrollbarTrack: string;
362
- scrollbarThumb: string;
363
- scrollbarThumbHover: string;
364
-
365
- foreground: string;
366
- active: string;
367
- placeholder: string;
368
-
369
- focus: string;
370
- inputActive: string;
371
-
372
- keyPK: string;
373
- keyFK: string;
374
- keyPFK: string;
375
- };
376
-
377
-
378
- // example
379
- editor.setTheme({...});
380
- ```
381
-
382
- #### CSS Variables
383
-
384
- ```css
385
- :root {
386
- --erd-editor-gray-color-1: #111113;
387
- --erd-editor-gray-color-2: #18191b;
388
- --erd-editor-gray-color-3: #212225;
389
- --erd-editor-gray-color-4: #272a2d;
390
- --erd-editor-gray-color-5: #2e3135;
391
- --erd-editor-gray-color-6: #363a3f;
392
- --erd-editor-gray-color-7: #43484e;
393
- --erd-editor-gray-color-8: #5a6169;
394
- --erd-editor-gray-color-9: #696e77;
395
- --erd-editor-gray-color-10: #777b84;
396
- --erd-editor-gray-color-11: #b0b4ba;
397
- --erd-editor-gray-color-12: #edeef0;
398
- --erd-editor-accent-color-1: #11131f;
399
- --erd-editor-accent-color-2: #141726;
400
- --erd-editor-accent-color-3: #182449;
401
- --erd-editor-accent-color-4: #1d2e62;
402
- --erd-editor-accent-color-5: #253974;
403
- --erd-editor-accent-color-6: #304384;
404
- --erd-editor-accent-color-7: #3a4f97;
405
- --erd-editor-accent-color-8: #435db1;
406
- --erd-editor-accent-color-9: #3e63dd;
407
- --erd-editor-accent-color-10: #5472e4;
408
- --erd-editor-accent-color-11: #9eb1ff;
409
- --erd-editor-accent-color-12: #d6e1ff;
410
- --erd-editor-canvas-background: #212225;
411
- --erd-editor-canvas-boundary-background: #111113;
412
- --erd-editor-table-background: #18191b;
413
- --erd-editor-table-select: #435db1;
414
- --erd-editor-table-border: #363a3f;
415
- --erd-editor-memo-background: #18191b;
416
- --erd-editor-memo-select: #435db1;
417
- --erd-editor-memo-border: #363a3f;
418
- --erd-editor-column-select: #2e3135;
419
- --erd-editor-column-hover: #272a2d;
420
- --erd-editor-relationship-hover: #435db1;
421
- --erd-editor-toolbar-background: #111113;
422
- --erd-editor-context-menu-background: #18191b;
423
- --erd-editor-context-menu-select: #272a2d;
424
- --erd-editor-context-menu-hover: #3a4f97;
425
- --erd-editor-context-menu-border: #363a3f;
426
- --erd-editor-minimap-border: black;
427
- --erd-editor-minimap-shadow: black;
428
- --erd-editor-minimap-viewport-border: #3a4f97;
429
- --erd-editor-minimap-viewport-border-hover: #435db1;
430
- --erd-editor-toast-background: #18191b;
431
- --erd-editor-toast-border: #363a3f;
432
- --erd-editor-darg-select-background: #253974;
433
- --erd-editor-darg-select-border: #435db1;
434
- --erd-editor-scrollbar-track: #ddeaf814;
435
- --erd-editor-scrollbar-thumb: #696e77;
436
- --erd-editor-scrollbar-thumb-hover: #777b84;
437
- --erd-editor-foreground: #b0b4ba;
438
- --erd-editor-active: #edeef0;
439
- --erd-editor-placeholder: #e5edfd7b;
440
- --erd-editor-focus: #435db1;
441
- --erd-editor-input-active: #5472e4;
442
- --erd-editor-key-pk: #ffc53d;
443
- --erd-editor-key-fk: #e54666;
444
- --erd-editor-key-pfk: #00a2c7;
445
- }
446
- ```
447
-
448
- ## setSchemaSQL
449
-
450
- Loads a schema SQL file.
451
-
452
- ```js
453
- editor.setSchemaSQL('Schema SQL...');
454
- ```
455
-
456
- ## getSchemaSQL
457
-
458
- Extracts the current editor state into a schema SQL.
459
- If `databaseVendor` is not specified, it operates based on the currently set vendor.
460
-
461
- ```ts
462
- type DatabaseVendor =
463
- | 'MariaDB'
464
- | 'MSSQL'
465
- | 'MySQL'
466
- | 'Oracle'
467
- | 'PostgreSQL'
468
- | 'SQLite';
469
-
470
- const schemaSQL = editor.getSchemaSQL();
471
- ```
472
-
473
46
  # Document
474
47
 
475
48
  - [Web App](https://erd-editor.io)
@@ -20,3 +20,4 @@ export type InjectAppContext = InjectEngineContext;
20
20
  export declare function createAppContext(ctx: InjectAppContext, getReadonly?: () => boolean): AppContext;
21
21
  export declare const appContext: import("@dineug/r-html").Context<AppContext>;
22
22
  export declare const useAppContext: (ctx: Ctx, fallback?: AppContext) => import("@dineug/r-html").Ref<AppContext>;
23
+ export declare function appDestroy(app: AppContext): void;
@@ -2,7 +2,6 @@ import { FC, Ref } from '@dineug/r-html';
2
2
  import { AppContext } from "../../appContext";
3
3
  export type AutomaticTablePlacementProps = {
4
4
  app: Ref<AppContext>;
5
- root: Ref<HTMLDivElement>;
6
5
  onChange: (tables: TablePoint[]) => void;
7
6
  };
8
7
  export type TablePoint = {
@@ -0,0 +1,9 @@
1
+ import { FC, Ref } from '@dineug/r-html';
2
+ import { AppContext } from "../../appContext";
3
+ export type DiffViewerProps = {
4
+ app: Ref<AppContext>;
5
+ initialValue: string;
6
+ onClose: () => void;
7
+ };
8
+ declare const DiffViewer: FC<DiffViewerProps>;
9
+ export default DiffViewer;
@@ -0,0 +1,3 @@
1
+ export declare const root: import("@dineug/r-html").CSSTemplateLiterals;
2
+ export declare const container: import("@dineug/r-html").CSSTemplateLiterals;
3
+ export declare const viewport: import("@dineug/r-html").CSSTemplateLiterals;
@@ -0,0 +1,19 @@
1
+ import { RootState } from "../../../engine/state";
2
+ import { Column, Table } from "../../../internal-types";
3
+ /**
4
+ * Map<uuid, [tag, Map<path, diff>]>
5
+ */
6
+ export type DiffMap = Map<string, DiffTuple>;
7
+ type DiffTuple = [string, Map<string, number>];
8
+ type NameToTableMap = Map<string, {
9
+ table: Table;
10
+ nameToColumnMap: Map<string, Column>;
11
+ }>;
12
+ export declare const Diff: {
13
+ readonly insert: 1;
14
+ readonly delete: 2;
15
+ };
16
+ export declare function diffState(prevState: RootState, state: RootState): [DiffMap, DiffMap];
17
+ export declare function getNameToTableMap({ doc: { tableIds }, collections, }: RootState): NameToTableMap;
18
+ export declare function getDiffStyle(diff: number, diffMap: DiffMap): HTMLStyleElement;
19
+ export {};
@@ -0,0 +1,10 @@
1
+ import { FC } from '@dineug/r-html';
2
+ import { AppContext } from "../../../appContext";
3
+ import { DiffMap } from "../diff";
4
+ export type ErdViewerProps = {
5
+ app: AppContext;
6
+ diff: number;
7
+ diffMap: DiffMap;
8
+ };
9
+ declare const ErdViewer: FC<ErdViewerProps>;
10
+ export default ErdViewer;
@@ -0,0 +1 @@
1
+ export declare const root: import("@dineug/r-html").CSSTemplateLiterals;
@@ -0,0 +1,11 @@
1
+ import { FC } from '@dineug/r-html';
2
+ import { AppContext } from "../../../appContext";
3
+ import { DiffMap } from "../diff";
4
+ export type TreeViewerProps = {
5
+ prevApp: AppContext;
6
+ prevDiffMap: DiffMap;
7
+ app: AppContext;
8
+ diffMap: DiffMap;
9
+ };
10
+ declare const TreeViewer: FC<TreeViewerProps>;
11
+ export default TreeViewer;
@@ -0,0 +1,5 @@
1
+ export declare const root: import("@dineug/r-html").CSSTemplateLiterals;
2
+ export declare const icon: import("@dineug/r-html").CSSTemplateLiterals;
3
+ export declare const table: import("@dineug/r-html").CSSTemplateLiterals;
4
+ export declare const column: import("@dineug/r-html").CSSTemplateLiterals;
5
+ export declare const ellipsis: import("@dineug/r-html").CSSTemplateLiterals;
@@ -28,4 +28,5 @@ export interface ErdEditorElement extends ErdEditorProps, HTMLElement {
28
28
  getSharedStore: (config?: SharedStoreConfig & {
29
29
  mouseTracker?: boolean;
30
30
  }) => SharedStore;
31
+ setDiffValue: (value: string) => void;
31
32
  }
@@ -10,7 +10,7 @@ type Props = {
10
10
  app: AppContext;
11
11
  root: Ref<HTMLDivElement>;
12
12
  };
13
- export declare function useErdEditorAttachElement({ props, ctx, app: { store, keyBindingMap, emitter, shortcut$, keydown$ }, root, }: Props): {
13
+ export declare function useErdEditorAttachElement({ props, ctx, app, root }: Props): {
14
14
  theme: Theme;
15
15
  themeState: {
16
16
  options: ThemeOptions;
@@ -30,3 +30,4 @@ export declare const MEMO_MIN_HEIGHT = 100;
30
30
  export declare const MINIMAP_SIZE = 150;
31
31
  export declare const MINIMAP_MARGIN = 20;
32
32
  export declare const TOOLBAR_HEIGHT = 30;
33
+ export declare const DIFF_TREE_WIDTH = 200;
@@ -4,5 +4,6 @@ export declare const Open: {
4
4
  readonly tableProperties: "tableProperties";
5
5
  readonly search: "search";
6
6
  readonly themeBuilder: "themeBuilder";
7
+ readonly diffViewer: "diffViewer";
7
8
  };
8
9
  export type Open = ValuesType<typeof Open>;
package/dist/engine.js CHANGED
@@ -1,15 +1,15 @@
1
- import { D as A, E as w, u as x, O as E, F as l, J as I, p as G, bs as d, I as p, Y as O, c_ as T, br as $, aA as j, d4 as k, d5 as F, U as J, d6 as R, cS as V } from "./schemaGCService-Cyip5lJB.js";
1
+ import { D as A, E as w, u as x, O as E, F as d, J as I, p as G, bs as l, I as p, Y as O, d0 as T, br as $, aB as j, d5 as k, d6 as F, U as J, d7 as R, cU as U } from "./schemaGCService-8ppNbFYF.js";
2
2
  /*!
3
3
  * @dineug/erd-editor
4
- * @version 3.1.8 | Sun Jan 28 2024
4
+ * @version 3.2.0 | Fri Feb 09 2024
5
5
  * @author SeungHwan-Lee <dineug2@gmail.com>
6
6
  * @license MIT
7
7
  */
8
8
  const b = {
9
9
  change: "change"
10
10
  };
11
- function D(u) {
12
- const o = /* @__PURE__ */ new Set(), t = A(u, !1), S = w(t), c = new x(), m = new E((e) => t.subscribe((a) => e.next(a))).pipe(l(p), I(200)), n = /* @__PURE__ */ new Set(), f = new V(), g = (e) => (n.has(e) || n.add(e), () => {
11
+ function z(u) {
12
+ const o = /* @__PURE__ */ new Set(), t = A(u, !1), m = w(t), c = new x(), S = new E((e) => t.subscribe((a) => e.next(a))).pipe(d(p), I(200)), n = /* @__PURE__ */ new Set(), f = new U(), g = (e) => (n.has(e) || n.add(e), () => {
13
13
  n.delete(e);
14
14
  }), i = (e, a) => {
15
15
  n.forEach((s) => {
@@ -18,7 +18,7 @@ function D(u) {
18
18
  });
19
19
  }, y = (e) => {
20
20
  const a = T(e);
21
- t.dispatchSync($(j(a) ? "{}" : a)), f.run(d(t.state)).then((s) => {
21
+ t.dispatchSync($(j(a) ? "{}" : a)), f.run(l(t.state)).then((s) => {
22
22
  (s.tableIds.length || s.tableColumnIds.length || s.relationshipIds.length || s.indexIds.length || s.indexColumnIds.length || s.memoIds.length) && (k(t.state, s), t.dispatchSync(F()), i(b.change, void 0));
23
23
  });
24
24
  }, r = (e) => {
@@ -26,11 +26,11 @@ function D(u) {
26
26
  }, v = (e) => {
27
27
  J(() => r(e));
28
28
  }, C = () => {
29
- Array.from(o).forEach((e) => e.unsubscribe()), o.clear(), n.clear(), t.destroy(), S.destroy();
29
+ Array.from(o).forEach((e) => e.unsubscribe()), o.clear(), n.clear(), t.destroy(), m.destroy();
30
30
  };
31
- return o.add(m.subscribe(() => i(b.change, void 0))).add(c.pipe(l(p), G((e) => e.map((a) => R(a, "tags")))).subscribe(t.dispatchSync)), Object.freeze({
31
+ return o.add(S.subscribe(() => i(b.change, void 0))).add(c.pipe(d(p), G((e) => e.map((a) => R(a, "tags")))).subscribe(t.dispatchSync)), Object.freeze({
32
32
  get value() {
33
- return d(t.state);
33
+ return l(t.state);
34
34
  },
35
35
  on: g,
36
36
  setInitialValue: y,
@@ -40,5 +40,5 @@ function D(u) {
40
40
  });
41
41
  }
42
42
  export {
43
- D as createReplicationStore
43
+ z as createReplicationStore
44
44
  };