@knotx/plugins-selection 0.0.7 → 0.0.9

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/dist/index.cjs CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  const core = require('@knotx/core');
4
4
  const decorators = require('@knotx/decorators');
5
- const pluginsBaseRender = require('@knotx/plugins-base-render');
6
5
  const SelectionArea = require('@viselect/vanilla');
7
6
  const rxjs = require('rxjs');
8
7
 
@@ -79,14 +78,12 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
79
78
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
80
79
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
81
80
  var _destroy_dec, _init_dec, _canInteract_dec, _endInteraction_dec, _startInteraction_dec, _registerPluginData_dec, _a, _init;
82
- const _Selection = class _Selection extends (_a = core.BasePlugin, _registerPluginData_dec = [decorators.inject.registerPluginData()], _startInteraction_dec = [decorators.inject.startInteraction()], _endInteraction_dec = [decorators.inject.endInteraction()], _canInteract_dec = [decorators.inject.canInteract()], _init_dec = [decorators.OnInit], _destroy_dec = [decorators.OnDestroy], _a) {
83
- constructor(options = {
84
- boundaries: [`.${core.bem("canvas", "wrapper")}`]
85
- }) {
86
- super();
87
- this.options = options;
81
+ class Selection extends (_a = core.BasePlugin, _registerPluginData_dec = [decorators.inject.registerPluginData()], _startInteraction_dec = [decorators.inject.startInteraction()], _endInteraction_dec = [decorators.inject.endInteraction()], _canInteract_dec = [decorators.inject.canInteract()], _init_dec = [decorators.OnInit], _destroy_dec = [decorators.OnDestroy], _a) {
82
+ constructor() {
83
+ super(...arguments);
88
84
  __runInitializers(_init, 5, this);
89
85
  __publicField(this, "name", "selection");
86
+ __publicField(this, "config");
90
87
  __publicField(this, "selection");
91
88
  __publicField(this, "selectedNodeIds$", new rxjs.BehaviorSubject([]));
92
89
  __publicField(this, "registerPluginData", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
@@ -94,23 +91,25 @@ const _Selection = class _Selection extends (_a = core.BasePlugin, _registerPlug
94
91
  __publicField(this, "endInteraction", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
95
92
  __publicField(this, "canInteract", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
96
93
  }
97
- init() {
94
+ init(config) {
95
+ this.config = __spreadValues({
96
+ boundaries: [`.${core.bem("canvas", "wrapper")}`]
97
+ }, config);
98
98
  this.registerPluginData("selection", "selectedNodeIds", this.selectedNodeIds$);
99
99
  this.createSelection();
100
100
  }
101
101
  createSelection() {
102
- const nodeClassName = core.addBemModifier(pluginsBaseRender.BaseRender.NODE_WRAPPER_CLASSNAME, "selected");
103
- const selectionAreaClass = _Selection.SELECTION_AREA_CLASSNAME;
104
- const selectables = [
105
- `.${pluginsBaseRender.BaseRender.NODE_WRAPPER_CLASSNAME}`
106
- ];
102
+ const nodeWrapperClassName = core.bem("node", "wrapper");
103
+ const nodeClassName = core.addBemModifier(nodeWrapperClassName, "selected");
104
+ const selectionAreaClass = core.bem("selection-area");
105
+ const selectables = [`.${nodeWrapperClassName}`];
107
106
  const endSelect = () => {
108
107
  this.endInteraction(this.pluginId, "select");
109
108
  };
110
- this.selection = new SelectionArea__default(__spreadProps(__spreadValues({}, this.options), { selectionAreaClass, selectables })).on("start", ({ store, event, selection }) => {
109
+ this.selection = new SelectionArea__default(__spreadProps(__spreadValues({}, this.config), { selectionAreaClass, selectables })).on("start", ({ store, event, selection }) => {
111
110
  if (!(event == null ? void 0 : event.ctrlKey) && !(event == null ? void 0 : event.metaKey)) {
112
111
  store.stored.forEach((el) => {
113
- if (el.className.includes(pluginsBaseRender.BaseRender.NODE_WRAPPER_CLASSNAME)) {
112
+ if (el.className.includes(nodeWrapperClassName)) {
114
113
  el.classList.remove(nodeClassName);
115
114
  }
116
115
  });
@@ -126,7 +125,7 @@ const _Selection = class _Selection extends (_a = core.BasePlugin, _registerPlug
126
125
  }
127
126
  const addedNodeIds = [];
128
127
  added.forEach((el) => {
129
- if (el.className.includes(pluginsBaseRender.BaseRender.NODE_WRAPPER_CLASSNAME)) {
128
+ if (el.className.includes(nodeWrapperClassName)) {
130
129
  el.classList.add(nodeClassName);
131
130
  const nodeId = el.getAttribute("data-node-id");
132
131
  if (nodeId)
@@ -135,7 +134,7 @@ const _Selection = class _Selection extends (_a = core.BasePlugin, _registerPlug
135
134
  });
136
135
  const removedNodeIds = [];
137
136
  removed.forEach((el) => {
138
- if (el.className.includes(pluginsBaseRender.BaseRender.NODE_WRAPPER_CLASSNAME)) {
137
+ if (el.className.includes(nodeWrapperClassName)) {
139
138
  el.classList.remove(nodeClassName);
140
139
  const nodeId = el.getAttribute("data-node-id");
141
140
  if (nodeId)
@@ -178,16 +177,14 @@ const _Selection = class _Selection extends (_a = core.BasePlugin, _registerPlug
178
177
  var _a2;
179
178
  (_a2 = this.selection) == null ? void 0 : _a2.destroy();
180
179
  }
181
- };
180
+ }
182
181
  _init = __decoratorStart(_a);
183
- __decorateElement(_init, 1, "init", _init_dec, _Selection);
184
- __decorateElement(_init, 1, "destroy", _destroy_dec, _Selection);
185
- __decorateElement(_init, 5, "registerPluginData", _registerPluginData_dec, _Selection);
186
- __decorateElement(_init, 5, "startInteraction", _startInteraction_dec, _Selection);
187
- __decorateElement(_init, 5, "endInteraction", _endInteraction_dec, _Selection);
188
- __decorateElement(_init, 5, "canInteract", _canInteract_dec, _Selection);
189
- __decoratorMetadata(_init, _Selection);
190
- __publicField(_Selection, "SELECTION_AREA_CLASSNAME", core.bem("selection-area"));
191
- let Selection = _Selection;
182
+ __decorateElement(_init, 1, "init", _init_dec, Selection);
183
+ __decorateElement(_init, 1, "destroy", _destroy_dec, Selection);
184
+ __decorateElement(_init, 5, "registerPluginData", _registerPluginData_dec, Selection);
185
+ __decorateElement(_init, 5, "startInteraction", _startInteraction_dec, Selection);
186
+ __decorateElement(_init, 5, "endInteraction", _endInteraction_dec, Selection);
187
+ __decorateElement(_init, 5, "canInteract", _canInteract_dec, Selection);
188
+ __decoratorMetadata(_init, Selection);
192
189
 
193
190
  exports.Selection = Selection;
package/dist/index.d.cts CHANGED
@@ -8,24 +8,24 @@ declare module '@knotx/core' {
8
8
  };
9
9
  }
10
10
  }
11
- declare class Selection extends BasePlugin<'selection'> {
12
- private options;
11
+ interface SelectionConfig extends PartialSelectionOptions {
12
+ }
13
+ declare class Selection extends BasePlugin<'selection', SelectionConfig> {
13
14
  name: "selection";
15
+ private config;
14
16
  private selection;
15
17
  private selectedNodeIds$;
16
18
  private registerPluginData;
17
19
  private startInteraction;
18
20
  private endInteraction;
19
21
  private canInteract;
20
- constructor(options?: PartialSelectionOptions);
21
- protected init(): void;
22
+ protected init(config: SelectionConfig): void;
22
23
  private createSelection;
23
24
  private updateSelection;
24
25
  getSelectedNodeIds(): string[];
25
26
  selectNodes(nodeIds: string[], clearPrevious?: boolean): void;
26
27
  clearSelection(): void;
27
28
  destroy(): void;
28
- static SELECTION_AREA_CLASSNAME: string;
29
29
  }
30
30
 
31
- export { Selection };
31
+ export { Selection, type SelectionConfig };
package/dist/index.d.mts CHANGED
@@ -8,24 +8,24 @@ declare module '@knotx/core' {
8
8
  };
9
9
  }
10
10
  }
11
- declare class Selection extends BasePlugin<'selection'> {
12
- private options;
11
+ interface SelectionConfig extends PartialSelectionOptions {
12
+ }
13
+ declare class Selection extends BasePlugin<'selection', SelectionConfig> {
13
14
  name: "selection";
15
+ private config;
14
16
  private selection;
15
17
  private selectedNodeIds$;
16
18
  private registerPluginData;
17
19
  private startInteraction;
18
20
  private endInteraction;
19
21
  private canInteract;
20
- constructor(options?: PartialSelectionOptions);
21
- protected init(): void;
22
+ protected init(config: SelectionConfig): void;
22
23
  private createSelection;
23
24
  private updateSelection;
24
25
  getSelectedNodeIds(): string[];
25
26
  selectNodes(nodeIds: string[], clearPrevious?: boolean): void;
26
27
  clearSelection(): void;
27
28
  destroy(): void;
28
- static SELECTION_AREA_CLASSNAME: string;
29
29
  }
30
30
 
31
- export { Selection };
31
+ export { Selection, type SelectionConfig };
package/dist/index.d.ts CHANGED
@@ -8,24 +8,24 @@ declare module '@knotx/core' {
8
8
  };
9
9
  }
10
10
  }
11
- declare class Selection extends BasePlugin<'selection'> {
12
- private options;
11
+ interface SelectionConfig extends PartialSelectionOptions {
12
+ }
13
+ declare class Selection extends BasePlugin<'selection', SelectionConfig> {
13
14
  name: "selection";
15
+ private config;
14
16
  private selection;
15
17
  private selectedNodeIds$;
16
18
  private registerPluginData;
17
19
  private startInteraction;
18
20
  private endInteraction;
19
21
  private canInteract;
20
- constructor(options?: PartialSelectionOptions);
21
- protected init(): void;
22
+ protected init(config: SelectionConfig): void;
22
23
  private createSelection;
23
24
  private updateSelection;
24
25
  getSelectedNodeIds(): string[];
25
26
  selectNodes(nodeIds: string[], clearPrevious?: boolean): void;
26
27
  clearSelection(): void;
27
28
  destroy(): void;
28
- static SELECTION_AREA_CLASSNAME: string;
29
29
  }
30
30
 
31
- export { Selection };
31
+ export { Selection, type SelectionConfig };
package/dist/index.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  import { bem, addBemModifier, InteractionPriority, BasePlugin } from '@knotx/core';
2
2
  import { inject, OnInit, OnDestroy } from '@knotx/decorators';
3
- import { BaseRender } from '@knotx/plugins-base-render';
4
3
  import SelectionArea from '@viselect/vanilla';
5
4
  import { BehaviorSubject } from 'rxjs';
6
5
 
@@ -73,14 +72,12 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
73
72
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
74
73
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
75
74
  var _destroy_dec, _init_dec, _canInteract_dec, _endInteraction_dec, _startInteraction_dec, _registerPluginData_dec, _a, _init;
76
- const _Selection = class _Selection extends (_a = BasePlugin, _registerPluginData_dec = [inject.registerPluginData()], _startInteraction_dec = [inject.startInteraction()], _endInteraction_dec = [inject.endInteraction()], _canInteract_dec = [inject.canInteract()], _init_dec = [OnInit], _destroy_dec = [OnDestroy], _a) {
77
- constructor(options = {
78
- boundaries: [`.${bem("canvas", "wrapper")}`]
79
- }) {
80
- super();
81
- this.options = options;
75
+ class Selection extends (_a = BasePlugin, _registerPluginData_dec = [inject.registerPluginData()], _startInteraction_dec = [inject.startInteraction()], _endInteraction_dec = [inject.endInteraction()], _canInteract_dec = [inject.canInteract()], _init_dec = [OnInit], _destroy_dec = [OnDestroy], _a) {
76
+ constructor() {
77
+ super(...arguments);
82
78
  __runInitializers(_init, 5, this);
83
79
  __publicField(this, "name", "selection");
80
+ __publicField(this, "config");
84
81
  __publicField(this, "selection");
85
82
  __publicField(this, "selectedNodeIds$", new BehaviorSubject([]));
86
83
  __publicField(this, "registerPluginData", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
@@ -88,23 +85,25 @@ const _Selection = class _Selection extends (_a = BasePlugin, _registerPluginDat
88
85
  __publicField(this, "endInteraction", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
89
86
  __publicField(this, "canInteract", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
90
87
  }
91
- init() {
88
+ init(config) {
89
+ this.config = __spreadValues({
90
+ boundaries: [`.${bem("canvas", "wrapper")}`]
91
+ }, config);
92
92
  this.registerPluginData("selection", "selectedNodeIds", this.selectedNodeIds$);
93
93
  this.createSelection();
94
94
  }
95
95
  createSelection() {
96
- const nodeClassName = addBemModifier(BaseRender.NODE_WRAPPER_CLASSNAME, "selected");
97
- const selectionAreaClass = _Selection.SELECTION_AREA_CLASSNAME;
98
- const selectables = [
99
- `.${BaseRender.NODE_WRAPPER_CLASSNAME}`
100
- ];
96
+ const nodeWrapperClassName = bem("node", "wrapper");
97
+ const nodeClassName = addBemModifier(nodeWrapperClassName, "selected");
98
+ const selectionAreaClass = bem("selection-area");
99
+ const selectables = [`.${nodeWrapperClassName}`];
101
100
  const endSelect = () => {
102
101
  this.endInteraction(this.pluginId, "select");
103
102
  };
104
- this.selection = new SelectionArea(__spreadProps(__spreadValues({}, this.options), { selectionAreaClass, selectables })).on("start", ({ store, event, selection }) => {
103
+ this.selection = new SelectionArea(__spreadProps(__spreadValues({}, this.config), { selectionAreaClass, selectables })).on("start", ({ store, event, selection }) => {
105
104
  if (!(event == null ? void 0 : event.ctrlKey) && !(event == null ? void 0 : event.metaKey)) {
106
105
  store.stored.forEach((el) => {
107
- if (el.className.includes(BaseRender.NODE_WRAPPER_CLASSNAME)) {
106
+ if (el.className.includes(nodeWrapperClassName)) {
108
107
  el.classList.remove(nodeClassName);
109
108
  }
110
109
  });
@@ -120,7 +119,7 @@ const _Selection = class _Selection extends (_a = BasePlugin, _registerPluginDat
120
119
  }
121
120
  const addedNodeIds = [];
122
121
  added.forEach((el) => {
123
- if (el.className.includes(BaseRender.NODE_WRAPPER_CLASSNAME)) {
122
+ if (el.className.includes(nodeWrapperClassName)) {
124
123
  el.classList.add(nodeClassName);
125
124
  const nodeId = el.getAttribute("data-node-id");
126
125
  if (nodeId)
@@ -129,7 +128,7 @@ const _Selection = class _Selection extends (_a = BasePlugin, _registerPluginDat
129
128
  });
130
129
  const removedNodeIds = [];
131
130
  removed.forEach((el) => {
132
- if (el.className.includes(BaseRender.NODE_WRAPPER_CLASSNAME)) {
131
+ if (el.className.includes(nodeWrapperClassName)) {
133
132
  el.classList.remove(nodeClassName);
134
133
  const nodeId = el.getAttribute("data-node-id");
135
134
  if (nodeId)
@@ -172,16 +171,14 @@ const _Selection = class _Selection extends (_a = BasePlugin, _registerPluginDat
172
171
  var _a2;
173
172
  (_a2 = this.selection) == null ? void 0 : _a2.destroy();
174
173
  }
175
- };
174
+ }
176
175
  _init = __decoratorStart(_a);
177
- __decorateElement(_init, 1, "init", _init_dec, _Selection);
178
- __decorateElement(_init, 1, "destroy", _destroy_dec, _Selection);
179
- __decorateElement(_init, 5, "registerPluginData", _registerPluginData_dec, _Selection);
180
- __decorateElement(_init, 5, "startInteraction", _startInteraction_dec, _Selection);
181
- __decorateElement(_init, 5, "endInteraction", _endInteraction_dec, _Selection);
182
- __decorateElement(_init, 5, "canInteract", _canInteract_dec, _Selection);
183
- __decoratorMetadata(_init, _Selection);
184
- __publicField(_Selection, "SELECTION_AREA_CLASSNAME", bem("selection-area"));
185
- let Selection = _Selection;
176
+ __decorateElement(_init, 1, "init", _init_dec, Selection);
177
+ __decorateElement(_init, 1, "destroy", _destroy_dec, Selection);
178
+ __decorateElement(_init, 5, "registerPluginData", _registerPluginData_dec, Selection);
179
+ __decorateElement(_init, 5, "startInteraction", _startInteraction_dec, Selection);
180
+ __decorateElement(_init, 5, "endInteraction", _endInteraction_dec, Selection);
181
+ __decorateElement(_init, 5, "canInteract", _canInteract_dec, Selection);
182
+ __decoratorMetadata(_init, Selection);
186
183
 
187
184
  export { Selection };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@knotx/plugins-selection",
3
3
  "type": "module",
4
- "version": "0.0.7",
4
+ "version": "0.0.9",
5
5
  "description": "Selection Plugin for Knotx",
6
6
  "author": "boenfu",
7
7
  "license": "MIT",
@@ -31,13 +31,12 @@
31
31
  "dependencies": {
32
32
  "@viselect/vanilla": "^3.9.0",
33
33
  "rxjs": "^7.8.1",
34
- "@knotx/core": "0.0.5",
35
- "@knotx/decorators": "0.0.5",
36
- "@knotx/plugins-base-render": "0.0.7"
34
+ "@knotx/core": "0.0.7",
35
+ "@knotx/decorators": "0.0.7"
37
36
  },
38
37
  "devDependencies": {
39
- "@knotx/eslint-config": "0.0.5",
40
- "@knotx/typescript-config": "0.0.5"
38
+ "@knotx/eslint-config": "0.0.7",
39
+ "@knotx/typescript-config": "0.0.7"
41
40
  },
42
41
  "scripts": {
43
42
  "build": "unbuild --failOnWarn=false",