@anglr/common 11.2.0-beta.20220228163820 → 11.2.0-beta.20220301064114

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/changelog.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Changelog
2
2
 
3
- ## Version 11.2.0 (2022-02-28)
3
+ ## Version 11.2.0 (2022-03-01)
4
4
 
5
5
  ### Features
6
6
 
@@ -26,6 +26,10 @@
26
26
  - new `PositionPlacement` enum with available positions for placement of target element against its source
27
27
  - new `PositionOffset` enum with applied offset to position of target in cross axis relative to placement
28
28
  - new `POSITION` *Injection Token* used for injecting service that is used for positioning of one element against another
29
+ - added *subpackage* `@anglr/common/floating-ui`
30
+ - *subpackage* `@anglr/common/floating-ui`
31
+ - new `FloatingUiDomPosition` service that is used for positioning two elements against each other, using floating-ui dom implementation
32
+ - new `FLOATING_UI_POSITION` provider for floating ui position implementation
29
33
 
30
34
  ## Version 11.1.0 (2022-02-22)
31
35
 
@@ -1,7 +1,9 @@
1
1
  import { __awaiter } from "tslib";
2
- import { PositionOffset, PositionPlacement } from '@anglr/common';
2
+ import { Injectable } from '@angular/core';
3
+ import { PositionOffset, PositionPlacement, POSITION } from '@anglr/common';
3
4
  import { extend } from '@jscrpt/common';
4
- import { computePosition, autoUpdate } from '@floating-ui/dom';
5
+ import { computePosition, autoUpdate, offset, flip } from '@floating-ui/dom';
6
+ import * as i0 from "@angular/core";
5
7
  /**
6
8
  * Default options for `FloatingUiDomPosition` implementation
7
9
  */
@@ -22,9 +24,13 @@ export class FloatingUiDomPosition {
22
24
  placeElement(target, source, options) {
23
25
  return __awaiter(this, void 0, void 0, function* () {
24
26
  const computedOptions = extend({}, defaultOptions, options);
27
+ const middlewares = [];
28
+ this._setOffset(middlewares, computedOptions);
29
+ this._setFlip(middlewares, computedOptions);
25
30
  const runComputation = () => __awaiter(this, void 0, void 0, function* () {
26
31
  const result = yield computePosition(source, target, {
27
- placement: this._getPlacement(computedOptions)
32
+ placement: this._getPlacement(computedOptions),
33
+ middleware: middlewares
28
34
  });
29
35
  if (computedOptions.autoUpdate && computedOptions.autoUpdateProcessor) {
30
36
  computedOptions.autoUpdateProcessor({
@@ -39,7 +45,19 @@ export class FloatingUiDomPosition {
39
45
  const result = yield runComputation();
40
46
  let dispose = () => { };
41
47
  if (computedOptions.autoUpdate) {
42
- dispose = autoUpdate(source, target, runComputation);
48
+ let options;
49
+ if (computedOptions.autoUpdate === true) {
50
+ options =
51
+ {
52
+ ancestorResize: true,
53
+ ancestorScroll: true,
54
+ elementResize: true
55
+ };
56
+ }
57
+ else {
58
+ options = computedOptions.autoUpdate;
59
+ }
60
+ dispose = autoUpdate(source, target, runComputation, options);
43
61
  }
44
62
  return {
45
63
  target,
@@ -50,6 +68,61 @@ export class FloatingUiDomPosition {
50
68
  });
51
69
  }
52
70
  //######################### protected methods #########################
71
+ /**
72
+ * Sets flip middleware
73
+ * @param middlewares - Array of middlewares that will set
74
+ * @param options - Options that contains definition of flip
75
+ */
76
+ _setFlip(middlewares, options) {
77
+ if (options.flip) {
78
+ middlewares.push(flip());
79
+ }
80
+ }
81
+ /**
82
+ * Sets offset middleware
83
+ * @param middlewares - Array of middlewares that will set
84
+ * @param options - Options that contains definition of offset
85
+ */
86
+ _setOffset(middlewares, options) {
87
+ if (options.offset != PositionOffset.None) {
88
+ //TODO: mouse enter
89
+ middlewares.push(offset(({ floating, placement }) => {
90
+ let dimension;
91
+ if (placement == 'bottom' || placement == 'bottom-start' || placement == 'bottom-end' ||
92
+ placement == 'top' || placement == 'top-start' || placement == 'top-end') {
93
+ dimension = floating.width;
94
+ }
95
+ else {
96
+ dimension = floating.height;
97
+ }
98
+ switch (options.offset) {
99
+ default:
100
+ //case PositionOffset.Full:
101
+ {
102
+ break;
103
+ }
104
+ case PositionOffset.Half:
105
+ {
106
+ dimension /= 2;
107
+ break;
108
+ }
109
+ case PositionOffset.NegativeFull:
110
+ {
111
+ dimension *= -1;
112
+ break;
113
+ }
114
+ case PositionOffset.NegativeHalf:
115
+ {
116
+ dimension *= -.5;
117
+ break;
118
+ }
119
+ }
120
+ return {
121
+ crossAxis: dimension
122
+ };
123
+ }));
124
+ }
125
+ }
53
126
  /**
54
127
  * Gets floating ui placement from position placement
55
128
  * @param options - Options containing position placement
@@ -108,4 +181,16 @@ export class FloatingUiDomPosition {
108
181
  }
109
182
  }
110
183
  }
184
+ FloatingUiDomPosition.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: FloatingUiDomPosition, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
185
+ FloatingUiDomPosition.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: FloatingUiDomPosition });
186
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: FloatingUiDomPosition, decorators: [{
187
+ type: Injectable
188
+ }] });
189
+ /**
190
+ * Provider for floating ui position implementation
191
+ */
192
+ export const FLOATING_UI_POSITION = {
193
+ provide: POSITION,
194
+ useClass: FloatingUiDomPosition
195
+ };
111
196
  //# sourceMappingURL=floatingUiDomPosition.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"floatingUiDomPosition.service.js","sourceRoot":"","sources":["../../../../floating-ui/src/services/floatingUiDomPosition.service.ts"],"names":[],"mappings":";AAAA,OAAO,EAA4C,cAAc,EAAE,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAC3G,OAAO,EAAC,MAAM,EAAC,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAC,eAAe,EAAa,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAExE;;GAEG;AACH,MAAM,cAAc,GACpB;IACI,UAAU,EAAE,KAAK;IACjB,IAAI,EAAE,KAAK;IACX,MAAM,EAAE,cAAc,CAAC,IAAI;IAC3B,SAAS,EAAE,iBAAiB,CAAC,GAAG;CACnC,CAAC;AAEF;;GAEG;AACH,MAAM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KAAK,iBAAiB,CAAC,MAAM;gBAC7B;oBACI,OAAO,SAAS,CAAC;iBACpB;YACD,KAAK,iBAAiB,CAAC,MAAM;gBAC7B;oBACI,OAAO,QAAQ,CAAC;iBACnB;YACD,KAAK,iBAAiB,CAAC,WAAW;gBAClC;oBACI,OAAO,cAAc,CAAC;iBACzB;YACD,KAAK,iBAAiB,CAAC,SAAS;gBAChC;oBACI,OAAO,YAAY,CAAC;iBACvB;YACD,KAAK,iBAAiB,CAAC,IAAI;gBAC3B;oBACI,OAAO,MAAM,CAAC;iBACjB;YACD,KAAK,iBAAiB,CAAC,SAAS;gBAChC;oBACI,OAAO,YAAY,CAAC;iBACvB;YACD,KAAK,iBAAiB,CAAC,OAAO;gBAC9B;oBACI,OAAO,UAAU,CAAC;iBACrB;YACD,KAAK,iBAAiB,CAAC,KAAK;gBAC5B;oBACI,OAAO,OAAO,CAAC;iBAClB;YACD,KAAK,iBAAiB,CAAC,UAAU;gBACjC;oBACI,OAAO,aAAa,CAAC;iBACxB;YACD,KAAK,iBAAiB,CAAC,QAAQ;gBAC/B;oBACI,OAAO,WAAW,CAAC;iBACtB;SACJ;IACL,CAAC;CACJ","sourcesContent":["import {Position, PositionResult, PositionOptions, PositionOffset, PositionPlacement} from '@anglr/common';\nimport {extend} from '@jscrpt/common';\nimport {computePosition, Placement, autoUpdate} from '@floating-ui/dom';\n\n/**\n * Default options for `FloatingUiDomPosition` implementation\n */\nconst defaultOptions: PositionOptions =\n{\n autoUpdate: false,\n flip: false,\n offset: PositionOffset.None,\n placement: PositionPlacement.Top\n};\n\n/**\n * Service that is used for positioning two elements against each other, using floating-ui dom implementation\n */\nexport class FloatingUiDomPosition implements Position\n{\n //######################### public methods - implementation of Position #########################\n\n /**\n * @inheritdoc\n */\n public async placeElement(target: Element, source: Element, options?: Partial<PositionOptions>): Promise<PositionResult>\n {\n const computedOptions = extend({}, defaultOptions, options);\n\n const runComputation = async () =>\n {\n const result = await computePosition(source,\n target as HTMLElement,\n {\n placement: this._getPlacement(computedOptions)\n });\n\n if(computedOptions.autoUpdate && computedOptions.autoUpdateProcessor)\n {\n computedOptions.autoUpdateProcessor(\n {\n target,\n dispose: () => {},\n x: result.x,\n y: result.y\n });\n }\n\n return result;\n };\n\n const result = await runComputation();\n let dispose = () => {};\n\n if(computedOptions.autoUpdate)\n {\n dispose = autoUpdate(source, target as HTMLElement, runComputation);\n }\n\n return {\n target,\n dispose,\n x: result.x,\n y: result.y\n };\n }\n\n //######################### protected methods #########################\n\n /**\n * Gets floating ui placement from position placement\n * @param options - Options containing position placement\n */\n protected _getPlacement(options: PositionOptions): Placement\n {\n switch(options.placement)\n {\n default:\n // case PositionPlacement.Top:\n {\n return 'bottom';\n }\n case PositionPlacement.TopStart:\n {\n return 'top-start';\n }\n case PositionPlacement.TopEnd:\n {\n return 'top-end';\n }\n case PositionPlacement.Bottom:\n {\n return 'bottom';\n }\n case PositionPlacement.BottomStart:\n {\n return 'bottom-start';\n }\n case PositionPlacement.BottomEnd:\n {\n return 'bottom-end';\n }\n case PositionPlacement.Left:\n {\n return 'left';\n }\n case PositionPlacement.LeftStart:\n {\n return 'left-start';\n }\n case PositionPlacement.LeftEnd:\n {\n return 'left-end';\n }\n case PositionPlacement.Right:\n {\n return 'right';\n }\n case PositionPlacement.RightStart:\n {\n return 'right-start';\n }\n case PositionPlacement.RightEnd:\n {\n return 'right-end';\n }\n }\n }\n}"]}
1
+ {"version":3,"file":"floatingUiDomPosition.service.js","sourceRoot":"","sources":["../../../../floating-ui/src/services/floatingUiDomPosition.service.ts"],"names":[],"mappings":";AAAA,OAAO,EAAgB,UAAU,EAAC,MAAM,eAAe,CAAC;AACxD,OAAO,EAA4C,cAAc,EAAE,iBAAiB,EAAqB,QAAQ,EAAC,MAAM,eAAe,CAAC;AACxI,OAAO,EAAC,MAAM,EAAC,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAC,eAAe,EAAa,UAAU,EAAc,MAAM,EAAE,IAAI,EAAC,MAAM,kBAAkB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AAW,CAAC;iBACtB;SACJ;IACL,CAAC;;kHA7MQ,qBAAqB;sHAArB,qBAAqB;2FAArB,qBAAqB;kBADjC,UAAU;;AAiNX;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GACjC;IACI,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,qBAAqB;CAClC,CAAC","sourcesContent":["import {ClassProvider, Injectable} from '@angular/core';\nimport {Position, PositionResult, PositionOptions, PositionOffset, PositionPlacement, AutoUpdateOptions, POSITION} from '@anglr/common';\nimport {extend} from '@jscrpt/common';\nimport {computePosition, Placement, autoUpdate, Middleware, offset, flip} from '@floating-ui/dom';\n\n/**\n * Default options for `FloatingUiDomPosition` implementation\n */\nconst defaultOptions: PositionOptions =\n{\n autoUpdate: false,\n flip: false,\n offset: PositionOffset.None,\n placement: PositionPlacement.Top\n};\n\n/**\n * Service that is used for positioning two elements against each other, using floating-ui dom implementation\n */\n@Injectable()\nexport class FloatingUiDomPosition implements Position\n{\n //######################### public methods - implementation of Position #########################\n\n /**\n * @inheritdoc\n */\n public async placeElement(target: Element, source: Element, options?: Partial<PositionOptions>): Promise<PositionResult>\n {\n const computedOptions = extend({}, defaultOptions, options);\n const middlewares: Middleware[] = [];\n\n this._setOffset(middlewares, computedOptions);\n this._setFlip(middlewares, computedOptions);\n\n const runComputation = async () =>\n {\n const result = await computePosition(source,\n target as HTMLElement,\n {\n placement: this._getPlacement(computedOptions),\n middleware: middlewares\n });\n\n if(computedOptions.autoUpdate && computedOptions.autoUpdateProcessor)\n {\n computedOptions.autoUpdateProcessor(\n {\n target,\n dispose: () => {},\n x: result.x,\n y: result.y\n });\n }\n\n return result;\n };\n\n const result = await runComputation();\n let dispose = () => {};\n\n if(computedOptions.autoUpdate)\n {\n let options: AutoUpdateOptions;\n\n if(computedOptions.autoUpdate === true)\n {\n options =\n {\n ancestorResize: true,\n ancestorScroll: true,\n elementResize: true\n };\n }\n else\n {\n options = computedOptions.autoUpdate;\n }\n\n dispose = autoUpdate(source,\n target as HTMLElement,\n runComputation,\n options);\n }\n\n return {\n target,\n dispose,\n x: result.x,\n y: result.y\n };\n }\n\n //######################### protected methods #########################\n\n /**\n * Sets flip middleware\n * @param middlewares - Array of middlewares that will set\n * @param options - Options that contains definition of flip\n */\n protected _setFlip(middlewares: Middleware[], options: PositionOptions): void\n {\n if(options.flip)\n {\n middlewares.push(flip());\n }\n }\n\n /**\n * Sets offset middleware\n * @param middlewares - Array of middlewares that will set\n * @param options - Options that contains definition of offset\n */\n protected _setOffset(middlewares: Middleware[], options: PositionOptions): void\n {\n if(options.offset != PositionOffset.None)\n {\n //TODO: mouse enter\n\n middlewares.push(offset(({floating, placement}) => \n {\n let dimension: number;\n\n if(placement == 'bottom' || placement == 'bottom-start' || placement == 'bottom-end' ||\n placement == 'top' || placement == 'top-start' || placement == 'top-end')\n {\n dimension = floating.width;\n }\n else\n {\n dimension = floating.height;\n }\n\n switch(options.offset)\n {\n default:\n //case PositionOffset.Full:\n {\n break;\n }\n case PositionOffset.Half:\n {\n dimension /= 2;\n\n break;\n }\n case PositionOffset.NegativeFull:\n {\n dimension *= -1;\n\n break;\n }\n case PositionOffset.NegativeHalf:\n {\n dimension *= -.5;\n\n break;\n }\n }\n \n return {\n crossAxis: dimension\n };\n }));\n }\n }\n\n /**\n * Gets floating ui placement from position placement\n * @param options - Options containing position placement\n */\n protected _getPlacement(options: PositionOptions): Placement\n {\n switch(options.placement)\n {\n default:\n // case PositionPlacement.Top:\n {\n return 'bottom';\n }\n case PositionPlacement.TopStart:\n {\n return 'top-start';\n }\n case PositionPlacement.TopEnd:\n {\n return 'top-end';\n }\n case PositionPlacement.Bottom:\n {\n return 'bottom';\n }\n case PositionPlacement.BottomStart:\n {\n return 'bottom-start';\n }\n case PositionPlacement.BottomEnd:\n {\n return 'bottom-end';\n }\n case PositionPlacement.Left:\n {\n return 'left';\n }\n case PositionPlacement.LeftStart:\n {\n return 'left-start';\n }\n case PositionPlacement.LeftEnd:\n {\n return 'left-end';\n }\n case PositionPlacement.Right:\n {\n return 'right';\n }\n case PositionPlacement.RightStart:\n {\n return 'right-start';\n }\n case PositionPlacement.RightEnd:\n {\n return 'right-end';\n }\n }\n }\n}\n\n/**\n * Provider for floating ui position implementation\n */\nexport const FLOATING_UI_POSITION: ClassProvider =\n{\n provide: POSITION,\n useClass: FloatingUiDomPosition\n};"]}
@@ -1,6 +1,8 @@
1
- import { PositionOffset, PositionPlacement } from '@anglr/common';
1
+ import { Injectable } from '@angular/core';
2
+ import { PositionOffset, PositionPlacement, POSITION } from '@anglr/common';
2
3
  import { extend } from '@jscrpt/common';
3
- import { computePosition, autoUpdate } from '@floating-ui/dom';
4
+ import { computePosition, autoUpdate, offset, flip } from '@floating-ui/dom';
5
+ import * as i0 from "@angular/core";
4
6
  /**
5
7
  * Default options for `FloatingUiDomPosition` implementation
6
8
  */
@@ -20,9 +22,13 @@ export class FloatingUiDomPosition {
20
22
  */
21
23
  async placeElement(target, source, options) {
22
24
  const computedOptions = extend({}, defaultOptions, options);
25
+ const middlewares = [];
26
+ this._setOffset(middlewares, computedOptions);
27
+ this._setFlip(middlewares, computedOptions);
23
28
  const runComputation = async () => {
24
29
  const result = await computePosition(source, target, {
25
- placement: this._getPlacement(computedOptions)
30
+ placement: this._getPlacement(computedOptions),
31
+ middleware: middlewares
26
32
  });
27
33
  if (computedOptions.autoUpdate && computedOptions.autoUpdateProcessor) {
28
34
  computedOptions.autoUpdateProcessor({
@@ -37,7 +43,19 @@ export class FloatingUiDomPosition {
37
43
  const result = await runComputation();
38
44
  let dispose = () => { };
39
45
  if (computedOptions.autoUpdate) {
40
- dispose = autoUpdate(source, target, runComputation);
46
+ let options;
47
+ if (computedOptions.autoUpdate === true) {
48
+ options =
49
+ {
50
+ ancestorResize: true,
51
+ ancestorScroll: true,
52
+ elementResize: true
53
+ };
54
+ }
55
+ else {
56
+ options = computedOptions.autoUpdate;
57
+ }
58
+ dispose = autoUpdate(source, target, runComputation, options);
41
59
  }
42
60
  return {
43
61
  target,
@@ -47,6 +65,61 @@ export class FloatingUiDomPosition {
47
65
  };
48
66
  }
49
67
  //######################### protected methods #########################
68
+ /**
69
+ * Sets flip middleware
70
+ * @param middlewares - Array of middlewares that will set
71
+ * @param options - Options that contains definition of flip
72
+ */
73
+ _setFlip(middlewares, options) {
74
+ if (options.flip) {
75
+ middlewares.push(flip());
76
+ }
77
+ }
78
+ /**
79
+ * Sets offset middleware
80
+ * @param middlewares - Array of middlewares that will set
81
+ * @param options - Options that contains definition of offset
82
+ */
83
+ _setOffset(middlewares, options) {
84
+ if (options.offset != PositionOffset.None) {
85
+ //TODO: mouse enter
86
+ middlewares.push(offset(({ floating, placement }) => {
87
+ let dimension;
88
+ if (placement == 'bottom' || placement == 'bottom-start' || placement == 'bottom-end' ||
89
+ placement == 'top' || placement == 'top-start' || placement == 'top-end') {
90
+ dimension = floating.width;
91
+ }
92
+ else {
93
+ dimension = floating.height;
94
+ }
95
+ switch (options.offset) {
96
+ default:
97
+ //case PositionOffset.Full:
98
+ {
99
+ break;
100
+ }
101
+ case PositionOffset.Half:
102
+ {
103
+ dimension /= 2;
104
+ break;
105
+ }
106
+ case PositionOffset.NegativeFull:
107
+ {
108
+ dimension *= -1;
109
+ break;
110
+ }
111
+ case PositionOffset.NegativeHalf:
112
+ {
113
+ dimension *= -.5;
114
+ break;
115
+ }
116
+ }
117
+ return {
118
+ crossAxis: dimension
119
+ };
120
+ }));
121
+ }
122
+ }
50
123
  /**
51
124
  * Gets floating ui placement from position placement
52
125
  * @param options - Options containing position placement
@@ -105,4 +178,16 @@ export class FloatingUiDomPosition {
105
178
  }
106
179
  }
107
180
  }
181
+ FloatingUiDomPosition.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: FloatingUiDomPosition, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
182
+ FloatingUiDomPosition.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: FloatingUiDomPosition });
183
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: FloatingUiDomPosition, decorators: [{
184
+ type: Injectable
185
+ }] });
186
+ /**
187
+ * Provider for floating ui position implementation
188
+ */
189
+ export const FLOATING_UI_POSITION = {
190
+ provide: POSITION,
191
+ useClass: FloatingUiDomPosition
192
+ };
108
193
  //# sourceMappingURL=floatingUiDomPosition.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"floatingUiDomPosition.service.js","sourceRoot":"","sources":["../../../../floating-ui/src/services/floatingUiDomPosition.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,cAAc,EAAE,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAC3G,OAAO,EAAC,MAAM,EAAC,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAC,eAAe,EAAa,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAExE;;GAEG;AACH,MAAM,cAAc,GACpB;IACI,UAAU,EAAE,KAAK;IACjB,IAAI,EAAE,KAAK;IACX,MAAM,EAAE,cAAc,CAAC,IAAI;IAC3B,SAAS,EAAE,iBAAiB,CAAC,GAAG;CACnC,CAAC;AAEF;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAE9B,iGAAiG;IAEjG;;OAEG;IACI,KAAK,CAAC,YAAY,CAAC,MAAe,EAAE,MAAe,EAAE,OAAkC;QAE1F,MAAM,eAAe,GAAG,MAAM,CAAC,EAAE,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;QAE5D,MAAM,cAAc,GAAG,KAAK,IAAI,EAAE;YAE9B,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,MAAM,EACN,MAAqB,EACrB;gBACI,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC;aACjD,CAAC,CAAC;YAExC,IAAG,eAAe,CAAC,UAAU,IAAI,eAAe,CAAC,mBAAmB,EACpE;gBACI,eAAe,CAAC,mBAAmB,CACnC;oB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AU,CAAC;iBACrB;YACD,KAAK,iBAAiB,CAAC,KAAK;gBAC5B;oBACI,OAAO,OAAO,CAAC;iBAClB;YACD,KAAK,iBAAiB,CAAC,UAAU;gBACjC;oBACI,OAAO,aAAa,CAAC;iBACxB;YACD,KAAK,iBAAiB,CAAC,QAAQ;gBAC/B;oBACI,OAAO,WAAW,CAAC;iBACtB;SACJ;IACL,CAAC;CACJ","sourcesContent":["import {Position, PositionResult, PositionOptions, PositionOffset, PositionPlacement} from '@anglr/common';\nimport {extend} from '@jscrpt/common';\nimport {computePosition, Placement, autoUpdate} from '@floating-ui/dom';\n\n/**\n * Default options for `FloatingUiDomPosition` implementation\n */\nconst defaultOptions: PositionOptions =\n{\n autoUpdate: false,\n flip: false,\n offset: PositionOffset.None,\n placement: PositionPlacement.Top\n};\n\n/**\n * Service that is used for positioning two elements against each other, using floating-ui dom implementation\n */\nexport class FloatingUiDomPosition implements Position\n{\n //######################### public methods - implementation of Position #########################\n\n /**\n * @inheritdoc\n */\n public async placeElement(target: Element, source: Element, options?: Partial<PositionOptions>): Promise<PositionResult>\n {\n const computedOptions = extend({}, defaultOptions, options);\n\n const runComputation = async () =>\n {\n const result = await computePosition(source,\n target as HTMLElement,\n {\n placement: this._getPlacement(computedOptions)\n });\n\n if(computedOptions.autoUpdate && computedOptions.autoUpdateProcessor)\n {\n computedOptions.autoUpdateProcessor(\n {\n target,\n dispose: () => {},\n x: result.x,\n y: result.y\n });\n }\n\n return result;\n };\n\n const result = await runComputation();\n let dispose = () => {};\n\n if(computedOptions.autoUpdate)\n {\n dispose = autoUpdate(source, target as HTMLElement, runComputation);\n }\n\n return {\n target,\n dispose,\n x: result.x,\n y: result.y\n };\n }\n\n //######################### protected methods #########################\n\n /**\n * Gets floating ui placement from position placement\n * @param options - Options containing position placement\n */\n protected _getPlacement(options: PositionOptions): Placement\n {\n switch(options.placement)\n {\n default:\n // case PositionPlacement.Top:\n {\n return 'bottom';\n }\n case PositionPlacement.TopStart:\n {\n return 'top-start';\n }\n case PositionPlacement.TopEnd:\n {\n return 'top-end';\n }\n case PositionPlacement.Bottom:\n {\n return 'bottom';\n }\n case PositionPlacement.BottomStart:\n {\n return 'bottom-start';\n }\n case PositionPlacement.BottomEnd:\n {\n return 'bottom-end';\n }\n case PositionPlacement.Left:\n {\n return 'left';\n }\n case PositionPlacement.LeftStart:\n {\n return 'left-start';\n }\n case PositionPlacement.LeftEnd:\n {\n return 'left-end';\n }\n case PositionPlacement.Right:\n {\n return 'right';\n }\n case PositionPlacement.RightStart:\n {\n return 'right-start';\n }\n case PositionPlacement.RightEnd:\n {\n return 'right-end';\n }\n }\n }\n}"]}
1
+ {"version":3,"file":"floatingUiDomPosition.service.js","sourceRoot":"","sources":["../../../../floating-ui/src/services/floatingUiDomPosition.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,UAAU,EAAC,MAAM,eAAe,CAAC;AACxD,OAAO,EAA4C,cAAc,EAAE,iBAAiB,EAAqB,QAAQ,EAAC,MAAM,eAAe,CAAC;AACxI,OAAO,EAAC,MAAM,EAAC,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAC,eAAe,EAAa,UAAU,EAAc,MAAM,EAAE,IAAI,EAAC,MAAM,kBAAkB,CAAC;;AAElG;;GAEG;AACH,MAAM,cAAc,GACpB;IACI,UAAU,EAAE,KAAK;IACjB,IAAI,EAAE,KAAK;IACX,MAAM,EAAE,cAAc,CAAC,IAAI;IAC3B,SAAS,EAAE,iBAAiB,CAAC,GAAG;CACnC,CAAC;AAEF;;GAEG;AAEH,MAAM,OAAO,qBAAqB;IAE9B,iGAAiG;IAEjG;;OAEG;IACI,KAAK,CAAC,YAAY,CAAC,MAAe,EAAE,MAAe,EAAE,OAAkC;QAE1F,MAAM,eAAe,GAAG,MAAM,CAAC,EAAE,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;QAC5D,MAAM,WAAW,GAAiB,EAAE,CAAC;QAErC,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,eAAe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AiB,CAAC,QAAQ;gBAC/B;oBACI,OAAO,WAAW,CAAC;iBACtB;YACD,KAAK,iBAAiB,CAAC,MAAM;gBAC7B;oBACI,OAAO,SAAS,CAAC;iBACpB;YACD,KAAK,iBAAiB,CAAC,MAAM;gBAC7B;oBACI,OAAO,QAAQ,CAAC;iBACnB;YACD,KAAK,iBAAiB,CAAC,WAAW;gBAClC;oBACI,OAAO,cAAc,CAAC;iBACzB;YACD,KAAK,iBAAiB,CAAC,SAAS;gBAChC;oBACI,OAAO,YAAY,CAAC;iBACvB;YACD,KAAK,iBAAiB,CAAC,IAAI;gBAC3B;oBACI,OAAO,MAAM,CAAC;iBACjB;YACD,KAAK,iBAAiB,CAAC,SAAS;gBAChC;oBACI,OAAO,YAAY,CAAC;iBACvB;YACD,KAAK,iBAAiB,CAAC,OAAO;gBAC9B;oBACI,OAAO,UAAU,CAAC;iBACrB;YACD,KAAK,iBAAiB,CAAC,KAAK;gBAC5B;oBACI,OAAO,OAAO,CAAC;iBAClB;YACD,KAAK,iBAAiB,CAAC,UAAU;gBACjC;oBACI,OAAO,aAAa,CAAC;iBACxB;YACD,KAAK,iBAAiB,CAAC,QAAQ;gBAC/B;oBACI,OAAO,WAAW,CAAC;iBACtB;SACJ;IACL,CAAC;;kHA7MQ,qBAAqB;sHAArB,qBAAqB;2FAArB,qBAAqB;kBADjC,UAAU;;AAiNX;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GACjC;IACI,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,qBAAqB;CAClC,CAAC","sourcesContent":["import {ClassProvider, Injectable} from '@angular/core';\nimport {Position, PositionResult, PositionOptions, PositionOffset, PositionPlacement, AutoUpdateOptions, POSITION} from '@anglr/common';\nimport {extend} from '@jscrpt/common';\nimport {computePosition, Placement, autoUpdate, Middleware, offset, flip} from '@floating-ui/dom';\n\n/**\n * Default options for `FloatingUiDomPosition` implementation\n */\nconst defaultOptions: PositionOptions =\n{\n autoUpdate: false,\n flip: false,\n offset: PositionOffset.None,\n placement: PositionPlacement.Top\n};\n\n/**\n * Service that is used for positioning two elements against each other, using floating-ui dom implementation\n */\n@Injectable()\nexport class FloatingUiDomPosition implements Position\n{\n //######################### public methods - implementation of Position #########################\n\n /**\n * @inheritdoc\n */\n public async placeElement(target: Element, source: Element, options?: Partial<PositionOptions>): Promise<PositionResult>\n {\n const computedOptions = extend({}, defaultOptions, options);\n const middlewares: Middleware[] = [];\n\n this._setOffset(middlewares, computedOptions);\n this._setFlip(middlewares, computedOptions);\n\n const runComputation = async () =>\n {\n const result = await computePosition(source,\n target as HTMLElement,\n {\n placement: this._getPlacement(computedOptions),\n middleware: middlewares\n });\n\n if(computedOptions.autoUpdate && computedOptions.autoUpdateProcessor)\n {\n computedOptions.autoUpdateProcessor(\n {\n target,\n dispose: () => {},\n x: result.x,\n y: result.y\n });\n }\n\n return result;\n };\n\n const result = await runComputation();\n let dispose = () => {};\n\n if(computedOptions.autoUpdate)\n {\n let options: AutoUpdateOptions;\n\n if(computedOptions.autoUpdate === true)\n {\n options =\n {\n ancestorResize: true,\n ancestorScroll: true,\n elementResize: true\n };\n }\n else\n {\n options = computedOptions.autoUpdate;\n }\n\n dispose = autoUpdate(source,\n target as HTMLElement,\n runComputation,\n options);\n }\n\n return {\n target,\n dispose,\n x: result.x,\n y: result.y\n };\n }\n\n //######################### protected methods #########################\n\n /**\n * Sets flip middleware\n * @param middlewares - Array of middlewares that will set\n * @param options - Options that contains definition of flip\n */\n protected _setFlip(middlewares: Middleware[], options: PositionOptions): void\n {\n if(options.flip)\n {\n middlewares.push(flip());\n }\n }\n\n /**\n * Sets offset middleware\n * @param middlewares - Array of middlewares that will set\n * @param options - Options that contains definition of offset\n */\n protected _setOffset(middlewares: Middleware[], options: PositionOptions): void\n {\n if(options.offset != PositionOffset.None)\n {\n //TODO: mouse enter\n\n middlewares.push(offset(({floating, placement}) => \n {\n let dimension: number;\n\n if(placement == 'bottom' || placement == 'bottom-start' || placement == 'bottom-end' ||\n placement == 'top' || placement == 'top-start' || placement == 'top-end')\n {\n dimension = floating.width;\n }\n else\n {\n dimension = floating.height;\n }\n\n switch(options.offset)\n {\n default:\n //case PositionOffset.Full:\n {\n break;\n }\n case PositionOffset.Half:\n {\n dimension /= 2;\n\n break;\n }\n case PositionOffset.NegativeFull:\n {\n dimension *= -1;\n\n break;\n }\n case PositionOffset.NegativeHalf:\n {\n dimension *= -.5;\n\n break;\n }\n }\n \n return {\n crossAxis: dimension\n };\n }));\n }\n }\n\n /**\n * Gets floating ui placement from position placement\n * @param options - Options containing position placement\n */\n protected _getPlacement(options: PositionOptions): Placement\n {\n switch(options.placement)\n {\n default:\n // case PositionPlacement.Top:\n {\n return 'bottom';\n }\n case PositionPlacement.TopStart:\n {\n return 'top-start';\n }\n case PositionPlacement.TopEnd:\n {\n return 'top-end';\n }\n case PositionPlacement.Bottom:\n {\n return 'bottom';\n }\n case PositionPlacement.BottomStart:\n {\n return 'bottom-start';\n }\n case PositionPlacement.BottomEnd:\n {\n return 'bottom-end';\n }\n case PositionPlacement.Left:\n {\n return 'left';\n }\n case PositionPlacement.LeftStart:\n {\n return 'left-start';\n }\n case PositionPlacement.LeftEnd:\n {\n return 'left-end';\n }\n case PositionPlacement.Right:\n {\n return 'right';\n }\n case PositionPlacement.RightStart:\n {\n return 'right-start';\n }\n case PositionPlacement.RightEnd:\n {\n return 'right-end';\n }\n }\n }\n}\n\n/**\n * Provider for floating ui position implementation\n */\nexport const FLOATING_UI_POSITION: ClassProvider =\n{\n provide: POSITION,\n useClass: FloatingUiDomPosition\n};"]}
@@ -1,5 +1,7 @@
1
+ import { ClassProvider } from '@angular/core';
1
2
  import { Position, PositionResult, PositionOptions } from '@anglr/common';
2
- import { Placement } from '@floating-ui/dom';
3
+ import { Placement, Middleware } from '@floating-ui/dom';
4
+ import * as i0 from "@angular/core";
3
5
  /**
4
6
  * Service that is used for positioning two elements against each other, using floating-ui dom implementation
5
7
  */
@@ -8,10 +10,28 @@ export declare class FloatingUiDomPosition implements Position {
8
10
  * @inheritdoc
9
11
  */
10
12
  placeElement(target: Element, source: Element, options?: Partial<PositionOptions>): Promise<PositionResult>;
13
+ /**
14
+ * Sets flip middleware
15
+ * @param middlewares - Array of middlewares that will set
16
+ * @param options - Options that contains definition of flip
17
+ */
18
+ protected _setFlip(middlewares: Middleware[], options: PositionOptions): void;
19
+ /**
20
+ * Sets offset middleware
21
+ * @param middlewares - Array of middlewares that will set
22
+ * @param options - Options that contains definition of offset
23
+ */
24
+ protected _setOffset(middlewares: Middleware[], options: PositionOptions): void;
11
25
  /**
12
26
  * Gets floating ui placement from position placement
13
27
  * @param options - Options containing position placement
14
28
  */
15
29
  protected _getPlacement(options: PositionOptions): Placement;
30
+ static ɵfac: i0.ɵɵFactoryDeclaration<FloatingUiDomPosition, never>;
31
+ static ɵprov: i0.ɵɵInjectableDeclaration<FloatingUiDomPosition>;
16
32
  }
33
+ /**
34
+ * Provider for floating ui position implementation
35
+ */
36
+ export declare const FLOATING_UI_POSITION: ClassProvider;
17
37
  //# sourceMappingURL=floatingUiDomPosition.service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"floatingUiDomPosition.service.d.ts","sourceRoot":"","sources":["floatingUiDomPosition.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,cAAc,EAAE,eAAe,EAAoC,MAAM,eAAe,CAAC;AAE3G,OAAO,EAAkB,SAAS,EAAa,MAAM,kBAAkB,CAAC;AAaxE;;GAEG;AACH,qBAAa,qBAAsB,YAAW,QAAQ;IAIlD;;OAEG;IACU,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;IA4CxH;;;OAGG;IACH,SAAS,CAAC,aAAa,CAAC,OAAO,EAAE,eAAe,GAAG,SAAS;CAuD/D"}
1
+ {"version":3,"file":"floatingUiDomPosition.service.d.ts","sourceRoot":"","sources":["floatingUiDomPosition.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAa,MAAM,eAAe,CAAC;AACxD,OAAO,EAAC,QAAQ,EAAE,cAAc,EAAE,eAAe,EAAiE,MAAM,eAAe,CAAC;AAExI,OAAO,EAAkB,SAAS,EAAc,UAAU,EAAe,MAAM,kBAAkB,CAAC;;AAalG;;GAEG;AACH,qBACa,qBAAsB,YAAW,QAAQ;IAIlD;;OAEG;IACU,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;IAoExH;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,UAAU,EAAE,EAAE,OAAO,EAAE,eAAe,GAAG,IAAI;IAQ7E;;;;OAIG;IACH,SAAS,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,EAAE,EAAE,OAAO,EAAE,eAAe,GAAG,IAAI;IAsD/E;;;OAGG;IACH,SAAS,CAAC,aAAa,CAAC,OAAO,EAAE,eAAe,GAAG,SAAS;yCAvJnD,qBAAqB;6CAArB,qBAAqB;CA8MjC;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,aAIlC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anglr/common",
3
- "version": "11.2.0-beta.20220228163820",
3
+ "version": "11.2.0-beta.20220301064114",
4
4
  "description": "Angular module for common angular stuff",
5
5
  "type": "module",
6
6
  "sideEffects": false,
package/version.bak CHANGED
@@ -1 +1 @@
1
- 11.2.0-beta.20220228163820
1
+ 11.2.0-beta.20220301064114