@mouseless/baked 1.1.2 → 1.1.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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mouseless/baked",
3
3
  "configKey": "baked",
4
- "version": "1.1.2",
4
+ "version": "1.1.4",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -3,7 +3,7 @@
3
3
  ref="panel"
4
4
  :header="localizeTitle ? l(title) : title"
5
5
  :collapsed="collapsedState"
6
- toggleable
6
+ :toggleable="toggleable ?? true"
7
7
  :pt="
8
8
  {
9
9
  headerActions: 'flex gap-2 items-center',
@@ -95,7 +95,7 @@ const panel = useTemplateRef("panel");
95
95
  const { schema } = defineProps({
96
96
  schema: { type: null, required: true }
97
97
  });
98
- const { collapsed, content, inputs, localizeTitle, title: titleData } = schema;
98
+ const { collapsed, content, inputs, localizeTitle, title: titleData, toggleable } = schema;
99
99
  const contextData = context.injectContextData();
100
100
  const path = context.injectPath();
101
101
  const collapsedState = computed(() => panelStates[path] ?? collapsed);
@@ -7,7 +7,7 @@
7
7
  <Dialog
8
8
  v-model:visible="visible"
9
9
  :header="l(header)"
10
- :style="{ width: 'min(450px, 90vw)' }"
10
+ class="w-max max-w-[90vw]"
11
11
  closable
12
12
  modal
13
13
  dismissable-mask
@@ -26,10 +26,12 @@ onMounted(async () => {
26
26
  if (schema.default && dataFetcher.shouldLoad(schema.default.type)) {
27
27
  defaultValue = await dataFetcher.fetch({ data: schema.default, contextData });
28
28
  }
29
- if (schema.queryBound && checkValue(query.value)) {
30
- model.value = query.value;
31
- } else {
32
- await set(defaultValue);
29
+ if (!checkValue(model.value)) {
30
+ if (schema.queryBound && checkValue(query.value)) {
31
+ model.value = query.value;
32
+ } else {
33
+ await set(defaultValue);
34
+ }
33
35
  }
34
36
  if (schema.queryBound) {
35
37
  watch(() => route.query, async (newQuery) => {
@@ -2,49 +2,62 @@
2
2
  <Input
3
3
  v-for="input in inputs"
4
4
  :key="input.name"
5
- v-model="values[input.name]"
5
+ v-model="models[input.name]"
6
6
  :schema="input"
7
7
  :class="inputClass"
8
8
  />
9
9
  </template>
10
10
 
11
11
  <script setup>
12
- import { onMounted, watch, reactive } from "vue";
13
- import { useContext } from "#imports";
12
+ import { computed, reactive, watch } from "vue";
13
+ import { useContext, useRoute } from "#imports";
14
14
  import { Input } from "#components";
15
15
  const context = useContext();
16
+ const route = useRoute();
16
17
  const { inputs } = defineProps({
17
18
  inputs: { type: Array, required: true },
18
19
  inputClass: { type: String, default: "" }
19
20
  });
20
21
  const emit = defineEmits(["ready", "changed"]);
21
22
  const parentPath = context.injectPath();
22
- const values = reactive({});
23
+ const models = reactive({});
24
+ const values = computed(
25
+ () => inputs.reduce((result, input) => {
26
+ result[input.name] = getValue(input);
27
+ return result;
28
+ }, {})
29
+ );
23
30
  context.providePath(`${parentPath}/inputs`);
24
- watch(values, async () => {
25
- emitChanged();
26
- emitReady();
27
- }, { deep: true });
28
- onMounted(async () => {
31
+ watch(values, (newValues) => {
32
+ if (inputs.filter((i) => i.default || i.defaultSelfManaged).some((i) => !checkValue(newValues[i.name]))) {
33
+ return;
34
+ }
29
35
  emitChanged();
30
36
  emitReady();
31
- });
37
+ }, { immediate: true });
32
38
  function emitReady() {
33
- emit(
34
- "ready",
35
- inputs.filter((i) => i.required).reduce((result, i) => result && checkValue(values[i.name]), true)
36
- );
39
+ const ready = inputs.filter((i) => i.required).map(getValue).reduce((result, value) => result && checkValue(value), true);
40
+ emit("ready", ready);
37
41
  }
38
42
  function emitChanged() {
43
+ const uniqueKey = inputs.map(getValue).filter(checkValue).join("-");
39
44
  emit("changed", {
40
- uniqueKey: inputs.map((i) => values[i.name]).filter(checkValue).join("-"),
41
- values
45
+ uniqueKey,
46
+ values: values.value
42
47
  });
43
48
  }
44
49
  function checkValue(value) {
45
50
  if (typeof value === "string") {
46
51
  return value !== "";
52
+ } else {
53
+ return value !== void 0 && value !== null;
54
+ }
55
+ }
56
+ function getValue(input) {
57
+ if (input.queryBound) {
58
+ return route.query[input.name];
59
+ } else {
60
+ return models[input.name];
47
61
  }
48
- return value !== void 0 && value !== null;
49
62
  }
50
63
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mouseless/baked",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Baked is an opinionated framework for .NET and Vue. This is the UI package of Baked project.",
5
5
  "keywords": [
6
6
  "baked",