masua 0.10.2 → 0.10.3

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/README.md CHANGED
@@ -18,7 +18,7 @@ grid(document.querySelector('#my-custom-grid'), {
18
18
  baseWidth: 300,
19
19
  minify: false,
20
20
  surroundingGutter: true,
21
- ultimateGutter: 10,
21
+ singleColumnGutter: 10,
22
22
  direction: 'rtl',
23
23
  wedge: true,
24
24
  })
package/index.ts CHANGED
@@ -13,7 +13,7 @@ interface State {
13
13
  gutterY: number | string
14
14
  gutter: number | string
15
15
  minify: boolean
16
- ultimateGutter: number
16
+ singleColumnGutter: string | number
17
17
  surroundingGutter: boolean
18
18
  direction: 'ltr' | 'rtl'
19
19
  wedge: boolean
@@ -26,7 +26,7 @@ export interface Configuration {
26
26
  gutterY: number | string
27
27
  minify: boolean
28
28
  surroundingGutter: boolean
29
- ultimateGutter: number
29
+ singleColumnGutter: number
30
30
  direction: 'ltr' | 'rtl'
31
31
  wedge: boolean
32
32
  }
@@ -79,7 +79,7 @@ function reset(state: State) {
79
79
 
80
80
  if (getCount(state) === 1) {
81
81
  // Set ultimate gutter when only one column is displayed
82
- state.currentGutterX = state.ultimateGutter
82
+ state.currentGutterX = state.singleColumnGutter
83
83
  // As gutters are reduced, two column may fit, forcing to 1
84
84
  state.count = 1
85
85
  } else if (state.width < state.baseWidth + 2 * state.currentGutterX) {
@@ -171,7 +171,7 @@ function layout(state: State) {
171
171
  child.style.transform = `translate3d(${Math.round(x)}px,${Math.round(y)}px,0)`
172
172
 
173
173
  state.columns[nextColumn] +=
174
- state.sizes[index] + (state.count > 1 ? state.gutterY : state.ultimateGutter) // margin-bottom
174
+ state.sizes[index] + (state.count > 1 ? state.gutterY : state.singleColumnGutter) // margin-bottom
175
175
  }
176
176
 
177
177
  state.container.style.height = `${state.columns[getLongest(state)] - state.currentGutterY}px`
@@ -248,13 +248,15 @@ export function grid(element: HTMLElement | string, configuration: Partial<Confi
248
248
  baseWidth: 255,
249
249
  gutter: 10,
250
250
  minify: true,
251
- ultimateGutter: 5,
252
251
  surroundingGutter: false,
253
252
  direction: 'ltr',
254
253
  wedge: false,
255
254
  ...configuration,
256
255
  gutterX: configuration.gutterX || configuration.gutter || 10,
257
256
  gutterY: configuration.gutterY || configuration.gutter || 10,
257
+ // One column is theoretically an Y-gutter so that's preferred if available.
258
+ singleColumnGutter:
259
+ configuration.singleColumnGutter || configuration.gutterY || configuration.gutter || 10,
258
260
  }
259
261
 
260
262
  // TODO use calc if gutter is string.
@@ -263,6 +265,13 @@ export function grid(element: HTMLElement | string, configuration: Partial<Confi
263
265
 
264
266
  return {
265
267
  destroy: () => destroy(state),
266
- update: () => layout(state),
268
+ update: (changes: Partial<Configuration> = {}) => {
269
+ Object.assign(state, changes)
270
+ state.gutterX = changes.gutterX || changes.gutter || state.gutterX
271
+ state.gutterY = changes.gutterY || changes.gutter || state.gutterY
272
+ state.singleColumnGutter =
273
+ changes.singleColumnGutter || changes.gutterY || changes.gutter || state.singleColumnGutter
274
+ layout(state)
275
+ },
267
276
  }
268
277
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "masua",
3
3
  "description": "Simple masonry layout library in TypeScript.",
4
- "version": "0.10.2",
4
+ "version": "0.10.3",
5
5
  "repository": "github:tobua/masua",
6
6
  "homepage": "https://tobua.github.io/masua",
7
7
  "license": "MIT",
@@ -22,7 +22,7 @@
22
22
  }
23
23
  },
24
24
  "devDependencies": {
25
- "@types/react": "^18.2.65",
25
+ "@types/react": "^18.2.67",
26
26
  "padua": "^4.0.0"
27
27
  },
28
28
  "peerDependencies": {
package/react.tsx CHANGED
@@ -12,19 +12,18 @@ const configurationProperties = [
12
12
  'gutterY',
13
13
  'minify',
14
14
  'surroundingGutter',
15
- 'ultimateGutter',
15
+ 'singleColumnGutter',
16
16
  'direction',
17
17
  'wedge',
18
18
  ]
19
19
 
20
- let instance: any
21
-
22
20
  export function Grid({
23
21
  disabled = false,
24
22
  children,
25
23
  ...props
26
24
  }: JSX.IntrinsicElements['div'] & Partial<ReactConfiguration>) {
27
25
  const gridRef = useRef(null)
26
+ const instance = useRef<ReturnType<typeof grid>>(null)
28
27
  const configurationProps = useMemo(
29
28
  () =>
30
29
  Object.entries(props).reduce((result, [key, value]) => {
@@ -39,12 +38,12 @@ export function Grid({
39
38
 
40
39
  useEffect(() => {
41
40
  if (disabled) return () => {}
42
- if (instance) {
43
- instance.update()
44
- return instance.destroy
41
+ if (instance.current) {
42
+ instance.current.update()
43
+ return instance.current.destroy
45
44
  }
46
- instance = grid(gridRef.current, configurationProps)
47
- return instance.destroy
45
+ instance.current = grid(gridRef.current, configurationProps)
46
+ return instance.current.destroy
48
47
  }, [children])
49
48
 
50
49
  return (