@parhelia/head 0.0.0-stage → 1.0.12951
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/LICENSE +8 -0
- package/README.md +231 -2
- package/package.json +133 -4
- package/src/bridge-core.d.ts +97 -0
- package/src/bridge-core.js +173 -0
- package/src/contentful.d.ts +34 -0
- package/src/contentful.js +213 -0
- package/src/env.d.ts +11 -0
- package/src/env.js +47 -0
- package/src/identity.d.ts +45 -0
- package/src/identity.js +137 -0
- package/src/index.d.ts +6 -0
- package/src/index.js +13 -0
- package/src/magnolia.d.ts +60 -0
- package/src/magnolia.js +199 -0
- package/src/picture-crops.d.ts +168 -0
- package/src/picture-crops.js +355 -0
- package/src/refresh-dom.d.ts +9 -0
- package/src/refresh-dom.js +92 -0
- package/src/refresh.d.ts +14 -0
- package/src/refresh.js +63 -0
- package/src/rich-text-reader.js +263 -0
- package/src/rich-text.d.ts +17 -0
- package/src/rich-text.js +354 -0
- package/src/server.d.ts +38 -0
- package/src/server.js +113 -0
- package/src/settings.cjs +35 -0
- package/src/settings.d.cts +7 -0
- package/src/sitecore.d.ts +53 -0
- package/src/sitecore.js +228 -0
- package/src/slot-markup.d.ts +5 -0
- package/src/slot-markup.js +24 -0
- package/src/typo3.d.ts +34 -0
- package/src/typo3.js +110 -0
- package/src/umbraco.d.ts +51 -0
- package/src/umbraco.js +146 -0
- package/src/vite.d.ts +18 -0
- package/src/vite.js +53 -0
package/src/umbraco.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** The item kinds an Umbraco field marker names. */
|
|
2
|
+
export type UmbItemKind = "document" | "block" | "media";
|
|
3
|
+
|
|
4
|
+
/** One rendered field's identity, as a head knows it. */
|
|
5
|
+
export type UmbFieldRef = {
|
|
6
|
+
kind: UmbItemKind;
|
|
7
|
+
/** The item's key as the Delivery API spells it (a GUID). */
|
|
8
|
+
key: string;
|
|
9
|
+
/** The property alias. */
|
|
10
|
+
property: string;
|
|
11
|
+
/** The rendered culture for a culture-variant property; null for an invariant one (`*`). */
|
|
12
|
+
culture: string | null;
|
|
13
|
+
/** The culture whose value is shown instead (language fallback), when it is not the rendered culture's own. */
|
|
14
|
+
fallbackFrom?: string | null;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** The vocabulary's wire name. */
|
|
18
|
+
export declare const UMBRACO_MARKER_VOCABULARY: "umbraco";
|
|
19
|
+
/** The item kinds a field marker names. */
|
|
20
|
+
export declare const UMB_ITEM_KINDS: readonly UmbItemKind[];
|
|
21
|
+
/** The attribute naming the item of each kind. */
|
|
22
|
+
export declare const UMB_KIND_ATTRIBUTE: Readonly<Record<UmbItemKind, string>>;
|
|
23
|
+
export declare const UMB_PROPERTY_ATTRIBUTE: string;
|
|
24
|
+
export declare const UMB_CULTURE_ATTRIBUTE: string;
|
|
25
|
+
export declare const UMB_FALLBACK_ATTRIBUTE: string;
|
|
26
|
+
export declare const UMB_RICHTEXT_ATTRIBUTE: string;
|
|
27
|
+
export declare const UMB_REFUSED_ATTRIBUTE: string;
|
|
28
|
+
export declare const UMB_CONTENT_TYPE_ATTRIBUTE: string;
|
|
29
|
+
/** The culture a field marker states for an invariant property. */
|
|
30
|
+
export declare const INVARIANT_CULTURE: "*";
|
|
31
|
+
/** Parhelia addresses an Umbraco item as its current state. */
|
|
32
|
+
export declare const PARHELIA_UMBRACO_VERSION: "0";
|
|
33
|
+
/** Umbraco's rich text block anchor tags (Delivery markup). */
|
|
34
|
+
export declare const UMB_RTE_BLOCK_TAGS: readonly string[];
|
|
35
|
+
/** The anchor's block key attribute (Delivery markup). */
|
|
36
|
+
export declare const UMB_RTE_BLOCK_KEY_ATTRIBUTE: string;
|
|
37
|
+
|
|
38
|
+
/** The field marker attributes of one rendered field; `{}` outside the editor. Throws for a malformed key or alias. */
|
|
39
|
+
export declare function umbFieldAttributes(ref: UmbFieldRef, edit: boolean): Record<string, string>;
|
|
40
|
+
/** The attribute saying a field element holds rich text; `{}` outside the editor. */
|
|
41
|
+
export declare function umbRichTextAttributes(edit: boolean): Record<string, string>;
|
|
42
|
+
/** The attribute naming a picked media item on its rendered image; `{}` outside the editor. */
|
|
43
|
+
export declare function umbPickedMediaAttributes(mediaKey: string, edit: boolean): Record<string, string>;
|
|
44
|
+
/** The attribute naming why a property is not shown. */
|
|
45
|
+
export declare function umbRefusedAttributes(refusal: string): Record<string, string>;
|
|
46
|
+
/** The root slot key of a Block List property or a Block Grid: the property alias. */
|
|
47
|
+
export declare function rootSlotKey(propertyAlias: string): string;
|
|
48
|
+
/** The slot key of a Block Grid area: `{areaAlias}_{OWNER-BLOCK-KEY}`. */
|
|
49
|
+
export declare function areaSlotKey(areaAlias: string, ownerBlockKey: string): string;
|
|
50
|
+
/** The attributes of a block's component-start script. */
|
|
51
|
+
export declare function componentStartAttributes(blockKey: string, contentType: string, culture: string): Record<string, string>;
|
package/src/umbraco.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@parhelia/head/umbraco` — **the Umbraco marker names, and the helpers a head renders them with** (Umbraco program
|
|
3
|
+
* umb-vocab). This module is the one source: an Umbraco head (the Next.js reference head imports it) renders these
|
|
4
|
+
* attributes, the editor's `umbraco` vocabulary (`@parhelia/core`, `bridge/vocabularies/umbraco/`) reads them by importing
|
|
5
|
+
* this module, and the Razor tag helpers of the Parhelia.Umbraco package take the same names from
|
|
6
|
+
* `Parhelia.Umbraco.Protocol.ParheliaMarkerNames`. Both languages are pinned to one test vector,
|
|
7
|
+
* `umbraco.markers.json` beside this file: a renamed attribute fails a test in each language.
|
|
8
|
+
*
|
|
9
|
+
* Fields carry the **Umbraco vocabulary** (store-resolved: the Delivery API answers property aliases and element keys, never
|
|
10
|
+
* Parhelia's field ids, so the page's store answers which item and field a marker names):
|
|
11
|
+
*
|
|
12
|
+
* data-umb-document="<document key>" | data-umb-block="<block content key>" | data-umb-media="<media key>"
|
|
13
|
+
* data-umb-property="<property alias>"
|
|
14
|
+
* data-umb-culture="<culture>" (a culture-variant property) | "*" (an invariant property)
|
|
15
|
+
* data-umb-fallback="<culture>" only when the value shown is the fallback culture's (language fallback)
|
|
16
|
+
* data-umb-richtext on a rich text field's element
|
|
17
|
+
* data-umb-refused="<name>" a property the package refused to render (never a field)
|
|
18
|
+
*
|
|
19
|
+
* Components and slots use Parhelia's own sentinels: a block is a component (`data-component-start` / `-end` scripts
|
|
20
|
+
* carrying the block's content key, which is its Parhelia item id; no `data-typeid`: the store answers it from the
|
|
21
|
+
* composition); a Block List property and a Block Grid root are slots keyed by the property alias, a Block Grid area is the
|
|
22
|
+
* slot `{areaAlias}_{OWNER-BLOCK-KEY}` (owner = the block holding the area, its content key uppercase and braced).
|
|
23
|
+
*
|
|
24
|
+
* A head renders every marker in Parhelia's editing frames only (`edit`); outside them the attributes are absent.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/** The vocabulary's wire name: what the canvas sends with the markers it found, and what the Umbraco store states. */
|
|
28
|
+
export const UMBRACO_MARKER_VOCABULARY = "umbraco";
|
|
29
|
+
|
|
30
|
+
/** The item kinds a field marker names (the entity kind the canvas sends). */
|
|
31
|
+
export const UMB_ITEM_KINDS = Object.freeze(/** @type {const} */ (["document", "block", "media"]));
|
|
32
|
+
|
|
33
|
+
/** The attribute naming the item of each kind (exactly one per field element). */
|
|
34
|
+
export const UMB_KIND_ATTRIBUTE = Object.freeze({
|
|
35
|
+
document: "data-umb-document",
|
|
36
|
+
block: "data-umb-block",
|
|
37
|
+
media: "data-umb-media",
|
|
38
|
+
});
|
|
39
|
+
export const UMB_PROPERTY_ATTRIBUTE = "data-umb-property";
|
|
40
|
+
export const UMB_CULTURE_ATTRIBUTE = "data-umb-culture";
|
|
41
|
+
export const UMB_FALLBACK_ATTRIBUTE = "data-umb-fallback";
|
|
42
|
+
export const UMB_RICHTEXT_ATTRIBUTE = "data-umb-richtext";
|
|
43
|
+
export const UMB_REFUSED_ATTRIBUTE = "data-umb-refused";
|
|
44
|
+
export const UMB_CONTENT_TYPE_ATTRIBUTE = "data-umb-content-type";
|
|
45
|
+
|
|
46
|
+
/** The culture a field marker states for an invariant property. */
|
|
47
|
+
export const INVARIANT_CULTURE = "*";
|
|
48
|
+
|
|
49
|
+
/** Parhelia addresses an Umbraco item as its current state (version 0): Umbraco keeps no numbered versions for it. */
|
|
50
|
+
export const PARHELIA_UMBRACO_VERSION = "0";
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Umbraco's own spelling of a rich text block anchor in the Delivery API's markup (`<umb-rte-block data-content-id>`; the
|
|
54
|
+
* stored form spells the key `data-content-key`). A head keeps the anchor and renders the block inside it.
|
|
55
|
+
*/
|
|
56
|
+
export const UMB_RTE_BLOCK_TAGS = Object.freeze(/** @type {const} */ (["umb-rte-block", "umb-rte-block-inline"]));
|
|
57
|
+
export const UMB_RTE_BLOCK_KEY_ATTRIBUTE = "data-content-id";
|
|
58
|
+
|
|
59
|
+
const GUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
60
|
+
const ALIAS = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The field marker attributes of one rendered field; `{}` outside the editor. Throws for a malformed key or alias.
|
|
64
|
+
* @param {import("./umbraco.js").UmbFieldRef} ref
|
|
65
|
+
* @param {boolean} edit
|
|
66
|
+
* @returns {Record<string, string>}
|
|
67
|
+
*/
|
|
68
|
+
export const umbFieldAttributes = (ref, edit) => {
|
|
69
|
+
if (!edit) return {};
|
|
70
|
+
if (!GUID.test(ref.key)) throw new TypeError(`An Umbraco field marker needs a GUID key; got ${JSON.stringify(ref.key)}.`);
|
|
71
|
+
if (!ALIAS.test(ref.property)) throw new TypeError(`An Umbraco field marker needs a property alias; got ${JSON.stringify(ref.property)}.`);
|
|
72
|
+
/** @type {Record<string, string>} */
|
|
73
|
+
const attributes = {
|
|
74
|
+
[UMB_KIND_ATTRIBUTE[ref.kind]]: ref.key.toLowerCase(),
|
|
75
|
+
[UMB_PROPERTY_ATTRIBUTE]: ref.property,
|
|
76
|
+
[UMB_CULTURE_ATTRIBUTE]: ref.culture ?? INVARIANT_CULTURE,
|
|
77
|
+
};
|
|
78
|
+
if (ref.fallbackFrom && ref.fallbackFrom !== ref.culture) attributes[UMB_FALLBACK_ATTRIBUTE] = ref.fallbackFrom;
|
|
79
|
+
return attributes;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The attribute saying a field element holds rich text; `{}` outside the editor.
|
|
84
|
+
* @param {boolean} edit
|
|
85
|
+
* @returns {Record<string, string>}
|
|
86
|
+
*/
|
|
87
|
+
export const umbRichTextAttributes = edit => (edit ? { [UMB_RICHTEXT_ATTRIBUTE]: "" } : {});
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The attribute naming a picked media item on its rendered image (not a field marker: no property); `{}` outside the editor.
|
|
91
|
+
* @param {string} mediaKey
|
|
92
|
+
* @param {boolean} edit
|
|
93
|
+
* @returns {Record<string, string>}
|
|
94
|
+
*/
|
|
95
|
+
export const umbPickedMediaAttributes = (mediaKey, edit) => (edit ? { [UMB_KIND_ATTRIBUTE.media]: mediaKey } : {});
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The attribute naming why a property is not shown (the package's refusal, e.g. `unattributable-converter`): rendered for
|
|
99
|
+
* every request, never a field.
|
|
100
|
+
* @param {string} refusal
|
|
101
|
+
* @returns {Record<string, string>}
|
|
102
|
+
*/
|
|
103
|
+
export const umbRefusedAttributes = refusal => ({ [UMB_REFUSED_ATTRIBUTE]: refusal });
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The root slot key of a Block List property or a Block Grid: the property alias.
|
|
107
|
+
* @param {string} propertyAlias
|
|
108
|
+
* @returns {string}
|
|
109
|
+
*/
|
|
110
|
+
export const rootSlotKey = propertyAlias => {
|
|
111
|
+
if (!propertyAlias) throw new TypeError("A slot key needs a property alias.");
|
|
112
|
+
return propertyAlias;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The slot key of a Block Grid area: `{areaAlias}_{OWNER-BLOCK-KEY}` (the owning block's key, uppercase and braced).
|
|
117
|
+
* @param {string} areaAlias
|
|
118
|
+
* @param {string} ownerBlockKey
|
|
119
|
+
* @returns {string}
|
|
120
|
+
*/
|
|
121
|
+
export const areaSlotKey = (areaAlias, ownerBlockKey) => {
|
|
122
|
+
if (!areaAlias) throw new TypeError("An area slot key needs the area alias.");
|
|
123
|
+
if (!GUID.test(ownerBlockKey))
|
|
124
|
+
throw new TypeError(`An area slot key needs the owner block's GUID key; got ${JSON.stringify(ownerBlockKey)}.`);
|
|
125
|
+
return `${areaAlias}_{${ownerBlockKey.toUpperCase()}}`;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The attributes of a block's component-start script.
|
|
130
|
+
* @param {string} blockKey
|
|
131
|
+
* @param {string} contentType
|
|
132
|
+
* @param {string} culture
|
|
133
|
+
* @returns {Record<string, string>}
|
|
134
|
+
*/
|
|
135
|
+
export const componentStartAttributes = (blockKey, contentType, culture) => {
|
|
136
|
+
if (!GUID.test(blockKey)) throw new TypeError(`A component boundary needs the block's GUID key; got ${JSON.stringify(blockKey)}.`);
|
|
137
|
+
const key = blockKey.toLowerCase();
|
|
138
|
+
return {
|
|
139
|
+
"data-component-start": key,
|
|
140
|
+
"data-itemid": key,
|
|
141
|
+
"data-component-name": contentType,
|
|
142
|
+
[UMB_CONTENT_TYPE_ATTRIBUTE]: contentType,
|
|
143
|
+
"data-language": culture,
|
|
144
|
+
"data-version": PARHELIA_UMBRACO_VERSION,
|
|
145
|
+
};
|
|
146
|
+
};
|
package/src/vite.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The Vite plugin of a rendering head: `base` below the rendering proxy, `PARHELIA_BASE_PATH` / `PARHELIA_ORIGIN`
|
|
5
|
+
* inlined into browser and server code, this package bundled for the server.
|
|
6
|
+
*/
|
|
7
|
+
export declare function parhelia(options?: { env?: Readonly<Record<string, string | undefined>> }): Plugin;
|
|
8
|
+
|
|
9
|
+
/** What the plugin adds to a Vite config (`base` only when `configuredBase` is undefined). */
|
|
10
|
+
export declare function parheliaViteSettings(
|
|
11
|
+
env: Readonly<Record<string, string | undefined>>,
|
|
12
|
+
configuredBase: string | undefined,
|
|
13
|
+
): {
|
|
14
|
+
base?: string;
|
|
15
|
+
define: Record<string, string>;
|
|
16
|
+
optimizeDeps: { exclude: string[] };
|
|
17
|
+
ssr: { noExternal: string[] };
|
|
18
|
+
};
|
package/src/vite.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@parhelia/head/vite` — `parhelia()`, the Vite plugin of a rendering head on a Vite-based framework (TanStack Start,
|
|
3
|
+
* React Router, plain Vite SSR). The counterpart of `withParhelia` (`@parhelia/next/config`):
|
|
4
|
+
*
|
|
5
|
+
* - `base`: the head is served below Parhelia's rendering proxy (`PARHELIA_RENDERING_PROXY_PATH`), assets included. A
|
|
6
|
+
* `base` the config sets itself is kept. The plugin runs first (`enforce: "pre"`; list it before the framework's), so
|
|
7
|
+
* a framework that derives its router's base path from `base` while it is configured sees it (TanStack Start does).
|
|
8
|
+
* - `define`: `process.env.PARHELIA_BASE_PATH` / `PARHELIA_ORIGIN` are inlined into the browser's and the server's code,
|
|
9
|
+
* so `withBasePath`, the bridge and `contentfulLivePreviewOrigins` read the build's values on both sides. Only
|
|
10
|
+
* these two: the editor secret and the preview key stay server-side environment variables.
|
|
11
|
+
* - The Parhelia head packages are bundled for the server (`ssr.noExternal`) and not pre-bundled (`optimizeDeps.exclude`),
|
|
12
|
+
* so the defines reach their code.
|
|
13
|
+
*
|
|
14
|
+
* The CSP framing rule for a directly framed head is the server's response header, outside the build: allow
|
|
15
|
+
* `PARHELIA_ORIGIN` in `frame-ancestors` where the head sets its headers.
|
|
16
|
+
*/
|
|
17
|
+
import settings from "./settings.cjs";
|
|
18
|
+
|
|
19
|
+
/** The packages that read the build values: bundled for the server and not pre-bundled, so the defines reach them. */
|
|
20
|
+
const PACKAGE_NAMES = ["@parhelia/head", "@parhelia/react", "@parhelia/astro"];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* What the plugin adds to a Vite config (`base` only when the config sets none): also used by the Astro integration,
|
|
24
|
+
* which owns `base` itself.
|
|
25
|
+
* @param {Readonly<Record<string, string | undefined>>} env
|
|
26
|
+
* @param {string | undefined} configuredBase
|
|
27
|
+
*/
|
|
28
|
+
export function parheliaViteSettings(env, configuredBase) {
|
|
29
|
+
const origin = settings.originFromEnv(env);
|
|
30
|
+
const basePath = settings.basePathFromEnv(env);
|
|
31
|
+
return {
|
|
32
|
+
...(basePath && configuredBase === undefined ? { base: `${basePath}/` } : {}),
|
|
33
|
+
define: {
|
|
34
|
+
"process.env.PARHELIA_BASE_PATH": JSON.stringify(basePath),
|
|
35
|
+
"process.env.PARHELIA_ORIGIN": JSON.stringify(origin),
|
|
36
|
+
},
|
|
37
|
+
optimizeDeps: { exclude: PACKAGE_NAMES },
|
|
38
|
+
ssr: { noExternal: PACKAGE_NAMES },
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** @param {{ env?: Readonly<Record<string, string | undefined>> }} [options] */
|
|
43
|
+
export function parhelia(options = {}) {
|
|
44
|
+
const env = options.env ?? process.env;
|
|
45
|
+
// Read once, at once: a value that is not an origin or a path fails the build where it is configured.
|
|
46
|
+
parheliaViteSettings(env, undefined);
|
|
47
|
+
return {
|
|
48
|
+
name: "parhelia",
|
|
49
|
+
enforce: "pre",
|
|
50
|
+
/** @param {{ base?: string }} config */
|
|
51
|
+
config: (config) => parheliaViteSettings(env, config.base),
|
|
52
|
+
};
|
|
53
|
+
}
|