isomorfeus-preact 10.9.0 → 22.9.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +14 -3
- data/README.md +23 -39
- data/lib/browser/delegate_native.rb +94 -72
- data/lib/browser/document.rb +38 -0
- data/lib/browser/element.rb +160 -176
- data/lib/browser/event.rb +99 -94
- data/lib/browser/history.rb +40 -20
- data/lib/browser/location.rb +59 -0
- data/lib/browser/window.rb +58 -0
- data/lib/data_uri/open_uri.rb +18 -0
- data/lib/data_uri/uri.rb +61 -0
- data/lib/data_uri.rb +4 -0
- data/lib/isomorfeus/preact/config.rb +42 -54
- data/lib/isomorfeus/preact/imports.rb +5 -20
- data/lib/isomorfeus/preact/ssr.rb +34 -0
- data/lib/isomorfeus/preact/thread_local_component_cache.rb +9 -11
- data/lib/isomorfeus/preact/version.rb +5 -0
- data/lib/isomorfeus/preact/view_helper.rb +72 -0
- data/lib/isomorfeus/props/validator.rb +19 -11
- data/lib/isomorfeus/top_level.rb +55 -33
- data/lib/isomorfeus-preact.rb +78 -103
- data/lib/link.rb +52 -0
- data/lib/lucid_app.rb +117 -0
- data/lib/lucid_component.rb +154 -0
- data/lib/nano_css.rb +282 -465
- data/lib/preact/component.rb +222 -0
- data/lib/preact/component_resolution.rb +49 -83
- data/lib/preact/context.rb +68 -0
- data/lib/preact/elements.rb +2 -9
- data/lib/preact/module_component_resolution.rb +50 -0
- data/lib/preact/prop_declaration_mixin.rb +73 -0
- data/lib/preact.rb +1548 -257
- data/lib/redirect.rb +34 -0
- data/lib/route.rb +15 -0
- data/lib/router.rb +145 -0
- data/lib/switch.rb +70 -0
- data/opal/iso_uri.rb +29 -0
- data/opal/uri/common.rb +18 -0
- data/opal/uri/generic.rb +47 -0
- metadata +45 -309
- data/lib/isomorfeus/preact/memcached_component_cache.rb +0 -19
- data/lib/isomorfeus/preact/redis_component_cache.rb +0 -19
- data/lib/isomorfeus/preact/ssr/history.rb +0 -23
- data/lib/isomorfeus/preact/ssr/render_core.rb +0 -117
- data/lib/isomorfeus/preact/ssr/top_level.rb +0 -37
- data/lib/isomorfeus/preact_view_helper.rb +0 -129
- data/lib/isomorfeus_preact/lucid_app/api.rb +0 -38
- data/lib/isomorfeus_preact/lucid_app/base.rb +0 -7
- data/lib/isomorfeus_preact/lucid_app/mixin.rb +0 -14
- data/lib/isomorfeus_preact/lucid_app/native_component_constructor.rb +0 -101
- data/lib/isomorfeus_preact/lucid_component/api.rb +0 -123
- data/lib/isomorfeus_preact/lucid_component/app_store_proxy.rb +0 -32
- data/lib/isomorfeus_preact/lucid_component/base.rb +0 -7
- data/lib/isomorfeus_preact/lucid_component/class_store_proxy.rb +0 -37
- data/lib/isomorfeus_preact/lucid_component/initializer.rb +0 -9
- data/lib/isomorfeus_preact/lucid_component/mixin.rb +0 -13
- data/lib/isomorfeus_preact/lucid_component/native_component_constructor.rb +0 -87
- data/lib/isomorfeus_preact/lucid_component/styles_wrapper.rb +0 -40
- data/lib/isomorfeus_preact/lucid_func/base.rb +0 -7
- data/lib/isomorfeus_preact/lucid_func/initializer.rb +0 -8
- data/lib/isomorfeus_preact/lucid_func/mixin.rb +0 -10
- data/lib/isomorfeus_preact/lucid_func/native_component_constructor.rb +0 -56
- data/lib/isomorfeus_preact/preact/function_component/api.rb +0 -164
- data/lib/isomorfeus_preact/preact/function_component/base.rb +0 -7
- data/lib/isomorfeus_preact/preact/function_component/initializer.rb +0 -6
- data/lib/isomorfeus_preact/preact/function_component/mixin.rb +0 -8
- data/lib/isomorfeus_preact/preact/function_component/native_component_constructor.rb +0 -47
- data/lib/lucid_app/context.rb +0 -24
- data/lib/lucid_prop_declaration/mixin.rb +0 -126
- data/lib/preact/component/api.rb +0 -137
- data/lib/preact/component/base.rb +0 -7
- data/lib/preact/component/callbacks.rb +0 -111
- data/lib/preact/component/initializer.rb +0 -7
- data/lib/preact/component/mixin.rb +0 -11
- data/lib/preact/component/native_component_constructor.rb +0 -77
- data/lib/preact/context_wrapper.rb +0 -48
- data/lib/preact/native_constant_wrapper.rb +0 -29
- data/lib/preact/option_hooks.rb +0 -98
- data/lib/preact/params.rb +0 -16
- data/lib/preact/props.rb +0 -69
- data/lib/preact/ref.rb +0 -17
- data/lib/preact/state.rb +0 -87
- data/lib/preact/version.rb +0 -3
- data/node_modules/.package-lock.json +0 -38
- data/node_modules/preact/LICENSE +0 -21
- data/node_modules/preact/README.md +0 -188
- data/node_modules/preact/compat/LICENSE +0 -21
- data/node_modules/preact/compat/client.js +0 -19
- data/node_modules/preact/compat/client.mjs +0 -17
- data/node_modules/preact/compat/dist/compat.js +0 -2
- data/node_modules/preact/compat/dist/compat.js.map +0 -1
- data/node_modules/preact/compat/dist/compat.mjs +0 -2
- data/node_modules/preact/compat/dist/compat.module.js +0 -2
- data/node_modules/preact/compat/dist/compat.module.js.map +0 -1
- data/node_modules/preact/compat/dist/compat.umd.js +0 -2
- data/node_modules/preact/compat/dist/compat.umd.js.map +0 -1
- data/node_modules/preact/compat/jsx-dev-runtime.js +0 -3
- data/node_modules/preact/compat/jsx-dev-runtime.mjs +0 -3
- data/node_modules/preact/compat/jsx-runtime.js +0 -3
- data/node_modules/preact/compat/jsx-runtime.mjs +0 -3
- data/node_modules/preact/compat/package.json +0 -49
- data/node_modules/preact/compat/scheduler.js +0 -15
- data/node_modules/preact/compat/scheduler.mjs +0 -23
- data/node_modules/preact/compat/server.browser.js +0 -4
- data/node_modules/preact/compat/server.js +0 -15
- data/node_modules/preact/compat/server.mjs +0 -4
- data/node_modules/preact/compat/src/Children.js +0 -21
- data/node_modules/preact/compat/src/PureComponent.js +0 -15
- data/node_modules/preact/compat/src/forwardRef.js +0 -44
- data/node_modules/preact/compat/src/index.d.ts +0 -164
- data/node_modules/preact/compat/src/index.js +0 -223
- data/node_modules/preact/compat/src/internal.d.ts +0 -47
- data/node_modules/preact/compat/src/memo.js +0 -34
- data/node_modules/preact/compat/src/portals.js +0 -82
- data/node_modules/preact/compat/src/render.js +0 -238
- data/node_modules/preact/compat/src/suspense-list.d.ts +0 -14
- data/node_modules/preact/compat/src/suspense-list.js +0 -126
- data/node_modules/preact/compat/src/suspense.d.ts +0 -15
- data/node_modules/preact/compat/src/suspense.js +0 -270
- data/node_modules/preact/compat/src/util.js +0 -28
- data/node_modules/preact/compat/test-utils.js +0 -1
- data/node_modules/preact/debug/LICENSE +0 -21
- data/node_modules/preact/debug/dist/debug.js +0 -2
- data/node_modules/preact/debug/dist/debug.js.map +0 -1
- data/node_modules/preact/debug/dist/debug.mjs +0 -2
- data/node_modules/preact/debug/dist/debug.module.js +0 -2
- data/node_modules/preact/debug/dist/debug.module.js.map +0 -1
- data/node_modules/preact/debug/dist/debug.umd.js +0 -2
- data/node_modules/preact/debug/dist/debug.umd.js.map +0 -1
- data/node_modules/preact/debug/package.json +0 -26
- data/node_modules/preact/debug/src/check-props.js +0 -54
- data/node_modules/preact/debug/src/component-stack.js +0 -146
- data/node_modules/preact/debug/src/constants.js +0 -3
- data/node_modules/preact/debug/src/debug.js +0 -437
- data/node_modules/preact/debug/src/index.js +0 -6
- data/node_modules/preact/debug/src/internal.d.ts +0 -82
- data/node_modules/preact/debug/src/util.js +0 -11
- data/node_modules/preact/devtools/LICENSE +0 -21
- data/node_modules/preact/devtools/dist/devtools.js +0 -2
- data/node_modules/preact/devtools/dist/devtools.js.map +0 -1
- data/node_modules/preact/devtools/dist/devtools.mjs +0 -2
- data/node_modules/preact/devtools/dist/devtools.module.js +0 -2
- data/node_modules/preact/devtools/dist/devtools.module.js.map +0 -1
- data/node_modules/preact/devtools/dist/devtools.umd.js +0 -2
- data/node_modules/preact/devtools/dist/devtools.umd.js.map +0 -1
- data/node_modules/preact/devtools/package.json +0 -25
- data/node_modules/preact/devtools/src/devtools.js +0 -10
- data/node_modules/preact/devtools/src/index.d.ts +0 -8
- data/node_modules/preact/devtools/src/index.js +0 -15
- data/node_modules/preact/dist/preact.js +0 -2
- data/node_modules/preact/dist/preact.js.map +0 -1
- data/node_modules/preact/dist/preact.min.js +0 -2
- data/node_modules/preact/dist/preact.min.js.map +0 -1
- data/node_modules/preact/dist/preact.mjs +0 -2
- data/node_modules/preact/dist/preact.module.js +0 -2
- data/node_modules/preact/dist/preact.module.js.map +0 -1
- data/node_modules/preact/dist/preact.umd.js +0 -2
- data/node_modules/preact/dist/preact.umd.js.map +0 -1
- data/node_modules/preact/hooks/LICENSE +0 -21
- data/node_modules/preact/hooks/dist/hooks.js +0 -2
- data/node_modules/preact/hooks/dist/hooks.js.map +0 -1
- data/node_modules/preact/hooks/dist/hooks.mjs +0 -2
- data/node_modules/preact/hooks/dist/hooks.module.js +0 -2
- data/node_modules/preact/hooks/dist/hooks.module.js.map +0 -1
- data/node_modules/preact/hooks/dist/hooks.umd.js +0 -2
- data/node_modules/preact/hooks/dist/hooks.umd.js.map +0 -1
- data/node_modules/preact/hooks/package.json +0 -35
- data/node_modules/preact/hooks/src/index.d.ts +0 -139
- data/node_modules/preact/hooks/src/index.js +0 -417
- data/node_modules/preact/hooks/src/internal.d.ts +0 -78
- data/node_modules/preact/jsx-runtime/LICENSE +0 -21
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js +0 -2
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js.map +0 -1
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.mjs +0 -2
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js +0 -2
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js.map +0 -1
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js +0 -2
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js.map +0 -1
- data/node_modules/preact/jsx-runtime/package.json +0 -28
- data/node_modules/preact/jsx-runtime/src/index.d.ts +0 -50
- data/node_modules/preact/jsx-runtime/src/index.js +0 -77
- data/node_modules/preact/package.json +0 -304
- data/node_modules/preact/src/cjs.js +0 -3
- data/node_modules/preact/src/clone-element.js +0 -34
- data/node_modules/preact/src/component.js +0 -225
- data/node_modules/preact/src/constants.js +0 -3
- data/node_modules/preact/src/create-context.js +0 -68
- data/node_modules/preact/src/create-element.js +0 -98
- data/node_modules/preact/src/diff/catch-error.js +0 -40
- data/node_modules/preact/src/diff/children.js +0 -335
- data/node_modules/preact/src/diff/index.js +0 -533
- data/node_modules/preact/src/diff/props.js +0 -158
- data/node_modules/preact/src/index.d.ts +0 -317
- data/node_modules/preact/src/index.js +0 -13
- data/node_modules/preact/src/internal.d.ts +0 -155
- data/node_modules/preact/src/jsx.d.ts +0 -1014
- data/node_modules/preact/src/options.js +0 -16
- data/node_modules/preact/src/render.js +0 -75
- data/node_modules/preact/src/util.js +0 -27
- data/node_modules/preact/test-utils/dist/testUtils.js +0 -2
- data/node_modules/preact/test-utils/dist/testUtils.js.map +0 -1
- data/node_modules/preact/test-utils/dist/testUtils.mjs +0 -2
- data/node_modules/preact/test-utils/dist/testUtils.module.js +0 -2
- data/node_modules/preact/test-utils/dist/testUtils.module.js.map +0 -1
- data/node_modules/preact/test-utils/dist/testUtils.umd.js +0 -2
- data/node_modules/preact/test-utils/dist/testUtils.umd.js.map +0 -1
- data/node_modules/preact/test-utils/package.json +0 -28
- data/node_modules/preact/test-utils/src/index.d.ts +0 -3
- data/node_modules/preact/test-utils/src/index.js +0 -118
- data/node_modules/preact-render-to-string/LICENSE +0 -21
- data/node_modules/preact-render-to-string/README.md +0 -102
- data/node_modules/preact-render-to-string/dist/commonjs.js +0 -2
- data/node_modules/preact-render-to-string/dist/commonjs.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/index.d.ts +0 -16
- data/node_modules/preact-render-to-string/dist/index.js +0 -1
- data/node_modules/preact-render-to-string/dist/index.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/index.mjs +0 -2
- data/node_modules/preact-render-to-string/dist/index.module.js +0 -2
- data/node_modules/preact-render-to-string/dist/index.module.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/jsx-entry.js +0 -2
- data/node_modules/preact-render-to-string/dist/jsx-entry.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/jsx.d.ts +0 -13
- data/node_modules/preact-render-to-string/dist/jsx.js +0 -1
- data/node_modules/preact-render-to-string/dist/jsx.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/jsx.mjs +0 -2
- data/node_modules/preact-render-to-string/dist/jsx.modern.js +0 -2
- data/node_modules/preact-render-to-string/dist/jsx.modern.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/jsx.module.js +0 -2
- data/node_modules/preact-render-to-string/dist/jsx.module.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/preact-render-to-string-tests.d.ts +0 -1
- data/node_modules/preact-render-to-string/jsx.js +0 -1
- data/node_modules/preact-render-to-string/package.json +0 -142
- data/node_modules/preact-render-to-string/src/index.d.ts +0 -16
- data/node_modules/preact-render-to-string/src/index.js +0 -462
- data/node_modules/preact-render-to-string/src/jsx.d.ts +0 -13
- data/node_modules/preact-render-to-string/src/jsx.js +0 -76
- data/node_modules/preact-render-to-string/src/polyfills.js +0 -8
- data/node_modules/preact-render-to-string/src/preact-render-to-string-tests.d.ts +0 -1
- data/node_modules/preact-render-to-string/src/util.js +0 -78
- data/node_modules/preact-render-to-string/typings.json +0 -5
- data/node_modules/pretty-format/.npmignore +0 -3
- data/node_modules/pretty-format/LICENSE.md +0 -15
- data/node_modules/pretty-format/README.md +0 -94
- data/node_modules/pretty-format/index.js +0 -343
- data/node_modules/pretty-format/package.json +0 -26
- data/node_modules/pretty-format/plugins/ReactElement.js +0 -74
- data/node_modules/pretty-format/plugins/ReactTestComponent.js +0 -58
- data/node_modules/pretty-format/printString.js +0 -7
- data/node_modules/wouter-preact/cjs/index.js +0 -180
- data/node_modules/wouter-preact/cjs/matcher.js +0 -72
- data/node_modules/wouter-preact/cjs/package.json +0 -1
- data/node_modules/wouter-preact/cjs/react-deps.js +0 -75
- data/node_modules/wouter-preact/cjs/static-location.js +0 -21
- data/node_modules/wouter-preact/cjs/use-location.js +0 -94
- data/node_modules/wouter-preact/index.d.ts +0 -110
- data/node_modules/wouter-preact/index.js +0 -178
- data/node_modules/wouter-preact/matcher.d.ts +0 -30
- data/node_modules/wouter-preact/matcher.js +0 -66
- data/node_modules/wouter-preact/package.json +0 -33
- data/node_modules/wouter-preact/react-deps.js +0 -15
- data/node_modules/wouter-preact/static-location.d.ts +0 -16
- data/node_modules/wouter-preact/static-location.js +0 -17
- data/node_modules/wouter-preact/use-location.d.ts +0 -43
- data/node_modules/wouter-preact/use-location.js +0 -86
- data/package.json +0 -8
data/lib/browser/element.rb
CHANGED
@@ -1,176 +1,160 @@
|
|
1
|
-
module Browser
|
2
|
-
autoload :FileList, 'browser/file_list'
|
3
|
-
autoload :Iterable, 'browser/iterable'
|
4
|
-
|
5
|
-
# Wrap a native DOM element
|
6
|
-
class Element
|
7
|
-
include EventTarget
|
8
|
-
include DelegateNative
|
9
|
-
|
10
|
-
@tags = Hash.new(self)
|
11
|
-
|
12
|
-
def self.element *tags, &block
|
13
|
-
tags.each do |tag|
|
14
|
-
@tags
|
15
|
-
.fetch(tag) { @tags[tag] = const_set(tag.capitalize, Class.new(self)) }
|
16
|
-
.class_exec(&block)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.new(native)
|
21
|
-
element = @tags[`(#{native}.tagName || '')`.downcase].allocate
|
22
|
-
element.initialize native
|
23
|
-
element
|
24
|
-
end
|
25
|
-
|
26
|
-
# @param native [JS] The native DOM element to wrap
|
27
|
-
def initialize native
|
28
|
-
@native = native
|
29
|
-
end
|
30
|
-
|
31
|
-
# Replace all child elements with the given element
|
32
|
-
#
|
33
|
-
# @param element [Browser::Element] The Browser element with which to replace
|
34
|
-
# this element's contents
|
35
|
-
def inner_dom= element
|
36
|
-
clear
|
37
|
-
append element
|
38
|
-
end
|
39
|
-
|
40
|
-
# The contents of this element as an HTML string
|
41
|
-
#
|
42
|
-
# @return [String] the HTML representation of this element's contents
|
43
|
-
def inner_html
|
44
|
-
`#@native.innerHTML`
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
#
|
108
|
-
#
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
#
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
#
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
#
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
#
|
154
|
-
#
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
Element.new(result) if result
|
163
|
-
end
|
164
|
-
|
165
|
-
def query_selector_all selector
|
166
|
-
Iterable.new(super).map { |element| Element.new(element) }
|
167
|
-
end
|
168
|
-
|
169
|
-
# The native representation of this element.
|
170
|
-
#
|
171
|
-
# @return [JS] the native element wrapped by this object.
|
172
|
-
def to_n
|
173
|
-
@native
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
1
|
+
module Browser
|
2
|
+
autoload :FileList, 'browser/file_list'
|
3
|
+
autoload :Iterable, 'browser/iterable'
|
4
|
+
|
5
|
+
# Wrap a native DOM element
|
6
|
+
class Element
|
7
|
+
include EventTarget
|
8
|
+
include DelegateNative
|
9
|
+
|
10
|
+
@tags = Hash.new(self)
|
11
|
+
|
12
|
+
def self.element *tags, &block
|
13
|
+
tags.each do |tag|
|
14
|
+
@tags
|
15
|
+
.fetch(tag) { @tags[tag] = const_set(tag.capitalize, Class.new(self)) }
|
16
|
+
.class_exec(&block)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.new(native)
|
21
|
+
element = @tags[`(#{native}.tagName || '')`.downcase].allocate
|
22
|
+
element.initialize native
|
23
|
+
element
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param native [JS] The native DOM element to wrap
|
27
|
+
def initialize native
|
28
|
+
@native = native
|
29
|
+
end
|
30
|
+
|
31
|
+
# Replace all child elements with the given element
|
32
|
+
#
|
33
|
+
# @param element [Browser::Element] The Browser element with which to replace
|
34
|
+
# this element's contents
|
35
|
+
def inner_dom= element
|
36
|
+
clear
|
37
|
+
append element
|
38
|
+
end
|
39
|
+
|
40
|
+
# The contents of this element as an HTML string
|
41
|
+
#
|
42
|
+
# @return [String] the HTML representation of this element's contents
|
43
|
+
def inner_html
|
44
|
+
`#@native.innerHTML`
|
45
|
+
end
|
46
|
+
|
47
|
+
def outer_html
|
48
|
+
`#@native.outerHTML`
|
49
|
+
end
|
50
|
+
|
51
|
+
# Use the supplied HTML string to replace this element's contents
|
52
|
+
#
|
53
|
+
# @param html [String] the HTML with which to replace this elements contents
|
54
|
+
def inner_html= html
|
55
|
+
`#@native.innerHTML = html`
|
56
|
+
end
|
57
|
+
|
58
|
+
# This element's direct child elements
|
59
|
+
#
|
60
|
+
# @return [Array<Browser::Element>] list of this element's children
|
61
|
+
def children
|
62
|
+
elements = []
|
63
|
+
|
64
|
+
%x{
|
65
|
+
var children = #@native.children;
|
66
|
+
for(var i = 0; i < children.length; i++) {
|
67
|
+
elements[i] = #{Element.new(`children[i]`)};
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
elements
|
72
|
+
end
|
73
|
+
|
74
|
+
# Determine whether this element has any contents
|
75
|
+
#
|
76
|
+
# @return [Boolean] true if the element has no children, false otherwise
|
77
|
+
def empty?
|
78
|
+
`#@native.children.length === 0`
|
79
|
+
end
|
80
|
+
|
81
|
+
# Remove all contents from this element. After this call, `empty?` will
|
82
|
+
# return `true`.
|
83
|
+
#
|
84
|
+
# @return [Browser::Element] self
|
85
|
+
def clear
|
86
|
+
if %w(input textarea).include? type
|
87
|
+
`#@native.value = null`
|
88
|
+
else
|
89
|
+
children.each do |child|
|
90
|
+
remove_child child
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
self
|
95
|
+
end
|
96
|
+
|
97
|
+
# This element's type. For example: "div", "span", "p"
|
98
|
+
#
|
99
|
+
# @return [String] the HTML tag name for this element
|
100
|
+
def type
|
101
|
+
`#@native.nodeName`.downcase
|
102
|
+
end
|
103
|
+
|
104
|
+
# Methods for <input /> elements
|
105
|
+
|
106
|
+
# A checkbox's checked status
|
107
|
+
#
|
108
|
+
# @return [Boolean] true if the checkbox is checked, false otherwise
|
109
|
+
def checked?
|
110
|
+
`!!#@native.checked`
|
111
|
+
end
|
112
|
+
|
113
|
+
# Get the currently selected file for this input. This is only useful for
|
114
|
+
# file inputs without the `multiple` property set.
|
115
|
+
#
|
116
|
+
# @return [Browser::File] the file selected by the user
|
117
|
+
def file
|
118
|
+
files.first
|
119
|
+
end
|
120
|
+
|
121
|
+
# Get the currently selected files for this input. This is only useful for
|
122
|
+
# file inputs with the `multiple` property set.
|
123
|
+
#
|
124
|
+
# @return [Browser::FileList] the currently selected files for this input
|
125
|
+
def files
|
126
|
+
FileList.new(`#@native.files`)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Determine whether this is the same element
|
130
|
+
#
|
131
|
+
# @return [boolean] true if the element is the same, false otherwise
|
132
|
+
def ==(other)
|
133
|
+
`#@native === #{other.to_n}`
|
134
|
+
end
|
135
|
+
|
136
|
+
# Set the specified attribute to the specified value
|
137
|
+
def []= attribute, value
|
138
|
+
`#@native.setAttribute(#{attribute}, #{value})`
|
139
|
+
nil
|
140
|
+
end
|
141
|
+
|
142
|
+
# Return the specified attribute
|
143
|
+
#
|
144
|
+
# @return [String] the value for the specified attribute
|
145
|
+
def [] attribute
|
146
|
+
%x{
|
147
|
+
let val = #@native.getAttribute(#{attribute});
|
148
|
+
if (val == null) { val = nil; }
|
149
|
+
return val;
|
150
|
+
}
|
151
|
+
end
|
152
|
+
|
153
|
+
# The native representation of this element.
|
154
|
+
#
|
155
|
+
# @return [JS] the native element wrapped by this object.
|
156
|
+
def to_n
|
157
|
+
@native
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
data/lib/browser/event.rb
CHANGED
@@ -1,94 +1,99 @@
|
|
1
|
-
module Browser
|
2
|
-
# Wrapper for JS events
|
3
|
-
class Event
|
4
|
-
# @param [JS] the native event to wrap
|
5
|
-
def initialize
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
#
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
#
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
#
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
# @
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
#
|
76
|
-
def
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
|
1
|
+
module Browser
|
2
|
+
# Wrapper for JS events
|
3
|
+
class Event
|
4
|
+
# @param [JS] the native event to wrap
|
5
|
+
def initialize native_or_string
|
6
|
+
%x{
|
7
|
+
if (typeof native_or_string === "string") {
|
8
|
+
native_or_string = new Event(native_or_string);
|
9
|
+
}
|
10
|
+
}
|
11
|
+
@native = native_or_string
|
12
|
+
end
|
13
|
+
|
14
|
+
# Prevent the runtime from executing this event's default behavior. For
|
15
|
+
# example, prevent navigation after clicking a link.
|
16
|
+
#
|
17
|
+
# @return [Browser::Event] self
|
18
|
+
def prevent
|
19
|
+
`#@native.preventDefault()`
|
20
|
+
self
|
21
|
+
end
|
22
|
+
alias_method :prevent_default, :prevent
|
23
|
+
|
24
|
+
# Prevent the runtime from bubbling this event up the hierarchy. This is
|
25
|
+
# typically used to keep an event local to the element on which it was
|
26
|
+
# triggered, such as keeping a click event on a button from unintentionally
|
27
|
+
# triggering a handler on a parent element.
|
28
|
+
#
|
29
|
+
# @return self
|
30
|
+
def stop_propagation
|
31
|
+
`#@native.stopPropagation()`
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [Boolean] true if `prevent` has been called on this event, false
|
36
|
+
# otherwise
|
37
|
+
def prevented?
|
38
|
+
`#@native.defaultPrevented`
|
39
|
+
end
|
40
|
+
alias_method :default_prevented?, :prevented?
|
41
|
+
|
42
|
+
# @return [Boolean] true if the Meta/Command/Windows key was pressed when
|
43
|
+
# this event fired, false otherwise
|
44
|
+
def meta?
|
45
|
+
`#@native.metaKey`
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [Boolean] true if the Shift key was pressed when this event fired,
|
49
|
+
# false otherwise
|
50
|
+
def shift?
|
51
|
+
`#@native.shiftKey`
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Boolean] true if the Ctrl key was pressed when this event fired,
|
55
|
+
# false otherwise
|
56
|
+
def ctrl?
|
57
|
+
`#@native.ctrlKey`
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [Boolean] true if the Alt key was pressed when this event fired,
|
61
|
+
# false otherwise
|
62
|
+
def alt?
|
63
|
+
`#@native.altKey`
|
64
|
+
end
|
65
|
+
|
66
|
+
# The target for this event
|
67
|
+
#
|
68
|
+
# @return [Browser::Element] the element on which this event was triggered
|
69
|
+
# @todo Handle non-DOM events here
|
70
|
+
def target
|
71
|
+
Element.new(`#@native.target`)
|
72
|
+
end
|
73
|
+
|
74
|
+
# @return [Numeric] the key code associated with this event. Only useful for
|
75
|
+
# keyboard-based events.
|
76
|
+
def code
|
77
|
+
`#@native.keyCode`
|
78
|
+
end
|
79
|
+
|
80
|
+
# Return properties on the event not covered by Ruby methods.
|
81
|
+
def method_missing name, *args
|
82
|
+
property = name.gsub(/_[a-z]/) { |match| match[-1, 1].upcase }
|
83
|
+
value = `#@native[property]`
|
84
|
+
|
85
|
+
if `!!value && #{Proc === value}`
|
86
|
+
value.call(*args)
|
87
|
+
elsif `value == null`
|
88
|
+
nil
|
89
|
+
else
|
90
|
+
value
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# @return [JS] the native event wrapped by this object.
|
95
|
+
def to_n
|
96
|
+
@native
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/lib/browser/history.rb
CHANGED
@@ -1,32 +1,52 @@
|
|
1
1
|
module Browser
|
2
2
|
class History
|
3
|
-
|
3
|
+
if RUBY_ENGINE == 'opal'
|
4
|
+
include Native::Wrapper
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
alias_native :back
|
7
|
+
alias_native :forward
|
8
|
+
alias_native :go
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
native_reader :length
|
11
|
+
alias :size :length
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def push_state(state, title = '', url = `null`)
|
14
|
+
`#@native.pushState(#{state.to_n}, #{title}, #{url})`
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def replace_state(state, title = '', url = `null`)
|
18
|
+
`#@native.replaceState(#{state.to_n}, #{title}, #{url})`
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def scroll_restoration
|
22
|
+
`#@native.scrollRestoration`
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def scroll_restoration=(s)
|
26
|
+
`#@native.scrollRestoration = #{s}`
|
27
|
+
end
|
28
|
+
|
29
|
+
def state
|
30
|
+
::Hash.new(`#@native.state`)
|
31
|
+
end
|
32
|
+
else
|
33
|
+
def back; end
|
34
|
+
def forward; end
|
35
|
+
def go(_); end
|
36
|
+
|
37
|
+
def length
|
38
|
+
0
|
39
|
+
end
|
40
|
+
alias :size :length
|
41
|
+
|
42
|
+
def push_state(state, title = '', url = nil); end
|
43
|
+
def replace_state(state, title = '', url = nil); end
|
44
|
+
def scroll_restoration; end
|
45
|
+
def scroll_restoration=(s); end
|
27
46
|
|
28
|
-
|
29
|
-
|
47
|
+
def state
|
48
|
+
{}
|
49
|
+
end
|
30
50
|
end
|
31
51
|
end
|
32
52
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Browser
|
2
|
+
class Location
|
3
|
+
if RUBY_ENGINE == 'opal'
|
4
|
+
include Native::Wrapper
|
5
|
+
|
6
|
+
alias_native :hash
|
7
|
+
alias_native :host
|
8
|
+
alias_native :hostname
|
9
|
+
alias_native :href
|
10
|
+
alias_native :origin
|
11
|
+
alias_native :pathname
|
12
|
+
alias_native :port
|
13
|
+
alias_native :protocol
|
14
|
+
alias_native :search
|
15
|
+
else
|
16
|
+
def initialize(location_string)
|
17
|
+
@location = URI(location_string)
|
18
|
+
rescue
|
19
|
+
@location = URI('http://localhost/')
|
20
|
+
end
|
21
|
+
|
22
|
+
def hash
|
23
|
+
@location.hash
|
24
|
+
end
|
25
|
+
|
26
|
+
def host
|
27
|
+
@location.host
|
28
|
+
end
|
29
|
+
|
30
|
+
def hostname
|
31
|
+
@location.hostname
|
32
|
+
end
|
33
|
+
|
34
|
+
def href
|
35
|
+
@location.to_s
|
36
|
+
end
|
37
|
+
|
38
|
+
def origin
|
39
|
+
@location.origin
|
40
|
+
end
|
41
|
+
|
42
|
+
def pathname
|
43
|
+
@location.path
|
44
|
+
end
|
45
|
+
|
46
|
+
def port
|
47
|
+
@location.port
|
48
|
+
end
|
49
|
+
|
50
|
+
def protocol
|
51
|
+
@location.scheme
|
52
|
+
end
|
53
|
+
|
54
|
+
def search
|
55
|
+
@location.query
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|