katalyst-navigation 1.8.4 → 2.0.0
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 +4 -4
- data/README.md +11 -2
- data/app/assets/builds/katalyst/navigation.esm.js +207 -109
- data/app/assets/builds/katalyst/navigation.js +207 -109
- data/app/assets/builds/katalyst/navigation.min.js +1 -1
- data/app/assets/builds/katalyst/navigation.min.js.map +1 -1
- data/app/assets/images/katalyst/navigation/icons/button.svg +1 -0
- data/app/assets/images/katalyst/navigation/icons/collapse.svg +3 -0
- data/app/assets/images/katalyst/navigation/icons/edit.svg +1 -0
- data/app/assets/images/katalyst/navigation/icons/expand.svg +3 -0
- data/app/assets/images/katalyst/navigation/icons/heading.svg +1 -0
- data/app/assets/images/katalyst/navigation/icons/hidden.svg +1 -0
- data/app/assets/images/katalyst/navigation/icons/indent.svg +3 -0
- data/app/assets/images/katalyst/navigation/icons/link.svg +1 -0
- data/app/assets/images/katalyst/navigation/icons/outdent.svg +4 -0
- data/app/assets/images/katalyst/navigation/icons/remove.svg +1 -0
- data/app/assets/stylesheets/katalyst/_navigation.scss +3 -0
- data/app/assets/stylesheets/katalyst/navigation/editor.css +175 -0
- data/app/assets/stylesheets/katalyst/navigation/icons.css +54 -0
- data/app/assets/stylesheets/katalyst/navigation/{editor/_status-bar.scss → status-bar.css} +30 -34
- data/app/assets/stylesheets/katalyst/navigation.css +3 -0
- data/app/components/katalyst/navigation/editor/base_component.rb +0 -6
- data/app/components/katalyst/navigation/editor/item_component.html.erb +26 -16
- data/app/components/katalyst/navigation/editor/item_component.rb +2 -3
- data/app/components/katalyst/navigation/editor/item_editor_component.rb +16 -19
- data/app/components/katalyst/navigation/editor/new_item_component.html.erb +15 -14
- data/app/components/katalyst/navigation/editor/new_item_component.rb +7 -10
- data/app/components/katalyst/navigation/editor/new_items_component.html.erb +41 -2
- data/app/components/katalyst/navigation/editor/new_items_component.rb +0 -2
- data/app/components/katalyst/navigation/editor/row_component.html.erb +2 -1
- data/app/components/katalyst/navigation/editor/status_bar_component.rb +9 -11
- data/app/components/katalyst/navigation/editor/table_component.html.erb +0 -6
- data/app/components/katalyst/navigation/editor/table_component.rb +12 -14
- data/app/components/katalyst/navigation/editor_component.html.erb +7 -0
- data/app/components/katalyst/navigation/editor_component.rb +13 -16
- data/app/controllers/katalyst/navigation/items_controller.rb +1 -1
- data/app/controllers/katalyst/navigation/menus_controller.rb +1 -1
- data/app/javascript/navigation/application.js +8 -3
- data/app/javascript/navigation/editor/item.js +1 -1
- data/app/javascript/navigation/editor/item_editor_controller.js +54 -0
- data/app/javascript/navigation/editor/list_controller.js +11 -103
- data/app/javascript/navigation/editor/new_items_controller.js +145 -0
- data/app/views/katalyst/navigation/items/_button.html.erb +24 -28
- data/app/views/katalyst/navigation/items/_form.html.erb +6 -0
- data/app/views/katalyst/navigation/items/_form_errors.html.erb +1 -1
- data/app/views/katalyst/navigation/items/_heading.html.erb +12 -14
- data/app/views/katalyst/navigation/items/_link.html.erb +24 -26
- data/app/views/katalyst/navigation/items/edit.html.erb +40 -2
- data/app/views/katalyst/navigation/items/edit.turbo_stream.erb +2 -0
- data/app/views/katalyst/navigation/items/update.turbo_stream.erb +0 -1
- data/app/views/katalyst/navigation/menus/show.html.erb +0 -1
- data/lib/katalyst/navigation/engine.rb +0 -1
- metadata +21 -28
- data/app/assets/stylesheets/katalyst/navigation/editor/_icon.scss +0 -17
- data/app/assets/stylesheets/katalyst/navigation/editor/_index.scss +0 -145
- data/app/assets/stylesheets/katalyst/navigation/editor/_item-actions.scss +0 -93
- data/app/assets/stylesheets/katalyst/navigation/editor/_item-rules.scss +0 -19
- data/app/assets/stylesheets/katalyst/navigation/editor/_new-items.scss +0 -67
- data/app/javascript/navigation/editor/new_item_controller.js +0 -12
@@ -1,24 +1,34 @@
|
|
1
1
|
<%= tag.div(**html_attributes) do %>
|
2
|
-
<div class="tree"
|
3
|
-
<
|
4
|
-
<span role="button" value="collapse" data-action="click-><%= MENU_CONTROLLER %>#collapse" title="Collapse tree"></span>
|
5
|
-
<span role="button" value="expand" data-action="click-><%= MENU_CONTROLLER %>#expand" title="Expand tree"></span>
|
6
|
-
</div>
|
2
|
+
<div class="tree">
|
3
|
+
<icon class="icon" data-icon="<%= item.model_name.param_key %>" aria-hidden="true"> </icon>
|
7
4
|
|
8
|
-
|
9
|
-
<h4 class="heading" title="<%= item.title %>"><%= item.title %></h4>
|
10
|
-
<span role="img" value="invisible" title="Hidden"></span>
|
11
|
-
</div>
|
5
|
+
<%= link_to_if(item.url.presence, item.title, item.url, target: "_blank", rel: "noopener") %>
|
12
6
|
|
13
|
-
|
14
|
-
|
7
|
+
<% unless item.visible? %>
|
8
|
+
<icon class="icon" data-icon="hidden" title="Hidden" role="img"> </icon>
|
9
|
+
<% end %>
|
15
10
|
</div>
|
16
11
|
|
17
|
-
<div role="toolbar"
|
18
|
-
<
|
19
|
-
|
20
|
-
|
21
|
-
<
|
12
|
+
<div role="toolbar" class="actions-group">
|
13
|
+
<button class="button" data-button-padding="tight" data-text-button data-action="navigation--editor--menu#collapse" title="Collapse tree">
|
14
|
+
<icon class="icon" data-icon="collapse" role="img"> </icon>
|
15
|
+
</button>
|
16
|
+
<button class="button" data-button-padding="tight" data-text-button data-action="navigation--editor--menu#expand" title="Expand tree">
|
17
|
+
<icon class="icon" data-icon="expand" role="img"> </icon>
|
18
|
+
</button>
|
19
|
+
<button class="button" data-button-padding="tight" data-text-button data-action="navigation--editor--menu#deNest" title="Outdent">
|
20
|
+
<icon class="icon" data-icon="outdent" role="img"> </icon>
|
21
|
+
</button>
|
22
|
+
<button class="button" data-button-padding="tight" data-text-button data-action="navigation--editor--menu#nest" title="Indent">
|
23
|
+
<icon class="icon" data-icon="indent" role="img"> </icon>
|
24
|
+
</button>
|
25
|
+
<%= link_to(edit_item_link, class: "button", title: "Edit", value: "edit",
|
26
|
+
data: { text_button: "", button_padding: "tight", turbo_frame: "navigation--editor--item-editor" }) do %>
|
27
|
+
<icon class="icon" data-icon="edit" role="img"> </icon>
|
28
|
+
<% end %>
|
29
|
+
<button class="button" data-button-padding="tight" data-text-button data-action="navigation--editor--menu#remove" title="Remove">
|
30
|
+
<icon class="icon" data-icon="remove" role="img"> </icon>
|
31
|
+
</button>
|
22
32
|
</div>
|
23
33
|
|
24
34
|
<input autocomplete="off" type="hidden" name="<%= attributes_scope %>[id]" value="<%= item.id %>">
|
@@ -4,8 +4,6 @@ module Katalyst
|
|
4
4
|
module Navigation
|
5
5
|
module Editor
|
6
6
|
class ItemComponent < BaseComponent
|
7
|
-
include KpopHelper
|
8
|
-
|
9
7
|
def edit_item_link
|
10
8
|
if item.persisted?
|
11
9
|
helpers.katalyst_navigation.edit_menu_item_path(menu, item)
|
@@ -20,7 +18,8 @@ module Katalyst
|
|
20
18
|
{
|
21
19
|
id: dom_id(item),
|
22
20
|
data: {
|
23
|
-
controller:
|
21
|
+
controller: "navigation--editor--item",
|
22
|
+
invisible: ("" unless item.visible?),
|
24
23
|
},
|
25
24
|
}
|
26
25
|
end
|
@@ -3,24 +3,28 @@
|
|
3
3
|
module Katalyst
|
4
4
|
module Navigation
|
5
5
|
module Editor
|
6
|
-
class ItemEditorComponent <
|
7
|
-
|
6
|
+
class ItemEditorComponent < ViewComponent::Base
|
7
|
+
attr_reader :menu, :item
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
alias_method :model, :item
|
10
|
+
|
11
|
+
def initialize(menu:, item:)
|
12
|
+
super()
|
13
|
+
|
14
|
+
@menu = menu
|
15
|
+
@item = item
|
13
16
|
end
|
14
17
|
|
15
18
|
def call
|
16
|
-
|
17
|
-
helpers.extend(Helpers)
|
18
|
-
helpers.render(item.model_name.param_key, item:, path:)
|
19
|
-
end
|
19
|
+
render("form", model:, scope:, url:, id:)
|
20
20
|
end
|
21
21
|
|
22
22
|
def id
|
23
|
-
|
23
|
+
dom_id(item, :form)
|
24
|
+
end
|
25
|
+
|
26
|
+
def scope
|
27
|
+
:item
|
24
28
|
end
|
25
29
|
|
26
30
|
def title
|
@@ -31,20 +35,13 @@ module Katalyst
|
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
34
|
-
def
|
38
|
+
def url
|
35
39
|
if item.persisted?
|
36
40
|
view_context.katalyst_navigation.menu_item_path(menu, item)
|
37
41
|
else
|
38
42
|
view_context.katalyst_navigation.menu_items_path(menu)
|
39
43
|
end
|
40
44
|
end
|
41
|
-
|
42
|
-
def default_html_attributes
|
43
|
-
{
|
44
|
-
id:,
|
45
|
-
class: "navigation--item-editor",
|
46
|
-
}
|
47
|
-
end
|
48
45
|
end
|
49
46
|
end
|
50
47
|
end
|
@@ -1,14 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
<% end %>
|
1
|
+
<li>
|
2
|
+
<%= tag.button(**html_attributes) do %>
|
3
|
+
<icon class="icon" data-icon="<%= icon_name %>" role="img"> </icon>
|
4
|
+
<%= label %>
|
5
|
+
<%#
|
6
|
+
# Template is stored inside the new item dom, and copied into the dom when
|
7
|
+
# the user selects the item.
|
8
|
+
%>
|
9
|
+
<template>
|
10
|
+
<%= render row_component do %>
|
11
|
+
<%= render item_component %>
|
12
|
+
<% end %>
|
13
|
+
</template>
|
14
|
+
<% end %>
|
15
|
+
</li>
|
@@ -4,10 +4,6 @@ module Katalyst
|
|
4
4
|
module Navigation
|
5
5
|
module Editor
|
6
6
|
class NewItemComponent < BaseComponent
|
7
|
-
ACTIONS = <<~ACTIONS.gsub(/\s+/, " ").freeze
|
8
|
-
dragstart->#{NEW_ITEM_CONTROLLER}#dragstart
|
9
|
-
ACTIONS
|
10
|
-
|
11
7
|
with_collection_parameter :item
|
12
8
|
|
13
9
|
def initialize(item:, menu: item.menu)
|
@@ -30,16 +26,17 @@ module Katalyst
|
|
30
26
|
item.model_name.param_key
|
31
27
|
end
|
32
28
|
|
29
|
+
alias icon_name item_type
|
30
|
+
|
33
31
|
private
|
34
32
|
|
35
33
|
def default_html_attributes
|
36
34
|
{
|
37
|
-
|
38
|
-
role:
|
39
|
-
data:
|
40
|
-
|
41
|
-
|
42
|
-
action: ACTIONS,
|
35
|
+
class: "button",
|
36
|
+
role: "listitem",
|
37
|
+
data: {
|
38
|
+
ghost_button: "",
|
39
|
+
action: "navigation--editor--new-items#add",
|
43
40
|
},
|
44
41
|
}
|
45
42
|
end
|
@@ -1,3 +1,42 @@
|
|
1
|
-
<div class="navigation--editor--new-items"
|
2
|
-
|
1
|
+
<div class="navigation--editor--new-items"
|
2
|
+
data-controller="navigation--editor--new-items"
|
3
|
+
data-action="turbo:before-morph-element->navigation--editor--new-items#morph">
|
4
|
+
<button aria-controls="navigation--editor--new-items-dialog"
|
5
|
+
class="button"
|
6
|
+
data-action="click->navigation--editor--new-items#open"
|
7
|
+
data-button-padding="tight"
|
8
|
+
data-text-button>
|
9
|
+
<icon aria-hidden="true" class="icon" data-icon="add"> </icon>
|
10
|
+
Add item
|
11
|
+
</button>
|
12
|
+
<div class="navigation--editor--inline-add" data-navigation--editor--new-items-target="inline" hidden>
|
13
|
+
<button aria-controls="navigation--editor--new-items-dialog"
|
14
|
+
class="button"
|
15
|
+
data-action="navigation--editor--new-items#open"
|
16
|
+
data-button-padding="tight">
|
17
|
+
<icon aria-hidden="true" class="icon" data-icon="add"> </icon>
|
18
|
+
<span class="visually-hidden">Add item here</span>
|
19
|
+
</button>
|
20
|
+
</div>
|
21
|
+
<dialog id="navigation--editor--new-items-dialog" class="modal" data-action="click->navigation--editor--new-items#close">
|
22
|
+
<article class="flow" data-action="click->navigation--editor--new-items#noop:stop">
|
23
|
+
<header class="repel" data-nowrap>
|
24
|
+
<h2>Add item</h2>
|
25
|
+
<button class="button"
|
26
|
+
data-action="click->navigation--editor--new-items#close"
|
27
|
+
data-button-padding="tight"
|
28
|
+
data-text-button>
|
29
|
+
<icon aria-hidden="true" class="icon" data-icon="close"> </icon>
|
30
|
+
<span class="visually-hidden">Close</span>
|
31
|
+
</button>
|
32
|
+
</header>
|
33
|
+
<main>
|
34
|
+
<%= tag.div(role: "list", data: { action: "click->navigation--editor--new-items#noop:stop" }) do %>
|
35
|
+
<ul role="list" class="items-list">
|
36
|
+
<%= render Katalyst::Navigation::Editor::NewItemComponent.with_collection(items) %>
|
37
|
+
</ul>
|
38
|
+
<% end %>
|
39
|
+
</main>
|
40
|
+
</article>
|
41
|
+
</dialog>
|
3
42
|
</div>
|
@@ -4,11 +4,6 @@ module Katalyst
|
|
4
4
|
module Navigation
|
5
5
|
module Editor
|
6
6
|
class StatusBarComponent < BaseComponent
|
7
|
-
ACTIONS = <<~ACTIONS.gsub(/\s+/, " ").freeze
|
8
|
-
navigation:change@document->#{STATUS_BAR_CONTROLLER}#change
|
9
|
-
turbo:morph-element->#{STATUS_BAR_CONTROLLER}#morph
|
10
|
-
ACTIONS
|
11
|
-
|
12
7
|
attr_reader :container
|
13
8
|
|
14
9
|
def call
|
@@ -28,10 +23,10 @@ module Katalyst
|
|
28
23
|
|
29
24
|
def actions
|
30
25
|
tag.menu do
|
31
|
-
concat action(:discard, class: "button
|
32
|
-
concat action(:revert, class: "button
|
33
|
-
concat action(:save, class: "button
|
34
|
-
concat action(:publish, class: "button
|
26
|
+
concat action(:discard, class: "button", data: { text_button: "" })
|
27
|
+
concat action(:revert, class: "button", data: { text_button: "" }) if menu.state == :draft
|
28
|
+
concat action(:save, class: "button", data: { ghost_button: "" })
|
29
|
+
concat action(:publish, class: "button")
|
35
30
|
end
|
36
31
|
end
|
37
32
|
|
@@ -50,8 +45,11 @@ module Katalyst
|
|
50
45
|
def default_html_attributes
|
51
46
|
{
|
52
47
|
data: {
|
53
|
-
controller:
|
54
|
-
action:
|
48
|
+
controller: "navigation--editor--status-bar",
|
49
|
+
action: %w[
|
50
|
+
navigation:change@document->navigation--editor--status-bar#change
|
51
|
+
turbo:morph-element->navigation--editor--status-bar#morph
|
52
|
+
],
|
55
53
|
state: menu.state,
|
56
54
|
},
|
57
55
|
}
|
@@ -4,16 +4,6 @@ module Katalyst
|
|
4
4
|
module Navigation
|
5
5
|
module Editor
|
6
6
|
class TableComponent < BaseComponent
|
7
|
-
ACTIONS = <<~ACTIONS.gsub(/\s+/, " ").freeze
|
8
|
-
dragstart->#{LIST_CONTROLLER}#dragstart
|
9
|
-
dragover->#{LIST_CONTROLLER}#dragover
|
10
|
-
dragenter->#{LIST_CONTROLLER}#dragenter
|
11
|
-
dragleave->#{LIST_CONTROLLER}#dragleave
|
12
|
-
drop->#{LIST_CONTROLLER}#drop
|
13
|
-
dragend->#{LIST_CONTROLLER}#dragend
|
14
|
-
keyup.esc@document->#{LIST_CONTROLLER}#dragend
|
15
|
-
ACTIONS
|
16
|
-
|
17
7
|
renders_many :items, ->(item) do
|
18
8
|
row = RowComponent.new(item:, menu:)
|
19
9
|
row.with_content(render(ItemComponent.new(item:, menu:)))
|
@@ -24,11 +14,19 @@ module Katalyst
|
|
24
14
|
|
25
15
|
def default_html_attributes
|
26
16
|
{
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
17
|
+
class: "katalyst--navigation--editor",
|
18
|
+
data: {
|
19
|
+
controller: "navigation--editor--list",
|
20
|
+
action: %w[
|
21
|
+
dragstart->navigation--editor--list#dragstart
|
22
|
+
dragover->navigation--editor--list#dragover
|
23
|
+
drop->navigation--editor--list#drop
|
24
|
+
dragend->navigation--editor--list#dragend
|
25
|
+
keyup.esc@document->navigation--editor--list#dragend
|
26
|
+
],
|
27
|
+
"navigation--editor--menu-target": "menu",
|
31
28
|
},
|
29
|
+
role: "list",
|
32
30
|
}
|
33
31
|
end
|
34
32
|
end
|
@@ -6,4 +6,11 @@
|
|
6
6
|
<%= render Katalyst::Navigation::Editor::TableComponent.new(menu:) do |list| %>
|
7
7
|
<%= menu.draft_items.each { |item| list.with_item(item) } %>
|
8
8
|
<% end %>
|
9
|
+
|
10
|
+
<%= render Katalyst::Navigation::Editor::NewItemsComponent.new(menu:) %>
|
9
11
|
<% end %>
|
12
|
+
|
13
|
+
<%= turbo_frame_tag(
|
14
|
+
"navigation--editor--item-editor",
|
15
|
+
data: { controller: "navigation--editor--item-editor" },
|
16
|
+
) %>
|
@@ -3,22 +3,12 @@
|
|
3
3
|
module Katalyst
|
4
4
|
module Navigation
|
5
5
|
class EditorComponent < Editor::BaseComponent
|
6
|
-
|
7
|
-
submit->#{MENU_CONTROLLER}#reindex
|
8
|
-
navigation:drop->#{MENU_CONTROLLER}#drop
|
9
|
-
navigation:reindex->#{MENU_CONTROLLER}#reindex
|
10
|
-
navigation:reset->#{MENU_CONTROLLER}#reset
|
11
|
-
turbo:render@document->#{MENU_CONTROLLER}#connect
|
12
|
-
ACTIONS
|
6
|
+
include ::Turbo::FramesHelper
|
13
7
|
|
14
8
|
def status_bar
|
15
9
|
@status_bar ||= Editor::StatusBarComponent.new(menu:)
|
16
10
|
end
|
17
11
|
|
18
|
-
def new_items
|
19
|
-
@new_items ||= Editor::NewItemsComponent.new(menu:)
|
20
|
-
end
|
21
|
-
|
22
12
|
def item_editor(item:)
|
23
13
|
Editor::ItemEditorComponent.new(menu:, item:)
|
24
14
|
end
|
@@ -35,11 +25,18 @@ module Katalyst
|
|
35
25
|
|
36
26
|
def default_html_attributes
|
37
27
|
{
|
38
|
-
id:
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
28
|
+
id: menu_form_id,
|
29
|
+
class: "navigation--editor",
|
30
|
+
data: {
|
31
|
+
controller: "navigation--editor--menu",
|
32
|
+
action: %w[
|
33
|
+
submit->navigation--editor--menu#reindex
|
34
|
+
navigation:drop->navigation--editor--menu#drop
|
35
|
+
navigation:reindex->navigation--editor--menu#reindex
|
36
|
+
navigation:reset->navigation--editor--menu#reset
|
37
|
+
turbo:render@document->navigation--editor--menu#connect
|
38
|
+
],
|
39
|
+
"navigation--editor--menu-max-depth-value": menu.depth,
|
43
40
|
},
|
44
41
|
}
|
45
42
|
end
|
@@ -83,7 +83,7 @@ module Katalyst
|
|
83
83
|
def menu_params
|
84
84
|
return {} if params[:menu].blank?
|
85
85
|
|
86
|
-
params.
|
86
|
+
params.expect(menu: [:title, :slug, :depth, { items_attributes: [%i[id index depth]] }])
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import MenuController from "./editor/menu_controller";
|
2
2
|
import ItemController from "./editor/item_controller";
|
3
|
+
import ItemEditorController from "./editor/item_editor_controller";
|
3
4
|
import ListController from "./editor/list_controller";
|
4
|
-
import
|
5
|
+
import NewItemsController from "./editor/new_items_controller";
|
5
6
|
import StatusBarController from "./editor/status_bar_controller";
|
6
7
|
|
7
8
|
const Definitions = [
|
@@ -13,13 +14,17 @@ const Definitions = [
|
|
13
14
|
identifier: "navigation--editor--item",
|
14
15
|
controllerConstructor: ItemController,
|
15
16
|
},
|
17
|
+
{
|
18
|
+
identifier: "navigation--editor--item-editor",
|
19
|
+
controllerConstructor: ItemEditorController,
|
20
|
+
},
|
16
21
|
{
|
17
22
|
identifier: "navigation--editor--list",
|
18
23
|
controllerConstructor: ListController,
|
19
24
|
},
|
20
25
|
{
|
21
|
-
identifier: "navigation--editor--new-
|
22
|
-
controllerConstructor:
|
26
|
+
identifier: "navigation--editor--new-items",
|
27
|
+
controllerConstructor: NewItemsController,
|
23
28
|
},
|
24
29
|
{
|
25
30
|
identifier: "navigation--editor--status-bar",
|
@@ -262,7 +262,7 @@ export default class Item {
|
|
262
262
|
*/
|
263
263
|
function createChildrenList(node) {
|
264
264
|
const childrenList = document.createElement("ol");
|
265
|
-
childrenList.
|
265
|
+
childrenList.toggleAttribute("hidden", true);
|
266
266
|
|
267
267
|
childrenList.dataset[`navigationChildren`] = "";
|
268
268
|
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import { Controller } from "@hotwired/stimulus";
|
2
|
+
import Item from "./item";
|
3
|
+
|
4
|
+
export default class ItemEditorController extends Controller {
|
5
|
+
static targets = ["dialog"];
|
6
|
+
|
7
|
+
connect() {
|
8
|
+
this.element.addEventListener("turbo:submit-end", this.onSubmit);
|
9
|
+
}
|
10
|
+
|
11
|
+
disconnect() {
|
12
|
+
this.element.removeEventListener("turbo:submit-end", this.onSubmit);
|
13
|
+
}
|
14
|
+
|
15
|
+
dismiss() {
|
16
|
+
if (!this.dialogTarget) return;
|
17
|
+
if (!this.dialogTarget.open) this.dialogTarget.close();
|
18
|
+
|
19
|
+
if (!("itemPersisted" in this.dialogTarget.dataset)) {
|
20
|
+
this.#removeTargetItem();
|
21
|
+
}
|
22
|
+
|
23
|
+
this.element.removeAttribute("src");
|
24
|
+
this.dialogTarget.remove();
|
25
|
+
}
|
26
|
+
|
27
|
+
dialogTargetConnected(dialog) {
|
28
|
+
dialog.showModal();
|
29
|
+
}
|
30
|
+
|
31
|
+
onSubmit = (event) => {
|
32
|
+
if (event.detail.success) {
|
33
|
+
this.dialogTarget.close();
|
34
|
+
this.element.removeAttribute("src");
|
35
|
+
this.dialogTarget.remove();
|
36
|
+
}
|
37
|
+
};
|
38
|
+
|
39
|
+
noop() {}
|
40
|
+
|
41
|
+
#removeTargetItem() {
|
42
|
+
const el = document.getElementById(this.dialogTarget.dataset.itemId);
|
43
|
+
const item = new Item(el.closest("[data-navigation-item]"));
|
44
|
+
const list = item.node.parentElement;
|
45
|
+
|
46
|
+
item.node.remove();
|
47
|
+
|
48
|
+
this.dispatch("reindex", {
|
49
|
+
target: list,
|
50
|
+
bubbles: true,
|
51
|
+
prefix: "navigation",
|
52
|
+
});
|
53
|
+
}
|
54
|
+
}
|