@coorax/core 0.0.0-canary.2 → 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/index.js CHANGED
@@ -230,6 +230,18 @@ var isPlainObject = (v) => {
230
230
  function areObjectsTheSame(objA, objB) {
231
231
  return _.isEqual(objA, objB);
232
232
  }
233
+ function compareDocumentVersion(...versions) {
234
+ return versions.map((version) => {
235
+ const [major, minor, patch] = version.split(".").map(Number);
236
+ return { major, minor, patch };
237
+ }).sort((a, b) => {
238
+ if (a.major !== b.major)
239
+ return a.major - b.major;
240
+ if (a.minor !== b.minor)
241
+ return a.minor - b.minor;
242
+ return a.patch - b.patch;
243
+ }).map(({ major, minor, patch }) => `${major}.${minor}.${patch}`);
244
+ }
233
245
  var UTILS = {
234
246
  generateRandomId,
235
247
  generateId,
@@ -307,7 +319,7 @@ var Text = {
307
319
  minHeight: "32px",
308
320
  whiteSpace: "pre-wrap",
309
321
  fontWeight: 400,
310
- lineHeight: 2,
322
+ lineHeight: 1.5,
311
323
  display: "block",
312
324
  alignItems: "center",
313
325
  outline: "none",
@@ -339,9 +351,30 @@ var Heading = {
339
351
  },
340
352
  className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
341
353
  };
354
+ var SubHeading = {
355
+ style: {
356
+ width: "100%",
357
+ maxWidth: "100%",
358
+ color: "var(--foreground)",
359
+ fontSize: "28px",
360
+ minHeight: "40px",
361
+ fontWeight: 400,
362
+ whiteSpace: "pre-wrap",
363
+ display: "block",
364
+ alignItems: "center",
365
+ outline: "none",
366
+ border: "none",
367
+ fieldSizing: "content",
368
+ cursor: "default",
369
+ paddingInline: 4,
370
+ userSelect: "none"
371
+ },
372
+ className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
373
+ };
342
374
  var Image = {
343
375
  style: {
344
376
  width: "100%",
377
+ alignSelf: "center",
345
378
  objectFit: "cover",
346
379
  display: "block",
347
380
  alignItems: "center",
@@ -492,6 +525,7 @@ var Caption = {
492
525
  var DEFAULT_STYLES = {
493
526
  text: Text,
494
527
  heading: Heading,
528
+ "sub-heading": SubHeading,
495
529
  image: Image,
496
530
  divider: Divider,
497
531
  video: Video,
@@ -505,7 +539,7 @@ function isEditableField(block) {
505
539
  return block.variant === "field" && isEditableType(block.type);
506
540
  }
507
541
  function isEditableType(type) {
508
- return type === "heading" || type === "text" || type === "blockquote" || type === "link" || type === "code" || type === "caption";
542
+ return type === "heading" || type === "sub-heading" || type === "text" || type === "blockquote" || type === "link" || type === "code" || type === "caption";
509
543
  }
510
544
  function isMediaField(block) {
511
545
  return block.variant === "field" && isMediaType(block.type);
@@ -530,7 +564,7 @@ function getIframeSrc(value) {
530
564
  const videoId = hostname === "youtu.be" ? segments[0] : segments[0] === "watch" ? url.searchParams.get("v") : ["embed", "shorts", "live"].includes(segments[0] ?? "") ? segments[1] : undefined;
531
565
  if (!videoId || !/^[\w-]{11}$/.test(videoId))
532
566
  return null;
533
- return `https://www.youtube.com/embed/${videoId}`;
567
+ return `https://www.youtube.com/embed/${videoId}?enablejsapi=1`;
534
568
  }
535
569
  function NewTextField(defaultValue) {
536
570
  return new FieldClass({
@@ -564,6 +598,22 @@ function NewHeadingField(defaultValue) {
564
598
  ...defaultValue
565
599
  });
566
600
  }
601
+ function NewSubHeadingField(defaultValue) {
602
+ return new FieldClass({
603
+ id: UTILS.generateFieldId(),
604
+ name: "Sub-heading field",
605
+ type: "sub-heading",
606
+ tag: "h2",
607
+ variant: "field",
608
+ props: {
609
+ children: { text: "", marks: [] },
610
+ "data-text-path": "props.children",
611
+ contentEditable: false,
612
+ ...DEFAULT_STYLES["sub-heading"]
613
+ },
614
+ ...defaultValue
615
+ });
616
+ }
567
617
  function NewImageField(defaultValue) {
568
618
  return new FieldClass({
569
619
  id: UTILS.generateFieldId(),
@@ -700,6 +750,8 @@ function NewField(type, defaultValue) {
700
750
  return NewTextField(defaultValue);
701
751
  case "heading":
702
752
  return NewHeadingField(defaultValue);
753
+ case "sub-heading":
754
+ return NewSubHeadingField(defaultValue);
703
755
  case "image":
704
756
  return NewImageField(defaultValue);
705
757
  case "video":
@@ -728,6 +780,7 @@ var FieldsUtils = {
728
780
  DeserializeField,
729
781
  NewTextField,
730
782
  NewHeadingField,
783
+ NewSubHeadingField,
731
784
  NewLinkField,
732
785
  NewImageField,
733
786
  NewDividerField,
@@ -1751,14 +1804,11 @@ class MutationsService {
1751
1804
  }
1752
1805
  const orderArray = Array.from(tree.order);
1753
1806
  let targetIndex = index;
1754
- while (targetIndex > 0 && targetIndex < orderArray.length) {
1755
- const previous = tree.fields.get(orderArray[targetIndex - 1]);
1756
- const current = tree.fields.get(orderArray[targetIndex]);
1757
- const isAttachedCaption = !!previous && isMediaType(previous.type) && !!current && current.type === "caption" && current.props.mediaId === previous.id;
1758
- if (!isAttachedCaption)
1759
- break;
1807
+ const previous = tree.fields.get(orderArray[targetIndex - 1]);
1808
+ const current = tree.fields.get(orderArray[targetIndex]);
1809
+ const isAttachedCaption = !!previous && isMediaType(previous.type) && !!current && current.type === "caption" && current.props.mediaId === previous.id;
1810
+ if (isAttachedCaption)
1760
1811
  targetIndex++;
1761
- }
1762
1812
  orderArray.splice(targetIndex, 0, field.id);
1763
1813
  order = new Set(orderArray);
1764
1814
  } else {
@@ -2445,7 +2495,11 @@ var InsertionModule = {
2445
2495
  ctx.events.emit("actions:toggle", isOpen);
2446
2496
  });
2447
2497
  ctx.commands.register("fields.change", ({ fieldId, type }) => {
2448
- ctx.document.apply((tree) => ctx.mutations.changeField(tree, { fieldId, type }), { origin: isMediaType(type) ? "history" : "user" });
2498
+ const block = ctx.document.getBlock(fieldId);
2499
+ if (block && block.type === "caption") {
2500
+ return;
2501
+ }
2502
+ ctx.document.apply((tree) => ctx.mutations.changeField(tree, { fieldId, type }), { origin: isMediaType(type) || type === "link" ? "history" : "user" });
2449
2503
  ctx.state.set("insertion", false);
2450
2504
  ctx.events.emit("fields:change", { fieldId, type });
2451
2505
  });
@@ -2498,14 +2552,15 @@ var InsertionModule = {
2498
2552
  getPayload: () => !ctx.state.get("insertion")
2499
2553
  });
2500
2554
  actionButton("insert-heading", "heading", "HeadingIcon", 1);
2501
- actionButton("insert-text", "text", "TextIcon", 2);
2502
- actionButton("insert-image", "image", "ImagePlus", 3);
2503
- actionButton("insert-video", "video", "TvMinimalPlayIcon", 4);
2504
- actionButton("insert-iframe", "iframe", "YoutubeIcon", 5);
2505
- actionButton("insert-doc", "link", "FileTextIcon", 6);
2506
- actionButton("insert-blockquote", "blockquote", "QuoteIcon", 7);
2507
- actionButton("insert-code", "code", "CodeIcon", 8);
2508
- actionButton("insert-divider", "divider", "DividerIcon", 9);
2555
+ actionButton("insert-sub-heading", "sub-heading", "Heading2Icon", 2);
2556
+ actionButton("insert-text", "text", "TextIcon", 3);
2557
+ actionButton("insert-image", "image", "ImagePlus", 4);
2558
+ actionButton("insert-video", "video", "TvMinimalPlayIcon", 5);
2559
+ actionButton("insert-iframe", "iframe", "YoutubeIcon", 6);
2560
+ actionButton("insert-doc", "link", "FileTextIcon", 7);
2561
+ actionButton("insert-blockquote", "blockquote", "QuoteIcon", 8);
2562
+ actionButton("insert-code", "code", "CodeIcon", 9);
2563
+ actionButton("insert-divider", "divider", "DividerIcon", 10);
2509
2564
  }
2510
2565
  };
2511
2566
  // src/modules/editor/editor.module.ts
@@ -2675,10 +2730,10 @@ var FocusModule = {
2675
2730
  getProps: (ui4) => {
2676
2731
  const editorState = ctx.state.get("editor") ?? { editorRect: null };
2677
2732
  const position = focusOverlayPropsFromUICtx(ui4, editorState?.editorRect);
2678
- const document = ctx.state.get("document");
2733
+ const document2 = ctx.state.get("document");
2679
2734
  return {
2680
2735
  position,
2681
- hidden: !ui4.focus?.id || !position || !document?.order.has(ui4?.focus?.id)
2736
+ hidden: !ui4.focus?.id || !position || !document2?.order.has(ui4?.focus?.id)
2682
2737
  };
2683
2738
  }
2684
2739
  }));
@@ -2768,11 +2823,11 @@ var HoverModule = {
2768
2823
  getProps: (ui4) => {
2769
2824
  const editorState = ctx.state.get("editor") ?? { editorRect: null };
2770
2825
  const selection = ctx.state.get("selection");
2771
- const document = ctx.state.get("document");
2826
+ const document2 = ctx.state.get("document");
2772
2827
  const position = hoverOverlayPropsFromUICtx(ui4, editorState?.editorRect);
2773
2828
  return {
2774
2829
  position,
2775
- hidden: !ui4.hover?.id || !position || !!selection && selection.blocks.has(ui4.hover?.id) || !document?.order.has(ui4.hover?.id)
2830
+ hidden: !ui4.hover?.id || !position || !!selection && selection.blocks.has(ui4.hover?.id) || !document2?.order.has(ui4.hover?.id)
2776
2831
  };
2777
2832
  }
2778
2833
  }));
@@ -3077,14 +3132,13 @@ var CodeModule = {
3077
3132
  }
3078
3133
  };
3079
3134
  // src/modules/caption/caption.module.ts
3080
- var hasCaptionFor = (fields, mediaId) => {
3081
- for (const field of fields) {
3082
- if (field.type !== "caption")
3083
- continue;
3084
- if (field.props.mediaId === mediaId)
3085
- return true;
3086
- }
3087
- return false;
3135
+ var hasCaptionFor = (tree, mediaId) => {
3136
+ const order = [...tree.order];
3137
+ const pos = order.indexOf(mediaId);
3138
+ if (pos === -1)
3139
+ return false;
3140
+ const next = tree.fields.get(order[pos + 1]);
3141
+ return next?.type === "caption" && next.props.mediaId === mediaId;
3088
3142
  };
3089
3143
  var CaptionModule = {
3090
3144
  name: "caption",
@@ -3095,30 +3149,24 @@ var CaptionModule = {
3095
3149
  const media = ctx.document.getBlock(mediaId);
3096
3150
  if (!media || !isMediaField(media))
3097
3151
  return;
3098
- if (hasCaptionFor(ctx.document.get().fields.values(), mediaId))
3152
+ if (hasCaptionFor(ctx.document.get(), mediaId))
3099
3153
  return;
3100
3154
  const pos = [...ctx.document.get().order].indexOf(mediaId);
3101
3155
  if (pos === -1)
3102
3156
  return;
3103
3157
  const caption = FieldsUtils.NewCaptionField();
3104
- if (caption.props?.mediaId) {
3105
- caption.props.mediaId = mediaId;
3106
- }
3107
- ctx.document.apply((tree) => ctx.mutations.insertField(tree, caption, pos + 1));
3158
+ ctx.document.apply((tree) => {
3159
+ const newTree = ctx.mutations.insertField(tree, caption, pos + 1);
3160
+ return ctx.mutations.mutateField(newTree, {
3161
+ id: caption.id,
3162
+ keyValuePairs: {
3163
+ "props.mediaId": mediaId
3164
+ }
3165
+ });
3166
+ });
3108
3167
  ctx.events.emit("caption:add", { mediaId });
3109
3168
  };
3110
3169
  ctx.commands.register("caption.add", ({ mediaId }) => addCaption(mediaId));
3111
- ctx.events.on("fields:change", ({ value }) => {
3112
- if (!isMediaType(value.type))
3113
- return;
3114
- addCaption(value.fieldId);
3115
- });
3116
- ctx.events.on("blocks:insert", ({ value }) => {
3117
- const block = value.block;
3118
- if (block.variant !== "field" || !isMediaType(block.type))
3119
- return;
3120
- addCaption(block.id);
3121
- });
3122
3170
  ctx.ui.contribute(defineButton({
3123
3171
  id: "insert-caption",
3124
3172
  slot: "toolbar",
@@ -3143,11 +3191,321 @@ var CaptionModule = {
3143
3191
  const media = ctx.document.getBlock(mediaId);
3144
3192
  if (!media || !isMediaField(media))
3145
3193
  return false;
3146
- return !hasCaptionFor(ctx.document.get().fields.values(), mediaId);
3194
+ const doc = ctx.document.get();
3195
+ const mediaIdx = [...doc.order].indexOf(mediaId);
3196
+ const caption = ctx.document.getBlock([...doc.order][mediaIdx + 1]);
3197
+ if (caption && caption.props.mediaId === media.id)
3198
+ return false;
3199
+ return true;
3147
3200
  }
3148
3201
  }));
3149
3202
  }
3150
3203
  };
3204
+ // src/modules/media/media.module.ts
3205
+ var IMAGE_WIDTHS = {
3206
+ sm: "calc(100% + 100px)",
3207
+ lg: "calc(100% + 300px)"
3208
+ };
3209
+ var selectedId = (ui4) => {
3210
+ const blocks = ui4.selection?.blocks;
3211
+ if (!blocks || blocks.size !== 1)
3212
+ return null;
3213
+ return [...blocks.keys()][0];
3214
+ };
3215
+ var isYouTubeIframe = (block) => {
3216
+ const field = block;
3217
+ if (!field || field.type !== "iframe")
3218
+ return false;
3219
+ return !!field.props?.src && !!getIframeSrc(field.props.src)?.startsWith("https://www.youtube.com/embed/");
3220
+ };
3221
+ var MediaModule = {
3222
+ name: "media",
3223
+ version: "1.0.0",
3224
+ requires: [],
3225
+ install(ctx) {
3226
+ ctx.commands.register("iframe.playback", ({ fieldId, action }) => {
3227
+ const block = ctx.document.getBlock(fieldId);
3228
+ if (!block || block.type !== "iframe")
3229
+ return;
3230
+ const iframe = document.getElementById(fieldId);
3231
+ iframe?.contentWindow?.postMessage(JSON.stringify({
3232
+ event: "command",
3233
+ func: action === "play" ? "playVideo" : "pauseVideo",
3234
+ args: []
3235
+ }), "*");
3236
+ ctx.events.emit("iframe:playback", { fieldId, action });
3237
+ });
3238
+ ctx.commands.register("image.setWidth", ({ fieldId, width }) => {
3239
+ const block = ctx.document.getBlock(fieldId);
3240
+ if (!block || block.type !== "image")
3241
+ return;
3242
+ const next = block.props.style?.width === width ? "100%" : width;
3243
+ ctx.document.apply((tree) => ctx.mutations.mutateField(tree, {
3244
+ id: fieldId,
3245
+ keyValuePairs: { "props.style": { width: next, maxWidth: "none" } }
3246
+ }));
3247
+ ctx.events.emit("image:setWidth", { fieldId, width: next });
3248
+ });
3249
+ ctx.ui.contribute(defineButton({
3250
+ id: "iframe-playback",
3251
+ slot: "toolbar",
3252
+ order: 70,
3253
+ kind: "button",
3254
+ icon: "PlayIcon",
3255
+ command: "iframe.playback",
3256
+ name: "IframePlaybackButton",
3257
+ label: "Play/Pause",
3258
+ getPayload: (ui4) => {
3259
+ const fieldId = selectedId(ui4);
3260
+ if (!fieldId)
3261
+ throw new Error("Empty selection...");
3262
+ return { fieldId, action: "play" };
3263
+ },
3264
+ getProps: () => ({}),
3265
+ when: (ui4) => {
3266
+ const fieldId = selectedId(ui4);
3267
+ if (!fieldId)
3268
+ return false;
3269
+ return isYouTubeIframe(ctx.document.getBlock(fieldId));
3270
+ }
3271
+ }));
3272
+ const widthButton = (id, icon, order, width) => ctx.ui.contribute(defineButton({
3273
+ id,
3274
+ slot: "toolbar",
3275
+ order,
3276
+ kind: "button",
3277
+ icon,
3278
+ command: "image.setWidth",
3279
+ name: "ImageWidthButton",
3280
+ label: `Width ${width}`,
3281
+ getPayload: (ui4) => {
3282
+ const fieldId = selectedId(ui4);
3283
+ if (!fieldId)
3284
+ throw new Error("Empty selection...");
3285
+ return { fieldId, width };
3286
+ },
3287
+ getProps: (ui4) => {
3288
+ const fieldId = selectedId(ui4);
3289
+ const block = fieldId ? ctx.document.getBlock(fieldId) : undefined;
3290
+ return { isActive: block?.props.style?.width === width };
3291
+ },
3292
+ when: (ui4) => {
3293
+ const fieldId = selectedId(ui4);
3294
+ if (!fieldId)
3295
+ return false;
3296
+ return ctx.document.getBlock(fieldId)?.type === "image";
3297
+ }
3298
+ }));
3299
+ widthButton("image-width-sm", "MoveHorizontalIcon", 80, IMAGE_WIDTHS.sm);
3300
+ widthButton("image-width-lg", "ExpandIcon", 81, IMAGE_WIDTHS.lg);
3301
+ }
3302
+ };
3303
+ // src/modules/divider/divider.module.ts
3304
+ var DIVIDER_STYLES = ["solid", "dashed", "dotted"];
3305
+ var DIVIDER_WIDTHS = {
3306
+ sm: "calc(100% - 100px)",
3307
+ lg: "calc(100% - 300px)"
3308
+ };
3309
+ var selectedId2 = (ui4) => {
3310
+ const blocks = ui4.selection?.blocks;
3311
+ if (!blocks || blocks.size !== 1)
3312
+ return null;
3313
+ return [...blocks.keys()][0];
3314
+ };
3315
+ var DividerModule = {
3316
+ name: "divider",
3317
+ version: "1.0.0",
3318
+ requires: [],
3319
+ install(ctx) {
3320
+ ctx.commands.register("divider.setWidth", ({ fieldId, width }) => {
3321
+ const block = ctx.document.getBlock(fieldId);
3322
+ if (!block || block.type !== "divider")
3323
+ return;
3324
+ const next = block.props.style?.width === width ? "100%" : width;
3325
+ ctx.document.apply((tree) => ctx.mutations.mutateField(tree, {
3326
+ id: fieldId,
3327
+ keyValuePairs: { "props.style": { width: next } }
3328
+ }));
3329
+ ctx.events.emit("divider:setWidth", { fieldId, width: next });
3330
+ });
3331
+ ctx.commands.register("divider.setStyle", ({ fieldId, style }) => {
3332
+ const block = ctx.document.getBlock(fieldId);
3333
+ if (!block || block.type !== "divider")
3334
+ return;
3335
+ ctx.document.apply((tree) => ctx.mutations.mutateField(tree, {
3336
+ id: fieldId,
3337
+ keyValuePairs: { "props.style": { borderTopStyle: style } }
3338
+ }));
3339
+ ctx.events.emit("divider:setStyle", { fieldId, style });
3340
+ });
3341
+ const widthButton = (id, icon, order, width) => ctx.ui.contribute(defineButton({
3342
+ id,
3343
+ slot: "toolbar",
3344
+ order,
3345
+ kind: "button",
3346
+ icon,
3347
+ command: "divider.setWidth",
3348
+ name: "DividerWidthButton",
3349
+ label: `Width ${width}`,
3350
+ getPayload: (ui4) => {
3351
+ const fieldId = selectedId2(ui4);
3352
+ if (!fieldId)
3353
+ throw new Error("Empty selection...");
3354
+ return { fieldId, width };
3355
+ },
3356
+ getProps: (ui4) => {
3357
+ const fieldId = selectedId2(ui4);
3358
+ const block = fieldId ? ctx.document.getBlock(fieldId) : undefined;
3359
+ return { isActive: block?.props.style?.width === width };
3360
+ },
3361
+ when: (ui4) => {
3362
+ const fieldId = selectedId2(ui4);
3363
+ if (!fieldId)
3364
+ return false;
3365
+ return ctx.document.getBlock(fieldId)?.type === "divider";
3366
+ }
3367
+ }));
3368
+ widthButton("divider-width-sm", "MoveHorizontalIcon", 90, DIVIDER_WIDTHS.sm);
3369
+ widthButton("divider-width-lg", "ExpandIcon", 91, DIVIDER_WIDTHS.lg);
3370
+ const styleButton = (id, order, borderStyle) => ctx.ui.contribute(defineButton({
3371
+ id,
3372
+ slot: "toolbar",
3373
+ order,
3374
+ kind: "button",
3375
+ icon: "LineStyleIcon",
3376
+ command: "divider.setStyle",
3377
+ name: "DividerStyleButton",
3378
+ label: `Style ${borderStyle}`,
3379
+ getPayload: (ui4) => {
3380
+ const fieldId = selectedId2(ui4);
3381
+ if (!fieldId)
3382
+ throw new Error("Empty selection...");
3383
+ return { fieldId, style: borderStyle };
3384
+ },
3385
+ getProps: (ui4) => {
3386
+ const fieldId = selectedId2(ui4);
3387
+ const block = fieldId ? ctx.document.getBlock(fieldId) : undefined;
3388
+ const current = block?.props.style?.borderTopStyle ?? "solid";
3389
+ return { isActive: current === borderStyle, borderStyle };
3390
+ },
3391
+ when: (ui4) => {
3392
+ const fieldId = selectedId2(ui4);
3393
+ if (!fieldId)
3394
+ return false;
3395
+ return ctx.document.getBlock(fieldId)?.type === "divider";
3396
+ }
3397
+ }));
3398
+ DIVIDER_STYLES.forEach((borderStyle, index) => {
3399
+ styleButton(`divider-style-${borderStyle}`, 92 + index, borderStyle);
3400
+ });
3401
+ }
3402
+ };
3403
+ // src/modules/paragraph-theme/paragraph-theme.module.ts
3404
+ var PARAGRAPH_THEMES = [
3405
+ "neutral",
3406
+ "warning",
3407
+ "error",
3408
+ "info"
3409
+ ];
3410
+ var THEME_ICONS = {
3411
+ neutral: "ThemeNeutralIcon",
3412
+ warning: "ThemeWarningIcon",
3413
+ error: "ThemeErrorIcon",
3414
+ info: "ThemeInfoIcon"
3415
+ };
3416
+ var PARAGRAPH_THEME_STYLES = {
3417
+ neutral: { backgroundColor: "var(--card)", color: "var(--muted-foreground)" },
3418
+ warning: { backgroundColor: "rgba(245, 158, 11, 0.05)", color: "rgb(180, 83, 9)" },
3419
+ error: { backgroundColor: "rgba(244, 63, 94, 0.05)", color: "rgb(190, 18, 60)" },
3420
+ info: { backgroundColor: "rgba(59, 130, 246, 0.05)", color: "rgb(29, 78, 216)" }
3421
+ };
3422
+ var getParagraphTheme = (content) => {
3423
+ const len = content.text.length;
3424
+ const mark = content.marks.find((m) => m.type === "theme" && m.start === 0 && m.end === len);
3425
+ if (!mark)
3426
+ return null;
3427
+ return mark.attrs?.["data-theme"] ?? null;
3428
+ };
3429
+ var ParagraphThemeModule = {
3430
+ name: "paragraph-theme",
3431
+ version: "1.0.0",
3432
+ requires: [],
3433
+ install(ctx) {
3434
+ ctx.text.registerMark("theme", { inclusive: true });
3435
+ const selectedId3 = (ui4) => {
3436
+ const blocks = ui4.selection?.blocks;
3437
+ if (!blocks || blocks.size !== 1)
3438
+ return null;
3439
+ const id = [...blocks.keys()][0];
3440
+ const type = ctx.document.getBlock(id)?.type;
3441
+ return type === "text" || type === "sub-heading" ? id : null;
3442
+ };
3443
+ ctx.commands.register("paragraph.setTheme", ({ fieldId, theme }) => {
3444
+ const block = ctx.document.getBlock(fieldId);
3445
+ if (!block || block.type !== "text" && block.type !== "sub-heading")
3446
+ return;
3447
+ const content = block.props.children;
3448
+ const len = content.text.length;
3449
+ if (len === 0)
3450
+ return;
3451
+ const isToggleOff = getParagraphTheme(content) === theme;
3452
+ const others = content.marks.filter((m) => m.type !== "theme");
3453
+ const marks = isToggleOff ? others : [
3454
+ ...others,
3455
+ {
3456
+ type: "theme",
3457
+ start: 0,
3458
+ end: len,
3459
+ attrs: {
3460
+ "data-theme": theme,
3461
+ style: {
3462
+ ...PARAGRAPH_THEME_STYLES[theme],
3463
+ height: "100%",
3464
+ display: "block",
3465
+ borderRadius: 12,
3466
+ paddingInline: 16,
3467
+ paddingBlock: 12,
3468
+ whiteSpace: "pre-wrap",
3469
+ lineHeight: 1.5
3470
+ }
3471
+ }
3472
+ }
3473
+ ];
3474
+ ctx.document.apply((tree) => ctx.mutations.mutateField(tree, {
3475
+ id: fieldId,
3476
+ keyValuePairs: { ["props.children"]: { text: content.text, marks } },
3477
+ autoMerge: false
3478
+ }));
3479
+ ctx.events.emit("paragraph:setTheme", { fieldId, theme });
3480
+ });
3481
+ const themeButton = (id, order, theme) => ctx.ui.contribute(defineButton({
3482
+ id,
3483
+ slot: "toolbar",
3484
+ order,
3485
+ kind: "button",
3486
+ icon: THEME_ICONS[theme],
3487
+ command: "paragraph.setTheme",
3488
+ name: "ParagraphThemeButton",
3489
+ label: `Theme ${theme}`,
3490
+ getPayload: (ui4) => {
3491
+ const fieldId = selectedId3(ui4);
3492
+ if (!fieldId)
3493
+ throw new Error("Empty selection...");
3494
+ return { fieldId, theme };
3495
+ },
3496
+ getProps: (ui4) => {
3497
+ const fieldId = selectedId3(ui4);
3498
+ const block = fieldId ? ctx.document.getBlock(fieldId) : undefined;
3499
+ const isActive = !!block && getParagraphTheme(block.props.children) === theme;
3500
+ return { isActive, theme };
3501
+ },
3502
+ when: (ui4) => selectedId3(ui4) !== null
3503
+ }));
3504
+ PARAGRAPH_THEMES.forEach((theme, index) => {
3505
+ themeButton(`paragraph-theme-${theme}`, 60 + index, theme);
3506
+ });
3507
+ }
3508
+ };
3151
3509
  // src/modules/deletion/deletion.module.ts
3152
3510
  var DeletionModule = {
3153
3511
  name: "deletion",
@@ -3195,12 +3553,14 @@ export {
3195
3553
  isMediaField,
3196
3554
  isEditableType,
3197
3555
  isEditableField,
3556
+ getParagraphTheme,
3198
3557
  getIframeSrc,
3199
3558
  getCollectedStyles,
3200
3559
  defineComponent,
3201
3560
  defineButton,
3202
3561
  coraxTreeDiffing,
3203
3562
  hash as coraxStyleHash,
3563
+ compareDocumentVersion,
3204
3564
  collectCoraxPseudoStyle,
3205
3565
  clearCollectedStyles,
3206
3566
  areObjectsTheSame,
@@ -3218,11 +3578,14 @@ export {
3218
3578
  StateError,
3219
3579
  SerializeTree,
3220
3580
  SelectionModule,
3581
+ ParagraphThemeModule,
3582
+ PARAGRAPH_THEME_STYLES,
3221
3583
  MutationsService,
3222
3584
  MutationPrototypeError,
3223
3585
  MutationError,
3224
3586
  ModuleUtils,
3225
3587
  ModuleManager,
3588
+ MediaModule,
3226
3589
  InsertionModule,
3227
3590
  HoverModule,
3228
3591
  HistoryModule,
@@ -3234,6 +3597,7 @@ export {
3234
3597
  Engine,
3235
3598
  EditorModule,
3236
3599
  DocumentService,
3600
+ DividerModule,
3237
3601
  DeserializeTree,
3238
3602
  DeletionModule,
3239
3603
  DEFAULT_STYLES,
@@ -0,0 +1,58 @@
1
+ import type { FieldId } from "@coorax/schema";
2
+ import type { CommandMap } from "../../services/commandsbus/commandsbus";
3
+ import type { TModule } from "../modules.types";
4
+ /** Styles de trait proposés dans la toolbar pour le séparateur. */
5
+ declare const DIVIDER_STYLES: readonly ["solid", "dashed", "dotted"];
6
+ export type DividerStyle = (typeof DIVIDER_STYLES)[number];
7
+ declare module "../modules-manager" {
8
+ interface ModuleMap {
9
+ divider: {};
10
+ }
11
+ }
12
+ declare module "../../services/commandsbus/commandsbus" {
13
+ interface CommandMap {
14
+ "divider.setWidth": {
15
+ payload: {
16
+ fieldId: FieldId;
17
+ width: string;
18
+ };
19
+ result: void;
20
+ };
21
+ "divider.setStyle": {
22
+ payload: {
23
+ fieldId: FieldId;
24
+ style: DividerStyle;
25
+ };
26
+ result: void;
27
+ };
28
+ }
29
+ }
30
+ declare module "../../services/eventbus/eventbus" {
31
+ interface TEventMap {
32
+ "divider:setWidth": CommandMap["divider.setWidth"]["payload"];
33
+ "divider:setStyle": CommandMap["divider.setStyle"]["payload"];
34
+ }
35
+ }
36
+ declare module "../../services/ui/ui" {
37
+ interface ButtonContributionIdentityMap {
38
+ "divider-width-sm": {};
39
+ "divider-width-lg": {};
40
+ "divider-style-solid": {};
41
+ "divider-style-dashed": {};
42
+ "divider-style-dotted": {};
43
+ }
44
+ interface IconMap {
45
+ LineStyleIcon: {};
46
+ }
47
+ interface SlotButtonPropsMap {
48
+ DividerWidthButton: {
49
+ isActive: boolean;
50
+ };
51
+ DividerStyleButton: {
52
+ isActive: boolean;
53
+ borderStyle: DividerStyle;
54
+ };
55
+ }
56
+ }
57
+ export declare const DividerModule: TModule;
58
+ export {};
@@ -9,4 +9,7 @@ export * from "./text-editing/text-editing.module";
9
9
  export * from "./editor/editor.module";
10
10
  export * from "./code/code.module";
11
11
  export * from "./caption/caption.module";
12
+ export * from "./media/media.module";
13
+ export * from "./divider/divider.module";
14
+ export * from "./paragraph-theme/paragraph-theme.module";
12
15
  export * from "./deletion/deletion.module";
@@ -51,6 +51,7 @@ declare module "../../services/ui/ui" {
51
51
  interface ButtonContributionIdentityMap {
52
52
  "insert-field": {};
53
53
  "insert-heading": {};
54
+ "insert-sub-heading": {};
54
55
  "insert-text": {};
55
56
  "insert-image": {};
56
57
  "insert-video": {};
@@ -66,6 +67,7 @@ declare module "../../services/ui/ui" {
66
67
  FileTextIcon: {};
67
68
  QuoteIcon: {};
68
69
  CodeIcon: {};
70
+ Heading2Icon: {};
69
71
  }
70
72
  }
71
73
  export declare const InsertionModule: TModule;
@@ -0,0 +1,52 @@
1
+ import { type FieldId } from "@coorax/schema";
2
+ import type { CommandMap } from "../../services/commandsbus/commandsbus";
3
+ import type { TModule } from "../modules.types";
4
+ declare module "../modules-manager" {
5
+ interface ModuleMap {
6
+ media: {};
7
+ }
8
+ }
9
+ declare module "../../services/commandsbus/commandsbus" {
10
+ interface CommandMap {
11
+ "iframe.playback": {
12
+ payload: {
13
+ fieldId: FieldId;
14
+ action: "play" | "pause";
15
+ };
16
+ result: void;
17
+ };
18
+ "image.setWidth": {
19
+ payload: {
20
+ fieldId: FieldId;
21
+ width: string;
22
+ };
23
+ result: void;
24
+ };
25
+ }
26
+ }
27
+ declare module "../../services/eventbus/eventbus" {
28
+ interface TEventMap {
29
+ "iframe:playback": CommandMap["iframe.playback"]["payload"];
30
+ "image:setWidth": CommandMap["image.setWidth"]["payload"];
31
+ }
32
+ }
33
+ declare module "../../services/ui/ui" {
34
+ interface ButtonContributionIdentityMap {
35
+ "iframe-playback": {};
36
+ "image-width-sm": {};
37
+ "image-width-lg": {};
38
+ }
39
+ interface IconMap {
40
+ PlayIcon: {};
41
+ PauseIcon: {};
42
+ MoveHorizontalIcon: {};
43
+ ExpandIcon: {};
44
+ }
45
+ interface SlotButtonPropsMap {
46
+ IframePlaybackButton: {};
47
+ ImageWidthButton: {
48
+ isActive: boolean;
49
+ };
50
+ }
51
+ }
52
+ export declare const MediaModule: TModule;
@@ -0,0 +1,49 @@
1
+ import type { FieldId, MarkTheme, NodeCommonProps, TextContent } from "@coorax/schema";
2
+ import type { CommandMap } from "../../services/commandsbus/commandsbus";
3
+ import type { TModule } from "../modules.types";
4
+ /** Style du `<span>` couvrant tout le texte du paragraphe, par thème. */
5
+ export declare const PARAGRAPH_THEME_STYLES: Record<MarkTheme, NodeCommonProps["style"]>;
6
+ /** Thème appliqué sur tout le texte du paragraphe, ou null s'il n'y en a pas. */
7
+ export declare const getParagraphTheme: (content: TextContent) => MarkTheme | null;
8
+ declare module "../modules-manager" {
9
+ interface ModuleMap {
10
+ "paragraph-theme": {};
11
+ }
12
+ }
13
+ declare module "../../services/commandsbus/commandsbus" {
14
+ interface CommandMap {
15
+ "paragraph.setTheme": {
16
+ payload: {
17
+ fieldId: FieldId;
18
+ theme: MarkTheme;
19
+ };
20
+ result: void;
21
+ };
22
+ }
23
+ }
24
+ declare module "../../services/eventbus/eventbus" {
25
+ interface TEventMap {
26
+ "paragraph:setTheme": CommandMap["paragraph.setTheme"]["payload"];
27
+ }
28
+ }
29
+ declare module "../../services/ui/ui" {
30
+ interface ButtonContributionIdentityMap {
31
+ "paragraph-theme-neutral": {};
32
+ "paragraph-theme-warning": {};
33
+ "paragraph-theme-error": {};
34
+ "paragraph-theme-info": {};
35
+ }
36
+ interface IconMap {
37
+ ThemeNeutralIcon: {};
38
+ ThemeWarningIcon: {};
39
+ ThemeErrorIcon: {};
40
+ ThemeInfoIcon: {};
41
+ }
42
+ interface SlotButtonPropsMap {
43
+ ParagraphThemeButton: {
44
+ isActive: boolean;
45
+ theme: MarkTheme;
46
+ };
47
+ }
48
+ }
49
+ export declare const ParagraphThemeModule: TModule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coorax/core",
3
- "version": "0.0.0-canary.2",
3
+ "version": "0.0.0-canary.3",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist",
@@ -36,22 +36,22 @@
36
36
  "prepublishOnly": "bun run build"
37
37
  },
38
38
  "dependencies": {
39
- "@coorax/schema": "0.0.0-canary.1",
40
- "@fontsource-variable/geist": "^5.3.0",
39
+ "@coorax/schema": "workspace:*",
40
+ "@fontsource-variable/geist": "catalog:",
41
41
  "@tailwindcss/cli": "^4.3.5",
42
- "cn": "^0.4.0",
42
+ "cn": "catalog:",
43
43
  "lodash": "^4.18.1"
44
44
  },
45
45
  "devDependencies": {
46
- "@tailwindcss/vite": "4.3.3",
46
+ "@tailwindcss/vite": "catalog:",
47
47
  "@types/lodash": "^4.17.27",
48
- "csstype": "^3.2.3",
48
+ "csstype": "catalog:",
49
49
  "oxfmt": "^0.71.0",
50
50
  "oxlint": "^1.86.0",
51
- "tailwindcss": "4.3.3",
51
+ "tailwindcss": "catalog:",
52
52
  "typescript": "~6.0.2",
53
53
  "vite": "^8.3.0",
54
- "vitest": "^5.0.3"
54
+ "vitest": "catalog:testing"
55
55
  },
56
56
  "packageManager": "bun@1.3.9"
57
57
  }