@coorax/core 0.0.0-canary.2 → 0.0.0-canary.4

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.
Files changed (44) hide show
  1. package/dist/index.js +414 -48
  2. package/dist/modules/divider/divider.module.d.ts +58 -0
  3. package/dist/modules/index.d.ts +3 -0
  4. package/dist/modules/insertion/insertion.module.d.ts +2 -0
  5. package/dist/modules/media/media.module.d.ts +52 -0
  6. package/dist/modules/paragraph-theme/paragraph-theme.module.d.ts +49 -0
  7. package/package.json +4 -4
  8. package/dist/base/classes/component.class.d.ts +0 -23
  9. package/dist/base/classes/container.class.d.ts +0 -17
  10. package/dist/base/classes/field.class.d.ts +0 -15
  11. package/dist/base/classes/tnode.class.d.ts +0 -14
  12. package/dist/base/index.d.ts +0 -19
  13. package/dist/base/types/components/components.d.ts +0 -13
  14. package/dist/base/types/container/container.d.ts +0 -27
  15. package/dist/base/types/container/division.types.d.ts +0 -3
  16. package/dist/base/types/container/section.types.d.ts +0 -3
  17. package/dist/base/types/container/ul-list.types.d.ts +0 -3
  18. package/dist/base/types/css.types.d.ts +0 -23
  19. package/dist/base/types/field/divider.types.d.ts +0 -3
  20. package/dist/base/types/field/field.blockquote.types.d.ts +0 -4
  21. package/dist/base/types/field/field.d.ts +0 -50
  22. package/dist/base/types/field/field.image.types.d.ts +0 -3
  23. package/dist/base/types/field/field.media.types.d.ts +0 -5
  24. package/dist/base/types/field/field.text.types.d.ts +0 -8
  25. package/dist/base/types/field/field.video.types.d.ts +0 -8
  26. package/dist/base/types/field/fields.iframe.types.d.ts +0 -7
  27. package/dist/base/types/field/heading.types.d.ts +0 -3
  28. package/dist/base/types/field/paragraph.types.d.ts +0 -3
  29. package/dist/base/types/global.types.d.ts +0 -26
  30. package/dist/base/types/node/link.types.d.ts +0 -3
  31. package/dist/base/types/node/node.d.ts +0 -24
  32. package/dist/base/types/node/span.types.d.ts +0 -3
  33. package/dist/base/types/tree/tree.d.ts +0 -24
  34. package/dist/constants/field.constants.d.ts +0 -1
  35. package/dist/constants/index.d.ts +0 -1
  36. package/dist/modules/text-editing/text-editing.utils.d.ts +0 -6
  37. package/dist/services/text-marks/marks.types.d.ts +0 -35
  38. package/dist/services/ui/default-styles.d.ts +0 -3
  39. package/dist/utils/components.utils.d.ts +0 -10
  40. package/dist/utils/container.utils.d.ts +0 -13
  41. package/dist/utils/fields.utils.d.ts +0 -27
  42. package/dist/utils/global.utils.d.ts +0 -47
  43. package/dist/utils/tnode.utils.d.ts +0 -9
  44. package/dist/utils/tree.utils.d.ts +0 -11
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,13 @@ 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 }), {
2503
+ origin: isMediaType(type) || type === "link" ? "history" : "user"
2504
+ });
2449
2505
  ctx.state.set("insertion", false);
2450
2506
  ctx.events.emit("fields:change", { fieldId, type });
2451
2507
  });
@@ -2498,14 +2554,15 @@ var InsertionModule = {
2498
2554
  getPayload: () => !ctx.state.get("insertion")
2499
2555
  });
2500
2556
  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);
2557
+ actionButton("insert-sub-heading", "sub-heading", "Heading2Icon", 2);
2558
+ actionButton("insert-text", "text", "TextIcon", 3);
2559
+ actionButton("insert-image", "image", "ImagePlus", 4);
2560
+ actionButton("insert-video", "video", "TvMinimalPlayIcon", 5);
2561
+ actionButton("insert-iframe", "iframe", "YoutubeIcon", 6);
2562
+ actionButton("insert-doc", "link", "FileTextIcon", 7);
2563
+ actionButton("insert-blockquote", "blockquote", "QuoteIcon", 8);
2564
+ actionButton("insert-code", "code", "CodeIcon", 9);
2565
+ actionButton("insert-divider", "divider", "DividerIcon", 10);
2509
2566
  }
2510
2567
  };
2511
2568
  // src/modules/editor/editor.module.ts
@@ -2675,10 +2732,10 @@ var FocusModule = {
2675
2732
  getProps: (ui4) => {
2676
2733
  const editorState = ctx.state.get("editor") ?? { editorRect: null };
2677
2734
  const position = focusOverlayPropsFromUICtx(ui4, editorState?.editorRect);
2678
- const document = ctx.state.get("document");
2735
+ const document2 = ctx.state.get("document");
2679
2736
  return {
2680
2737
  position,
2681
- hidden: !ui4.focus?.id || !position || !document?.order.has(ui4?.focus?.id)
2738
+ hidden: !ui4.focus?.id || !position || !document2?.order.has(ui4?.focus?.id)
2682
2739
  };
2683
2740
  }
2684
2741
  }));
@@ -2768,11 +2825,11 @@ var HoverModule = {
2768
2825
  getProps: (ui4) => {
2769
2826
  const editorState = ctx.state.get("editor") ?? { editorRect: null };
2770
2827
  const selection = ctx.state.get("selection");
2771
- const document = ctx.state.get("document");
2828
+ const document2 = ctx.state.get("document");
2772
2829
  const position = hoverOverlayPropsFromUICtx(ui4, editorState?.editorRect);
2773
2830
  return {
2774
2831
  position,
2775
- hidden: !ui4.hover?.id || !position || !!selection && selection.blocks.has(ui4.hover?.id) || !document?.order.has(ui4.hover?.id)
2832
+ hidden: !ui4.hover?.id || !position || !!selection && selection.blocks.has(ui4.hover?.id) || !document2?.order.has(ui4.hover?.id)
2776
2833
  };
2777
2834
  }
2778
2835
  }));
@@ -3077,14 +3134,13 @@ var CodeModule = {
3077
3134
  }
3078
3135
  };
3079
3136
  // 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;
3137
+ var hasCaptionFor = (tree, mediaId) => {
3138
+ const order = [...tree.order];
3139
+ const pos = order.indexOf(mediaId);
3140
+ if (pos === -1)
3141
+ return false;
3142
+ const next = tree.fields.get(order[pos + 1]);
3143
+ return next?.type === "caption" && next.props.mediaId === mediaId;
3088
3144
  };
3089
3145
  var CaptionModule = {
3090
3146
  name: "caption",
@@ -3095,30 +3151,24 @@ var CaptionModule = {
3095
3151
  const media = ctx.document.getBlock(mediaId);
3096
3152
  if (!media || !isMediaField(media))
3097
3153
  return;
3098
- if (hasCaptionFor(ctx.document.get().fields.values(), mediaId))
3154
+ if (hasCaptionFor(ctx.document.get(), mediaId))
3099
3155
  return;
3100
3156
  const pos = [...ctx.document.get().order].indexOf(mediaId);
3101
3157
  if (pos === -1)
3102
3158
  return;
3103
3159
  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));
3160
+ ctx.document.apply((tree) => {
3161
+ const newTree = ctx.mutations.insertField(tree, caption, pos + 1);
3162
+ return ctx.mutations.mutateField(newTree, {
3163
+ id: caption.id,
3164
+ keyValuePairs: {
3165
+ "props.mediaId": mediaId
3166
+ }
3167
+ });
3168
+ });
3108
3169
  ctx.events.emit("caption:add", { mediaId });
3109
3170
  };
3110
3171
  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
3172
  ctx.ui.contribute(defineButton({
3123
3173
  id: "insert-caption",
3124
3174
  slot: "toolbar",
@@ -3143,9 +3193,319 @@ var CaptionModule = {
3143
3193
  const media = ctx.document.getBlock(mediaId);
3144
3194
  if (!media || !isMediaField(media))
3145
3195
  return false;
3146
- return !hasCaptionFor(ctx.document.get().fields.values(), mediaId);
3196
+ const doc = ctx.document.get();
3197
+ const mediaIdx = [...doc.order].indexOf(mediaId);
3198
+ const caption = ctx.document.getBlock([...doc.order][mediaIdx + 1]);
3199
+ if (caption && caption.props.mediaId === media.id)
3200
+ return false;
3201
+ return true;
3202
+ }
3203
+ }));
3204
+ }
3205
+ };
3206
+ // src/modules/media/media.module.ts
3207
+ var IMAGE_WIDTHS = {
3208
+ sm: "calc(100% + 100px)",
3209
+ lg: "calc(100% + 300px)"
3210
+ };
3211
+ var selectedId = (ui4) => {
3212
+ const blocks = ui4.selection?.blocks;
3213
+ if (!blocks || blocks.size !== 1)
3214
+ return null;
3215
+ return [...blocks.keys()][0];
3216
+ };
3217
+ var isYouTubeIframe = (block) => {
3218
+ const field = block;
3219
+ if (!field || field.type !== "iframe")
3220
+ return false;
3221
+ return !!field.props?.src && !!getIframeSrc(field.props.src)?.startsWith("https://www.youtube.com/embed/");
3222
+ };
3223
+ var MediaModule = {
3224
+ name: "media",
3225
+ version: "1.0.0",
3226
+ requires: [],
3227
+ install(ctx) {
3228
+ ctx.commands.register("iframe.playback", ({ fieldId, action }) => {
3229
+ const block = ctx.document.getBlock(fieldId);
3230
+ if (!block || block.type !== "iframe")
3231
+ return;
3232
+ const iframe = document.getElementById(fieldId);
3233
+ iframe?.contentWindow?.postMessage(JSON.stringify({
3234
+ event: "command",
3235
+ func: action === "play" ? "playVideo" : "pauseVideo",
3236
+ args: []
3237
+ }), "*");
3238
+ ctx.events.emit("iframe:playback", { fieldId, action });
3239
+ });
3240
+ ctx.commands.register("image.setWidth", ({ fieldId, width }) => {
3241
+ const block = ctx.document.getBlock(fieldId);
3242
+ if (!block || block.type !== "image")
3243
+ return;
3244
+ const next = block.props.style?.width === width ? "100%" : width;
3245
+ ctx.document.apply((tree) => ctx.mutations.mutateField(tree, {
3246
+ id: fieldId,
3247
+ keyValuePairs: { "props.style": { width: next, maxWidth: "none" } }
3248
+ }));
3249
+ ctx.events.emit("image:setWidth", { fieldId, width: next });
3250
+ });
3251
+ ctx.ui.contribute(defineButton({
3252
+ id: "iframe-playback",
3253
+ slot: "toolbar",
3254
+ order: 70,
3255
+ kind: "button",
3256
+ icon: "PlayIcon",
3257
+ command: "iframe.playback",
3258
+ name: "IframePlaybackButton",
3259
+ label: "Play/Pause",
3260
+ getPayload: (ui4) => {
3261
+ const fieldId = selectedId(ui4);
3262
+ if (!fieldId)
3263
+ throw new Error("Empty selection...");
3264
+ return { fieldId, action: "play" };
3265
+ },
3266
+ getProps: () => ({}),
3267
+ when: (ui4) => {
3268
+ const fieldId = selectedId(ui4);
3269
+ if (!fieldId)
3270
+ return false;
3271
+ return isYouTubeIframe(ctx.document.getBlock(fieldId));
3272
+ }
3273
+ }));
3274
+ const widthButton = (id, icon, order, width) => ctx.ui.contribute(defineButton({
3275
+ id,
3276
+ slot: "toolbar",
3277
+ order,
3278
+ kind: "button",
3279
+ icon,
3280
+ command: "image.setWidth",
3281
+ name: "ImageWidthButton",
3282
+ label: `Width ${width}`,
3283
+ getPayload: (ui4) => {
3284
+ const fieldId = selectedId(ui4);
3285
+ if (!fieldId)
3286
+ throw new Error("Empty selection...");
3287
+ return { fieldId, width };
3288
+ },
3289
+ getProps: (ui4) => {
3290
+ const fieldId = selectedId(ui4);
3291
+ const block = fieldId ? ctx.document.getBlock(fieldId) : undefined;
3292
+ return { isActive: block?.props.style?.width === width };
3293
+ },
3294
+ when: (ui4) => {
3295
+ const fieldId = selectedId(ui4);
3296
+ if (!fieldId)
3297
+ return false;
3298
+ return ctx.document.getBlock(fieldId)?.type === "image";
3299
+ }
3300
+ }));
3301
+ widthButton("image-width-sm", "MoveHorizontalIcon", 80, IMAGE_WIDTHS.sm);
3302
+ widthButton("image-width-lg", "ExpandIcon", 81, IMAGE_WIDTHS.lg);
3303
+ }
3304
+ };
3305
+ // src/modules/divider/divider.module.ts
3306
+ var DIVIDER_STYLES = ["solid", "dashed", "dotted"];
3307
+ var DIVIDER_WIDTHS = {
3308
+ sm: "calc(100% - 100px)",
3309
+ lg: "calc(100% - 300px)"
3310
+ };
3311
+ var selectedId2 = (ui4) => {
3312
+ const blocks = ui4.selection?.blocks;
3313
+ if (!blocks || blocks.size !== 1)
3314
+ return null;
3315
+ return [...blocks.keys()][0];
3316
+ };
3317
+ var DividerModule = {
3318
+ name: "divider",
3319
+ version: "1.0.0",
3320
+ requires: [],
3321
+ install(ctx) {
3322
+ ctx.commands.register("divider.setWidth", ({ fieldId, width }) => {
3323
+ const block = ctx.document.getBlock(fieldId);
3324
+ if (!block || block.type !== "divider")
3325
+ return;
3326
+ const next = block.props.style?.width === width ? "100%" : width;
3327
+ ctx.document.apply((tree) => ctx.mutations.mutateField(tree, {
3328
+ id: fieldId,
3329
+ keyValuePairs: { "props.style": { width: next } }
3330
+ }));
3331
+ ctx.events.emit("divider:setWidth", { fieldId, width: next });
3332
+ });
3333
+ ctx.commands.register("divider.setStyle", ({ fieldId, style }) => {
3334
+ const block = ctx.document.getBlock(fieldId);
3335
+ if (!block || block.type !== "divider")
3336
+ return;
3337
+ ctx.document.apply((tree) => ctx.mutations.mutateField(tree, {
3338
+ id: fieldId,
3339
+ keyValuePairs: { "props.style": { borderTopStyle: style } }
3340
+ }));
3341
+ ctx.events.emit("divider:setStyle", { fieldId, style });
3342
+ });
3343
+ const widthButton = (id, icon, order, width) => ctx.ui.contribute(defineButton({
3344
+ id,
3345
+ slot: "toolbar",
3346
+ order,
3347
+ kind: "button",
3348
+ icon,
3349
+ command: "divider.setWidth",
3350
+ name: "DividerWidthButton",
3351
+ label: `Width ${width}`,
3352
+ getPayload: (ui4) => {
3353
+ const fieldId = selectedId2(ui4);
3354
+ if (!fieldId)
3355
+ throw new Error("Empty selection...");
3356
+ return { fieldId, width };
3357
+ },
3358
+ getProps: (ui4) => {
3359
+ const fieldId = selectedId2(ui4);
3360
+ const block = fieldId ? ctx.document.getBlock(fieldId) : undefined;
3361
+ return { isActive: block?.props.style?.width === width };
3362
+ },
3363
+ when: (ui4) => {
3364
+ const fieldId = selectedId2(ui4);
3365
+ if (!fieldId)
3366
+ return false;
3367
+ return ctx.document.getBlock(fieldId)?.type === "divider";
3147
3368
  }
3148
3369
  }));
3370
+ widthButton("divider-width-sm", "MoveHorizontalIcon", 90, DIVIDER_WIDTHS.sm);
3371
+ widthButton("divider-width-lg", "ExpandIcon", 91, DIVIDER_WIDTHS.lg);
3372
+ const styleButton = (id, order, borderStyle) => ctx.ui.contribute(defineButton({
3373
+ id,
3374
+ slot: "toolbar",
3375
+ order,
3376
+ kind: "button",
3377
+ icon: "LineStyleIcon",
3378
+ command: "divider.setStyle",
3379
+ name: "DividerStyleButton",
3380
+ label: `Style ${borderStyle}`,
3381
+ getPayload: (ui4) => {
3382
+ const fieldId = selectedId2(ui4);
3383
+ if (!fieldId)
3384
+ throw new Error("Empty selection...");
3385
+ return { fieldId, style: borderStyle };
3386
+ },
3387
+ getProps: (ui4) => {
3388
+ const fieldId = selectedId2(ui4);
3389
+ const block = fieldId ? ctx.document.getBlock(fieldId) : undefined;
3390
+ const current = block?.props.style?.borderTopStyle ?? "solid";
3391
+ return { isActive: current === borderStyle, borderStyle };
3392
+ },
3393
+ when: (ui4) => {
3394
+ const fieldId = selectedId2(ui4);
3395
+ if (!fieldId)
3396
+ return false;
3397
+ return ctx.document.getBlock(fieldId)?.type === "divider";
3398
+ }
3399
+ }));
3400
+ DIVIDER_STYLES.forEach((borderStyle, index) => {
3401
+ styleButton(`divider-style-${borderStyle}`, 92 + index, borderStyle);
3402
+ });
3403
+ }
3404
+ };
3405
+ // src/modules/paragraph-theme/paragraph-theme.module.ts
3406
+ var PARAGRAPH_THEMES = [
3407
+ "neutral",
3408
+ "warning",
3409
+ "error",
3410
+ "info"
3411
+ ];
3412
+ var THEME_ICONS = {
3413
+ neutral: "ThemeNeutralIcon",
3414
+ warning: "ThemeWarningIcon",
3415
+ error: "ThemeErrorIcon",
3416
+ info: "ThemeInfoIcon"
3417
+ };
3418
+ var PARAGRAPH_THEME_STYLES = {
3419
+ neutral: { backgroundColor: "var(--card)", color: "var(--muted-foreground)" },
3420
+ warning: { backgroundColor: "rgba(245, 158, 11, 0.05)", color: "rgb(180, 83, 9)" },
3421
+ error: { backgroundColor: "rgba(244, 63, 94, 0.05)", color: "rgb(190, 18, 60)" },
3422
+ info: { backgroundColor: "rgba(59, 130, 246, 0.05)", color: "rgb(29, 78, 216)" }
3423
+ };
3424
+ var getParagraphTheme = (content) => {
3425
+ const len = content.text.length;
3426
+ const mark = content.marks.find((m) => m.type === "theme" && m.start === 0 && m.end === len);
3427
+ if (!mark)
3428
+ return null;
3429
+ return mark.attrs?.["data-theme"] ?? null;
3430
+ };
3431
+ var ParagraphThemeModule = {
3432
+ name: "paragraph-theme",
3433
+ version: "1.0.0",
3434
+ requires: [],
3435
+ install(ctx) {
3436
+ ctx.text.registerMark("theme", { inclusive: true });
3437
+ const selectedId3 = (ui4) => {
3438
+ const blocks = ui4.selection?.blocks;
3439
+ if (!blocks || blocks.size !== 1)
3440
+ return null;
3441
+ const id = [...blocks.keys()][0];
3442
+ const type = ctx.document.getBlock(id)?.type;
3443
+ return type === "text" || type === "sub-heading" ? id : null;
3444
+ };
3445
+ ctx.commands.register("paragraph.setTheme", ({ fieldId, theme }) => {
3446
+ const block = ctx.document.getBlock(fieldId);
3447
+ if (!block || block.type !== "text" && block.type !== "sub-heading")
3448
+ return;
3449
+ const content = block.props.children;
3450
+ const len = content.text.length;
3451
+ if (len === 0)
3452
+ return;
3453
+ const isToggleOff = getParagraphTheme(content) === theme;
3454
+ const others = content.marks.filter((m) => m.type !== "theme");
3455
+ const marks = isToggleOff ? others : [
3456
+ ...others,
3457
+ {
3458
+ type: "theme",
3459
+ start: 0,
3460
+ end: len,
3461
+ attrs: {
3462
+ "data-theme": theme,
3463
+ style: {
3464
+ ...PARAGRAPH_THEME_STYLES[theme],
3465
+ height: "100%",
3466
+ display: "block",
3467
+ borderRadius: 12,
3468
+ paddingInline: 16,
3469
+ paddingBlock: 12,
3470
+ whiteSpace: "pre-wrap",
3471
+ lineHeight: 1.5
3472
+ }
3473
+ }
3474
+ }
3475
+ ];
3476
+ ctx.document.apply((tree) => ctx.mutations.mutateField(tree, {
3477
+ id: fieldId,
3478
+ keyValuePairs: { ["props.children"]: { text: content.text, marks } },
3479
+ autoMerge: false
3480
+ }));
3481
+ ctx.events.emit("paragraph:setTheme", { fieldId, theme });
3482
+ });
3483
+ const themeButton = (id, order, theme) => ctx.ui.contribute(defineButton({
3484
+ id,
3485
+ slot: "toolbar",
3486
+ order,
3487
+ kind: "button",
3488
+ icon: THEME_ICONS[theme],
3489
+ command: "paragraph.setTheme",
3490
+ name: "ParagraphThemeButton",
3491
+ label: `Theme ${theme}`,
3492
+ getPayload: (ui4) => {
3493
+ const fieldId = selectedId3(ui4);
3494
+ if (!fieldId)
3495
+ throw new Error("Empty selection...");
3496
+ return { fieldId, theme };
3497
+ },
3498
+ getProps: (ui4) => {
3499
+ const fieldId = selectedId3(ui4);
3500
+ const block = fieldId ? ctx.document.getBlock(fieldId) : undefined;
3501
+ const isActive = !!block && getParagraphTheme(block.props.children) === theme;
3502
+ return { isActive, theme };
3503
+ },
3504
+ when: (ui4) => selectedId3(ui4) !== null
3505
+ }));
3506
+ PARAGRAPH_THEMES.forEach((theme, index) => {
3507
+ themeButton(`paragraph-theme-${theme}`, 60 + index, theme);
3508
+ });
3149
3509
  }
3150
3510
  };
3151
3511
  // src/modules/deletion/deletion.module.ts
@@ -3195,12 +3555,14 @@ export {
3195
3555
  isMediaField,
3196
3556
  isEditableType,
3197
3557
  isEditableField,
3558
+ getParagraphTheme,
3198
3559
  getIframeSrc,
3199
3560
  getCollectedStyles,
3200
3561
  defineComponent,
3201
3562
  defineButton,
3202
3563
  coraxTreeDiffing,
3203
3564
  hash as coraxStyleHash,
3565
+ compareDocumentVersion,
3204
3566
  collectCoraxPseudoStyle,
3205
3567
  clearCollectedStyles,
3206
3568
  areObjectsTheSame,
@@ -3218,11 +3580,14 @@ export {
3218
3580
  StateError,
3219
3581
  SerializeTree,
3220
3582
  SelectionModule,
3583
+ ParagraphThemeModule,
3584
+ PARAGRAPH_THEME_STYLES,
3221
3585
  MutationsService,
3222
3586
  MutationPrototypeError,
3223
3587
  MutationError,
3224
3588
  ModuleUtils,
3225
3589
  ModuleManager,
3590
+ MediaModule,
3226
3591
  InsertionModule,
3227
3592
  HoverModule,
3228
3593
  HistoryModule,
@@ -3234,6 +3599,7 @@ export {
3234
3599
  Engine,
3235
3600
  EditorModule,
3236
3601
  DocumentService,
3602
+ DividerModule,
3237
3603
  DeserializeTree,
3238
3604
  DeletionModule,
3239
3605
  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";