mce 0.11.3 → 0.11.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.
package/dist/index.js CHANGED
@@ -1873,69 +1873,6 @@ const _2_export = defineMixin((editor) => {
1873
1873
  to
1874
1874
  });
1875
1875
  });
1876
- const _2_export_json = defineMixin((editor) => {
1877
- const {
1878
- registerExporter,
1879
- getAabb,
1880
- selection,
1881
- root,
1882
- getTimeRange
1883
- } = editor;
1884
- registerExporter({
1885
- name: "json",
1886
- copyAs: (exported) => JSON.stringify(exported),
1887
- saveAs: (exported) => new Blob([JSON.stringify(exported)], { type: "application/json" }),
1888
- handle: (options) => {
1889
- const {
1890
- selected = false,
1891
- scale = 1
1892
- } = options;
1893
- let id = idGenerator();
1894
- let elements = [];
1895
- if (Array.isArray(selected)) {
1896
- elements = selected;
1897
- } else {
1898
- if (selected === true) {
1899
- elements = selection.value;
1900
- }
1901
- if (elements.length === 0 && root.value) {
1902
- if (root.value.meta.id) {
1903
- id = root.value.meta.id;
1904
- }
1905
- elements = root.value.children;
1906
- }
1907
- }
1908
- const box = getAabb(elements, "parent");
1909
- console.log(box);
1910
- return {
1911
- id,
1912
- style: {
1913
- width: box.width * scale,
1914
- height: box.height * scale,
1915
- transformOrigin: "left top",
1916
- transform: `scale(${scale})`
1917
- },
1918
- children: elements.map((el) => {
1919
- const json = el.toJSON();
1920
- if (box.left) {
1921
- json.style.left = (json.style.left ?? 0) - box.left;
1922
- }
1923
- if (box.top) {
1924
- json.style.top = (json.style.top ?? 0) - box.top;
1925
- }
1926
- json.meta ??= {};
1927
- json.meta.inPptIs = "Slide";
1928
- return json;
1929
- }),
1930
- meta: {
1931
- inPptIs: "Pptx",
1932
- inCanvasIs: "Element2D",
1933
- ...getTimeRange(elements)
1934
- }
1935
- };
1936
- }
1937
- });
1938
- });
1939
1876
  const _2_load = defineMixin((editor) => {
1940
1877
  const {
1941
1878
  state
@@ -2012,36 +1949,6 @@ const _2_load = defineMixin((editor) => {
2012
1949
  openFileDialog
2013
1950
  });
2014
1951
  });
2015
- const _2_loader_json = defineMixin((editor) => {
2016
- const {
2017
- registerLoader
2018
- } = editor;
2019
- const RE = /\.json$/i;
2020
- registerLoader({
2021
- name: "json",
2022
- accept: ".json",
2023
- test: (source) => {
2024
- if (source instanceof Blob) {
2025
- if (source.type.startsWith("application/json")) {
2026
- return true;
2027
- }
2028
- }
2029
- if (source instanceof File) {
2030
- if (RE.test(source.name)) {
2031
- return true;
2032
- }
2033
- }
2034
- return false;
2035
- },
2036
- load: async (source) => {
2037
- const json = JSON.parse(await source.text());
2038
- if ("version" in json && "elements" in json) {
2039
- console.log(json);
2040
- }
2041
- return json;
2042
- }
2043
- });
2044
- });
2045
1952
  const _3_view = defineMixin((editor) => {
2046
1953
  const {
2047
1954
  renderEngine,
@@ -2734,9 +2641,7 @@ const mixins = [
2734
2641
  _1_upload,
2735
2642
  _2_box,
2736
2643
  _2_export,
2737
- _2_export_json,
2738
2644
  _2_load,
2739
- _2_loader_json,
2740
2645
  _3_view,
2741
2646
  _4_0_text,
2742
2647
  _4_1_lock,
@@ -4672,6 +4577,97 @@ const _import = definePlugin((editor) => {
4672
4577
  }
4673
4578
  };
4674
4579
  });
4580
+ const _json = definePlugin((editor) => {
4581
+ const {
4582
+ getAabb,
4583
+ selection,
4584
+ root,
4585
+ getTimeRange
4586
+ } = editor;
4587
+ const RE = /\.json$/i;
4588
+ return {
4589
+ name: "mce:json",
4590
+ loaders: [
4591
+ {
4592
+ name: "json",
4593
+ accept: ".json",
4594
+ test: (source) => {
4595
+ if (source instanceof Blob) {
4596
+ if (source.type.startsWith("application/json")) {
4597
+ return true;
4598
+ }
4599
+ }
4600
+ if (source instanceof File) {
4601
+ if (RE.test(source.name)) {
4602
+ return true;
4603
+ }
4604
+ }
4605
+ return false;
4606
+ },
4607
+ load: async (source) => {
4608
+ const json = JSON.parse(await source.text());
4609
+ if ("version" in json && "elements" in json) {
4610
+ console.log(json);
4611
+ }
4612
+ return json;
4613
+ }
4614
+ }
4615
+ ],
4616
+ exporters: [
4617
+ {
4618
+ name: "json",
4619
+ handle: (options) => {
4620
+ const {
4621
+ selected = false,
4622
+ scale = 1
4623
+ } = options;
4624
+ let id = idGenerator();
4625
+ let elements = [];
4626
+ if (Array.isArray(selected)) {
4627
+ elements = selected;
4628
+ } else {
4629
+ if (selected === true) {
4630
+ elements = selection.value;
4631
+ }
4632
+ if (elements.length === 0 && root.value) {
4633
+ if (root.value.meta.id) {
4634
+ id = root.value.meta.id;
4635
+ }
4636
+ elements = root.value.children;
4637
+ }
4638
+ }
4639
+ const box = getAabb(elements, "parent");
4640
+ return {
4641
+ id,
4642
+ style: {
4643
+ width: box.width * scale,
4644
+ height: box.height * scale,
4645
+ transformOrigin: "left top",
4646
+ transform: `scale(${scale})`
4647
+ },
4648
+ children: elements.map((el) => {
4649
+ const json = el.toJSON();
4650
+ if (box.left) {
4651
+ json.style.left = (json.style.left ?? 0) - box.left;
4652
+ }
4653
+ if (box.top) {
4654
+ json.style.top = (json.style.top ?? 0) - box.top;
4655
+ }
4656
+ json.meta ??= {};
4657
+ json.meta.inPptIs = "Slide";
4658
+ return json;
4659
+ }),
4660
+ meta: {
4661
+ inPptIs: "Pptx",
4662
+ inCanvasIs: "Element2D",
4663
+ ...getTimeRange(elements)
4664
+ }
4665
+ };
4666
+ }
4667
+ }
4668
+ ]
4669
+ };
4670
+ });
4675
4671
  const _layerOrder = definePlugin((editor) => {
4676
4672
  const {
4677
4673
  selection
@@ -4825,25 +4821,26 @@ const _menu = definePlugin((editor, options) => {
4825
4821
  { key: "open" },
4826
4822
  { type: "divider" },
4827
4823
  { key: "import" },
4828
- exportMenu.value
4829
- ]
4824
+ exportMenu.value.children.length && exportMenu.value
4825
+ ].filter(Boolean)
4830
4826
  }));
4831
4827
  const historyMenus = computed(() => [
4832
4828
  { key: "undo", disabled: !canUndo.value },
4833
4829
  { key: "redo", disabled: !canRedo.value }
4834
4830
  ]);
4831
+ const copyAsMenu = computed(() => ({
4832
+ key: "copyAs",
4833
+ disabled: !hasSelected.value,
4834
+ children: [...exporters.value.values()].filter((v) => Boolean(v.copyAs)).map((v) => ({ key: `copyAs:${v.name}` }))
4835
+ }));
4835
4836
  const editMenus1 = computed(() => [
4836
4837
  { key: "copy", disabled: !hasSelected.value },
4837
- {
4838
- key: "copyAs",
4839
- disabled: !hasSelected.value,
4840
- children: [...exporters.value.values()].filter((v) => Boolean(v.copyAs)).map((v) => ({ key: `copyAs:${v.name}` }))
4841
- },
4838
+ copyAsMenu.value.children.length && copyAsMenu.value,
4842
4839
  { key: "cut", disabled: !hasSelected.value },
4843
4840
  { key: "paste" },
4844
4841
  { key: "duplicate", disabled: !hasSelected.value },
4845
4842
  { key: "delete", disabled: !hasSelected.value }
4846
- ]);
4843
+ ].filter(Boolean));
4847
4844
  const selectMenu = computed(() => ({
4848
4845
  key: "select",
4849
4846
  children: [
@@ -5423,6 +5420,7 @@ const plugins = [
5423
5420
  _html,
5424
5421
  _image,
5425
5422
  _import,
5423
+ _json,
5426
5424
  _layerOrder,
5427
5425
  _layerPosition,
5428
5426
  _lock,
@@ -22,5 +22,5 @@ declare global {
22
22
  }
23
23
  }
24
24
  }
25
- declare const _default: import("../..").Mixin;
25
+ declare const _default: import("..").Plugin;
26
26
  export default _default;
@@ -15,9 +15,7 @@ import './mixins/1.timeline'
15
15
  import './mixins/1.upload'
16
16
  import './mixins/2.box'
17
17
  import './mixins/2.export'
18
- import './mixins/2.export/json'
19
18
  import './mixins/2.load'
20
- import './mixins/2.loader/json'
21
19
  import './mixins/3.view'
22
20
  import './mixins/4.0.text'
23
21
  import './mixins/4.1.lock'
@@ -37,6 +35,7 @@ import './plugins/history'
37
35
  import './plugins/html'
38
36
  import './plugins/image'
39
37
  import './plugins/import'
38
+ import './plugins/json'
40
39
  import './plugins/layerOrder'
41
40
  import './plugins/layerPosition'
42
41
  import './plugins/lock'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mce",
3
3
  "type": "module",
4
- "version": "0.11.3",
4
+ "version": "0.11.4",
5
5
  "description": "The headless canvas editor framework. only the ESM.",
6
6
  "author": "wxm",
7
7
  "license": "MIT",
@@ -1,2 +0,0 @@
1
- declare const _default: import("../..").Mixin;
2
- export default _default;