|
|
|
@ -73,18 +73,32 @@ const componentInstanceToBindable = walkResult => i => { |
|
|
|
|
|
|
|
const contextToBindables = (models, walkResult) => context => { |
|
|
|
const contextParentPath = getParentPath(walkResult, context) |
|
|
|
const isModel = context.model?.isModel || typeof context.model === "string" |
|
|
|
const modelId = |
|
|
|
typeof context.model === "string" ? context.model : context.model.modelId |
|
|
|
const model = models.find(model => model._id === modelId) |
|
|
|
|
|
|
|
let model, schema |
|
|
|
if (typeof context.model === "string" || context.model.type === "model") { |
|
|
|
const modelId = |
|
|
|
typeof context.model === "string" ? context.model : context.model.modelId |
|
|
|
model = models.find(model => model._id === modelId) |
|
|
|
schema = model?.schema |
|
|
|
} else if (context.model.type === "view") { |
|
|
|
const modelId = context.model.modelId |
|
|
|
model = models.find(model => model._id === modelId) |
|
|
|
schema = model?.views?.[context.model.name]?.schema |
|
|
|
} else if (context.model.type === "link") { |
|
|
|
console.log(context.model) |
|
|
|
const modelId = context.model.modelId |
|
|
|
model = models.find(model => model._id === modelId) |
|
|
|
schema = model?.schema |
|
|
|
} |
|
|
|
|
|
|
|
// Avoid crashing whenever no data source has been selected
|
|
|
|
if (model == null) { |
|
|
|
if (!schema) { |
|
|
|
return [] |
|
|
|
} |
|
|
|
|
|
|
|
const newBindable = key => ({ |
|
|
|
const newBindable = ([key, fieldSchema]) => ({ |
|
|
|
type: "context", |
|
|
|
fieldSchema, |
|
|
|
instance: context.instance, |
|
|
|
// how the binding expression persists, and is used in the app at runtime
|
|
|
|
runtimeBinding: `${contextParentPath}data.${key}`, |
|
|
|
@ -92,15 +106,11 @@ const contextToBindables = (models, walkResult) => context => { |
|
|
|
readableBinding: `${context.instance._instanceName}.${model.name}.${key}`, |
|
|
|
}) |
|
|
|
|
|
|
|
// see ModelViewSelect.svelte for the format of context.model
|
|
|
|
// ... this allows us to bind to Model schemas, or View schemas
|
|
|
|
const schema = isModel ? model.schema : model.views[context.model.name].schema |
|
|
|
|
|
|
|
return ( |
|
|
|
Object.keys(schema) |
|
|
|
Object.entries(schema) |
|
|
|
.map(newBindable) |
|
|
|
// add _id and _rev fields - not part of schema, but always valid
|
|
|
|
.concat([newBindable("_id"), newBindable("_rev")]) |
|
|
|
.concat([newBindable(["_id", "string"]), newBindable(["_rev", "string"])]) |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
|