@coorax/schema 0.0.0-canary.1 → 0.0.0-canary.3
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/dist/base/index.d.ts +1 -0
- package/dist/base/types/field/field.d.ts +4 -1
- package/dist/base/types/field/field.media.types.d.ts +8 -0
- package/dist/base/types/field/sub-heading.types.d.ts +3 -0
- package/dist/index.js +57 -3
- package/dist/services/text-marks/marks.types.d.ts +6 -0
- package/dist/utils/fields.utils.d.ts +2 -0
- package/dist/utils/global.utils.d.ts +2 -0
- package/package.json +1 -1
- package/dist/base/types/field/field.document.types.d.ts +0 -3
package/dist/base/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from "./types/container/ul-list.types";
|
|
|
11
11
|
export * from "./types/field/field";
|
|
12
12
|
export * from "./types/field/field.text.types";
|
|
13
13
|
export * from "./types/field/heading.types";
|
|
14
|
+
export * from "./types/field/sub-heading.types";
|
|
14
15
|
export * from "./types/field/paragraph.types";
|
|
15
16
|
export * from "./types/node/link.types";
|
|
16
17
|
export * from "./types/node/node";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ParagraphProps } from "./paragraph.types.ts";
|
|
2
2
|
import type { HeadingProps } from "./heading.types.ts";
|
|
3
|
+
import type { SubHeadingProps } from "./sub-heading.types.ts";
|
|
3
4
|
import type { ContainerId } from "../container/container.ts";
|
|
4
5
|
import type { OmitFieldsMethods } from "../global.types.ts";
|
|
5
6
|
import type { DividerProps } from "./divider.types";
|
|
@@ -16,6 +17,7 @@ export type FieldId = `field:${string}-${string}-${string}-${string}-${string}`
|
|
|
16
17
|
export interface FieldMap {
|
|
17
18
|
p: ParagraphProps;
|
|
18
19
|
h1: HeadingProps;
|
|
20
|
+
h2: SubHeadingProps;
|
|
19
21
|
img: ImageFieldProps;
|
|
20
22
|
video: VideoFieldProps;
|
|
21
23
|
a: LinkFieldProps;
|
|
@@ -28,6 +30,7 @@ export interface FieldMap {
|
|
|
28
30
|
export interface FieldTMap {
|
|
29
31
|
text: {};
|
|
30
32
|
heading: {};
|
|
33
|
+
"sub-heading": {};
|
|
31
34
|
link: {};
|
|
32
35
|
image: {};
|
|
33
36
|
video: {};
|
|
@@ -50,7 +53,7 @@ export interface Field<T extends FieldType = FieldType, A extends FieldTag = Fie
|
|
|
50
53
|
isContainerized(): boolean;
|
|
51
54
|
getCurrentFieldObject(): OmitFieldsMethods<Field<T, A>>;
|
|
52
55
|
}
|
|
53
|
-
export type TextField = Field<"heading" | "text", "h1" | "p">;
|
|
56
|
+
export type TextField = Field<"heading" | "sub-heading" | "text", "h1" | "h2" | "p">;
|
|
54
57
|
export type MediaField = Field<"image" | "video", "img" | "video">;
|
|
55
58
|
export type ImageField = Field<"image", "img">;
|
|
56
59
|
export type LinkField = Field<"link", "a">;
|
|
@@ -2,4 +2,12 @@ import type { NodeCommonProps } from "../global.types";
|
|
|
2
2
|
export interface MediaCommonProps extends NodeCommonProps {
|
|
3
3
|
src: string;
|
|
4
4
|
alt: string;
|
|
5
|
+
/**
|
|
6
|
+
* Dimensions intrinsèques du média, capturées au chargement (image : `naturalWidth`,
|
|
7
|
+
* vidéo : `videoWidth`, …). Elles servent à réserver un ratio **par média** avant
|
|
8
|
+
* l'affichage effectif, pour éviter tout saut de hauteur (et un calcul de rects faussé)
|
|
9
|
+
* au fil du chargement.
|
|
10
|
+
*/
|
|
11
|
+
intrinsicWidth?: number;
|
|
12
|
+
intrinsicHeight?: number;
|
|
5
13
|
}
|
package/dist/index.js
CHANGED
|
@@ -231,6 +231,18 @@ var isPlainObject = (v) => {
|
|
|
231
231
|
function areObjectsTheSame(objA, objB) {
|
|
232
232
|
return _.isEqual(objA, objB);
|
|
233
233
|
}
|
|
234
|
+
function compareDocumentVersion(...versions) {
|
|
235
|
+
return versions.map((version) => {
|
|
236
|
+
const [major, minor, patch] = version.split(".").map(Number);
|
|
237
|
+
return { major, minor, patch };
|
|
238
|
+
}).sort((a, b) => {
|
|
239
|
+
if (a.major !== b.major)
|
|
240
|
+
return a.major - b.major;
|
|
241
|
+
if (a.minor !== b.minor)
|
|
242
|
+
return a.minor - b.minor;
|
|
243
|
+
return a.patch - b.patch;
|
|
244
|
+
}).map(({ major, minor, patch }) => `${major}.${minor}.${patch}`);
|
|
245
|
+
}
|
|
234
246
|
var UTILS = {
|
|
235
247
|
generateRandomId,
|
|
236
248
|
generateId,
|
|
@@ -312,7 +324,7 @@ var Text = {
|
|
|
312
324
|
minHeight: "32px",
|
|
313
325
|
whiteSpace: "pre-wrap",
|
|
314
326
|
fontWeight: 400,
|
|
315
|
-
lineHeight:
|
|
327
|
+
lineHeight: 1.5,
|
|
316
328
|
display: "block",
|
|
317
329
|
alignItems: "center",
|
|
318
330
|
outline: "none",
|
|
@@ -344,9 +356,30 @@ var Heading = {
|
|
|
344
356
|
},
|
|
345
357
|
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
|
|
346
358
|
};
|
|
359
|
+
var SubHeading = {
|
|
360
|
+
style: {
|
|
361
|
+
width: "100%",
|
|
362
|
+
maxWidth: "100%",
|
|
363
|
+
color: "var(--foreground)",
|
|
364
|
+
fontSize: "28px",
|
|
365
|
+
minHeight: "40px",
|
|
366
|
+
fontWeight: 400,
|
|
367
|
+
whiteSpace: "pre-wrap",
|
|
368
|
+
display: "block",
|
|
369
|
+
alignItems: "center",
|
|
370
|
+
outline: "none",
|
|
371
|
+
border: "none",
|
|
372
|
+
fieldSizing: "content",
|
|
373
|
+
cursor: "default",
|
|
374
|
+
paddingInline: 4,
|
|
375
|
+
userSelect: "none"
|
|
376
|
+
},
|
|
377
|
+
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
|
|
378
|
+
};
|
|
347
379
|
var Image = {
|
|
348
380
|
style: {
|
|
349
381
|
width: "100%",
|
|
382
|
+
alignSelf: "center",
|
|
350
383
|
objectFit: "cover",
|
|
351
384
|
display: "block",
|
|
352
385
|
alignItems: "center",
|
|
@@ -497,6 +530,7 @@ var Caption = {
|
|
|
497
530
|
var DEFAULT_STYLES = {
|
|
498
531
|
text: Text,
|
|
499
532
|
heading: Heading,
|
|
533
|
+
"sub-heading": SubHeading,
|
|
500
534
|
image: Image,
|
|
501
535
|
divider: Divider,
|
|
502
536
|
video: Video,
|
|
@@ -512,7 +546,7 @@ function isEditableField(block) {
|
|
|
512
546
|
return block.variant === "field" && isEditableType(block.type);
|
|
513
547
|
}
|
|
514
548
|
function isEditableType(type) {
|
|
515
|
-
return type === "heading" || type === "text" || type === "blockquote" || type === "link" || type === "code" || type === "caption";
|
|
549
|
+
return type === "heading" || type === "sub-heading" || type === "text" || type === "blockquote" || type === "link" || type === "code" || type === "caption";
|
|
516
550
|
}
|
|
517
551
|
function isMediaField(block) {
|
|
518
552
|
return block.variant === "field" && isMediaType(block.type);
|
|
@@ -537,7 +571,7 @@ function getIframeSrc(value) {
|
|
|
537
571
|
const videoId = hostname === "youtu.be" ? segments[0] : segments[0] === "watch" ? url.searchParams.get("v") : ["embed", "shorts", "live"].includes(segments[0] ?? "") ? segments[1] : undefined;
|
|
538
572
|
if (!videoId || !/^[\w-]{11}$/.test(videoId))
|
|
539
573
|
return null;
|
|
540
|
-
return `https://www.youtube.com/embed/${videoId}`;
|
|
574
|
+
return `https://www.youtube.com/embed/${videoId}?enablejsapi=1`;
|
|
541
575
|
}
|
|
542
576
|
function NewTextField(defaultValue) {
|
|
543
577
|
return new FieldClass({
|
|
@@ -571,6 +605,22 @@ function NewHeadingField(defaultValue) {
|
|
|
571
605
|
...defaultValue
|
|
572
606
|
});
|
|
573
607
|
}
|
|
608
|
+
function NewSubHeadingField(defaultValue) {
|
|
609
|
+
return new FieldClass({
|
|
610
|
+
id: UTILS.generateFieldId(),
|
|
611
|
+
name: "Sub-heading field",
|
|
612
|
+
type: "sub-heading",
|
|
613
|
+
tag: "h2",
|
|
614
|
+
variant: "field",
|
|
615
|
+
props: {
|
|
616
|
+
children: { text: "", marks: [] },
|
|
617
|
+
"data-text-path": "props.children",
|
|
618
|
+
contentEditable: false,
|
|
619
|
+
...DEFAULT_STYLES["sub-heading"]
|
|
620
|
+
},
|
|
621
|
+
...defaultValue
|
|
622
|
+
});
|
|
623
|
+
}
|
|
574
624
|
function NewImageField(defaultValue) {
|
|
575
625
|
return new FieldClass({
|
|
576
626
|
id: UTILS.generateFieldId(),
|
|
@@ -707,6 +757,8 @@ function NewField(type, defaultValue) {
|
|
|
707
757
|
return NewTextField(defaultValue);
|
|
708
758
|
case "heading":
|
|
709
759
|
return NewHeadingField(defaultValue);
|
|
760
|
+
case "sub-heading":
|
|
761
|
+
return NewSubHeadingField(defaultValue);
|
|
710
762
|
case "image":
|
|
711
763
|
return NewImageField(defaultValue);
|
|
712
764
|
case "video":
|
|
@@ -735,6 +787,7 @@ var FieldsUtils = {
|
|
|
735
787
|
DeserializeField,
|
|
736
788
|
NewTextField,
|
|
737
789
|
NewHeadingField,
|
|
790
|
+
NewSubHeadingField,
|
|
738
791
|
NewLinkField,
|
|
739
792
|
NewImageField,
|
|
740
793
|
NewDividerField,
|
|
@@ -1207,6 +1260,7 @@ export {
|
|
|
1207
1260
|
getCollectedStyles,
|
|
1208
1261
|
coraxTreeDiffing,
|
|
1209
1262
|
hash as coraxStyleHash,
|
|
1263
|
+
compareDocumentVersion,
|
|
1210
1264
|
collectCoraxPseudoStyle,
|
|
1211
1265
|
clearCollectedStyles,
|
|
1212
1266
|
areObjectsTheSame,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { TextField } from "../../base";
|
|
2
2
|
import type { NodeCommonProps, PathToProp } from "../../base/types/global.types";
|
|
3
|
+
/** Thèmes de paragraphe pouvant être posés via le mark `theme`. */
|
|
4
|
+
export type MarkTheme = "neutral" | "warning" | "error" | "info";
|
|
3
5
|
export interface MarkMap {
|
|
4
6
|
bold: {};
|
|
5
7
|
italic: {};
|
|
@@ -11,6 +13,10 @@ export interface MarkMap {
|
|
|
11
13
|
initial: {
|
|
12
14
|
style: NodeCommonProps["style"];
|
|
13
15
|
};
|
|
16
|
+
theme: {
|
|
17
|
+
"data-theme": MarkTheme;
|
|
18
|
+
style: NodeCommonProps["style"];
|
|
19
|
+
};
|
|
14
20
|
}
|
|
15
21
|
export type MarkType = keyof MarkMap;
|
|
16
22
|
export type MarkAttrs<T extends MarkType = MarkType> = MarkMap[T];
|
|
@@ -8,6 +8,7 @@ export declare function isMediaType<T extends FieldType = FieldType>(type: T): b
|
|
|
8
8
|
export declare function getIframeSrc(value: string): string | null;
|
|
9
9
|
declare function NewTextField(defaultValue?: Partial<OmitFieldsMethods<Field<"text", FieldTag>>>): Field<"text">;
|
|
10
10
|
declare function NewHeadingField(defaultValue?: Partial<OmitFieldsMethods<Field<"heading", FieldTag>>>): Field<"heading">;
|
|
11
|
+
declare function NewSubHeadingField(defaultValue?: Partial<OmitFieldsMethods<Field<"sub-heading", FieldTag>>>): Field<"sub-heading">;
|
|
11
12
|
declare function NewImageField(defaultValue?: Partial<OmitFieldsMethods<Field<"image", FieldTag>>>): Field<"image">;
|
|
12
13
|
declare function NewIFrameField(defaultValue?: Partial<OmitFieldsMethods<Field<"iframe", FieldTag>>>): Field<"iframe">;
|
|
13
14
|
declare function NewLinkField(defaultValue?: Partial<OmitFieldsMethods<Field<"link", FieldTag>>>): Field<"link">;
|
|
@@ -22,6 +23,7 @@ export declare const FieldsUtils: {
|
|
|
22
23
|
DeserializeField: typeof DeserializeField;
|
|
23
24
|
NewTextField: typeof NewTextField;
|
|
24
25
|
NewHeadingField: typeof NewHeadingField;
|
|
26
|
+
NewSubHeadingField: typeof NewSubHeadingField;
|
|
25
27
|
NewLinkField: typeof NewLinkField;
|
|
26
28
|
NewImageField: typeof NewImageField;
|
|
27
29
|
NewDividerField: typeof NewDividerField;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CoraxTree } from "../base";
|
|
1
2
|
declare function generateRandomId(): string;
|
|
2
3
|
export type CustomID<T extends string> = `${T}:${string}-${string}-${string}-${string}-${string}`;
|
|
3
4
|
declare function generateId<T extends string>(prefix: T): CustomID<T>;
|
|
@@ -31,6 +32,7 @@ export declare class CustomObject<T extends object> {
|
|
|
31
32
|
baseObject(): T;
|
|
32
33
|
}
|
|
33
34
|
export declare function areObjectsTheSame(objA: object, objB: object): boolean;
|
|
35
|
+
export declare function compareDocumentVersion(...versions: CoraxTree["version"][]): `${number}.${number}.${number}`[];
|
|
34
36
|
export declare const UTILS: {
|
|
35
37
|
generateRandomId: typeof generateRandomId;
|
|
36
38
|
generateId: typeof generateId;
|
package/package.json
CHANGED