@fugood/bricks-project 2.21.0-beta.17 → 2.21.0-beta.18

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
@@ -26,6 +26,7 @@ import type {
26
26
  Generator,
27
27
  Canvas,
28
28
  Subspace,
29
+ EventActionForItem,
29
30
  } from '../types'
30
31
 
31
32
  const compileProperty = (property, errorReference: string, result = {}) => {
@@ -91,7 +92,7 @@ const compileActionParam = (templateKey: string, actionName: string, paramName:
91
92
 
92
93
  const compileEvents = (
93
94
  templateKey: string,
94
- eventMap: { [key: string]: Array<EventAction> },
95
+ eventMap: { [key: string]: Array<any> },
95
96
  options = { camelCase: false, errorReference: '' },
96
97
  ) => {
97
98
  const { camelCase, errorReference } = options
@@ -106,8 +107,14 @@ const compileEvents = (
106
107
  else handlerKey = handler.toUpperCase()
107
108
  if (handlerKey === 'SYSTEM') handlerTemplateKey = 'SYSTEM'
108
109
  } else if (typeof handler === 'function') {
109
- const instance = handler() as Brick | Generator
110
- handlerKey = instance?.id
110
+ let instance = handler()
111
+ if (instance?.id) {
112
+ instance = instance as { id: string }
113
+ handlerKey = instance?.id
114
+ } else if (instance?.brickId) {
115
+ instance = instance as { brickId: string; templateKey: string }
116
+ handlerKey = instance.brickId
117
+ }
111
118
  handlerTemplateKey = instance?.templateKey
112
119
  }
113
120
  if (!handlerKey) throw new Error(`Invalid handler: ${handler} ${errorReference}`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fugood/bricks-project",
3
- "version": "2.21.0-beta.17",
3
+ "version": "2.21.0-beta.18",
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
- "gitHead": "fdf1004ac8e6cde8d103bae1f8d4e9d995787d88"
16
+ "gitHead": "5affdfe765bab2d2844658feb9d505d6a8911bab"
17
17
  }
package/tools/pull.ts CHANGED
@@ -47,11 +47,23 @@ if (isGitRepo) {
47
47
  if (confirmContinue !== 'y') throw new Error('Pull cancelled')
48
48
  }
49
49
 
50
+ const prettierConfig = await Bun.file(`${cwd}/.prettierrc`)
51
+ .json()
52
+ .catch(() => ({
53
+ trailingComma: 'all',
54
+ tabWidth: 2,
55
+ semi: false,
56
+ singleQuote: true,
57
+ printWidth: 100,
58
+ }))
59
+
50
60
  await Promise.all(
51
61
  files.map(async (file) =>
52
62
  Bun.write(
53
63
  `${cwd}/${file.name}`,
54
- file.formatable ? await format(file.input, { parser: 'typescript' }) : file.input,
64
+ file.formatable
65
+ ? await format(file.input, { parser: 'typescript', ...prettierConfig })
66
+ : file.input,
55
67
  ),
56
68
  ),
57
69
  )
package/types/bricks.ts CHANGED
@@ -1,7 +1,14 @@
1
1
  import type { SwitchCondInnerStateCurrentCanvas, SwitchCondData, SwitchDef } from './switch'
2
2
  import type { Data, DataLink } from './data'
3
3
  import type { Animation, AnimationBasicEvents } from './animation'
4
- import type { Brick, EventAction, ActionWithDataParams, ActionWithParams, Action } from './common'
4
+ import type {
5
+ Brick,
6
+ EventAction,
7
+ EventActionForItem,
8
+ ActionWithDataParams,
9
+ ActionWithParams,
10
+ Action,
11
+ } from './common'
5
12
 
6
13
  interface BrickBasicProperty {
7
14
  /* The brick opacity (0 ~ 1) */
@@ -62,6 +69,12 @@ interface BrickBasicEvents {
62
69
  standby?: Array<EventAction>
63
70
  }
64
71
 
72
+ interface BrickBasicEventsForItem {
73
+ showStart?: Array<EventActionForItem>
74
+ switchUpdate?: Array<EventActionForItem>
75
+ standby?: Array<EventActionForItem>
76
+ }
77
+
65
78
  interface BrickRectDef {
66
79
  /*
67
80
  Default property:
@@ -2127,10 +2140,10 @@ Default property:
2127
2140
  }
2128
2141
  >
2129
2142
  | DataLink
2130
- events?: BrickBasicEvents & {
2143
+ events?: BrickBasicEventsForItem & {
2131
2144
  /* Event on page render finished */
2132
2145
  onPageRender?: Array<
2133
- EventAction & {
2146
+ EventActionForItem & {
2134
2147
  eventPropertyMapping?: {
2135
2148
  pageIndex: {
2136
2149
  type: 'number'
@@ -2145,7 +2158,7 @@ Default property:
2145
2158
  >
2146
2159
  /* Event on page change. */
2147
2160
  onPageChange?: Array<
2148
- EventAction & {
2161
+ EventActionForItem & {
2149
2162
  eventPropertyMapping?: {
2150
2163
  pageIndex: {
2151
2164
  type: 'number'
@@ -2160,7 +2173,7 @@ Default property:
2160
2173
  >
2161
2174
  /* Event on page index out of bound. */
2162
2175
  onPageOutOfBound?: Array<
2163
- EventAction & {
2176
+ EventActionForItem & {
2164
2177
  eventPropertyMapping?: {
2165
2178
  pageIndex: {
2166
2179
  type: 'number'
@@ -2175,7 +2188,7 @@ Default property:
2175
2188
  >
2176
2189
  /* Event on into `detail` mode */
2177
2190
  onIntoDetailMode?: Array<
2178
- EventAction & {
2191
+ EventActionForItem & {
2179
2192
  eventPropertyMapping?: {
2180
2193
  pageIndex: {
2181
2194
  type: 'number'
@@ -2194,7 +2207,7 @@ Default property:
2194
2207
  >
2195
2208
  /* Event on into `list` mode. */
2196
2209
  onIntoListMode?: Array<
2197
- EventAction & {
2210
+ EventActionForItem & {
2198
2211
  eventPropertyMapping?: {
2199
2212
  pageIndex: {
2200
2213
  type: 'number'
@@ -2209,7 +2222,7 @@ Default property:
2209
2222
  >
2210
2223
  /* Event on render error */
2211
2224
  onError?: Array<
2212
- EventAction & {
2225
+ EventActionForItem & {
2213
2226
  eventPropertyMapping?: {
2214
2227
  errorMessage: {
2215
2228
  type: 'string'
package/types/common.ts CHANGED
@@ -68,6 +68,18 @@ export type EventAction = {
68
68
  eventPropertyMapping?: object
69
69
  }
70
70
 
71
+ export type EventActionForItem = {
72
+ handler:
73
+ | 'system'
74
+ | (() => Brick | Generator | { brickId: string; templateKey: string })
75
+ | SubspaceID
76
+ | ItemBrickID
77
+ action: Action
78
+ waitAsync?: boolean
79
+ // Event Property Definition mapping to params (use path to replace)
80
+ eventPropertyMapping?: object
81
+ }
82
+
71
83
  export type ApplicationFont = {
72
84
  name: string
73
85
  url: string