@ctx-core/window 14.2.28 → 15.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @ctx-core/window
2
2
 
3
+ ## 15.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - window*location\_\_: Be<ReadableAtom*<Location>>
8
+ - pathname\__:Be<ReadableAtom_<string>>
9
+ - window_location**: - window_location**reset
10
+ - hostname\__:Be<ReadableAtom_<string|undefined>>
11
+ - - window_location\_\_T
12
+
13
+ ### Minor Changes
14
+
15
+ - - window_location\_\_reset
16
+ - - window*location*
17
+ - - hostname\_
18
+ - - pathname\_
19
+
20
+ ### Patch Changes
21
+
22
+ - fix: run on server
23
+
3
24
  ## 14.2.28
4
25
 
5
26
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctx-core/window",
3
- "version": "14.2.28",
3
+ "version": "15.0.0",
4
4
  "description": "ctx-core window",
5
5
  "keywords": [
6
6
  "ctx-core",
@@ -32,7 +32,7 @@
32
32
  "devDependencies": {
33
33
  "c8": "^7.13.0",
34
34
  "check-dts": "^0.7.0",
35
- "tsx": "^3.12.3",
35
+ "tsx": "^3.12.4",
36
36
  "typescript": "next",
37
37
  "uvu": "^0.5.6"
38
38
  },
@@ -1,4 +1,9 @@
1
- import type { WritableAtom_ } from '@ctx-core/nanostores'
2
- import type { Be } from '@ctx-core/object'
3
- export declare const hostname__:Be<WritableAtom_<string|undefined>>
4
- export { hostname__ as hostname$_ }
1
+ import type { ReadableAtom_ } from '@ctx-core/nanostores'
2
+ import type { Be, Ctx } from '@ctx-core/object'
3
+ export declare const hostname__:Be<ReadableAtom_<string>>
4
+ export {
5
+ hostname__ as hostname$_,
6
+ hostname__ as window_location_hostname__,
7
+ hostname__ as window_location_hostname$_
8
+ }
9
+ export declare function hostname_(ctx:Ctx):string
@@ -1,6 +1,23 @@
1
- import { atom_ } from '@ctx-core/nanostores'
1
+ import { nullish__check_ } from '@ctx-core/function'
2
+ import { computed_ } from '@ctx-core/nanostores'
2
3
  import { be_ } from '@ctx-core/object'
4
+ import { window_location__ } from '../window_location__/index.js'
5
+ /** @typedef {import('@ctx-core/object').Ctx}Ctx */
3
6
  /** @type {typeof import('./index.d.ts').hostname__} */
4
- export const hostname__ = be_('hostname__', ()=>
5
- atom_(undefined))
6
- export { hostname__ as hostname$_ }
7
+ export const hostname__ = be_('hostname__', ctx =>
8
+ computed_(window_location__(ctx), window_location=>
9
+ nullish__check_([window_location], ()=>
10
+ window_location.hostname)))
11
+ export {
12
+ hostname__ as hostname$_,
13
+ hostname__ as window_location_hostname__,
14
+ hostname__ as window_location_hostname$_
15
+ }
16
+ /**
17
+ * @param {Ctx}ctx
18
+ * @returns {string}
19
+ * @private
20
+ */
21
+ export function hostname_(ctx) {
22
+ return hostname__(ctx).$
23
+ }
package/src/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
1
  export * from './hostname__'
2
2
  export * from './pathname__'
3
3
  export * from './window_location__'
4
- export * from './window_location_hostname__'
5
- export * from './window_location_pathname__'
package/src/index.js CHANGED
@@ -1,5 +1,3 @@
1
1
  export * from './hostname__/index.js'
2
2
  export * from './pathname__/index.js'
3
3
  export * from './window_location__/index.js'
4
- export * from './window_location_hostname__/index.js'
5
- export * from './window_location_pathname__/index.js'
@@ -1,7 +1,10 @@
1
- import type { WritableAtom_ } from '@ctx-core/nanostores'
2
- import type { Be } from '@ctx-core/object'
3
- export declare const pathname__:Be<WritableAtom_<string|undefined>>
1
+ import type { ReadableAtom_ } from '@ctx-core/nanostores'
2
+ import type { Be, Ctx } from '@ctx-core/object'
3
+ export declare const pathname__:Be<ReadableAtom_<string>>
4
4
  export {
5
5
  pathname__ as pathname$_,
6
- pathname__ as b__pathname
6
+ pathname__ as b__pathname,
7
+ pathname__ as window_location_pathname__,
8
+ pathname__ as window_location_pathname$_,
7
9
  }
10
+ export declare function pathname_(ctx:Ctx):string
@@ -1,9 +1,24 @@
1
- import { atom_ } from '@ctx-core/nanostores'
1
+ import { nullish__check_ } from '@ctx-core/function'
2
+ import { computed_ } from '@ctx-core/nanostores'
2
3
  import { be_ } from '@ctx-core/object'
4
+ import { window_location__ } from '../window_location__/index.js'
5
+ /** @typedef {import('@ctx-core/object').Ctx}Ctx */
3
6
  /** @type {typeof import('./index.d.ts').pathname__} */
4
- export const pathname__ = be_('pathname__',
5
- ()=>atom_(undefined))
7
+ export const pathname__ = be_('pathname__', ctx=>
8
+ computed_(window_location__(ctx), window_location=>
9
+ nullish__check_([window_location], ()=>
10
+ window_location.pathname)))
6
11
  export {
7
12
  pathname__ as pathname$_,
8
- pathname__ as b__pathname
13
+ pathname__ as b__pathname,
14
+ pathname__ as window_location_pathname__,
15
+ pathname__ as window_location_pathname$_,
16
+ }
17
+ /**
18
+ * @param {Ctx}ctx
19
+ * @returns {string}
20
+ * @private
21
+ */
22
+ export function pathname_(ctx) {
23
+ return pathname__(ctx).$
9
24
  }
@@ -1,7 +1,6 @@
1
- import type { WritableAtom_ } from '@ctx-core/nanostores'
2
- import type { Be } from '@ctx-core/object'
3
- export declare const window_location__:Be<window_location__T>
4
- export interface window_location__T extends WritableAtom_<Location|undefined> {
5
- window_location__reset:()=>void;
6
- }
1
+ import type { ReadableAtom_ } from '@ctx-core/nanostores'
2
+ import type { Be, Ctx } from '@ctx-core/object'
3
+ export declare const window_location__:Be<ReadableAtom_<Location>>
4
+ export declare function window_location_(ctx:Ctx):Location
7
5
  export { window_location__ as window_location$_ }
6
+ export declare function window_location__reset(ctx:Ctx):void
@@ -1,23 +1,35 @@
1
- import { has_dom } from '@ctx-core/dom'
2
- import { atom_ } from '@ctx-core/nanostores'
3
- import { assign, be_ } from '@ctx-core/object'
1
+ import { has_dom, no_dom } from '@ctx-core/dom'
2
+ import { atom_, computed_ } from '@ctx-core/nanostores'
3
+ import { be_ } from '@ctx-core/object'
4
+ const window_location__atom_ = be_('window_location__atom_', ()=>
5
+ atom_())
6
+ /** @typedef {import('@ctx-core/nanostores').WritableAtom_}WritableAtom_ */
7
+ /** @typedef {import('@ctx-core/object').Be}Be */
8
+ /** @typedef {import('@ctx-core/object').Ctx}Ctx */
4
9
  /** @type {typeof import('./index.d.ts').window_location__} */
5
- export const window_location__ = be_('window_location__', ()=>{
6
- const window_location_ = atom_(undefined)
7
- const window_location__onpopstate__bound_ = atom_(false)
10
+ export const window_location__ = be_('window_location__', ctx=>{
8
11
  if (has_dom) {
9
- window_location__reset()
10
- }
11
- return assign(window_location_, {
12
- window_location__reset
13
- })
14
- function window_location__reset() {
15
- if (!has_dom) return
16
- if (!window_location__onpopstate__bound_.$) {
17
- window_location__onpopstate__bound_.set(true)
18
- window.addEventListener('popstate', window_location__reset)
19
- }
20
- window_location_.set(window.location)
12
+ window.addEventListener('popstate', ()=>
13
+ window_location__reset(ctx))
21
14
  }
15
+ return computed_(
16
+ window_location__atom_(ctx),
17
+ $=>$)
22
18
  })
23
19
  export { window_location__ as window_location$_ }
20
+ /**
21
+ * @param {Ctx}ctx
22
+ * @returns {Location}
23
+ * @private
24
+ */
25
+ export function window_location_(ctx) {
26
+ return window_location__(ctx).$
27
+ }
28
+ /** @typedef {Be<WritableAtom_<boolean>>} */
29
+ /**
30
+ * @param {Ctx}ctx
31
+ */
32
+ export function window_location__reset(ctx) {
33
+ if (no_dom) return
34
+ window_location__atom_(ctx).$ = window.location
35
+ }
package/COMMIT_EDITMSG DELETED
@@ -1,3 +0,0 @@
1
-
2
-
3
-
@@ -1,4 +0,0 @@
1
- import type { ReadableAtom_ } from '@ctx-core/nanostores'
2
- import type { Be } from '@ctx-core/object'
3
- export declare const window_location_hostname__:Be<ReadableAtom_<string|undefined>>
4
- export { window_location_hostname__ as window_location_hostname$_ }
@@ -1,11 +0,0 @@
1
- import { computed_ } from '@ctx-core/nanostores'
2
- import { be_ } from '@ctx-core/object'
3
- import { hostname__ } from '../hostname__/index.js'
4
- import { window_location__ } from '../window_location__/index.js'
5
- /** @type {typeof import('./index.d.ts').window_location_hostname__} */
6
- export const window_location_hostname__ = be_('window_location_hostname__', (ctx)=>computed_([
7
- hostname__(ctx),
8
- window_location__(ctx),
9
- ], (hostname, window_location)=>
10
- window_location && window_location.hostname || hostname || ''))
11
- export { window_location_hostname__ as window_location_hostname$_ }
@@ -1,5 +0,0 @@
1
- import type { ReadableAtom_ } from '@ctx-core/nanostores'
2
- import type { Be } from '@ctx-core/object'
3
- export declare const window_location_pathname__:Be<ReadableAtom_<window_location_pathname_T>>
4
- export declare type window_location_pathname_T = string|undefined
5
- export { window_location_pathname__ as window_location_pathname$_ }
@@ -1,12 +0,0 @@
1
- import { computed_ } from '@ctx-core/nanostores'
2
- import { be_ } from '@ctx-core/object'
3
- import { pathname__ } from '../pathname__/index.js'
4
- import { window_location__ } from '../window_location__/index.js'
5
- /** @type {typeof import('./index.d.ts').window_location_pathname__} */
6
- export const window_location_pathname__ = be_('window_location_pathname__', ctx=>
7
- computed_([
8
- pathname__(ctx),
9
- window_location__(ctx),
10
- ], (pathname, location__window)=>
11
- location__window && location__window.pathname || pathname || ''))
12
- export { window_location_pathname__ as window_location_pathname$_ }