marksmith 0.2.2 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cd9065c9b2a4cf7fb640152c51f9592964d2bfd17aa171b6f8decb3580d98e2
4
- data.tar.gz: a3821853114f3ec6bd488189bcbedf5b0057d806f1c05800fc5672759a304b77
3
+ metadata.gz: ed572a170bb7408c863a6da5190ffd35ed7f9070c38e93f0337982bf24cd53c4
4
+ data.tar.gz: c8c19b7705c18922362892e94e33300e18d0aa91467e1336496b5ac16168b492
5
5
  SHA512:
6
- metadata.gz: 83dbae5278cc4a481d369a6ab92a224bb638becbac950b44430021b70a0fc06ec5f3214313b2587a60475bbbbe163bedf73048651cee3d27e20bce3bfe8bbc15
7
- data.tar.gz: 7ecfde500396c1f0775fc7a4467f0031c36ab89dcab1a3a23f41d2a8680d0925861b17863b2eb862050b324e07997753fe2a58184335ccd8c8e7c2fba2bda433
6
+ metadata.gz: c7e47d37276d05e9e908ecc54ef0a98f5fc07ba6e4c7f4847d1ef01658f806baae698db75e204959a2c846bbab59d9257f3f1715c9ef4bb748588f328ab67ab2
7
+ data.tar.gz: e614a5b204d2c6587cf832426f67b95ebfcc4742ea5d757cc15c14f2ae08cea9fd6a4c23cccebc10faa8a6f02ad2d2a7c142a0d0e66762286e972457bde8e18d
data/README.md CHANGED
@@ -104,7 +104,7 @@ Marksmith accepts a few configuration options.
104
104
 
105
105
  ### Field options
106
106
 
107
- The field supports a few of the regular options like `disabled`, `placeholder`, `autofocus`, `style`, `class`, `rows`, `data`, and `value`, but also a custom one.
107
+ The field supports a few of the regular options like `disabled`, `placeholder`, `autofocus`, `style`, `class`, `data`, and `value`, but also a custom one.
108
108
 
109
109
  `extra_preview_params` - Sends extra params to the preview renderer.
110
110
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Marksmith 0.2.2
2
+ Marksmith 0.3.0
3
3
  */
4
4
  var ListContinuationController = (function () {
5
5
  'use strict';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Marksmith 0.2.2
2
+ Marksmith 0.3.0
3
3
  */
4
4
  var ListContinuationController = (function (stimulus) {
5
5
  'use strict';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Marksmith 0.2.2
2
+ Marksmith 0.3.0
3
3
  */
4
4
  var MarksmithController = (function () {
5
5
  'use strict';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Marksmith 0.2.2
2
+ Marksmith 0.3.0
3
3
  */
4
4
  var MarksmithController = (function (stimulus) {
5
5
  'use strict';
@@ -803,6 +803,9 @@
803
803
  .ms\:inline {
804
804
  display: inline;
805
805
  }
806
+ .ms\:field-sizing-content {
807
+ field-sizing: content;
808
+ }
806
809
  .ms\:size-4 {
807
810
  width: calc(var(--ms-spacing) * 4);
808
811
  height: calc(var(--ms-spacing) * 4);
@@ -811,6 +814,9 @@
811
814
  width: 100%;
812
815
  height: 100%;
813
816
  }
817
+ .ms\:min-h-60 {
818
+ min-height: calc(var(--ms-spacing) * 60);
819
+ }
814
820
  .ms\:w-full {
815
821
  width: 100%;
816
822
  }
@@ -0,0 +1,103 @@
1
+ require "uri"
2
+
3
+ class Marksmith::Editor
4
+ attr_reader :name,
5
+ :extra_preview_params,
6
+ :form,
7
+ :disabled,
8
+ :controller_data_attributes,
9
+ :classes,
10
+ :data_attributes,
11
+ :placeholder,
12
+ :autofocus,
13
+ :style,
14
+ :gallery,
15
+ :kwargs
16
+
17
+ def initialize(name:,
18
+ upload_url: nil,
19
+ rails_direct_uploads_url: nil,
20
+ enable_file_uploads: nil,
21
+ extra_preview_params: {},
22
+ form: nil,
23
+ disabled: false,
24
+ controller_data_attributes: {},
25
+ classes: nil,
26
+ data_attributes: {},
27
+ placeholder: nil,
28
+ autofocus: false,
29
+ style: nil,
30
+ gallery: {},
31
+ **kwargs)
32
+ @name = name
33
+ @kwargs = kwargs
34
+
35
+ @upload_url = upload_url
36
+ @rails_direct_uploads_url = rails_direct_uploads_url
37
+ @enable_file_uploads = enable_file_uploads
38
+ @extra_preview_params = extra_preview_params
39
+ @form = form
40
+ @disabled = disabled
41
+ @controller_data_attributes = controller_data_attributes
42
+ @classes = classes
43
+ @data_attributes = data_attributes
44
+ @placeholder = placeholder
45
+ @autofocus = autofocus
46
+ @style = style
47
+ @gallery = gallery
48
+ end
49
+
50
+ def gallery_enabled
51
+ gallery.fetch(:enabled, false)
52
+ end
53
+
54
+ def gallery_open_path
55
+ gallery.fetch(:open_path, nil)
56
+ end
57
+
58
+ def gallery_params
59
+ gallery.fetch(:params, {})
60
+ end
61
+
62
+ def gallery_turbo_frame
63
+ gallery.fetch(:turbo_frame, nil)
64
+ end
65
+
66
+ def gallery_full_path
67
+ if gallery_open_path.present?
68
+ uri = URI.parse(gallery_open_path)
69
+ uri.query = [ uri.query, gallery_params.map { |k, v| "#{k}=#{v}" }.join("&") ].compact.join("&")
70
+ uri.to_s
71
+ end
72
+ end
73
+
74
+ def upload_url
75
+ if @upload_url.present?
76
+ @upload_url
77
+ elsif defined?(ActiveStorage)
78
+ @rails_direct_uploads_url
79
+ end
80
+ end
81
+
82
+ def enable_file_uploads
83
+ if upload_url.blank?
84
+ false
85
+ elsif @enable_file_uploads.nil?
86
+ true
87
+ else
88
+ @enable_file_uploads
89
+ end
90
+ end
91
+
92
+ def field_name
93
+ form&.field_name(name) || name
94
+ end
95
+
96
+ def value
97
+ if defined?(form)
98
+ form&.object&.send(name)
99
+ else
100
+ @value || nil
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,12 @@
1
+ <markdown-toolbar for="<%= name %>" class="<%= class_names("ms:flex ms:flex-wrap", "ms:pointer-events-none": disabled) %>" data-marksmith-target="toolbar">
2
+ <%= marksmith_toolbar_button "bold" %>
3
+ <%= marksmith_toolbar_button "header" %>
4
+ <%= marksmith_toolbar_button "italic" %>
5
+ <%= marksmith_toolbar_button "quote" %>
6
+ <%= marksmith_toolbar_button "code" %>
7
+ <%= marksmith_toolbar_button "link" %>
8
+ <%= marksmith_toolbar_button "image" %>
9
+ <%= marksmith_toolbar_button "unordered-list" %>
10
+ <%= marksmith_toolbar_button "ordered-list" %>
11
+ <%= marksmith_toolbar_button "task-list" %>
12
+ </markdown-toolbar>
@@ -1,44 +1,3 @@
1
- <%
2
- data_attributes = local_assigns[:data] || {}
3
- disabled = local_assigns[:disabled] || false
4
- placeholder = local_assigns[:placeholder] || nil
5
- autofocus = local_assigns[:autofocus] || false
6
- style = local_assigns[:style] || nil
7
- classes = local_assigns[:class] || nil
8
- rows = local_assigns[:rows] || 15
9
- field_name = form&.field_name(name) || name
10
- value = if defined?(form)
11
- form.object.send(name)
12
- else
13
- local_assigns[:value] || nil
14
- end
15
- extra_preview_params = local_assigns[:extra_preview_params] || {}
16
- upload_url = if local_assigns[:upload_url].present?
17
- local_assigns[:upload_url]
18
- elsif defined?(ActiveStorage)
19
- main_app.rails_direct_uploads_url
20
- end
21
-
22
- enable_file_uploads = if upload_url.blank?
23
- false
24
- elsif local_assigns[:enable_file_uploads].nil?
25
- true
26
- else
27
- local_assigns[:enable_file_uploads]
28
- end
29
-
30
-
31
- # Used by Avo and other adapters to enable the gallery link.
32
- gallery_enabled = local_assigns.dig(:gallery, :enabled) || false
33
- gallery_open_path = local_assigns.dig(:gallery, :open_path) || nil
34
- gallery_params = local_assigns.dig(:gallery, :params) || {}
35
- if gallery_open_path.present?
36
- gallery_full_path = gallery_open_path + "?" + gallery_params.map { |k,v| "#{k}=#{v}" }.join('&')
37
- else
38
- gallery_full_path = nil
39
- end
40
- gallery_turbo_frame = local_assigns.dig(:gallery, :turbo_frame) || nil
41
- %>
42
1
  <%= content_tag :div,
43
2
  class: "marksmith ms:block ms:flex-col ms:w-full ms:border ms:border-neutral-300 ms:rounded ms:@container ms:focus-within:border-neutral-400",
44
3
  data: {
@@ -49,79 +8,15 @@
49
8
  ",
50
9
  unique_selector: ".#{@input_id}", # used to pinpoint the exact element in which to insert the attachment
51
10
  marksmith_preview_url_value: marksmith.markdown_previews_path,
52
- marksmith_file_uploads_enabled_value: enable_file_uploads,
11
+ marksmith_file_uploads_enabled_value: editor.enable_file_uploads,
53
12
  marksmith_active_tab_class: "bg-white",
54
- marksmith_attach_url_value: upload_url,
55
- marksmith_extra_preview_params_value: extra_preview_params.as_json,
56
- **local_assigns.fetch(:controller_data_attributes, {})
13
+ marksmith_attach_url_value: editor.upload_url,
14
+ marksmith_extra_preview_params_value: editor.extra_preview_params.as_json,
15
+ **editor.controller_data_attributes,
57
16
  } do %>
58
- <% toggle_button_classes = class_names(marksmith_button_classes, "ms:bg-neutral-200 ms:border-0 ms:bg-none ms:text-sm ms:hover:bg-neutral-300 ms:uppercase ms:text-xs ms:font-semibold ms:text-neutral-800") %>
59
- <div class="ms:flex-1 ms:flex-col-reverse ms:@md:flex-row ms:grow ms:flex ms:justify-bewteen ms:bg-neutral-50 ms:rounded ms:px-2 ms:py-1 ms:gap-y-1">
60
- <div class="ms:flex-1 ms:flex ms:items:center">
61
- <button class="<%= toggle_button_classes %>" data-action="click->marksmith#switchToPreview" data-marksmith-target="previewTabButton" type="button">
62
- <%= t('marksmith.preview').humanize %>
63
- </button>
64
- <button class="<%= toggle_button_classes %> ms:hidden ms:bg-neutral-200" data-action="click->marksmith#switchToWrite" data-marksmith-target="writeTabButton" type="button">
65
- <%= t('marksmith.write').humanize %>
66
- </button>
67
- </div>
68
-
69
- <markdown-toolbar for="<%= name %>" class="<%= class_names("ms:flex ms:flex-wrap", "ms:pointer-events-none": disabled) %>" data-marksmith-target="toolbar">
70
- <%= marksmith_toolbar_button "bold" %>
71
- <%= marksmith_toolbar_button "header" %>
72
- <%= marksmith_toolbar_button "italic" %>
73
- <%= marksmith_toolbar_button "quote" %>
74
- <%= marksmith_toolbar_button "code" %>
75
- <%= marksmith_toolbar_button "link" %>
76
- <%= marksmith_toolbar_button "image" %>
77
- <%= marksmith_toolbar_button "unordered-list" %>
78
- <%= marksmith_toolbar_button "ordered-list" %>
79
- <%= marksmith_toolbar_button "task-list" %>
80
- </markdown-toolbar>
81
- </div>
82
- <% toolbar_button_classes = "ms:cursor-pointer ms:hover:bg-neutral-100 ms:px-1 ms:py-px ms:rounded ms:text-sm" %>
17
+ <%= render partial: "marksmith/shared/toolbar", locals: { name: editor.name, disabled: editor.disabled } %>
83
18
  <div class="ms:border-t ms:w-full ms:border-neutral-300 ms:flex ms:flex-1">
84
- <%= content_tag :div, class: "ms:flex ms:flex-1 ms:flex-col ms:size-full", data: { marksmith_target: "fieldContainer" } do %>
85
- <%= text_area_tag field_name, value,
86
- id: name,
87
- class: class_names("ms:flex ms:flex-1 ms:rounded ms:border-none ms:resize-none ms:focus:outline-none ms:font-mono ms:focus:ring-0 ms:leading-normal ms:p-2 ms:text-sm", classes),
88
- rows: rows,
89
- data: {
90
- action: "drop->marksmith#dropUpload paste->marksmith#pasteUpload",
91
- marksmith_target: "fieldElement",
92
- **data_attributes
93
- },
94
- disabled:,
95
- placeholder:,
96
- autofocus:,
97
- style:
98
- %>
99
- <div class="ms:flex ms:flex-1 ms:flex-grow ms:space-x-2 ms:py-1 ms:border-t ms:border-neutral-300 ms:px-2 ms:font-sans ms:text-sm ms:p-2">
100
- <%= link_to "https://docs.github.com/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax", target: "_blank", class: class_names("ms:flex ms:items-center ms:text-neutral-800 ms:no-underline", toolbar_button_classes) do %>
101
- <%= image_tag asset_path("marksmith/svgs/markdown.svg"), class: "ms:inline ms:size-4 ms:mr-1" %> <%= t("marksmith.markdown_is_supported").humanize %>
102
- <% end %>
103
- <% if enable_file_uploads %>
104
- <%= button_tag data: { action: "click->marksmith#buttonUpload" }, class: class_names("ms:bg-none ms:border-none ms:bg-transparent ms:text-neutral-600 ms:items-center ms:flex", toolbar_button_classes) do %>
105
- <%= image_tag asset_path("marksmith/svgs/paperclip.svg"), class: "ms:inline ms:size-4 ms:mr-1" %> <%= t("marksmith.upload_files").humanize %>
106
- <% end %>
107
- <% end %>
108
- <% if gallery_enabled %>
109
- <%= link_to gallery_full_path, data: { turbo_frame: gallery_turbo_frame }, class: class_names("ms:flex ms:items-center ms:text-neutral-800 ms:no-underline", toolbar_button_classes) do %>
110
- <%= image_tag asset_path("marksmith/svgs/gallery.svg"), class: "ms:inline ms:size-4 ms:mr-1" %> <%= t("marksmith.attach_from_gallery").humanize %>
111
- <% end %>
112
- <% end %>
113
- </div>
114
- <% end %>
115
- <%= content_tag :div,
116
- class: "ms:hidden ms:markdown-preview ms:size-full ms:flex-1 ms:flex ms:size-full ms:p-2 ms:overflow-auto",
117
- id: "markdown-preview-#{name}",
118
- data: {
119
- marksmith_target: "previewElement",
120
- } do %>
121
- <div class="ms:button-spinner">
122
- <div class="double-bounce1"></div>
123
- <div class="double-bounce2"></div>
124
- </div>
125
- <% end %>
19
+ <%= render partial: "marksmith/shared/editor_pane", locals: { editor: } %>
20
+ <%= render partial: "marksmith/shared/preview_pane", locals: { name: editor.name } %>
126
21
  </div>
127
22
  <% end %>
@@ -0,0 +1,31 @@
1
+ <% toolbar_button_classes = "ms:cursor-pointer ms:hover:bg-neutral-100 ms:px-1 ms:py-px ms:rounded ms:text-sm" %>
2
+ <%= content_tag :div, class: "ms:flex ms:flex-1 ms:flex-col ms:size-full", data: { marksmith_target: "fieldContainer" } do %>
3
+ <%= text_area_tag editor.field_name, editor.value,
4
+ id: editor.name,
5
+ class: class_names("ms:flex ms:flex-1 ms:rounded ms:border-none ms:resize-none ms:focus:outline-none ms:font-mono ms:focus:ring-0 ms:leading-normal ms:p-2 ms:text-sm ms:field-sizing-content ms:min-h-60", editor.classes),
6
+ data: {
7
+ action: "drop->marksmith#dropUpload paste->marksmith#pasteUpload",
8
+ marksmith_target: "fieldElement",
9
+ **editor.data_attributes
10
+ },
11
+ disabled: editor.disabled,
12
+ placeholder: editor.placeholder,
13
+ autofocus: editor.autofocus,
14
+ style: editor.style
15
+ %>
16
+ <div class="ms:flex ms:flex-1 ms:flex-grow ms:space-x-2 ms:py-1 ms:border-t ms:border-neutral-300 ms:px-2 ms:font-sans ms:text-sm ms:p-2">
17
+ <%= link_to "https://docs.github.com/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax", target: "_blank", class: class_names("ms:flex ms:items-center ms:text-neutral-800 ms:no-underline", toolbar_button_classes) do %>
18
+ <%= image_tag asset_path("marksmith/svgs/markdown.svg"), class: "ms:inline ms:size-4 ms:mr-1" %> <%= t("marksmith.markdown_is_supported").humanize %>
19
+ <% end %>
20
+ <% if editor.enable_file_uploads %>
21
+ <%= button_tag data: { action: "click->marksmith#buttonUpload" }, class: class_names("ms:bg-none ms:border-none ms:bg-transparent ms:text-neutral-600 ms:items-center ms:flex", toolbar_button_classes) do %>
22
+ <%= image_tag asset_path("marksmith/svgs/paperclip.svg"), class: "ms:inline ms:size-4 ms:mr-1" %> <%= t("marksmith.upload_files").humanize %>
23
+ <% end %>
24
+ <% end %>
25
+ <% if editor.gallery_enabled %>
26
+ <%= link_to editor.gallery_full_path, data: { turbo_frame: editor.gallery_turbo_frame }, class: class_names("ms:flex ms:items-center ms:text-neutral-800 ms:no-underline", toolbar_button_classes) do %>
27
+ <%= image_tag asset_path("marksmith/svgs/gallery.svg"), class: "ms:inline ms:size-4 ms:mr-1" %> <%= t("marksmith.attach_from_gallery").humanize %>
28
+ <% end %>
29
+ <% end %>
30
+ </div>
31
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <div class="ms:button-spinner">
2
+ <div class="double-bounce1"></div>
3
+ <div class="double-bounce2"></div>
4
+ </div>
@@ -0,0 +1,8 @@
1
+ <%= content_tag :div,
2
+ class: "ms:hidden ms:markdown-preview ms:size-full ms:flex-1 ms:flex ms:size-full ms:p-2 ms:overflow-auto",
3
+ id: "markdown-preview-#{name}",
4
+ data: {
5
+ marksmith_target: "previewElement",
6
+ } do %>
7
+ <%= render partial: "marksmith/shared/loading_indicator" %>
8
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <div class="ms:flex-1 ms:flex ms:items:center">
2
+ <button class="<%= marksmith_toggle_button_classes %>" data-action="click->marksmith#switchToPreview" data-marksmith-target="previewTabButton" type="button">
3
+ <%= t('marksmith.preview').humanize %>
4
+ </button>
5
+ <button class="<%= marksmith_toggle_button_classes %> ms:hidden ms:bg-neutral-200" data-action="click->marksmith#switchToWrite" data-marksmith-target="writeTabButton" type="button">
6
+ <%= t('marksmith.write').humanize %>
7
+ </button>
8
+ </div>
@@ -0,0 +1,5 @@
1
+ <div class="ms:flex-1 ms:flex-col-reverse ms:@md:flex-row ms:grow ms:flex ms:justify-bewteen ms:bg-neutral-50 ms:rounded ms:px-2 ms:py-1 ms:gap-y-1">
2
+ <%= render partial: "marksmith/shared/tabs" %>
3
+
4
+ <%= render partial: "marksmith/shared/action_bar", locals: { name:, disabled: } %>
5
+ </div>
@@ -5,7 +5,13 @@ module Marksmith
5
5
  end
6
6
 
7
7
  def marksmith_tag(name, **kwargs, &block)
8
- render partial: "marksmith/shared/editor", locals: { name: name, **kwargs }
8
+ rails_direct_uploads_url = if defined?(ActiveStorage)
9
+ main_app.rails_direct_uploads_url
10
+ end
11
+
12
+ editor = Marksmith::Editor.new(name:, rails_direct_uploads_url:, **kwargs, &block)
13
+
14
+ render partial: "marksmith/shared/editor", locals: { name: editor.name, editor: }
9
15
  end
10
16
 
11
17
  def marksmith_asset_tags(*args, **kwargs)
@@ -21,6 +27,10 @@ module Marksmith
21
27
  content_tag "md-#{name}", marksmith_toolbar_svg(name), title: t("marksmith.#{name.to_s.gsub("-", "_")}").humanize, class: marksmith_button_classes
22
28
  end
23
29
 
30
+ def marksmith_toggle_button_classes
31
+ class_names(marksmith_button_classes, "ms:bg-neutral-200 ms:border-0 ms:bg-none ms:text-sm ms:hover:bg-neutral-300 ms:uppercase ms:text-xs ms:font-semibold ms:text-neutral-800")
32
+ end
33
+
24
34
  # TODO: maybe inline svgs in the future
25
35
  def marksmith_toolbar_svg(name)
26
36
  image_tag asset_path("marksmith/svgs/#{name}.svg"), class: "ms:inline ms:size-4"
@@ -1,3 +1,3 @@
1
1
  module Marksmith
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marksmith
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Marin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-21 00:00:00.000000000 Z
11
+ date: 2025-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -71,11 +71,18 @@ files:
71
71
  - app/frontend/entrypoints/javascript/controllers/list_continuation_controller.js
72
72
  - app/frontend/entrypoints/javascript/controllers/marksmith_controller.js
73
73
  - app/models/marksmith/application_record.rb
74
+ - app/models/marksmith/editor.rb
74
75
  - app/models/marksmith/renderer.rb
75
76
  - app/views/layouts/marksmith/application.html.erb
76
77
  - app/views/marksmith/markdown_previews/create.turbo_stream.erb
78
+ - app/views/marksmith/shared/_action_bar.html.erb
77
79
  - app/views/marksmith/shared/_editor.html.erb
80
+ - app/views/marksmith/shared/_editor_pane.html.erb
81
+ - app/views/marksmith/shared/_loading_indicator.html.erb
82
+ - app/views/marksmith/shared/_preview_pane.html.erb
78
83
  - app/views/marksmith/shared/_rendered_body.html.erb
84
+ - app/views/marksmith/shared/_tabs.html.erb
85
+ - app/views/marksmith/shared/_toolbar.html.erb
79
86
  - config/locales/marksmith.en.yml
80
87
  - config/routes.rb
81
88
  - config/vite.json