rails_design 0.0.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.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/README.md +18 -0
  4. data/Rakefile +18 -0
  5. data/app/assets/images/image-square.png +0 -0
  6. data/app/assets/images/logo.png +0 -0
  7. data/app/assets/javascripts/default_form/datetime.js +31 -0
  8. data/app/assets/javascripts/default_form/default_valid.js +101 -0
  9. data/app/assets/javascripts/default_form/field.js +33 -0
  10. data/app/assets/javascripts/default_form/index.js +9 -0
  11. data/app/assets/javascripts/default_form/valid_weui.js +17 -0
  12. data/app/assets/javascripts/rails_design/attachment.js +295 -0
  13. data/app/assets/javascripts/rails_design/cable.js +3 -0
  14. data/app/assets/javascripts/rails_design/dataset.js +39 -0
  15. data/app/assets/javascripts/rails_design/index.js +4 -0
  16. data/app/assets/javascripts/rails_design/stimulus.js +19 -0
  17. data/app/assets/javascripts/rails_design/turbo.js +35 -0
  18. data/app/assets/javascripts/stimulus_com/checkbox.js +77 -0
  19. data/app/assets/javascripts/stimulus_com/choice.js +18 -0
  20. data/app/assets/javascripts/stimulus_com/common.js +52 -0
  21. data/app/assets/javascripts/stimulus_com/count_down.js +27 -0
  22. data/app/assets/javascripts/stimulus_com/former.js +26 -0
  23. data/app/assets/javascripts/stimulus_com/hover.js +40 -0
  24. data/app/assets/javascripts/stimulus_com/index.js +58 -0
  25. data/app/assets/javascripts/stimulus_com/input.js +36 -0
  26. data/app/assets/javascripts/stimulus_com/menu.js +34 -0
  27. data/app/assets/javascripts/stimulus_com/modal.js +85 -0
  28. data/app/assets/javascripts/stimulus_com/modal_show.js +16 -0
  29. data/app/assets/javascripts/stimulus_com/navbar.js +11 -0
  30. data/app/assets/javascripts/stimulus_com/notice.js +10 -0
  31. data/app/assets/javascripts/stimulus_com/picture.js +85 -0
  32. data/app/assets/javascripts/stimulus_com/show.js +26 -0
  33. data/app/assets/javascripts/stimulus_com/showcase.js +34 -0
  34. data/app/assets/javascripts/stimulus_com/slide.js +188 -0
  35. data/app/assets/javascripts/stimulus_com/slide_y.js +189 -0
  36. data/app/assets/javascripts/stimulus_com/sortable.js +41 -0
  37. data/app/assets/javascripts/stimulus_com/sticky.js +11 -0
  38. data/app/assets/javascripts/stimulus_com/swipe.js +78 -0
  39. data/app/assets/javascripts/stimulus_com/taxon.js +45 -0
  40. data/app/assets/javascripts/stimulus_com/time.js +19 -0
  41. data/app/assets/javascripts/stimulus_com/touch.js +83 -0
  42. data/app/assets/javascripts/stimulus_com/tree.js +34 -0
  43. data/app/assets/javascripts/stimulus_com/tree_remote.js +64 -0
  44. data/app/assets/javascripts/stimulus_com/typer.js +41 -0
  45. data/app/assets/javascripts/stimulus_com/visit.js +61 -0
  46. data/app/assets/javascripts/stimulus_phone/index.js +19 -0
  47. data/app/assets/javascripts/stimulus_phone/qq_map.js +29 -0
  48. data/app/assets/javascripts/stimulus_phone/search.js +37 -0
  49. data/app/assets/javascripts/stimulus_phone/wechat.js +80 -0
  50. data/app/assets/javascripts/stimulus_phone/weui-actionsheet.js +43 -0
  51. data/app/assets/javascripts/stimulus_phone/weui-datepicker.js +38 -0
  52. data/app/assets/javascripts/stimulus_phone/weui-dialog.js +24 -0
  53. data/app/assets/javascripts/stimulus_phone/weui-picker.js +54 -0
  54. data/app/assets/javascripts/stimulus_phone/wxpay.js +29 -0
  55. data/app/assets/stylesheets/app.scss +3 -0
  56. data/app/assets/stylesheets/ext_bulma/base/_all.scss +5 -0
  57. data/app/assets/stylesheets/ext_bulma/base/_choices.scss +3 -0
  58. data/app/assets/stylesheets/ext_bulma/base/_global.scss +19 -0
  59. data/app/assets/stylesheets/ext_bulma/base/_main.scss +15 -0
  60. data/app/assets/stylesheets/ext_bulma/components/_all.scss +10 -0
  61. data/app/assets/stylesheets/ext_bulma/components/_box.scss +15 -0
  62. data/app/assets/stylesheets/ext_bulma/components/_breadcrumb.scss +17 -0
  63. data/app/assets/stylesheets/ext_bulma/components/_card.scss +12 -0
  64. data/app/assets/stylesheets/ext_bulma/components/_level.scss +8 -0
  65. data/app/assets/stylesheets/ext_bulma/components/_media.scss +14 -0
  66. data/app/assets/stylesheets/ext_bulma/components/_menu.scss +76 -0
  67. data/app/assets/stylesheets/ext_bulma/components/_pagination.scss +9 -0
  68. data/app/assets/stylesheets/ext_bulma/components/_panel.scss +5 -0
  69. data/app/assets/stylesheets/ext_bulma/elements/_all.scss +7 -0
  70. data/app/assets/stylesheets/ext_bulma/elements/_button.scss +14 -0
  71. data/app/assets/stylesheets/ext_bulma/elements/_fa.scss +4 -0
  72. data/app/assets/stylesheets/ext_bulma/elements/_image.scss +38 -0
  73. data/app/assets/stylesheets/ext_bulma/elements/_table.scss +52 -0
  74. data/app/assets/stylesheets/ext_bulma/elements/_title.scss +9 -0
  75. data/app/assets/stylesheets/ext_bulma/expand/_all.scss +2 -0
  76. data/app/assets/stylesheets/ext_bulma/expand/_slide.scss +26 -0
  77. data/app/assets/stylesheets/ext_bulma/expand/_sortable.scss +4 -0
  78. data/app/assets/stylesheets/ext_bulma/form/_all.scss +34 -0
  79. data/app/assets/stylesheets/ext_bulma/form/_checkbox.scss +267 -0
  80. data/app/assets/stylesheets/ext_bulma/form/_file.scss +23 -0
  81. data/app/assets/stylesheets/ext_bulma/form/_select.scss +5 -0
  82. data/app/assets/stylesheets/ext_bulma/form/_tools.scss +30 -0
  83. data/app/assets/stylesheets/ext_bulma/grid/_all.scss +3 -0
  84. data/app/assets/stylesheets/ext_bulma/grid/_columns.scss +13 -0
  85. data/app/assets/stylesheets/ext_bulma/helpers/_all.scss +5 -0
  86. data/app/assets/stylesheets/ext_bulma/helpers/_dot.scss +11 -0
  87. data/app/assets/stylesheets/ext_bulma/helpers/_drawable.scss +3 -0
  88. data/app/assets/stylesheets/ext_bulma/helpers/_grid.scss +10 -0
  89. data/app/assets/stylesheets/ext_bulma/index.scss +22 -0
  90. data/app/assets/stylesheets/ext_bulma/layout/_all.scss +4 -0
  91. data/app/assets/stylesheets/ext_bulma/layout/_footer.scss +4 -0
  92. data/app/assets/stylesheets/ext_bulma/layout/_level.scss +1 -0
  93. data/app/assets/stylesheets/ext_choices/index.scss +16 -0
  94. data/app/assets/stylesheets/ext_font/index.scss +4 -0
  95. data/app/assets/stylesheets/ext_weui/index.scss +24 -0
  96. data/app/assets/stylesheets/ext_weui/widget/_actionsheet.scss +3 -0
  97. data/app/assets/stylesheets/ext_weui/widget/_article.scss +7 -0
  98. data/app/assets/stylesheets/ext_weui/widget/_button.scss +7 -0
  99. data/app/assets/stylesheets/ext_weui/widget/_cell.scss +17 -0
  100. data/app/assets/stylesheets/ext_weui/widget/_form.scss +3 -0
  101. data/app/assets/stylesheets/ext_weui/widget/_half_screen_dialog.scss +10 -0
  102. data/app/assets/stylesheets/ext_weui/widget/_icon.scss +9 -0
  103. data/app/assets/stylesheets/ext_weui/widget/_media.scss +43 -0
  104. data/app/assets/stylesheets/ext_weui/widget/_panel.scss +4 -0
  105. data/app/assets/stylesheets/ext_weui/widget/_preview.scss +5 -0
  106. data/app/assets/stylesheets/ext_weui/widget/_search.scss +5 -0
  107. data/app/assets/stylesheets/ext_weui/widget/_tab.scss +10 -0
  108. data/app/assets/stylesheets/ext_weui/widget/_tabbar.scss +12 -0
  109. data/app/assets/stylesheets/ext_weui/widget/_uploader.scss +14 -0
  110. data/app/assets/stylesheets/phone.scss +6 -0
  111. data/app/assets/stylesheets/slide/index.scss +208 -0
  112. data/app/assets/stylesheets/ui_tooltip/_mixins.scss +46 -0
  113. data/app/assets/stylesheets/ui_tooltip/_variables.scss +5 -0
  114. data/app/assets/stylesheets/ui_tooltip/index.scss +278 -0
  115. data/app/controllers/design/base_controller.rb +4 -0
  116. data/app/controllers/design/home_controller.rb +13 -0
  117. data/app/views/design/home/swipe.html.erb +7 -0
  118. data/app/views/layouts/ui/base.html.erb +5 -0
  119. data/config/routes.rb +11 -0
  120. data/lib/rails_design/config.rb +8 -0
  121. data/lib/rails_design/engine.rb +5 -0
  122. data/lib/rails_design.rb +2 -0
  123. metadata +181 -0
@@ -0,0 +1,3 @@
1
+ import { createConsumer } from '@rails/actioncable'
2
+
3
+ export default createConsumer()
@@ -0,0 +1,39 @@
1
+ // el.dataset.add('controller', 'xx')
2
+ // el.dataset.add('', 'xx')
3
+ DOMStringMap.prototype.add = function(name, value) {
4
+ if (typeof this[name] === 'string') {
5
+ let values = this[name].split(' ')
6
+ if (!values.includes(value)) {
7
+ values.push(value)
8
+ }
9
+ this[name] = values.join(' ')
10
+ } else {
11
+ this[name] = value
12
+ }
13
+ }
14
+
15
+ // el.dataset.remove('controller', 'xx')
16
+ DOMStringMap.prototype.remove = function(name, value) {
17
+ if (typeof this[name] === 'string') {
18
+ let values = this[name].split(' ')
19
+ let index = values.indexOf(value)
20
+ if (index > -1) {
21
+ values.splice(index, 1)
22
+ }
23
+ this[name] = values.join(' ')
24
+ }
25
+ }
26
+
27
+ // el.dataset.replace('action', old, 'new')
28
+ DOMStringMap.prototype.replace = function(name, old_value, new_value) {
29
+ if (typeof this[name] === 'string') {
30
+ let values = this[name].split(' ')
31
+ let reg = new RegExp(old_value)
32
+ values.forEach((ele, index) => {
33
+ if (reg.test(ele)) {
34
+ values[index] = String(ele).replace(old_value, new_value)
35
+ }
36
+ })
37
+ this[name] = values.join(' ')
38
+ }
39
+ }
@@ -0,0 +1,4 @@
1
+ import '../stimulus_com'
2
+ import '../default_form'
3
+ import './dataset'
4
+ import './turbo'
@@ -0,0 +1,19 @@
1
+ import { Application, Controller } from '@hotwired/stimulus'
2
+ export const application = Application.start()
3
+ application.debug = true
4
+ window.application = application
5
+
6
+ Controller.prototype.submit = function(form) {
7
+ let evt = document.createEvent('Event')
8
+ evt.initEvent('submit', true, true)
9
+ form.dispatchEvent(evt)
10
+ }
11
+
12
+ Controller.prototype.csrfToken = function() {
13
+ let meta = document.querySelector('meta[name=csrf-token]')
14
+ return meta && meta.content
15
+ }
16
+
17
+ HTMLElement.prototype.controller = function(identifier) {
18
+ return application.getControllerForElementAndIdentifier(this, identifier)
19
+ }
@@ -0,0 +1,35 @@
1
+ import * as Turbo from '@hotwired/turbo'
2
+ window.Turbo = Turbo
3
+
4
+ document.addEventListener('turbo:before-fetch-request', event => {
5
+ let xhr = event.detail.fetchOptions
6
+ xhr.headers['Utc-Offset'] = (new Date).getTimezoneOffset()
7
+ //xhr.headers['X-Csp-Nonce'] = Rails.cspNonce()
8
+ })
9
+
10
+ document.addEventListener('turbo:before-cache', event => {
11
+ let modal = document.getElementById('modal')
12
+ if (modal) {
13
+ modal.removeAttribute('src')
14
+ }
15
+ })
16
+
17
+ // 当 target 为 body 的时候,则不用 getElementById 的逻辑,而是直接使用body
18
+ Object.defineProperties(customElements.get('turbo-stream').prototype, {
19
+ targetElementsById: {
20
+ get: function() {
21
+ let element
22
+ if (this.target === 'body') {
23
+ element = this.ownerDocument.body
24
+ } else if (this.target) {
25
+ element = this.ownerDocument.getElementById(this.target)
26
+ }
27
+
28
+ if (element !== null) {
29
+ return [ element ]
30
+ } else {
31
+ return []
32
+ }
33
+ }
34
+ }
35
+ })
@@ -0,0 +1,77 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+
3
+ // data-controller="check"
4
+ export default class extends Controller {
5
+ static targets = ['added', 'moved']
6
+
7
+ applyFor(event) {
8
+ const link = event.currentTarget
9
+ const url = new URL(link.href)
10
+ const added = this.addedIds()
11
+ const moved = this.movedIds()
12
+ if (added.length > 0) {
13
+ url.searchParams.set('add_ids', added)
14
+ }
15
+ if (moved.length > 0) {
16
+ url.searchParams.set('remove_ids', added)
17
+ }
18
+
19
+ link.href = url
20
+ }
21
+
22
+ addedIds() {
23
+ const ids = []
24
+ this.addedTargets.forEach(item => {
25
+ ids.push(item.value)
26
+ })
27
+ return ids.join(',')
28
+ }
29
+
30
+ movedIds() {
31
+ const ids = []
32
+ this.movedTargets.forEach(item => {
33
+ ids.push(item.value)
34
+ })
35
+ return ids.join(',')
36
+ }
37
+
38
+ // data-action="check#toggle"
39
+ toggle(event) {
40
+ this.doToggle(event.currentTarget)
41
+ }
42
+
43
+ // data-action="check#toggleAll"
44
+ // value: 'xx'
45
+ toggleAll(event) {
46
+ const element = event.currentTarget
47
+ const checkboxes = document.getElementsByName(element.value)
48
+
49
+ for (let checkbox of checkboxes) {
50
+ checkbox.checked = element.checked
51
+ this.doToggle(checkbox)
52
+ }
53
+ }
54
+
55
+ toggleAllName(event) {
56
+ const element = event.currentTarget
57
+ const checkboxes = document.querySelectorAll(`input[data-name='${element.value}']`)
58
+
59
+ for (let checkbox of checkboxes) {
60
+ checkbox.checked = element.checked
61
+ this.doToggle(checkbox)
62
+ }
63
+ }
64
+
65
+ doToggle(checkbox) {
66
+ const changed = checkbox.checked !== checkbox.defaultChecked
67
+
68
+ if (changed && checkbox.checked) {
69
+ checkbox.dataset.add_target('check.added')
70
+ } else if (changed && !checkbox.checked) {
71
+ checkbox.dataset.add_target('check.moved')
72
+ } else {
73
+ checkbox.dataset.remove_target('check.added')
74
+ checkbox.dataset.remove_target('check.moved')
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,18 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+ import Choices from 'choices.js'
3
+
4
+ export default class extends Controller {
5
+
6
+ reload(element) {
7
+ new Choices(element, {
8
+ noChoicesText: '无可选项',
9
+ itemSelectText: '点击选择',
10
+ removeItemButton: true
11
+ })
12
+ }
13
+
14
+ connect() {
15
+ this.reload(this.element)
16
+ }
17
+
18
+ }
@@ -0,0 +1,52 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+
3
+ export default class extends Controller {
4
+ static values = {
5
+ url: String,
6
+ params: Object
7
+ }
8
+
9
+ cancel(event) {
10
+ event.preventDefault()
11
+ Turbo.visit(location.href, { action: 'replace' })
12
+ }
13
+
14
+ // 用于兼容 rails ujs data-method 的逻辑
15
+ link(event) {
16
+ event.preventDefault()
17
+ const ele = event.currentTarget
18
+ const method = (ele.dataset.method && ele.dataset.method.toUpperCase()) || 'GET'
19
+
20
+ fetch(ele.href, {
21
+ method: method,
22
+ headers: {
23
+ Accept: 'text/vnd.turbo-stream.html'
24
+ }
25
+ }).then(response => {
26
+ return response.text()
27
+ }).then(body => {
28
+ Turbo.renderStreamMessage(body)
29
+ })
30
+ }
31
+
32
+ stream(event) {
33
+ const ele = event.currentTarget
34
+ const search_url = new URL(this.urlValue, location.origin)
35
+ search_url.searchParams.set('node_id', ele.value)
36
+ Object.keys(this.paramsValue).forEach(k => {
37
+ search_url.searchParams.set(k, this.paramsValue[k])
38
+ })
39
+
40
+ fetch(search_url, {
41
+ method: 'GET',
42
+ headers: {
43
+ Accept: 'text/vnd.turbo-stream.html'
44
+ }
45
+ }).then(response => {
46
+ return response.text()
47
+ }).then(body => {
48
+ Turbo.renderStreamMessage(body)
49
+ })
50
+ }
51
+
52
+ }
@@ -0,0 +1,27 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+
3
+ export default class extends Controller {
4
+ static values = {
5
+ time: Number
6
+ }
7
+
8
+ connect() {
9
+ this.countDown()
10
+ }
11
+
12
+ countDown() {
13
+ let countdown = this.timeValue || 60
14
+ this.element.innerText = '重新发送(' + countdown + ')'
15
+
16
+ let timer = setInterval(() => {
17
+ countdown--
18
+ if (countdown <= 0) {
19
+ this.element.removeAttribute('disabled')
20
+ this.element.innerText = '获取验证码'
21
+ clearInterval(timer)
22
+ } else {
23
+ this.element.innerText = '重新发送(' + countdown + ')'
24
+ }
25
+ }, 1000, countdown, this.element)
26
+ }
27
+ }
@@ -0,0 +1,26 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+
3
+ export default class extends Controller {
4
+ static values = {
5
+ id: String,
6
+ url: String
7
+ }
8
+
9
+ submit() {
10
+ let ele = document.getElementById(this.idValue)
11
+ let data = new FormData(ele)
12
+
13
+ fetch(this.urlValue, {
14
+ method: 'POST',
15
+ headers: {
16
+ Accept: 'text/vnd.turbo-stream.html',
17
+ 'X-CSRF-Token': this.csrfToken()
18
+ },
19
+ body: data
20
+ }).then(response => {
21
+ return response.text()
22
+ }).then(body => {
23
+ Turbo.renderStreamMessage(body)
24
+ })
25
+ }
26
+ }
@@ -0,0 +1,40 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+
3
+ export default class extends Controller {
4
+ static targets = ['card']
5
+ static values = {
6
+ url: String
7
+ }
8
+
9
+ show(event) {
10
+ let ele = event.currentTarget
11
+ if (this.hasCardTarget) {
12
+ this.cardTarget.classList.remove('is-hidden')
13
+ } else if (this.urlValue) {
14
+ Rails.ajax({
15
+ url: this.urlValue,
16
+ type: 'GET',
17
+ dataType: 'text/html',
18
+ success: function(html) {
19
+ ele.insertAdjacentHTML('beforebegin', html.body.innerHTML)
20
+ },
21
+ error: function(data) {
22
+ console.debug('error', data)
23
+ }
24
+ })
25
+ }
26
+ }
27
+
28
+ hide() {
29
+ if (this.hasCardTarget) {
30
+ this.cardTarget.classList.add('is-hidden')
31
+ }
32
+ }
33
+
34
+ disconnect() {
35
+ if (this.hasCardTarget) {
36
+ this.cardTarget.remove()
37
+ }
38
+ }
39
+
40
+ }
@@ -0,0 +1,58 @@
1
+ import { application } from '../rails_ui/stimulus'
2
+
3
+ import CheckboxController from './checkbox'
4
+ import CommonController from './common'
5
+ import CountDownController from './count_down'
6
+ import FormerController from './former'
7
+ import HoverController from './hover'
8
+ import InputController from './input'
9
+ import MenuController from './menu'
10
+ import NavbarController from './navbar'
11
+ import NoticeController from './notice'
12
+ import PictureController from './picture'
13
+ import ShowController from './show'
14
+ import ShowcaseController from './showcase' // 点击小图,显示大图
15
+ import SlideController from './slide'
16
+ import SlideYController from './slide_y'
17
+ import StickyController from './sticky'
18
+ import SwipeController from './swipe'
19
+ import TaxonController from './taxon'
20
+ import TimeController from './time' // 时间格式根据浏览器时区等进行转化
21
+ import TreeController from './tree'
22
+ import TreeRemoteController from './tree_remote'
23
+ import TyperController from './typer'
24
+ import VisitController from './visit'
25
+
26
+ import SortableController from './sortable' // dependent on sortable
27
+ import ChoiceController from './choice' // Dependent on Choices.js
28
+
29
+ // Dependent on Bulma CSS
30
+ import ModalController from './modal'
31
+ import ModalShowController from './modal_show'
32
+
33
+ application.register('check', CheckboxController)
34
+ application.register('choice', ChoiceController)
35
+ application.register('common', CommonController)
36
+ application.register('count-down', CountDownController)
37
+ application.register('former', FormerController)
38
+ application.register('hover', HoverController)
39
+ application.register('input', InputController)
40
+ application.register('menu', MenuController)
41
+ application.register('modal', ModalController)
42
+ application.register('modal-show', ModalShowController)
43
+ application.register('navbar', NavbarController)
44
+ application.register('notice', NoticeController)
45
+ application.register('picture', PictureController)
46
+ application.register('show', ShowController)
47
+ application.register('showcase', ShowcaseController)
48
+ application.register('slide', SlideController)
49
+ application.register('slide-y', SlideYController)
50
+ application.register('sortable', SortableController)
51
+ application.register('sticky', StickyController)
52
+ application.register('swipe', SwipeController)
53
+ application.register('taxon', TaxonController)
54
+ application.register('time', TimeController)
55
+ application.register('tree', TreeController)
56
+ application.register('tree-remote', TreeRemoteController)
57
+ application.register('typer', TyperController)
58
+ application.register('visit', VisitController)
@@ -0,0 +1,36 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+
3
+ // data-controller="input"
4
+ export default class extends Controller {
5
+ static targets = ['checkbox']
6
+
7
+ // <label data-action="click->input#check"></label>
8
+ // label out of check
9
+ check() {
10
+ if (this.hasCheckboxTarget) {
11
+ this.checkboxTarget.checked = !this.checkboxTarget.checked
12
+ this.submit(this.checkboxTarget.form)
13
+ }
14
+ }
15
+
16
+ form(event) {
17
+ const el = event.currentTarget
18
+
19
+ if (el.value.length > 0) {
20
+ this.submit(event.currentTarget.form)
21
+ }
22
+ }
23
+
24
+ filter(event) {
25
+ const ele = event.currentTarget
26
+ if (!ele.value) {
27
+ return
28
+ }
29
+ this.submit(ele.form)
30
+ }
31
+
32
+ remove() {
33
+ this.element.remove()
34
+ }
35
+
36
+ }