@portabletext/editor 1.19.0 → 1.21.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.
Files changed (132) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +8 -68
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs +11 -39
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +1 -1
  6. package/lib/_chunks-cjs/util.get-block-start-point.cjs +30 -0
  7. package/lib/_chunks-cjs/util.get-block-start-point.cjs.map +1 -0
  8. package/lib/_chunks-cjs/util.is-empty-text-block.cjs +71 -0
  9. package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -0
  10. package/lib/_chunks-cjs/util.is-keyed-segment.cjs +6 -0
  11. package/lib/_chunks-cjs/util.is-keyed-segment.cjs.map +1 -0
  12. package/lib/_chunks-es/behavior.core.js +7 -66
  13. package/lib/_chunks-es/behavior.core.js.map +1 -1
  14. package/lib/_chunks-es/selector.get-text-before.js +5 -31
  15. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  16. package/lib/_chunks-es/selector.is-selection-collapsed.js.map +1 -1
  17. package/lib/_chunks-es/util.get-block-start-point.js +31 -0
  18. package/lib/_chunks-es/util.get-block-start-point.js.map +1 -0
  19. package/lib/_chunks-es/util.is-empty-text-block.js +73 -0
  20. package/lib/_chunks-es/util.is-empty-text-block.js.map +1 -0
  21. package/lib/_chunks-es/util.is-keyed-segment.js +7 -0
  22. package/lib/_chunks-es/util.is-keyed-segment.js.map +1 -0
  23. package/lib/behaviors/index.cjs +7 -7
  24. package/lib/behaviors/index.cjs.map +1 -1
  25. package/lib/behaviors/index.d.cts +179 -119
  26. package/lib/behaviors/index.d.ts +179 -119
  27. package/lib/behaviors/index.js +3 -2
  28. package/lib/behaviors/index.js.map +1 -1
  29. package/lib/index.cjs +72 -177
  30. package/lib/index.cjs.map +1 -1
  31. package/lib/index.d.cts +1061 -140
  32. package/lib/index.d.ts +1061 -140
  33. package/lib/index.js +72 -177
  34. package/lib/index.js.map +1 -1
  35. package/lib/selectors/index.cjs +73 -1
  36. package/lib/selectors/index.cjs.map +1 -1
  37. package/lib/selectors/index.d.cts +14 -0
  38. package/lib/selectors/index.d.ts +14 -0
  39. package/lib/selectors/index.js +73 -0
  40. package/lib/selectors/index.js.map +1 -1
  41. package/lib/utils/index.cjs +11 -0
  42. package/lib/utils/index.cjs.map +1 -0
  43. package/lib/utils/index.d.cts +87 -0
  44. package/lib/utils/index.d.ts +87 -0
  45. package/lib/utils/index.js +13 -0
  46. package/lib/utils/index.js.map +1 -0
  47. package/package.json +18 -14
  48. package/src/behavior-actions/behavior.action-utils.insert-block.ts +1 -1
  49. package/src/behavior-actions/behavior.action.insert-block-object.ts +1 -1
  50. package/src/behavior-actions/behavior.action.insert-inline-object.ts +1 -1
  51. package/src/behavior-actions/behavior.action.text-block.set.ts +1 -1
  52. package/src/behavior-actions/behavior.action.text-block.unset.ts +1 -1
  53. package/src/behavior-actions/behavior.actions.ts +5 -5
  54. package/src/behaviors/behavior.code-editor.ts +1 -1
  55. package/src/behaviors/behavior.core.block-objects.ts +2 -2
  56. package/src/behaviors/behavior.core.decorators.ts +1 -1
  57. package/src/behaviors/behavior.core.lists.ts +2 -2
  58. package/src/behaviors/behavior.emoji-picker.ts +1 -1
  59. package/src/behaviors/behavior.links.ts +1 -1
  60. package/src/behaviors/behavior.markdown.ts +2 -2
  61. package/src/behaviors/behavior.types.ts +52 -19
  62. package/src/behaviors/index.ts +1 -0
  63. package/src/editor/Editable.tsx +12 -12
  64. package/src/editor/PortableTextEditor.tsx +2 -2
  65. package/src/editor/components/DraggableBlock.tsx +2 -2
  66. package/src/editor/components/Element.tsx +20 -26
  67. package/src/editor/components/Leaf.tsx +1 -1
  68. package/src/editor/components/Synchronizer.tsx +1 -1
  69. package/src/editor/create-editor.ts +39 -20
  70. package/src/editor/create-slate-editor.tsx +5 -2
  71. package/src/editor/editor-machine.ts +72 -18
  72. package/src/editor/get-value.ts +2 -2
  73. package/src/editor/hooks/usePortableTextEditorSelection.tsx +1 -1
  74. package/src/editor/mutation-machine.ts +2 -2
  75. package/src/editor/nodes/DefaultObject.tsx +2 -2
  76. package/src/editor/plugins/create-with-event-listeners.ts +11 -3
  77. package/src/editor/plugins/createWithEditableAPI.ts +7 -7
  78. package/src/editor/plugins/createWithHotKeys.ts +2 -2
  79. package/src/editor/plugins/createWithInsertData.ts +7 -7
  80. package/src/editor/plugins/createWithMaxBlocks.ts +2 -2
  81. package/src/editor/plugins/createWithObjectKeys.ts +2 -2
  82. package/src/editor/plugins/createWithPatches.ts +10 -10
  83. package/src/editor/plugins/createWithPlaceholderBlock.ts +3 -3
  84. package/src/editor/plugins/createWithPortableTextBlockStyle.ts +1 -1
  85. package/src/editor/plugins/createWithPortableTextMarkModel.ts +4 -4
  86. package/src/editor/plugins/createWithPortableTextSelections.ts +6 -6
  87. package/src/editor/plugins/createWithSchemaTypes.ts +1 -1
  88. package/src/editor/plugins/createWithUndoRedo.ts +5 -5
  89. package/src/editor/plugins/createWithUtils.ts +2 -2
  90. package/src/editor/plugins/with-plugins.ts +1 -1
  91. package/src/editor/sync-machine.ts +8 -5
  92. package/src/index.ts +5 -1
  93. package/src/selectors/index.ts +2 -0
  94. package/src/selectors/selector.get-selection-text.test.ts +75 -0
  95. package/src/selectors/selector.get-selection-text.ts +3 -3
  96. package/src/selectors/selector.get-text-before.ts +7 -4
  97. package/src/selectors/selector.is-point-after-selection.ts +82 -0
  98. package/src/selectors/selector.is-point-before-selection.ts +82 -0
  99. package/src/utils/_exports/index.ts +1 -0
  100. package/src/utils/index.ts +11 -0
  101. package/src/{editor/utils/utils.block-offset.test.ts → utils/util.block-offset.test.ts} +1 -1
  102. package/src/{editor/utils/utils.block-offset.ts → utils/util.block-offset.ts} +23 -7
  103. package/src/{editor/utils/utils.get-start-point.ts → utils/util.get-block-start-point.ts} +5 -2
  104. package/src/utils/util.get-text-block-text.ts +8 -0
  105. package/src/{editor/utils/utils.ts → utils/util.is-empty-text-block.ts} +4 -5
  106. package/src/{editor/utils/utils.is-keyed-segment.ts → utils/util.is-keyed-segment.ts} +3 -0
  107. package/src/{editor/utils/utils.reverse-selection.ts → utils/util.reverse-selection.ts} +4 -1
  108. package/src/editor/nodes/index.ts +0 -189
  109. /package/src/{utils → internal-utils}/__tests__/dmpToOperations.test.ts +0 -0
  110. /package/src/{utils → internal-utils}/__tests__/operationToPatches.test.ts +0 -0
  111. /package/src/{utils → internal-utils}/__tests__/patchToOperations.test.ts +0 -0
  112. /package/src/{utils → internal-utils}/__tests__/ranges.test.ts +0 -0
  113. /package/src/{utils → internal-utils}/__tests__/valueNormalization.test.tsx +0 -0
  114. /package/src/{utils → internal-utils}/__tests__/values.test.ts +0 -0
  115. /package/src/{utils → internal-utils}/applyPatch.ts +0 -0
  116. /package/src/{utils → internal-utils}/debug.ts +0 -0
  117. /package/src/{utils → internal-utils}/is-hotkey.test.ts +0 -0
  118. /package/src/{utils → internal-utils}/is-hotkey.ts +0 -0
  119. /package/src/{utils → internal-utils}/looks-like-url.test.ts +0 -0
  120. /package/src/{utils → internal-utils}/looks-like-url.ts +0 -0
  121. /package/src/{utils → internal-utils}/operationToPatches.ts +0 -0
  122. /package/src/{utils → internal-utils}/paths.ts +0 -0
  123. /package/src/{utils → internal-utils}/ranges.ts +0 -0
  124. /package/src/{utils → internal-utils}/schema.ts +0 -0
  125. /package/src/{utils → internal-utils}/selection.ts +0 -0
  126. /package/src/{utils → internal-utils}/sibling-utils.ts +0 -0
  127. /package/src/{utils → internal-utils}/validateValue.ts +0 -0
  128. /package/src/{utils → internal-utils}/values.ts +0 -0
  129. /package/src/{utils → internal-utils}/weakMaps.ts +0 -0
  130. /package/src/{utils → internal-utils}/withChanges.ts +0 -0
  131. /package/src/{utils → internal-utils}/withUndoRedo.ts +0 -0
  132. /package/src/{utils → internal-utils}/withoutPatching.ts +0 -0
@@ -1,7 +1,7 @@
1
1
  import {isPortableTextSpan, isPortableTextTextBlock} from '@sanity/types'
2
2
  import type {EditorSelector} from '../editor/editor-selector'
3
- import {isKeyedSegment} from '../editor/utils/utils.is-keyed-segment'
4
- import {reverseSelection} from '../editor/utils/utils.reverse-selection'
3
+ import {isKeyedSegment} from '../utils/util.is-keyed-segment'
4
+ import {reverseSelection} from '../utils/util.reverse-selection'
5
5
 
6
6
  /**
7
7
  * @public
@@ -70,7 +70,7 @@ export const getSelectionText: EditorSelector<string> = ({context}) => {
70
70
  }
71
71
 
72
72
  if (text.length > 0) {
73
- text + child.text
73
+ text = text + child.text
74
74
  }
75
75
  }
76
76
  }
@@ -1,7 +1,7 @@
1
1
  import type {EditorSelector} from '../editor/editor-selector'
2
- import {getStartPoint} from '../editor/utils/utils.get-start-point'
3
- import {isKeyedSegment} from '../editor/utils/utils.is-keyed-segment'
4
- import {reverseSelection} from '../editor/utils/utils.reverse-selection'
2
+ import {getBlockStartPoint} from '../utils/util.get-block-start-point'
3
+ import {isKeyedSegment} from '../utils/util.is-keyed-segment'
4
+ import {reverseSelection} from '../utils/util.reverse-selection'
5
5
  import {getSelectionText} from './selector.get-selection-text'
6
6
 
7
7
  /**
@@ -26,7 +26,10 @@ export const getBlockTextBefore: EditorSelector<string> = ({context}) => {
26
26
  return ''
27
27
  }
28
28
 
29
- const startOfBlock = getStartPoint({node: block, path: [{_key: block._key}]})
29
+ const startOfBlock = getBlockStartPoint({
30
+ node: block,
31
+ path: [{_key: block._key}],
32
+ })
30
33
 
31
34
  return getSelectionText({
32
35
  context: {
@@ -0,0 +1,82 @@
1
+ import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'
2
+ import type {EditorSelector} from '../editor/editor-selector'
3
+ import type {EditorSelectionPoint} from '../types/editor'
4
+ import {reverseSelection} from '../utils/util.reverse-selection'
5
+
6
+ /**
7
+ * @public
8
+ */
9
+ export function isPointAfterSelection(
10
+ point: EditorSelectionPoint,
11
+ ): EditorSelector<boolean> {
12
+ return (snapshot) => {
13
+ if (!snapshot.context.selection) {
14
+ return false
15
+ }
16
+
17
+ const selection = reverseSelection(snapshot.context.selection)
18
+
19
+ const pointBlockKey = isKeySegment(point.path[0])
20
+ ? point.path[0]._key
21
+ : undefined
22
+ const pointChildKey = isKeySegment(point.path[2])
23
+ ? point.path[2]._key
24
+ : undefined
25
+
26
+ const endBlockKey = isKeySegment(selection.focus.path[0])
27
+ ? selection.focus.path[0]._key
28
+ : undefined
29
+ const endChildKey = isKeySegment(selection.focus.path[2])
30
+ ? selection.focus.path[2]._key
31
+ : undefined
32
+
33
+ if (!pointBlockKey || !endBlockKey) {
34
+ return false
35
+ }
36
+
37
+ let after = false
38
+
39
+ for (const block of snapshot.context.value) {
40
+ if (block._key === endBlockKey) {
41
+ if (block._key !== pointBlockKey) {
42
+ after = true
43
+ break
44
+ }
45
+
46
+ // Both the point and the selection end in this block
47
+
48
+ if (!isPortableTextTextBlock(block)) {
49
+ break
50
+ }
51
+
52
+ if (!pointChildKey || !endChildKey) {
53
+ break
54
+ }
55
+
56
+ for (const child of block.children) {
57
+ if (child._key === endChildKey) {
58
+ if (child._key !== pointChildKey) {
59
+ after = true
60
+ break
61
+ }
62
+
63
+ // Both the point and the selection end in this child
64
+
65
+ after = point.offset > selection.focus.offset
66
+ break
67
+ }
68
+
69
+ if (child._key === pointChildKey) {
70
+ break
71
+ }
72
+ }
73
+ }
74
+
75
+ if (block._key === pointBlockKey) {
76
+ break
77
+ }
78
+ }
79
+
80
+ return after
81
+ }
82
+ }
@@ -0,0 +1,82 @@
1
+ import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'
2
+ import type {EditorSelector} from '../editor/editor-selector'
3
+ import type {EditorSelectionPoint} from '../types/editor'
4
+ import {reverseSelection} from '../utils/util.reverse-selection'
5
+
6
+ /**
7
+ * @public
8
+ */
9
+ export function isPointBeforeSelection(
10
+ point: EditorSelectionPoint,
11
+ ): EditorSelector<boolean> {
12
+ return (snapshot) => {
13
+ if (!snapshot.context.selection) {
14
+ return false
15
+ }
16
+
17
+ const selection = reverseSelection(snapshot.context.selection)
18
+
19
+ const pointBlockKey = isKeySegment(point.path[0])
20
+ ? point.path[0]._key
21
+ : undefined
22
+ const pointChildKey = isKeySegment(point.path[2])
23
+ ? point.path[2]._key
24
+ : undefined
25
+
26
+ const startBlockKey = isKeySegment(selection.anchor.path[0])
27
+ ? selection.anchor.path[0]._key
28
+ : undefined
29
+ const startChildKey = isKeySegment(selection.anchor.path[2])
30
+ ? selection.anchor.path[2]._key
31
+ : undefined
32
+
33
+ if (!pointBlockKey || !startBlockKey) {
34
+ return false
35
+ }
36
+
37
+ let before = false
38
+
39
+ for (const block of snapshot.context.value) {
40
+ if (block._key === pointBlockKey) {
41
+ if (block._key !== startBlockKey) {
42
+ before = true
43
+ break
44
+ }
45
+
46
+ // Both the point and the selection start in this block
47
+
48
+ if (!isPortableTextTextBlock(block)) {
49
+ break
50
+ }
51
+
52
+ if (!pointChildKey || !startChildKey) {
53
+ break
54
+ }
55
+
56
+ for (const child of block.children) {
57
+ if (child._key === pointChildKey) {
58
+ if (child._key !== startChildKey) {
59
+ before = true
60
+ break
61
+ }
62
+
63
+ // Both the point and the selection start in this child
64
+
65
+ before = point.offset < selection.anchor.offset
66
+ break
67
+ }
68
+
69
+ if (child._key === startChildKey) {
70
+ break
71
+ }
72
+ }
73
+ }
74
+
75
+ if (block._key === startBlockKey) {
76
+ break
77
+ }
78
+ }
79
+
80
+ return before
81
+ }
82
+ }
@@ -0,0 +1 @@
1
+ export * from '../index'
@@ -0,0 +1,11 @@
1
+ export type {BlockOffset} from '../behaviors/behavior.types'
2
+ export type {EditorSelection, EditorSelectionPoint} from '../types/editor'
3
+ export {
4
+ blockOffsetToSpanSelectionPoint,
5
+ spanSelectionPointToBlockOffset,
6
+ } from './util.block-offset'
7
+ export {getBlockStartPoint} from './util.get-block-start-point'
8
+ export {getTextBlockText} from './util.get-text-block-text'
9
+ export {isEmptyTextBlock} from './util.is-empty-text-block'
10
+ export {isKeyedSegment} from './util.is-keyed-segment'
11
+ export {reverseSelection} from './util.reverse-selection'
@@ -1,6 +1,6 @@
1
1
  import type {PortableTextBlock} from '@sanity/types'
2
2
  import {expect, test} from 'vitest'
3
- import {blockOffsetToSpanSelectionPoint} from './utils.block-offset'
3
+ import {blockOffsetToSpanSelectionPoint} from './util.block-offset'
4
4
 
5
5
  test(blockOffsetToSpanSelectionPoint.name, () => {
6
6
  const value: Array<PortableTextBlock> = [
@@ -4,8 +4,13 @@ import {
4
4
  type KeyedSegment,
5
5
  type PortableTextBlock,
6
6
  } from '@sanity/types'
7
- import type {BlockOffset} from '../../behaviors/behavior.types'
7
+ import type {BlockOffset} from '../behaviors/behavior.types'
8
+ import type {EditorSelectionPoint} from '../types/editor'
9
+ import {isKeyedSegment} from './util.is-keyed-segment'
8
10
 
11
+ /**
12
+ * @public
13
+ */
9
14
  export function blockOffsetToSpanSelectionPoint({
10
15
  value,
11
16
  blockOffset,
@@ -55,20 +60,31 @@ export function blockOffsetToSpanSelectionPoint({
55
60
  return selectionPoint
56
61
  }
57
62
 
63
+ /**
64
+ * @public
65
+ */
58
66
  export function spanSelectionPointToBlockOffset({
59
67
  value,
60
68
  selectionPoint,
61
69
  }: {
62
70
  value: Array<PortableTextBlock>
63
- selectionPoint: {
64
- path: [KeyedSegment, 'children', KeyedSegment]
65
- offset: number
66
- }
71
+ selectionPoint: EditorSelectionPoint
67
72
  }): BlockOffset | undefined {
68
73
  let offset = 0
69
74
 
75
+ const blockKey = isKeyedSegment(selectionPoint.path[0])
76
+ ? selectionPoint.path[0]._key
77
+ : undefined
78
+ const spanKey = isKeyedSegment(selectionPoint.path[2])
79
+ ? selectionPoint.path[2]._key
80
+ : undefined
81
+
82
+ if (!blockKey || !spanKey) {
83
+ return undefined
84
+ }
85
+
70
86
  for (const block of value) {
71
- if (block._key !== selectionPoint.path[0]._key) {
87
+ if (block._key !== blockKey) {
72
88
  continue
73
89
  }
74
90
 
@@ -81,7 +97,7 @@ export function spanSelectionPointToBlockOffset({
81
97
  continue
82
98
  }
83
99
 
84
- if (child._key === selectionPoint.path[2]._key) {
100
+ if (child._key === spanKey) {
85
101
  return {
86
102
  path: [{_key: block._key}],
87
103
  offset: offset + selectionPoint.offset,
@@ -3,9 +3,12 @@ import {
3
3
  type KeyedSegment,
4
4
  type PortableTextBlock,
5
5
  } from '@sanity/types'
6
- import type {EditorSelectionPoint} from '../../types/editor'
6
+ import type {EditorSelectionPoint} from '../types/editor'
7
7
 
8
- export function getStartPoint({
8
+ /**
9
+ * @public
10
+ */
11
+ export function getBlockStartPoint({
9
12
  node,
10
13
  path,
11
14
  }: {
@@ -0,0 +1,8 @@
1
+ import type {PortableTextTextBlock} from '@sanity/types'
2
+
3
+ /**
4
+ * @public
5
+ */
6
+ export function getTextBlockText(block: PortableTextTextBlock) {
7
+ return block.children.map((child) => child.text ?? '').join('')
8
+ }
@@ -2,9 +2,12 @@ import {
2
2
  isPortableTextSpan,
3
3
  isPortableTextTextBlock,
4
4
  type PortableTextBlock,
5
- type PortableTextTextBlock,
6
5
  } from '@sanity/types'
6
+ import {getTextBlockText} from './util.get-text-block-text'
7
7
 
8
+ /**
9
+ * @public
10
+ */
8
11
  export function isEmptyTextBlock(block: PortableTextBlock) {
9
12
  if (!isPortableTextTextBlock(block)) {
10
13
  return false
@@ -15,7 +18,3 @@ export function isEmptyTextBlock(block: PortableTextBlock) {
15
18
 
16
19
  return onlyText && blockText === ''
17
20
  }
18
-
19
- export function getTextBlockText(block: PortableTextTextBlock) {
20
- return block.children.map((child) => child.text ?? '').join('')
21
- }
@@ -1,5 +1,8 @@
1
1
  import type {KeyedSegment, PathSegment} from '@sanity/types'
2
2
 
3
+ /**
4
+ * @public
5
+ */
3
6
  export function isKeyedSegment(segment: PathSegment): segment is KeyedSegment {
4
7
  return typeof segment === 'object' && segment !== null && '_key' in segment
5
8
  }
@@ -1,5 +1,8 @@
1
- import type {EditorSelection} from '../../types/editor'
1
+ import type {EditorSelection} from '../types/editor'
2
2
 
3
+ /**
4
+ * @public
5
+ */
3
6
  export function reverseSelection(
4
7
  selection: NonNullable<EditorSelection>,
5
8
  ): NonNullable<EditorSelection> {
@@ -1,189 +0,0 @@
1
- import {styled} from 'styled-components'
2
-
3
- export const DefaultBlockObject = styled.div<{selected: boolean}>`
4
- user-select: none;
5
- border: ${(props) => {
6
- if (props.selected) {
7
- return '1px solid blue'
8
- }
9
- return '1px solid transparent'
10
- }};
11
- `
12
-
13
- export const DefaultInlineObject = styled.span<{selected: boolean}>`
14
- background: #999;
15
- border: ${(props) => {
16
- if (props.selected) {
17
- return '1px solid blue'
18
- }
19
- return '1px solid transparent'
20
- }};
21
- `
22
-
23
- type ListItemProps = {listLevel: number; listStyle: string}
24
-
25
- export const DefaultListItem = styled.div<ListItemProps>`
26
- &.pt-list-item {
27
- width: fit-content;
28
- position: relative;
29
- display: block;
30
-
31
- /* Important 'transform' in order to force refresh the ::before and ::after rules
32
- in Webkit: https://stackoverflow.com/a/21947628/831480
33
- */
34
- transform: translateZ(0);
35
- margin-left: ${(props: ListItemProps) => getLeftPositionForListLevel(props.listLevel)};
36
- }
37
- &.pt-list-item > .pt-list-item-inner {
38
- display: flex;
39
- margin: 0;
40
- padding: 0;
41
- &:before {
42
- justify-content: flex-start;
43
- vertical-align: top;
44
- }
45
- }
46
- &.pt-list-item-bullet > .pt-list-item-inner:before {
47
- content: '${(props: ListItemProps) =>
48
- getContentForListLevelAndStyle(props.listLevel, props.listStyle)}';
49
- font-size: 0.4375rem; /* 7px */
50
- line-height: 1.5rem; /* Same as body text */
51
- /* Optical alignment */
52
- position: relative;
53
- }
54
- }
55
- &.pt-list-item-bullet > .pt-list-item-inner {
56
- &:before {
57
- min-width: 1.5rem; /* Make sure space between bullet and text never shrinks */
58
- }
59
- }
60
- &.pt-list-item-number {
61
- counter-increment: ${(props: {listLevel: number}) =>
62
- getCounterIncrementForListLevel(props.listLevel)};
63
- counter-reset: ${(props: {listLevel: number}) => getCounterResetForListLevel(props.listLevel)};
64
- }
65
- & + :not(.pt-list-item-number) {
66
- counter-reset: listItemNumber;
67
- }
68
- &.pt-list-item-number > .pt-list-item-inner:before {
69
- content: ${(props) => getCounterContentForListLevel(props.listLevel)};
70
- min-width: 1.5rem; /* Make sure space between number and text never shrinks */
71
- /* Optical alignment */
72
- position: relative;
73
- top: 1px;
74
- }
75
- `
76
-
77
- export const DefaultListItemInner = styled.div``
78
-
79
- function getLeftPositionForListLevel(level: number) {
80
- switch (Number(level)) {
81
- case 1:
82
- return '1.5em'
83
- case 2:
84
- return '3em'
85
- case 3:
86
- return '4.5em'
87
- case 4:
88
- return '6em'
89
- case 5:
90
- return '7.5em'
91
- case 6:
92
- return '9em'
93
- case 7:
94
- return '10.5em'
95
- case 8:
96
- return '12em'
97
- case 9:
98
- return '13.5em'
99
- case 10:
100
- return '15em'
101
- default:
102
- return '0em'
103
- }
104
- }
105
-
106
- const bullets = ['●', '○', '■']
107
-
108
- function getContentForListLevelAndStyle(level: number, style: string) {
109
- const normalizedLevel = (level - 1) % 3
110
- if (style === 'bullet') {
111
- return bullets[normalizedLevel]
112
- }
113
- return '*'
114
- }
115
-
116
- function getCounterIncrementForListLevel(level: number) {
117
- switch (level) {
118
- case 1:
119
- return 'listItemNumber'
120
- case 2:
121
- return 'listItemAlpha'
122
- case 3:
123
- return 'listItemRoman'
124
- case 4:
125
- return 'listItemNumberNext'
126
- case 5:
127
- return 'listItemLetterNext'
128
- case 6:
129
- return 'listItemRomanNext'
130
- case 7:
131
- return 'listItemNumberNextNext'
132
- case 8:
133
- return 'listItemAlphaNextNext'
134
- case 9:
135
- return 'listItemRomanNextNext'
136
- default:
137
- return 'listItemNumberNextNextNext'
138
- }
139
- }
140
-
141
- function getCounterResetForListLevel(level: number) {
142
- switch (level) {
143
- case 1:
144
- return 'listItemAlpha'
145
- case 2:
146
- return 'listItemRoman'
147
- case 3:
148
- return 'listItemNumberNext'
149
- case 4:
150
- return 'listItemLetterNext'
151
- case 5:
152
- return 'listItemRomanNext'
153
- case 6:
154
- return 'listItemNumberNextNext'
155
- case 7:
156
- return 'listItemAlphaNextNext'
157
- case 8:
158
- return 'listItemRomanNextNext'
159
- case 9:
160
- return 'listItemNumberNextNextNext'
161
- default:
162
- return 'listItemNumberNextNextNext'
163
- }
164
- }
165
-
166
- function getCounterContentForListLevel(level: number) {
167
- switch (level) {
168
- case 1:
169
- return `counter(listItemNumber) '. '`
170
- case 2:
171
- return `counter(listItemAlpha, lower-alpha) '. '`
172
- case 3:
173
- return `counter(listItemRoman, lower-roman) '. '`
174
- case 4:
175
- return `counter(listItemNumberNext) '. '`
176
- case 5:
177
- return `counter(listItemLetterNext, lower-alpha) '. '`
178
- case 6:
179
- return `counter(listItemRomanNext, lower-roman) '. '`
180
- case 7:
181
- return `counter(listItemNumberNextNext) '. '`
182
- case 8:
183
- return `counter(listItemAlphaNextNext, lower-alpha) '. '`
184
- case 9:
185
- return `counter(listItemRomanNextNext, lower-roman) '. '`
186
- default:
187
- return `counter(listItemNumberNextNextNext) '. '`
188
- }
189
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes