@flyo/nitro-vue3 1.0.2 → 2.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.
package/README.md CHANGED
@@ -1,9 +1,201 @@
1
- # Flyo Nitro Vue3 Components
1
+ # @flyo/nitro-vue3
2
2
 
3
- Vue3 Components for Flyo Nitro
3
+ Vue 3 integration for [Flyo Nitro](https://github.com/flyocloud/nitro-typescript-sdk) — build Vue 3 sites powered by the Flyo CMS with ready-made components and composables.
4
4
 
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @flyo/nitro-vue3
9
+ ```
10
+
11
+ ## Setup
12
+
13
+ Register the plugin in your Vue application entry point. You need a Flyo API token from your Nitro configuration.
14
+
15
+ ```js
16
+ import { createApp } from 'vue'
17
+ import { FlyoVue } from '@flyo/nitro-vue3'
18
+ import App from './App.vue'
19
+
20
+ const app = createApp(App)
21
+
22
+ app.use(FlyoVue, {
23
+ apiToken: 'YOUR_FLYO_API_TOKEN',
24
+ // optional: override the API base URL
25
+ // apiBasePath: 'https://api.flyo.cloud/nitro/v1',
26
+ // optional: additional default request headers
27
+ // defaultHeaders: {},
28
+ // optional: enable live-edit mode (for use inside the Flyo preview iframe)
29
+ liveEdit: false,
30
+ liveEditOrigin: 'https://flyo.cloud'
31
+ })
32
+
33
+ app.mount('#app')
5
34
  ```
6
- yarn add @flyo/nitro-vue3
35
+
36
+ ## Components
37
+
38
+ Both components are globally registered when you call `app.use(FlyoVue, ...)`.
39
+
40
+ ### `<FlyoPage>`
41
+
42
+ Renders the blocks of a page returned by `useFlyoPage`. It handles the live-edit postMessage bridge automatically, so editors can preview changes in real time inside the Flyo UI.
43
+
44
+ **Props**
45
+
46
+ | Prop | Type | Default | Description |
47
+ |---|---|---|---|
48
+ | `page` | `Object \| Boolean` | `false` | The page object returned by `useFlyoPage().fetch()` |
49
+
50
+ **Events**
51
+
52
+ | Event | Payload | Description |
53
+ |---|---|---|
54
+ | `update:page` | updated page | Emitted when the Flyo live-edit bridge pushes a new page state |
55
+
56
+ **Example**
57
+
58
+ ```vue
59
+ <script setup>
60
+ import { useFlyoPage } from '@flyo/nitro-vue3'
61
+
62
+ const { response: page, fetch } = useFlyoPage('about-us')
63
+ await fetch()
64
+ </script>
65
+
66
+ <template>
67
+ <FlyoPage v-model:page="page" />
68
+ </template>
7
69
  ```
8
70
 
9
- [Read more on dev.flyo.cloud/nitro/vue](https://dev.flyo.cloud/nitro/vue)
71
+ You can also use the default slot to wrap the output:
72
+
73
+ ```vue
74
+ <FlyoPage :page="page">
75
+ <template #default="{ json }">
76
+ <FlyoBlock v-for="item in json" :key="item.uid" :item="item" />
77
+ </template>
78
+ </FlyoPage>
79
+ ```
80
+
81
+ ---
82
+
83
+ ### `<FlyoBlock>`
84
+
85
+ Renders a single content block by resolving the block's `component` name to a locally or globally registered Vue component and passing all block data as props.
86
+
87
+ **Props**
88
+
89
+ | Prop | Type | Default | Description |
90
+ |---|---|---|---|
91
+ | `item` | `Object` | `{}` | A block object from `page.json` |
92
+
93
+ The resolved component receives: `config`, `content`, `items`, and `slots`.
94
+
95
+ **Example**
96
+
97
+ ```vue
98
+ <FlyoBlock :item="item" />
99
+ ```
100
+
101
+ ---
102
+
103
+ ## Composables
104
+
105
+ ### `useFlyoConfig()`
106
+
107
+ Fetches the global Nitro config (navigation containers, available slugs, globals).
108
+
109
+ ```js
110
+ import { useFlyoConfig } from '@flyo/nitro-vue3'
111
+
112
+ const { isLoading, response, error, fetch } = useFlyoConfig()
113
+
114
+ // fetch once on mount
115
+ await fetch()
116
+
117
+ console.log(response.value) // ConfigResponse
118
+ ```
119
+
120
+ ---
121
+
122
+ ### `useFlyoPage(slug)`
123
+
124
+ Fetches a page by its slug.
125
+
126
+ ```js
127
+ import { useFlyoPage } from '@flyo/nitro-vue3'
128
+
129
+ const { isLoading, response, error, fetch } = useFlyoPage('about-us')
130
+
131
+ await fetch()
132
+
133
+ console.log(response.value) // Page object with .json blocks, meta info, etc.
134
+ ```
135
+
136
+ ---
137
+
138
+ ### `useFlyoEntity(uniqueid)`
139
+
140
+ Fetches a single entity by its Nitro unique identifier.
141
+
142
+ ```js
143
+ import { useFlyoEntity } from '@flyo/nitro-vue3'
144
+
145
+ const { isLoading, response, error, fetch } = useFlyoEntity('my-blog-entry-uid')
146
+
147
+ await fetch()
148
+
149
+ console.log(response.value) // Entity fields
150
+ ```
151
+
152
+ ---
153
+
154
+ ### `useFlyoSitemap()`
155
+
156
+ Fetches the full sitemap — all pages and mapped entities including their resolved `href` paths.
157
+
158
+ ```js
159
+ import { useFlyoSitemap } from '@flyo/nitro-vue3'
160
+
161
+ const { isLoading, response, error, fetch } = useFlyoSitemap()
162
+
163
+ await fetch()
164
+
165
+ console.log(response.value) // Array of sitemap items
166
+ ```
167
+
168
+ ---
169
+
170
+ ## Composable return values
171
+
172
+ Every composable returns the same reactive shape:
173
+
174
+ | Key | Type | Description |
175
+ |---|---|---|
176
+ | `isLoading` | `Ref<boolean \| null>` | `true` while the request is in flight |
177
+ | `response` | `Ref<T \| null>` | The response data, `null` until fetched |
178
+ | `error` | `Ref<any \| null>` | The error object if the request failed |
179
+ | `fetch` | `async () => { response, error }` | Call this to trigger the request |
180
+
181
+ ---
182
+
183
+ ## Live-edit support
184
+
185
+ When your site is embedded in the Flyo preview iframe, `FlyoPage` automatically listens for `pageRefresh` messages and emits `update:page` so your component can reactively update without a full reload. Enable this by passing `liveEdit: true` to the plugin options.
186
+
187
+ ---
188
+
189
+ ## Releases
190
+
191
+ This package uses [semantic-release](https://github.com/semantic-release/semantic-release) — versions are bumped automatically based on [Conventional Commits](https://www.conventionalcommits.org/):
192
+
193
+ | Commit prefix | Release type |
194
+ |---|---|
195
+ | `fix:` | Patch (`1.0.x`) |
196
+ | `feat:` | Minor (`1.x.0`) |
197
+ | `feat!:` / `BREAKING CHANGE` | Major (`x.0.0`) |
198
+
199
+ ## License
200
+
201
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("@flyo/nitro-typescript"),e=require("vue");let m=null;const F=({apiToken:n,apiBasePath:t,defaultHeaders:o})=>{m=new u.Configuration({apiKey:n,...t&&{basePath:t},headers:o||{}})},f=()=>m,N={name:"FlyoBlock"},y=Object.assign(N,{props:{item:{type:Object,default:()=>{}}},setup(n){return(t,o)=>(e.openBlock(),e.createBlock(e.resolveDynamicComponent(n.item.component),{config:n.item.config,content:n.item.content,items:n.item.items,slots:n.item.slots},null,8,["config","content","items","slots"]))}}),J={name:"FlyoPage"},d=Object.assign(J,{props:{page:{type:[Object,Boolean],default:!1}},emits:["update:page"],setup(n,{emit:t}){const o=n,s=t,{liveEdit:a,liveEditOrigin:i}=e.inject("flyo"),p=r=>{const c=r.parent||r.opener;return r.self===c?!1:r.parent||r.opener},O=r=>{a&&process.client&&p(window)&&p(window).postMessage({action:"openEdit",data:JSON.parse(JSON.stringify({page:o.page,item:r}))},i)};return process.client&&p(window)&&window.addEventListener("message",r=>{if(r.origin!==i){console.log(`Message from ${r.origin} blocked. Expected ${i}.`);return}const c=r.data;c.action==="pageRefresh"&&s("update:page",c.data)}),(r,c)=>{const S=e.resolveComponent("FlyoBlock");return e.openBlock(),e.createElementBlock("div",null,[n.page?e.renderSlot(r.$slots,"default",e.normalizeProps(e.mergeProps({key:0},n.page)),()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.page.json,g=>(e.openBlock(),e.createBlock(S,{key:g.uid,item:g,onClick:()=>O(g)},null,8,["item","onClick"]))),128))]):e.createCommentVNode("",!0)])}}}),l=e.reactive({isLoading:null,response:null,error:null}),k=()=>{const n=async()=>{try{l.error=null,l.isLoading=!0,l.response=JSON.parse(JSON.stringify(await new u.ConfigApi(f()).config())),l.isLoading=!1}catch(t){l.isLoading=!1,l.response=null,l.error=JSON.parse(JSON.stringify(t))}return{response:l.response,error:l.error}};return{...e.toRefs(l),fetch:n}},h=n=>{const t=e.ref(!1),o=e.ref(null),s=e.ref(null);return{isLoading:t,response:o,error:s,fetch:async()=>{try{s.value=null,t.value=!0,o.value=JSON.parse(JSON.stringify(await new u.EntitiesApi(f()).entityByUniqueid({uniqueid:n}))),t.value=!1}catch(i){t.value=!1,o.value=null,s.value=JSON.parse(JSON.stringify(i))}return{response:e.unref(o),error:e.unref(s)}}}},E=n=>{const t=e.ref(!1),o=e.ref(null),s=e.ref(null);return{isLoading:t,response:o,error:s,fetch:async()=>{try{s.value=null,t.value=!0,o.value=JSON.parse(JSON.stringify(await new u.PagesApi(f()).page({slug:n}))),t.value=!1}catch(i){t.value=!1,o.value=null,s.value=JSON.parse(JSON.stringify(i))}return{response:e.unref(o),error:e.unref(s)}}}},B=()=>{const n=e.ref(!1),t=e.ref(null),o=e.ref(null);return{isLoading:n,response:t,error:o,fetch:async()=>{try{o.value=null,n.value=!0,t.value=JSON.parse(JSON.stringify(await new u.SitemapApi(f()).sitemap())),n.value=!1}catch(a){n.value=!1,t.value=null,o.value=JSON.parse(JSON.stringify(a))}return{response:e.unref(t),error:e.unref(o)}}}},v={install(n,t){F(t),n.component(y.name,y),n.component(d.name,d),n.provide("flyo",{liveEdit:t.liveEdit,liveEditOrigin:t.liveEditOrigin})}};exports.Block=y;exports.FlyoVue=v;exports.Page=d;exports.default=v;exports.getFlyoConfig=f;exports.useFlyoConfig=k;exports.useFlyoEntity=h;exports.useFlyoPage=E;exports.useFlyoSitemap=B;
@@ -0,0 +1,72 @@
1
+ import type { App, Component, Ref } from 'vue'
2
+ import type {
3
+ Configuration,
4
+ ConfigApi,
5
+ EntitiesApi,
6
+ PagesApi,
7
+ SitemapApi
8
+ } from '@flyo/nitro-typescript'
9
+
10
+ export interface FlyoVuePluginOptions {
11
+ apiToken: string
12
+ apiBasePath?: string
13
+ defaultHeaders?: Record<string, string>
14
+ liveEdit?: boolean
15
+ liveEditOrigin?: string
16
+ }
17
+
18
+ export interface FlyoFetchResult<T> {
19
+ response: T | null
20
+ error: unknown | null
21
+ }
22
+
23
+ export type FlyoConfigResponse = Awaited<ReturnType<ConfigApi['config']>>
24
+ export type FlyoPageResponse = Awaited<ReturnType<PagesApi['page']>>
25
+ export type FlyoEntityResponse = Awaited<ReturnType<EntitiesApi['entityByUniqueid']>>
26
+ export type FlyoSitemapResponse = Awaited<ReturnType<SitemapApi['sitemap']>>
27
+
28
+ export interface UseFlyoConfigReturn {
29
+ isLoading: Ref<boolean | null>
30
+ response: Ref<FlyoConfigResponse | null>
31
+ error: Ref<unknown | null>
32
+ fetch: () => Promise<FlyoFetchResult<FlyoConfigResponse>>
33
+ }
34
+
35
+ export interface UseFlyoPageReturn {
36
+ isLoading: Ref<boolean>
37
+ response: Ref<FlyoPageResponse | null>
38
+ error: Ref<unknown | null>
39
+ fetch: () => Promise<FlyoFetchResult<FlyoPageResponse>>
40
+ }
41
+
42
+ export interface UseFlyoEntityReturn {
43
+ isLoading: Ref<boolean>
44
+ response: Ref<FlyoEntityResponse | null>
45
+ error: Ref<unknown | null>
46
+ fetch: () => Promise<FlyoFetchResult<FlyoEntityResponse>>
47
+ }
48
+
49
+ export interface UseFlyoSitemapReturn {
50
+ isLoading: Ref<boolean>
51
+ response: Ref<FlyoSitemapResponse | null>
52
+ error: Ref<unknown | null>
53
+ fetch: () => Promise<FlyoFetchResult<FlyoSitemapResponse>>
54
+ }
55
+
56
+ export interface FlyoVuePlugin {
57
+ install: (app: App, options: FlyoVuePluginOptions) => void
58
+ }
59
+
60
+ declare const FlyoVue: FlyoVuePlugin
61
+ declare const Block: Component
62
+ declare const Page: Component
63
+
64
+ export default FlyoVue
65
+ export { FlyoVue, Block, Page }
66
+
67
+ export function getFlyoConfig(): Configuration | null
68
+
69
+ export function useFlyoConfig(): UseFlyoConfigReturn
70
+ export function useFlyoPage(slug: string): UseFlyoPageReturn
71
+ export function useFlyoEntity(uniqueid: string): UseFlyoEntityReturn
72
+ export function useFlyoSitemap(): UseFlyoSitemapReturn
package/dist/index.mjs ADDED
@@ -0,0 +1,163 @@
1
+ import { Configuration as h, ConfigApi as E, EntitiesApi as F, PagesApi as k, SitemapApi as w } from "@flyo/nitro-typescript";
2
+ import { openBlock as f, createBlock as O, resolveDynamicComponent as C, inject as L, resolveComponent as B, createElementBlock as y, renderSlot as b, normalizeProps as j, mergeProps as P, Fragment as A, renderList as $, createCommentVNode as _, reactive as x, toRefs as M, ref as a, unref as i } from "vue";
3
+ let S = null;
4
+ const R = ({ apiToken: e, apiBasePath: n, defaultHeaders: t }) => {
5
+ S = new h({
6
+ apiKey: e,
7
+ ...n && { basePath: n },
8
+ headers: t || {}
9
+ });
10
+ }, p = () => S, W = {
11
+ name: "FlyoBlock"
12
+ }, d = /* @__PURE__ */ Object.assign(W, {
13
+ props: {
14
+ item: {
15
+ type: Object,
16
+ default: () => {
17
+ }
18
+ }
19
+ },
20
+ setup(e) {
21
+ return (n, t) => (f(), O(C(e.item.component), {
22
+ config: e.item.config,
23
+ content: e.item.content,
24
+ items: e.item.items,
25
+ slots: e.item.slots
26
+ }, null, 8, ["config", "content", "items", "slots"]));
27
+ }
28
+ }), q = {
29
+ name: "FlyoPage"
30
+ }, v = /* @__PURE__ */ Object.assign(q, {
31
+ props: {
32
+ page: {
33
+ type: [Object, Boolean],
34
+ default: !1
35
+ }
36
+ },
37
+ emits: ["update:page"],
38
+ setup(e, { emit: n }) {
39
+ const t = e, o = n, { liveEdit: c, liveEditOrigin: l } = L("flyo"), g = (s) => {
40
+ const u = s.parent || s.opener;
41
+ return s.self === u ? !1 : s.parent || s.opener;
42
+ }, N = (s) => {
43
+ c && process.client && g(window) && g(window).postMessage({
44
+ action: "openEdit",
45
+ data: JSON.parse(JSON.stringify({
46
+ page: t.page,
47
+ item: s
48
+ }))
49
+ }, l);
50
+ };
51
+ return process.client && g(window) && window.addEventListener("message", (s) => {
52
+ if (s.origin !== l) {
53
+ console.log(`Message from ${s.origin} blocked. Expected ${l}.`);
54
+ return;
55
+ }
56
+ const u = s.data;
57
+ u.action === "pageRefresh" && o("update:page", u.data);
58
+ }), (s, u) => {
59
+ const J = B("FlyoBlock");
60
+ return f(), y("div", null, [
61
+ e.page ? b(s.$slots, "default", j(P({ key: 0 }, e.page)), () => [
62
+ (f(!0), y(A, null, $(e.page.json, (m) => (f(), O(J, {
63
+ key: m.uid,
64
+ item: m,
65
+ onClick: () => N(m)
66
+ }, null, 8, ["item", "onClick"]))), 128))
67
+ ]) : _("", !0)
68
+ ]);
69
+ };
70
+ }
71
+ }), r = x({
72
+ isLoading: null,
73
+ response: null,
74
+ error: null
75
+ }), K = () => {
76
+ const e = async () => {
77
+ try {
78
+ r.error = null, r.isLoading = !0, r.response = JSON.parse(JSON.stringify(await new E(p()).config())), r.isLoading = !1;
79
+ } catch (n) {
80
+ r.isLoading = !1, r.response = null, r.error = JSON.parse(JSON.stringify(n));
81
+ }
82
+ return {
83
+ response: r.response,
84
+ error: r.error
85
+ };
86
+ };
87
+ return {
88
+ ...M(r),
89
+ fetch: e
90
+ };
91
+ }, U = (e) => {
92
+ const n = a(!1), t = a(null), o = a(null);
93
+ return {
94
+ isLoading: n,
95
+ response: t,
96
+ error: o,
97
+ fetch: async () => {
98
+ try {
99
+ o.value = null, n.value = !0, t.value = JSON.parse(JSON.stringify(await new F(p()).entityByUniqueid({ uniqueid: e }))), n.value = !1;
100
+ } catch (l) {
101
+ n.value = !1, t.value = null, o.value = JSON.parse(JSON.stringify(l));
102
+ }
103
+ return {
104
+ response: i(t),
105
+ error: i(o)
106
+ };
107
+ }
108
+ };
109
+ }, G = (e) => {
110
+ const n = a(!1), t = a(null), o = a(null);
111
+ return {
112
+ isLoading: n,
113
+ response: t,
114
+ error: o,
115
+ fetch: async () => {
116
+ try {
117
+ o.value = null, n.value = !0, t.value = JSON.parse(JSON.stringify(await new k(p()).page({ slug: e }))), n.value = !1;
118
+ } catch (l) {
119
+ n.value = !1, t.value = null, o.value = JSON.parse(JSON.stringify(l));
120
+ }
121
+ return {
122
+ response: i(t),
123
+ error: i(o)
124
+ };
125
+ }
126
+ };
127
+ }, H = () => {
128
+ const e = a(!1), n = a(null), t = a(null);
129
+ return {
130
+ isLoading: e,
131
+ response: n,
132
+ error: t,
133
+ fetch: async () => {
134
+ try {
135
+ t.value = null, e.value = !0, n.value = JSON.parse(JSON.stringify(await new w(p()).sitemap())), e.value = !1;
136
+ } catch (c) {
137
+ e.value = !1, n.value = null, t.value = JSON.parse(JSON.stringify(c));
138
+ }
139
+ return {
140
+ response: i(n),
141
+ error: i(t)
142
+ };
143
+ }
144
+ };
145
+ }, I = {
146
+ install(e, n) {
147
+ R(n), e.component(d.name, d), e.component(v.name, v), e.provide("flyo", {
148
+ liveEdit: n.liveEdit,
149
+ liveEditOrigin: n.liveEditOrigin
150
+ });
151
+ }
152
+ };
153
+ export {
154
+ d as Block,
155
+ I as FlyoVue,
156
+ v as Page,
157
+ I as default,
158
+ p as getFlyoConfig,
159
+ K as useFlyoConfig,
160
+ U as useFlyoEntity,
161
+ G as useFlyoPage,
162
+ H as useFlyoSitemap
163
+ };
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@flyo/nitro-vue3",
3
- "version": "1.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "Vue3 Components for Flyo Nitro",
5
- "main": "./dist/index.js",
6
- "module": "./dist/index.js",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
7
8
  "exports": {
8
9
  ".": {
9
- "import": "./dist/index.js"
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.cjs"
10
13
  }
11
14
  },
12
15
  "repository": "git@github.com:flyocloud/nitro-vue3.git",
@@ -17,19 +20,28 @@
17
20
  "dist"
18
21
  ],
19
22
  "scripts": {
20
- "build": "rollup -c",
23
+ "build": "vite build && npm run build:types",
24
+ "build:types": "node scripts/build-types.mjs",
25
+ "prepublishOnly": "npm run build",
26
+ "test": "vitest run",
27
+ "test:watch": "vitest",
21
28
  "release": "npm publish --access=public"
22
29
  },
23
30
  "peerDependencies": {
24
31
  "vue": "^3.2.21"
25
32
  },
26
33
  "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"
34
+ "@semantic-release/changelog": "^6.0.0",
35
+ "@semantic-release/git": "^10.0.0",
36
+ "@vitejs/plugin-vue": "^5.0.0",
37
+ "@vue/compiler-sfc": "^3.4.0",
38
+ "@vue/test-utils": "^2.4.0",
39
+ "happy-dom": "^13.0.0",
40
+ "semantic-release": "^24.0.0",
41
+ "vite": "^5.0.0",
42
+ "vitest": "^1.0.0"
31
43
  },
32
44
  "dependencies": {
33
- "@flyo/nitro-js": "^1.0"
45
+ "@flyo/nitro-typescript": "^1.4.0"
34
46
  }
35
47
  }
package/dist/index.js DELETED
@@ -1,277 +0,0 @@
1
- import { ApiClient, ConfigApi, EntitiesApi, PagesApi, SitemapApi } from '@flyo/nitro-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 ApiToken = defaultClient.authentications["ApiToken"];
13
- ApiToken.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 };