masua 0.11.4 → 0.11.6

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Matthias Giger, 2017 Spope
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -43,7 +43,7 @@ grid(document.querySelector('#my-custom-grid'), {
43
43
  import { Grid } from 'masua/react'
44
44
 
45
45
  const MyGrid = () => (
46
- <Grid disabled={window.innerWidth < 501}>
46
+ <Grid disabled={window.innerWidth < 501} gutter={50}>
47
47
  <Box />
48
48
  <Box size={3} />
49
49
  <Box size={2} />
package/index.ts CHANGED
@@ -21,7 +21,7 @@ interface State {
21
21
  }
22
22
 
23
23
  export interface Configuration {
24
- baseWidth: number
24
+ baseWidth: number | string
25
25
  gutter: number | string
26
26
  gutterX: number | string
27
27
  gutterY: number | string
@@ -33,6 +33,7 @@ export interface Configuration {
33
33
  }
34
34
 
35
35
  interface NumberConfiguration extends Configuration {
36
+ baseWidth: number
36
37
  gutter: number
37
38
  gutterX: number
38
39
  gutterY: number
@@ -52,7 +53,7 @@ function getCount(state: State) {
52
53
  function getLongest(state: State) {
53
54
  let longest = 0
54
55
  for (let index = 0; index < state.count; index += 1) {
55
- if (state.columns[index] > state.columns[longest]) {
56
+ if ((state.columns[index] ?? 0) > (state.columns[longest] ?? 1)) {
56
57
  longest = index
57
58
  }
58
59
  }
@@ -66,7 +67,7 @@ function getNextColumn(index: number, state: State) {
66
67
  function getShortest(state: State) {
67
68
  let shortest = 0
68
69
  for (let index = 0; index < state.count; index += 1) {
69
- if (state.columns[index] < state.columns[shortest]) {
70
+ if ((state.columns[index] ?? 1) < (state.columns[shortest] ?? 0)) {
70
71
  shortest = index
71
72
  }
72
73
  }
@@ -174,15 +175,17 @@ function layout(state: State) {
174
175
  } else {
175
176
  x = startX - (colWidth + childrenGutter) * nextColumn - colWidth
176
177
  }
177
- const y = state.columns[nextColumn]
178
+ const y = state.columns[nextColumn] ?? 0
178
179
  const child = children[index] as HTMLElement
179
180
  child.style.transform = `translate3d(${Math.round(x)}px,${Math.round(y)}px,0)`
180
181
  child.style.position = 'absolute'
181
182
 
182
- state.columns[nextColumn] += state.sizes[index] + (state.count > 1 ? state.gutterY : state.singleColumnGutter) // margin-bottom
183
+ if (state.columns[nextColumn]) {
184
+ state.columns[nextColumn] += (state.sizes[index] ?? 0) + (state.count > 1 ? state.gutterY : state.singleColumnGutter) // margin-bottom
185
+ }
183
186
  }
184
187
 
185
- state.container.style.height = `${state.columns[getLongest(state)] - state.currentGutterY}px`
188
+ state.container.style.height = `${(state.columns[getLongest(state)] ?? 0) - state.currentGutterY}px`
186
189
  }
187
190
 
188
191
  function resizeThrottler(state: State) {
@@ -257,13 +260,14 @@ function getSizeInPixels(size: string) {
257
260
  return pixels
258
261
  }
259
262
 
260
- const sizeValues: (keyof Configuration)[] = ['gutter', 'gutterX', 'gutterY', 'singleColumnGutter']
263
+ const sizeValues: (keyof Configuration)[] = ['baseWidth', 'gutter', 'gutterX', 'gutterY', 'singleColumnGutter']
261
264
 
262
265
  function convertStringSizesToPixels(configuration: Partial<Configuration>): Partial<NumberConfiguration> {
263
266
  for (const property of sizeValues) {
264
267
  const value = configuration[property]
265
268
  if (typeof value === 'string') {
266
- configuration.gutter = getSizeInPixels(value)
269
+ // @ts-ignore No idea what's the issue here.
270
+ configuration[property] = getSizeInPixels(value)
267
271
  }
268
272
  }
269
273
 
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.11.4",
4
+ "version": "0.11.6",
5
5
  "repository": "github:tobua/masua",
6
6
  "homepage": "https://tobua.github.io/masua",
7
7
  "license": "MIT",
@@ -10,16 +10,15 @@
10
10
  "Spope (minimasonry)"
11
11
  ],
12
12
  "scripts": {
13
- "format": "bun biome format . --write",
14
- "lint": "bun biome lint .",
13
+ "check": "biome check --write .",
15
14
  "types": "tsc"
16
15
  },
17
16
  "devDependencies": {
18
- "@biomejs/biome": "^1.7.1",
19
- "@types/bun": "^1.1.0",
20
- "@types/react": "^18.3.1",
21
- "typescript": "^5.4.5",
22
- "zero-configuration": "^0.5.5"
17
+ "@biomejs/biome": "^1.8.3",
18
+ "@types/bun": "^1.1.6",
19
+ "@types/react": "^18.3.3",
20
+ "typescript": "^5.5.3",
21
+ "zero-configuration": "^0.17.0"
23
22
  },
24
23
  "peerDependencies": {
25
24
  "react": ">= 18",
@@ -63,12 +62,21 @@
63
62
  "publishConfig": {
64
63
  "provenance": true
65
64
  },
66
- "engines": {
67
- "node": ">= 18"
68
- },
69
65
  "configuration": {
70
66
  "gitignore": "bundle",
71
67
  "vscode": "biome",
68
+ "license": {
69
+ "extends": "MIT",
70
+ "authors": [
71
+ {
72
+ "name": "Matthias Giger"
73
+ },
74
+ {
75
+ "name": "Spope",
76
+ "year": "2017"
77
+ }
78
+ ]
79
+ },
72
80
  "typescript": {
73
81
  "extends": "plugin",
74
82
  "compilerOptions": {
@@ -81,13 +89,6 @@
81
89
  },
82
90
  "biome": {
83
91
  "extends": "recommended",
84
- "linter": {
85
- "rules": {
86
- "nursery": {
87
- "all": true
88
- }
89
- }
90
- },
91
92
  "files": {
92
93
  "ignore": [
93
94
  "demo"
package/react.tsx CHANGED
@@ -1,6 +1,5 @@
1
- // biome-ignore lint/nursery/noUndeclaredDependencies: This is a reference to the local package.
2
1
  import { type Configuration, grid } from 'masua'
3
- import { type JSX, useEffect, useMemo, useRef } from 'react'
2
+ import { type JSX, useEffect, useRef } from 'react'
4
3
 
5
4
  interface ReactConfiguration extends Configuration {
6
5
  disabled: boolean
@@ -21,18 +20,15 @@ const configurationProperties = [
21
20
  export function Grid({ disabled = false, children, ...props }: JSX.IntrinsicElements['div'] & Partial<ReactConfiguration>) {
22
21
  const gridRef = useRef(null)
23
22
  const instance = useRef<ReturnType<typeof grid> | null>(null)
24
- const configurationProps = useMemo(
25
- () =>
26
- Object.entries(props).reduce((result: { [key: string]: string }, [key, value]) => {
27
- if (configurationProperties.includes(key)) {
28
- result[key] = value
29
- // @ts-ignore
30
- delete props[key]
31
- }
32
- return result
33
- }, {}),
34
- [props],
35
- )
23
+ // TODO props changes on every render, cannot be memoized, should do deep compare.
24
+ const configurationProps = Object.entries(props).reduce((result: { [key: string]: string }, [key, value]) => {
25
+ if (configurationProperties.includes(key)) {
26
+ result[key] = value
27
+ // @ts-ignore
28
+ delete props[key]
29
+ }
30
+ return result
31
+ }, {})
36
32
 
37
33
  useEffect(() => {
38
34
  if (disabled) {