@wix/site-service-pages 1.9.0 → 1.10.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/README.md CHANGED
@@ -17,16 +17,20 @@ import { PagesService } from '@wix/site-service-pages/implementations'
17
17
  createServicesMap().addService(PagesDefinition, PagesService, config)
18
18
 
19
19
  const service = servicesManager.getService(PagesDefinition)
20
- // service.pages ← Record<string, Page>
20
+ // service.pages ← Record<string, PageConfig>, keyed by page ID
21
21
  // service.mainPage ← Page (resolved by provider, stored as-is)
22
22
  // service.currentPage ← Page (resolved by provider, stored as-is)
23
+
24
+ // Find a page by its slug:
25
+ const springPage = Object.values(service.pages).find((page) => page.slug === 'spring')
26
+ const onMainPage = service.currentPage.slug === service.mainPage.slug
23
27
  ```
24
28
 
25
29
  ## API
26
30
 
27
31
  | Member | Type | Throws when | Description |
28
32
  |---|---|---|---|
29
- | `pages` | `Record<string, Page>` | never | All pages with `id` stamped from map key. |
33
+ | `pages` | `Record<string, PageConfig>` | never | All pages, keyed by page ID. Each page also has its `slug`. |
30
34
  | `mainPage` | `Page` | never | The site's main/home page as provided. |
31
35
  | `currentPage` | `Page` | never | The currently active page as provided. |
32
36
  | `_updateConfig` | `(Partial<IPagesServiceConfig>) => void` | never | Replace-on-write per field. Re-stamps `id` on `pages` update. |
@@ -37,7 +41,7 @@ const service = servicesManager.getService(PagesDefinition)
37
41
 
38
42
  ```ts
39
43
  type IPagesServiceConfig = {
40
- /** id-as-key map; values omit `id` (P3). Service stamps id at write time (P16). */
44
+ /** id-as-key map; values omit `id` (P3) and carry `slug`. */
41
45
  pages: Record<string, PageConfig>
42
46
  /** Provider resolves and passes the full main page object. */
43
47
  mainPage: Page
@@ -47,7 +51,11 @@ type IPagesServiceConfig = {
47
51
 
48
52
  type PageConfig = {
49
53
  title: string
54
+ /** The page's `pageUriSEO`, unique across the site, including popups. */
55
+ slug: string
50
56
  path: string
57
+ /** Slug of the parent page. */
58
+ parentSlug?: string
51
59
  parentPageId?: string
52
60
  popup: boolean
53
61
  /** TPA page identifier (e.g. `ecom_side_cart`). Not globally unique on its own — pair with `appDefinitionId`. */
@@ -61,6 +69,8 @@ type Page = PageConfig & { id: string }
61
69
 
62
70
  The provider is responsible for resolving which page is `mainPage` / `currentPage` before injecting config. The service stores them as independent signals and does no internal lookup.
63
71
 
72
+ The provider supplies `slug` on every page, and `parentSlug` alongside `parentPageId`.
73
+
64
74
  ## Reactivity
65
75
 
66
76
  This service is a thin signal wrapper over `@wix/services-definitions/core-services/signals`. All three properties are signal-backed; wrap reads in `effect` / `computed` to react to changes. Signals are not exposed directly.
@@ -11,18 +11,36 @@ export type PageConfig = {
11
11
  * @exampleValue 'Spring Collection'
12
12
  */
13
13
  title: string;
14
+ /**
15
+ * Page slug, the page's own segment of its URL, as a Wix user set it in the page's SEO settings.
16
+ *
17
+ * The slug is unique across the site, including popups, so use it to find a page in the `pages` map or
18
+ * to compare two pages. A Wix user can change it, and a multilingual site can translate it, so don't
19
+ * store it. To identify an app's page across sites, use `appPageId` and `appDefinitionId`.
20
+ *
21
+ * @exampleValue 'spring'
22
+ */
23
+ slug: string;
14
24
  /**
15
25
  * Page path, relative to the site root URL.
16
26
  *
17
27
  * For a nested page, the path usually starts with its parent page's path, such as `collections/spring`.
18
28
  * When a Wix user turns off URL hierarchy in the site's SEO settings, the path is just the page's own
19
- * slug, such as `spring`. To find a page's parent, use `parentPageId`, not the path.
29
+ * slug, such as `spring`. To find a page's parent, use `parentSlug`, not the path.
20
30
  *
21
31
  * To build the page's URL, join the site root URL and the path with a single `/`.
22
32
  *
23
33
  * @exampleValue 'collections/spring'
24
34
  */
25
35
  path: string;
36
+ /**
37
+ * Slug of this page's parent page in the site's page structure.
38
+ *
39
+ * Undefined if the page doesn't have a parent page.
40
+ *
41
+ * @exampleValue 'collections'
42
+ */
43
+ parentSlug?: string;
26
44
  /**
27
45
  * ID of this page's parent page in the site's page structure.
28
46
  *
@@ -71,7 +89,7 @@ export type Page = PageConfig & {
71
89
  };
72
90
  /** Values the host supplies when it creates the service. */
73
91
  export type IPagesServiceConfig = {
74
- /** Every page on the site, keyed by page ID. The values have no `id`. */
92
+ /** Every page on the site, keyed by page ID. The values have no `id`, and each has its `slug`. */
75
93
  pages: {
76
94
  [pageId: string]: PageConfig;
77
95
  };
@@ -88,12 +106,13 @@ export interface IPagesService {
88
106
  /**
89
107
  * Every page on the site, keyed by page ID.
90
108
  *
91
- * The values don't include an `id`. Use the key as the page's ID.
109
+ * The values don't include an `id`. Use the key as the page's ID. To find a page by its slug, search the
110
+ * values: `Object.values(pages).find((page) => page.slug === slug)`.
92
111
  *
93
112
  * Don't change the map or its pages. Every component on the page reads the same map, so a change shows in
94
113
  * all of them, and the site doesn't save it.
95
114
  *
96
- * @exampleValue `{ "m4rw8": { "title": "Home", "path": "home", "popup": false }, "c1dmp": { "title": "Shop", "path": "shop", "popup": false }, "i9xk2": { "title": "Collections", "path": "collections", "popup": false }, "t5nb6": { "title": "Spring Collection", "path": "collections/spring", "parentPageId": "i9xk2", "popup": false }, "q7hz3": { "title": "Side Cart", "path": "side-cart", "popup": true, "appPageId": "ecom_side_cart", "appDefinitionId": "1380b703-ce81-ff05-f115-39571d94dfcd" } }`
115
+ * @exampleValue `{ "m4rw8": { "title": "Home", "slug": "home", "path": "home", "popup": false }, "c1dmp": { "title": "Shop", "slug": "shop", "path": "shop", "popup": false }, "i9xk2": { "title": "Collections", "slug": "collections", "path": "collections", "popup": false }, "t5nb6": { "title": "Spring Collection", "slug": "spring", "path": "collections/spring", "parentSlug": "collections", "parentPageId": "i9xk2", "popup": false }, "q7hz3": { "title": "Side Cart", "slug": "side-cart", "path": "side-cart", "popup": true, "appPageId": "ecom_side_cart", "appDefinitionId": "1380b703-ce81-ff05-f115-39571d94dfcd" } }`
97
116
  */
98
117
  readonly pages: {
99
118
  [pageId: string]: PageConfig;
@@ -102,12 +121,12 @@ export interface IPagesService {
102
121
  * Main page, the page a site visitor reaches at the site root URL.
103
122
  *
104
123
  * A Wix user chooses which page this is. To check whether the page that's currently displayed is the
105
- * main page, compare `currentPage.id` with `mainPage.id`.
124
+ * main page, compare `currentPage.slug` with `mainPage.slug`.
106
125
  *
107
126
  * Don't change its fields. Every component on the page reads the same object, so a change shows in all of
108
127
  * them, and the site doesn't save it.
109
128
  *
110
- * @exampleValue `{ "id": "m4rw8", "title": "Home", "path": "home", "popup": false }`
129
+ * @exampleValue `{ "id": "m4rw8", "title": "Home", "slug": "home", "path": "home", "popup": false }`
111
130
  */
112
131
  readonly mainPage: Page;
113
132
  /**
@@ -116,7 +135,7 @@ export interface IPagesService {
116
135
  * Don't change its fields. Every component on the page reads the same object, so a change shows in all of
117
136
  * them, and the site doesn't save it.
118
137
  *
119
- * @exampleValue `{ "id": "c1dmp", "title": "Shop", "path": "shop", "popup": false }`
138
+ * @exampleValue `{ "id": "c1dmp", "title": "Shop", "slug": "shop", "path": "shop", "popup": false }`
120
139
  */
121
140
  readonly currentPage: Page;
122
141
  /** @internal Host-only. Replaces config values when the host's state changes. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/definition/index.ts"],"names":[],"mappings":";;;AAAA,oEAAyD;AAmI5C,QAAA,eAAe,GAAG,IAAA,oCAAa,EAAqC,yBAAyB,CAAC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/definition/index.ts"],"names":[],"mappings":";;;AAAA,oEAAyD;AAsJ5C,QAAA,eAAe,GAAG,IAAA,oCAAa,EAAqC,yBAAyB,CAAC,CAAA"}
@@ -11,18 +11,36 @@ export type PageConfig = {
11
11
  * @exampleValue 'Spring Collection'
12
12
  */
13
13
  title: string;
14
+ /**
15
+ * Page slug, the page's own segment of its URL, as a Wix user set it in the page's SEO settings.
16
+ *
17
+ * The slug is unique across the site, including popups, so use it to find a page in the `pages` map or
18
+ * to compare two pages. A Wix user can change it, and a multilingual site can translate it, so don't
19
+ * store it. To identify an app's page across sites, use `appPageId` and `appDefinitionId`.
20
+ *
21
+ * @exampleValue 'spring'
22
+ */
23
+ slug: string;
14
24
  /**
15
25
  * Page path, relative to the site root URL.
16
26
  *
17
27
  * For a nested page, the path usually starts with its parent page's path, such as `collections/spring`.
18
28
  * When a Wix user turns off URL hierarchy in the site's SEO settings, the path is just the page's own
19
- * slug, such as `spring`. To find a page's parent, use `parentPageId`, not the path.
29
+ * slug, such as `spring`. To find a page's parent, use `parentSlug`, not the path.
20
30
  *
21
31
  * To build the page's URL, join the site root URL and the path with a single `/`.
22
32
  *
23
33
  * @exampleValue 'collections/spring'
24
34
  */
25
35
  path: string;
36
+ /**
37
+ * Slug of this page's parent page in the site's page structure.
38
+ *
39
+ * Undefined if the page doesn't have a parent page.
40
+ *
41
+ * @exampleValue 'collections'
42
+ */
43
+ parentSlug?: string;
26
44
  /**
27
45
  * ID of this page's parent page in the site's page structure.
28
46
  *
@@ -71,7 +89,7 @@ export type Page = PageConfig & {
71
89
  };
72
90
  /** Values the host supplies when it creates the service. */
73
91
  export type IPagesServiceConfig = {
74
- /** Every page on the site, keyed by page ID. The values have no `id`. */
92
+ /** Every page on the site, keyed by page ID. The values have no `id`, and each has its `slug`. */
75
93
  pages: {
76
94
  [pageId: string]: PageConfig;
77
95
  };
@@ -88,12 +106,13 @@ export interface IPagesService {
88
106
  /**
89
107
  * Every page on the site, keyed by page ID.
90
108
  *
91
- * The values don't include an `id`. Use the key as the page's ID.
109
+ * The values don't include an `id`. Use the key as the page's ID. To find a page by its slug, search the
110
+ * values: `Object.values(pages).find((page) => page.slug === slug)`.
92
111
  *
93
112
  * Don't change the map or its pages. Every component on the page reads the same map, so a change shows in
94
113
  * all of them, and the site doesn't save it.
95
114
  *
96
- * @exampleValue `{ "m4rw8": { "title": "Home", "path": "home", "popup": false }, "c1dmp": { "title": "Shop", "path": "shop", "popup": false }, "i9xk2": { "title": "Collections", "path": "collections", "popup": false }, "t5nb6": { "title": "Spring Collection", "path": "collections/spring", "parentPageId": "i9xk2", "popup": false }, "q7hz3": { "title": "Side Cart", "path": "side-cart", "popup": true, "appPageId": "ecom_side_cart", "appDefinitionId": "1380b703-ce81-ff05-f115-39571d94dfcd" } }`
115
+ * @exampleValue `{ "m4rw8": { "title": "Home", "slug": "home", "path": "home", "popup": false }, "c1dmp": { "title": "Shop", "slug": "shop", "path": "shop", "popup": false }, "i9xk2": { "title": "Collections", "slug": "collections", "path": "collections", "popup": false }, "t5nb6": { "title": "Spring Collection", "slug": "spring", "path": "collections/spring", "parentSlug": "collections", "parentPageId": "i9xk2", "popup": false }, "q7hz3": { "title": "Side Cart", "slug": "side-cart", "path": "side-cart", "popup": true, "appPageId": "ecom_side_cart", "appDefinitionId": "1380b703-ce81-ff05-f115-39571d94dfcd" } }`
97
116
  */
98
117
  readonly pages: {
99
118
  [pageId: string]: PageConfig;
@@ -102,12 +121,12 @@ export interface IPagesService {
102
121
  * Main page, the page a site visitor reaches at the site root URL.
103
122
  *
104
123
  * A Wix user chooses which page this is. To check whether the page that's currently displayed is the
105
- * main page, compare `currentPage.id` with `mainPage.id`.
124
+ * main page, compare `currentPage.slug` with `mainPage.slug`.
106
125
  *
107
126
  * Don't change its fields. Every component on the page reads the same object, so a change shows in all of
108
127
  * them, and the site doesn't save it.
109
128
  *
110
- * @exampleValue `{ "id": "m4rw8", "title": "Home", "path": "home", "popup": false }`
129
+ * @exampleValue `{ "id": "m4rw8", "title": "Home", "slug": "home", "path": "home", "popup": false }`
111
130
  */
112
131
  readonly mainPage: Page;
113
132
  /**
@@ -116,7 +135,7 @@ export interface IPagesService {
116
135
  * Don't change its fields. Every component on the page reads the same object, so a change shows in all of
117
136
  * them, and the site doesn't save it.
118
137
  *
119
- * @exampleValue `{ "id": "c1dmp", "title": "Shop", "path": "shop", "popup": false }`
138
+ * @exampleValue `{ "id": "c1dmp", "title": "Shop", "slug": "shop", "path": "shop", "popup": false }`
120
139
  */
121
140
  readonly currentPage: Page;
122
141
  /** @internal Host-only. Replaces config values when the host's state changes. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAmIzD,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAqC,yBAAyB,CAAC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAsJzD,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAqC,yBAAyB,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/site-service-pages",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "license": "UNLICENSED",
5
5
  "files": [
6
6
  "dist",
@@ -77,5 +77,5 @@
77
77
  ]
78
78
  }
79
79
  },
80
- "falconPackageHash": "c622db257aae8f54416d87dfce31ffc74820e291e115a6a9cce8b0c4"
80
+ "falconPackageHash": "d568b273bf9a7f463a24f3c9e0c60003b8cffa648be73d8aca1a2505"
81
81
  }
@@ -13,18 +13,36 @@ export type PageConfig = {
13
13
  * @exampleValue 'Spring Collection'
14
14
  */
15
15
  title: string
16
+ /**
17
+ * Page slug, the page's own segment of its URL, as a Wix user set it in the page's SEO settings.
18
+ *
19
+ * The slug is unique across the site, including popups, so use it to find a page in the `pages` map or
20
+ * to compare two pages. A Wix user can change it, and a multilingual site can translate it, so don't
21
+ * store it. To identify an app's page across sites, use `appPageId` and `appDefinitionId`.
22
+ *
23
+ * @exampleValue 'spring'
24
+ */
25
+ slug: string
16
26
  /**
17
27
  * Page path, relative to the site root URL.
18
28
  *
19
29
  * For a nested page, the path usually starts with its parent page's path, such as `collections/spring`.
20
30
  * When a Wix user turns off URL hierarchy in the site's SEO settings, the path is just the page's own
21
- * slug, such as `spring`. To find a page's parent, use `parentPageId`, not the path.
31
+ * slug, such as `spring`. To find a page's parent, use `parentSlug`, not the path.
22
32
  *
23
33
  * To build the page's URL, join the site root URL and the path with a single `/`.
24
34
  *
25
35
  * @exampleValue 'collections/spring'
26
36
  */
27
37
  path: string
38
+ /**
39
+ * Slug of this page's parent page in the site's page structure.
40
+ *
41
+ * Undefined if the page doesn't have a parent page.
42
+ *
43
+ * @exampleValue 'collections'
44
+ */
45
+ parentSlug?: string
28
46
  /**
29
47
  * ID of this page's parent page in the site's page structure.
30
48
  *
@@ -75,7 +93,7 @@ export type Page = PageConfig & {
75
93
 
76
94
  /** Values the host supplies when it creates the service. */
77
95
  export type IPagesServiceConfig = {
78
- /** Every page on the site, keyed by page ID. The values have no `id`. */
96
+ /** Every page on the site, keyed by page ID. The values have no `id`, and each has its `slug`. */
79
97
  pages: { [pageId: string]: PageConfig }
80
98
  /** The main page. The service stores it unchanged. */
81
99
  mainPage: Page
@@ -91,12 +109,13 @@ export interface IPagesService {
91
109
  /**
92
110
  * Every page on the site, keyed by page ID.
93
111
  *
94
- * The values don't include an `id`. Use the key as the page's ID.
112
+ * The values don't include an `id`. Use the key as the page's ID. To find a page by its slug, search the
113
+ * values: `Object.values(pages).find((page) => page.slug === slug)`.
95
114
  *
96
115
  * Don't change the map or its pages. Every component on the page reads the same map, so a change shows in
97
116
  * all of them, and the site doesn't save it.
98
117
  *
99
- * @exampleValue `{ "m4rw8": { "title": "Home", "path": "home", "popup": false }, "c1dmp": { "title": "Shop", "path": "shop", "popup": false }, "i9xk2": { "title": "Collections", "path": "collections", "popup": false }, "t5nb6": { "title": "Spring Collection", "path": "collections/spring", "parentPageId": "i9xk2", "popup": false }, "q7hz3": { "title": "Side Cart", "path": "side-cart", "popup": true, "appPageId": "ecom_side_cart", "appDefinitionId": "1380b703-ce81-ff05-f115-39571d94dfcd" } }`
118
+ * @exampleValue `{ "m4rw8": { "title": "Home", "slug": "home", "path": "home", "popup": false }, "c1dmp": { "title": "Shop", "slug": "shop", "path": "shop", "popup": false }, "i9xk2": { "title": "Collections", "slug": "collections", "path": "collections", "popup": false }, "t5nb6": { "title": "Spring Collection", "slug": "spring", "path": "collections/spring", "parentSlug": "collections", "parentPageId": "i9xk2", "popup": false }, "q7hz3": { "title": "Side Cart", "slug": "side-cart", "path": "side-cart", "popup": true, "appPageId": "ecom_side_cart", "appDefinitionId": "1380b703-ce81-ff05-f115-39571d94dfcd" } }`
100
119
  */
101
120
  readonly pages: { [pageId: string]: PageConfig }
102
121
 
@@ -104,12 +123,12 @@ export interface IPagesService {
104
123
  * Main page, the page a site visitor reaches at the site root URL.
105
124
  *
106
125
  * A Wix user chooses which page this is. To check whether the page that's currently displayed is the
107
- * main page, compare `currentPage.id` with `mainPage.id`.
126
+ * main page, compare `currentPage.slug` with `mainPage.slug`.
108
127
  *
109
128
  * Don't change its fields. Every component on the page reads the same object, so a change shows in all of
110
129
  * them, and the site doesn't save it.
111
130
  *
112
- * @exampleValue `{ "id": "m4rw8", "title": "Home", "path": "home", "popup": false }`
131
+ * @exampleValue `{ "id": "m4rw8", "title": "Home", "slug": "home", "path": "home", "popup": false }`
113
132
  */
114
133
  readonly mainPage: Page
115
134
 
@@ -119,7 +138,7 @@ export interface IPagesService {
119
138
  * Don't change its fields. Every component on the page reads the same object, so a change shows in all of
120
139
  * them, and the site doesn't save it.
121
140
  *
122
- * @exampleValue `{ "id": "c1dmp", "title": "Shop", "path": "shop", "popup": false }`
141
+ * @exampleValue `{ "id": "c1dmp", "title": "Shop", "slug": "shop", "path": "shop", "popup": false }`
123
142
  */
124
143
  readonly currentPage: Page
125
144