@mouseless/baked 1.0.3 → 1.1.0

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 (172) hide show
  1. package/dist/module.d.mts +1 -1
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +5 -4
  4. package/dist/runtime/components/AwaitLoading.d.ts +14 -0
  5. package/dist/runtime/components/AwaitLoading.js +27 -0
  6. package/dist/runtime/components/Bake.d.vue.ts +25 -11
  7. package/dist/runtime/components/Bake.vue +87 -16
  8. package/dist/runtime/components/Bake.vue.d.ts +25 -11
  9. package/dist/runtime/components/Button.d.vue.ts +27 -0
  10. package/dist/runtime/components/Button.vue +26 -0
  11. package/dist/runtime/components/Button.vue.d.ts +27 -0
  12. package/dist/runtime/components/CardLink.d.vue.ts +11 -9
  13. package/dist/runtime/components/CardLink.vue +1 -2
  14. package/dist/runtime/components/CardLink.vue.d.ts +11 -9
  15. package/dist/runtime/components/Composite.d.vue.ts +13 -0
  16. package/dist/runtime/components/Composite.vue +17 -0
  17. package/dist/runtime/components/Composite.vue.d.ts +13 -0
  18. package/dist/runtime/components/Conditional.d.vue.ts +23 -0
  19. package/dist/runtime/components/Conditional.vue +31 -0
  20. package/dist/runtime/components/Conditional.vue.d.ts +23 -0
  21. package/dist/runtime/components/Contents.d.vue.ts +40 -0
  22. package/dist/runtime/components/Contents.vue +25 -0
  23. package/dist/runtime/components/Contents.vue.d.ts +40 -0
  24. package/dist/runtime/components/DataPanel.d.vue.ts +13 -11
  25. package/dist/runtime/components/DataPanel.vue +35 -36
  26. package/dist/runtime/components/DataPanel.vue.d.ts +13 -11
  27. package/dist/runtime/components/DataTable.d.vue.ts +19 -9
  28. package/dist/runtime/components/DataTable.vue +69 -55
  29. package/dist/runtime/components/DataTable.vue.d.ts +19 -9
  30. package/dist/runtime/components/DefaultLayout.d.vue.ts +11 -9
  31. package/dist/runtime/components/DefaultLayout.vue +1 -2
  32. package/dist/runtime/components/DefaultLayout.vue.d.ts +11 -9
  33. package/dist/runtime/components/DeferredTabContent.d.vue.ts +26 -8
  34. package/dist/runtime/components/DeferredTabContent.vue +4 -3
  35. package/dist/runtime/components/DeferredTabContent.vue.d.ts +26 -8
  36. package/dist/runtime/components/Dialog.d.vue.ts +17 -0
  37. package/dist/runtime/components/Dialog.vue +57 -0
  38. package/dist/runtime/components/Dialog.vue.d.ts +17 -0
  39. package/dist/runtime/components/Error.vue +6 -0
  40. package/dist/runtime/components/ErrorPage.d.vue.ts +20 -8
  41. package/dist/runtime/components/ErrorPage.vue.d.ts +20 -8
  42. package/dist/runtime/components/Fieldset.d.vue.ts +21 -0
  43. package/dist/runtime/components/Fieldset.vue +38 -0
  44. package/dist/runtime/components/Fieldset.vue.d.ts +21 -0
  45. package/dist/runtime/components/Filter.d.vue.ts +23 -9
  46. package/dist/runtime/components/Filter.vue +5 -7
  47. package/dist/runtime/components/Filter.vue.d.ts +23 -9
  48. package/dist/runtime/components/FormPage.d.vue.ts +17 -0
  49. package/dist/runtime/components/FormPage.vue +48 -0
  50. package/dist/runtime/components/FormPage.vue.d.ts +17 -0
  51. package/dist/runtime/components/Header.d.vue.ts +19 -9
  52. package/dist/runtime/components/Header.vue +27 -29
  53. package/dist/runtime/components/Header.vue.d.ts +19 -9
  54. package/dist/runtime/components/Icon.d.vue.ts +11 -9
  55. package/dist/runtime/components/Icon.vue +1 -2
  56. package/dist/runtime/components/Icon.vue.d.ts +11 -9
  57. package/dist/runtime/components/Input.d.vue.ts +25 -0
  58. package/dist/runtime/components/Input.vue +78 -0
  59. package/dist/runtime/components/Input.vue.d.ts +25 -0
  60. package/dist/runtime/components/InputNumber.d.vue.ts +25 -0
  61. package/dist/runtime/components/InputNumber.vue +35 -0
  62. package/dist/runtime/components/InputNumber.vue.d.ts +25 -0
  63. package/dist/runtime/components/InputText.d.vue.ts +25 -0
  64. package/dist/runtime/components/InputText.vue +31 -0
  65. package/dist/runtime/components/InputText.vue.d.ts +25 -0
  66. package/dist/runtime/components/Inputs.d.vue.ts +29 -0
  67. package/dist/runtime/components/Inputs.vue +50 -0
  68. package/dist/runtime/components/Inputs.vue.d.ts +29 -0
  69. package/dist/runtime/components/LanguageSwitcher.d.vue.ts +1 -9
  70. package/dist/runtime/components/LanguageSwitcher.vue +0 -4
  71. package/dist/runtime/components/LanguageSwitcher.vue.d.ts +1 -9
  72. package/dist/runtime/components/Layout.vue +9 -5
  73. package/dist/runtime/components/Logo.d.vue.ts +11 -7
  74. package/dist/runtime/components/Logo.vue.d.ts +11 -7
  75. package/dist/runtime/components/MenuPage.d.vue.ts +11 -9
  76. package/dist/runtime/components/MenuPage.vue +28 -29
  77. package/dist/runtime/components/MenuPage.vue.d.ts +11 -9
  78. package/dist/runtime/components/Message.d.vue.ts +19 -9
  79. package/dist/runtime/components/Message.vue +10 -14
  80. package/dist/runtime/components/Message.vue.d.ts +19 -9
  81. package/dist/runtime/components/MissingComponent.d.vue.ts +21 -0
  82. package/dist/runtime/components/MissingComponent.vue +174 -0
  83. package/dist/runtime/components/MissingComponent.vue.d.ts +21 -0
  84. package/dist/runtime/components/ModalLayout.d.vue.ts +10 -15
  85. package/dist/runtime/components/ModalLayout.vue +0 -7
  86. package/dist/runtime/components/ModalLayout.vue.d.ts +10 -15
  87. package/dist/runtime/components/Money.d.vue.ts +11 -9
  88. package/dist/runtime/components/Money.vue +10 -15
  89. package/dist/runtime/components/Money.vue.d.ts +11 -9
  90. package/dist/runtime/components/NavLink.d.vue.ts +19 -9
  91. package/dist/runtime/components/NavLink.vue +34 -20
  92. package/dist/runtime/components/NavLink.vue.d.ts +19 -9
  93. package/dist/runtime/components/Number.d.vue.ts +11 -9
  94. package/dist/runtime/components/Number.vue +10 -15
  95. package/dist/runtime/components/Number.vue.d.ts +11 -9
  96. package/dist/runtime/components/Page.vue +7 -4
  97. package/dist/runtime/components/PageTitle.d.vue.ts +15 -9
  98. package/dist/runtime/components/PageTitle.vue +39 -8
  99. package/dist/runtime/components/PageTitle.vue.d.ts +15 -9
  100. package/dist/runtime/components/PersistentPopover.vue +1 -1
  101. package/dist/runtime/components/ProvideParentContext.d.vue.ts +28 -0
  102. package/dist/runtime/components/ProvideParentContext.vue +14 -0
  103. package/dist/runtime/components/ProvideParentContext.vue.d.ts +28 -0
  104. package/dist/runtime/components/Rate.d.vue.ts +11 -9
  105. package/dist/runtime/components/Rate.vue +6 -11
  106. package/dist/runtime/components/Rate.vue.d.ts +11 -9
  107. package/dist/runtime/components/Select.d.vue.ts +31 -9
  108. package/dist/runtime/components/Select.vue +30 -49
  109. package/dist/runtime/components/Select.vue.d.ts +31 -9
  110. package/dist/runtime/components/SelectButton.d.vue.ts +31 -9
  111. package/dist/runtime/components/SelectButton.vue +21 -36
  112. package/dist/runtime/components/SelectButton.vue.d.ts +31 -9
  113. package/dist/runtime/components/SideMenu.d.vue.ts +19 -9
  114. package/dist/runtime/components/SideMenu.vue.d.ts +19 -9
  115. package/dist/runtime/components/SideMenuItem.d.vue.ts +19 -9
  116. package/dist/runtime/components/SideMenuItem.vue.d.ts +19 -9
  117. package/dist/runtime/components/SimpleForm.d.vue.ts +17 -0
  118. package/dist/runtime/components/SimpleForm.vue +108 -0
  119. package/dist/runtime/components/SimpleForm.vue.d.ts +17 -0
  120. package/dist/runtime/components/SimplePage.d.vue.ts +13 -0
  121. package/dist/runtime/components/SimplePage.vue +19 -0
  122. package/dist/runtime/components/SimplePage.vue.d.ts +13 -0
  123. package/dist/runtime/components/TabbedPage.d.vue.ts +13 -0
  124. package/dist/runtime/components/{ReportPage.vue → TabbedPage.vue} +47 -65
  125. package/dist/runtime/components/TabbedPage.vue.d.ts +13 -0
  126. package/dist/runtime/components/Text.d.vue.ts +19 -9
  127. package/dist/runtime/components/Text.vue +9 -13
  128. package/dist/runtime/components/Text.vue.d.ts +19 -9
  129. package/dist/runtime/composables/useActionExecuter.d.ts +7 -0
  130. package/dist/runtime/composables/useActionExecuter.js +108 -0
  131. package/dist/runtime/composables/useConstraintEvaluator.d.ts +7 -0
  132. package/dist/runtime/composables/useConstraintEvaluator.js +58 -0
  133. package/dist/runtime/composables/useContext.d.ts +13 -8
  134. package/dist/runtime/composables/useContext.js +42 -18
  135. package/dist/runtime/composables/useDataFetcher.d.ts +6 -6
  136. package/dist/runtime/composables/useDataFetcher.js +66 -40
  137. package/dist/runtime/composables/useEvents.d.ts +7 -0
  138. package/dist/runtime/composables/useEvents.js +33 -0
  139. package/dist/runtime/composables/useFormat.d.ts +0 -1
  140. package/dist/runtime/composables/useFormat.js +0 -13
  141. package/dist/runtime/composables/useLoginRedirect.d.ts +1 -1
  142. package/dist/runtime/composables/useLoginRedirect.js +2 -2
  143. package/dist/runtime/composables/useNuxtError.d.ts +1 -1
  144. package/dist/runtime/composables/useNuxtError.js +2 -2
  145. package/dist/runtime/composables/useNuxtRoute.d.ts +1 -1
  146. package/dist/runtime/composables/useNuxtRoute.js +3 -3
  147. package/dist/runtime/composables/usePathBuilder.d.ts +3 -0
  148. package/dist/runtime/composables/usePathBuilder.js +18 -0
  149. package/dist/runtime/composables/useReactionHandler.d.ts +6 -0
  150. package/dist/runtime/composables/useReactionHandler.js +104 -0
  151. package/dist/runtime/composables/useRedirect.d.ts +3 -0
  152. package/dist/runtime/composables/useRedirect.js +17 -0
  153. package/dist/runtime/composables/useToken.js +2 -2
  154. package/dist/runtime/plugins/auth.js +16 -3
  155. package/dist/runtime/plugins/baked.js +23 -0
  156. package/dist/runtime/plugins/fetch.js +2 -2
  157. package/package.json +18 -18
  158. package/dist/runtime/components/None.d.vue.ts +0 -11
  159. package/dist/runtime/components/None.vue +0 -25
  160. package/dist/runtime/components/None.vue.d.ts +0 -11
  161. package/dist/runtime/components/Parameters.d.vue.ts +0 -11
  162. package/dist/runtime/components/Parameters.vue +0 -61
  163. package/dist/runtime/components/Parameters.vue.d.ts +0 -11
  164. package/dist/runtime/components/QueryParameters.d.vue.ts +0 -11
  165. package/dist/runtime/components/QueryParameters.vue +0 -109
  166. package/dist/runtime/components/QueryParameters.vue.d.ts +0 -11
  167. package/dist/runtime/components/ReportPage.d.vue.ts +0 -11
  168. package/dist/runtime/components/ReportPage.vue.d.ts +0 -11
  169. package/dist/runtime/composables/useConditional.d.ts +0 -3
  170. package/dist/runtime/composables/useConditional.js +0 -15
  171. package/dist/runtime/composables/useQuery.d.ts +0 -3
  172. package/dist/runtime/composables/useQuery.js +0 -13
@@ -1,12 +1,12 @@
1
1
  <template>
2
- <div class="space-y-4">
2
+ <div class="flex flex-col gap-4">
3
3
  <PageTitle :schema="title">
4
4
  <template
5
- v-if="queryParameters?.length > 0"
6
- #actions
5
+ v-if="inputs?.length > 0"
6
+ #inputs
7
7
  >
8
- <QueryParameters
9
- :parameters="queryParameters"
8
+ <Inputs
9
+ :inputs
10
10
  @ready="onReady"
11
11
  @changed="onChanged"
12
12
  />
@@ -40,7 +40,7 @@
40
40
  severity="info"
41
41
  >
42
42
  <i class="pi pi-info-circle" />
43
- <span class="ml-3">{{ lc("Select required values to view this report") }}</span>
43
+ <span class="ml-3">{{ lc("Select required values to view this page") }}</span>
44
44
  </Message>
45
45
  <div
46
46
  v-if="ready"
@@ -51,97 +51,79 @@
51
51
  :key="`${uniqueKey}-${tab.id}`"
52
52
  v-model="currentTab"
53
53
  :when="tab.id"
54
- :class="{ 'max-w-screen-xl 3xl:max-w-screen-2xl': !tab.fullScreen }"
55
- class="w-full"
56
54
  >
57
- <template v-if="tab.fullScreen">
58
- <template
59
- v-for="content in tab.contents"
60
- :key="`content-${content.key}`"
61
- >
62
- <Bake
63
- v-if="content.showWhen ? page[content.showWhen] : true"
64
- :name="`tabs/${tab.id}/contents/${content.key}`"
65
- :descriptor="content.component"
66
- />
67
- </template>
55
+ <template #default="{ hidden }">
56
+ <Contents
57
+ :contents="tab.contents"
58
+ :name-prefix="`tabs/${tab.id}`"
59
+ :full-screen="tab.fullScreen"
60
+ :class="{ hidden }"
61
+ />
68
62
  </template>
69
- <div
70
- v-else
71
- class="b-ReportPage--grid grid grid-cols-1 lg:grid-cols-2 gap-4"
72
- >
73
- <template
74
- v-for="content in tab.contents"
75
- :key="`content-${content.key}`"
76
- >
77
- <div
78
- v-if="content.showWhen ? page[content.showWhen] : true"
79
- :class="{ 'lg:col-span-2': !content.narrow }"
80
- >
81
- <Bake
82
- :name="`tabs/${tab.id}/contents/${content.key}`"
83
- :descriptor="content.component"
84
- />
85
- </div>
86
- </template>
87
- </div>
88
63
  </DeferredTabContent>
89
64
  </div>
90
65
  </div>
91
66
  </template>
92
67
 
93
68
  <script setup>
94
- import { computed, onMounted, ref, watch } from "vue";
69
+ import { computed, onBeforeUnmount, onMounted, reactive, ref } from "vue";
95
70
  import { Message, Tab, TabList, Tabs } from "primevue";
96
- import { useContext, useLocalization } from "#imports";
97
- import { Bake, DeferredTabContent, PageTitle, QueryParameters } from "#components";
71
+ import { useContext, useLocalization, useReactionHandler } from "#imports";
72
+ import { Bake, Contents, DeferredTabContent, Inputs, PageTitle } from "#components";
98
73
  const context = useContext();
99
74
  const { localize: l } = useLocalization();
100
- const { localize: lc } = useLocalization({ group: "ReportPage" });
75
+ const { localize: lc } = useLocalization({ group: "TabbedPage" });
76
+ const reactionHandler = useReactionHandler();
101
77
  const { schema } = defineProps({
102
- schema: { type: null, required: true },
103
- data: { type: null, default: null }
78
+ schema: { type: null, required: true }
104
79
  });
105
- const { title, queryParameters, tabs } = schema;
106
- const page = context.injectPage();
107
- const ready = ref(queryParameters.length === 0);
80
+ const { title, inputs, tabs } = schema;
81
+ const path = context.injectPath();
82
+ const ready = ref(inputs.length === 0);
108
83
  const uniqueKey = ref();
109
84
  const currentTab = ref(tabs.length > 0 ? tabs[0].id : "");
110
- const shownTabs = computed(() => tabs.filter((tab) => tab.showWhen ? page[tab.showWhen] : true));
85
+ const tabVisible = reactive(tabs.reduce((prev, cur) => ({ ...prev, [cur.id]: true }), {}));
86
+ const shownTabs = computed(() => tabs.filter((tab) => tabVisible[tab.id]));
111
87
  const lastTab = ref();
88
+ const tabReactions = [];
112
89
  const showRequiredMessage = ref(false);
113
- onMounted(() => {
114
- showRequiredMessage.value = !ready.value;
115
- });
116
90
  for (const tab of tabs) {
117
- if (!tab.showWhen) {
91
+ if (!tab.reactions) {
118
92
  continue;
119
93
  }
120
- watch(
121
- () => page[tab.showWhen],
122
- (show, previousShow) => {
123
- if (show === previousShow) {
124
- return;
125
- }
126
- if (currentTab.value === tab.id && !show) {
94
+ const tabReaction = reactionHandler.create(`${path}/tabs/${tab.id}`, {
95
+ reload() {
96
+ },
97
+ show(visible) {
98
+ tabVisible[tab.id] = visible;
99
+ if (currentTab.value === tab.id && !visible) {
127
100
  lastTab.value = currentTab.value;
128
101
  const firstAvailableTab = shownTabs.value[0];
129
102
  if (firstAvailableTab) {
130
103
  currentTab.value = firstAvailableTab.id;
131
104
  }
132
- } else if (lastTab.value === tab.id && show) {
105
+ } else if (lastTab.value === tab.id && visible) {
133
106
  currentTab.value = lastTab.value;
134
107
  lastTab.value = null;
135
108
  }
136
- },
137
- { immediate: true }
138
- );
109
+ }
110
+ });
111
+ tabReaction.bind(tab.reactions);
112
+ tabReactions.push(tabReaction);
139
113
  }
114
+ onMounted(() => {
115
+ showRequiredMessage.value = !ready.value;
116
+ });
117
+ onBeforeUnmount(() => {
118
+ for (const tabReaction of tabReactions) {
119
+ tabReaction.unbind();
120
+ }
121
+ });
140
122
  function onReady(value) {
141
123
  ready.value = value;
142
124
  showRequiredMessage.value = !value;
143
125
  }
144
- function onChanged(value) {
145
- uniqueKey.value = value;
126
+ function onChanged(event) {
127
+ uniqueKey.value = event.uniqueKey;
146
128
  }
147
129
  </script>
@@ -0,0 +1,13 @@
1
+ declare const _default: typeof __VLS_export;
2
+ export default _default;
3
+ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
4
+ schema: {
5
+ type: null;
6
+ required: true;
7
+ };
8
+ }>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
9
+ schema: {
10
+ type: null;
11
+ required: true;
12
+ };
13
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -1,11 +1,21 @@
1
1
  declare const _default: typeof __VLS_export;
2
2
  export default _default;
3
- declare const __VLS_export: import("vue").DefineComponent<{}, {
4
- $props: Partial<typeof __VLS_props>;
5
- schema: any;
6
- data: any;
7
- }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
8
- declare const __VLS_props: {
9
- readonly schema: any;
10
- readonly data: any;
11
- };
3
+ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
4
+ schema: {
5
+ type: null;
6
+ required: true;
7
+ };
8
+ data: {
9
+ type: null;
10
+ required: true;
11
+ };
12
+ }>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
13
+ schema: {
14
+ type: null;
15
+ required: true;
16
+ };
17
+ data: {
18
+ type: null;
19
+ required: true;
20
+ };
21
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -1,27 +1,23 @@
1
1
  <template>
2
- <Skeleton
3
- v-if="loading"
4
- height="1.5rem"
5
- />
6
- <span
7
- v-else-if="data"
8
- v-tooltip.bottom="tooltip"
9
- >{{ text }}</span>
10
- <span v-else>-</span>
2
+ <AwaitLoading :skeleton="{ height: '1.5rem' }">
3
+ <span
4
+ v-if="data"
5
+ v-tooltip.bottom="tooltip"
6
+ >{{ text }}</span>
7
+ <span v-else>-</span>
8
+ </AwaitLoading>
11
9
  </template>
12
10
 
13
11
  <script setup>
14
12
  import { computed } from "vue";
15
- import { Skeleton } from "primevue";
16
- import { useContext, useFormat } from "#imports";
17
- const context = useContext();
13
+ import { useFormat } from "#imports";
14
+ import { AwaitLoading } from "#components";
18
15
  const { truncate } = useFormat();
19
16
  const { schema, data } = defineProps({
20
17
  schema: { type: null, required: true },
21
18
  data: { type: null, required: true }
22
19
  });
23
20
  const { maxLength } = schema;
24
- const loading = context.injectLoading();
25
21
  const lengthIsExceeded = computed(() => maxLength && data.length > maxLength);
26
22
  const text = computed(() => lengthIsExceeded.value ? truncate(data, maxLength) : data);
27
23
  const tooltip = computed(() => ({
@@ -1,11 +1,21 @@
1
1
  declare const _default: typeof __VLS_export;
2
2
  export default _default;
3
- declare const __VLS_export: import("vue").DefineComponent<{}, {
4
- $props: Partial<typeof __VLS_props>;
5
- schema: any;
6
- data: any;
7
- }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
8
- declare const __VLS_props: {
9
- readonly schema: any;
10
- readonly data: any;
11
- };
3
+ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
4
+ schema: {
5
+ type: null;
6
+ required: true;
7
+ };
8
+ data: {
9
+ type: null;
10
+ required: true;
11
+ };
12
+ }>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
13
+ schema: {
14
+ type: null;
15
+ required: true;
16
+ };
17
+ data: {
18
+ type: null;
19
+ required: true;
20
+ };
21
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -0,0 +1,7 @@
1
+ export default function _default(): {
2
+ execute: ({ action, contextData, events }: {
3
+ action: any;
4
+ contextData: any;
5
+ events: any;
6
+ }) => Promise<void>;
7
+ };
@@ -0,0 +1,108 @@
1
+ import { useRuntimeConfig } from "#app";
2
+ import { useComposableResolver, useDataFetcher, usePathBuilder, useUnref } from "#imports";
3
+
4
+ export default function() {
5
+ const actions = {
6
+ "Composite": Composite({ actionExecuter: { execute } }),
7
+ "Local": Local(),
8
+ "Publish": Publish(),
9
+ "Remote": Remote({ actionExecuter: { execute } })
10
+ };
11
+
12
+ async function execute({ action, contextData, events }) {
13
+ const executer = actions[action?.type];
14
+
15
+ await executer.execute({ action, contextData, events });
16
+ }
17
+
18
+ return {
19
+ execute
20
+ };
21
+ }
22
+
23
+ function Composite({ actionExecuter }) {
24
+ async function execute({ action, contextData, events }) {
25
+ for(const part of action.parts) {
26
+ await actionExecuter.execute({ action: part, contextData, events });
27
+ }
28
+ }
29
+
30
+ return {
31
+ execute
32
+ };
33
+ }
34
+
35
+ function Local() {
36
+ const composableResolver = useComposableResolver();
37
+ const dataFetcher = useDataFetcher();
38
+
39
+ async function execute({ action, contextData }) {
40
+ const composable = (await composableResolver.resolve(action.composable)).default();
41
+
42
+ if(composable.run) {
43
+ const options = action.options ? await dataFetcher.fetch({ data: action.options, contextData }) : { };
44
+
45
+ return await composable.run(options);
46
+ }
47
+
48
+ throw new Error("Action composable should have async `run`");
49
+ }
50
+
51
+ return {
52
+ execute
53
+ };
54
+ }
55
+
56
+ function Publish() {
57
+ const dataFetcher = useDataFetcher();
58
+
59
+ async function execute({ action, contextData, events }) {
60
+ const data = action.data ? await dataFetcher.fetch({ data: action.data, contextData }) : undefined;
61
+
62
+ if(action.event) {
63
+ await events.publish(action.event, data);
64
+ }
65
+
66
+ if(action.pageContextKey) {
67
+ contextData.page[action.pageContextKey] = data;
68
+ }
69
+ }
70
+
71
+ return {
72
+ execute
73
+ };
74
+ }
75
+
76
+ function Remote({ actionExecuter }) {
77
+ const dataFetcher = useDataFetcher();
78
+ const pathBuilder = usePathBuilder();
79
+ const { public: { apiBaseURL } } = useRuntimeConfig();
80
+ const unref = useUnref();
81
+
82
+ async function execute({ action, contextData, events }) {
83
+ const headers = action.headers ? unref.deepUnref(await dataFetcher.fetch({ data: action.headers, contextData })) : { };
84
+ const query = action.query ? unref.deepUnref(await dataFetcher.fetch({ data: action.query, contextData })) : null;
85
+ const params = action.params ? unref.deepUnref(await dataFetcher.fetch({ data: action.params, contextData })) : { };
86
+ const body = action.method === "GET"
87
+ ? null
88
+ : (action.body ? unref.deepUnref(await dataFetcher.fetch({ data: action.body, contextData })) : { });
89
+
90
+ const response = await $fetch(pathBuilder.build(action.path, params), {
91
+ baseURL: apiBaseURL,
92
+ method: action.method,
93
+ headers: headers,
94
+ query: query,
95
+ body: body
96
+ });
97
+
98
+ await actionExecuter.execute({
99
+ action: action.postAction,
100
+ contextData: { ...contextData, response },
101
+ events
102
+ });
103
+ }
104
+
105
+ return {
106
+ execute
107
+ };
108
+ }
@@ -0,0 +1,7 @@
1
+ export default function _default(): {
2
+ evaluate: ({ constraint, value, contextData }: {
3
+ constraint: any;
4
+ value: any;
5
+ contextData: any;
6
+ }) => Promise<any>;
7
+ };
@@ -0,0 +1,58 @@
1
+ import { useComposableResolver, useDataFetcher } from "#imports";
2
+
3
+ export default function() {
4
+ const constraints = {
5
+ "Composable": Composable(),
6
+ "Is": Is(),
7
+ "IsNot": IsNot()
8
+ };
9
+
10
+ async function evaluate({ constraint, value, contextData }) {
11
+ if(!constraint) { return true; }
12
+
13
+ const evaluator = constraints[constraint.type];
14
+
15
+ return await evaluator.evaluate({ constraint, contextData, value });
16
+ }
17
+
18
+ return {
19
+ evaluate
20
+ };
21
+ }
22
+
23
+ function Composable() {
24
+ const composableResolver = useComposableResolver();
25
+ const dataFetcher = useDataFetcher();
26
+
27
+ async function evaluate({ constraint, value, contextData }) {
28
+ const options = constraint.options ? await dataFetcher.fetch({ data: constraint.options, contextData }) : { };
29
+ const composable = (await composableResolver.resolve(constraint.composable)).default(options);
30
+ if(!composable.validate) { throw new Error("Constraint composable should have `validate`"); }
31
+
32
+ return composable.validate(value);
33
+ }
34
+
35
+ return {
36
+ evaluate
37
+ };
38
+ }
39
+
40
+ function Is() {
41
+ async function evaluate({ constraint, value }) {
42
+ return constraint.is === value;
43
+ }
44
+
45
+ return {
46
+ evaluate
47
+ };
48
+ }
49
+
50
+ function IsNot() {
51
+ async function evaluate({ constraint, value }) {
52
+ return constraint.isNot !== value;
53
+ }
54
+
55
+ return {
56
+ evaluate
57
+ };
58
+ }
@@ -1,15 +1,20 @@
1
1
  export default function _default(): {
2
2
  injectPath: () => string;
3
- providePath: (name: any) => void;
3
+ providePath: (value: any) => void;
4
+ injectContextData: () => {
5
+ page: any;
6
+ parent: null;
7
+ };
4
8
  injectDataDescriptor: () => null;
5
9
  provideDataDescriptor: (value: any) => void;
6
- injectData: () => {
7
- ParentData: null;
8
- Custom: null;
9
- };
10
- provideData: (value: any, key: any) => void;
10
+ injectEvents: () => any;
11
+ provideEvents: (value: any) => void;
12
+ injectExecuting: () => import("vue").Ref<boolean, boolean>;
13
+ provideExecuting: (value: any) => void;
11
14
  injectLoading: () => import("vue").Ref<boolean, boolean>;
12
15
  provideLoading: (value: any) => void;
13
- injectPage: () => any;
14
- providePage: (value: any) => void;
16
+ injectPageContext: () => any;
17
+ providePageContext: (value: any) => void;
18
+ injectParentContext: () => null;
19
+ provideParentContext: (value: any) => void;
15
20
  };
@@ -1,15 +1,21 @@
1
1
  import { inject, provide, ref } from "vue";
2
2
 
3
3
  export default function() {
4
- function providePath(name) {
5
- const path = inject("__bake_path", null);
6
- provide("__bake_path", path ? `${path}/${name}` : name);
4
+ function providePath(value) {
5
+ provide("__bake_path", value);
7
6
  }
8
7
 
9
8
  function injectPath() {
10
9
  return inject("__bake_path", "");
11
10
  }
12
11
 
12
+ function injectContextData() {
13
+ return {
14
+ page: injectPageContext(),
15
+ parent: injectParentContext()
16
+ };
17
+ }
18
+
13
19
  function injectDataDescriptor() {
14
20
  return inject("__bake_data_descriptor", null);
15
21
  }
@@ -18,15 +24,20 @@ export default function() {
18
24
  return provide("__bake_data_descriptor", value);
19
25
  }
20
26
 
21
- function injectData() {
22
- return {
23
- ParentData: inject("__bake_injected_data:ParentData", null),
24
- Custom: inject("__bake_injected_data:Custom", null)
25
- };
27
+ function injectEvents() {
28
+ return inject("__bake_events");
29
+ }
30
+
31
+ function provideEvents(value) {
32
+ provide("__bake_events", value);
33
+ }
34
+
35
+ function injectExecuting() {
36
+ return inject("__bake_executing", ref(false));
26
37
  }
27
38
 
28
- function provideData(value, key) {
29
- provide(`__bake_injected_data:${key}`, value);
39
+ function provideExecuting(value) {
40
+ return provide("__bake_executing", value);
30
41
  }
31
42
 
32
43
  function injectLoading() {
@@ -37,24 +48,37 @@ export default function() {
37
48
  provide("__bake_loading", value);
38
49
  }
39
50
 
40
- function injectPage() {
41
- return inject("__bake_page");
51
+ function injectPageContext() {
52
+ return inject("__bake_page_context");
53
+ }
54
+
55
+ function providePageContext(value) {
56
+ provide("__bake_page_context", value);
57
+ }
58
+
59
+ function injectParentContext() {
60
+ return inject("__bake_parent_context", null);
42
61
  }
43
62
 
44
- function providePage(value) {
45
- provide("__bake_page", value);
63
+ function provideParentContext(value) {
64
+ provide("__bake_parent_context", value);
46
65
  }
47
66
 
48
67
  return {
49
68
  injectPath,
50
69
  providePath,
70
+ injectContextData,
51
71
  injectDataDescriptor,
52
72
  provideDataDescriptor,
53
- injectData,
54
- provideData,
73
+ injectEvents,
74
+ provideEvents,
75
+ injectExecuting,
76
+ provideExecuting,
55
77
  injectLoading,
56
78
  provideLoading,
57
- injectPage,
58
- providePage
79
+ injectPageContext,
80
+ providePageContext,
81
+ injectParentContext,
82
+ provideParentContext
59
83
  };
60
84
  }
@@ -1,15 +1,15 @@
1
1
  export default function _default(): {
2
2
  shouldLoad: (dataType: any) => boolean;
3
- get: ({ data, injectedData }: {
3
+ get: ({ data, contextData }: {
4
4
  data: any;
5
- injectedData: any;
5
+ contextData: any;
6
6
  }) => any;
7
- fetch: ({ data, injectedData }: {
7
+ fetch: ({ data, contextData }: {
8
8
  data: any;
9
- injectedData: any;
9
+ contextData: any;
10
10
  }) => Promise<any>;
11
- fetchParameters: ({ data, injectedData }: {
11
+ fetchParameters: ({ data, contextData }: {
12
12
  data: any;
13
- injectedData: any;
13
+ contextData: any;
14
14
  }) => Promise<any>;
15
15
  };