@mouseless/baked 1.4.1 → 1.4.2

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.4.1",
4
+ "version": "1.4.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
@@ -13,36 +13,128 @@
13
13
  </template>
14
14
  </PageTitle>
15
15
  <div class="flex justify-center">
16
- <Contents>
17
- <Inputs
18
- v-if="inputs"
19
- :inputs="inputs"
20
- :input-class="`w-full lg:col-span-2`"
21
- @ready="onReady"
22
- @changed="onChanged"
23
- />
16
+ <Contents class="gap-6">
17
+ <div
18
+ v-for="section in sectionsWithGroups"
19
+ :key="section.key"
20
+ class="w-full col-span-2 grid gap-4"
21
+ >
22
+ <div
23
+ v-if="sectionsWithGroups.length > 1"
24
+ class="
25
+ pb-2 border-b-2
26
+ border-zinc-100 dark:border-zinc-900
27
+ "
28
+ >
29
+ <span
30
+ class="
31
+ text-md font-semibold
32
+ text-zinc-800 dark:text-zinc-400
33
+ "
34
+ >
35
+ {{ l(section.label) }}
36
+ </span>
37
+ </div>
38
+ <div
39
+ class="
40
+ grid grid-flow-col
41
+ gap-4 items-start
42
+ max-md:flex max-md:flex-col
43
+ "
44
+ :class="{ 'grid-cols-2': !singleColumn }"
45
+ :style="{ 'grid-template-rows': `repeat(${section.rowCount}, auto)` }"
46
+ >
47
+ <div
48
+ v-for="sGroup in section.groups"
49
+ :key="sGroup.name"
50
+ :class="{ 'col-span-2': !singleColumn && sGroup.wide }"
51
+ class="w-full"
52
+ >
53
+ <div
54
+ class="flex gap-2 max-md:flex-col"
55
+ :class="{ 'narrow': sGroup.inputs.length > 1 }"
56
+ >
57
+ <Inputs
58
+ :inputs="sGroup.inputs"
59
+ input-class="w-full"
60
+ @ready="(value) => onReady(`${section.key}_${sGroup.name}`, value)"
61
+ @changed="onChanged"
62
+ />
63
+ </div>
64
+ </div>
65
+ </div>
66
+ </div>
24
67
  </Contents>
25
68
  </div>
26
69
  </div>
27
70
  </template>
28
71
 
29
72
  <script setup>
30
- import { ref } from "vue";
73
+ import { computed, ref } from "vue";
74
+ import { useLocalization } from "#imports";
31
75
  import { Button, Contents, Inputs, PageTitle } from "#components";
76
+ const { localize: l } = useLocalization();
32
77
  const { schema } = defineProps({
33
78
  schema: { type: null, required: true }
34
79
  });
35
80
  const emit = defineEmits(["submit"]);
36
- const { title, submit, inputs } = schema;
81
+ const { title, submit, inputs, sections, groups, wide, singleColumn } = schema;
37
82
  const formData = ref({});
38
- const ready = ref(inputs.length === 0);
39
- function onReady(value) {
40
- ready.value = value;
83
+ const readyData = ref({});
84
+ const ready = computed(() => Object.values(readyData.value).every((v) => v));
85
+ const group = {};
86
+ for (const groupName in groups) {
87
+ for (const inputName of groups[groupName]) {
88
+ group[inputName] = groupName;
89
+ }
90
+ }
91
+ const inputsByName = {};
92
+ for (let i = 0; i < inputs.length; i++) {
93
+ const input = inputs[i];
94
+ inputsByName[input.name] = { input, i };
95
+ }
96
+ const sectionsWithGroups = [];
97
+ for (const section of sections) {
98
+ const sectionWithGroups = {
99
+ key: section.key,
100
+ label: section.label,
101
+ groups: [],
102
+ groupsByName: {}
103
+ };
104
+ const sortedInputNames = [...section.inputs].sort((l2, r) => inputsByName[l2].i - inputsByName[r].i);
105
+ for (const name of sortedInputNames) {
106
+ const input = inputsByName[name].input;
107
+ const inputGroupName = group[name] || name;
108
+ let inputGroup = sectionWithGroups.groupsByName[inputGroupName];
109
+ if (!inputGroup) {
110
+ inputGroup = {
111
+ name: inputGroupName,
112
+ inputs: [],
113
+ wide: wide.includes(inputGroupName)
114
+ };
115
+ sectionWithGroups.groups.push(inputGroup);
116
+ sectionWithGroups.groupsByName[inputGroupName] = inputGroup;
117
+ }
118
+ inputGroup.inputs.push(input);
119
+ }
120
+ const cellCount = sectionWithGroups.groups.reduce((sum, group2) => sum + group2.wide + 1, 0);
121
+ sectionWithGroups.rowCount = singleColumn ? cellCount : Math.ceil(cellCount / 2);
122
+ sectionsWithGroups.push(sectionWithGroups);
123
+ }
124
+ function onReady(key, value) {
125
+ Object.assign(readyData.value, { [key]: value });
41
126
  }
42
127
  function onChanged({ values }) {
43
- formData.value = values;
128
+ Object.assign(formData.value, values);
44
129
  }
45
130
  function onSubmit() {
131
+ if (!ready.value) {
132
+ return;
133
+ }
46
134
  emit("submit", formData.value);
47
135
  }
48
136
  </script>
137
+
138
+ <style>
139
+ .b-component--FormPage .narrow *{@apply min-w-0}
140
+ </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mouseless/baked",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
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",