@tmagic/editor 1.0.0-rc.1 → 1.0.0-rc.4

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 (69) hide show
  1. package/coverage/clover.xml +476 -443
  2. package/coverage/coverage-final.json +10 -10
  3. package/coverage/lcov-report/index.html +55 -55
  4. package/coverage/lcov-report/src/Editor.vue.html +36 -9
  5. package/coverage/lcov-report/src/components/ContentMenu.vue.html +11 -11
  6. package/coverage/lcov-report/src/components/Icon.vue.html +2 -2
  7. package/coverage/lcov-report/src/components/ScrollViewer.vue.html +1 -1
  8. package/coverage/lcov-report/src/components/ToolButton.vue.html +25 -25
  9. package/coverage/lcov-report/src/components/index.html +5 -5
  10. package/coverage/lcov-report/src/index.html +14 -14
  11. package/coverage/lcov-report/src/layouts/AddPageBox.vue.html +1 -1
  12. package/coverage/lcov-report/src/layouts/Framework.vue.html +48 -9
  13. package/coverage/lcov-report/src/layouts/NavMenu.vue.html +1 -1
  14. package/coverage/lcov-report/src/layouts/PropsPanel.vue.html +2 -2
  15. package/coverage/lcov-report/src/layouts/Resizer.vue.html +1 -1
  16. package/coverage/lcov-report/src/layouts/index.html +15 -15
  17. package/coverage/lcov-report/src/layouts/sidebar/ComponentListPanel.vue.html +1 -1
  18. package/coverage/lcov-report/src/layouts/sidebar/LayerMenu.vue.html +17 -17
  19. package/coverage/lcov-report/src/layouts/sidebar/LayerPanel.vue.html +1 -1
  20. package/coverage/lcov-report/src/layouts/sidebar/Sidebar.vue.html +1 -1
  21. package/coverage/lcov-report/src/layouts/sidebar/TabPane.vue.html +2 -2
  22. package/coverage/lcov-report/src/layouts/sidebar/index.html +19 -19
  23. package/coverage/lcov-report/src/layouts/workspace/PageBar.vue.html +1 -1
  24. package/coverage/lcov-report/src/layouts/workspace/Stage.vue.html +13 -4
  25. package/coverage/lcov-report/src/layouts/workspace/ViewerMenu.vue.html +69 -33
  26. package/coverage/lcov-report/src/layouts/workspace/Workspace.vue.html +73 -10
  27. package/coverage/lcov-report/src/layouts/workspace/index.html +32 -32
  28. package/coverage/lcov-report/src/services/BaseService.ts.html +2 -2
  29. package/coverage/lcov-report/src/services/componentList.ts.html +1 -1
  30. package/coverage/lcov-report/src/services/editor.ts.html +100 -10
  31. package/coverage/lcov-report/src/services/events.ts.html +1 -1
  32. package/coverage/lcov-report/src/services/history.ts.html +1 -1
  33. package/coverage/lcov-report/src/services/index.html +15 -15
  34. package/coverage/lcov-report/src/services/props.ts.html +1 -1
  35. package/coverage/lcov-report/src/services/ui.ts.html +1 -1
  36. package/coverage/lcov-report/src/type.ts.html +1 -1
  37. package/coverage/lcov-report/src/utils/compose.ts.html +1 -1
  38. package/coverage/lcov-report/src/utils/config.ts.html +1 -1
  39. package/coverage/lcov-report/src/utils/editor.ts.html +1 -1
  40. package/coverage/lcov-report/src/utils/index.html +1 -1
  41. package/coverage/lcov-report/src/utils/index.ts.html +1 -1
  42. package/coverage/lcov-report/src/utils/logger.ts.html +1 -1
  43. package/coverage/lcov-report/src/utils/props.ts.html +1 -1
  44. package/coverage/lcov-report/src/utils/scroll-viewer.ts.html +1 -1
  45. package/coverage/lcov-report/src/utils/undo-redo.ts.html +1 -1
  46. package/coverage/lcov.info +1203 -1065
  47. package/dist/style.css +3 -3
  48. package/dist/tmagic-editor.es.js +86 -1233
  49. package/dist/tmagic-editor.es.js.map +1 -1
  50. package/dist/tmagic-editor.umd.js +87 -1234
  51. package/dist/tmagic-editor.umd.js.map +1 -1
  52. package/dist/types/src/Editor.vue.d.ts +14 -0
  53. package/dist/types/src/layouts/Framework.vue.d.ts +15 -3
  54. package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +5 -1
  55. package/dist/types/src/services/BaseService.d.ts +1 -1
  56. package/package.json +16 -8
  57. package/src/Editor.vue +10 -1
  58. package/src/components/ContentMenu.vue +1 -1
  59. package/src/layouts/CodeEditor.vue +1 -4
  60. package/src/layouts/Framework.vue +14 -1
  61. package/src/layouts/PropsPanel.vue +1 -1
  62. package/src/layouts/sidebar/TabPane.vue +1 -1
  63. package/src/layouts/workspace/Stage.vue +3 -0
  64. package/src/layouts/workspace/ViewerMenu.vue +14 -2
  65. package/src/layouts/workspace/Workspace.vue +21 -0
  66. package/src/services/BaseService.ts +1 -1
  67. package/src/services/editor.ts +31 -1
  68. package/src/theme/props-panel.scss +6 -4
  69. package/src/utils/polyfills.ts +5 -19
@@ -1,19 +1,23 @@
1
- import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, ref, watchEffect, inject, markRaw, createElementBlock, createVNode, withCtx, withModifiers, createCommentVNode, createTextVNode, toDisplayString, watch, onMounted, onUnmounted, reactive, toRaw, createElementVNode, renderSlot, Fragment, normalizeClass, resolveDynamicComponent, renderList, normalizeProps, mergeProps, getCurrentInstance, nextTick, withDirectives, Teleport, vShow, toHandlers, createSlots, provide } from 'vue';
1
+ import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, ref, watchEffect, inject, markRaw, createElementBlock, createVNode, withCtx, withModifiers, createCommentVNode, createTextVNode, toDisplayString, watch, onMounted, onUnmounted, reactive, toRaw, createElementVNode, renderSlot, Fragment, normalizeClass, resolveDynamicComponent, renderList, normalizeProps, mergeProps, getCurrentInstance, nextTick, Teleport, toHandlers, createSlots, provide } from 'vue';
2
2
  import serialize from 'serialize-javascript';
3
3
  import { Delete, Pointer, Close, Plus, Edit, ArrowDown, Grid, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Files, DocumentCopy, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons';
4
4
  import { throttle, cloneDeep, mergeWith, random } from 'lodash-es';
5
5
  import * as monaco from 'monaco-editor';
6
6
  import { NodeType } from '@tmagic/schema';
7
7
  import { toLine, isPop, getNodePath, isNumber, isPage } from '@tmagic/utils';
8
- import { EventEmitter as EventEmitter$2 } from 'events';
8
+ import { EventEmitter } from 'events';
9
9
  import { DEFAULT_EVENTS, DEFAULT_METHODS } from '@tmagic/core';
10
+ import Gesto from 'gesto';
10
11
  import { ElMessage } from 'element-plus';
11
12
  import KeyController from 'keycon';
12
13
  import StageCore from '@tmagic/stage';
13
14
 
14
- if (typeof window.global === "undefined") {
15
+ if (typeof global === "undefined") {
15
16
  window.global = window;
16
17
  }
18
+ if (typeof globalThis === "undefined") {
19
+ window.globalThis = window;
20
+ }
17
21
 
18
22
  var _export_sfc = (sfc, props) => {
19
23
  const target = sfc.__vccOpts || sfc;
@@ -310,11 +314,7 @@ const _sfc_main$j = defineComponent({
310
314
  const options = {
311
315
  value: values.value,
312
316
  language: props.language,
313
- tabSize: 2,
314
317
  theme: "vs-dark",
315
- fontFamily: 'dm, Menlo, Monaco, "Courier New", monospace',
316
- fontSize: 14,
317
- formatOnPaste: true,
318
318
  ...props.options
319
319
  };
320
320
  if (props.type === "diff") {
@@ -328,6 +328,7 @@ const _sfc_main$j = defineComponent({
328
328
  codeEditor.value.addEventListener("keydown", (e) => {
329
329
  if (e.keyCode === 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
330
330
  e.preventDefault();
331
+ e.stopPropagation();
331
332
  emit("save", getEditorValue());
332
333
  }
333
334
  });
@@ -483,7 +484,7 @@ const doAction = async (args, scope, sourceMethod, beforeMethodName, afterMethod
483
484
  throw error;
484
485
  }
485
486
  };
486
- class BaseService extends EventEmitter$2 {
487
+ class BaseService extends EventEmitter {
487
488
  constructor(methods = [], serialMethods = []) {
488
489
  super();
489
490
  this.pluginOptionsList = {};
@@ -944,6 +945,13 @@ class Editor$1 extends BaseService {
944
945
  } else {
945
946
  historyService.empty();
946
947
  }
948
+ if (node?.id) {
949
+ this.get("stage")?.renderer.runtime?.getApp?.()?.emit("editor:select", {
950
+ node,
951
+ page,
952
+ parent
953
+ }, getNodePath(node.id, this.get("root").items));
954
+ }
947
955
  this.emit("select", node);
948
956
  return node;
949
957
  }
@@ -1132,6 +1140,9 @@ class Editor$1 extends BaseService {
1132
1140
  ...position
1133
1141
  };
1134
1142
  }
1143
+ if (isPage(config)) {
1144
+ config.name = generatePageNameByApp(this.get("root"));
1145
+ }
1135
1146
  return await this.add(config);
1136
1147
  }
1137
1148
  async alignCenter(config2) {
@@ -1141,7 +1152,17 @@ class Editor$1 extends BaseService {
1141
1152
  if (layout === Layout.RELATIVE) {
1142
1153
  return;
1143
1154
  }
1144
- if (parent.style?.width && node.style?.width) {
1155
+ if (!node.style)
1156
+ return;
1157
+ const stage = this.get("stage");
1158
+ const doc = stage?.renderer.contentWindow?.document;
1159
+ if (doc) {
1160
+ const parentEl = doc.getElementById(`${parent.id}`);
1161
+ const el = doc.getElementById(`${node.id}`);
1162
+ if (parentEl && el) {
1163
+ node.style.left = (parentEl.clientWidth - el.clientWidth) / 2;
1164
+ }
1165
+ } else if (parent.style && isNumber(parent.style?.width) && isNumber(node.style?.width)) {
1145
1166
  node.style.left = (parent.style.width - node.style.width) / 2;
1146
1167
  }
1147
1168
  await this.update(node);
@@ -1553,1215 +1574,6 @@ function _sfc_render$i(_ctx, _cache, $props, $setup, $data, $options) {
1553
1574
  }
1554
1575
  var AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["render", _sfc_render$i]]);
1555
1576
 
1556
- /*
1557
- Copyright (c) 2018 Daybrush
1558
- @name: @daybrush/utils
1559
- license: MIT
1560
- author: Daybrush
1561
- repository: https://github.com/daybrush/utils
1562
- @version 1.6.0
1563
- */
1564
- /**
1565
- * get string "object"
1566
- * @memberof Consts
1567
- * @example
1568
- import {OBJECT} from "@daybrush/utils";
1569
-
1570
- console.log(OBJECT); // "object"
1571
- */
1572
-
1573
- var OBJECT = "object";
1574
- /**
1575
- * Check the type that the value is object.
1576
- * @memberof Utils
1577
- * @param {string} value - Value to check the type
1578
- * @return {} true if the type is correct, false otherwise
1579
- * @example
1580
- import {isObject} from "@daybrush/utils";
1581
-
1582
- console.log(isObject({})); // true
1583
- console.log(isObject(undefined)); // false
1584
- console.log(isObject("")); // false
1585
- console.log(isObject(null)); // false
1586
- */
1587
-
1588
- function isObject(value) {
1589
- return value && typeof value === OBJECT;
1590
- }
1591
- /**
1592
- * Date.now() method
1593
- * @memberof CrossBrowser
1594
- * @return {number} milliseconds
1595
- * @example
1596
- import {now} from "@daybrush/utils";
1597
-
1598
- console.log(now()); // 12121324241(milliseconds)
1599
- */
1600
-
1601
- function now() {
1602
- return Date.now ? Date.now() : new Date().getTime();
1603
- }
1604
- /**
1605
- * Returns the index of the first element in the array that satisfies the provided testing function.
1606
- * @function
1607
- * @memberof CrossBrowser
1608
- * @param - The array `findIndex` was called upon.
1609
- * @param - A function to execute on each value in the array until the function returns true, indicating that the satisfying element was found.
1610
- * @param - Returns defaultIndex if not found by the function.
1611
- * @example
1612
- import { findIndex } from "@daybrush/utils";
1613
-
1614
- findIndex([{a: 1}, {a: 2}, {a: 3}, {a: 4}], ({ a }) => a === 2); // 1
1615
- */
1616
-
1617
- function findIndex(arr, callback, defaultIndex) {
1618
- if (defaultIndex === void 0) {
1619
- defaultIndex = -1;
1620
- }
1621
-
1622
- var length = arr.length;
1623
-
1624
- for (var i = 0; i < length; ++i) {
1625
- if (callback(arr[i], i, arr)) {
1626
- return i;
1627
- }
1628
- }
1629
-
1630
- return defaultIndex;
1631
- }
1632
- /**
1633
- * Sets up a function that will be called whenever the specified event is delivered to the target
1634
- * @memberof DOM
1635
- * @param - event target
1636
- * @param - A case-sensitive string representing the event type to listen for.
1637
- * @param - The object which receives a notification (an object that implements the Event interface) when an event of the specified type occurs
1638
- * @param - An options object that specifies characteristics about the event listener.
1639
- * @example
1640
- import {addEvent} from "@daybrush/utils";
1641
-
1642
- addEvent(el, "click", e => {
1643
- console.log(e);
1644
- });
1645
- */
1646
-
1647
- function addEvent(el, type, listener, options) {
1648
- el.addEventListener(type, listener, options);
1649
- }
1650
- /**
1651
- * removes from the EventTarget an event listener previously registered with EventTarget.addEventListener()
1652
- * @memberof DOM
1653
- * @param - event target
1654
- * @param - A case-sensitive string representing the event type to listen for.
1655
- * @param - The EventListener function of the event handler to remove from the event target.
1656
- * @param - An options object that specifies characteristics about the event listener.
1657
- * @example
1658
- import {addEvent, removeEvent} from "@daybrush/utils";
1659
- const listener = e => {
1660
- console.log(e);
1661
- };
1662
- addEvent(el, "click", listener);
1663
- removeEvent(el, "click", listener);
1664
- */
1665
-
1666
- function removeEvent(el, type, listener, options) {
1667
- el.removeEventListener(type, listener, options);
1668
- }
1669
-
1670
- /*
1671
- Copyright (c) 2019 Daybrush
1672
- name: @scena/event-emitter
1673
- license: MIT
1674
- author: Daybrush
1675
- repository: git+https://github.com/daybrush/gesture.git
1676
- version: 1.0.5
1677
- */
1678
-
1679
- /*! *****************************************************************************
1680
- Copyright (c) Microsoft Corporation.
1681
-
1682
- Permission to use, copy, modify, and/or distribute this software for any
1683
- purpose with or without fee is hereby granted.
1684
-
1685
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1686
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1687
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1688
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1689
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1690
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1691
- PERFORMANCE OF THIS SOFTWARE.
1692
- ***************************************************************************** */
1693
- var __assign$1 = function () {
1694
- __assign$1 = Object.assign || function __assign(t) {
1695
- for (var s, i = 1, n = arguments.length; i < n; i++) {
1696
- s = arguments[i];
1697
-
1698
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
1699
- }
1700
-
1701
- return t;
1702
- };
1703
-
1704
- return __assign$1.apply(this, arguments);
1705
- };
1706
- function __spreadArrays() {
1707
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
1708
-
1709
- for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j];
1710
-
1711
- return r;
1712
- }
1713
-
1714
- /**
1715
- * Implement EventEmitter on object or component.
1716
- */
1717
-
1718
- var EventEmitter =
1719
- /*#__PURE__*/
1720
- function () {
1721
- function EventEmitter() {
1722
- this._events = {};
1723
- }
1724
- /**
1725
- * Add a listener to the registered event.
1726
- * @param - Name of the event to be added
1727
- * @param - listener function of the event to be added
1728
- * @example
1729
- * import EventEmitter from "@scena/event-emitter";
1730
- * cosnt emitter = new EventEmitter();
1731
- *
1732
- * // Add listener in "a" event
1733
- * emitter.on("a", () => {
1734
- * });
1735
- * // Add listeners
1736
- * emitter.on({
1737
- * a: () => {},
1738
- * b: () => {},
1739
- * });
1740
- */
1741
-
1742
-
1743
- var __proto = EventEmitter.prototype;
1744
-
1745
- __proto.on = function (eventName, listener) {
1746
- if (isObject(eventName)) {
1747
- for (var name in eventName) {
1748
- this.on(name, eventName[name]);
1749
- }
1750
- } else {
1751
- this._addEvent(eventName, listener, {});
1752
- }
1753
-
1754
- return this;
1755
- };
1756
- /**
1757
- * Remove listeners registered in the event target.
1758
- * @param - Name of the event to be removed
1759
- * @param - listener function of the event to be removed
1760
- * @example
1761
- * import EventEmitter from "@scena/event-emitter";
1762
- * cosnt emitter = new EventEmitter();
1763
- *
1764
- * // Remove all listeners.
1765
- * emitter.off();
1766
- *
1767
- * // Remove all listeners in "A" event.
1768
- * emitter.off("a");
1769
- *
1770
- *
1771
- * // Remove "listener" listener in "a" event.
1772
- * emitter.off("a", listener);
1773
- */
1774
-
1775
-
1776
- __proto.off = function (eventName, listener) {
1777
- if (!eventName) {
1778
- this._events = {};
1779
- } else if (isObject(eventName)) {
1780
- for (var name in eventName) {
1781
- this.off(name);
1782
- }
1783
- } else if (!listener) {
1784
- this._events[eventName] = [];
1785
- } else {
1786
- var events = this._events[eventName];
1787
-
1788
- if (events) {
1789
- var index = findIndex(events, function (e) {
1790
- return e.listener === listener;
1791
- });
1792
-
1793
- if (index > -1) {
1794
- events.splice(index, 1);
1795
- }
1796
- }
1797
- }
1798
-
1799
- return this;
1800
- };
1801
- /**
1802
- * Add a disposable listener and Use promise to the registered event.
1803
- * @param - Name of the event to be added
1804
- * @param - disposable listener function of the event to be added
1805
- * @example
1806
- * import EventEmitter from "@scena/event-emitter";
1807
- * cosnt emitter = new EventEmitter();
1808
- *
1809
- * // Add a disposable listener in "a" event
1810
- * emitter.once("a", () => {
1811
- * });
1812
- *
1813
- * // Use Promise
1814
- * emitter.once("a").then(e => {
1815
- * });
1816
- */
1817
-
1818
-
1819
- __proto.once = function (eventName, listener) {
1820
- var _this = this;
1821
-
1822
- if (listener) {
1823
- this._addEvent(eventName, listener, {
1824
- once: true
1825
- });
1826
- }
1827
-
1828
- return new Promise(function (resolve) {
1829
- _this._addEvent(eventName, resolve, {
1830
- once: true
1831
- });
1832
- });
1833
- };
1834
- /**
1835
- * Fires an event to call listeners.
1836
- * @param - Event name
1837
- * @param - Event parameter
1838
- * @return If false, stop the event.
1839
- * @example
1840
- *
1841
- * import EventEmitter from "@scena/event-emitter";
1842
- *
1843
- *
1844
- * const emitter = new EventEmitter();
1845
- *
1846
- * emitter.on("a", e => {
1847
- * });
1848
- *
1849
- *
1850
- * emitter.emit("a", {
1851
- * a: 1,
1852
- * });
1853
- */
1854
-
1855
-
1856
- __proto.emit = function (eventName, param) {
1857
- var _this = this;
1858
-
1859
- if (param === void 0) {
1860
- param = {};
1861
- }
1862
-
1863
- var events = this._events[eventName];
1864
-
1865
- if (!eventName || !events) {
1866
- return true;
1867
- }
1868
-
1869
- var isStop = false;
1870
- param.eventType = eventName;
1871
-
1872
- param.stop = function () {
1873
- isStop = true;
1874
- };
1875
-
1876
- param.currentTarget = this;
1877
-
1878
- __spreadArrays(events).forEach(function (info) {
1879
- info.listener(param);
1880
-
1881
- if (info.once) {
1882
- _this.off(eventName, info.listener);
1883
- }
1884
- });
1885
-
1886
- return !isStop;
1887
- };
1888
- /**
1889
- * Fires an event to call listeners.
1890
- * @param - Event name
1891
- * @param - Event parameter
1892
- * @return If false, stop the event.
1893
- * @example
1894
- *
1895
- * import EventEmitter from "@scena/event-emitter";
1896
- *
1897
- *
1898
- * const emitter = new EventEmitter();
1899
- *
1900
- * emitter.on("a", e => {
1901
- * });
1902
- *
1903
- *
1904
- * emitter.emit("a", {
1905
- * a: 1,
1906
- * });
1907
- */
1908
-
1909
- /**
1910
- * Fires an event to call listeners.
1911
- * @param - Event name
1912
- * @param - Event parameter
1913
- * @return If false, stop the event.
1914
- * @example
1915
- *
1916
- * import EventEmitter from "@scena/event-emitter";
1917
- *
1918
- *
1919
- * const emitter = new EventEmitter();
1920
- *
1921
- * emitter.on("a", e => {
1922
- * });
1923
- *
1924
- * // emit
1925
- * emitter.trigger("a", {
1926
- * a: 1,
1927
- * });
1928
- */
1929
-
1930
-
1931
- __proto.trigger = function (eventName, param) {
1932
- if (param === void 0) {
1933
- param = {};
1934
- }
1935
-
1936
- return this.emit(eventName, param);
1937
- };
1938
-
1939
- __proto._addEvent = function (eventName, listener, options) {
1940
- var events = this._events;
1941
- events[eventName] = events[eventName] || [];
1942
- var listeners = events[eventName];
1943
- listeners.push(__assign$1({
1944
- listener: listener
1945
- }, options));
1946
- };
1947
-
1948
- return EventEmitter;
1949
- }();
1950
-
1951
- var EventEmitter$1 = EventEmitter;
1952
-
1953
- /*
1954
- Copyright (c) 2019 Daybrush
1955
- name: gesto
1956
- license: MIT
1957
- author: Daybrush
1958
- repository: git+https://github.com/daybrush/gesto.git
1959
- version: 1.7.0
1960
- */
1961
-
1962
- /*! *****************************************************************************
1963
- Copyright (c) Microsoft Corporation. All rights reserved.
1964
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
1965
- this file except in compliance with the License. You may obtain a copy of the
1966
- License at http://www.apache.org/licenses/LICENSE-2.0
1967
-
1968
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1969
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
1970
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
1971
- MERCHANTABLITY OR NON-INFRINGEMENT.
1972
-
1973
- See the Apache Version 2.0 License for specific language governing permissions
1974
- and limitations under the License.
1975
- ***************************************************************************** */
1976
-
1977
- /* global Reflect, Promise */
1978
- var extendStatics = function (d, b) {
1979
- extendStatics = Object.setPrototypeOf || {
1980
- __proto__: []
1981
- } instanceof Array && function (d, b) {
1982
- d.__proto__ = b;
1983
- } || function (d, b) {
1984
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
1985
- };
1986
-
1987
- return extendStatics(d, b);
1988
- };
1989
-
1990
- function __extends(d, b) {
1991
- extendStatics(d, b);
1992
-
1993
- function __() {
1994
- this.constructor = d;
1995
- }
1996
-
1997
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1998
- }
1999
- var __assign = function () {
2000
- __assign = Object.assign || function __assign(t) {
2001
- for (var s, i = 1, n = arguments.length; i < n; i++) {
2002
- s = arguments[i];
2003
-
2004
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
2005
- }
2006
-
2007
- return t;
2008
- };
2009
-
2010
- return __assign.apply(this, arguments);
2011
- };
2012
-
2013
- function getRad(pos1, pos2) {
2014
- var distX = pos2[0] - pos1[0];
2015
- var distY = pos2[1] - pos1[1];
2016
- var rad = Math.atan2(distY, distX);
2017
- return rad >= 0 ? rad : rad + Math.PI * 2;
2018
- }
2019
- function getRotatiion(touches) {
2020
- return getRad([touches[0].clientX, touches[0].clientY], [touches[1].clientX, touches[1].clientY]) / Math.PI * 180;
2021
- }
2022
- function isMultiTouch(e) {
2023
- return e.touches && e.touches.length >= 2;
2024
- }
2025
- function getEventClients(e) {
2026
- if (e.touches) {
2027
- return getClients(e.touches);
2028
- } else {
2029
- return [getClient(e)];
2030
- }
2031
- }
2032
- function getPosition(clients, prevClients, startClients) {
2033
- var length = startClients.length;
2034
-
2035
- var _a = getAverageClient(clients, length),
2036
- clientX = _a.clientX,
2037
- clientY = _a.clientY,
2038
- originalClientX = _a.originalClientX,
2039
- originalClientY = _a.originalClientY;
2040
-
2041
- var _b = getAverageClient(prevClients, length),
2042
- prevX = _b.clientX,
2043
- prevY = _b.clientY;
2044
-
2045
- var _c = getAverageClient(startClients, length),
2046
- startX = _c.clientX,
2047
- startY = _c.clientY;
2048
-
2049
- var deltaX = clientX - prevX;
2050
- var deltaY = clientY - prevY;
2051
- var distX = clientX - startX;
2052
- var distY = clientY - startY;
2053
- return {
2054
- clientX: originalClientX,
2055
- clientY: originalClientY,
2056
- deltaX: deltaX,
2057
- deltaY: deltaY,
2058
- distX: distX,
2059
- distY: distY
2060
- };
2061
- }
2062
- function getDist(clients) {
2063
- return Math.sqrt(Math.pow(clients[0].clientX - clients[1].clientX, 2) + Math.pow(clients[0].clientY - clients[1].clientY, 2));
2064
- }
2065
- function getClients(touches) {
2066
- var length = Math.min(touches.length, 2);
2067
- var clients = [];
2068
-
2069
- for (var i = 0; i < length; ++i) {
2070
- clients.push(getClient(touches[i]));
2071
- }
2072
-
2073
- return clients;
2074
- }
2075
- function getClient(e) {
2076
- return {
2077
- clientX: e.clientX,
2078
- clientY: e.clientY
2079
- };
2080
- }
2081
- function getAverageClient(clients, length) {
2082
- if (length === void 0) {
2083
- length = clients.length;
2084
- }
2085
-
2086
- var sumClient = {
2087
- clientX: 0,
2088
- clientY: 0,
2089
- originalClientX: 0,
2090
- originalClientY: 0
2091
- };
2092
-
2093
- for (var i = 0; i < length; ++i) {
2094
- var client = clients[i];
2095
- sumClient.originalClientX += "originalClientX" in client ? client.originalClientX : client.clientX;
2096
- sumClient.originalClientY += "originalClientY" in client ? client.originalClientY : client.clientY;
2097
- sumClient.clientX += client.clientX;
2098
- sumClient.clientY += client.clientY;
2099
- }
2100
-
2101
- if (!length) {
2102
- return sumClient;
2103
- }
2104
-
2105
- return {
2106
- clientX: sumClient.clientX / length,
2107
- clientY: sumClient.clientY / length,
2108
- originalClientX: sumClient.originalClientX / length,
2109
- originalClientY: sumClient.originalClientY / length
2110
- };
2111
- }
2112
-
2113
- var ClientStore =
2114
- /*#__PURE__*/
2115
- function () {
2116
- function ClientStore(clients) {
2117
- this.prevClients = [];
2118
- this.startClients = [];
2119
- this.movement = 0;
2120
- this.length = 0;
2121
- this.startClients = clients;
2122
- this.prevClients = clients;
2123
- this.length = clients.length;
2124
- }
2125
-
2126
- var __proto = ClientStore.prototype;
2127
-
2128
- __proto.getAngle = function (clients) {
2129
- if (clients === void 0) {
2130
- clients = this.prevClients;
2131
- }
2132
-
2133
- return getRotatiion(clients);
2134
- };
2135
-
2136
- __proto.getRotation = function (clients) {
2137
- if (clients === void 0) {
2138
- clients = this.prevClients;
2139
- }
2140
-
2141
- return getRotatiion(clients) - getRotatiion(this.startClients);
2142
- };
2143
-
2144
- __proto.getPosition = function (clients, isAdd) {
2145
- if (clients === void 0) {
2146
- clients = this.prevClients;
2147
- }
2148
-
2149
- var position = getPosition(clients || this.prevClients, this.prevClients, this.startClients);
2150
- var deltaX = position.deltaX,
2151
- deltaY = position.deltaY;
2152
- this.movement += Math.sqrt(deltaX * deltaX + deltaY * deltaY);
2153
- this.prevClients = clients;
2154
- return position;
2155
- };
2156
-
2157
- __proto.getPositions = function (clients) {
2158
- if (clients === void 0) {
2159
- clients = this.prevClients;
2160
- }
2161
-
2162
- var prevClients = this.prevClients;
2163
- return this.startClients.map(function (startClient, i) {
2164
- return getPosition([clients[i]], [prevClients[i]], [startClient]);
2165
- });
2166
- };
2167
-
2168
- __proto.getMovement = function (clients) {
2169
- var movement = this.movement;
2170
-
2171
- if (!clients) {
2172
- return movement;
2173
- }
2174
-
2175
- var currentClient = getAverageClient(clients, this.length);
2176
- var prevClient = getAverageClient(this.prevClients, this.length);
2177
- var deltaX = currentClient.clientX - prevClient.clientX;
2178
- var deltaY = currentClient.clientY - prevClient.clientY;
2179
- return Math.sqrt(deltaX * deltaX + deltaY * deltaY) + movement;
2180
- };
2181
-
2182
- __proto.getDistance = function (clients) {
2183
- if (clients === void 0) {
2184
- clients = this.prevClients;
2185
- }
2186
-
2187
- return getDist(clients);
2188
- };
2189
-
2190
- __proto.getScale = function (clients) {
2191
- if (clients === void 0) {
2192
- clients = this.prevClients;
2193
- }
2194
-
2195
- return getDist(clients) / getDist(this.startClients);
2196
- };
2197
-
2198
- __proto.move = function (deltaX, deltaY) {
2199
- this.startClients.forEach(function (client) {
2200
- client.clientX -= deltaX;
2201
- client.clientY -= deltaY;
2202
- });
2203
- };
2204
-
2205
- return ClientStore;
2206
- }();
2207
-
2208
- var INPUT_TAGNAMES = ["textarea", "input"];
2209
- /**
2210
- * You can set up drag, pinch events in any browser.
2211
- */
2212
-
2213
- var Gesto =
2214
- /*#__PURE__*/
2215
- function (_super) {
2216
- __extends(Gesto, _super);
2217
- /**
2218
- *
2219
- */
2220
-
2221
-
2222
- function Gesto(targets, options) {
2223
- if (options === void 0) {
2224
- options = {};
2225
- }
2226
-
2227
- var _this = _super.call(this) || this;
2228
-
2229
- _this.options = {};
2230
- _this.flag = false;
2231
- _this.pinchFlag = false;
2232
- _this.datas = {};
2233
- _this.isDrag = false;
2234
- _this.isPinch = false;
2235
- _this.isMouse = false;
2236
- _this.isTouch = false;
2237
- _this.clientStores = [];
2238
- _this.targets = [];
2239
- _this.prevTime = 0;
2240
- _this.doubleFlag = false;
2241
- _this._dragFlag = false;
2242
-
2243
- _this.onDragStart = function (e, isTrusted) {
2244
- if (isTrusted === void 0) {
2245
- isTrusted = true;
2246
- }
2247
-
2248
- if (!_this.flag && e.cancelable === false) {
2249
- return;
2250
- }
2251
-
2252
- var _a = _this.options,
2253
- container = _a.container,
2254
- pinchOutside = _a.pinchOutside,
2255
- preventRightClick = _a.preventRightClick,
2256
- preventDefault = _a.preventDefault,
2257
- checkInput = _a.checkInput;
2258
- var isTouch = _this.isTouch;
2259
- var isDragStart = !_this.flag;
2260
-
2261
- if (isDragStart) {
2262
- var activeElement = document.activeElement;
2263
- var target = e.target;
2264
- var tagName = target.tagName.toLowerCase();
2265
- var hasInput = INPUT_TAGNAMES.indexOf(tagName) > -1;
2266
- var hasContentEditable = target.isContentEditable;
2267
-
2268
- if (hasInput || hasContentEditable) {
2269
- if (checkInput || activeElement === target) {
2270
- // force false or already focused.
2271
- return false;
2272
- } // no focus
2273
-
2274
-
2275
- if (activeElement && hasContentEditable && activeElement.isContentEditable && activeElement.contains(target)) {
2276
- return false;
2277
- }
2278
- } else if ((preventDefault || e.type === "touchstart") && activeElement) {
2279
- var activeTagName = activeElement.tagName;
2280
-
2281
- if (activeElement.isContentEditable || INPUT_TAGNAMES.indexOf(activeTagName) > -1) {
2282
- activeElement.blur();
2283
- }
2284
- }
2285
-
2286
- _this.clientStores = [new ClientStore(getEventClients(e))];
2287
- _this.flag = true;
2288
- _this.isDrag = false;
2289
- _this._dragFlag = true;
2290
- _this.datas = {};
2291
-
2292
- if (preventRightClick && (e.which === 3 || e.button === 2)) {
2293
- _this.initDrag();
2294
-
2295
- return false;
2296
- }
2297
-
2298
- _this.doubleFlag = now() - _this.prevTime < 200;
2299
-
2300
- var result = _this.emit("dragStart", __assign({
2301
- datas: _this.datas,
2302
- inputEvent: e,
2303
- isTrusted: isTrusted,
2304
- isDouble: _this.doubleFlag
2305
- }, _this.getCurrentStore().getPosition(), {
2306
- preventDefault: function () {
2307
- e.preventDefault();
2308
- },
2309
- preventDrag: function () {
2310
- _this._dragFlag = false;
2311
- }
2312
- }));
2313
-
2314
- if (result === false) {
2315
- _this.initDrag();
2316
- }
2317
-
2318
- _this.flag && preventDefault && e.preventDefault();
2319
- }
2320
-
2321
- if (!_this.flag) {
2322
- return false;
2323
- }
2324
-
2325
- var timer = 0;
2326
-
2327
- if (isDragStart && isTouch && pinchOutside) {
2328
- timer = setTimeout(function () {
2329
- addEvent(container, "touchstart", _this.onDragStart, {
2330
- passive: false
2331
- });
2332
- });
2333
- }
2334
-
2335
- if (!isDragStart && isTouch && pinchOutside) {
2336
- removeEvent(container, "touchstart", _this.onDragStart);
2337
- }
2338
-
2339
- if (_this.flag && isMultiTouch(e)) {
2340
- clearTimeout(timer);
2341
-
2342
- if (isDragStart && e.touches.length !== e.changedTouches.length) {
2343
- return;
2344
- }
2345
-
2346
- if (!_this.pinchFlag) {
2347
- _this.onPinchStart(e);
2348
- }
2349
- }
2350
- };
2351
-
2352
- _this.onDrag = function (e, isScroll) {
2353
- if (!_this.flag) {
2354
- return;
2355
- }
2356
-
2357
- var clients = getEventClients(e);
2358
-
2359
- var result = _this.moveClients(clients, e, false);
2360
-
2361
- if (_this._dragFlag) {
2362
- if (_this.pinchFlag || result.deltaX || result.deltaY) {
2363
- var dragResult = _this.emit("drag", __assign({}, result, {
2364
- isScroll: !!isScroll,
2365
- inputEvent: e
2366
- }));
2367
-
2368
- if (dragResult === false) {
2369
- _this.stop();
2370
-
2371
- return;
2372
- }
2373
- }
2374
-
2375
- if (_this.pinchFlag) {
2376
- _this.onPinch(e, clients);
2377
- }
2378
- }
2379
-
2380
- _this.getCurrentStore().getPosition(clients, true);
2381
- };
2382
-
2383
- _this.onDragEnd = function (e) {
2384
- if (!_this.flag) {
2385
- return;
2386
- }
2387
-
2388
- var _a = _this.options,
2389
- pinchOutside = _a.pinchOutside,
2390
- container = _a.container;
2391
-
2392
- if (_this.isTouch && pinchOutside) {
2393
- removeEvent(container, "touchstart", _this.onDragStart);
2394
- }
2395
-
2396
- _this.flag = false;
2397
-
2398
- var position = _this._getPosition();
2399
-
2400
- var currentTime = now();
2401
- var isDouble = !_this.isDrag && _this.doubleFlag;
2402
- _this.prevTime = _this.isDrag || isDouble ? 0 : currentTime;
2403
-
2404
- _this.emit("dragEnd", __assign({
2405
- datas: _this.datas,
2406
- isDouble: isDouble,
2407
- isDrag: _this.isDrag,
2408
- isClick: !_this.isDrag,
2409
- inputEvent: e
2410
- }, position));
2411
-
2412
- if (_this.pinchFlag) {
2413
- _this.onPinchEnd(e);
2414
- }
2415
-
2416
- _this.clientStores = [];
2417
- };
2418
-
2419
- _this.onBlur = function () {
2420
- _this.onDragEnd();
2421
- };
2422
-
2423
- var elements = [].concat(targets);
2424
- _this.options = __assign({
2425
- checkInput: false,
2426
- container: elements.length > 1 ? window : elements[0],
2427
- preventRightClick: true,
2428
- preventDefault: true,
2429
- checkWindowBlur: false,
2430
- pinchThreshold: 0,
2431
- events: ["touch", "mouse"]
2432
- }, options);
2433
- var _a = _this.options,
2434
- container = _a.container,
2435
- events = _a.events,
2436
- checkWindowBlur = _a.checkWindowBlur;
2437
- _this.isTouch = events.indexOf("touch") > -1;
2438
- _this.isMouse = events.indexOf("mouse") > -1;
2439
- _this.targets = elements;
2440
-
2441
- if (_this.isMouse) {
2442
- elements.forEach(function (el) {
2443
- addEvent(el, "mousedown", _this.onDragStart);
2444
- });
2445
- addEvent(container, "mousemove", _this.onDrag);
2446
- addEvent(container, "mouseup", _this.onDragEnd);
2447
- addEvent(container, "contextmenu", _this.onDragEnd);
2448
- }
2449
-
2450
- if (checkWindowBlur) {
2451
- addEvent(window, "blur", _this.onBlur);
2452
- }
2453
-
2454
- if (_this.isTouch) {
2455
- var passive_1 = {
2456
- passive: false
2457
- };
2458
- elements.forEach(function (el) {
2459
- addEvent(el, "touchstart", _this.onDragStart, passive_1);
2460
- });
2461
- addEvent(container, "touchmove", _this.onDrag, passive_1);
2462
- addEvent(container, "touchend", _this.onDragEnd, passive_1);
2463
- addEvent(container, "touchcancel", _this.onDragEnd, passive_1);
2464
- }
2465
-
2466
- return _this;
2467
- }
2468
- /**
2469
- * Stop Gesto's drag events.
2470
- */
2471
-
2472
-
2473
- var __proto = Gesto.prototype;
2474
-
2475
- __proto.stop = function () {
2476
- this.isDrag = false;
2477
- this.flag = false;
2478
- this.clientStores = [];
2479
- this.datas = {};
2480
- };
2481
- /**
2482
- * The total moved distance
2483
- */
2484
-
2485
-
2486
- __proto.getMovement = function (clients) {
2487
- return this.getCurrentStore().getMovement(clients) + this.clientStores.slice(1).reduce(function (prev, cur) {
2488
- return prev + cur.movement;
2489
- }, 0);
2490
- };
2491
- /**
2492
- * Whether to drag
2493
- */
2494
-
2495
-
2496
- __proto.isDragging = function () {
2497
- return this.isDrag;
2498
- };
2499
- /**
2500
- * Whether to start drag
2501
- */
2502
-
2503
-
2504
- __proto.isFlag = function () {
2505
- return this.flag;
2506
- };
2507
- /**
2508
- * Whether to start pinch
2509
- */
2510
-
2511
-
2512
- __proto.isPinchFlag = function () {
2513
- return this.pinchFlag;
2514
- };
2515
- /**
2516
- * Whether to start double click
2517
- */
2518
-
2519
-
2520
- __proto.isDoubleFlag = function () {
2521
- return this.doubleFlag;
2522
- };
2523
- /**
2524
- * Whether to pinch
2525
- */
2526
-
2527
-
2528
- __proto.isPinching = function () {
2529
- return this.isPinch;
2530
- };
2531
- /**
2532
- * If a scroll event occurs, it is corrected by the scroll distance.
2533
- */
2534
-
2535
-
2536
- __proto.scrollBy = function (deltaX, deltaY, e, isCallDrag) {
2537
- if (isCallDrag === void 0) {
2538
- isCallDrag = true;
2539
- }
2540
-
2541
- if (!this.flag) {
2542
- return;
2543
- }
2544
-
2545
- this.clientStores[0].move(deltaX, deltaY);
2546
- isCallDrag && this.onDrag(e, true);
2547
- };
2548
- /**
2549
- * Create a virtual drag event.
2550
- */
2551
-
2552
-
2553
- __proto.move = function (_a, inputEvent) {
2554
- var deltaX = _a[0],
2555
- deltaY = _a[1];
2556
- var store = this.getCurrentStore();
2557
- var nextClients = store.prevClients;
2558
- return this.moveClients(nextClients.map(function (_a) {
2559
- var clientX = _a.clientX,
2560
- clientY = _a.clientY;
2561
- return {
2562
- clientX: clientX + deltaX,
2563
- clientY: clientY + deltaY,
2564
- originalClientX: clientX,
2565
- originalClientY: clientY
2566
- };
2567
- }), inputEvent, true);
2568
- };
2569
- /**
2570
- * The dragStart event is triggered by an external event.
2571
- */
2572
-
2573
-
2574
- __proto.triggerDragStart = function (e) {
2575
- this.onDragStart(e, false);
2576
- };
2577
- /**
2578
- * Set the event data while dragging.
2579
- */
2580
-
2581
-
2582
- __proto.setEventDatas = function (datas) {
2583
- var currentDatas = this.datas;
2584
-
2585
- for (var name in datas) {
2586
- currentDatas[name] = datas[name];
2587
- }
2588
-
2589
- return this;
2590
- };
2591
- /**
2592
- * Get the current event state while dragging.
2593
- */
2594
-
2595
-
2596
- __proto.getCurrentEvent = function (inputEvent) {
2597
- return __assign({
2598
- datas: this.datas
2599
- }, this._getPosition(), {
2600
- movement: this.getMovement(),
2601
- isDrag: this.isDrag,
2602
- isPinch: this.isPinch,
2603
- isScroll: false,
2604
- inputEvent: inputEvent
2605
- });
2606
- };
2607
- /**
2608
- * Get & Set the event data while dragging.
2609
- */
2610
-
2611
-
2612
- __proto.getEventDatas = function () {
2613
- return this.datas;
2614
- };
2615
- /**
2616
- * Unset Gesto
2617
- */
2618
-
2619
-
2620
- __proto.unset = function () {
2621
- var _this = this;
2622
-
2623
- var targets = this.targets;
2624
- var container = this.options.container;
2625
- this.off();
2626
- removeEvent(window, "blur", this.onBlur);
2627
-
2628
- if (this.isMouse) {
2629
- targets.forEach(function (target) {
2630
- removeEvent(target, "mousedown", _this.onDragStart);
2631
- });
2632
- removeEvent(container, "mousemove", this.onDrag);
2633
- removeEvent(container, "mouseup", this.onDragEnd);
2634
- removeEvent(container, "contextmenu", this.onDragEnd);
2635
- }
2636
-
2637
- if (this.isTouch) {
2638
- targets.forEach(function (target) {
2639
- removeEvent(target, "touchstart", _this.onDragStart);
2640
- });
2641
- removeEvent(container, "touchstart", this.onDragStart);
2642
- removeEvent(container, "touchmove", this.onDrag);
2643
- removeEvent(container, "touchend", this.onDragEnd);
2644
- removeEvent(container, "touchcancel", this.onDragEnd);
2645
- }
2646
- };
2647
-
2648
- __proto.onPinchStart = function (e) {
2649
- var pinchThreshold = this.options.pinchThreshold;
2650
-
2651
- if (this.isDrag && this.getMovement() > pinchThreshold) {
2652
- return;
2653
- }
2654
-
2655
- var store = new ClientStore(getEventClients(e));
2656
- this.pinchFlag = true;
2657
- this.clientStores.splice(0, 0, store);
2658
- var result = this.emit("pinchStart", __assign({
2659
- datas: this.datas,
2660
- angle: store.getAngle(),
2661
- touches: this.getCurrentStore().getPositions()
2662
- }, store.getPosition(), {
2663
- inputEvent: e
2664
- }));
2665
-
2666
- if (result === false) {
2667
- this.pinchFlag = false;
2668
- }
2669
- };
2670
-
2671
- __proto.onPinch = function (e, clients) {
2672
- if (!this.flag || !this.pinchFlag || clients.length < 2) {
2673
- return;
2674
- }
2675
-
2676
- var store = this.getCurrentStore();
2677
- this.isPinch = true;
2678
- this.emit("pinch", __assign({
2679
- datas: this.datas,
2680
- movement: this.getMovement(clients),
2681
- angle: store.getAngle(clients),
2682
- rotation: store.getRotation(clients),
2683
- touches: store.getPositions(clients),
2684
- scale: store.getScale(clients),
2685
- distance: store.getDistance(clients)
2686
- }, store.getPosition(clients), {
2687
- inputEvent: e
2688
- }));
2689
- };
2690
-
2691
- __proto.onPinchEnd = function (e) {
2692
- if (!this.pinchFlag) {
2693
- return;
2694
- }
2695
-
2696
- var isPinch = this.isPinch;
2697
- this.isPinch = false;
2698
- this.pinchFlag = false;
2699
- var store = this.getCurrentStore();
2700
- this.emit("pinchEnd", __assign({
2701
- datas: this.datas,
2702
- isPinch: isPinch,
2703
- touches: store.getPositions()
2704
- }, store.getPosition(), {
2705
- inputEvent: e
2706
- }));
2707
- this.isPinch = false;
2708
- this.pinchFlag = false;
2709
- };
2710
-
2711
- __proto.initDrag = function () {
2712
- this.clientStores = [];
2713
- this.pinchFlag = false;
2714
- this.doubleFlag = false;
2715
- this.prevTime = 0;
2716
- this.flag = false;
2717
- };
2718
-
2719
- __proto.getCurrentStore = function () {
2720
- return this.clientStores[0];
2721
- };
2722
-
2723
- __proto.moveClients = function (clients, inputEvent, isAdd) {
2724
- var position = this._getPosition(clients, isAdd);
2725
-
2726
- if (position.deltaX || position.deltaY) {
2727
- this.isDrag = true;
2728
- }
2729
-
2730
- return __assign({
2731
- datas: this.datas
2732
- }, position, {
2733
- movement: this.getMovement(clients),
2734
- isDrag: this.isDrag,
2735
- isPinch: this.isPinch,
2736
- isScroll: false,
2737
- inputEvent: inputEvent
2738
- });
2739
- };
2740
-
2741
- __proto._getPosition = function (clients, isAdd) {
2742
- var store = this.getCurrentStore();
2743
- var position = store.getPosition(clients, isAdd);
2744
-
2745
- var _a = this.clientStores.slice(1).reduce(function (prev, cur) {
2746
- var storePosition = cur.getPosition();
2747
- prev.distX += storePosition.distX;
2748
- prev.distY += storePosition.distY;
2749
- return prev;
2750
- }, position),
2751
- distX = _a.distX,
2752
- distY = _a.distY;
2753
-
2754
- return __assign({}, position, {
2755
- distX: distX,
2756
- distY: distY
2757
- });
2758
- };
2759
-
2760
- return Gesto;
2761
- }(EventEmitter$1);
2762
-
2763
- var Gesto$1 = Gesto;
2764
-
2765
1577
  const _sfc_main$h = defineComponent({
2766
1578
  name: "m-editor-resize",
2767
1579
  props: {
@@ -2776,7 +1588,7 @@ const _sfc_main$h = defineComponent({
2776
1588
  onMounted(() => {
2777
1589
  if (!target.value)
2778
1590
  return;
2779
- getso = new Gesto$1(target.value, {
1591
+ getso = new Gesto(target.value, {
2780
1592
  container: window,
2781
1593
  pinchOutside: true
2782
1594
  }).on("drag", (e) => {
@@ -2820,6 +1632,12 @@ const _sfc_main$g = defineComponent({
2820
1632
  AddPageBox,
2821
1633
  Resizer
2822
1634
  },
1635
+ props: {
1636
+ codeOptions: {
1637
+ type: Object,
1638
+ default: () => ({})
1639
+ }
1640
+ },
2823
1641
  setup() {
2824
1642
  const { editorService, uiService } = inject("services") || {};
2825
1643
  const root = computed(() => editorService?.get("root"));
@@ -2854,8 +1672,9 @@ function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
2854
1672
  key: 0,
2855
1673
  class: "m-editor-content",
2856
1674
  "init-values": _ctx.root,
1675
+ options: _ctx.codeOptions,
2857
1676
  onSave: _ctx.saveCode
2858
- }, null, 8, ["init-values", "onSave"])) : (openBlock(), createElementBlock("div", _hoisted_2$3, [
1677
+ }, null, 8, ["init-values", "options", "onSave"])) : (openBlock(), createElementBlock("div", _hoisted_2$3, [
2859
1678
  createElementVNode("div", {
2860
1679
  class: "m-editor-framework-left",
2861
1680
  style: normalizeStyle(`width: ${_ctx.columnWidth?.left}px`)
@@ -3303,13 +2122,13 @@ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
3303
2122
  const _component_m_form = resolveComponent("m-form");
3304
2123
  return openBlock(), createBlock(_component_m_form, {
3305
2124
  class: normalizeClass(`m-editor-props-panel ${_ctx.propsPanelSize}`),
3306
- "popper-class": "m-editor-props-panel-popper",
2125
+ "popper-class": `m-editor-props-panel-popper ${_ctx.propsPanelSize}`,
3307
2126
  ref: "configForm",
3308
2127
  size: _ctx.propsPanelSize,
3309
2128
  "init-values": _ctx.values,
3310
2129
  config: _ctx.curFormConfig,
3311
2130
  onChange: _ctx.submit
3312
- }, null, 8, ["class", "size", "init-values", "config", "onChange"]);
2131
+ }, null, 8, ["class", "popper-class", "size", "init-values", "config", "onChange"]);
3313
2132
  }
3314
2133
  var PropsPanel = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["render", _sfc_render$c]]);
3315
2134
 
@@ -3489,7 +2308,7 @@ const _sfc_main$a = defineComponent({
3489
2308
  function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
3490
2309
  const _component_tool_button = resolveComponent("tool-button");
3491
2310
  const _component_content_menu = resolveComponent("content-menu", true);
3492
- return _ctx.menuData.length ? withDirectives((openBlock(), createElementBlock("div", {
2311
+ return _ctx.menuData.length && _ctx.visible ? (openBlock(), createElementBlock("div", {
3493
2312
  key: 0,
3494
2313
  class: "magic-editor-content-menu",
3495
2314
  ref: "menu",
@@ -3513,9 +2332,7 @@ function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
3513
2332
  "menu-data": _ctx.subMenuData
3514
2333
  }, null, 8, ["menu-data"])
3515
2334
  ]))
3516
- ], 4)), [
3517
- [vShow, _ctx.visible]
3518
- ]) : createCommentVNode("", true);
2335
+ ], 4)) : createCommentVNode("", true);
3519
2336
  }
3520
2337
  var ContentMenu = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$a]]);
3521
2338
 
@@ -3815,7 +2632,7 @@ const _sfc_main$7 = defineComponent({
3815
2632
  components: { MIcon },
3816
2633
  props: {
3817
2634
  data: {
3818
- type: Object
2635
+ type: [Object, String]
3819
2636
  }
3820
2637
  },
3821
2638
  setup(props) {
@@ -4418,8 +3235,17 @@ const _sfc_main$3 = defineComponent({
4418
3235
  text: "\u7C98\u8D34",
4419
3236
  display: () => canPaste.value,
4420
3237
  handler: () => {
4421
- const top = menu.value?.$el.offsetTop || 0;
4422
- const left = menu.value?.$el.offsetLeft || 0;
3238
+ const stage = editorService?.get("stage");
3239
+ const rect = menu.value?.$el.getBoundingClientRect();
3240
+ const parentRect = stage?.container?.getBoundingClientRect();
3241
+ let left = (rect?.left || 0) - (parentRect?.left || 0);
3242
+ let top = (rect?.top || 0) - (parentRect?.top || 0);
3243
+ if (node.value?.items && stage) {
3244
+ const parentEl = stage.renderer.contentWindow?.document.getElementById(`${node.value.id}`);
3245
+ const parentElRect = parentEl?.getBoundingClientRect();
3246
+ left = left - (parentElRect?.left || 0);
3247
+ top = top - (parentElRect?.top || 0);
3248
+ }
4423
3249
  editorService?.paste({ left, top });
4424
3250
  }
4425
3251
  },
@@ -4514,6 +3340,7 @@ const _sfc_main$2 = defineComponent({
4514
3340
  type: Function
4515
3341
  },
4516
3342
  runtimeUrl: String,
3343
+ autoScrollIntoView: Boolean,
4517
3344
  canSelect: {
4518
3345
  type: Function,
4519
3346
  default: (el) => Boolean(el.id)
@@ -4549,6 +3376,7 @@ const _sfc_main$2 = defineComponent({
4549
3376
  render: props.render,
4550
3377
  runtimeUrl: props.runtimeUrl,
4551
3378
  zoom: zoom.value,
3379
+ autoScrollIntoView: props.autoScrollIntoView,
4552
3380
  canSelect: (el, event, stop) => {
4553
3381
  const elCanSelect = props.canSelect(el);
4554
3382
  if (uiSelectMode.value && elCanSelect && event.type === "mousedown") {
@@ -4638,6 +3466,7 @@ const _sfc_main$2 = defineComponent({
4638
3466
  const { scrollTop, scrollLeft } = stage.mask;
4639
3467
  if (layout === Layout.ABSOLUTE) {
4640
3468
  config.style = {
3469
+ ...config.style || {},
4641
3470
  position: "absolute",
4642
3471
  top: e.clientY - containerRect.top + scrollTop,
4643
3472
  left: e.clientX - containerRect.left + scrollLeft
@@ -4685,6 +3514,7 @@ const _sfc_main$1 = defineComponent({
4685
3514
  },
4686
3515
  props: {
4687
3516
  runtimeUrl: String,
3517
+ autoScrollIntoView: Boolean,
4688
3518
  render: {
4689
3519
  type: Function
4690
3520
  },
@@ -4703,8 +3533,12 @@ const _sfc_main$1 = defineComponent({
4703
3533
  const mouseenterHandler = () => {
4704
3534
  workspace.value?.focus();
4705
3535
  };
3536
+ const mouseleaveHandler = () => {
3537
+ workspace.value?.blur();
3538
+ };
4706
3539
  onMounted(() => {
4707
3540
  workspace.value?.addEventListener("mouseenter", mouseenterHandler);
3541
+ workspace.value?.addEventListener("mouseleave", mouseleaveHandler);
4708
3542
  keycon = new KeyController(workspace.value);
4709
3543
  const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
4710
3544
  const ctrl = isMac ? "meta" : "ctrl";
@@ -4713,6 +3547,11 @@ const _sfc_main$1 = defineComponent({
4713
3547
  if (!node.value || isPage(node.value))
4714
3548
  return;
4715
3549
  services?.editorService.remove(node.value);
3550
+ }).keyup("backspace", (e) => {
3551
+ e.inputEvent.preventDefault();
3552
+ if (!node.value || isPage(node.value))
3553
+ return;
3554
+ services?.editorService.remove(node.value);
4716
3555
  }).keydown([ctrl, "c"], (e) => {
4717
3556
  e.inputEvent.preventDefault();
4718
3557
  node.value && services?.editorService.copy(node.value);
@@ -4764,13 +3603,20 @@ const _sfc_main$1 = defineComponent({
4764
3603
  }).keydown([ctrl, "="], (e) => {
4765
3604
  e.inputEvent.preventDefault();
4766
3605
  services?.uiService.zoom(0.1);
3606
+ }).keydown([ctrl, "numpadplus"], (e) => {
3607
+ e.inputEvent.preventDefault();
3608
+ services?.uiService.zoom(0.1);
4767
3609
  }).keydown([ctrl, "-"], (e) => {
4768
3610
  e.inputEvent.preventDefault();
4769
3611
  services?.uiService.zoom(-0.1);
3612
+ }).keydown([ctrl, "numpad-"], (e) => {
3613
+ e.inputEvent.preventDefault();
3614
+ services?.uiService.zoom(-0.1);
4770
3615
  });
4771
3616
  });
4772
3617
  onUnmounted(() => {
4773
3618
  workspace.value?.removeEventListener("mouseenter", mouseenterHandler);
3619
+ workspace.value?.removeEventListener("mouseleave", mouseleaveHandler);
4774
3620
  keycon.destroy();
4775
3621
  });
4776
3622
  return {
@@ -4791,10 +3637,11 @@ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
4791
3637
  (openBlock(), createBlock(_component_magic_stage, {
4792
3638
  key: _ctx.page?.id,
4793
3639
  "runtime-url": _ctx.runtimeUrl,
3640
+ "auto-scroll-into-view": _ctx.autoScrollIntoView,
4794
3641
  render: _ctx.render,
4795
3642
  "moveable-options": _ctx.moveableOptions,
4796
3643
  "can-select": _ctx.canSelect
4797
- }, null, 8, ["runtime-url", "render", "moveable-options", "can-select"])),
3644
+ }, null, 8, ["runtime-url", "auto-scroll-into-view", "render", "moveable-options", "can-select"])),
4798
3645
  renderSlot(_ctx.$slots, "workspace-content"),
4799
3646
  createVNode(_component_page_bar, null, {
4800
3647
  "page-bar-title": withCtx(({ page }) => [
@@ -4971,6 +3818,7 @@ const _sfc_main = defineComponent({
4971
3818
  type: Function
4972
3819
  },
4973
3820
  runtimeUrl: String,
3821
+ autoScrollIntoView: Boolean,
4974
3822
  propsConfigs: {
4975
3823
  type: Object,
4976
3824
  default: () => ({})
@@ -4994,6 +3842,10 @@ const _sfc_main = defineComponent({
4994
3842
  },
4995
3843
  stageRect: {
4996
3844
  type: [String, Object]
3845
+ },
3846
+ codeOptions: {
3847
+ type: Object,
3848
+ default: () => ({})
4997
3849
  }
4998
3850
  },
4999
3851
  emits: ["props-panel-mounted", "update:modelValue"],
@@ -5052,7 +3904,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
5052
3904
  const _component_workspace = resolveComponent("workspace");
5053
3905
  const _component_props_panel = resolveComponent("props-panel");
5054
3906
  const _component_framework = resolveComponent("framework");
5055
- return openBlock(), createBlock(_component_framework, null, {
3907
+ return openBlock(), createBlock(_component_framework, { "code-options": _ctx.codeOptions }, {
5056
3908
  nav: withCtx(() => [
5057
3909
  renderSlot(_ctx.$slots, "nav", { editorService: _ctx.editorService }, () => [
5058
3910
  createVNode(_component_nav_menu, { data: _ctx.menu }, null, 8, ["data"])
@@ -5067,6 +3919,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
5067
3919
  renderSlot(_ctx.$slots, "workspace", {}, () => [
5068
3920
  createVNode(_component_workspace, {
5069
3921
  "runtime-url": _ctx.runtimeUrl,
3922
+ "auto-scroll-into-view": _ctx.autoScrollIntoView,
5070
3923
  render: _ctx.render,
5071
3924
  "moveable-options": _ctx.moveableOptions,
5072
3925
  "can-select": _ctx.canSelect
@@ -5081,7 +3934,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
5081
3934
  renderSlot(_ctx.$slots, "page-bar-popover", { page })
5082
3935
  ]),
5083
3936
  _: 3
5084
- }, 8, ["runtime-url", "render", "moveable-options", "can-select"])
3937
+ }, 8, ["runtime-url", "auto-scroll-into-view", "render", "moveable-options", "can-select"])
5085
3938
  ])
5086
3939
  ]),
5087
3940
  propsPanel: withCtx(() => [
@@ -5096,7 +3949,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
5096
3949
  renderSlot(_ctx.$slots, "empty", { editorService: _ctx.editorService })
5097
3950
  ]),
5098
3951
  _: 3
5099
- });
3952
+ }, 8, ["code-options"]);
5100
3953
  }
5101
3954
  var Editor = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
5102
3955