x-prop-tree 0.8.32 → 0.8.34

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.
@@ -4,6 +4,10 @@ import { t as __exportAll } from "./rolldown-runtime.c6i0pdwe.js";
4
4
  var en_exports = /* @__PURE__ */ __exportAll({ default: () => en_default });
5
5
  var en_default = { "x-prop-tree": {
6
6
  copy: "Copy",
7
+ dlg: { saveChange: {
8
+ title: "Save Changes",
9
+ text: "Do you want to save the changes?"
10
+ } },
7
11
  json: "JSON",
8
12
  jsonEditor: "JSON Editor",
9
13
  noAdaptSlot: "No Adapt Slot",
@@ -4,6 +4,10 @@ import { t as __exportAll } from "./rolldown-runtime.c6i0pdwe.js";
4
4
  var zhHans_exports = /* @__PURE__ */ __exportAll({ default: () => zhHans_default });
5
5
  var zhHans_default = { "x-prop-tree": {
6
6
  copy: "拷贝",
7
+ dlg: { saveChange: {
8
+ title: "保存变化",
9
+ text: "你想要保存变化吗?"
10
+ } },
7
11
  json: "JSON",
8
12
  jsonEditor: "JSON编辑器",
9
13
  noAdaptSlot: "没有适配插槽",
package/dist/index.d.ts CHANGED
@@ -2,6 +2,12 @@
2
2
  export declare function loadLocaleMessagePropTree(locale: string): Promise<{
3
3
  'x-prop-tree': {
4
4
  copy: string;
5
+ dlg: {
6
+ saveChange: {
7
+ title: string;
8
+ text: string;
9
+ };
10
+ };
5
11
  json: string;
6
12
  jsonEditor: string;
7
13
  noAdaptSlot: string;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  (function(){try{document.getElementById(`x-prop-tree`)?.remove();const e = document.createElement(`style`);e.setAttribute(`id`, `x-prop-tree`);const t = document.createTextNode(``);e.appendChild(t);document.head.appendChild(e);}catch(e){console.error('rolldown-plugin-inject-css', e);}})()
2
2
  import { n as isEqual, r as cloneDeep, t as omit } from "./vendor.mu9vrf3y.js";
3
3
  import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, h, inject, isRef, mergeModels, mergeProps, normalizeStyle, onBeforeUnmount, onMounted, onUnmounted, openBlock, provide, ref, renderList, renderSlot, resolveComponent, resolveDirective, toDisplayString, unref, useId, useModel, useTemplateRef, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers } from "vue";
4
- import { eventBus, globalObjects, injectDark, injectLocale, openNumberDlg, openPromptDlg, useColor, useSystem, useViewStack } from "x-essential-lib";
4
+ import { addView, delView, eventBus, globalObjects, hasView, injectDark, injectLocale, injectViews, openConfirmDlg, openNumberDlg, openPromptDlg, useColor, useSystem, useViewStack } from "x-essential-lib";
5
5
  import { getElement, getItems, getPropertyDefault, getPropertyDefaultArray, getTag, getTypes, isHexColor, isThemeColor, makeSlotId, parseNumberUnit, pkgs, rules, themeColors, unwrapSlotId } from "x-runtime-lib";
6
6
  import { getListEntry, setCollapse, tidyList } from "x-group-list";
7
7
  import { useI18n } from "vue-i18n";
@@ -1698,43 +1698,24 @@ var icon_default = index_vue_vue_type_script_setup_true_lang_default$11;
1698
1698
  //#region src/components/values/json/editor.vue?vue&type=script&setup=true&lang.ts
1699
1699
  var editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
1700
1700
  __name: "editor",
1701
- props: {
1702
- "modelValue": {
1703
- type: String,
1704
- required: true
1705
- },
1706
- "modelModifiers": {},
1707
- "lock": {
1708
- type: Boolean,
1709
- required: true
1710
- },
1711
- "lockModifiers": {},
1712
- "scale": {
1713
- type: Number,
1714
- required: true
1715
- },
1716
- "scaleModifiers": {}
1717
- },
1718
- emits: [
1719
- "update:modelValue",
1720
- "update:lock",
1721
- "update:scale"
1722
- ],
1701
+ props: { json: {
1702
+ type: String,
1703
+ required: true
1704
+ } },
1723
1705
  setup(__props, { expose: __expose }) {
1724
- const json = useModel(__props, "modelValue");
1725
- const lock = useModel(__props, "lock");
1726
- const scale = useModel(__props, "scale");
1727
1706
  const dark = injectDark();
1728
1707
  const locale = injectLocale();
1729
1708
  const version = injectVersion();
1709
+ const lock = ref(false);
1710
+ const scale = ref(1);
1730
1711
  const target = useTemplateRef("target");
1731
1712
  function onReady() {
1732
- const object = JSON.parse(json.value);
1713
+ const object = JSON.parse(__props.json);
1733
1714
  target.value?.load(object);
1734
1715
  }
1735
1716
  function save() {
1736
1717
  const object = target.value.save();
1737
- json.value = JSON.stringify(object, null, 2);
1718
+ return JSON.stringify(object, null, 2);
1738
1719
  }
1739
1720
  __expose({ save });
1740
1721
  return (_ctx, _cache) => {
@@ -1793,10 +1774,9 @@ var index_vue_vue_type_script_setup_true_lang_default$10 = /*@__PURE__*/ defineC
1793
1774
  const { t } = useI18n();
1794
1775
  const { sysBarAvail } = useSystem();
1795
1776
  const { backgroundColor0, backgroundColor1, backgroundColor2 } = useColor();
1777
+ const views = injectViews();
1796
1778
  const json = useModel(__props, "modelValue");
1797
1779
  const emit = __emit;
1798
- const lock = ref(false);
1799
- const scale = ref(1);
1800
1780
  const contStyle = computed(() => {
1801
1781
  let h = 48;
1802
1782
  if (sysBarAvail.value) h += 24;
@@ -1806,13 +1786,46 @@ var index_vue_vue_type_script_setup_true_lang_default$10 = /*@__PURE__*/ defineC
1806
1786
  height: `calc(100% - ${h}px)`
1807
1787
  };
1808
1788
  });
1809
- const { open } = useViewStack(`propTreejsonEditorDlg${useId()}`);
1810
- onUnmounted(() => {
1811
- open.value = false;
1812
- });
1813
1789
  const editor = useTemplateRef("editor");
1790
+ const name = `propTreejsonEditorDlg${useId()}`;
1791
+ const open = ref(false);
1792
+ const view = computed({
1793
+ get() {
1794
+ return hasView(views, name);
1795
+ },
1796
+ set(val) {
1797
+ if (val) addView(views, name);
1798
+ else delView(views, name);
1799
+ }
1800
+ });
1801
+ function onOpen() {
1802
+ open.value = true;
1803
+ }
1804
+ async function onClose() {
1805
+ try {
1806
+ const newJson = editor.value.save();
1807
+ if (isEqual(newJson, json.value)) return;
1808
+ if (!await openConfirmDlg({
1809
+ title: t("x-prop-tree.dlg.saveChange.title"),
1810
+ text: t("x-prop-tree.dlg.saveChange.text")
1811
+ })) return;
1812
+ json.value = newJson;
1813
+ } finally {
1814
+ open.value = false;
1815
+ }
1816
+ }
1817
+ onMounted(() => {
1818
+ eventBus.on(name, onOpen);
1819
+ });
1820
+ onBeforeUnmount(() => {
1821
+ eventBus.off(name, onOpen);
1822
+ });
1814
1823
  watch(open, (val) => {
1815
- if (!val) editor.value?.save();
1824
+ view.value = val;
1825
+ });
1826
+ watch(view, async (val) => {
1827
+ if (!val) await onClose();
1828
+ open.value = val;
1816
1829
  });
1817
1830
  return (_ctx, _cache) => {
1818
1831
  const _component_v_btn = resolveComponent("v-btn");
@@ -1820,14 +1833,14 @@ var index_vue_vue_type_script_setup_true_lang_default$10 = /*@__PURE__*/ defineC
1820
1833
  const _component_v_spacer = resolveComponent("v-spacer");
1821
1834
  const _component_v_dialog = resolveComponent("v-dialog");
1822
1835
  return openBlock(), createBlock(_component_v_dialog, {
1823
- modelValue: unref(open),
1824
- "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => isRef(open) ? open.value = $event : null),
1836
+ modelValue: open.value,
1837
+ "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => open.value = $event),
1825
1838
  attach: "",
1826
1839
  fullscreen: "",
1827
1840
  "no-click-animation": "",
1828
1841
  persistent: "",
1829
1842
  transition: "dialog-bottom-transition",
1830
- onKeydown: _cache[6] || (_cache[6] = withKeys(withModifiers(($event) => open.value = false, ["stop", "prevent"]), ["esc"]))
1843
+ onKeydown: withKeys(withModifiers(onClose, ["stop", "prevent"]), ["esc"])
1831
1844
  }, {
1832
1845
  activator: withCtx(({ props: activatorProps }) => [createVNode(_component_v_btn, mergeProps(activatorProps, {
1833
1846
  block: "",
@@ -1865,7 +1878,7 @@ var index_vue_vue_type_script_setup_true_lang_default$10 = /*@__PURE__*/ defineC
1865
1878
  density: "comfortable",
1866
1879
  icon: "mdi-close",
1867
1880
  variant: "text",
1868
- onClick: _cache[1] || (_cache[1] = ($event) => open.value = false)
1881
+ onClick: onClose
1869
1882
  }),
1870
1883
  createElementVNode("span", _hoisted_1$10, toDisplayString(unref(t)("x-prop-tree.jsonEditor")), 1),
1871
1884
  createVNode(_component_v_spacer)
@@ -1875,22 +1888,13 @@ var index_vue_vue_type_script_setup_true_lang_default$10 = /*@__PURE__*/ defineC
1875
1888
  createElementVNode("div", { style: normalizeStyle(contStyle.value) }, [createVNode(editor_default, {
1876
1889
  ref_key: "editor",
1877
1890
  ref: editor,
1878
- modelValue: json.value,
1879
- "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => json.value = $event),
1880
- lock: lock.value,
1881
- "onUpdate:lock": _cache[3] || (_cache[3] = ($event) => lock.value = $event),
1882
- scale: scale.value,
1883
- "onUpdate:scale": _cache[4] || (_cache[4] = ($event) => scale.value = $event)
1884
- }, null, 8, [
1885
- "modelValue",
1886
- "lock",
1887
- "scale"
1888
- ])], 4)
1891
+ json: json.value
1892
+ }, null, 8, ["json"])], 4)
1889
1893
  ]),
1890
1894
  _: 1
1891
1895
  }, 8, ["color"])]),
1892
1896
  _: 1
1893
- }, 8, ["modelValue"]);
1897
+ }, 8, ["modelValue", "onKeydown"]);
1894
1898
  };
1895
1899
  }
1896
1900
  });
@@ -3581,8 +3585,8 @@ const install = (app) => {
3581
3585
  //#endregion
3582
3586
  //#region src/i18n/index.ts
3583
3587
  async function loadLocaleMessagePropTree(locale) {
3584
- if (locale === "en") return (await import("./i18n-en.fevhb1gv.js").then((n) => n.t)).default;
3585
- else if (locale === "zhHans") return (await import("./i18n-zhHans.cro9uz6i.js").then((n) => n.t)).default;
3588
+ if (locale === "en") return (await import("./i18n-en.l2rmrsld.js").then((n) => n.t)).default;
3589
+ else if (locale === "zhHans") return (await import("./i18n-zhHans.mlbij4hp.js").then((n) => n.t)).default;
3586
3590
  else throw new Error(`invalid locale=${locale}`);
3587
3591
  }
3588
3592
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-prop-tree",
3
- "version": "0.8.32",
3
+ "version": "0.8.34",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -43,11 +43,11 @@
43
43
  "vue": "^3.5.42",
44
44
  "vue-i18n": "^11.4.10",
45
45
  "vuetify": "^4.2.1",
46
- "x-block-lib": "^0.11.10",
46
+ "x-block-lib": "^0.11.11",
47
47
  "x-error-lib": "^0.6.5",
48
48
  "x-essential-lib": "^0.10.40",
49
49
  "x-group-list": "^0.4.19",
50
- "x-runtime-lib": "^0.10.4",
50
+ "x-runtime-lib": "^0.10.5",
51
51
  "x-state-lib": "^0.4.5"
52
52
  }
53
53
  }