lookbook 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a8ca9a9db0798d392083b4470397bf94260811a1f82f8b89dee0e5646fca156
4
- data.tar.gz: 24fe83948823edd7387b11ca2ee5628f778a15034173491bfdfd20347d6b1484
3
+ metadata.gz: 18630747bc279477cc077cccfd3f2df3611d6d277c1140f1d63616cb9fc4cc4e
4
+ data.tar.gz: 40ca16f9e0f8ad6a44b93c7678700f728fdeaf149e1bc14cd36efd17a2c58b8b
5
5
  SHA512:
6
- metadata.gz: 1463db9307bc67d9224a4a96f21ee404902fe0e266b40b0456c84e551a26b96a779e816f2780b5c1ea30189b8d94e3e5dfc16ab6d2f0b3df3a0e06d8f2705282
7
- data.tar.gz: ea867f97d2cb0d532e59c3c62de31405dca1fe29e7f9ade020fe6b7eb2cb3d2b04d16d7b110e3479eaa54316d6df9ba3328594c73c659e37f6c513867325ad54
6
+ metadata.gz: 8c13c64ca2591b32c832efbd7624106562990e2eda63bb1260af07ac1ed26727d1f716751b43a82470b638158374e16fa5128871d6f6a656c9fca59c2f00669f
7
+ data.tar.gz: 6ccd1a92b40b72734a27568a6461158cffd59ca0a6d87eb4f997453ce3a60fa30face2b0cbe1ed83facc181b9d1c6b6373559e32fd6c0d026406c024b09be309
@@ -1,10 +1,12 @@
1
1
  <%= render_component_tag :li,
2
2
  id: id,
3
+ key: "#{id}-directory",
3
4
  class: "list-none",
4
5
  "x-show": "!filteredOut",
5
6
  data: { "entity-type": :directory },
6
7
  cloak: true do %>
7
8
  <%= lookbook_tag :button,
9
+ key: "#{id}-action",
8
10
  class: "nav-action",
9
11
  style: "padding-left: #{left_pad}px",
10
12
  "x-bind": "bindings.toggle" do %>
@@ -1,11 +1,13 @@
1
1
  <%= render_component_tag :li,
2
2
  id: id,
3
+ key: "#{id}-entity-#{type}",
3
4
  class: "list-none",
4
5
  "x-show": "!filteredOut",
5
6
  data: { "entity-type": type },
6
7
  cloak: true do %>
7
8
  <%= lookbook_tag href.present? ? :a : :button,
8
9
  href: href,
10
+ key: "#{id}-action",
9
11
  class: "nav-action",
10
12
  style: "padding-left: #{left_pad}px",
11
13
  "x-bind": "bindings.#{href.present? ? "link" : "toggle"}" do %>
@@ -8,7 +8,7 @@ module Lookbook
8
8
  }.freeze
9
9
 
10
10
  def nav_icon
11
- ICONS[type] || :file
11
+ ICONS[collapsed? ? :preview : node.type] || :file
12
12
  end
13
13
 
14
14
  def href
@@ -19,7 +19,7 @@ module Lookbook
19
19
  end
20
20
 
21
21
  def children
22
- @children ||= node.map { |node| render_item(node) }
22
+ @children ||= node.sort.map { |node| render_item(node) }
23
23
  end
24
24
 
25
25
  def nav_icon
@@ -18,10 +18,6 @@ module Lookbook
18
18
  entities.append(node.content? ? node.content : collect_ordered_entities(node))
19
19
  end.flatten
20
20
  end
21
-
22
- def sort_entities
23
- @entities.sort_by! { |entity| [entity.depth, entity.position, entity.label] }
24
- end
25
21
  end
26
22
  end
27
23
  end
@@ -12,53 +12,48 @@ module Lookbook
12
12
  add(entities)
13
13
  end
14
14
 
15
- def add(entities = nil)
16
- Array(entities).each do |entity|
15
+ def add(to_add = nil)
16
+ Array(to_add).each do |entity|
17
17
  unless find_by_path(entity.path)
18
- clear_cache
19
18
  @entities.push(entity)
20
19
  end
21
20
  end
22
- sort_entities
21
+ clear_cache
23
22
  end
24
23
 
25
24
  def find_by_id(id)
26
25
  id = Utils.id(id)
27
- find { |entity| entity.id == id }
26
+ entities.find { |entity| entity.id == id }
28
27
  end
29
28
 
30
29
  def find_by_path(path)
31
- find { |entity| entity.path.to_s == path.to_s }
30
+ entities.find { |entity| entity.path.to_s == path.to_s }
32
31
  end
33
32
 
34
33
  def next(entity)
35
- index = find_index { |i| i.path == entity.path }
34
+ index = entities.find_index { |i| i.path == entity.path }
36
35
  entities[index + 1] unless index.nil?
37
36
  end
38
37
 
39
38
  def previous(entity)
40
- index = find_index { |i| i.path == entity.path }
39
+ index = entities.find_index { |i| i.path == entity.path }
41
40
  entities[index - 1] if !index.nil? && index > 0
42
41
  end
43
42
 
44
43
  def each(&block)
45
44
  if block
46
- entities.each { |entity| yield entity }
45
+ entities.sort.each { |entity| yield entity }
47
46
  else
48
47
  to_enum(:each)
49
48
  end
50
49
  end
51
50
 
52
51
  def flat_map(...)
53
- map(...).map(&:to_a).flatten
52
+ entities.map(...).map(&:to_a).flatten
54
53
  end
55
54
 
56
55
  protected
57
56
 
58
- def sort_entities
59
- @entities.sort_by! { |entity| [entity.label] }
60
- end
61
-
62
57
  def clear_cache
63
58
  @_cache = {}
64
59
  end
@@ -1,9 +1,4 @@
1
1
  module Lookbook
2
2
  class PreviewExampleCollection < EntityCollection
3
- protected
4
-
5
- def sort_entities
6
- @entities.sort_by!(&:label) if Lookbook.config.sort_examples
7
- end
8
3
  end
9
4
  end
@@ -12,16 +12,32 @@ module Lookbook
12
12
  end
13
13
 
14
14
  def position
15
- if @position_prefixes && respond_to?(:file_name)
16
- PositionPrefixParser.call(file_name).first || 10000
15
+ return @_position if @_position
16
+
17
+ pos = if @position_prefixes && respond_to?(:file_name)
18
+ PositionPrefixParser.call(file_name).first || default_position
17
19
  else
18
- fetch_config(:position, 10000)
20
+ fetch_config(:position, default_position)
19
21
  end
22
+
23
+ @_position ||= pos.to_i
20
24
  end
21
25
 
22
26
  def depth
23
27
  path.split("/").size
24
28
  end
29
+
30
+ def default_position
31
+ @default_position || 10000
32
+ end
33
+
34
+ def <=>(other)
35
+ if respond_to?(:sort_handler, true)
36
+ sort_handler(other)
37
+ else
38
+ [position, label] <=> [other.position, other.label]
39
+ end
40
+ end
25
41
  end
26
42
  end
27
43
  end
@@ -1,5 +1,6 @@
1
1
  module Lookbook
2
2
  class Entity
3
+ include Comparable
3
4
  include Lookbook::Engine.routes.url_helpers
4
5
 
5
6
  def initialize(lookup_path = nil)
@@ -36,6 +37,10 @@ module Lookbook
36
37
  @_type ||= self.class.name.demodulize.underscore.downcase.to_sym
37
38
  end
38
39
 
40
+ def <=>(other)
41
+ label <=> other.label
42
+ end
43
+
39
44
  alias_method :path, :lookup_path
40
45
  alias_method :logical_path, :lookup_path
41
46
 
@@ -81,7 +81,7 @@ module Lookbook
81
81
  def example_entities
82
82
  public_methods = preview_class.public_instance_methods(false)
83
83
  method_objects = code_object.meths.select { |m| public_methods.include?(m.name) }
84
- method_objects.map { |code_object| PreviewExample.new(code_object, self) }
84
+ method_objects.map.with_index { |code_object, i| PreviewExample.new(code_object, self, position: i) }
85
85
  end
86
86
  end
87
87
  end
@@ -8,9 +8,10 @@ module Lookbook
8
8
 
9
9
  attr_reader :preview
10
10
 
11
- def initialize(code_object, preview)
11
+ def initialize(code_object, preview, position: nil)
12
12
  @code_object = code_object
13
13
  @preview = preview
14
+ @default_position = position
14
15
  @lookup_path = "#{parent.lookup_path}/#{name}"
15
16
  end
16
17
 
@@ -65,6 +66,14 @@ module Lookbook
65
66
 
66
67
  protected
67
68
 
69
+ def sort_handler(other_entity)
70
+ if Lookbook.config.sort_examples
71
+ label <=> other_entity.label
72
+ else
73
+ [position, label] <=> [other_entity.position, other_entity.label]
74
+ end
75
+ end
76
+
68
77
  def format_source(source)
69
78
  source.sub(/^def \w+\s?(\([^)]+\))?/m, "").split("\n")[0..-2].join("\n")
70
79
  end
@@ -22,7 +22,7 @@ module Lookbook
22
22
  end
23
23
 
24
24
  def resolve_path(path, base_dir)
25
- path.start_with?(".") ? File.expand_path(path, base_dir) : Rails.root.join(path)
25
+ Pathname(path.start_with?(".") ? File.expand_path(path, base_dir) : Rails.root.join(path))
26
26
  end
27
27
  end
28
28
  end
@@ -1,6 +1,7 @@
1
1
  module Lookbook
2
2
  class TreeNode
3
3
  include Enumerable
4
+ include Comparable
4
5
 
5
6
  delegate_missing_to :content
6
7
 
@@ -40,7 +41,6 @@ module Lookbook
40
41
 
41
42
  def add_child(name, content = nil, position: 10000)
42
43
  children << TreeNode.new("#{path}/#{name}", content, position: position)
43
- sort_children
44
44
  end
45
45
 
46
46
  def has_child?(name)
@@ -57,7 +57,7 @@ module Lookbook
57
57
 
58
58
  def each(&block)
59
59
  if block
60
- children.each do |child|
60
+ children.sort.each do |child|
61
61
  yield child
62
62
  end
63
63
  else
@@ -65,6 +65,14 @@ module Lookbook
65
65
  end
66
66
  end
67
67
 
68
+ def <=>(other)
69
+ if content?
70
+ content <=> (other.content? ? other.content : other)
71
+ else
72
+ [position, label] <=> [other.position, other.label]
73
+ end
74
+ end
75
+
68
76
  protected
69
77
 
70
78
  def content_value(method_name, fallback = nil)
@@ -72,10 +80,6 @@ module Lookbook
72
80
  value || fallback
73
81
  end
74
82
 
75
- def sort_children
76
- @children.sort_by! { |child| [child.position, child.label] }
77
- end
78
-
79
83
  def segments
80
84
  path.split("/")
81
85
  end
@@ -1,3 +1,3 @@
1
1
  module Lookbook
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.1"
3
3
  end
@@ -7705,7 +7705,7 @@ function $5439cede634b2921$var$toCamel(s) {
7705
7705
  }
7706
7706
 
7707
7707
 
7708
- var $4ae691aa3fe187ba$exports = {};
7708
+ var $068816311f4006ce$exports = {};
7709
7709
  var $cbd28b10fa9798c7$exports = {};
7710
7710
 
7711
7711
  $parcel$defineInteropFlag($cbd28b10fa9798c7$exports);
@@ -11327,6 +11327,31 @@ function $e398acaded942bbe$export$2e2bcd8739ae039(targetSelector) {
11327
11327
  }
11328
11328
 
11329
11329
 
11330
+ var $e9904a14dabf652d$exports = {};
11331
+
11332
+ $parcel$defineInteropFlag($e9904a14dabf652d$exports);
11333
+
11334
+ $parcel$export($e9904a14dabf652d$exports, "default", () => $e9904a14dabf652d$export$2e2bcd8739ae039);
11335
+ function $e9904a14dabf652d$export$2e2bcd8739ae039(store) {
11336
+ return {
11337
+ focussed: false,
11338
+ get active () {
11339
+ return store.active;
11340
+ },
11341
+ get text () {
11342
+ return store.text;
11343
+ },
11344
+ clear () {
11345
+ if (store.raw === "") this.$refs.input.blur();
11346
+ else store.raw = "";
11347
+ },
11348
+ focus () {
11349
+ this.$refs.input.focus();
11350
+ }
11351
+ };
11352
+ }
11353
+
11354
+
11330
11355
  var $e1f51f020443edd4$exports = {};
11331
11356
 
11332
11357
  $parcel$defineInteropFlag($e1f51f020443edd4$exports);
@@ -12201,43 +12226,6 @@ function $e1f51f020443edd4$export$2e2bcd8739ae039(id, embedStore) {
12201
12226
  }
12202
12227
 
12203
12228
 
12204
- var $e9904a14dabf652d$exports = {};
12205
-
12206
- $parcel$defineInteropFlag($e9904a14dabf652d$exports);
12207
-
12208
- $parcel$export($e9904a14dabf652d$exports, "default", () => $e9904a14dabf652d$export$2e2bcd8739ae039);
12209
- function $e9904a14dabf652d$export$2e2bcd8739ae039(store) {
12210
- return {
12211
- focussed: false,
12212
- get active () {
12213
- return store.active;
12214
- },
12215
- get text () {
12216
- return store.text;
12217
- },
12218
- clear () {
12219
- if (store.raw === "") this.$refs.input.blur();
12220
- else store.raw = "";
12221
- },
12222
- focus () {
12223
- this.$refs.input.focus();
12224
- }
12225
- };
12226
- }
12227
-
12228
-
12229
- var $36506012e0c6e9e3$exports = {};
12230
-
12231
- $parcel$defineInteropFlag($36506012e0c6e9e3$exports);
12232
-
12233
- $parcel$export($36506012e0c6e9e3$exports, "default", () => $36506012e0c6e9e3$export$2e2bcd8739ae039);
12234
- function $36506012e0c6e9e3$export$2e2bcd8739ae039(iconName) {
12235
- return {
12236
- iconName: iconName
12237
- };
12238
- }
12239
-
12240
-
12241
12229
  var $d92d9d5253f84566$exports = {};
12242
12230
 
12243
12231
  $parcel$defineInteropFlag($d92d9d5253f84566$exports);
@@ -12282,6 +12270,18 @@ function $d92d9d5253f84566$export$2e2bcd8739ae039(store) {
12282
12270
  }
12283
12271
 
12284
12272
 
12273
+ var $36506012e0c6e9e3$exports = {};
12274
+
12275
+ $parcel$defineInteropFlag($36506012e0c6e9e3$exports);
12276
+
12277
+ $parcel$export($36506012e0c6e9e3$exports, "default", () => $36506012e0c6e9e3$export$2e2bcd8739ae039);
12278
+ function $36506012e0c6e9e3$export$2e2bcd8739ae039(iconName) {
12279
+ return {
12280
+ iconName: iconName
12281
+ };
12282
+ }
12283
+
12284
+
12285
12285
  var $506dabb2bf255b38$exports = {};
12286
12286
 
12287
12287
  $parcel$defineInteropFlag($506dabb2bf255b38$exports);
@@ -13078,15 +13078,15 @@ function $6d64716f0b34fdf4$export$2e2bcd8739ae039(store) {
13078
13078
  }
13079
13079
 
13080
13080
 
13081
- $4ae691aa3fe187ba$exports = {
13081
+ $068816311f4006ce$exports = {
13082
13082
  "button": $cbd28b10fa9798c7$exports,
13083
13083
  "code": $99486586f6691564$exports,
13084
13084
  "copy_button": $47a1c62621be0c54$exports,
13085
13085
  "dimensions_display": $e398acaded942bbe$exports,
13086
- "embed": $e1f51f020443edd4$exports,
13087
13086
  "filter": $e9904a14dabf652d$exports,
13088
- "icon": $36506012e0c6e9e3$exports,
13087
+ "embed": $e1f51f020443edd4$exports,
13089
13088
  "nav": $d92d9d5253f84566$exports,
13089
+ "icon": $36506012e0c6e9e3$exports,
13090
13090
  "split_layout": $506dabb2bf255b38$exports,
13091
13091
  "tabs": $0db07828cadc68e0$exports,
13092
13092
  "tab_panels": $a87dacf5139b5e2f$exports,
@@ -13379,7 +13379,7 @@ const $d73574cc5e9b9e72$var$prefix = window.APP_NAME;
13379
13379
  // Components
13380
13380
  (0, $caa9439642c6336c$export$2e2bcd8739ae039).data("app", (0, $d709d0f4027033b2$export$2e2bcd8739ae039));
13381
13381
  [
13382
- $4ae691aa3fe187ba$exports,
13382
+ $068816311f4006ce$exports,
13383
13383
  $fe98e3f2bf49b28f$exports,
13384
13384
  $6c10158820e535ef$exports
13385
13385
  ].forEach((scripts)=>{