mind-elixir 4.5.2 → 5.0.0-beta.10

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.
Files changed (33) hide show
  1. package/LICENSE +21 -21
  2. package/dist/MindElixir.iife.js +9 -14
  3. package/dist/MindElixir.js +1253 -1177
  4. package/dist/MindElixirLite.iife.js +7 -12
  5. package/dist/MindElixirLite.js +778 -1208
  6. package/dist/example.iife.js +1 -1
  7. package/dist/example.js +14 -13
  8. package/dist/types/arrow.d.ts +1 -0
  9. package/dist/types/index.d.ts +17 -24
  10. package/dist/types/interact.d.ts +10 -13
  11. package/dist/types/methods.d.ts +16 -14
  12. package/dist/types/nodeOperation.d.ts +1 -2
  13. package/dist/types/summary.d.ts +2 -2
  14. package/dist/types/types/dom.d.ts +4 -1
  15. package/dist/types/types/index.d.ts +8 -6
  16. package/dist/types/utils/dragMoveHelper.d.ts +4 -3
  17. package/dist/types/utils/index.d.ts +5 -1
  18. package/dist/types/utils/pubsub.d.ts +12 -16
  19. package/dist/types/utils/svg.d.ts +3 -1
  20. package/dist/types/vanilla/src/EventEmitter.d.ts +13 -0
  21. package/dist/types/vanilla/src/index.d.ts +112 -0
  22. package/dist/types/vanilla/src/types.d.ts +84 -0
  23. package/dist/types/vanilla/src/utils/arrayify.d.ts +1 -0
  24. package/dist/types/vanilla/src/utils/browser.d.ts +2 -0
  25. package/dist/types/vanilla/src/utils/css.d.ts +10 -0
  26. package/dist/types/vanilla/src/utils/domRect.d.ts +1 -0
  27. package/dist/types/vanilla/src/utils/events.d.ts +29 -0
  28. package/dist/types/vanilla/src/utils/frames.d.ts +7 -0
  29. package/dist/types/vanilla/src/utils/intersects.d.ts +9 -0
  30. package/dist/types/vanilla/src/utils/matchesTrigger.d.ts +16 -0
  31. package/dist/types/vanilla/src/utils/selectAll.d.ts +8 -0
  32. package/package.json +3 -3
  33. package/readme.md +12 -1
@@ -0,0 +1,112 @@
1
+ import { EventTarget } from './EventEmitter';
2
+ import type { AreaLocation, ScrollEvent, SelectionEvents } from './types';
3
+ import type { PartialSelectionOptions } from './types';
4
+ import type { SelectAllSelectors } from './utils/selectAll';
5
+ export * from './types';
6
+ export default class SelectionArea extends EventTarget<SelectionEvents> {
7
+ static version: string;
8
+ private readonly _options;
9
+ private _selection;
10
+ private readonly _area;
11
+ private readonly _clippingElement;
12
+ private _targetElement?;
13
+ private _targetBoundary?;
14
+ private _targetBoundaryScrolled;
15
+ private _targetRect?;
16
+ private _selectables;
17
+ private _latestElement?;
18
+ private _areaLocation;
19
+ private _areaRect;
20
+ private _singleClick;
21
+ private _frame;
22
+ private _scrollAvailable;
23
+ private _scrollingActive;
24
+ private _scrollSpeed;
25
+ private _scrollDelta;
26
+ private _lastMousePosition;
27
+ constructor(opt: PartialSelectionOptions);
28
+ _toggleStartEvents(activate?: boolean): void;
29
+ _onTapStart(evt: MouseEvent | TouchEvent, silent?: boolean): void;
30
+ _onSingleTap(evt: MouseEvent | TouchEvent): void;
31
+ _delayedTapMove(evt: MouseEvent | TouchEvent): void;
32
+ _setupSelectionArea(): void;
33
+ _onTapMove(evt: MouseEvent | TouchEvent): void;
34
+ _handleMoveEvent(evt: MouseEvent | TouchEvent): void;
35
+ _onScroll(): void;
36
+ _onStartAreaScroll(): void;
37
+ _wheelScroll(evt: ScrollEvent): void;
38
+ _keyboardScroll(evt: KeyboardEvent): void;
39
+ _recalculateSelectionAreaRect(): void;
40
+ _redrawSelectionArea(): void;
41
+ _onTapStop(evt: MouseEvent | TouchEvent | null, silent: boolean): void;
42
+ _updateElementSelection(): void;
43
+ _emitEvent(name: keyof SelectionEvents, evt: MouseEvent | TouchEvent | null): unknown;
44
+ _keepSelection(): void;
45
+ /**
46
+ * Manually triggers the start of a selection
47
+ * @param evt A MouseEvent / TouchEvent-like object
48
+ * @param silent If beforestart should be fired
49
+ */
50
+ trigger(evt: MouseEvent | TouchEvent, silent?: boolean): void;
51
+ /**
52
+ * Can be used if during a selection elements have been added
53
+ * Will update everything that can be selected
54
+ */
55
+ resolveSelectables(): void;
56
+ /**
57
+ * Same as deselecting, but for all elements currently selected
58
+ * @param includeStored If the store should also get cleared
59
+ * @param quiet If move / stop events should be fired
60
+ */
61
+ clearSelection(includeStored?: boolean, quiet?: boolean): void;
62
+ /**
63
+ * @returns {Array} Selected elements
64
+ */
65
+ getSelection(): Element[];
66
+ /**
67
+ * @returns {HTMLElement} The selection area element
68
+ */
69
+ getSelectionArea(): HTMLElement;
70
+ /**
71
+ * @returns {Element[]} Available selectable elements for current selection
72
+ */
73
+ getSelectables(): Element[];
74
+ /**
75
+ * Set the location of the selection area
76
+ * @param location A partial AreaLocation object
77
+ */
78
+ setAreaLocation(location: Partial<AreaLocation>): void;
79
+ /**
80
+ * @returns {AreaLocation} The current location of the selection area
81
+ */
82
+ getAreaLocation(): AreaLocation;
83
+ /**
84
+ * Cancel the current selection process, pass true to fire a stop event after cancel
85
+ * @param keepEvent If a stop event should be fired
86
+ */
87
+ cancel(keepEvent?: boolean): void;
88
+ /**
89
+ * Unbinds all events and removes the area-element.
90
+ */
91
+ destroy(): void;
92
+ /**
93
+ * Enable selecting elements
94
+ */
95
+ enable: (activate?: boolean) => void;
96
+ /**
97
+ * Disable selecting elements
98
+ */
99
+ disable: () => void;
100
+ /**
101
+ * Adds elements to the selection
102
+ * @param query CSS Query, can be an array of queries
103
+ * @param quiet If this should not trigger the move event
104
+ */
105
+ select(query: SelectAllSelectors, quiet?: boolean): Element[];
106
+ /**
107
+ * Removes a particular element from the selection
108
+ * @param query CSS Query, can be an array of queries
109
+ * @param quiet If this should not trigger the move event
110
+ */
111
+ deselect(query: SelectAllSelectors, quiet?: boolean): void;
112
+ }
@@ -0,0 +1,84 @@
1
+ import type SelectionArea from './index';
2
+ import type { Intersection } from './utils/intersects';
3
+ import type { Trigger } from './utils/matchesTrigger';
4
+ export type DeepPartial<T> = T extends unknown[] ? T : T extends HTMLElement ? T : {
5
+ [P in keyof T]?: DeepPartial<T[P]>;
6
+ };
7
+ export type Quantify<T> = T[] | T;
8
+ export interface ScrollEvent extends MouseEvent {
9
+ deltaY: number;
10
+ deltaX: number;
11
+ }
12
+ export interface ChangedElements {
13
+ added: Element[];
14
+ removed: Element[];
15
+ }
16
+ export interface SelectionStore {
17
+ touched: Element[];
18
+ stored: Element[];
19
+ selected: Element[];
20
+ changed: ChangedElements;
21
+ }
22
+ export interface SelectionEvent {
23
+ event: MouseEvent | TouchEvent | null;
24
+ store: SelectionStore;
25
+ selection: SelectionArea;
26
+ }
27
+ export type SelectionEvents = {
28
+ beforestart: (e: SelectionEvent) => boolean | void;
29
+ beforedrag: (e: SelectionEvent) => boolean | void;
30
+ start: (e: SelectionEvent) => void;
31
+ move: (e: SelectionEvent) => void;
32
+ stop: (e: SelectionEvent) => void;
33
+ };
34
+ export type AreaLocation = {
35
+ x1: number;
36
+ y1: number;
37
+ x2: number;
38
+ y2: number;
39
+ };
40
+ export interface Coordinates {
41
+ x: number;
42
+ y: number;
43
+ }
44
+ export type TapMode = 'touch' | 'native';
45
+ export type OverlapMode = 'keep' | 'drop' | 'invert';
46
+ export interface Scrolling {
47
+ speedDivider: number;
48
+ manualSpeed: number;
49
+ startScrollMargins: {
50
+ x: number;
51
+ y: number;
52
+ };
53
+ }
54
+ export interface SingleTap {
55
+ allow: boolean;
56
+ intersect: TapMode;
57
+ }
58
+ export interface Features {
59
+ deselectOnBlur: boolean;
60
+ singleTap: SingleTap;
61
+ range: boolean;
62
+ touch: boolean;
63
+ }
64
+ export interface Behaviour {
65
+ intersect: Intersection;
66
+ startThreshold: number | Coordinates;
67
+ overlap: OverlapMode;
68
+ scrolling: Scrolling;
69
+ triggers: Trigger[];
70
+ }
71
+ export interface SelectionOptions {
72
+ selectionAreaClass: string;
73
+ selectionContainerClass: string | undefined;
74
+ container: Quantify<string | HTMLElement>;
75
+ document: Document;
76
+ selectables: Quantify<string>;
77
+ startAreas: Quantify<string | HTMLElement>;
78
+ boundaries: Quantify<string | HTMLElement>;
79
+ behaviour: Behaviour;
80
+ features: Features;
81
+ }
82
+ export type PartialSelectionOptions = DeepPartial<Omit<SelectionOptions, 'document'>> & {
83
+ document?: Document;
84
+ };
@@ -0,0 +1 @@
1
+ export declare const arrayify: <T>(value: T | T[]) => T[];
@@ -0,0 +1,2 @@
1
+ export declare const isTouchDevice: () => boolean;
2
+ export declare const isSafariBrowser: () => boolean;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Add css to a DOM-Element or returns the current
3
+ * value of a property.
4
+ *
5
+ * @param el The Element.
6
+ * @param attr The attribute or an object which holds css key-properties.
7
+ * @param val The value for a single attribute.
8
+ * @returns {*}
9
+ */
10
+ export declare const css: ({ style }: HTMLElement, attr: Partial<Record<keyof CSSStyleDeclaration, string | number>> | string, val?: string | number) => void;
@@ -0,0 +1 @@
1
+ export declare const domRect: (x?: number, y?: number, width?: number, height?: number) => DOMRect;
@@ -0,0 +1,29 @@
1
+ type AnyFunction = (...arg: any) => any;
2
+ /**
3
+ * Add event(s) to element(s).
4
+ * @param elements DOM-Elements
5
+ * @param events Event names
6
+ * @param fn Callback
7
+ * @param options Optional options
8
+ * @return Array passed arguments
9
+ */
10
+ export declare const on: (items: (EventTarget | undefined) | (EventTarget | undefined)[], events: string | string[], fn: AnyFunction, options?: {}) => void;
11
+ /**
12
+ * Remove event(s) from element(s).
13
+ * @param elements DOM-Elements
14
+ * @param events Event names
15
+ * @param fn Callback
16
+ * @param options Optional options
17
+ * @return Array passed arguments
18
+ */
19
+ export declare const off: (items: (EventTarget | undefined) | (EventTarget | undefined)[], events: string | string[], fn: AnyFunction, options?: {}) => void;
20
+ /**
21
+ * Simplifies a touch / mouse-event
22
+ * @param evt
23
+ */
24
+ export declare const simplifyEvent: (evt: any) => {
25
+ target: HTMLElement;
26
+ x: number;
27
+ y: number;
28
+ };
29
+ export {};
@@ -0,0 +1,7 @@
1
+ type AnyFunction = (...args: any[]) => void;
2
+ export interface Frames<F extends AnyFunction = AnyFunction> {
3
+ next(...args: Parameters<F>): void;
4
+ cancel(): void;
5
+ }
6
+ export declare const frames: <F extends AnyFunction>(fn: F) => Frames<F>;
7
+ export {};
@@ -0,0 +1,9 @@
1
+ export type Intersection = 'center' | 'cover' | 'touch';
2
+ /**
3
+ * Check if two DOM-Elements intersects each other.
4
+ * @param a BoundingClientRect of the first element.
5
+ * @param b BoundingClientRect of the second element.
6
+ * @param mode Options are center, cover or touch.
7
+ * @returns {boolean} If both elements intersects each other.
8
+ */
9
+ export declare const intersects: (a: DOMRect, b: DOMRect, mode?: Intersection) => boolean;
@@ -0,0 +1,16 @@
1
+ export type MouseButton = 0 | 1 | 2 | 3 | 4;
2
+ export type Modifier = 'ctrl' | 'alt' | 'shift';
3
+ export type MouseButtonWithModifiers = {
4
+ button: MouseButton;
5
+ modifiers: Modifier[];
6
+ };
7
+ export type Trigger = MouseButton | MouseButtonWithModifiers;
8
+ /**
9
+ * Determines whether a MouseEvent should execute until completion depending on
10
+ * which button and modifier(s) are active for the MouseEvent.
11
+ * The Event will execute to completion if ANY of the triggers "matches"
12
+ * @param event MouseEvent that should be checked
13
+ * @param triggers A list of Triggers that signify that the event should execute until completion
14
+ * @returns Whether the MouseEvent should execute until completion
15
+ */
16
+ export declare const matchesTrigger: (event: MouseEvent, triggers: Trigger[]) => boolean;
@@ -0,0 +1,8 @@
1
+ export type SelectAllSelectors = (string | Element)[] | string | Element;
2
+ /**
3
+ * Takes a selector (or array of selectors) and returns the matched nodes.
4
+ * @param selector The selector or an Array of selectors.
5
+ * @param doc
6
+ * @returns {Array} Array of DOM-Nodes.
7
+ */
8
+ export declare const selectAll: (selector: SelectAllSelectors, doc?: Document) => Element[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mind-elixir",
3
- "version": "4.5.2",
3
+ "version": "5.0.0-beta.10",
4
4
  "type": "module",
5
5
  "description": "Mind elixir is a free open source mind map core.",
6
6
  "keywords": [
@@ -77,7 +77,7 @@
77
77
  "@types/node": "^20.14.2",
78
78
  "@typescript-eslint/eslint-plugin": "^5.62.0",
79
79
  "@typescript-eslint/parser": "^5.62.0",
80
- "@viselect/vanilla": "3.5.1",
80
+ "@viselect/vanilla": "3.9.0",
81
81
  "eslint": "^8.57.0",
82
82
  "eslint-config-prettier": "^8.10.0",
83
83
  "eslint-plugin-prettier": "^4.2.1",
@@ -89,4 +89,4 @@
89
89
  "vite": "^4.5.3",
90
90
  "vite-plugin-css-injected-by-js": "^3.5.1"
91
91
  }
92
- }
92
+ }
package/readme.md CHANGED
@@ -36,11 +36,13 @@ Mind elixir is a open source JavaScript mind map core. You can use it with any f
36
36
 
37
37
  Features:
38
38
 
39
+ - Fluent UX
40
+ - Well designed
39
41
  - Lightweight
40
42
  - High performance
41
43
  - Framework agnostic
42
44
  - Pluginable
43
- - Build-in drag and drop / node edit plugin
45
+ - Built-in drag and drop / node edit plugin
44
46
  - Export as SVG / PNG / Html
45
47
  - Summarize nodes
46
48
  - Bulk operations supported
@@ -428,3 +430,12 @@ Thanks for your contributions to Mind Elixir! Your support and dedication make t
428
430
  <a href="https://github.com/SSShooter/mind-elixir-core/graphs/contributors">
429
431
  <img src="https://contrib.rocks/image?repo=SSShooter/mind-elixir-core&columns=6" />
430
432
  </a>
433
+
434
+ ## v5 Breaking Changes
435
+
436
+ - Move scroll-based movement to transition-based movement
437
+ - `Summary.text` -> `Summary.label`
438
+ - Remove `getDataMd()`
439
+ - MindElixir.dragMoveHelper -> instance.dragMoveHelper
440
+ - Remove `unselectNode()`
441
+ - Remove `removeNode()`