@flexkit/studio 0.0.33 → 0.0.34

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.
@@ -1,2 +1,2 @@
1
- import'./index.css';import {d}from'./chunk-2OBWJ6UY.js';import {c}from'./chunk-WDRCARCP.js';import {createContext,useReducer,useContext,useMemo}from'react';import {jsx}from'react/jsx-runtime';import J from'swr';import {find,propEq}from'ramda';var O="core.context.scope:",b={breadcrumbs:[],isRouteLoading:false,pageTitle:"",scope:"",relationships:{}},x=createContext(b),C=createContext(()=>{});function $(t,e){let{type:o,payload:r}=e;switch(o){case "setScope":return typeof localStorage<"u"&&r.projectId&&localStorage.setItem(`${O}${r.projectId}`,r.scope),{...t,scope:r.scope};case "setRelationship":return {...t,relationships:{...t.relationships,...r}};default:throw Error(`Unknown action: ${o}`)}}function K({children:t}){let[e,o]=useReducer($,b);return jsx(x.Provider,{value:e,children:jsx(C.Provider,{value:o,children:t})})}function I(){return useContext(x)}function V(){return useContext(C)}function E(t){if(t?.attributes.length)return t.display?t.attributes.find(e=>e.name===t.display)??t.attributes[0]:t.attributes[0]}function Q(t,e){let{scope:o}=I(),{projects:r,currentProjectId:u}=d(),{schema:n,scopes:l}=find(propEq(u??"","projectId"))(r),s=l?.find(m=>m.isDefault)?.name??"default",a=e?.commonParams.q?JSON.stringify(e):null,{data:i,error:h,isLoading:p}=J(a,()=>fetch(c(t).search,{headers:{"Content-Type":"application/json"},body:JSON.stringify(e),method:"POST",mode:"cors"}).then(m=>m.json()));return {results:useMemo(()=>L(i?.results??[],t,n,o,s)??[],[i,s,t,n,o]),error:h,isLoading:p}}function L(t,e,o,r,u){return t?.filter(n=>n?.hits?.length>0).map(n=>{let l=n,s=l.collection.replace(`${e}_`,"").replace(/_\d+$/,""),a=find(propEq(s,"plural"))(o);if(!a)return [];let i=E(a)?.name??"",h=a?.name??s;return l.hits.map(({document:p})=>{let c=p[i],w=(c&&typeof c!="string"?c[r]??c[u]:null)??p[i],D=Object.entries(p).reduce((y,[d,f])=>{if(d!==i&&d!=="id"&&d!=="_updatedAt"){let T=typeof f!="string"?f[r]??f[u]:f;y[d]=T;}return y},{});return {_id:p.id,_entityName:h,_entityNamePlural:s,[i]:w,...D}})}).flat()}export{O as a,K as b,I as c,V as d,E as e,Q as f};//# sourceMappingURL=chunk-MLYKIVZC.js.map
2
- //# sourceMappingURL=chunk-MLYKIVZC.js.map
1
+ import'./index.css';import {d}from'./chunk-LIV5RBWJ.js';import {c}from'./chunk-WDRCARCP.js';import {createContext,useReducer,useContext,useMemo}from'react';import {jsx}from'react/jsx-runtime';import J from'swr';import {find,propEq}from'ramda';var O="core.context.scope:",b={breadcrumbs:[],isRouteLoading:false,pageTitle:"",scope:"",relationships:{}},x=createContext(b),C=createContext(()=>{});function $(t,e){let{type:o,payload:r}=e;switch(o){case "setScope":return typeof localStorage<"u"&&r.projectId&&localStorage.setItem(`${O}${r.projectId}`,r.scope),{...t,scope:r.scope};case "setRelationship":return {...t,relationships:{...t.relationships,...r}};default:throw Error(`Unknown action: ${o}`)}}function K({children:t}){let[e,o]=useReducer($,b);return jsx(x.Provider,{value:e,children:jsx(C.Provider,{value:o,children:t})})}function I(){return useContext(x)}function V(){return useContext(C)}function E(t){if(t?.attributes.length)return t.display?t.attributes.find(e=>e.name===t.display)??t.attributes[0]:t.attributes[0]}function Q(t,e){let{scope:o}=I(),{projects:r,currentProjectId:u}=d(),{schema:n,scopes:l}=find(propEq(u??"","projectId"))(r),s=l?.find(m=>m.isDefault)?.name??"default",a=e?.commonParams.q?JSON.stringify(e):null,{data:i,error:h,isLoading:p}=J(a,()=>fetch(c(t).search,{headers:{"Content-Type":"application/json"},body:JSON.stringify(e),method:"POST",mode:"cors"}).then(m=>m.json()));return {results:useMemo(()=>L(i?.results??[],t,n,o,s)??[],[i,s,t,n,o]),error:h,isLoading:p}}function L(t,e,o,r,u){return t?.filter(n=>n?.hits?.length>0).map(n=>{let l=n,s=l.collection.replace(`${e}_`,"").replace(/_\d+$/,""),a=find(propEq(s,"plural"))(o);if(!a)return [];let i=E(a)?.name??"",h=a?.name??s;return l.hits.map(({document:p})=>{let c=p[i],w=(c&&typeof c!="string"?c[r]??c[u]:null)??p[i],D=Object.entries(p).reduce((y,[d,f])=>{if(d!==i&&d!=="id"&&d!=="_updatedAt"){let T=typeof f!="string"?f[r]??f[u]:f;y[d]=T;}return y},{});return {_id:p.id,_entityName:h,_entityNamePlural:s,[i]:w,...D}})}).flat()}export{O as a,K as b,I as c,V as d,E as e,Q as f};//# sourceMappingURL=chunk-JH4MVD36.js.map
2
+ //# sourceMappingURL=chunk-JH4MVD36.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/app-context.tsx","../src/core/get-display-attribute.ts","../src/core/use-search.tsx"],"names":["SCOPE_STORAGE_KEY","initialState","AppContext","createContext","AppDispatchContext","reducer","state","action","type","payload","AppProvider","children","dispatch","useReducer","jsx","useAppContext","useContext","useAppDispatch","getDisplayAttribute","entity","attr","useSearch","projectId","searchRequest","scope","projects","currentProjectId","useConfig","schema","scopes","find","propEq","defaultScope","s","swrKey","data","error","isLoading","useSWR","apiPaths","res","useMemo","mapResults","results","result","item","entityNamePlural","entitySchema","primaryAttributeName","entityName","document","primaryAttribute","primaryAttributeValue","attributes","acc","key","value","scopedValue"],"mappings":"mPAMO,IAAMA,CAAAA,CAAoB,qBAAA,CAE3BC,EAAe,CACnB,WAAA,CAAa,EAAC,CACd,cAAA,CAAgB,KAAA,CAChB,SAAA,CAAW,EAAA,CACX,KAAA,CAAO,EAAA,CACP,aAAA,CAAe,EACjB,CAAA,CAEMC,EAAaC,aAAAA,CAA8BF,CAAY,CAAA,CAEvDG,CAAAA,CAAqBD,aAAAA,CAAgE,IAAM,CAEjG,CAAC,EAED,SAASE,CAAAA,CAAQC,CAAAA,CAAuBC,CAAAA,CAAgE,CACtG,GAAM,CAAE,IAAA,CAAAC,CAAAA,CAAM,OAAA,CAAAC,CAAQ,CAAA,CAAIF,CAA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A,CAAQH,CAAQ,CAAA,CAAE,MAAA,CAC1C,CAACI,CAAAA,CAA0E,CAACC,CAAAA,CAAKC,CAAK,CAAA,GAAM,CAC1F,GAAID,CAAAA,GAAQP,CAAAA,EAAwBO,CAAAA,GAAQ,IAAA,EAAQA,CAAAA,GAAQ,YAAA,CAAc,CACxE,IAAME,CAAAA,CAAc,OAAOD,CAAAA,EAAU,QAAA,CAAYA,CAAAA,CAAMhC,CAAK,CAAA,EAAKgC,CAAAA,CAAMxB,CAAY,CAAA,CAAKwB,CAAAA,CAExFF,CAAAA,CAAIC,CAAG,CAAA,CAAIE,EACb,CAEA,OAAOH,CACT,CAAA,CACA,EACF,CAAA,CAEA,OAAO,CACL,GAAA,CAAKJ,CAAAA,CAAS,EAAA,CACd,WAAA,CAAaD,CAAAA,CACb,iBAAA,CAAmBH,CAAAA,CACnB,CAACE,CAAoB,EAAGI,CAAAA,CACxB,GAAGC,CACL,CACF,CAAC,CACH,CAAC,CAAA,CACA,IAAA,EACL","file":"chunk-MLYKIVZC.js","sourcesContent":["'use client';\n\nimport { createContext, useContext, useReducer } from 'react';\nimport type { Dispatch, JSX, ReactNode } from 'react';\nimport type { ActionSetRelationship, ActionSetScope, AppContextType } from './types';\n\nexport const SCOPE_STORAGE_KEY = 'core.context.scope:';\n\nconst initialState = {\n breadcrumbs: [],\n isRouteLoading: false,\n pageTitle: '',\n scope: '',\n relationships: {},\n};\n\nconst AppContext = createContext<AppContextType>(initialState);\n\nconst AppDispatchContext = createContext<Dispatch<ActionSetRelationship | ActionSetScope>>(() => {\n /* void */\n});\n\nfunction reducer(state: AppContextType, action: ActionSetRelationship | ActionSetScope): AppContextType {\n const { type, payload } = action;\n\n switch (type) {\n case 'setScope':\n if (typeof localStorage !== 'undefined' && payload.projectId) {\n localStorage.setItem(`${SCOPE_STORAGE_KEY}${payload.projectId}`, payload.scope);\n }\n\n return {\n ...state,\n scope: payload.scope,\n };\n case 'setRelationship':\n return {\n ...state,\n relationships: { ...state.relationships, ...payload },\n };\n default:\n throw Error(`Unknown action: ${type as string}`);\n }\n}\n\nexport function AppProvider({ children }: { children: ReactNode }): JSX.Element {\n const [state, dispatch] = useReducer(reducer, initialState);\n\n return (\n <AppContext.Provider value={state}>\n <AppDispatchContext.Provider value={dispatch}>{children}</AppDispatchContext.Provider>\n </AppContext.Provider>\n );\n}\n\nexport function useAppContext(): AppContextType {\n return useContext(AppContext);\n}\n\nexport function useAppDispatch(): Dispatch<ActionSetRelationship | ActionSetScope> {\n return useContext(AppDispatchContext);\n}\n","import type { Attribute, Entity } from './types';\n\n/**\n * Resolve the attribute used as the entity's human-readable label.\n * Uses `entity.display` when it matches an attribute name; otherwise the first attribute.\n * The effective display attribute must not be space-bound (enforced at define/deploy time).\n */\nexport function getDisplayAttribute(entity: Entity | undefined): Attribute | undefined {\n if (!entity?.attributes.length) {\n return undefined;\n }\n\n if (entity.display) {\n return entity.attributes.find((attr) => attr.name === entity.display) ?? entity.attributes[0];\n }\n\n return entity.attributes[0];\n}\n","'use client';\n\nimport { useMemo } from 'react';\nimport useSWR from 'swr';\nimport { find, propEq } from 'ramda';\nimport { apiPaths } from './api-paths';\nimport { useAppContext } from './app-context';\nimport { useConfig } from './config/config-context';\nimport type { SingleProject } from './config/types';\nimport { getDisplayAttribute } from './get-display-attribute';\nimport type { Entity, RawResultItem, RawSearchResultItems, SearchRequestProps, SearchResultItem } from './types';\n\nexport function useSearch(\n projectId: string,\n searchRequest: SearchRequestProps | null\n): { results: SearchResultItem[] | []; error: Error; isLoading: boolean } {\n const { scope } = useAppContext();\n const { projects, currentProjectId } = useConfig();\n const { schema, scopes } = find(propEq(currentProjectId ?? '', 'projectId'))(projects) as SingleProject;\n const defaultScope = scopes?.find((s) => s.isDefault)?.name ?? 'default';\n const swrKey = searchRequest?.commonParams.q ? JSON.stringify(searchRequest) : null;\n const { data, error, isLoading } = useSWR(swrKey, () =>\n fetch(apiPaths(projectId).search, {\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(searchRequest),\n method: 'POST',\n mode: 'cors',\n }).then((res) => res.json() as Promise<{ results: RawSearchResultItems }>)\n );\n const results = useMemo(\n () => mapResults(data?.results ?? [], projectId, schema, scope, defaultScope) ?? [],\n [data, defaultScope, projectId, schema, scope]\n );\n\n return { results, error, isLoading };\n}\n\nfunction mapResults(\n results: RawSearchResultItems | undefined,\n projectId: string,\n schema: Entity[],\n scope: string,\n defaultScope: string\n): SearchResultItem[] | undefined {\n return results\n ?.filter((result) => (result as RawResultItem)?.hits?.length > 0)\n .map((result) => {\n const item = result as RawResultItem;\n const entityNamePlural = item.collection.replace(`${projectId}_`, '').replace(/_\\d+$/, '');\n const entitySchema = find<Entity>(propEq(entityNamePlural, 'plural'))(schema);\n\n if (!entitySchema) {\n return [];\n }\n\n const primaryAttributeName = getDisplayAttribute(entitySchema)?.name ?? '';\n const entityName = entitySchema?.name ?? entityNamePlural;\n\n // iterate over the hits and return an object with the primary attribute value first and then the rest of the attributes.\n return item.hits.map(({ document }) => {\n const primaryAttribute = document[primaryAttributeName];\n const scopedPrimaryAttribute =\n primaryAttribute && typeof primaryAttribute !== 'string'\n ? (primaryAttribute[scope] ?? primaryAttribute[defaultScope])\n : null;\n const primaryAttributeValue = scopedPrimaryAttribute ?? document[primaryAttributeName];\n const attributes = Object.entries(document).reduce(\n (acc: Omit<SearchResultItem, '_id' | '_entityName' | '_entityNamePlural'>, [key, value]) => {\n if (key !== primaryAttributeName && key !== 'id' && key !== '_updatedAt') {\n const scopedValue = typeof value !== 'string' ? (value[scope] ?? value[defaultScope]) : value;\n\n acc[key] = scopedValue;\n }\n\n return acc;\n },\n {}\n );\n\n return {\n _id: document.id,\n _entityName: entityName,\n _entityNamePlural: entityNamePlural,\n [primaryAttributeName]: primaryAttributeValue as string,\n ...attributes,\n };\n });\n })\n .flat();\n}\n"]}
1
+ {"version":3,"sources":["../src/core/app-context.tsx","../src/core/get-display-attribute.ts","../src/core/use-search.tsx"],"names":["SCOPE_STORAGE_KEY","initialState","AppContext","createContext","AppDispatchContext","reducer","state","action","type","payload","AppProvider","children","dispatch","useReducer","jsx","useAppContext","useContext","useAppDispatch","getDisplayAttribute","entity","attr","useSearch","projectId","searchRequest","scope","projects","currentProjectId","useConfig","schema","scopes","find","propEq","defaultScope","s","swrKey","data","error","isLoading","useSWR","apiPaths","res","useMemo","mapResults","results","result","item","entityNamePlural","entitySchema","primaryAttributeName","entityName","document","primaryAttribute","primaryAttributeValue","attributes","acc","key","value","scopedValue"],"mappings":"mPAMO,IAAMA,CAAAA,CAAoB,qBAAA,CAE3BC,EAAe,CACnB,WAAA,CAAa,EAAC,CACd,cAAA,CAAgB,KAAA,CAChB,SAAA,CAAW,EAAA,CACX,KAAA,CAAO,EAAA,CACP,aAAA,CAAe,EACjB,CAAA,CAEMC,EAAaC,aAAAA,CAA8BF,CAAY,CAAA,CAEvDG,CAAAA,CAAqBD,aAAAA,CAAgE,IAAM,CAEjG,CAAC,EAED,SAASE,CAAAA,CAAQC,CAAAA,CAAuBC,CAAAA,CAAgE,CACtG,GAAM,CAAE,IAAA,CAAAC,CAAAA,CAAM,OAAA,CAAAC,CAAQ,CAAA,CAAIF,CAAAA,CAE1B,OAAQC,CAAAA,EACN,KAAK,UAAA,CACH,OAAI,OAAO,aAAiB,GAAA,EAAeC,CAAAA,CAAQ,SAAA,EACjD,YAAA,CAAa,OAAA,CAAQ,CAAA,EAAGT,CAAiB,CAAA,EAAGS,CAAAA,CAAQ,SAAS,CAAA,CAAA,CAAIA,CAAAA,CAAQ,KAAK,CAAA,CAGzE,CACL,GAAGH,CAAAA,CACH,KAAA,CAAOG,CAAAA,CAAQ,KACjB,CAAA,CACF,KAAK,iBAAA,CACH,OAAO,CACL,GAAGH,CAAAA,CACH,aAAA,CAAe,CAAE,GAAGA,CAAAA,CAAM,aAAA,CAAe,GAAGG,CAAQ,CACtD,CAAA,CACF,QACE,MAAM,KAAA,CAAM,CAAA,gBAAA,EAAmBD,CAAc,CAAA,CAAE,CACnD,CACF,CAE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mBH,CAAAA,CACnB,CAACE,CAAoB,EAAGI,CAAAA,CACxB,GAAGC,CACL,CACF,CAAC,CACH,CAAC,CAAA,CACA,IAAA,EACL","file":"chunk-JH4MVD36.js","sourcesContent":["'use client';\n\nimport { createContext, useContext, useReducer } from 'react';\nimport type { Dispatch, JSX, ReactNode } from 'react';\nimport type { ActionSetRelationship, ActionSetScope, AppContextType } from './types';\n\nexport const SCOPE_STORAGE_KEY = 'core.context.scope:';\n\nconst initialState = {\n breadcrumbs: [],\n isRouteLoading: false,\n pageTitle: '',\n scope: '',\n relationships: {},\n};\n\nconst AppContext = createContext<AppContextType>(initialState);\n\nconst AppDispatchContext = createContext<Dispatch<ActionSetRelationship | ActionSetScope>>(() => {\n /* void */\n});\n\nfunction reducer(state: AppContextType, action: ActionSetRelationship | ActionSetScope): AppContextType {\n const { type, payload } = action;\n\n switch (type) {\n case 'setScope':\n if (typeof localStorage !== 'undefined' && payload.projectId) {\n localStorage.setItem(`${SCOPE_STORAGE_KEY}${payload.projectId}`, payload.scope);\n }\n\n return {\n ...state,\n scope: payload.scope,\n };\n case 'setRelationship':\n return {\n ...state,\n relationships: { ...state.relationships, ...payload },\n };\n default:\n throw Error(`Unknown action: ${type as string}`);\n }\n}\n\nexport function AppProvider({ children }: { children: ReactNode }): JSX.Element {\n const [state, dispatch] = useReducer(reducer, initialState);\n\n return (\n <AppContext.Provider value={state}>\n <AppDispatchContext.Provider value={dispatch}>{children}</AppDispatchContext.Provider>\n </AppContext.Provider>\n );\n}\n\nexport function useAppContext(): AppContextType {\n return useContext(AppContext);\n}\n\nexport function useAppDispatch(): Dispatch<ActionSetRelationship | ActionSetScope> {\n return useContext(AppDispatchContext);\n}\n","import type { Attribute, Entity } from './types';\n\n/**\n * Resolve the attribute used as the entity's human-readable label.\n * Uses `entity.display` when it matches an attribute name; otherwise the first attribute.\n * The effective display attribute must not be space-bound (enforced at define/deploy time).\n */\nexport function getDisplayAttribute(entity: Entity | undefined): Attribute | undefined {\n if (!entity?.attributes.length) {\n return undefined;\n }\n\n if (entity.display) {\n return entity.attributes.find((attr) => attr.name === entity.display) ?? entity.attributes[0];\n }\n\n return entity.attributes[0];\n}\n","'use client';\n\nimport { useMemo } from 'react';\nimport useSWR from 'swr';\nimport { find, propEq } from 'ramda';\nimport { apiPaths } from './api-paths';\nimport { useAppContext } from './app-context';\nimport { useConfig } from './config/config-context';\nimport type { SingleProject } from './config/types';\nimport { getDisplayAttribute } from './get-display-attribute';\nimport type { Entity, RawResultItem, RawSearchResultItems, SearchRequestProps, SearchResultItem } from './types';\n\nexport function useSearch(\n projectId: string,\n searchRequest: SearchRequestProps | null\n): { results: SearchResultItem[] | []; error: Error; isLoading: boolean } {\n const { scope } = useAppContext();\n const { projects, currentProjectId } = useConfig();\n const { schema, scopes } = find(propEq(currentProjectId ?? '', 'projectId'))(projects) as SingleProject;\n const defaultScope = scopes?.find((s) => s.isDefault)?.name ?? 'default';\n const swrKey = searchRequest?.commonParams.q ? JSON.stringify(searchRequest) : null;\n const { data, error, isLoading } = useSWR(swrKey, () =>\n fetch(apiPaths(projectId).search, {\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(searchRequest),\n method: 'POST',\n mode: 'cors',\n }).then((res) => res.json() as Promise<{ results: RawSearchResultItems }>)\n );\n const results = useMemo(\n () => mapResults(data?.results ?? [], projectId, schema, scope, defaultScope) ?? [],\n [data, defaultScope, projectId, schema, scope]\n );\n\n return { results, error, isLoading };\n}\n\nfunction mapResults(\n results: RawSearchResultItems | undefined,\n projectId: string,\n schema: Entity[],\n scope: string,\n defaultScope: string\n): SearchResultItem[] | undefined {\n return results\n ?.filter((result) => (result as RawResultItem)?.hits?.length > 0)\n .map((result) => {\n const item = result as RawResultItem;\n const entityNamePlural = item.collection.replace(`${projectId}_`, '').replace(/_\\d+$/, '');\n const entitySchema = find<Entity>(propEq(entityNamePlural, 'plural'))(schema);\n\n if (!entitySchema) {\n return [];\n }\n\n const primaryAttributeName = getDisplayAttribute(entitySchema)?.name ?? '';\n const entityName = entitySchema?.name ?? entityNamePlural;\n\n // iterate over the hits and return an object with the primary attribute value first and then the rest of the attributes.\n return item.hits.map(({ document }) => {\n const primaryAttribute = document[primaryAttributeName];\n const scopedPrimaryAttribute =\n primaryAttribute && typeof primaryAttribute !== 'string'\n ? (primaryAttribute[scope] ?? primaryAttribute[defaultScope])\n : null;\n const primaryAttributeValue = scopedPrimaryAttribute ?? document[primaryAttributeName];\n const attributes = Object.entries(document).reduce(\n (acc: Omit<SearchResultItem, '_id' | '_entityName' | '_entityNamePlural'>, [key, value]) => {\n if (key !== primaryAttributeName && key !== 'id' && key !== '_updatedAt') {\n const scopedValue = typeof value !== 'string' ? (value[scope] ?? value[defaultScope]) : value;\n\n acc[key] = scopedValue;\n }\n\n return acc;\n },\n {}\n );\n\n return {\n _id: document.id,\n _entityName: entityName,\n _entityNamePlural: entityNamePlural,\n [primaryAttributeName]: primaryAttributeValue as string,\n ...attributes,\n };\n });\n })\n .flat();\n}\n"]}
@@ -1,2 +1,2 @@
1
- import'./index.css';import {createContext,useMemo,useContext}from'react';import {path,has}from'ramda';import {useParams}from'react-router-dom';import {jsx}from'react/jsx-runtime';var c={name:"_asset",plural:"_assets",display:"originalFilename",menu:{hidden:true},attributes:[{name:"path",label:"Asset",scope:"global",options:{size:140},dataType:"string",inputType:"text",previewType:"assetPreviewField",defaultValue:""},{name:"originalFilename",label:"Filename",scope:"global",options:{size:320},dataType:"string",inputType:"text",previewType:"text",defaultValue:""},{name:"size",label:"Size",scope:"global",options:{size:120},dataType:"int",inputType:"text",previewType:"text",defaultValue:""},{name:"width",label:"Width",scope:"global",options:{size:90},dataType:"int",inputType:"text",previewType:"text",defaultValue:""},{name:"height",label:"Height",scope:"global",options:{size:100},dataType:"int",inputType:"text",previewType:"text",defaultValue:""},{name:"mimeType",label:"Mime Type",scope:"global",options:{size:160},dataType:"string",inputType:"text",previewType:"text",defaultValue:""},{name:"lqip",label:"lqip",scope:"global",hidden:true,dataType:"string",inputType:"text",previewType:"text",defaultValue:""},{name:"url",label:"URL",scope:"global",hidden:true,readOnly:true,dataType:"string",inputType:"text",previewType:"text",defaultValue:""},{name:"_updatedAt",label:"Updated At",scope:"global",options:{size:220},readOnly:true,hidden:true,dataType:"datetime",inputType:"datetime",previewType:"datetime",defaultValue:""},{name:"tags",label:"Tags",scope:"relationship",dataType:"string",inputType:"relationship",defaultValue:"",previewType:"tags",options:{size:300},relationship:{mode:"multiple",field:"name",entity:"_tag"}}]};var d={name:"_tag",plural:"_tags",display:"name",menu:{hidden:true},attributes:[{name:"name",label:"Tag Name",scope:"global",options:{size:220},dataType:"string",inputType:"text",previewType:"text",defaultValue:""},{name:"_updatedAt",label:"Updated At",scope:"global",options:{size:220},readOnly:true,hidden:true,dataType:"datetime",inputType:"datetime",previewType:"datetime",defaultValue:""},{name:"assets",label:"Assets",scope:"relationship",dataType:"string",inputType:"relationship",defaultValue:"",relationship:{mode:"multiple",field:"originalFilename",entity:"_asset"}}]};var T=createContext({contributions:{apps:[]},currentProjectId:void 0,currentProjectSchema:[],getContributionPointConfig:()=>[],plugins:[],projects:[]}),l=n=>Object.prototype.hasOwnProperty.call(n,"projectId"),g=n=>Object.prototype.hasOwnProperty.call(n,"contributes");function F({config:n,children:o}){let{projectId:i}=useParams(),t=useMemo(()=>{let e=s=>[...s.filter(P=>P.name!==c.name&&P.name!==d.name),c,d];return n.map(s=>({...s,schema:e(s.schema)}))},[n]),p=useMemo(()=>r(["plugins"],t),[t]),m=useMemo(()=>r(["plugins"],t.filter(e=>e.projectId===i)),[t,i]),f=useMemo(()=>p.filter(e=>!l(e)&&g(e)),[p]),u=useMemo(()=>m.filter(e=>!l(e)&&g(e)),[m]),O=useMemo(()=>({contributions:{apps:y("apps",[],u)},currentProjectId:i,currentProjectSchema:t.find(e=>e.projectId===i)?.schema??[],getContributionPointConfig:(e,s=[])=>y(e,s,u),plugins:f,projects:p.filter(e=>l(e))}),[f,i,u,t,p]);return jsx(T.Provider,{value:O,children:o})}function R(){return useContext(T)}function r(n,o){return Array.isArray(o)?o.reduce((i,t)=>path(n,t)?[...i,t,...r(n,path(n,t)??[])]:[...i,t],[]):[o]}function y(n,o=[],i){let t=["contributes",n,...o];return r(t.flat(),i).filter(p=>has("component",p))}function N(n){let i=r(["plugins"],n).filter(t=>!l(t)&&g(t));return y("apps",[],i)}export{c as a,d as b,F as c,R as d,N as e};//# sourceMappingURL=chunk-2OBWJ6UY.js.map
2
- //# sourceMappingURL=chunk-2OBWJ6UY.js.map
1
+ import'./index.css';import {createContext,useMemo,useContext}from'react';import {path,has}from'ramda';import {useParams}from'react-router-dom';import {jsx}from'react/jsx-runtime';var d={name:"_asset",plural:"_assets",display:"originalFilename",menu:{hidden:true},attributes:[{name:"path",label:"Asset",scope:"global",options:{size:140},dataType:"string",inputType:"text",previewType:"assetPreviewField",defaultValue:""},{name:"originalFilename",label:"Filename",scope:"global",options:{size:320},dataType:"string",inputType:"text",previewType:"text",defaultValue:""},{name:"size",label:"Size",scope:"global",options:{size:120},dataType:"int",inputType:"text",previewType:"text",defaultValue:""},{name:"width",label:"Width",scope:"global",options:{size:90},dataType:"int",inputType:"text",previewType:"text",defaultValue:""},{name:"height",label:"Height",scope:"global",options:{size:100},dataType:"int",inputType:"text",previewType:"text",defaultValue:""},{name:"mimeType",label:"Mime Type",scope:"global",options:{size:160},dataType:"string",inputType:"text",previewType:"text",defaultValue:""},{name:"lqip",label:"lqip",scope:"global",hidden:true,dataType:"string",inputType:"text",previewType:"text",defaultValue:""},{name:"url",label:"URL",scope:"global",hidden:true,readOnly:true,dataType:"string",inputType:"text",previewType:"text",defaultValue:""},{name:"_updatedAt",label:"Updated At",scope:"global",options:{size:220},readOnly:true,hidden:true,dataType:"datetime",inputType:"datetime",previewType:"datetime",defaultValue:""},{name:"tags",label:"Tags",scope:"relationship",dataType:"string",inputType:"relationship",defaultValue:"",previewType:"tags",options:{size:300},relationship:{mode:"multiple",field:"name",entity:"_tag"}}]};var c={name:"_tag",plural:"_tags",display:"name",menu:{hidden:true},attributes:[{name:"name",label:"Tag Name",scope:"global",options:{size:220},dataType:"string",inputType:"text",previewType:"text",defaultValue:""},{name:"_updatedAt",label:"Updated At",scope:"global",options:{size:220},readOnly:true,hidden:true,dataType:"datetime",inputType:"datetime",previewType:"datetime",defaultValue:""},{name:"assets",label:"Assets",scope:"relationship",dataType:"string",inputType:"relationship",defaultValue:"",relationship:{mode:"multiple",field:"originalFilename",entity:"_asset"}}]};var T=createContext({contributions:{apps:[]},currentProjectId:void 0,currentProjectSchema:[],getContributionPointConfig:()=>[],extensions:[],projects:[]}),l=n=>Object.prototype.hasOwnProperty.call(n,"projectId"),y=n=>Object.prototype.hasOwnProperty.call(n,"contributes");function F({config:n,children:i}){let{projectId:o}=useParams(),t=useMemo(()=>{let e=a=>[...a.filter(x=>x.name!==d.name&&x.name!==c.name),d,c];return n.map(a=>({...a,schema:e(a.schema)}))},[n]),s=useMemo(()=>p(["extensions"],t),[t]),f=useMemo(()=>p(["extensions"],t.filter(e=>e.projectId===o)),[t,o]),g=useMemo(()=>s.filter(e=>!l(e)&&y(e)),[s]),u=useMemo(()=>f.filter(e=>!l(e)&&y(e)),[f]),h=useMemo(()=>({contributions:{apps:m("apps",[],u)},currentProjectId:o,currentProjectSchema:t.find(e=>e.projectId===o)?.schema??[],getContributionPointConfig:(e,a=[])=>m(e,a,u),extensions:g,projects:s.filter(e=>l(e))}),[g,o,u,t,s]);return jsx(T.Provider,{value:h,children:i})}function R(){return useContext(T)}function p(n,i){return Array.isArray(i)?i.reduce((o,t)=>path(n,t)?[...o,t,...p(n,path(n,t)??[])]:[...o,t],[]):[i]}function m(n,i=[],o){let t=["contributes",n,...i];return p(t.flat(),o).filter(s=>has("component",s))}function k(n){let o=p(["extensions"],n).filter(t=>!l(t)&&y(t));return m("apps",[],o)}export{d as a,c as b,F as c,R as d,k as e};//# sourceMappingURL=chunk-LIV5RBWJ.js.map
2
+ //# sourceMappingURL=chunk-LIV5RBWJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/entities/assets-schema.ts","../src/entities/tags-schema.ts","../src/core/config/config-context.tsx"],"names":["assetSchema","tagSchema","ConfigContext","createContext","hasProjectIdProperty","configItem","hasContributesProperty","ConfigProvider","config","children","currentProjectId","useParams","enhancedConfig","useMemo","upsertReservedEntities","schema","entity","project","globalFlattenedConfig","flattenConfigByProperty","currentProjectFlattenedConfig","item","allExtensions","currentProjectExtensions","globalConfig","_getContributionPointConfig","contributionPoint","subPath","jsx","useConfig","useContext","property","acc","curr","path","pathArray","has","getApps","extensions"],"mappings":"mLAEO,IAAMA,EAAsB,CACjC,IAAA,CAAM,QAAA,CACN,MAAA,CAAQ,UACR,OAAA,CAAS,kBAAA,CACT,IAAA,CAAM,CACJ,OAAQ,IACV,CAAA,CACA,WAAY,CACV,CACE,KAAM,MAAA,CACN,KAAA,CAAO,OAAA,CACP,KAAA,CAAO,SACP,OAAA,CAAS,CACP,KAAM,GACR,CAAA,CACA,SAAU,QAAA,CACV,SAAA,CAAW,MAAA,CACX,WAAA,CAAa,oBACb,YAAA,CAAc,EAChB,EACA,CACE,IAAA,CAAM,mBACN,KAAA,CAAO,UAAA,CACP,KAAA,CAAO,QAAA,CACP,QAAS,CACP,IAAA,CAAM,GACR,CAAA,CACA,QAAA,CAAU,SACV,SAAA,CAAW,MAAA,CACX,WAAA,CAAa,MAAA,CACb,aAAc,EAChB,CAAA,CACA,CACE,IAAA,CAAM,MAAA,CACN,MAAO,MAAA,CACP,KAAA,CAAO,QAAA,CACP,OAAA,CAAS,CACP,IAAA,CAAM,GACR,EACA,QAAA,CAAU,KAAA,CACV,UAAW,MAAA,CACX,WAAA,CAAa,MAAA,CACb,YAAA,CAAc,EAChB,CAAA,CACA,CACE,KAAM,OAAA,CACN,KAAA,CAAO,QACP,KAAA,CAAO,QAAA,CACP,OAAA,CAAS,CACP,KAAM,EACR,CAAA,CACA,SAAU,KAAA,CACV,SAAA,CAAW,OACX,WAAA,CAAa,MAAA,C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,GAAGC,CAAO,CAAA,CAE/D,OAAOR,CAAAA,CAAwBgB,CAAAA,CAAU,MAAK,CAAG3B,CAAM,EAAE,MAAA,CAAQa,CAAAA,EAC/De,IAAI,WAAA,CAAaf,CAAI,CACvB,CACF,CAEO,SAASgB,CAAAA,CAAQ7B,EAA6C,CAEnE,IAAM8B,EADkBnB,CAAAA,CAAwB,CAAC,YAAY,CAAA,CAAGX,CAAM,CAAA,CACnC,MAAA,CAChCa,GAA2C,CAACjB,CAAAA,CAAqBiB,CAAI,CAAA,EAAKf,CAAAA,CAAuBe,CAAI,CACxG,EACA,OAAOI,CAAAA,CAA4B,OAAQ,EAAC,CAAGa,CAAU,CAC3D","file":"chunk-LIV5RBWJ.js","sourcesContent":["import type { Entity } from '../core/types';\n\nexport const assetSchema: Entity = {\n name: '_asset',\n plural: '_assets',\n display: 'originalFilename',\n menu: {\n hidden: true,\n },\n attributes: [\n {\n name: 'path',\n label: 'Asset',\n scope: 'global',\n options: {\n size: 140,\n },\n dataType: 'string',\n inputType: 'text',\n previewType: 'assetPreviewField',\n defaultValue: '',\n },\n {\n name: 'originalFilename',\n label: 'Filename',\n scope: 'global',\n options: {\n size: 320,\n },\n dataType: 'string',\n inputType: 'text',\n previewType: 'text',\n defaultValue: '',\n },\n {\n name: 'size',\n label: 'Size',\n scope: 'global',\n options: {\n size: 120,\n },\n dataType: 'int',\n inputType: 'text',\n previewType: 'text',\n defaultValue: '',\n },\n {\n name: 'width',\n label: 'Width',\n scope: 'global',\n options: {\n size: 90,\n },\n dataType: 'int',\n inputType: 'text',\n previewType: 'text',\n defaultValue: '',\n },\n {\n name: 'height',\n label: 'Height',\n scope: 'global',\n options: {\n size: 100,\n },\n dataType: 'int',\n inputType: 'text',\n previewType: 'text',\n defaultValue: '',\n },\n {\n name: 'mimeType',\n label: 'Mime Type',\n scope: 'global',\n options: {\n size: 160,\n },\n dataType: 'string',\n inputType: 'text',\n previewType: 'text',\n defaultValue: '',\n },\n {\n name: 'lqip',\n label: 'lqip',\n scope: 'global',\n hidden: true,\n dataType: 'string',\n inputType: 'text',\n previewType: 'text',\n defaultValue: '',\n },\n {\n name: 'url',\n label: 'URL',\n scope: 'global',\n hidden: true,\n readOnly: true,\n dataType: 'string',\n inputType: 'text',\n previewType: 'text',\n defaultValue: '',\n },\n {\n name: '_updatedAt',\n label: 'Updated At',\n scope: 'global',\n options: {\n size: 220,\n },\n readOnly: true,\n hidden: true,\n dataType: 'datetime',\n inputType: 'datetime',\n previewType: 'datetime',\n defaultValue: '',\n },\n {\n name: 'tags',\n label: 'Tags',\n scope: 'relationship',\n dataType: 'string',\n inputType: 'relationship',\n defaultValue: '',\n previewType: 'tags',\n options: {\n size: 300,\n },\n relationship: {\n mode: 'multiple',\n field: 'name',\n entity: '_tag',\n },\n },\n ],\n};\n","import type { Entity } from '../core/types';\n\nexport const tagSchema: Entity = {\n name: '_tag',\n plural: '_tags',\n display: 'name',\n menu: {\n hidden: true,\n },\n attributes: [\n {\n name: 'name',\n label: 'Tag Name',\n scope: 'global',\n options: {\n size: 220,\n },\n dataType: 'string',\n inputType: 'text',\n previewType: 'text',\n defaultValue: '',\n },\n {\n name: '_updatedAt',\n label: 'Updated At',\n scope: 'global',\n options: {\n size: 220,\n },\n readOnly: true,\n hidden: true,\n dataType: 'datetime',\n inputType: 'datetime',\n previewType: 'datetime',\n defaultValue: '',\n },\n {\n name: 'assets',\n label: 'Assets',\n scope: 'relationship',\n dataType: 'string',\n inputType: 'relationship',\n defaultValue: '',\n relationship: {\n mode: 'multiple',\n field: 'originalFilename',\n entity: '_asset',\n },\n },\n ],\n};\n","'use client';\n\nimport { createContext, useContext, useMemo } from 'react';\nimport type { JSX } from 'react';\nimport { has, path } from 'ramda';\nimport { useParams } from 'react-router-dom';\nimport { assetSchema } from '../../entities/assets-schema';\nimport { tagSchema } from '../../entities/tags-schema';\nimport type { AppOptions, StudioExtension, StudioContributions, ProjectOptions } from './types';\nimport type { Entity } from '../types';\n\nexport interface ConfigContext {\n contributions: {\n apps: AppOptions[] | [];\n };\n currentProjectId?: string;\n currentProjectSchema: Entity[];\n getContributionPointConfig: <T extends keyof StudioContributions>(\n contributionPoint: T,\n subPath?: string[]\n ) => StudioContributions[T][] | [];\n extensions: StudioExtension[];\n projects: ProjectOptions[];\n}\n\nconst ConfigContext = createContext<ConfigContext>({\n contributions: {\n apps: [],\n },\n currentProjectId: undefined,\n currentProjectSchema: [],\n getContributionPointConfig: () => [],\n extensions: [] as StudioExtension[],\n projects: [] as ProjectOptions[],\n});\nconst hasProjectIdProperty = (configItem: ProjectOptions | StudioExtension): boolean =>\n Object.prototype.hasOwnProperty.call(configItem, 'projectId');\nconst hasContributesProperty = (configItem: ProjectOptions | StudioExtension): boolean =>\n Object.prototype.hasOwnProperty.call(configItem, 'contributes');\n\nexport function ConfigProvider({\n config,\n children,\n}: {\n config: ProjectOptions[];\n children: React.ReactNode;\n}): JSX.Element {\n /**\n * Getting the projectId from the URL via react-router-dom's useParams hook triggers a rerender of this Context\n * every time the URL changes.\n */\n const { projectId: currentProjectId } = useParams<{ projectId: string }>();\n const enhancedConfig = useMemo(() => {\n const upsertReservedEntities = (schema: Entity[]): Entity[] => {\n const withoutReserved = schema.filter(\n (entity) => entity.name !== assetSchema.name && entity.name !== tagSchema.name\n );\n\n return [...withoutReserved, assetSchema, tagSchema];\n };\n\n return config.map((project) => ({\n ...project,\n schema: upsertReservedEntities(project.schema),\n }));\n }, [config]);\n\n const globalFlattenedConfig = useMemo(\n () => flattenConfigByProperty(['extensions'], enhancedConfig),\n [enhancedConfig]\n );\n const currentProjectFlattenedConfig = useMemo(\n () =>\n flattenConfigByProperty(\n ['extensions'],\n enhancedConfig.filter((item) => item.projectId === currentProjectId)\n ),\n [enhancedConfig, currentProjectId]\n );\n const allExtensions = useMemo(\n () =>\n globalFlattenedConfig.filter(\n (item: ProjectOptions | StudioExtension) => !hasProjectIdProperty(item) && hasContributesProperty(item)\n ) as StudioExtension[],\n [globalFlattenedConfig]\n );\n const currentProjectExtensions = useMemo(\n () =>\n currentProjectFlattenedConfig.filter(\n (item: ProjectOptions | StudioExtension) => !hasProjectIdProperty(item) && hasContributesProperty(item)\n ) as StudioExtension[],\n [currentProjectFlattenedConfig]\n );\n\n const globalConfig = useMemo(\n () => ({\n contributions: {\n apps: _getContributionPointConfig('apps', [], currentProjectExtensions) as AppOptions[] | [],\n },\n currentProjectId,\n currentProjectSchema: enhancedConfig.find((item) => item.projectId === currentProjectId)?.schema ?? [],\n getContributionPointConfig: <T extends keyof StudioContributions>(\n contributionPoint: T,\n subPath: string[] = []\n ): StudioContributions[T][] =>\n _getContributionPointConfig(contributionPoint, subPath, currentProjectExtensions) as StudioContributions[T][],\n extensions: allExtensions,\n projects: globalFlattenedConfig.filter((item: ProjectOptions | StudioExtension) =>\n hasProjectIdProperty(item)\n ) as ProjectOptions[],\n }),\n [allExtensions, currentProjectId, currentProjectExtensions, enhancedConfig, globalFlattenedConfig]\n );\n\n return <ConfigContext.Provider value={globalConfig}>{children}</ConfigContext.Provider>;\n}\n\nexport function useConfig(): ConfigContext {\n return useContext(ConfigContext);\n}\n\nfunction flattenConfigByProperty(\n property: string[],\n config: (ProjectOptions | StudioExtension)[]\n): (ProjectOptions | StudioExtension)[] | [] {\n if (!Array.isArray(config)) {\n return [config];\n }\n\n return config.reduce<(ProjectOptions | StudioExtension)[]>((acc, curr) => {\n if (path(property, curr)) {\n return [...acc, curr, ...flattenConfigByProperty(property, path(property, curr) ?? [])];\n }\n\n return [...acc, curr];\n }, []);\n}\n\nfunction _getContributionPointConfig<T extends keyof StudioContributions>(\n contributionPoint: T,\n subPath: string[] = [],\n config: StudioExtension[]\n): StudioContributions[T] {\n const pathArray = ['contributes', contributionPoint, ...subPath];\n\n return flattenConfigByProperty(pathArray.flat(), config).filter((item) =>\n has('component', item)\n ) as StudioContributions[T];\n}\n\nexport function getApps(config: ProjectOptions[]): AppOptions[] | [] {\n const flattenedConfig = flattenConfigByProperty(['extensions'], config);\n const extensions = flattenedConfig.filter(\n (item: ProjectOptions | StudioExtension) => !hasProjectIdProperty(item) && hasContributesProperty(item)\n ) as StudioExtension[];\n return _getContributionPointConfig('apps', [], extensions) as AppOptions[] | [];\n}\n"]}
@@ -1,2 +1,2 @@
1
- import'./index.css';import {d}from'./chunk-2OBWJ6UY.js';import {c as c$1}from'./chunk-WDRCARCP.js';import {createContext,useContext}from'react';import h from'swr';import {useParams}from'react-router-dom';import {jsx}from'react/jsx-runtime';function n(){let{projectId:e}=useParams(),{projects:t}=d(),r=t.find(s=>s.projectId===e)??t[0],{data:a,isLoading:d$1}=h(c$1(e??"").currentUser,s=>fetch(s,{mode:"cors",credentials:"include"}).then(o=>o.json()).then(o=>({...o,spaces:o.spaces??[]})));return [d$1,{user:a,logout:async()=>{await fetch(c$1(e??"").logout(r?.basePath??"/"),{method:"POST",mode:"cors",credentials:"include"}),await fetch("/api/flexkit/logout",{method:"GET",credentials:"include"}),window.location.reload();}}]}var c=createContext([true,{user:null,logout:()=>Promise.resolve()}]);function L({children:e}){let[t,r]=n();return jsx(c.Provider,{value:[t,r],children:e})}function j(){return useContext(c)}export{L as a,j as b};//# sourceMappingURL=chunk-ORY5DLME.js.map
2
- //# sourceMappingURL=chunk-ORY5DLME.js.map
1
+ import'./index.css';import {d}from'./chunk-LIV5RBWJ.js';import {c as c$1}from'./chunk-WDRCARCP.js';import {createContext,useContext}from'react';import h from'swr';import {useParams}from'react-router-dom';import {jsx}from'react/jsx-runtime';function n(){let{projectId:e}=useParams(),{projects:t}=d(),r=t.find(s=>s.projectId===e)??t[0],{data:a,isLoading:d$1}=h(c$1(e??"").currentUser,s=>fetch(s,{mode:"cors",credentials:"include"}).then(o=>o.json()).then(o=>({...o,spaces:o.spaces??[]})));return [d$1,{user:a,logout:async()=>{await fetch(c$1(e??"").logout(r?.basePath??"/"),{method:"POST",mode:"cors",credentials:"include"}),await fetch("/api/flexkit/logout",{method:"GET",credentials:"include"}),window.location.reload();}}]}var c=createContext([true,{user:null,logout:()=>Promise.resolve()}]);function L({children:e}){let[t,r]=n();return jsx(c.Provider,{value:[t,r],children:e})}function j(){return useContext(c)}export{L as a,j as b};//# sourceMappingURL=chunk-WJ4ORIXF.js.map
2
+ //# sourceMappingURL=chunk-WJ4ORIXF.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/auth/use-auth-service.ts","../src/auth/auth-context.tsx"],"names":["useAuthService","projectId","useParams","projects","useConfig","currentProject","project","user","isLoadingUser","useSWR","apiPaths","url","res","data","AuthContext","createContext","AuthProvider","children","isLoading","auth","jsx","useAuth","useContext"],"mappings":"gPAQe,SAARA,CAAAA,EAA+C,CACpD,GAAM,CAAE,SAAA,CAAAC,CAAU,CAAA,CAAIC,SAAAA,EAAU,CAC1B,CAAE,SAAAC,CAAS,CAAA,CAAIC,GAAU,CACzBC,CAAAA,CAAiBF,EAAS,IAAA,CAAMG,CAAAA,EAAYA,EAAQ,SAAA,GAAcL,CAAS,GAAKE,CAAAA,CAAS,CAAC,EAC1F,CAAE,IAAA,CAAMI,EAAM,SAAA,CAAWC,GAAc,CAAA,CAAIC,CAAAA,CAAOC,IAAST,CAAAA,EAAa,EAAE,EAAE,WAAA,CAAcU,CAAAA,EAC9F,MAAMA,CAAAA,CAAK,CAAE,KAAM,MAAA,CAAQ,WAAA,CAAa,SAAU,CAAC,CAAA,CAChD,KAAMC,CAAAA,EAAQA,CAAAA,CAAI,MAAuB,CAAA,CACzC,IAAA,CAAMC,CAAAA,GAAU,CAAE,GAAGA,CAAAA,CAAM,OAAQA,CAAAA,CAAK,MAAA,EAAU,EAAG,CAAA,CAAE,CAC5D,CAAA,CAGA,OAAO,CAFWL,GAAAA,CAIhB,CACE,KAAAD,CAAAA,CACA,MAAA,CAAQ,SAAY,CAElB,MAAM,KAAA,CAAMG,GAAAA,CAAST,GAAa,EAAE,CAAA,CAAE,OAAOI,CAAAA,EAAgB,QAAA,EAAY,GAAG,CAAA,CAAG,CAC7E,OAAQ,MAAA,CACR,IAAA,CAAM,OACN,WAAA,CAAa,SACf,CAAC,CAAA,CAGD,MAAM,MAAM,qBAAA,CAAuB,CAAE,MAAA,CAAQ,KAAA,CAAO,YAAa,SAAU,CAAC,EAE5E,MAAA,CAAO,QAAA,CAAS,SAClB,CACF,CACF,CACF,CChCA,IAAMS,CAAAA,CAAcC,aAAAA,CAAc,CAChC,IAAA,CACA,CACE,IAAA,CAAM,IAAA,CACN,OAAQ,IAAM,OAAA,CAAQ,SACxB,CACF,CAAC,CAAA,CAEM,SAASC,EAAa,CAAE,QAAA,CAAAC,CAAS,CAAA,CAA+C,CACrF,GAAM,CAACC,CAAAA,CAAWC,CAAI,CAAA,CAAInB,CAAAA,EAAe,CAEzC,OAAOoB,IAACN,CAAAA,CAAY,QAAA,CAAZ,CAAqB,KAAA,CAAO,CAACI,EAAWC,CAAI,CAAA,CAAI,SAAAF,CAAAA,CAAS,CACnE,CAEO,SAASI,CAAAA,EAAuB,CACrC,OAAOC,UAAAA,CAAWR,CAAW,CAC/B","file":"chunk-ORY5DLME.js","sourcesContent":["'use client';\n\nimport useSWR from 'swr';\nimport { useParams } from 'react-router-dom';\nimport { apiPaths } from '../core/api-paths';\nimport { useConfig } from '../core/config/config-context';\nimport type { AuthService, User } from './types';\n\nexport default function useAuthService(): AuthService {\n const { projectId } = useParams();\n const { projects } = useConfig();\n const currentProject = projects.find((project) => project.projectId === projectId) ?? projects[0];\n const { data: user, isLoading: isLoadingUser } = useSWR(apiPaths(projectId ?? '').currentUser, (url: string) =>\n fetch(url, { mode: 'cors', credentials: 'include' })\n .then((res) => res.json() as Promise<User>)\n .then((data) => ({ ...data, spaces: data.spaces ?? [] }))\n );\n const isLoading = isLoadingUser;\n\n return [\n isLoading,\n {\n user,\n logout: async () => {\n // wipe remote session\n await fetch(apiPaths(projectId ?? '').logout(currentProject?.basePath ?? '/'), {\n method: 'POST',\n mode: 'cors',\n credentials: 'include',\n });\n\n // delete first-party auth cookie\n await fetch('/api/flexkit/logout', { method: 'GET', credentials: 'include' });\n\n window.location.reload();\n },\n },\n ];\n}\n","'use client';\n\nimport { createContext, JSX, useContext } from 'react';\nimport useAuthService from './use-auth-service';\nimport type { Auth, AuthService, User } from './types';\n\nconst AuthContext = createContext([\n true,\n {\n user: null as User | null,\n logout: () => Promise.resolve(),\n } as Auth,\n]);\n\nexport function AuthProvider({ children }: { children: React.ReactNode }): JSX.Element {\n const [isLoading, auth] = useAuthService();\n\n return <AuthContext.Provider value={[isLoading, auth]}>{children}</AuthContext.Provider>;\n}\n\nexport function useAuth(): AuthService {\n return useContext(AuthContext) as AuthService;\n}\n"]}
1
+ {"version":3,"sources":["../src/auth/use-auth-service.ts","../src/auth/auth-context.tsx"],"names":["useAuthService","projectId","useParams","projects","useConfig","currentProject","project","user","isLoadingUser","useSWR","apiPaths","url","res","data","AuthContext","createContext","AuthProvider","children","isLoading","auth","jsx","useAuth","useContext"],"mappings":"gPAQe,SAARA,CAAAA,EAA+C,CACpD,GAAM,CAAE,SAAA,CAAAC,CAAU,CAAA,CAAIC,SAAAA,EAAU,CAC1B,CAAE,SAAAC,CAAS,CAAA,CAAIC,GAAU,CACzBC,CAAAA,CAAiBF,EAAS,IAAA,CAAMG,CAAAA,EAAYA,EAAQ,SAAA,GAAcL,CAAS,GAAKE,CAAAA,CAAS,CAAC,EAC1F,CAAE,IAAA,CAAMI,EAAM,SAAA,CAAWC,GAAc,CAAA,CAAIC,CAAAA,CAAOC,IAAST,CAAAA,EAAa,EAAE,EAAE,WAAA,CAAcU,CAAAA,EAC9F,MAAMA,CAAAA,CAAK,CAAE,KAAM,MAAA,CAAQ,WAAA,CAAa,SAAU,CAAC,CAAA,CAChD,KAAMC,CAAAA,EAAQA,CAAAA,CAAI,MAAuB,CAAA,CACzC,IAAA,CAAMC,CAAAA,GAAU,CAAE,GAAGA,CAAAA,CAAM,OAAQA,CAAAA,CAAK,MAAA,EAAU,EAAG,CAAA,CAAE,CAC5D,CAAA,CAGA,OAAO,CAFWL,GAAAA,CAIhB,CACE,KAAAD,CAAAA,CACA,MAAA,CAAQ,SAAY,CAElB,MAAM,KAAA,CAAMG,GAAAA,CAAST,GAAa,EAAE,CAAA,CAAE,OAAOI,CAAAA,EAAgB,QAAA,EAAY,GAAG,CAAA,CAAG,CAC7E,OAAQ,MAAA,CACR,IAAA,CAAM,OACN,WAAA,CAAa,SACf,CAAC,CAAA,CAGD,MAAM,MAAM,qBAAA,CAAuB,CAAE,MAAA,CAAQ,KAAA,CAAO,YAAa,SAAU,CAAC,EAE5E,MAAA,CAAO,QAAA,CAAS,SAClB,CACF,CACF,CACF,CChCA,IAAMS,CAAAA,CAAcC,aAAAA,CAAc,CAChC,IAAA,CACA,CACE,IAAA,CAAM,IAAA,CACN,OAAQ,IAAM,OAAA,CAAQ,SACxB,CACF,CAAC,CAAA,CAEM,SAASC,EAAa,CAAE,QAAA,CAAAC,CAAS,CAAA,CAA+C,CACrF,GAAM,CAACC,CAAAA,CAAWC,CAAI,CAAA,CAAInB,CAAAA,EAAe,CAEzC,OAAOoB,IAACN,CAAAA,CAAY,QAAA,CAAZ,CAAqB,KAAA,CAAO,CAACI,EAAWC,CAAI,CAAA,CAAI,SAAAF,CAAAA,CAAS,CACnE,CAEO,SAASI,CAAAA,EAAuB,CACrC,OAAOC,UAAAA,CAAWR,CAAW,CAC/B","file":"chunk-WJ4ORIXF.js","sourcesContent":["'use client';\n\nimport useSWR from 'swr';\nimport { useParams } from 'react-router-dom';\nimport { apiPaths } from '../core/api-paths';\nimport { useConfig } from '../core/config/config-context';\nimport type { AuthService, User } from './types';\n\nexport default function useAuthService(): AuthService {\n const { projectId } = useParams();\n const { projects } = useConfig();\n const currentProject = projects.find((project) => project.projectId === projectId) ?? projects[0];\n const { data: user, isLoading: isLoadingUser } = useSWR(apiPaths(projectId ?? '').currentUser, (url: string) =>\n fetch(url, { mode: 'cors', credentials: 'include' })\n .then((res) => res.json() as Promise<User>)\n .then((data) => ({ ...data, spaces: data.spaces ?? [] }))\n );\n const isLoading = isLoadingUser;\n\n return [\n isLoading,\n {\n user,\n logout: async () => {\n // wipe remote session\n await fetch(apiPaths(projectId ?? '').logout(currentProject?.basePath ?? '/'), {\n method: 'POST',\n mode: 'cors',\n credentials: 'include',\n });\n\n // delete first-party auth cookie\n await fetch('/api/flexkit/logout', { method: 'GET', credentials: 'include' });\n\n window.location.reload();\n },\n },\n ];\n}\n","'use client';\n\nimport { createContext, JSX, useContext } from 'react';\nimport useAuthService from './use-auth-service';\nimport type { Auth, AuthService, User } from './types';\n\nconst AuthContext = createContext([\n true,\n {\n user: null as User | null,\n logout: () => Promise.resolve(),\n } as Auth,\n]);\n\nexport function AuthProvider({ children }: { children: React.ReactNode }): JSX.Element {\n const [isLoading, auth] = useAuthService();\n\n return <AuthContext.Provider value={[isLoading, auth]}>{children}</AuthContext.Provider>;\n}\n\nexport function useAuth(): AuthService {\n return useContext(AuthContext) as AuthService;\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React$1 from 'react';
2
2
  import React__default, { Dispatch, JSX, SetStateAction, UIEvent, ReactElement } from 'react';
3
- import { A as AppContextType, a as ActionSetRelationship, b as ActionSetScope, C as Config, c as AppOptions, E as Entity, P as PluginOptions, d as ProjectOptions, O as OrderedAssetValue, S as SearchRequestProps, e as SearchResultItem, f as Attribute, F as FieldGroup, g as AuthService, U as UseEntityQueryParams, M as MappedEntityItem, h as FormEntityItem, I as ImageValue, i as Schema, j as User, k as AttributeValue, l as MultipleRelationshipConnection, m as SingleRelationshipConnection } from './types.d-C12xWeN_.js';
4
- export { n as ConditionalFieldContext, o as ConditionalFlag, D as DataType, p as DefaultValue, q as DefaultValueByDataType, r as EntityData, s as FormFieldParams, t as FormFieldProps, u as FormFieldValue, L as LogoProps, v as ScopeType, w as SingleProject } from './types.d-C12xWeN_.js';
3
+ import { A as AppContextType, a as ActionSetRelationship, b as ActionSetScope, C as Config, c as AppOptions, E as Entity, S as StudioContributions, d as StudioExtension, P as ProjectOptions, O as OrderedAssetValue, e as SearchRequestProps, f as SearchResultItem, g as Attribute, F as FieldGroup, h as AuthService, U as UseEntityQueryParams, M as MappedEntityItem, i as FormEntityItem, I as ImageValue, j as Schema, k as User, l as AttributeValue, m as MultipleRelationshipConnection, n as SingleRelationshipConnection } from './types.d-9Gbw_A9L.js';
4
+ export { o as ConditionalFieldContext, p as ConditionalFlag, D as DataType, q as DefaultValue, r as DefaultValueByDataType, s as EntityData, t as FormFieldParams, u as FormFieldProps, v as FormFieldValue, L as LogoProps, w as ScopeType, x as SingleProject } from './types.d-9Gbw_A9L.js';
5
5
  export { Outlet, useLocation, useParams } from 'react-router-dom';
6
6
  import { OperationVariables, DocumentNode, ErrorLike } from '@apollo/client';
7
7
  export { gql } from '@apollo/client';
@@ -36,15 +36,14 @@ declare function FlexkitStudio({ config }: {
36
36
  config: Config;
37
37
  }): JSX.Element | null;
38
38
 
39
- type Contributes = NonNullable<PluginOptions['contributes']>;
40
39
  interface ConfigContext {
41
40
  contributions: {
42
41
  apps: AppOptions[] | [];
43
42
  };
44
43
  currentProjectId?: string;
45
44
  currentProjectSchema: Entity[];
46
- getContributionPointConfig: <T extends keyof Contributes>(contributionPoint: T, subPath?: string[]) => Contributes[T][] | [];
47
- plugins: PluginOptions[];
45
+ getContributionPointConfig: <T extends keyof StudioContributions>(contributionPoint: T, subPath?: string[]) => StudioContributions[T][] | [];
46
+ extensions: StudioExtension[];
48
47
  projects: ProjectOptions[];
49
48
  }
50
49
  declare function useConfig(): ConfigContext;
@@ -92,6 +91,9 @@ declare function useSearch(projectId: string, searchRequest: SearchRequestProps
92
91
 
93
92
  declare function defineConfig<T extends Config>(config: T): T;
94
93
 
94
+ /** Define a Studio extension while preserving its specific contribution types. */
95
+ declare function defineExtension<T extends StudioExtension>(extension: T): T;
96
+
95
97
  declare function defineEntity<T extends Entity>(entity: T): Entity;
96
98
 
97
99
  /**
@@ -392,4 +394,4 @@ declare const assetSchema: Entity;
392
394
 
393
395
  declare const tagSchema: Entity;
394
396
 
395
- export { ALL_FIELDS_GROUP, ALL_FIELDS_GROUP_NAME, AppOptions, Attribute, AttributeValue, type ConfigContext, DataTable, DataTableColumnHeader, DataTableFacetedFilter, DataTableRowActions, DataTableSortedBy, DataTableToolbar, DataTableViewOptions, DefaultValueSwitch, Entity, type EntityListRowPatch, FieldGroup, FlexkitStudio, FormEntityItem, IMAGES_BASE_URL, MappedEntityItem, PluginOptions, ProjectDisabled, Schema, SchemaError, SearchRequestProps, SearchResultItem, type UploadedFileResult, assetSchema, canAccessSpaces, canMutateData, defineConfig, defineEntity, filterAttributesForSpaces, filterEntitiesForSpaces, getEntityCreateMutation, getEntityDeleteMutation, getEntityDeleteWhere, getEntityQuery, getEntitySchema, getEntityUpdateMutation, getSortNotNullWhere, tagSchema, useAppContext, useAppDispatch, useAuth, useCanMutate, useConfig, useDispatch, useEntityMutation, useEntityQuery, useGraphQLError, useGridColumnsDefinition, usePatchEntityList, useRefreshEntityList, useSearch, useUploadAssets };
397
+ export { ALL_FIELDS_GROUP, ALL_FIELDS_GROUP_NAME, AppOptions, Attribute, AttributeValue, type ConfigContext, DataTable, DataTableColumnHeader, DataTableFacetedFilter, DataTableRowActions, DataTableSortedBy, DataTableToolbar, DataTableViewOptions, DefaultValueSwitch, Entity, type EntityListRowPatch, FieldGroup, FlexkitStudio, FormEntityItem, IMAGES_BASE_URL, MappedEntityItem, ProjectDisabled, Schema, SchemaError, SearchRequestProps, SearchResultItem, StudioContributions, StudioExtension, type UploadedFileResult, assetSchema, canAccessSpaces, canMutateData, defineConfig, defineEntity, defineExtension, filterAttributesForSpaces, filterEntitiesForSpaces, getEntityCreateMutation, getEntityDeleteMutation, getEntityDeleteWhere, getEntityQuery, getEntitySchema, getEntityUpdateMutation, getSortNotNullWhere, tagSchema, useAppContext, useAppDispatch, useAuth, useCanMutate, useConfig, useDispatch, useEntityMutation, useEntityQuery, useGraphQLError, useGridColumnsDefinition, usePatchEntityList, useRefreshEntityList, useSearch, useUploadAssets };