@pcg/dynamic-components 1.0.0-alpha.2 → 1.0.0-alpha.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 (61) hide show
  1. package/dist/index.d.ts +6 -6
  2. package/dist/index.js +52 -52
  3. package/dist/index.js.map +1 -1
  4. package/package.json +15 -3
  5. package/.turbo/turbo-build.log +0 -16
  6. package/CHANGELOG.md +0 -24
  7. package/eslint.config.cjs +0 -14
  8. package/src/assertions/basic.ts +0 -7
  9. package/src/assertions/containers.ts +0 -8
  10. package/src/assertions/index.ts +0 -6
  11. package/src/assertions/paths.ts +0 -12
  12. package/src/assertions/rich-text.ts +0 -16
  13. package/src/assertions/yjs.ts +0 -25
  14. package/src/data-objects/data-object.ts +0 -34
  15. package/src/data-objects/index.ts +0 -3
  16. package/src/data-objects/rich-text.ts +0 -38
  17. package/src/dynamic-components/fractional-indexing.ts +0 -321
  18. package/src/dynamic-components/index.ts +0 -6
  19. package/src/dynamic-components/paths.ts +0 -194
  20. package/src/dynamic-components/registry/chats.ts +0 -24
  21. package/src/dynamic-components/registry/content.ts +0 -118
  22. package/src/dynamic-components/registry/forms.ts +0 -525
  23. package/src/dynamic-components/registry/index.ts +0 -6
  24. package/src/dynamic-components/registry/layout.ts +0 -86
  25. package/src/dynamic-components/registry/uikit-dynamic-component.ts +0 -84
  26. package/src/dynamic-components/tools.ts +0 -195
  27. package/src/dynamic-components/types.ts +0 -237
  28. package/src/index.ts +0 -7
  29. package/src/paths/array-keys.ts +0 -164
  30. package/src/paths/array-ops.ts +0 -124
  31. package/src/paths/basic-ops.ts +0 -181
  32. package/src/paths/constants.ts +0 -1
  33. package/src/paths/index.ts +0 -7
  34. package/src/paths/tools.ts +0 -42
  35. package/src/paths/types.ts +0 -133
  36. package/src/y-components/index.ts +0 -3
  37. package/src/y-components/tools.ts +0 -234
  38. package/src/y-components/types.ts +0 -19
  39. package/src/y-tools/array-path-ops.ts +0 -240
  40. package/src/y-tools/basic-path-ops.ts +0 -189
  41. package/src/y-tools/index.ts +0 -6
  42. package/src/y-tools/tools.ts +0 -122
  43. package/src/y-tools/types.ts +0 -32
  44. package/src/y-tools/y-array-keys.ts +0 -47
  45. package/tests/assertions/basic-types.test.ts +0 -78
  46. package/tests/assertions/containers.test.ts +0 -72
  47. package/tests/assertions/paths.test.ts +0 -23
  48. package/tests/assertions/yjs.test.ts +0 -33
  49. package/tests/dynamic-components/paths.test.ts +0 -171
  50. package/tests/dynamic-components/tools.test.ts +0 -121
  51. package/tests/paths/array-keys.test.ts +0 -182
  52. package/tests/paths/array-ops.test.ts +0 -164
  53. package/tests/paths/basic-ops.test.ts +0 -263
  54. package/tests/paths/tools.test.ts +0 -55
  55. package/tests/y-components/tools.test.ts +0 -198
  56. package/tests/y-tools/array-base-ops.test.ts +0 -55
  57. package/tests/y-tools/array-path-ops.test.ts +0 -95
  58. package/tsconfig.json +0 -13
  59. package/tsconfig.lib.json +0 -13
  60. package/tsdown.config.ts +0 -18
  61. package/vitest.config.ts +0 -19
package/dist/index.d.ts CHANGED
@@ -993,11 +993,11 @@ interface DRowSettings extends DynamicComponent {
993
993
  declare const isRowSettingsComponent: (component: DynamicComponent) => component is DRowSettings;
994
994
  //#endregion
995
995
  //#region src/dynamic-components/registry/uikit-dynamic-component.d.ts
996
- type FormDynamicComponent = DTextInput | DCheckbox | DTextarea | DSelect | DEntitySelect | DRadioGroup | DCheckboxGroup | DFileUploader | DImageUploader | DSimpleImageUploader | DRawImageUploader | DSlug | DEmbedCode | DRichTextEditor | DNumberInput | DSwitch | DHeading | DRawImagesUploader | DDateTimePicker | DComputedValue | DHiddenInput | DConfirmDeletionInput;
996
+ type UiKitFormDynamicComponent = DTextInput | DCheckbox | DTextarea | DSelect | DEntitySelect | DRadioGroup | DCheckboxGroup | DFileUploader | DImageUploader | DSimpleImageUploader | DRawImageUploader | DSlug | DEmbedCode | DRichTextEditor | DNumberInput | DSwitch | DHeading | DRawImagesUploader | DDateTimePicker | DComputedValue | DHiddenInput | DConfirmDeletionInput;
997
997
  type UiKitContentDynamicComponent = DRichText | DEmbedCode | DImage | DBibleQuote | DBiblePassage;
998
998
  type UiKitLayoutDynamicComponent = DRow | DColumn | DRowSettings | DCollection | DRepeatableCollection;
999
999
  type UiKitChatDynamicComponent = DChatTextMessage;
1000
- type UiKitDynamicComponent = FormDynamicComponent | UiKitContentDynamicComponent | UiKitLayoutDynamicComponent | UiKitChatDynamicComponent;
1000
+ type UiKitDynamicComponent = UiKitFormDynamicComponent | UiKitContentDynamicComponent | UiKitLayoutDynamicComponent | UiKitChatDynamicComponent;
1001
1001
  //#endregion
1002
1002
  //#region src/dynamic-components/tools.d.ts
1003
1003
  declare const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
@@ -1305,7 +1305,7 @@ declare const moveInPath: (object: NestedRecord, path: (string | number)[], oldP
1305
1305
  * @example
1306
1306
  * getFromPath({ items: [{ name: 'John' }] }, ['items', 0, 'name']); // Returns 'John'
1307
1307
  */
1308
- declare const getFromPath: <TValue = unknown>(object: NestedRecord | undefined, path: (string | number)[]) => TValue | undefined;
1308
+ declare const getFromPath: (object: NestedRecord | undefined, path: (string | number)[]) => unknown;
1309
1309
  /**
1310
1310
  * Sets a nested property value in a path, creates the path properties if they don't exist.
1311
1311
  * @param {NestedRecord} object - The object to set the value in.
@@ -1366,7 +1366,7 @@ declare const joinPath: (path: (string | number)[], ...items: (string | number)[
1366
1366
  * @example
1367
1367
  * sortByPosition('a1', 'a2'); // Returns -1
1368
1368
  */
1369
- declare const sortByPosition: (aPosition: string, bPosition: string) => 1 | -1 | 0;
1369
+ declare const sortByPosition: (aPosition: string, bPosition: string) => 0 | 1 | -1;
1370
1370
  //#endregion
1371
1371
  //#region src/y-components/types.d.ts
1372
1372
  /**
@@ -1581,7 +1581,7 @@ declare const unsetYPath: (yType: Y.Map<unknown> | Y.Array<unknown>, path: (stri
1581
1581
  * const value = getFromYPath(ymap, ['key']);
1582
1582
  * // value is now: 'value'
1583
1583
  */
1584
- declare const getFromYPath: (entry: Y.Array<any> | Y.Map<any>, path: (string | number)[]) => unknown | null;
1584
+ declare const getFromYPath: (entry: Y.Array<any> | Y.Map<any> | null | undefined, path: (string | number)[]) => unknown;
1585
1585
  //#endregion
1586
1586
  //#region src/y-tools/tools.d.ts
1587
1587
  /**
@@ -1707,5 +1707,5 @@ interface AwarenessState {
1707
1707
  */
1708
1708
  declare const getYArrayIndexByArrayKey: (yArray: unknown, key: string) => number;
1709
1709
  //#endregion
1710
- export { AwarenessState, AwarenessStateChange, BaseDataObject, ComponentStyles, DBiblePassage, DBibleQuote, DChatMessageDelay, DChatTextMessage, DCheckbox, DCheckboxGroup, DCollection, DColumn, DComputedValue, DConfirmDeletionInput, DDateTimePicker, DEmbedCode, DEntitySelect, DFileUploader, DHeading, DHiddenInput, DImage, DImageUploader, DLegacyContent, DNumberInput, DPractice, DRadioGroup, DRawImageUploader, DRawImagesUploader, DRepeatableCollection, DRichText, DRichTextEditor, DRow, DRowSettings, DSelect, DSimpleImageUploader, DSlug, DStatement, DSwitch, DTest, DTextInput, DTextarea, DynamicComponent, DynamicComponentIO, DynamicComponentLink, DynamicComponentWithPosition, FormDynamicComponent, ID_PATH_KEY_PREFIX, IImageRenditionType, IRenditionOptions, ISizeType, InsertYMapAfterOptions, InsertYMapBeforeOptions, InsertYMapToEndOptions, MovePayload, MoveYMapAfterOptions, MoveYMapBeforeOptions, MoveYMapToEndOptions, MoveYMapToStartOptions, NestedRecord, PATH_REGEXP, POSITION_ARRAY_KEY_PREFIX, Point, PullPayload, PushPayload, RichText, SetPayload, TestItem, TestItemVariant, UiKitChatDynamicComponent, UiKitContentDynamicComponent, UiKitDynamicComponent, UiKitLayoutDynamicComponent, UnsetPayload, ValidationRules, YComponent, YComponentProps, YComponentsArray, arrayToYArray, copyDynamicComponent, createIdArrayKey, createPositionArrayKey, customAlphabet, defineDynamicComponent, defineDynamicComponents, dynamicComponentPropsToYComponentProps, dynamicComponentToYComponent, dynamicComponentToYMap, dynamicComponentsToYArray, entriesOf, existsInPath, extractIdFromArrayKey, extractPositionFromArrayKey, findInYArray, findIndexInYArray, findYComponentInArray, generateKeyBetween, getComponentPropertyPath, getComponentsSubtreeByPath, getComponentsSubtreeByRPath, getDataObjectKey, getFromPath, getFromYPath, getIndexByArrayKey, getRelativePoint, getSortedYArray, getYArrayIndexByArrayKey, getYArrayRefsByPosition, getYComponentComponentsArray, getYComponentProps, getYComponentsArrayParentComponent, insertInPath, insertYMapAfter, insertYMapBefore, insertYMapToEnd, isArrayKey, isBiblePassageComponent, isBibleQuoteComponent, isCallable, isChatMessageDelayComponent, isChatTextMessageComponent, isCheckboxComponent, isCheckboxGroupComponent, isCollectionComponent, isColumnComponent, isComputedValueComponent, isConfirmDeletionInputComponent, isContainerValue, isDateTimePickerComponent, isEmbedCodeComponent, isEmptyArray, isEmptyContainer, isEntitySelectComponent, isEqualPath, isFileUploaderComponent, isHeadingComponent, isIdArrayKey, isImageComponent, isImageUploaderComponent, isIndex, isLegacyContentComponent, isNullOrUndefined, isNumber, isNumberInputComponent, isObject, isPositionArrayKey, isPracticeComponent, isRadioGroupComponent, isRawImageUploaderComponent, isRawImagesUploaderComponent, isRepeatableCollectionComponent, isRichText, isRichTextComponent, isRichTextEditorComponent, isRowComponent, isRowSettingsComponent, isSamePath, isSelectComponent, isSimpleImageUploaderComponent, isSlugComponent, isStatementComponent, isString, isSwitchComponent, isTestComponent, isTextInputComponent, isTextareaComponent, isYArray, isYComponent, isYMap, joinPath, keysOf, makeDynamicComponentsWithPosition, moveInPath, moveInYPath, moveYMapAfter, moveYMapBefore, moveYMapToEnd, moveYMapToStart, objectToYMap, pullFromPath, pullFromYPath, pushInPath, pushInYPath, searchDynamicComponentInTree, setInPath, setInYPath, sortByPosition, sortDynamicComponents, uid, unsetPath, unsetYPath, urlAlphabet, yComponentHasComponentsYArray, yComponentToDynamicComponent };
1710
+ export { AwarenessState, AwarenessStateChange, BaseDataObject, ComponentStyles, DBiblePassage, DBibleQuote, DChatMessageDelay, DChatTextMessage, DCheckbox, DCheckboxGroup, DCollection, DColumn, DComputedValue, DConfirmDeletionInput, DDateTimePicker, DEmbedCode, DEntitySelect, DFileUploader, DHeading, DHiddenInput, DImage, DImageUploader, DLegacyContent, DNumberInput, DPractice, DRadioGroup, DRawImageUploader, DRawImagesUploader, DRepeatableCollection, DRichText, DRichTextEditor, DRow, DRowSettings, DSelect, DSimpleImageUploader, DSlug, DStatement, DSwitch, DTest, DTextInput, DTextarea, DynamicComponent, DynamicComponentIO, DynamicComponentLink, DynamicComponentWithPosition, ID_PATH_KEY_PREFIX, IImageRenditionType, IRenditionOptions, ISizeType, InsertYMapAfterOptions, InsertYMapBeforeOptions, InsertYMapToEndOptions, MovePayload, MoveYMapAfterOptions, MoveYMapBeforeOptions, MoveYMapToEndOptions, MoveYMapToStartOptions, NestedRecord, PATH_REGEXP, POSITION_ARRAY_KEY_PREFIX, Point, PullPayload, PushPayload, RichText, SetPayload, TestItem, TestItemVariant, UiKitChatDynamicComponent, UiKitContentDynamicComponent, UiKitDynamicComponent, UiKitFormDynamicComponent, UiKitLayoutDynamicComponent, UnsetPayload, ValidationRules, YComponent, YComponentProps, YComponentsArray, arrayToYArray, copyDynamicComponent, createIdArrayKey, createPositionArrayKey, customAlphabet, defineDynamicComponent, defineDynamicComponents, dynamicComponentPropsToYComponentProps, dynamicComponentToYComponent, dynamicComponentToYMap, dynamicComponentsToYArray, entriesOf, existsInPath, extractIdFromArrayKey, extractPositionFromArrayKey, findInYArray, findIndexInYArray, findYComponentInArray, generateKeyBetween, getComponentPropertyPath, getComponentsSubtreeByPath, getComponentsSubtreeByRPath, getDataObjectKey, getFromPath, getFromYPath, getIndexByArrayKey, getRelativePoint, getSortedYArray, getYArrayIndexByArrayKey, getYArrayRefsByPosition, getYComponentComponentsArray, getYComponentProps, getYComponentsArrayParentComponent, insertInPath, insertYMapAfter, insertYMapBefore, insertYMapToEnd, isArrayKey, isBiblePassageComponent, isBibleQuoteComponent, isCallable, isChatMessageDelayComponent, isChatTextMessageComponent, isCheckboxComponent, isCheckboxGroupComponent, isCollectionComponent, isColumnComponent, isComputedValueComponent, isConfirmDeletionInputComponent, isContainerValue, isDateTimePickerComponent, isEmbedCodeComponent, isEmptyArray, isEmptyContainer, isEntitySelectComponent, isEqualPath, isFileUploaderComponent, isHeadingComponent, isIdArrayKey, isImageComponent, isImageUploaderComponent, isIndex, isLegacyContentComponent, isNullOrUndefined, isNumber, isNumberInputComponent, isObject, isPositionArrayKey, isPracticeComponent, isRadioGroupComponent, isRawImageUploaderComponent, isRawImagesUploaderComponent, isRepeatableCollectionComponent, isRichText, isRichTextComponent, isRichTextEditorComponent, isRowComponent, isRowSettingsComponent, isSamePath, isSelectComponent, isSimpleImageUploaderComponent, isSlugComponent, isStatementComponent, isString, isSwitchComponent, isTestComponent, isTextInputComponent, isTextareaComponent, isYArray, isYComponent, isYMap, joinPath, keysOf, makeDynamicComponentsWithPosition, moveInPath, moveInYPath, moveYMapAfter, moveYMapBefore, moveYMapToEnd, moveYMapToStart, objectToYMap, pullFromPath, pullFromYPath, pushInPath, pushInYPath, searchDynamicComponentInTree, setInPath, setInYPath, sortByPosition, sortDynamicComponents, uid, unsetPath, unsetYPath, urlAlphabet, yComponentHasComponentsYArray, yComponentToDynamicComponent };
1711
1711
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -81,7 +81,7 @@ const INTEGER_ZERO = "a0";
81
81
  */
82
82
  const midpoint = (a, b, digits) => {
83
83
  if (b !== null && a >= b) throw new Error(a + " >= " + b);
84
- if (a.slice(-1) === "0" || b && b.slice(-1) === "0") throw new Error("trailing zero");
84
+ if (a.endsWith("0") || b?.endsWith("0")) throw new Error("trailing zero");
85
85
  if (b) {
86
86
  let n = 0;
87
87
  while ((a[n] || "0") === b[n]) n++;
@@ -127,7 +127,7 @@ const getIntegerPart = (key) => {
127
127
  const validateOrderKey = (key) => {
128
128
  if (key === SMALLEST_INTEGER) throw new Error("invalid order key: " + key);
129
129
  const i = getIntegerPart(key);
130
- if (key.slice(i.length).slice(-1) === "0") throw new Error("invalid order key: " + key);
130
+ if (key.slice(i.length).endsWith("0")) throw new Error("invalid order key: " + key);
131
131
  };
132
132
  /**
133
133
  * @param {string} x
@@ -204,8 +204,7 @@ const generateKeyBetween = (a, b, digits = BASE_62_DIGITS) => {
204
204
  if (b === null) {
205
205
  const ia$1 = getIntegerPart(a);
206
206
  const fa$1 = a.slice(ia$1.length);
207
- const i$1 = incrementInteger(ia$1, digits);
208
- return i$1 === null ? ia$1 + midpoint(fa$1, null, digits) : i$1;
207
+ return incrementInteger(ia$1, digits) ?? ia$1 + midpoint(fa$1, null, digits);
209
208
  }
210
209
  const ia = getIntegerPart(a);
211
210
  const fa = a.slice(ia.length);
@@ -274,8 +273,8 @@ const createPositionArrayKey = (position) => {
274
273
  * extractPositionFromArrayKey('pos:0'); // Returns '0'
275
274
  */
276
275
  const extractPositionFromArrayKey = (key) => {
277
- if (!isPositionArrayKey(key)) throw new Error(`Invalid array key ${key}. Must be "pos:xxxxx"`);
278
- return key.split(POSITION_ARRAY_KEY_PREFIX)[1];
276
+ if (!key.startsWith(POSITION_ARRAY_KEY_PREFIX)) throw new Error(`Invalid array key ${key}. Must be "pos:xxxxx"`);
277
+ return key.slice(4);
279
278
  };
280
279
  const ID_PATH_KEY_PREFIX = "id:";
281
280
  /**
@@ -307,8 +306,8 @@ const createIdArrayKey = (id) => {
307
306
  * extractIdFromArrayKey('id:123'); // Returns '123'
308
307
  */
309
308
  const extractIdFromArrayKey = (key) => {
310
- if (!isIdArrayKey(key)) throw new Error(`Invalid array key ${key}. Must be "id:xxxxx"`);
311
- return key.split(ID_PATH_KEY_PREFIX)[1];
309
+ if (!key.startsWith(ID_PATH_KEY_PREFIX)) throw new Error(`Invalid array key ${key}. Must be "id:xxxxx"`);
310
+ return key.slice(3);
312
311
  };
313
312
  /**
314
313
  * Checks if the given key is an array key (either a position array key or an ID array key).
@@ -333,20 +332,18 @@ const getIndexByArrayKey = (array, key) => {
333
332
  console.error(`Non-array type`, array);
334
333
  throw new Error(`Can't use array key in non array type (${key})`);
335
334
  }
336
- if (!isArrayKey(key)) throw new Error(`Unknown array key type (${key})`);
335
+ if (!isArrayKey(key)) throw new Error(`Unknown array key type (${String(key)})`);
337
336
  if (array.length === 0) return 0;
338
- if (isIdArrayKey(key)) {
337
+ if (key.startsWith(ID_PATH_KEY_PREFIX)) {
339
338
  const id = extractIdFromArrayKey(key);
340
- const index = array.findIndex((it) => isObject(it) && it.id === id);
341
- if (index === -1) throw new Error(`Can't find index by id ${id} (${key})`);
342
- return index;
343
- } else if (isPositionArrayKey(key)) {
344
- const position = extractPositionFromArrayKey(key);
345
- const index = array.findIndex((it) => it.position === position);
346
- if (index === -1) throw new Error(`Can't find index by position ${position} (${key})`);
347
- return index;
339
+ const index$1 = array.findIndex((it) => isObject(it) && it.id === id);
340
+ if (index$1 === -1) throw new Error(`Can't find index by id ${id} (${key})`);
341
+ return index$1;
348
342
  }
349
- return 0;
343
+ const position = extractPositionFromArrayKey(key);
344
+ const index = array.findIndex((it) => it.position === position);
345
+ if (index === -1) throw new Error(`Can't find index by position ${position} (${key})`);
346
+ return index;
350
347
  };
351
348
 
352
349
  //#endregion
@@ -381,7 +378,7 @@ const setInPath = (object, path, value) => {
381
378
  for (const [i, rawKey] of path.entries()) {
382
379
  const key = isArrayKey(rawKey) ? getIndexByArrayKey(acc, rawKey) : rawKey;
383
380
  if (Array.isArray(acc)) {
384
- const index = Number(key);
381
+ const index = typeof key === "number" ? key : Number(key);
385
382
  if (i === path.length - 1) {
386
383
  acc[index] = value;
387
384
  return;
@@ -406,10 +403,11 @@ const setInPath = (object, path, value) => {
406
403
  };
407
404
  const unset = (object, key) => {
408
405
  if (Array.isArray(object) && isIndex(key)) {
409
- object.splice(Number(key), 1);
406
+ const index = typeof key === "number" ? key : Number(key);
407
+ object.splice(index, 1);
410
408
  return;
411
409
  }
412
- if (isObject(object)) delete object[key];
410
+ if (isObject(object) && typeof key === "string") delete object[key];
413
411
  };
414
412
  /**
415
413
  * Removes a nested property from an object using a path.
@@ -428,7 +426,7 @@ const unsetPath = (object, path) => {
428
426
  break;
429
427
  }
430
428
  if (Array.isArray(acc)) {
431
- const index = Number(key);
429
+ const index = typeof key === "number" ? key : Number(key);
432
430
  if (!(key in acc) || isNullOrUndefined(acc[index])) break;
433
431
  acc = acc[index];
434
432
  } else {
@@ -517,7 +515,7 @@ const pullFromPath = (object, path, key) => {
517
515
  }
518
516
  }
519
517
  };
520
- const printPosition$1 = (array) => array.map((it) => isObject(it) ? it.position ?? "no-position" : "not-object");
518
+ const printPosition$1 = (array) => JSON.stringify(array.map((it) => isObject(it) ? it.position ?? "no-position" : "not-object"));
521
519
  /**
522
520
  * Moves an item to a new position relative to another item in the array or object at the specified path.
523
521
  *
@@ -527,19 +525,20 @@ const printPosition$1 = (array) => array.map((it) => isObject(it) ? it.position
527
525
  const moveInPath = (object, path, oldPosition, relativePosition, insert) => {
528
526
  const array = getFromPath(object, path);
529
527
  if (!Array.isArray(array)) throw new Error(`Can't move. Target item is not array in path ${JSON.stringify(path)}`);
530
- const item = array.find((it) => isObject(it) && it.position === oldPosition);
531
- const relativeItemIndex = array.findIndex((it) => isObject(it) && it.position === relativePosition);
532
- if (!isObject(item)) throw new Error(`Can't move. Item in position ${oldPosition} not found. ${printPosition$1(array)}`);
533
- if (relativeItemIndex === -1) throw new Error(`Can't move. Relative item in position ${relativePosition} not found. ${printPosition$1(array)}`);
534
- const relativeItem = array[relativeItemIndex];
535
- if (!isObject(relativeItem)) throw new Error(`Can't move. Relative item in position ${relativePosition} must be an object. ${printPosition$1(array)}`);
528
+ const positionedArray = array;
529
+ const item = positionedArray.find((it) => isObject(it) && it.position === oldPosition);
530
+ const relativeItemIndex = positionedArray.findIndex((it) => isObject(it) && it.position === relativePosition);
531
+ if (!isObject(item)) throw new Error(`Can't move. Item in position ${oldPosition} not found. ${printPosition$1(positionedArray)}`);
532
+ if (relativeItemIndex === -1) throw new Error(`Can't move. Relative item in position ${relativePosition} not found. ${printPosition$1(positionedArray)}`);
533
+ const relativeItem = positionedArray[relativeItemIndex];
534
+ if (!isObject(relativeItem)) throw new Error(`Can't move. Relative item in position ${relativePosition} must be an object. ${printPosition$1(positionedArray)}`);
536
535
  if (insert === "before") {
537
- const left = array[relativeItemIndex - 1];
536
+ const left = positionedArray[relativeItemIndex - 1];
538
537
  const newPosition$1 = generateKeyBetween(isObject(left) ? left.position ?? null : null, relativeItem.position);
539
538
  item.position = newPosition$1;
540
539
  return newPosition$1;
541
540
  }
542
- const right = array[relativeItemIndex + 1];
541
+ const right = positionedArray[relativeItemIndex + 1];
543
542
  const rightPosition = isObject(right) ? right.position ?? null : null;
544
543
  const newPosition = generateKeyBetween(relativeItem.position, rightPosition);
545
544
  item.position = newPosition;
@@ -562,8 +561,8 @@ const PATH_REGEXP = /\.|\[(\d+)\]/;
562
561
  * joinPath(['items', 'id:xxx'], 'name'); // Returns ['items', 'id:xxx', 'name']
563
562
  */
564
563
  const joinPath = (path, ...items) => {
565
- if (!Array.isArray(path)) throw new Error(`path must be array: ${path}`);
566
- for (const item of items) if (!isString(item) && !Number.isInteger(item)) throw new Error(`Invalid path item: ${item}`);
564
+ if (!Array.isArray(path)) throw new Error(`path must be array: ${String(path)}`);
565
+ for (const item of items) if (!isString(item) && !Number.isInteger(item)) throw new Error(`Invalid path item: ${String(item)}`);
567
566
  return path.concat(items);
568
567
  };
569
568
  /**
@@ -966,12 +965,13 @@ const getYArrayIndexByArrayKey = (yArray, key) => {
966
965
  console.error(`Non-YArray type`, yArray);
967
966
  throw new Error(`Can't use array key in non YArray type (${key})`);
968
967
  }
969
- if (isIdArrayKey(key)) {
968
+ if (key.startsWith("id:")) {
970
969
  const id = extractIdFromArrayKey(key);
971
970
  const index = yArray.toArray().findIndex((it) => isYMap(it) && it.get("id") === id);
972
971
  if (index === -1) throw new Error(`Can't find index by id ${id} (${key})`);
973
972
  return index;
974
- } else if (isPositionArrayKey(key)) {
973
+ }
974
+ if (key.startsWith("pos:")) {
975
975
  const position = extractPositionFromArrayKey(key);
976
976
  const index = yArray.toArray().findIndex((it) => isYMap(it) && it.get("position") === position);
977
977
  if (index === -1) throw new Error(`Can't find index by position ${position} (${key})`);
@@ -1023,7 +1023,7 @@ const setInYPath = (ymap, path, value) => {
1023
1023
  }
1024
1024
  };
1025
1025
  const yUnset = (yType, key) => {
1026
- if (yType instanceof Y.Array && isIndex(key)) yType.delete(Number(key));
1026
+ if (yType instanceof Y.Array && isIndex(key)) yType.delete(key);
1027
1027
  else if (yType instanceof Y.Map && isString(key)) yType.delete(key);
1028
1028
  };
1029
1029
  /**
@@ -1044,7 +1044,7 @@ const unsetYPath = (yType, path) => {
1044
1044
  break;
1045
1045
  }
1046
1046
  if (acc instanceof Y.Array && isIndex(key)) {
1047
- const index = Number(key);
1047
+ const index = key;
1048
1048
  if (isNullOrUndefined(acc.get(index))) break;
1049
1049
  acc = acc.get(index);
1050
1050
  } else if (acc instanceof Y.Map && isString(key)) {
@@ -1063,26 +1063,26 @@ const unsetYPath = (yType, path) => {
1063
1063
  * // value is now: 'value'
1064
1064
  */
1065
1065
  const getFromYPath = (entry, path) => {
1066
- if (!entry) return;
1066
+ if (!entry) return null;
1067
1067
  if (path.length === 0) return entry;
1068
1068
  let ref = entry;
1069
1069
  for (const rawKey of path) {
1070
1070
  const key = isArrayKey(rawKey) ? getYArrayIndexByArrayKey(ref, rawKey) : rawKey;
1071
1071
  if (isYArray(ref)) {
1072
1072
  if (!isIndex(key)) {
1073
- console.warn(`Can't use non index key in YArray ${key}: ${JSON.stringify(path)}`);
1073
+ console.warn(`Can't use non index key in YArray ${String(key)}: ${JSON.stringify(path)}`);
1074
1074
  return null;
1075
1075
  }
1076
1076
  ref = ref.get(key);
1077
1077
  continue;
1078
1078
  } else if (isYMap(ref)) {
1079
1079
  if (!isString(key)) {
1080
- console.warn(`Can't use non string key in YMap ${key}: ${JSON.stringify(path)}`);
1080
+ console.warn(`Can't use non string key in YMap ${String(key)}: ${JSON.stringify(path)}`);
1081
1081
  return null;
1082
1082
  }
1083
1083
  ref = ref.get(key);
1084
1084
  } else {
1085
- console.warn(`Non supported YType on ${key}: ${JSON.stringify(path)}`);
1085
+ console.warn(`Non supported YType on ${String(key)}: ${JSON.stringify(path)}`);
1086
1086
  return null;
1087
1087
  }
1088
1088
  }
@@ -1205,7 +1205,7 @@ const pushInYPath = (entry, path, value) => {
1205
1205
  if (!isYArray(yArray)) setInYPath(entry, path, Y.Array.from([value]));
1206
1206
  else yArray.push([value]);
1207
1207
  };
1208
- const printPosition = (array) => array.map((it) => isYMap(it) ? it.get("position") ?? "no-position" : "not-ymap");
1208
+ const printPosition = (array) => JSON.stringify(array.map((it) => isYMap(it) ? it.get("position") ?? "no-position" : "not-ymap"));
1209
1209
  /**
1210
1210
  * Moves an item to a new position relative to another item in the Y.Array or Y.Map at the specified path.
1211
1211
  *
@@ -1259,7 +1259,7 @@ const pullFromYPath = (entry, path, key) => {
1259
1259
  * */
1260
1260
  const moveYMapToStart = ({ yArray, yMap }) => {
1261
1261
  const first = getSortedYArray(yArray)[0];
1262
- const rightIndex = first ? first.get("position") : null;
1262
+ const rightIndex = first ? first.get("position") ?? null : null;
1263
1263
  yMap.set("position", generateKeyBetween(null, rightIndex));
1264
1264
  };
1265
1265
  /**
@@ -1268,7 +1268,7 @@ const moveYMapToStart = ({ yArray, yMap }) => {
1268
1268
  const moveYMapToEnd = ({ yArray, yMap }) => {
1269
1269
  const sortedArray = getSortedYArray(yArray);
1270
1270
  const last = sortedArray[sortedArray.length - 1];
1271
- const leftIndex = last ? last.get("position") : null;
1271
+ const leftIndex = last ? last.get("position") ?? null : null;
1272
1272
  yMap.set("position", generateKeyBetween(leftIndex, null));
1273
1273
  };
1274
1274
  /**
@@ -1277,8 +1277,8 @@ const moveYMapToEnd = ({ yArray, yMap }) => {
1277
1277
  const moveYMapBefore = ({ yArray, yMap, relativePosition }) => {
1278
1278
  const { ref: relative, left } = getYArrayRefsByPosition(yArray, relativePosition);
1279
1279
  const right = relative;
1280
- const rightIndex = right ? right.get("position") : null;
1281
- const leftIndex = left ? left.get("position") : null;
1280
+ const rightIndex = right ? right.get("position") ?? null : null;
1281
+ const leftIndex = left ? left.get("position") ?? null : null;
1282
1282
  yMap.set("position", generateKeyBetween(leftIndex, rightIndex));
1283
1283
  };
1284
1284
  /**
@@ -1287,8 +1287,8 @@ const moveYMapBefore = ({ yArray, yMap, relativePosition }) => {
1287
1287
  const moveYMapAfter = ({ yArray, yMap, relativePosition }) => {
1288
1288
  const { ref: relative, right } = getYArrayRefsByPosition(yArray, relativePosition);
1289
1289
  const left = relative;
1290
- const rightIndex = right ? right.get("position") : null;
1291
- const leftIndex = left ? left.get("position") : null;
1290
+ const rightIndex = right ? right.get("position") ?? null : null;
1291
+ const leftIndex = left ? left.get("position") ?? null : null;
1292
1292
  yMap.set("position", generateKeyBetween(leftIndex, rightIndex));
1293
1293
  };
1294
1294
  /**
@@ -1334,7 +1334,7 @@ const dynamicComponentToYMap = (component, yMap = new Y.Map()) => {
1334
1334
  const { props: propsWithComponents,...fields } = component;
1335
1335
  const { components,...props } = propsWithComponents ?? {};
1336
1336
  for (const [key, value] of Object.entries(fields)) yMap.set(key, value);
1337
- const yProps = props ? objectToYMap(props) : new Y.Map();
1337
+ const yProps = objectToYMap(props);
1338
1338
  if (Array.isArray(components)) yProps.set("components", dynamicComponentsToYArray(components));
1339
1339
  yMap.set("props", yProps);
1340
1340
  return yMap;
@@ -1389,7 +1389,7 @@ const dynamicComponentToYComponent = (component) => {
1389
1389
  */
1390
1390
  const getYComponentProps = (yComponent) => {
1391
1391
  const props = yComponent.get("props");
1392
- if (!isYMap(props)) throw new Error(`Component hasn't "props" property. It must have to be defined as Y.Map (component: ${yComponent.get("id")})`);
1392
+ if (!isYMap(props)) throw new Error(`Component hasn't "props" property. It must have to be defined as Y.Map (component: ${String(yComponent.get("id"))})`);
1393
1393
  return props;
1394
1394
  };
1395
1395
  /**
@@ -1397,7 +1397,7 @@ const getYComponentProps = (yComponent) => {
1397
1397
  */
1398
1398
  const getYComponentComponentsArray = (yComponent) => {
1399
1399
  const yComponents = getYComponentProps(yComponent).get("components");
1400
- if (!isYArray(yComponents)) throw new Error(`Component hasn't "props.components" property. It must be defined as Y.Array (component: ${yComponent.get("id")})`);
1400
+ if (!isYArray(yComponents)) throw new Error(`Component hasn't "props.components" property. It must be defined as Y.Array (component: ${String(yComponent.get("id"))})`);
1401
1401
  return yComponents;
1402
1402
  };
1403
1403
  /**