xote 6.4.0 → 7.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.
Files changed (46) hide show
  1. package/README.md +146 -36
  2. package/dist/RuntimeAttr.res-Cr5Qmz0i.js +1 -0
  3. package/dist/RuntimeAttr.res-DAZkL5CF.mjs +539 -0
  4. package/dist/RuntimeHydrationMarkers.res-C5-ieaOS.js +1 -0
  5. package/dist/RuntimeHydrationMarkers.res-DHikAvHr.mjs +6 -0
  6. package/dist/RuntimeJsxProp.res-A6N-qWoK.js +1 -0
  7. package/dist/RuntimeJsxProp.res-D3W5GXqT.mjs +64 -0
  8. package/dist/Stdlib_Array-1YCQzU_Y.mjs +22 -0
  9. package/dist/Stdlib_Array-BeBVUIuY.js +1 -0
  10. package/dist/View.res-C36--SJD.js +1 -0
  11. package/dist/View.res-SuqJrQPC.mjs +777 -0
  12. package/dist/client.cjs +1 -0
  13. package/dist/client.mjs +131 -0
  14. package/dist/hydration.cjs +1 -0
  15. package/dist/hydration.mjs +385 -0
  16. package/dist/mdx.cjs +1 -0
  17. package/dist/mdx.mjs +50 -0
  18. package/dist/router.cjs +1 -0
  19. package/dist/router.mjs +276 -0
  20. package/dist/ssr.cjs +17 -0
  21. package/dist/ssr.mjs +321 -0
  22. package/dist/xote.cjs +1 -17
  23. package/dist/xote.mjs +1456 -2467
  24. package/dist/xote.umd.js +1 -17
  25. package/package.json +42 -10
  26. package/rescript.json +2 -2
  27. package/src/Mdx.res +77 -0
  28. package/src/Mdx.res.mjs +93 -0
  29. package/src/Router.res +62 -8
  30. package/src/Router.res.mjs +60 -6
  31. package/src/RuntimeDom.res +7 -0
  32. package/src/RuntimeDom.res.mjs +8 -0
  33. package/src/RuntimeJsxProp.res +5 -8
  34. package/src/RuntimeJsxProp.res.mjs +9 -10
  35. package/src/RuntimeValue.res +35 -0
  36. package/src/RuntimeValue.res.mjs +67 -0
  37. package/src/SSRState.res +1 -4
  38. package/src/SSRState.res.mjs +4 -10
  39. package/src/View.res +224 -34
  40. package/src/View.res.mjs +306 -32
  41. package/src/jsx-dev-runtime.mjs +7 -0
  42. package/src/jsx-runtime.mjs +276 -0
  43. package/src/Node.res +0 -2
  44. package/src/Node.res.mjs +0 -82
  45. package/src/ReactiveProp.res +0 -2
  46. package/src/ReactiveProp.res.mjs +0 -19
@@ -6,6 +6,7 @@ import * as Route$Xote from "./Route.res.mjs";
6
6
  import * as Signal$Xote from "./Signal.res.mjs";
7
7
  import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
8
8
  import * as Computed$Xote from "./Computed.res.mjs";
9
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
9
10
  import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
10
11
  import * as RuntimeJsxProp$Xote from "./RuntimeJsxProp.res.mjs";
11
12
 
@@ -90,6 +91,26 @@ function addBasePath(pathname) {
90
91
  }
91
92
  }
92
93
 
94
+ function parseTarget(to) {
95
+ let hashParts = to.split("#");
96
+ let beforeHash = Stdlib_Option.getOr(hashParts[0], "");
97
+ let value = hashParts[1];
98
+ let hash = value !== undefined ? "#" + value : "";
99
+ let searchParts = beforeHash.split("?");
100
+ let pathname = Stdlib_Option.getOr(searchParts[0], "/");
101
+ let value$1 = searchParts[1];
102
+ let search = value$1 !== undefined ? "?" + value$1 : "";
103
+ return {
104
+ pathname: pathname,
105
+ search: search,
106
+ hash: hash
107
+ };
108
+ }
109
+
110
+ function targetToHref(target) {
111
+ return addBasePath(target.pathname) + target.search + target.hash;
112
+ }
113
+
93
114
  function getScrollPosition() {
94
115
  let x = (window.scrollX || window.pageXOffset || 0);
95
116
  let y = (window.scrollY || window.pageYOffset || 0);
@@ -103,6 +124,32 @@ function scrollTo(x, y) {
103
124
  ((window.scrollTo(x, y)));
104
125
  }
105
126
 
127
+ function queueMicrotask(callback) {
128
+ ((globalThis.queueMicrotask(callback)));
129
+ }
130
+
131
+ function scrollHashIntoView(hash) {
132
+ (((() => {
133
+ if (!hash) {
134
+ return;
135
+ }
136
+
137
+ const id = decodeURIComponent(hash.startsWith("#") ? hash.slice(1) : hash);
138
+ const target = document.getElementById(id);
139
+ if (target && typeof target.scrollIntoView === "function") {
140
+ target.scrollIntoView();
141
+ }
142
+ })()));
143
+ }
144
+
145
+ function scrollAfterNavigation(hash) {
146
+ if (hash === "") {
147
+ return scrollTo(0.0, 0.0);
148
+ } else {
149
+ return queueMicrotask(() => scrollHashIntoView(hash));
150
+ }
151
+ }
152
+
106
153
  function makeHistoryState(scrollX, scrollY) {
107
154
  return (({ scrollX: scrollX, scrollY: scrollY }));
108
155
  }
@@ -193,7 +240,7 @@ function push(pathname, searchOpt, hashOpt, param) {
193
240
  let url = browserPathname + search + hash;
194
241
  window.history.pushState(emptyHistoryState(), "", url);
195
242
  Signal$Xote.set(getGlobalState().location, newLocation);
196
- scrollTo(0.0, 0.0);
243
+ scrollAfterNavigation(hash);
197
244
  }
198
245
 
199
246
  function replace(pathname, searchOpt, hashOpt, param) {
@@ -209,7 +256,7 @@ function replace(pathname, searchOpt, hashOpt, param) {
209
256
  let url = browserPathname + search + hash;
210
257
  window.history.replaceState(emptyHistoryState(), "", url);
211
258
  Signal$Xote.set(getGlobalState().location, newLocation);
212
- scrollTo(0.0, 0.0);
259
+ scrollAfterNavigation(hash);
213
260
  }
214
261
 
215
262
  function route(pattern, render) {
@@ -249,11 +296,12 @@ function link(to, attrsOpt, childrenOpt, param) {
249
296
  let attrs = attrsOpt !== undefined ? attrsOpt : [];
250
297
  let children = childrenOpt !== undefined ? childrenOpt : [];
251
298
  warnIfNotInitialized("Router.link()");
299
+ let target = parseTarget(to);
252
300
  let handleClick = _evt => {
253
301
  ((_evt.preventDefault()));
254
- push(to, undefined, undefined, undefined);
302
+ push(target.pathname, target.search, target.hash, undefined);
255
303
  };
256
- return Html$Xote.a(attrs.concat([View$Xote.attr("href", addBasePath(to))]), [[
304
+ return Html$Xote.a(attrs.concat([View$Xote.attr("href", targetToHref(target))]), [[
257
305
  "click",
258
306
  handleClick
259
307
  ]], children, undefined);
@@ -299,15 +347,16 @@ function getChildren(props) {
299
347
 
300
348
  function make(props) {
301
349
  warnIfNotInitialized("Router.Link");
350
+ let target = parseTarget(props.to);
302
351
  let handleClick = evt => {
303
352
  ((evt.preventDefault()));
304
- push(props.to, undefined, undefined, undefined);
353
+ push(target.pathname, target.search, target.hash, undefined);
305
354
  let handler = props.onClick;
306
355
  if (handler !== undefined) {
307
356
  return handler(evt);
308
357
  }
309
358
  };
310
- return Html$Xote.a(propsToAttrs(props).concat([View$Xote.attr("href", addBasePath(props.to))]), [[
359
+ return Html$Xote.a(propsToAttrs(props).concat([View$Xote.attr("href", targetToHref(target))]), [[
311
360
  "click",
312
361
  handleClick
313
362
  ]], getChildren(props), undefined);
@@ -349,8 +398,13 @@ export {
349
398
  normalizeBasePath,
350
399
  stripBasePath,
351
400
  addBasePath,
401
+ parseTarget,
402
+ targetToHref,
352
403
  getScrollPosition,
353
404
  scrollTo,
405
+ queueMicrotask,
406
+ scrollHashIntoView,
407
+ scrollAfterNavigation,
354
408
  makeHistoryState,
355
409
  emptyHistoryState,
356
410
  getScrollFromState,
@@ -1,3 +1,5 @@
1
+ module Core = RescriptCore
2
+
1
3
  let svgNamespace = "http://www.w3.org/2000/svg"
2
4
 
3
5
  let svgTags = [
@@ -61,6 +63,11 @@ external getElementById: string => Nullable.t<Dom.element> = "getElementById"
61
63
  @get external getNextSibling: Dom.element => Nullable.t<Dom.element> = "nextSibling"
62
64
  @get external getFirstChild: Dom.element => Nullable.t<Dom.element> = "firstChild"
63
65
  @get external getParentNode: Dom.element => Nullable.t<Dom.element> = "parentNode"
66
+ @get external childNodes: Dom.element => Array.arrayLike<Dom.element> = "childNodes"
67
+
68
+ let childNodesToArray = (el: Dom.element): array<Dom.element> => {
69
+ el->childNodes->Core.Array.fromArrayLike
70
+ }
64
71
 
65
72
  @send
66
73
  external addEventListener: (Dom.element, string, Dom.event => unit) => unit = "addEventListener"
@@ -55,6 +55,10 @@ function isSvgTag(tag) {
55
55
  return Stdlib_Option.isSome(d[tag]);
56
56
  }
57
57
 
58
+ function childNodesToArray(el) {
59
+ return Array.from(el.childNodes);
60
+ }
61
+
58
62
  function createElementForTag(tag) {
59
63
  if (Stdlib_Option.isSome(d[tag])) {
60
64
  return document.createElementNS(svgNamespace, tag);
@@ -88,13 +92,17 @@ function setAttrOrProp(el, key, value) {
88
92
  }
89
93
  }
90
94
 
95
+ let Core;
96
+
91
97
  let svgTagSet = d;
92
98
 
93
99
  export {
100
+ Core,
94
101
  svgNamespace,
95
102
  svgTags,
96
103
  svgTagSet,
97
104
  isSvgTag,
105
+ childNodesToArray,
98
106
  createElementForTag,
99
107
  setAttrOrProp,
100
108
  }
@@ -1,7 +1,4 @@
1
- let isReactiveProp = (value: 'a): bool => {
2
- ignore(value)
3
- %raw(`value && typeof value === 'object' && ('TAG' in value) && (value.TAG === 'Static' || value.TAG === 'Reactive')`)
4
- }
1
+ let isReactiveProp = RuntimeValue.isReactiveProp
5
2
 
6
3
  let toStringAttr = (key: string, value: 'a): (string, View.attrValue) => {
7
4
  if isReactiveProp(value) {
@@ -10,10 +7,10 @@ let toStringAttr = (key: string, value: 'a): (string, View.attrValue) => {
10
7
  | Static(value) => View.attr(key, value)
11
8
  | Reactive(signal) => View.signalAttr(key, signal)
12
9
  }
13
- } else if typeof(value) == #function {
10
+ } else if value->RuntimeValue.isFunction {
14
11
  let compute: unit => string = Obj.magic(value)
15
12
  View.computedAttr(key, compute)
16
- } else if typeof(value) == #object {
13
+ } else if value->RuntimeValue.isObject {
17
14
  let signal: Signal.t<string> = Obj.magic(value)
18
15
  View.signalAttr(key, signal)
19
16
  } else {
@@ -32,10 +29,10 @@ let toBoolAttr = (key: string, value: 'a): (string, View.attrValue) => {
32
29
  View.signalAttr(key, stringSignal)
33
30
  }
34
31
  }
35
- } else if typeof(value) == #function {
32
+ } else if value->RuntimeValue.isFunction {
36
33
  let compute: unit => bool = Obj.magic(value)
37
34
  View.computedAttr(key, () => RuntimeAttr.boolToString(compute()))
38
- } else if typeof(value) == #object {
35
+ } else if value->RuntimeValue.isObject {
39
36
  let signal: Signal.t<bool> = Obj.magic(value)
40
37
  let stringSignal = Computed.make(() => RuntimeAttr.boolToString(Signal.get(signal)))
41
38
  View.signalAttr(key, stringSignal)
@@ -4,21 +4,18 @@ import * as View$Xote from "./View.res.mjs";
4
4
  import * as Signal$Xote from "./Signal.res.mjs";
5
5
  import * as Computed$Xote from "./Computed.res.mjs";
6
6
  import * as RuntimeAttr$Xote from "./RuntimeAttr.res.mjs";
7
-
8
- function isReactiveProp(value) {
9
- return (value && typeof value === 'object' && ('TAG' in value) && (value.TAG === 'Static' || value.TAG === 'Reactive'));
10
- }
7
+ import * as RuntimeValue$Xote from "./RuntimeValue.res.mjs";
11
8
 
12
9
  function toStringAttr(key, value) {
13
- if (isReactiveProp(value)) {
10
+ if (RuntimeValue$Xote.isReactiveProp(value)) {
14
11
  if (value.TAG === "Reactive") {
15
12
  return View$Xote.signalAttr(key, value._0);
16
13
  } else {
17
14
  return View$Xote.attr(key, value._0);
18
15
  }
19
- } else if (typeof value === "function") {
16
+ } else if (RuntimeValue$Xote.isFunction(value)) {
20
17
  return View$Xote.computedAttr(key, value);
21
- } else if (typeof value === "object") {
18
+ } else if (RuntimeValue$Xote.isObject(value)) {
22
19
  return View$Xote.signalAttr(key, value);
23
20
  } else {
24
21
  return View$Xote.attr(key, value);
@@ -26,7 +23,7 @@ function toStringAttr(key, value) {
26
23
  }
27
24
 
28
25
  function toBoolAttr(key, value) {
29
- if (isReactiveProp(value)) {
26
+ if (RuntimeValue$Xote.isReactiveProp(value)) {
30
27
  if (value.TAG !== "Reactive") {
31
28
  return View$Xote.attr(key, RuntimeAttr$Xote.boolToString(value._0));
32
29
  }
@@ -34,16 +31,18 @@ function toBoolAttr(key, value) {
34
31
  let stringSignal = Computed$Xote.make(() => RuntimeAttr$Xote.boolToString(Signal$Xote.get(signal)), undefined, undefined);
35
32
  return View$Xote.signalAttr(key, stringSignal);
36
33
  }
37
- if (typeof value === "function") {
34
+ if (RuntimeValue$Xote.isFunction(value)) {
38
35
  return View$Xote.computedAttr(key, () => RuntimeAttr$Xote.boolToString(value()));
39
36
  }
40
- if (typeof value !== "object") {
37
+ if (!RuntimeValue$Xote.isObject(value)) {
41
38
  return View$Xote.attr(key, RuntimeAttr$Xote.boolToString(value));
42
39
  }
43
40
  let stringSignal$1 = Computed$Xote.make(() => RuntimeAttr$Xote.boolToString(Signal$Xote.get(value)), undefined, undefined);
44
41
  return View$Xote.signalAttr(key, stringSignal$1);
45
42
  }
46
43
 
44
+ let isReactiveProp = RuntimeValue$Xote.isReactiveProp;
45
+
47
46
  export {
48
47
  isReactiveProp,
49
48
  toStringAttr,
@@ -0,0 +1,35 @@
1
+ module Core = RescriptCore
2
+
3
+ let objectHasTag = (obj: {..}, tag: string): bool =>
4
+ switch obj->Core.Object.get("TAG") {
5
+ | Some(value) => value == tag
6
+ | None => false
7
+ }
8
+
9
+ let isReactiveProp = (value: 'value): bool => {
10
+ switch value->Core.Type.Classify.classify {
11
+ | Object(obj) => {
12
+ let obj: {..} = Obj.magic(obj)
13
+ obj->Core.Object.hasOwnProperty("TAG") &&
14
+ (obj->objectHasTag("Static") || obj->objectHasTag("Reactive"))
15
+ }
16
+ | _ => false
17
+ }
18
+ }
19
+
20
+ let isFunction = (value: 'value): bool =>
21
+ switch value->Core.Type.Classify.classify {
22
+ | Function(_) => true
23
+ | _ => false
24
+ }
25
+
26
+ let isObject = (value: 'value): bool =>
27
+ switch value->Core.Type.Classify.classify {
28
+ | Object(_) => true
29
+ | _ => false
30
+ }
31
+
32
+ let getField = (props: 'props, key: string): option<'value> => {
33
+ let props: {..} = Obj.magic(props)
34
+ props->Core.Object.get(key)
35
+ }
@@ -0,0 +1,67 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Core__Type from "@rescript/core/src/Core__Type.res.mjs";
4
+ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
5
+
6
+ function objectHasTag(obj, tag) {
7
+ let value = obj["TAG"];
8
+ if (value !== undefined) {
9
+ return Primitive_option.valFromOption(value) === tag;
10
+ } else {
11
+ return false;
12
+ }
13
+ }
14
+
15
+ function isReactiveProp(value) {
16
+ let obj = Core__Type.Classify.classify(value);
17
+ if (typeof obj !== "object") {
18
+ return false;
19
+ }
20
+ if (obj.TAG !== "Object") {
21
+ return false;
22
+ }
23
+ let obj$1 = obj._0;
24
+ if (Object.prototype.hasOwnProperty.call(obj$1, "TAG")) {
25
+ if (objectHasTag(obj$1, "Static")) {
26
+ return true;
27
+ } else {
28
+ return objectHasTag(obj$1, "Reactive");
29
+ }
30
+ } else {
31
+ return false;
32
+ }
33
+ }
34
+
35
+ function isFunction(value) {
36
+ let match = Core__Type.Classify.classify(value);
37
+ if (typeof match !== "object") {
38
+ return false;
39
+ } else {
40
+ return match.TAG === "Function";
41
+ }
42
+ }
43
+
44
+ function isObject(value) {
45
+ let match = Core__Type.Classify.classify(value);
46
+ if (typeof match !== "object") {
47
+ return false;
48
+ } else {
49
+ return match.TAG === "Object";
50
+ }
51
+ }
52
+
53
+ function getField(props, key) {
54
+ return props[key];
55
+ }
56
+
57
+ let Core;
58
+
59
+ export {
60
+ Core,
61
+ objectHasTag,
62
+ isReactiveProp,
63
+ isFunction,
64
+ isObject,
65
+ getField,
66
+ }
67
+ /* No side effect */
package/src/SSRState.res CHANGED
@@ -239,11 +239,8 @@ let sync = (id: string, signal: Signal.t<'a>, codec: Codec.t<'a>): unit => {
239
239
  }
240
240
 
241
241
  /* Create and sync a signal in one call */
242
- let make = (id: string, initial: 'a, codec: Codec.t<'a>): Signal.t<'a> => {
242
+ let signal = (id: string, initial: 'a, codec: Codec.t<'a>): Signal.t<'a> => {
243
243
  let signal = Signal.make(initial)
244
244
  sync(id, signal, codec)
245
245
  signal
246
246
  }
247
-
248
- let signal = make
249
- let syncSignal = sync
@@ -265,16 +265,12 @@ function sync(id, signal, codec) {
265
265
  SSRContext$Xote.match(() => register(id, signal, codec), () => restore(id, signal, codec));
266
266
  }
267
267
 
268
- function make$1(id, initial, codec) {
269
- let signal = Signal$Xote.make(initial, undefined, undefined);
270
- sync(id, signal, codec);
271
- return signal;
268
+ function signal(id, initial, codec) {
269
+ let signal$1 = Signal$Xote.make(initial, undefined, undefined);
270
+ sync(id, signal$1, codec);
271
+ return signal$1;
272
272
  }
273
273
 
274
- let signal = make$1;
275
-
276
- let syncSignal = sync;
277
-
278
274
  export {
279
275
  Codec,
280
276
  registry,
@@ -285,8 +281,6 @@ export {
285
281
  getClientState,
286
282
  restore,
287
283
  sync,
288
- make$1 as make,
289
284
  signal,
290
- syncSignal,
291
285
  }
292
286
  /* SSRContext-Xote Not a pure module */