@fugood/bricks-project 2.21.0-beta.14.test8 → 2.21.0-beta.16

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/api/instance.ts CHANGED
@@ -6,7 +6,7 @@ const apiUrlMap = {
6
6
 
7
7
  const workspaceToken = process.env.BRICKS_WORKSPACE_TOKEN
8
8
 
9
- type Stage = 'production' | 'beta' | 'dev'
9
+ type Stage = 'production' | 'beta' | 'development'
10
10
 
11
11
  const doGQL = async (stage: Stage, query: string, variables: Record<string, any>) => {
12
12
  if (!workspaceToken) throw new Error('env BRICKS_WORKSPACE_TOKEN is not set')
package/compile/index.ts CHANGED
@@ -7,6 +7,7 @@ import { templateActionNameMap } from './action-name-map'
7
7
  import type {
8
8
  Application,
9
9
  Data,
10
+ DataAssetKind,
10
11
  Animation,
11
12
  AnimationDef,
12
13
  AnimationComposeDef,
@@ -98,23 +99,27 @@ const compileEvents = (
98
99
  if (Object.hasOwn(action, 'params')) {
99
100
  const actionDef = action as ActionWithParams
100
101
  ;(actionDef.params || []).forEach(({ input, value, mapping }) => {
101
- parameterList.push({
102
+ const param = {
102
103
  [camelCase ? 'inputToReceiver' : 'input_to_receiver']: handlerTemplateKey
103
104
  ? compileActionParam(handlerTemplateKey, action.__actionName, input)
104
105
  : input,
105
- [camelCase ? 'resultFromSender' : 'result_from_sender']: compileProperty(value),
106
- [camelCase ? 'resultDataMapping' : 'result_data_mapping']: mapping,
107
- })
106
+ [camelCase ? 'resultFromSender' : 'result_from_sender']:
107
+ mapping || compileProperty(value),
108
+ }
109
+ if (mapping) param[camelCase ? 'resultDataMapping' : 'result_data_mapping'] = true
110
+ parameterList.push(param)
108
111
  })
109
112
  } else if (Object.hasOwn(action, 'dataParams')) {
110
113
  const actionDef = action as ActionWithDataParams
111
114
  ;(actionDef.dataParams || []).forEach(({ input, value, mapping }) => {
112
115
  if (!input) return
113
- parameterList.push({
116
+ const param = {
114
117
  [camelCase ? 'inputToReceiver' : 'input_to_receiver']: input().id,
115
- [camelCase ? 'resultFromSender' : 'result_from_sender']: compileProperty(value),
116
- [camelCase ? 'resultDataMapping' : 'result_data_mapping']: mapping,
117
- })
118
+ [camelCase ? 'resultFromSender' : 'result_from_sender']:
119
+ mapping || compileProperty(value),
120
+ }
121
+ if (mapping) param[camelCase ? 'resultDataMapping' : 'result_data_mapping'] = true
122
+ parameterList.push(param)
118
123
  })
119
124
  }
120
125
  return {
@@ -199,9 +204,37 @@ const compileFrame = (frame: Canvas['items'][number]['frame']) => ({
199
204
  render_out_of_viewport: frame.renderOutOfViewport,
200
205
  })
201
206
 
207
+ const preloadTypes = [
208
+ 'media-resource-image',
209
+ 'media-resource-video',
210
+ 'media-resource-audio',
211
+ 'media-resource-file',
212
+ 'lottie-file-uri',
213
+ 'ggml-model-asset',
214
+ 'gguf-model-asset',
215
+ 'binary-asset',
216
+ ]
217
+
202
218
  const compileKind = (kind: Data['kind']) => {
203
219
  const { type, ...rest } = kind || {}
204
220
  if (!type) return {}
221
+ if (preloadTypes.includes(type)) {
222
+ const { preload, metadata } = kind as DataAssetKind
223
+ const result: any = { kind: type, ...rest }
224
+ if (preload) {
225
+ result.preload = {
226
+ type: preload.type,
227
+ hashType: preload.hashType,
228
+ }
229
+ if (preload.hashType) result.preload[preload.hashType] = preload.hash
230
+ }
231
+ // Handle metadata
232
+ if (type === 'gguf-model-asset') {
233
+ result._hfRepoInfo = metadata?.hfRepoInfo
234
+ }
235
+ return result
236
+ }
237
+
205
238
  return { kind: type, ...rest }
206
239
  }
207
240
 
@@ -240,13 +273,26 @@ const compileModule = (subspace: Subspace) => {
240
273
  }
241
274
  }
242
275
 
243
- export const compile = (app: Application) => {
276
+ export const compile = async (app: Application) => {
277
+ await new Promise((resolve) => setImmediate(resolve, 0))
244
278
  const config = {
245
279
  title: app.name,
246
280
  subspace_map: app.subspaces.reduce((subspaceMap, subspace) => {
247
281
  subspaceMap[subspace.id] = {
248
282
  title: subspace.title,
249
283
  description: subspace.description,
284
+ _expanded: subspace.unexpanded
285
+ ? {
286
+ brick: !subspace.unexpanded.brick,
287
+ generator: !subspace.unexpanded.generator,
288
+ canvas: subspace.unexpanded.canvas?.reduce((acc, canvas) => {
289
+ acc[canvas.id] = canvas?.id ? false : true
290
+ return acc
291
+ }, {}),
292
+ property_bank: !subspace.unexpanded.data,
293
+ property_bank_calc: !subspace.unexpanded.dataCalculation,
294
+ }
295
+ : undefined,
250
296
  layout: {
251
297
  width: subspace.layout?.width,
252
298
  height: subspace.layout?.height,
@@ -289,6 +335,7 @@ export const compile = (app: Application) => {
289
335
  brickId: itemBrick.brickId,
290
336
  brickIdPrefix: itemBrick.brickIdPrefix,
291
337
  templateKey: itemBrick.templateKey,
338
+ frame: itemBrick.frame,
292
339
  property: compileProperty(itemBrick.property),
293
340
  propertyMapping: itemBrick.propertyMapping,
294
341
  animation: compileAnimations(itemBrick.templateKey, itemBrick.animation || {}),
@@ -382,6 +429,7 @@ export const compile = (app: Application) => {
382
429
  ? { brick_id: (item.item as () => Brick)()?.id }
383
430
  : { subspace_id: item.item }),
384
431
  frame: compileFrame(item.frame),
432
+ hidden: item.hidden,
385
433
  })),
386
434
  }
387
435
  return map
@@ -564,7 +612,13 @@ export const compile = (app: Application) => {
564
612
  const declarationBody = (
565
613
  (program.body[0] as ExportNamedDeclaration).declaration as FunctionDeclaration
566
614
  )?.body
567
- code = escodegen.generate(declarationBody)
615
+ code = escodegen.generate(declarationBody, {
616
+ format: {
617
+ indent: { style: ' ' },
618
+ semicolons: false,
619
+ },
620
+ comment: true,
621
+ })
568
622
  } catch (e) {
569
623
  code = scriptCalc.code || ''
570
624
  }
package/index.ts CHANGED
@@ -2,4 +2,4 @@ export type * from './types'
2
2
 
3
3
  export { makeId } from './utils/id'
4
4
  export { generateDataCalculationMapEditorInfo } from './utils/calc'
5
- export { linkData, useSystemData } from './utils/data'
5
+ export { linkData, useSystemData, createCanvasIdRef } from './utils/data'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fugood/bricks-project",
3
- "version": "2.21.0-beta.14.test8",
3
+ "version": "2.21.0-beta.16",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "build": "node scripts/build.js"
@@ -13,5 +13,5 @@
13
13
  "lodash": "^4.17.4",
14
14
  "uuid": "^8.3.1"
15
15
  },
16
- "devDependencies": {}
16
+ "gitHead": "5a3d442c4eca74ab88878feac51c927c3fdbd6f6"
17
17
  }
@@ -20,6 +20,7 @@ if (!previewUrl) throw new Error(`Invalid BRICKS_STAGE: ${stage}`)
20
20
 
21
21
  app.on('ready', () => {
22
22
  const mainWindow = new BrowserWindow({ width: 1280, height: 768 })
23
+ mainWindow.setBackgroundColor('#333')
23
24
  mainWindow.loadURL(previewUrl)
24
25
 
25
26
  const sendConfig = () => {
@@ -35,6 +36,8 @@ app.on('ready', () => {
35
36
 
36
37
  mainWindow.webContents.once('dom-ready', sendConfig)
37
38
 
39
+ mainWindow.on('close', () => app.quit())
40
+
38
41
  watchFile(
39
42
  `${cwd}/.bricks/build/application-config.json`,
40
43
  {
package/tools/preview.ts CHANGED
@@ -27,7 +27,7 @@ const compileDebounced = debounce(compile, 500)
27
27
 
28
28
  const cwd = process.cwd()
29
29
 
30
- watch(`${cwd}/subspaces`, { recursive: true }, async (event, filename) => {
30
+ const watcher = watch(`${cwd}/subspaces`, { recursive: true }, async (event, filename) => {
31
31
  console.log(`Detected ${event} in ${filename}`)
32
32
  compileDebounced()
33
33
  })
@@ -35,3 +35,4 @@ watch(`${cwd}/subspaces`, { recursive: true }, async (event, filename) => {
35
35
  const app = await Bun.file(`${cwd}/application.json`).json()
36
36
 
37
37
  await $`BRICKS_STAGE=${app.stage || 'production'} bunx electron ${__dirname}/preview-main.mjs`
38
+ watcher.close()