keystone_ui-blocks 0.1.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a9effabb0c7a22247df585e2f60cf4ec1dfbd2256feeca4cfdeafc108bf170c
4
- data.tar.gz: 01d24bf7544dbb1ab376e72edacf336f002b0ee815f13981fbe8cfacd1b196e5
3
+ metadata.gz: 7323dfd615c2e4738c0bdf5722585c72a84d2e025e50d9331b0b468078c006b5
4
+ data.tar.gz: 4b2c50a5e4e22c31915604c3ca73fb510f13e02d62b417b8d1e62e08570c6c17
5
5
  SHA512:
6
- metadata.gz: 8ed0465e1674ddd075da1d207408dbeaa5e8d59c0e071a565efff1f0ddf2e02fc17a089132ed4e2cfdcda225b32a26758e5ffa9057c9e5743e03f38386d4ebd0
7
- data.tar.gz: 62885b92e2be83b5a448b1f8c8d816d44ffa7637799270cefc0bc0b6a57b1df432330155be7ec530b6cfcc103f343f86bdc9b1e9f506bcd83e8e4ace0f10da77
6
+ metadata.gz: 3a532844033cc22da2548961f7a1215301088b6d643280c311b826d7448a9a0f63ec67f6bcff9764866733221acde3b26d41969f9a1f2ea73bf2040499fb5b06
7
+ data.tar.gz: 7152e5abc082918dc921616f4787900d5969810bd029a9f4cf42e631d266d664345b48c6f52af6297ca2aa2cdbb9a6bcc21917110e630d492685c5d0a9dbb14f
@@ -4,12 +4,14 @@
4
4
  gap: var(--ks-blocks-gap, 10px);
5
5
  }
6
6
 
7
- @media (max-width: 640px) {
8
- .ks-blocks-layout {
9
- display: block;
10
- }
7
+ .ks-blocks-layout > * {
8
+ grid-column: calc(var(--ks-block-x) + 1) / span var(--ks-block-w);
9
+ grid-row: calc(var(--ks-block-y) + 1) / span var(--ks-block-h);
10
+ }
11
11
 
12
- .ks-blocks-layout > * + * {
13
- margin-top: var(--ks-blocks-gap, 10px);
12
+ @media (max-width: 640px) {
13
+ .ks-blocks-layout > * {
14
+ grid-column: span var(--ks-block-narrow-w, var(--ks-blocks-columns, 12));
15
+ grid-row: span var(--ks-block-narrow-h, 1);
14
16
  }
15
17
  }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module KeystoneUi
4
4
  module Blocks
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.1"
6
6
  end
7
7
  end
@@ -1,6 +1,6 @@
1
1
  module KsBlocks
2
- BlockType = Data.define(:key, :name, :width, :height, :min_width, :max_width, :min_height, :max_height, :resizable, :once, :full_width, :fixed, :description, :group, :fields) do
3
- def initialize(key:, name:, width:, height:, min_width: 1, max_width: nil, min_height: 1, max_height: nil, resizable: true, once: false, full_width: false, fixed: false, description: nil, group: nil, fields: [])
2
+ BlockType = Data.define(:key, :name, :width, :height, :min_width, :max_width, :min_height, :max_height, :resizable, :once, :full_width, :fixed, :description, :group, :fields, :narrow_width, :narrow_height) do
3
+ def initialize(key:, name:, width:, height:, min_width: 1, max_width: nil, min_height: 1, max_height: nil, resizable: true, once: false, full_width: false, fixed: false, description: nil, group: nil, fields: [], narrow_width: nil, narrow_height: nil)
4
4
  super
5
5
  end
6
6
  end
@@ -15,7 +15,7 @@ module KsBlocks
15
15
  define_method(:place_blocks) do |positions, version: nil|
16
16
  raise InvalidLayout, "This layout changed since it was last drawn" if version && version != KsBlocks.version_of(public_send(column))
17
17
 
18
- update!(column => Grid.place(public_send(column), positions, columns: columns, types: KsBlocks.registry.block_types(kind: kind)))
18
+ update!(column => Grid.place(public_send(column), positions, columns: columns, types: block_layout_types))
19
19
  end
20
20
 
21
21
  define_method(:fill_block) do |id, content|
@@ -23,13 +23,15 @@ module KsBlocks
23
23
  end
24
24
 
25
25
  define_method(:remove_block) do |id|
26
- update!(column => Grid.remove(public_send(column), id, types: KsBlocks.registry.block_types(kind: kind)))
26
+ update!(column => Grid.remove(public_send(column), id, types: block_layout_types))
27
27
  end
28
28
 
29
- define_method(:block_layout_kind) { kind }
29
+ define_method(:block_layout_kind) { kind.respond_to?(:call) ? kind.call(self) : kind }
30
+
31
+ define_method(:block_layout_types) { KsBlocks.registry.block_types(kind: block_layout_kind) }
30
32
 
31
33
  define_method(:layout_data) do
32
- KsBlocks.layout_data(public_send(column), kind: kind, grid: { columns: columns, row_height: row_height, gap: gap })
34
+ KsBlocks.layout_data(public_send(column), kind: block_layout_kind, grid: { columns: columns, row_height: row_height, gap: gap })
33
35
  end
34
36
  end
35
37
  end
@@ -5,7 +5,7 @@ module KsBlocks
5
5
  module LayoutHelper
6
6
  def block_layout(blocks, columns: Grid::COLUMNS, gap: Grid::GAP, kind: nil, &block)
7
7
  tag.div(class: "ks-blocks-layout", style: "--ks-blocks-columns: #{columns}; --ks-blocks-gap: #{gap}px") do
8
- safe_join(block_layout_shown(blocks, kind).map { |placed| block_layout_block(placed, &block) })
8
+ safe_join(block_layout_shown(blocks, kind).map { |placed| block_layout_block(placed, block_layout_type(placed, kind), &block) })
9
9
  end
10
10
  end
11
11
 
@@ -16,8 +16,23 @@ module KsBlocks
16
16
  shown.sort_by { |placed| [ placed["y"], placed["x"] ] }
17
17
  end
18
18
 
19
- def block_layout_block(placed, &block)
20
- tag.div(capture(placed, &block), data: { block: placed["id"] }, style: "grid-column: #{placed['x'] + 1} / span #{placed['w']}; grid-row: #{placed['y'] + 1} / span #{placed['h']}")
19
+ def block_layout_type(placed, kind)
20
+ KsBlocks.registry.block_types(kind: kind || :blocks).find { |block_type| block_type.key.to_s == placed["type"] }
21
+ end
22
+
23
+ def block_layout_block(placed, block_type, &block)
24
+ tag.div(capture(placed, &block), data: { block: placed["id"] }, style: block_layout_placing(placed, block_type))
25
+ end
26
+
27
+ def block_layout_placing(placed, block_type)
28
+ "--ks-block-x: #{placed['x']}; --ks-block-y: #{placed['y']}; --ks-block-w: #{placed['w']}; --ks-block-h: #{placed['h']}" \
29
+ "#{block_layout_narrow(block_type)}"
30
+ end
31
+
32
+ def block_layout_narrow(block_type)
33
+ return "" if block_type&.narrow_width.nil?
34
+
35
+ "; --ks-block-narrow-w: #{block_type.narrow_width}; --ks-block-narrow-h: #{block_type.narrow_height || 1}"
21
36
  end
22
37
  end
23
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keystone_ui-blocks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider