@flyo/nitro-vue3 1.0.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.
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/index.js +277 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Flyo Cloud
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { ApiClient, ConfigApi, EntitiesApi, PagesApi, SitemapApi } from '@flyodev/nitrocms-js';
|
|
2
|
+
import { openBlock, createBlock, resolveDynamicComponent, inject, resolveComponent, createElementBlock, renderSlot, normalizeProps, mergeProps, Fragment, renderList, createCommentVNode, reactive, toRefs, ref, unref } from 'vue';
|
|
3
|
+
|
|
4
|
+
const initFlyoApi = ({ apiToken, apiBasePath, defaultHeaders }) => {
|
|
5
|
+
const defaultClient = ApiClient.instance;
|
|
6
|
+
defaultClient.defaultHeaders = defaultHeaders || {};
|
|
7
|
+
|
|
8
|
+
if (apiBasePath) {
|
|
9
|
+
defaultClient.basePath = apiBasePath;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const ApiKeyAuth = defaultClient.authentications["ApiKeyAuth"];
|
|
13
|
+
ApiKeyAuth.apiKey = apiToken;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const __default__$1 = {
|
|
17
|
+
name: 'FlyoBlock'
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
var script$1 = /*#__PURE__*/Object.assign(__default__$1, {
|
|
22
|
+
props: {
|
|
23
|
+
item: {
|
|
24
|
+
type: Object,
|
|
25
|
+
default: () => { }
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
setup(__props) {
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
return (_ctx, _cache) => {
|
|
33
|
+
return (openBlock(), createBlock(resolveDynamicComponent(__props.item.component), {
|
|
34
|
+
config: __props.item.config,
|
|
35
|
+
content: __props.item.content,
|
|
36
|
+
items: __props.item.items,
|
|
37
|
+
slots: __props.item.slots
|
|
38
|
+
}, null, 8 /* PROPS */, ["config", "content", "items", "slots"]))
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
script$1.__file = "src/components/Block.vue";
|
|
45
|
+
|
|
46
|
+
const __default__ = {
|
|
47
|
+
name: 'FlyoPage'
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
var script = /*#__PURE__*/Object.assign(__default__, {
|
|
52
|
+
props: {
|
|
53
|
+
page: {
|
|
54
|
+
type: [Object, Boolean],
|
|
55
|
+
default: false
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
emits: ['update:page'],
|
|
59
|
+
setup(__props, { emit: emits }) {
|
|
60
|
+
|
|
61
|
+
const props = __props;
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
const { liveEdit, liveEditOrigin } = inject('flyo');
|
|
68
|
+
|
|
69
|
+
const parentWindow = window => {
|
|
70
|
+
const parentWindow = window.parent || window.opener;
|
|
71
|
+
if (window.self === parentWindow) {
|
|
72
|
+
return false
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return window.parent || window.opener;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const openFlyoEdit = (item) => {
|
|
79
|
+
if (!liveEdit) {
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (process.client && parentWindow(window)) {
|
|
84
|
+
parentWindow(window).postMessage({
|
|
85
|
+
action: 'openEdit',
|
|
86
|
+
data: JSON.parse(JSON.stringify({
|
|
87
|
+
page: props.page,
|
|
88
|
+
item: item
|
|
89
|
+
}))
|
|
90
|
+
}, liveEditOrigin);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
if (process.client && parentWindow(window)) {
|
|
95
|
+
window.addEventListener("message", (event) => {
|
|
96
|
+
if (event.origin !== liveEditOrigin) {
|
|
97
|
+
console.log(`Message from ${event.origin} blocked. Expected ${liveEditOrigin}.`);
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const message = event.data;
|
|
102
|
+
if (message.action === 'pageRefresh') {
|
|
103
|
+
emits('update:page', message.data);
|
|
104
|
+
|
|
105
|
+
/*
|
|
106
|
+
const itemIndex = props.page.json.findIndex(item => item.uid === data.uid)
|
|
107
|
+
props.page.json[itemIndex] = {
|
|
108
|
+
...props.page.json[itemIndex],
|
|
109
|
+
...data
|
|
110
|
+
}
|
|
111
|
+
*/
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return (_ctx, _cache) => {
|
|
117
|
+
const _component_FlyoBlock = resolveComponent("FlyoBlock");
|
|
118
|
+
|
|
119
|
+
return (openBlock(), createElementBlock("div", null, [
|
|
120
|
+
(__props.page)
|
|
121
|
+
? renderSlot(_ctx.$slots, "default", normalizeProps(mergeProps({ key: 0 }, __props.page)), () => [
|
|
122
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(__props.page.json, (item) => {
|
|
123
|
+
return (openBlock(), createBlock(_component_FlyoBlock, {
|
|
124
|
+
key: item.uid,
|
|
125
|
+
item: item,
|
|
126
|
+
onClick: () => openFlyoEdit(item)
|
|
127
|
+
}, null, 8 /* PROPS */, ["item", "onClick"]))
|
|
128
|
+
}), 128 /* KEYED_FRAGMENT */))
|
|
129
|
+
])
|
|
130
|
+
: createCommentVNode("v-if", true)
|
|
131
|
+
]))
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
script.__file = "src/components/Page.vue";
|
|
138
|
+
|
|
139
|
+
const flyoConfigState = reactive({
|
|
140
|
+
isLoading: null,
|
|
141
|
+
response: null,
|
|
142
|
+
error: null
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const useFlyoConfig = () => {
|
|
146
|
+
const fetch = async () => {
|
|
147
|
+
try {
|
|
148
|
+
flyoConfigState.error = null;
|
|
149
|
+
flyoConfigState.isLoading = true;
|
|
150
|
+
flyoConfigState.response = JSON.parse(JSON.stringify(await new ConfigApi().config()));
|
|
151
|
+
flyoConfigState.isLoading = false;
|
|
152
|
+
} catch (e) {
|
|
153
|
+
flyoConfigState.isLoading = false;
|
|
154
|
+
flyoConfigState.response = null;
|
|
155
|
+
flyoConfigState.error = JSON.parse(JSON.stringify(e));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
response: flyoConfigState.response,
|
|
160
|
+
error: flyoConfigState.error
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
...toRefs(flyoConfigState),
|
|
166
|
+
fetch
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const useFlyoEntity = (uniqueid) => {
|
|
171
|
+
const isLoading = ref(false);
|
|
172
|
+
const response = ref(null);
|
|
173
|
+
const error = ref(null);
|
|
174
|
+
|
|
175
|
+
const fetch = async () => {
|
|
176
|
+
try {
|
|
177
|
+
error.value = null;
|
|
178
|
+
isLoading.value = true;
|
|
179
|
+
response.value = JSON.parse(JSON.stringify(await new EntitiesApi().entity(uniqueid)));
|
|
180
|
+
} catch (e) {
|
|
181
|
+
isLoading.value = false;
|
|
182
|
+
response.value = null;
|
|
183
|
+
error.value = JSON.parse(JSON.stringify(e));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
response: unref(response),
|
|
188
|
+
error: unref(error)
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
isLoading,
|
|
194
|
+
response,
|
|
195
|
+
error,
|
|
196
|
+
fetch
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const useFlyoPage = (slug) => {
|
|
201
|
+
const isLoading = ref(false);
|
|
202
|
+
const response = ref(null);
|
|
203
|
+
const error = ref(null);
|
|
204
|
+
|
|
205
|
+
const fetch = async () => {
|
|
206
|
+
try {
|
|
207
|
+
error.value = null;
|
|
208
|
+
isLoading.value = true;
|
|
209
|
+
response.value = JSON.parse(JSON.stringify(await new PagesApi().page({ slug })));
|
|
210
|
+
} catch (e) {
|
|
211
|
+
isLoading.value = false;
|
|
212
|
+
response.value = null;
|
|
213
|
+
error.value = JSON.parse(JSON.stringify(e));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return {
|
|
217
|
+
response: unref(response),
|
|
218
|
+
error: unref(error)
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
return {
|
|
223
|
+
isLoading,
|
|
224
|
+
response,
|
|
225
|
+
error,
|
|
226
|
+
fetch
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const useFlyoSitemap = () => {
|
|
231
|
+
const isLoading = ref(false);
|
|
232
|
+
const response = ref(null);
|
|
233
|
+
const error = ref(null);
|
|
234
|
+
|
|
235
|
+
const fetch = async () => {
|
|
236
|
+
try {
|
|
237
|
+
error.value = null;
|
|
238
|
+
isLoading.value = true;
|
|
239
|
+
response.value = JSON.parse(JSON.stringify(await new SitemapApi().sitemap()));
|
|
240
|
+
} catch (e) {
|
|
241
|
+
isLoading.value = false;
|
|
242
|
+
sitemap.value = null;
|
|
243
|
+
error.value = JSON.parse(JSON.stringify(e));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
response: unref(response),
|
|
248
|
+
error: unref(error)
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
return {
|
|
253
|
+
isLoading,
|
|
254
|
+
response,
|
|
255
|
+
error,
|
|
256
|
+
fetch
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const FlyoVue = {
|
|
261
|
+
install(Vue, options) {
|
|
262
|
+
// Initialize the flyo api
|
|
263
|
+
initFlyoApi(options);
|
|
264
|
+
|
|
265
|
+
// Setup flyo components
|
|
266
|
+
Vue.component(script$1.name, script$1);
|
|
267
|
+
Vue.component(script.name, script);
|
|
268
|
+
|
|
269
|
+
// Provide flyo object with global / persistent data
|
|
270
|
+
Vue.provide('flyo', {
|
|
271
|
+
liveEdit: options.liveEdit,
|
|
272
|
+
liveEditOrigin: options.liveEditOrigin
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
export { script$1 as Block, FlyoVue, script as Page, FlyoVue as default, useFlyoConfig, useFlyoEntity, useFlyoPage, useFlyoSitemap };
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flyo/nitro-vue3",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Vue3 Components for Flyo Nitro",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"repository": "git@github.com:flyocloud/nitrocms-vue3.git",
|
|
13
|
+
"author": "Basil Suter <git@nadar.io>",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "rollup -c",
|
|
21
|
+
"release": "npm publish --access=public"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"vue": "^3.2.21"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@vue/compiler-sfc": "^3.2.47",
|
|
28
|
+
"rollup": "^3.15.0",
|
|
29
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
30
|
+
"rollup-plugin-vue": "^6.0.0"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@flyo/nitro-js": "^1.0"
|
|
34
|
+
}
|
|
35
|
+
}
|