@fugood/bricks-project 2.21.0-beta.14.test10 → 2.21.0-beta.14.test12

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/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,
@@ -203,9 +204,37 @@ const compileFrame = (frame: Canvas['items'][number]['frame']) => ({
203
204
  render_out_of_viewport: frame.renderOutOfViewport,
204
205
  })
205
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
+
206
218
  const compileKind = (kind: Data['kind']) => {
207
219
  const { type, ...rest } = kind || {}
208
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
+
209
238
  return { kind: type, ...rest }
210
239
  }
211
240
 
@@ -244,13 +273,26 @@ const compileModule = (subspace: Subspace) => {
244
273
  }
245
274
  }
246
275
 
247
- export const compile = (app: Application) => {
276
+ export const compile = async (app: Application) => {
277
+ await new Promise((resolve) => setImmediate(resolve, 0))
248
278
  const config = {
249
279
  title: app.name,
250
280
  subspace_map: app.subspaces.reduce((subspaceMap, subspace) => {
251
281
  subspaceMap[subspace.id] = {
252
282
  title: subspace.title,
253
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,
254
296
  layout: {
255
297
  width: subspace.layout?.width,
256
298
  height: subspace.layout?.height,
@@ -293,6 +335,7 @@ export const compile = (app: Application) => {
293
335
  brickId: itemBrick.brickId,
294
336
  brickIdPrefix: itemBrick.brickIdPrefix,
295
337
  templateKey: itemBrick.templateKey,
338
+ frame: itemBrick.frame,
296
339
  property: compileProperty(itemBrick.property),
297
340
  propertyMapping: itemBrick.propertyMapping,
298
341
  animation: compileAnimations(itemBrick.templateKey, itemBrick.animation || {}),
@@ -386,6 +429,7 @@ export const compile = (app: Application) => {
386
429
  ? { brick_id: (item.item as () => Brick)()?.id }
387
430
  : { subspace_id: item.item }),
388
431
  frame: compileFrame(item.frame),
432
+ hidden: item.hidden,
389
433
  })),
390
434
  }
391
435
  return map
@@ -568,7 +612,13 @@ export const compile = (app: Application) => {
568
612
  const declarationBody = (
569
613
  (program.body[0] as ExportNamedDeclaration).declaration as FunctionDeclaration
570
614
  )?.body
571
- code = escodegen.generate(declarationBody)
615
+ code = escodegen.generate(declarationBody, {
616
+ format: {
617
+ indent: { style: ' ' },
618
+ semicolons: false,
619
+ },
620
+ comment: true,
621
+ })
572
622
  } catch (e) {
573
623
  code = scriptCalc.code || ''
574
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.test10",
3
+ "version": "2.21.0-beta.14.test12",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "build": "node scripts/build.js"
@@ -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()
package/types/bricks.ts CHANGED
@@ -2052,6 +2052,7 @@ Default property:
2052
2052
  | {
2053
2053
  title?: string | DataLink
2054
2054
  description?: string | DataLink
2055
+ hidden?: boolean | DataLink
2055
2056
  brickId?: string | DataLink
2056
2057
  brickIdPrefix?: string | DataLink
2057
2058
  templateKey?: string | DataLink
@@ -2068,6 +2069,14 @@ Default property:
2068
2069
  y?: number | DataLink
2069
2070
  width?: number | DataLink
2070
2071
  height?: number | DataLink
2072
+ standbyMode?: 'custom' | 'top' | 'bottom' | 'left' | 'right' | DataLink
2073
+ standbyFrame?: DataLink | {}
2074
+ standbyOpacity?: number | DataLink
2075
+ standbyDelay?: number | DataLink
2076
+ standbyDelayRandom?: number | DataLink
2077
+ standbyEasing?: string | DataLink
2078
+ showingDelay?: number | DataLink
2079
+ renderOutOfViewport?: boolean | DataLink
2071
2080
  }
2072
2081
  show?: string | DataLink
2073
2082
  pressToOpenDetail?: boolean | DataLink
@@ -2081,6 +2090,7 @@ Default property:
2081
2090
  | {
2082
2091
  title?: string | DataLink
2083
2092
  description?: string | DataLink
2093
+ hidden?: boolean | DataLink
2084
2094
  brickId?: string | DataLink
2085
2095
  brickIdPrefix?: string | DataLink
2086
2096
  templateKey?: string | DataLink
@@ -2097,6 +2107,14 @@ Default property:
2097
2107
  y?: number | DataLink
2098
2108
  width?: number | DataLink
2099
2109
  height?: number | DataLink
2110
+ standbyMode?: 'custom' | 'top' | 'bottom' | 'left' | 'right' | DataLink
2111
+ standbyFrame?: DataLink | {}
2112
+ standbyOpacity?: number | DataLink
2113
+ standbyDelay?: number | DataLink
2114
+ standbyDelayRandom?: number | DataLink
2115
+ standbyEasing?: string | DataLink
2116
+ showingDelay?: number | DataLink
2117
+ renderOutOfViewport?: boolean | DataLink
2100
2118
  }
2101
2119
  show?: string | DataLink
2102
2120
  pressToBackList?: boolean | DataLink
package/types/canvas.ts CHANGED
@@ -74,5 +74,6 @@ export type Canvas = CanvasDef & {
74
74
  showingDelay?: number
75
75
  renderOutOfViewport?: boolean
76
76
  }
77
+ hidden?: boolean // Hide in Editor
77
78
  }>
78
79
  }
package/types/data.ts CHANGED
@@ -47,6 +47,7 @@ export type Data<T = any> = DataDef & {
47
47
  min?: number
48
48
  step?: number
49
49
  }
50
+ | DataAssetKind
50
51
  | {
51
52
  type:
52
53
  | 'color'
@@ -55,18 +56,28 @@ export type Data<T = any> = DataDef & {
55
56
  | 'rich-text-content'
56
57
  | 'sandbox-script'
57
58
  | 'llm-prompt'
58
- | 'media-resource-image'
59
- | 'media-resource-video'
60
- | 'media-resource-audio'
61
- | 'media-resource-file'
62
- | 'lottie-file-uri'
63
- | 'ggml-model-asset'
64
- | 'gguf-model-asset'
65
- | 'binary-asset'
66
59
  }
67
60
  value: T
68
61
  }
69
62
 
63
+ export type DataAssetKind = {
64
+ type:
65
+ | 'media-resource-image'
66
+ | 'media-resource-video'
67
+ | 'media-resource-audio'
68
+ | 'media-resource-file'
69
+ | 'lottie-file-uri'
70
+ | 'ggml-model-asset'
71
+ | 'gguf-model-asset'
72
+ | 'binary-asset'
73
+ preload?: {
74
+ type: 'url'
75
+ hashType: 'md5' | 'sha256'
76
+ hash: string
77
+ }
78
+ metadata?: { [key: string]: any }
79
+ }
80
+
70
81
  export type DataLink = {
71
82
  __typename: 'DataLink'
72
83
  data: () => Data
package/types/subspace.ts CHANGED
@@ -9,7 +9,14 @@ export type Subspace = {
9
9
  id: string
10
10
  title: string
11
11
  description?: string
12
- localSyncChangeCanvas?: LocalSyncStrategy
12
+ // Unexpanded in Editor
13
+ unexpanded?: {
14
+ data?: boolean
15
+ dataCalculation?: boolean
16
+ brick?: boolean
17
+ generator?: boolean
18
+ canvas?: Array<Canvas>
19
+ }
13
20
  module?: {
14
21
  id: string
15
22
  version: string
@@ -25,6 +32,7 @@ export type Subspace = {
25
32
  version: string
26
33
  }>
27
34
  }
35
+ localSyncChangeCanvas?: LocalSyncStrategy
28
36
  layout: {
29
37
  width: number
30
38
  height: number
package/utils/data.ts CHANGED
@@ -1,10 +1,36 @@
1
- import type { DataLink, Data } from '../types'
1
+ import type { DataLink, Data, Canvas } from '../types'
2
+ import { makeId } from './id'
2
3
 
3
4
  export const linkData: (dataGetter: () => Data) => DataLink = (dataGetter) => ({
4
5
  __typename: 'DataLink',
5
6
  data: dataGetter,
6
7
  })
7
8
 
9
+ const idOpts = {
10
+ snapshotMode: process.env.BRICKS_SNAPSHOT_MODE === '1',
11
+ }
12
+
13
+ export const createCanvasIdRef: (canvasGetter: () => Canvas) => Data<string> = (canvasGetter) => {
14
+ const data: Data<string> = {
15
+ __typename: 'Data',
16
+ id: makeId('data', idOpts),
17
+ type: 'string',
18
+ routing: 'read-only',
19
+ kind: {
20
+ type: 'auto-generated-item-id',
21
+ idType: 'canvas',
22
+ },
23
+ title: '',
24
+ value: '',
25
+ }
26
+ setImmediate(() => {
27
+ const canvas = canvasGetter()
28
+ data.title = `Canvas ID: ${canvas.title}`
29
+ data.value = canvas.id
30
+ })
31
+ return data
32
+ }
33
+
8
34
  type SystemDataName =
9
35
  | 'isLocalSyncMainDevice'
10
36
  | 'currentCanvasId'