vue-mount-plugin 4.0.0-beta.5 → 4.0.0-beta.6

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
@@ -10,9 +10,6 @@ function _arrayLikeToArray(r, a) {
10
10
  function _arrayWithHoles(r) {
11
11
  if (Array.isArray(r)) return r;
12
12
  }
13
- function _arrayWithoutHoles(r) {
14
- if (Array.isArray(r)) return _arrayLikeToArray(r);
15
- }
16
13
  function _assertThisInitialized(e) {
17
14
  if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
18
15
  return e;
@@ -92,9 +89,6 @@ function _isNativeReflectConstruct() {
92
89
  return !!t;
93
90
  })();
94
91
  }
95
- function _iterableToArray(r) {
96
- if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
97
- }
98
92
  function _iterableToArrayLimit(r, l) {
99
93
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
100
94
  if (null != t) {
@@ -122,9 +116,6 @@ function _iterableToArrayLimit(r, l) {
122
116
  function _nonIterableRest() {
123
117
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
124
118
  }
125
- function _nonIterableSpread() {
126
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
127
- }
128
119
  function ownKeys(e, r) {
129
120
  var t = Object.keys(e);
130
121
  if (Object.getOwnPropertySymbols) {
@@ -159,9 +150,6 @@ function _setPrototypeOf(t, e) {
159
150
  function _slicedToArray(r, e) {
160
151
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
161
152
  }
162
- function _toConsumableArray(r) {
163
- return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
164
- }
165
153
  function _toPrimitive(t, r) {
166
154
  if ("object" != typeof t || !t) return t;
167
155
  var e = t[Symbol.toPrimitive];
@@ -184,6 +172,25 @@ function _unsupportedIterableToArray(r, a) {
184
172
  }
185
173
  }
186
174
 
175
+ var globalConfig = {
176
+ installed: false
177
+ };
178
+ function setGlobalConfig(config) {
179
+ Object.assign(globalConfig, config);
180
+ }
181
+ function getGlobalConfig() {
182
+ return _objectSpread2({}, globalConfig);
183
+ }
184
+ function resetGlobalConfig() {
185
+ Object.keys(globalConfig).forEach(function (key) {
186
+ delete globalConfig[key];
187
+ });
188
+ globalConfig.installed = false;
189
+ }
190
+ function mergeWithGlobalConfig(options) {
191
+ return _objectSpread2(_objectSpread2({}, globalConfig), options);
192
+ }
193
+
187
194
  var singletonInstances = new Map();
188
195
  var componentKeys = new WeakMap();
189
196
  function getComponentKey(component) {
@@ -220,36 +227,10 @@ function clearSingletons() {
220
227
  function hasSingleton(key) {
221
228
  return singletonInstances.has(key);
222
229
  }
223
- function getSingletonKeys() {
224
- return Array.from(singletonInstances.keys());
225
- }
226
-
227
- var globalConfig = {
228
- installed: false
229
- };
230
- function setGlobalConfig(config) {
231
- Object.assign(globalConfig, config);
232
- }
233
- function getGlobalConfig() {
234
- return _objectSpread2({}, globalConfig);
235
- }
236
- function resetGlobalConfig() {
237
- Object.keys(globalConfig).forEach(function (key) {
238
- delete globalConfig[key];
239
- });
240
- globalConfig.installed = false;
241
- }
242
- function mergeWithGlobalConfig(options) {
243
- return _objectSpread2(_objectSpread2({}, globalConfig), options);
244
- }
245
230
 
246
231
  function isBrowser() {
247
232
  return typeof document !== 'undefined';
248
233
  }
249
- function isNodeEnv() {
250
- var _process$versions;
251
- return typeof process !== 'undefined' && !!((_process$versions = process.versions) !== null && _process$versions !== void 0 && _process$versions.node);
252
- }
253
234
  function resolveTarget(target) {
254
235
  if (!target) return null;
255
236
  if (typeof target === 'string') {
@@ -285,9 +266,8 @@ function appendTo(element, target) {
285
266
  }
286
267
  }
287
268
  function removeElement(element) {
288
- if (element.parentNode) {
289
- element.parentNode.removeChild(element);
290
- }
269
+ var _element$parentNode;
270
+ (_element$parentNode = element.parentNode) === null || _element$parentNode === void 0 || _element$parentNode.removeChild(element);
291
271
  }
292
272
  function isInDOM(element) {
293
273
  return document.body.contains(element);
@@ -297,19 +277,8 @@ function setZIndex(element, zIndex) {
297
277
  element.style.zIndex = String(zIndex);
298
278
  }
299
279
  }
300
- function addClass(element, className) {
301
- if (className) {
302
- var _element$classList;
303
- (_element$classList = element.classList).add.apply(_element$classList, _toConsumableArray(className.split(/\s+/).filter(Boolean)));
304
- }
305
- }
306
- function removeClass(element, className) {
307
- if (className) {
308
- var _element$classList2;
309
- (_element$classList2 = element.classList).remove.apply(_element$classList2, _toConsumableArray(className.split(/\s+/).filter(Boolean)));
310
- }
311
- }
312
280
 
281
+ var instanceCounter = 0;
313
282
  var EventEmitter = /*#__PURE__*/function () {
314
283
  function EventEmitter() {
315
284
  _classCallCheck(this, EventEmitter);
@@ -368,7 +337,6 @@ var EventEmitter = /*#__PURE__*/function () {
368
337
  }
369
338
  }]);
370
339
  }();
371
- var instanceCounter = 0;
372
340
  function createInstanceId() {
373
341
  return "mount-".concat(++instanceCounter, "-").concat(Date.now().toString(36));
374
342
  }
@@ -554,10 +522,8 @@ var MountBase = /*#__PURE__*/function () {
554
522
  }, {
555
523
  key: "_appendElementToDOM",
556
524
  value: function _appendElementToDOM() {
557
- if (!this.el) return;
558
- if (this._autoCreatedTarget) {
559
- appendTo(this.el, null);
560
- }
525
+ if (!this.el || !this._autoCreatedTarget) return;
526
+ appendTo(this.el, null);
561
527
  }
562
528
  }, {
563
529
  key: "_resolvePromise",
@@ -579,8 +545,7 @@ var MountBase = /*#__PURE__*/function () {
579
545
  var _ref2 = _slicedToArray(_ref, 2),
580
546
  event = _ref2[0],
581
547
  handler = _ref2[1];
582
- var propName = eventToPropName(event);
583
- result[propName] = function () {
548
+ result[eventToPropName(event)] = function () {
584
549
  if (typeof handler === 'function') {
585
550
  handler.apply(void 0, arguments);
586
551
  }
@@ -631,7 +596,7 @@ function inheritVue2Context(parent, options) {
631
596
  }
632
597
  return context;
633
598
  }
634
- function inheritVue3Context(app, _options) {
599
+ function inheritVue3Context(app) {
635
600
  if (app !== null && app !== void 0 && app._context) {
636
601
  return {
637
602
  appContext: app._context,
@@ -680,15 +645,55 @@ var MountVue2 = /*#__PURE__*/function (_MountBase) {
680
645
  on = _this$options.on;
681
646
  var mergedListeners = _objectSpread2(_objectSpread2({}, listeners), on);
682
647
  var context = inheritVue2Context(parent, this.options);
683
- var componentOptions = this._component;
684
- if (this._component.options) {
685
- componentOptions = this._component.options;
686
- }
648
+ var componentOptions = this._component.options || this._component;
687
649
  var ComponentConstructor = VueConstructor.extend(componentOptions);
688
650
  var instance = new ComponentConstructor({
689
651
  propsData: props || {},
690
652
  parent: parent
691
653
  });
654
+ this._injectContext(instance, context);
655
+ this._bindListeners(instance, mergedListeners);
656
+ this._interceptEmit(instance);
657
+ instance.$on('close', function (value) {
658
+ _this2._resolvePromise(value);
659
+ _this2.unmount();
660
+ });
661
+ instance._mountId = this.id;
662
+ this._vue2Instance = instance;
663
+ }
664
+ }, {
665
+ key: "_mountVM",
666
+ value: function _mountVM() {
667
+ if (!this._vue2Instance) return;
668
+ this._ensureElement();
669
+ this._appendElementToDOM();
670
+ this._vue2Instance.$mount(this.el);
671
+ if (this._vue2Instance.$el) {
672
+ this.el = this._vue2Instance.$el;
673
+ }
674
+ this.vm = this._vue2Instance;
675
+ this.mounted = true;
676
+ }
677
+ }, {
678
+ key: "_unmountVM",
679
+ value: function _unmountVM() {
680
+ if (this._vue2Instance) {
681
+ this._vue2Instance.$destroy();
682
+ this._vue2Instance = null;
683
+ }
684
+ this.vm = null;
685
+ this.mounted = false;
686
+ }
687
+ }, {
688
+ key: "_updateVM",
689
+ value: function _updateVM() {
690
+ if (this._vue2Instance && this.options.props) {
691
+ Object.assign(this._vue2Instance.$props, this.options.props);
692
+ }
693
+ }
694
+ }, {
695
+ key: "_injectContext",
696
+ value: function _injectContext(instance, context) {
692
697
  if (context.router) {
693
698
  Object.defineProperty(instance, '$router', {
694
699
  get: function get() {
@@ -713,7 +718,11 @@ var MountVue2 = /*#__PURE__*/function (_MountBase) {
713
718
  configurable: true
714
719
  });
715
720
  }
716
- Object.entries(mergedListeners).forEach(function (_ref) {
721
+ }
722
+ }, {
723
+ key: "_bindListeners",
724
+ value: function _bindListeners(instance, listeners) {
725
+ Object.entries(listeners).forEach(function (_ref) {
717
726
  var _ref2 = _slicedToArray(_ref, 2),
718
727
  event = _ref2[0],
719
728
  handler = _ref2[1];
@@ -725,51 +734,20 @@ var MountVue2 = /*#__PURE__*/function (_MountBase) {
725
734
  instance.$on(event, handler);
726
735
  }
727
736
  });
737
+ }
738
+ }, {
739
+ key: "_interceptEmit",
740
+ value: function _interceptEmit(instance) {
741
+ var _this3 = this;
728
742
  var originalEmit = instance.$emit.bind(instance);
729
743
  instance.$emit = function (event) {
730
- var _this2$_eventEmitter;
744
+ var _this3$_eventEmitter;
731
745
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
732
746
  args[_key - 1] = arguments[_key];
733
747
  }
734
- (_this2$_eventEmitter = _this2._eventEmitter).emit.apply(_this2$_eventEmitter, [event].concat(args));
748
+ (_this3$_eventEmitter = _this3._eventEmitter).emit.apply(_this3$_eventEmitter, [event].concat(args));
735
749
  return originalEmit.apply(void 0, [event].concat(args));
736
750
  };
737
- instance.$on('close', function (value) {
738
- _this2._resolvePromise(value);
739
- _this2.unmount();
740
- });
741
- instance._mountId = this.id;
742
- this._vue2Instance = instance;
743
- }
744
- }, {
745
- key: "_mountVM",
746
- value: function _mountVM() {
747
- if (!this._vue2Instance) return;
748
- this._ensureElement();
749
- this._appendElementToDOM();
750
- this._vue2Instance.$mount(this.el);
751
- if (this._vue2Instance.$el) {
752
- this.el = this._vue2Instance.$el;
753
- }
754
- this.vm = this._vue2Instance;
755
- this.mounted = true;
756
- }
757
- }, {
758
- key: "_unmountVM",
759
- value: function _unmountVM() {
760
- if (this._vue2Instance) {
761
- this._vue2Instance.$destroy();
762
- this._vue2Instance = null;
763
- }
764
- this.vm = null;
765
- this.mounted = false;
766
- }
767
- }, {
768
- key: "_updateVM",
769
- value: function _updateVM() {
770
- if (this._vue2Instance && this.options.props) {
771
- Object.assign(this._vue2Instance.$props, this.options.props);
772
- }
773
751
  }
774
752
  }]);
775
753
  }(MountBase);
@@ -840,23 +818,11 @@ var MountVue3 = /*#__PURE__*/function (_MountBase) {
840
818
  this._ensureElement();
841
819
  this._appendElementToDOM();
842
820
  getRender().then(function (render) {
843
- if (render && _this3._vNode && _this3.el) {
844
- var _this3$_vNode$compone, _this3$_vNode$compone2;
845
- render(_this3._vNode, _this3.el);
846
- _this3.vm = (_this3$_vNode$compone = (_this3$_vNode$compone2 = _this3._vNode.component) === null || _this3$_vNode$compone2 === void 0 ? void 0 : _this3$_vNode$compone2.proxy) !== null && _this3$_vNode$compone !== void 0 ? _this3$_vNode$compone : null;
847
- var component = _this3._vNode.component;
848
- if (component) {
849
- var originalEmit = component.emit;
850
- component.emit = function (event) {
851
- var _this3$_eventEmitter;
852
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
853
- args[_key - 1] = arguments[_key];
854
- }
855
- (_this3$_eventEmitter = _this3._eventEmitter).emit.apply(_this3$_eventEmitter, [event].concat(args));
856
- return originalEmit.call.apply(originalEmit, [component, event].concat(args));
857
- };
858
- }
859
- }
821
+ var _this3$_vNode$compone, _this3$_vNode$compone2;
822
+ if (!render || !_this3._vNode || !_this3.el) return;
823
+ render(_this3._vNode, _this3.el);
824
+ _this3.vm = (_this3$_vNode$compone = (_this3$_vNode$compone2 = _this3._vNode.component) === null || _this3$_vNode$compone2 === void 0 ? void 0 : _this3$_vNode$compone2.proxy) !== null && _this3$_vNode$compone !== void 0 ? _this3$_vNode$compone : null;
825
+ _this3._interceptEmit();
860
826
  });
861
827
  this.mounted = true;
862
828
  }
@@ -890,6 +856,23 @@ var MountVue3 = /*#__PURE__*/function (_MountBase) {
890
856
  });
891
857
  }
892
858
  }
859
+ }, {
860
+ key: "_interceptEmit",
861
+ value: function _interceptEmit() {
862
+ var _this$_vNode,
863
+ _this6 = this;
864
+ var component = (_this$_vNode = this._vNode) === null || _this$_vNode === void 0 ? void 0 : _this$_vNode.component;
865
+ if (!component) return;
866
+ var originalEmit = component.emit;
867
+ component.emit = function (event) {
868
+ var _this6$_eventEmitter;
869
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
870
+ args[_key - 1] = arguments[_key];
871
+ }
872
+ (_this6$_eventEmitter = _this6._eventEmitter).emit.apply(_this6$_eventEmitter, [event].concat(args));
873
+ return originalEmit.call.apply(originalEmit, [component, event].concat(args));
874
+ };
875
+ }
893
876
  }]);
894
877
  }(MountBase);
895
878
 
@@ -939,16 +922,14 @@ function useMount() {
939
922
  }
940
923
  function useSingleton() {
941
924
  var getOrCreate = function getOrCreate(key, component, options) {
942
- var existingInstances = useMount().instances.value;
943
- var existing = existingInstances.find(function (i) {
944
- return i.id === key || i.options.singleton === key;
945
- });
925
+ var existing = getSingleton(key);
946
926
  if (existing) {
947
927
  return existing;
948
928
  }
949
929
  var instance = createMount(component, _objectSpread2(_objectSpread2({}, options), {}, {
950
930
  singleton: key
951
931
  }));
932
+ setSingleton(key, instance);
952
933
  instance.show();
953
934
  return instance;
954
935
  };
@@ -999,7 +980,6 @@ exports.MountBase = MountBase;
999
980
  exports.MountPlugin = MountPlugin;
1000
981
  exports.MountVue2 = MountVue2;
1001
982
  exports.MountVue3 = MountVue3;
1002
- exports.addClass = addClass;
1003
983
  exports.appendTo = appendTo;
1004
984
  exports.capitalize = capitalize;
1005
985
  exports.clearSingletons = clearSingletons;
@@ -1014,7 +994,6 @@ exports.getInstanceById = getInstanceById;
1014
994
  exports.getInstances = getInstances;
1015
995
  exports.getSingleton = getSingleton;
1016
996
  exports.getSingletonKey = getSingletonKey;
1017
- exports.getSingletonKeys = getSingletonKeys;
1018
997
  exports.globalConfig = globalConfig;
1019
998
  exports.hasSingleton = hasSingleton;
1020
999
  exports.inheritVue2Context = inheritVue2Context;
@@ -1022,10 +1001,8 @@ exports.inheritVue3Context = inheritVue3Context;
1022
1001
  exports.isBrowser = isBrowser;
1023
1002
  exports.isInDOM = isInDOM;
1024
1003
  exports.isMounted = isMounted;
1025
- exports.isNodeEnv = isNodeEnv;
1026
1004
  exports.mergeWithGlobalConfig = mergeWithGlobalConfig;
1027
1005
  exports.mount = mount;
1028
- exports.removeClass = removeClass;
1029
1006
  exports.removeElement = removeElement;
1030
1007
  exports.removeSingleton = removeSingleton;
1031
1008
  exports.resetGlobalConfig = resetGlobalConfig;
package/dist/index.d.ts CHANGED
@@ -6,8 +6,6 @@ import { Ref } from 'vue-demi';
6
6
  import type { VNode } from 'vue-demi';
7
7
  import type { VNodeProps } from 'vue-demi';
8
8
 
9
- export declare function addClass(element: Element, className: string): void;
10
-
11
9
  export { App }
12
10
 
13
11
  export { AppContext }
@@ -63,8 +61,6 @@ export declare function getSingleton(key: string | symbol): MountInstance | unde
63
61
 
64
62
  export declare function getSingletonKey(component: any, singleton?: boolean | string): string | symbol | undefined;
65
63
 
66
- export declare function getSingletonKeys(): (string | symbol)[];
67
-
68
64
  export declare interface GlobalConfig extends Partial<MountOptions> {
69
65
  zIndex?: number;
70
66
  container?: string | Element | null;
@@ -79,7 +75,7 @@ export declare function hasSingleton(key: string | symbol): boolean;
79
75
 
80
76
  export declare function inheritVue2Context(parent: any, options: MountOptions): ContextOptions;
81
77
 
82
- export declare function inheritVue3Context(app: App | undefined, _options?: MountOptions): {
78
+ export declare function inheritVue3Context(app: App | undefined): {
83
79
  appContext?: App['_context'];
84
80
  provides?: Record<string, unknown>;
85
81
  };
@@ -90,8 +86,6 @@ export declare function isInDOM(element: Element): boolean;
90
86
 
91
87
  export declare function isMounted(id: string): boolean;
92
88
 
93
- export declare function isNodeEnv(): boolean;
94
-
95
89
  export declare interface KeepAliveOptions {
96
90
  enabled?: boolean;
97
91
  include?: string | RegExp | string[];
@@ -216,6 +210,9 @@ export declare class MountVue2 extends MountBase {
216
210
  protected _mountVM(): void;
217
211
  protected _unmountVM(): void;
218
212
  protected _updateVM(): void;
213
+ private _injectContext;
214
+ private _bindListeners;
215
+ private _interceptEmit;
219
216
  }
220
217
 
221
218
  export declare class MountVue3 extends MountBase {
@@ -226,12 +223,11 @@ export declare class MountVue3 extends MountBase {
226
223
  protected _mountVM(): void;
227
224
  protected _unmountVM(): void;
228
225
  protected _updateVM(): void;
226
+ private _interceptEmit;
229
227
  }
230
228
 
231
229
  export { Ref }
232
230
 
233
- export declare function removeClass(element: Element, className: string): void;
234
-
235
231
  export declare function removeElement(element: Element): void;
236
232
 
237
233
  export declare function removeSingleton(key: string | symbol): void;