@sanity/orderable-document-list 0.0.9 → 0.1.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 (38) hide show
  1. package/.prettierrc.js +6 -0
  2. package/.releaserc.json +4 -0
  3. package/.semantic-release/sanity-orderable-document-list-0.1.0.tgz +0 -0
  4. package/CHANGELOG.md +16 -0
  5. package/LICENSE +1 -1
  6. package/README.md +15 -2
  7. package/lib/Document.js +8 -21
  8. package/lib/Document.js.map +1 -1
  9. package/lib/DocumentListQuery.js +15 -47
  10. package/lib/DocumentListQuery.js.map +1 -1
  11. package/lib/DocumentListWrapper.js +11 -32
  12. package/lib/DocumentListWrapper.js.map +1 -1
  13. package/lib/DraggableList.js +56 -90
  14. package/lib/DraggableList.js.map +1 -1
  15. package/lib/Feedback.js +0 -6
  16. package/lib/Feedback.js.map +1 -1
  17. package/lib/OrderableContext.js +0 -4
  18. package/lib/OrderableContext.js.map +1 -1
  19. package/lib/OrderableDocumentList.js +0 -24
  20. package/lib/OrderableDocumentList.js.map +1 -1
  21. package/lib/desk-structure/orderableDocumentListDeskItem.js +6 -14
  22. package/lib/desk-structure/orderableDocumentListDeskItem.js.map +1 -1
  23. package/lib/fields/orderRankField.js +0 -16
  24. package/lib/fields/orderRankField.js.map +1 -1
  25. package/lib/fields/orderRankOrdering.js +0 -2
  26. package/lib/fields/orderRankOrdering.js.map +1 -1
  27. package/lib/helpers/constants.js.map +1 -1
  28. package/lib/helpers/initialRank.js +0 -2
  29. package/lib/helpers/initialRank.js.map +1 -1
  30. package/lib/helpers/reorderDocuments.js +51 -64
  31. package/lib/helpers/reorderDocuments.js.map +1 -1
  32. package/lib/helpers/resetOrder.js +3 -16
  33. package/lib/helpers/resetOrder.js.map +1 -1
  34. package/lib/index.js +0 -3
  35. package/lib/index.js.map +1 -1
  36. package/package.json +25 -20
  37. package/src/DocumentListWrapper.js +2 -3
  38. package/src/desk-structure/orderableDocumentListDeskItem.js +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"orderableDocumentListDeskItem.js","names":["orderableDocumentListDeskItem","config","type","Error","filter","params","title","icon","listTitle","listId","listIcon","SortIcon","typeTitle","schema","get","S","listItem","id","child","Object","assign","documentTypeList","serialize","__preserveInstance","key","component","OrderableDocumentList","options","menuItems","menuItem","intent","GenerateIcon","action"],"sources":["../../src/desk-structure/orderableDocumentListDeskItem.js"],"sourcesContent":["import S from '@sanity/desk-tool/structure-builder'\nimport {SortIcon, GenerateIcon} from '@sanity/icons'\nimport schema from 'part:@sanity/base/schema'\n\nimport OrderableDocumentList from '../OrderableDocumentList'\n\nexport function orderableDocumentListDeskItem(config = {}) {\n if (!config?.type) {\n throw new Error(`\n \"type\" not defined in orderableDocumentListDeskItem parameters.\n \\n\\n\n Example: orderableDocumentListDeskItem({type: 'category'})\n `)\n }\n\n const {type, filter, params, title, icon} = config\n\n const listTitle = title ?? `Orderable ${type}`\n const listId = `orderable-${type}`\n const listIcon = icon ?? SortIcon\n const typeTitle = schema.get(type)?.title ?? type\n\n return S.listItem(type)\n .title(listTitle)\n .id(listId)\n .icon(listIcon)\n .child(\n Object.assign(S.documentTypeList(type).serialize(), {\n // Prevents the component from re-rendering when switching documents\n __preserveInstance: true,\n // Prevents the component from NOT re-rendering when switching listItems\n key: listId,\n\n type: 'component',\n component: OrderableDocumentList,\n options: {type, filter, params},\n menuItems: [\n S.menuItem()\n .title(`Create new ${typeTitle}`)\n .intent({type: 'create', params: {type}})\n .serialize(),\n S.menuItem().title(`Reset Order`).icon(GenerateIcon).action(`resetOrder`).serialize(),\n S.menuItem().title(`Show Increments`).icon(SortIcon).action(`showIncrements`).serialize(),\n ],\n })\n )\n .serialize()\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;AAEO,SAASA,6BAAT,GAAoD;EAAA;;EAAA,IAAbC,MAAa,uEAAJ,EAAI;;EACzD,IAAI,EAACA,MAAD,aAACA,MAAD,eAACA,MAAM,CAAEC,IAA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KTP,yBAAA,CAAEc,QAAF,GAAavB,KAAb,gBAAkCC,IAAlC,CAAuCwB,mBAAvC,EAAqDC,MAArD,eAA0EV,SAA1E,EALS,EAMTP,yBAAA,CAAEc,QAAF,GAAavB,KAAb,oBAAsCC,IAAtC,CAA2CI,eAA3C,EAAqDqB,MAArD,mBAA8EV,SAA9E,EANS;EATuC,CAApD,CALG,EAwBJA,SAxBI,EAAP;AAyBD"}
1
+ {"version":3,"file":"orderableDocumentListDeskItem.js","names":["orderableDocumentListDeskItem","config","type","Error","filter","params","title","icon","id","listTitle","listId","listIcon","SortIcon","typeTitle","schema","get","S","listItem","child","Object","assign","documentTypeList","serialize","__preserveInstance","key","component","OrderableDocumentList","options","menuItems","menuItem","intent","GenerateIcon","action"],"sources":["../../src/desk-structure/orderableDocumentListDeskItem.js"],"sourcesContent":["import S from '@sanity/desk-tool/structure-builder'\nimport {SortIcon, GenerateIcon} from '@sanity/icons'\nimport schema from 'part:@sanity/base/schema'\n\nimport OrderableDocumentList from '../OrderableDocumentList'\n\nexport function orderableDocumentListDeskItem(config = {}) {\n if (!config?.type) {\n throw new Error(`\n \"type\" not defined in orderableDocumentListDeskItem parameters.\n \\n\\n\n Example: orderableDocumentListDeskItem({type: 'category'})\n `)\n }\n\n const {type, filter, params, title, icon, id} = config\n\n const listTitle = title ?? `Orderable ${type}`\n const listId = id ?? `orderable-${type}`\n const listIcon = icon ?? SortIcon\n const typeTitle = schema.get(type)?.title ?? type\n\n return S.listItem(type)\n .title(listTitle)\n .id(listId)\n .icon(listIcon)\n .child(\n Object.assign(S.documentTypeList(type).serialize(), {\n // Prevents the component from re-rendering when switching documents\n __preserveInstance: true,\n // Prevents the component from NOT re-rendering when switching listItems\n key: listId,\n\n type: 'component',\n component: OrderableDocumentList,\n options: {type, filter, params},\n menuItems: [\n S.menuItem()\n .title(`Create new ${typeTitle}`)\n .intent({type: 'create', params: {type}})\n .serialize(),\n S.menuItem().title(`Reset Order`).icon(GenerateIcon).action(`resetOrder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IAAI,EAAE,WAAW;IACjBuB,SAAS,EAAEC,8BAAqB;IAChCC,OAAO,EAAE;MAACzB,IAAI;MAAEE,MAAM;MAAEC;IAAM,CAAC;IAC/BuB,SAAS,EAAE,CACTZ,yBAAC,CAACa,QAAQ,EAAE,CACTvB,KAAK,sBAAeO,SAAS,EAAG,CAChCiB,MAAM,CAAC;MAAC5B,IAAI,EAAE,QAAQ;MAAEG,MAAM,EAAE;QAACH;MAAI;IAAC,CAAC,CAAC,CACxCoB,SAAS,EAAE,EACdN,yBAAC,CAACa,QAAQ,EAAE,CAACvB,KAAK,eAAe,CAACC,IAAI,CAACwB,mBAAY,CAAC,CAACC,MAAM,cAAc,CAACV,SAAS,EAAE,EACrFN,yBAAC,CAACa,QAAQ,EAAE,CAACvB,KAAK,mBAAmB,CAACC,IAAI,CAACK,eAAQ,CAAC,CAACoB,MAAM,kBAAkB,CAACV,SAAS,EAAE;EAE7F,CAAC,CAAC,CACH,CACAA,SAAS,EAAE;AAChB"}
@@ -4,36 +4,23 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.orderRankField = void 0;
7
-
8
7
  var _client = _interopRequireDefault(require("part:@sanity/base/client"));
9
-
10
8
  var _constants = require("../helpers/constants");
11
-
12
9
  var _initialRank = _interopRequireDefault(require("../helpers/initialRank"));
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
11
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
17
-
18
12
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
19
-
20
13
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
-
22
14
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
23
-
24
15
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
-
26
16
  var client = _client.default.withConfig({
27
17
  apiVersion: "2021-05-19"
28
18
  });
29
-
30
19
  var orderRankField = function orderRankField() {
31
20
  var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
32
-
33
21
  if (!(config !== null && config !== void 0 && config.type)) {
34
22
  throw new Error("\n \"type\" not defined in orderRankField parameter object. \n Example: orderRankField({type: 'category'})\n ");
35
23
  }
36
-
37
24
  var type = config.type;
38
25
  return _objectSpread(_objectSpread({
39
26
  title: 'Order Rank',
@@ -50,15 +37,12 @@ var orderRankField = function orderRankField() {
50
37
  });
51
38
  return (0, _initialRank.default)(lastDocOrderRank);
52
39
  });
53
-
54
40
  function initialValue() {
55
41
  return _initialValue.apply(this, arguments);
56
42
  }
57
-
58
43
  return initialValue;
59
44
  }()
60
45
  });
61
46
  };
62
-
63
47
  exports.orderRankField = orderRankField;
64
48
  //# sourceMappingURL=orderRankField.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"orderRankField.js","names":["client","sanityClient","withConfig","apiVersion","orderRankField","config","type","Error","title","readOnly","hidden","name","ORDER_FIELD_NAME","initialValue","lastDocOrderRank","fetch","order","initialRank"],"sources":["../../src/fields/orderRankField.js"],"sourcesContent":["import sanityClient from 'part:@sanity/base/client'\nimport {ORDER_FIELD_NAME} from '../helpers/constants'\nimport initialRank from '../helpers/initialRank'\n\nconst client = sanityClient.withConfig({apiVersion: `2021-05-19`})\n\nexport const orderRankField = (config = {}) => {\n if (!config?.type) {\n throw new Error(\n `\n \"type\" not defined in orderRankField parameter object. \n Example: orderRankField({type: 'category'})\n `\n )\n }\n\n const {type} = config\n\n return {\n title: 'Order Rank',\n readOnly: true,\n hidden: true,\n ...config,\n name: ORDER_FIELD_NAME,\n type: 'string',\n initialValue: async () => {\n const lastDocOrderRank = await client.fetch(\n `*[_type == $type]|order(@[$order] desc)[0][$order]`,\n {type, order: ORDER_FIELD_NAME}\n )\n\n return initialRank(lastDocOrderRank)\n },\n }\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;;;;;;;;;;;AAEA,IAAMA,MAAM,GAAGC,eAAA,CAAaC,UAAb,CAAwB;EAACC,UAAU;AAAX,CAAxB,CAAf;;AAEO,IAAMC,cAAc,GAAG,SAAjBA,cAAiB,GAAiB;EAAA,IAAhBC,MAAgB,uEAAP,EAAO;;EAC7C,IAAI,EAACA,MAAD,aAACA,MAAD,eAACA,MAAM,CAAEC,IAAT,CAAJ,EAAmB;IACjB,MAAM,IAAIC,KAAJ,gIAAN;EAMD;;EAED,IAAOD,IAAP,GAAeD,MAAf,CAAOC,IAAP;EAEA;IACEE,KAAK,EAAE,YADT;IAEEC,QAAQ,EAAE,IAFZ;IAGEC,MAAM,EAAE;EAHV,GAIKL,MAJL;IAKEM,IAAI,EAAEC,2BALR;IAMEN,IAAI,EAAE,QANR;IAOEO,YAAY;MAAA,sCAAE,aAAY;QACxB,IAAMC,gBAAgB,SAASd,MAAM,CAACe,KAAP,uDAE7B;UAACT,IAAD;UAAOU,KAAK,EAAEJ;QAAd,CAF6B,CAA/B;QAKA,OAAO,IAAAK,oBAAA,EAAYH,gBAAZ,CAAP;MACD,CAPW;;MAAA;QAAA;MAAA;;MAAA;IAAA;EAPd;AAgBD,CA5BM"}
1
+ {"version":3,"file":"orderRankField.js","names":["client","sanityClient","withConfig","apiVersion","orderRankField","config","type","Error","title","readOnly","hidden","name","ORDER_FIELD_NAME","initialValue","lastDocOrderRank","fetch","order","initialRank"],"sources":["../../src/fields/orderRankField.js"],"sourcesContent":["import sanityClient from 'part:@sanity/base/client'\nimport {ORDER_FIELD_NAME} from '../helpers/constants'\nimport initialRank from '../helpers/initialRank'\n\nconst client = sanityClient.withConfig({apiVersion: `2021-05-19`})\n\nexport const orderRankField = (config = {}) => {\n if (!config?.type) {\n throw new Error(\n `\n \"type\" not defined in orderRankField parameter object. \n Example: orderRankField({type: 'category'})\n `\n )\n }\n\n const {type} = config\n\n return {\n title: 'Order Rank',\n readOnly: true,\n hidden: true,\n ...config,\n name: ORDER_FIELD_NAME,\n type: 'string',\n initialValue: async () => {\n const lastDocOrderRank = await client.fetch(\n `*[_type == $type]|order(@[$order] desc)[0][$order]`,\n {type, order: ORDER_FIELD_NAME}\n )\n\n return initialRank(lastDocOrderRank)\n },\n }\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AAAgD;AAAA;AAAA;AAAA;AAAA;AAAA;AAEhD,IAAMA,MAAM,GAAGC,eAAY,CAACC,UAAU,CAAC;EAACC,UAAU;AAAc,CAAC,CAAC;AAE3D,IAAMC,cAAc,GAAG,SAAjBA,cAAc,GAAoB;EAAA,IAAhBC,MAAM,uEAAG,CAAC,CAAC;EACxC,IAAI,EAACA,MAAM,aAANA,MAAM,eAANA,MAAM,CAAEC,IAAI,GAAE;IACjB,MAAM,IAAIC,KAAK,gIAKd;EACH;EAEA,IAAOD,IAAI,GAAID,MAAM,CAAdC,IAAI;EAEX;IACEE,KAAK,EAAE,YAAY;IACnBC,QAAQ,EAAE,IAAI;IACdC,MAAM,EAAE;EAAI,GACTL,MAAM;IACTM,IAAI,EAAEC,2BAAgB;IACtBN,IAAI,EAAE,QAAQ;IACdO,YAAY;MAAA,sCAAE,aAAY;QACxB,IAAMC,gBAAgB,SAASd,MAAM,CAACe,KAAK,uDAEzC;UAACT,IAAI;UAAEU,KAAK,EAAEJ;QAAgB,CAAC,CAChC;QAED,OAAO,IAAAK,oBAAW,EAACH,gBAAgB,CAAC;MACtC,CAAC;MAAA;QAAA;MAAA;MAAA;IAAA;EAAA;AAEL,CAAC;AAAA"}
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.orderRankOrdering = void 0;
7
-
8
7
  var _constants = require("../helpers/constants");
9
-
10
8
  var orderRankOrdering = {
11
9
  title: 'Ordered',
12
10
  name: 'ordered',
@@ -1 +1 @@
1
- {"version":3,"file":"orderRankOrdering.js","names":["orderRankOrdering","title","name","by","field","ORDER_FIELD_NAME","direction"],"sources":["../../src/fields/orderRankOrdering.js"],"sourcesContent":["import {ORDER_FIELD_NAME} from '../helpers/constants'\n\nexport const orderRankOrdering = {\n title: 'Ordered',\n name: 'ordered',\n by: [{field: ORDER_FIELD_NAME, direction: 'asc'}],\n}\n"],"mappings":";;;;;;;AAAA;;AAEO,IAAMA,iBAAiB,GAAG;EAC/BC,KAAK,EAAE,SADwB;EAE/BC,IAAI,EAAE,SAFyB;EAG/BC,EAAE,EAAE,CAAC;IAACC,KAAK,EAAEC,2BAAR;IAA0BC,SAAS,EAAE;EAArC,CAAD;AAH2B,CAA1B"}
1
+ {"version":3,"file":"orderRankOrdering.js","names":["orderRankOrdering","title","name","by","field","ORDER_FIELD_NAME","direction"],"sources":["../../src/fields/orderRankOrdering.js"],"sourcesContent":["import {ORDER_FIELD_NAME} from '../helpers/constants'\n\nexport const orderRankOrdering = {\n title: 'Ordered',\n name: 'ordered',\n by: [{field: ORDER_FIELD_NAME, direction: 'asc'}],\n}\n"],"mappings":";;;;;;AAAA;AAEO,IAAMA,iBAAiB,GAAG;EAC/BC,KAAK,EAAE,SAAS;EAChBC,IAAI,EAAE,SAAS;EACfC,EAAE,EAAE,CAAC;IAACC,KAAK,EAAEC,2BAAgB;IAAEC,SAAS,EAAE;EAAK,CAAC;AAClD,CAAC;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":["ORDER_FIELD_NAME"],"sources":["../../src/helpers/constants.js"],"sourcesContent":["export const ORDER_FIELD_NAME = `orderRank`\n"],"mappings":";;;;;;AAAO,IAAMA,gBAAgB,cAAtB"}
1
+ {"version":3,"file":"constants.js","names":["ORDER_FIELD_NAME"],"sources":["../../src/helpers/constants.js"],"sourcesContent":["export const ORDER_FIELD_NAME = `orderRank`\n"],"mappings":";;;;;;AAAO,IAAMA,gBAAgB,cAAc;AAAA"}
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = initialRank;
7
-
8
7
  var _lexorank = require("lexorank");
9
-
10
8
  // Use in initial value field by passing in the rank value of the last document
11
9
  // If not value passed, generate a sensibly low rank
12
10
  function initialRank() {
@@ -1 +1 @@
1
- {"version":3,"file":"initialRank.js","names":["initialRank","lastRankValue","lastRank","LexoRank","parse","min","nextRank","genNext","value"],"sources":["../../src/helpers/initialRank.js"],"sourcesContent":["import {LexoRank} from 'lexorank'\n\n// Use in initial value field by passing in the rank value of the last document\n// If not value passed, generate a sensibly low rank\nexport default function initialRank(lastRankValue = ``) {\n const lastRank = lastRankValue ? LexoRank.parse(lastRankValue) : LexoRank.min()\n const nextRank = lastRank.genNext().genNext()\n\n return nextRank.value\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;AACA;AACe,SAASA,WAAT,GAAyC;EAAA,IAApBC,aAAoB;EACtD,IAAMC,QAAQ,GAAGD,aAAa,GAAGE,kBAAA,CAASC,KAAT,CAAeH,aAAf,CAAH,GAAmCE,kBAAA,CAASE,GAAT,EAAjE;EACA,IAAMC,QAAQ,GAAGJ,QAAQ,CAACK,OAAT,GAAmBA,OAAnB,EAAjB;EAEA,OAAOD,QAAQ,CAACE,KAAhB;AACD"}
1
+ {"version":3,"file":"initialRank.js","names":["initialRank","lastRankValue","lastRank","LexoRank","parse","min","nextRank","genNext","value"],"sources":["../../src/helpers/initialRank.js"],"sourcesContent":["import {LexoRank} from 'lexorank'\n\n// Use in initial value field by passing in the rank value of the last document\n// If not value passed, generate a sensibly low rank\nexport default function initialRank(lastRankValue = ``) {\n const lastRank = lastRankValue ? LexoRank.parse(lastRankValue) : LexoRank.min()\n const nextRank = lastRank.genNext().genNext()\n\n return nextRank.value\n}\n"],"mappings":";;;;;;AAAA;AAEA;AACA;AACe,SAASA,WAAW,GAAqB;EAAA,IAApBC,aAAa;EAC/C,IAAMC,QAAQ,GAAGD,aAAa,GAAGE,kBAAQ,CAACC,KAAK,CAACH,aAAa,CAAC,GAAGE,kBAAQ,CAACE,GAAG,EAAE;EAC/E,IAAMC,QAAQ,GAAGJ,QAAQ,CAACK,OAAO,EAAE,CAACA,OAAO,EAAE;EAE7C,OAAOD,QAAQ,CAACE,KAAK;AACvB"}
@@ -4,38 +4,32 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.reorderDocuments = void 0;
7
-
8
7
  var _lexorank = require("lexorank");
9
-
10
8
  var _constants = require("./constants");
11
-
12
9
  function lexicographicalSort(a, b) {
13
10
  if (a[_constants.ORDER_FIELD_NAME] < b[_constants.ORDER_FIELD_NAME]) {
14
11
  return -1;
15
12
  }
16
-
17
13
  if (a[_constants.ORDER_FIELD_NAME] > b[_constants.ORDER_FIELD_NAME]) {
18
14
  return 1;
19
15
  }
20
-
21
16
  return 0;
22
- } // In lieu of actual *tests*, this is a table
17
+ }
18
+
19
+ // In lieu of actual *tests*, this is a table
23
20
  // to visualise the new order which if correct, shows:
24
21
  // 1. The `before` field (or start of the list)
25
22
  // 2. The inserted fields, in order
26
23
  // 3. The `after` document (or end of the list)
27
24
  // eslint-disable-next-line no-unused-vars
28
-
29
-
30
25
  function createManifest(_ref) {
31
26
  var _entities, _entities2;
32
-
33
27
  var entities = _ref.entities,
34
- selectedItems = _ref.selectedItems,
35
- isMovingUp = _ref.isMovingUp,
36
- curIndex = _ref.curIndex,
37
- nextIndex = _ref.nextIndex,
38
- prevIndex = _ref.prevIndex;
28
+ selectedItems = _ref.selectedItems,
29
+ isMovingUp = _ref.isMovingUp,
30
+ curIndex = _ref.curIndex,
31
+ nextIndex = _ref.nextIndex,
32
+ prevIndex = _ref.prevIndex;
39
33
  var table = [{
40
34
  name: "Before",
41
35
  title: curIndex === 0 ? "<<Start of List>>" : (_entities = entities[isMovingUp ? prevIndex : curIndex]) === null || _entities === void 0 ? void 0 : _entities.title,
@@ -51,74 +45,68 @@ function createManifest(_ref) {
51
45
  }];
52
46
  return table.sort(lexicographicalSort);
53
47
  }
54
-
55
48
  var reorderDocuments = _ref2 => {
56
49
  var entities = _ref2.entities,
57
- selectedIds = _ref2.selectedIds,
58
- source = _ref2.source,
59
- destination = _ref2.destination,
60
- _ref2$debug = _ref2.debug,
61
- debug = _ref2$debug === void 0 ? false : _ref2$debug;
50
+ selectedIds = _ref2.selectedIds,
51
+ source = _ref2.source,
52
+ destination = _ref2.destination,
53
+ _ref2$debug = _ref2.debug,
54
+ debug = _ref2$debug === void 0 ? false : _ref2$debug;
62
55
  var startIndex = source.index;
63
56
  var endIndex = destination.index;
64
57
  var isMovingUp = startIndex > endIndex;
65
58
  var selectedItems = entities.filter(item => selectedIds.includes(item._id));
66
59
  var message = ["Moved", selectedItems.length === 1 ? "1 Document" : "".concat(selectedItems.length, " Documents"), isMovingUp ? "up" : "down", "from position", "".concat(startIndex + 1, " to ").concat(endIndex + 1)].join(' ');
67
-
68
60
  var _entities$reduce = entities.reduce((acc, cur, curIndex) => {
69
- // Selected items get spread in below, so skip them here
70
- if (selectedIds.includes(cur._id)) {
71
- return {
72
- all: acc.all,
73
- selected: acc.selected
74
- };
75
- } // Drop seleced items in
76
-
77
-
78
- if (curIndex === endIndex) {
79
- var _entities$prevIndex, _entities$prevIndex2, _entities$nextIndex, _entities$nextIndex2;
80
-
81
- var prevIndex = curIndex - 1;
82
- var prevRank = (_entities$prevIndex = entities[prevIndex]) !== null && _entities$prevIndex !== void 0 && _entities$prevIndex[_constants.ORDER_FIELD_NAME] ? _lexorank.LexoRank.parse((_entities$prevIndex2 = entities[prevIndex]) === null || _entities$prevIndex2 === void 0 ? void 0 : _entities$prevIndex2[_constants.ORDER_FIELD_NAME]) : _lexorank.LexoRank.min();
83
-
84
- var curRank = _lexorank.LexoRank.parse(entities[curIndex][_constants.ORDER_FIELD_NAME]);
85
-
86
- var nextIndex = curIndex + 1;
87
- var nextRank = (_entities$nextIndex = entities[nextIndex]) !== null && _entities$nextIndex !== void 0 && _entities$nextIndex[_constants.ORDER_FIELD_NAME] ? _lexorank.LexoRank.parse((_entities$nextIndex2 = entities[nextIndex]) === null || _entities$nextIndex2 === void 0 ? void 0 : _entities$nextIndex2[_constants.ORDER_FIELD_NAME]) : _lexorank.LexoRank.max();
88
- var betweenRank = isMovingUp ? prevRank.between(curRank) : curRank.between(nextRank); // For each selected item, assign a new orderRank between now and next
89
-
90
- for (var selectedIndex = 0; selectedIndex < selectedItems.length; selectedIndex += 1) {
91
- selectedItems[selectedIndex][_constants.ORDER_FIELD_NAME] = betweenRank.value;
92
- betweenRank = isMovingUp ? betweenRank.between(curRank) : betweenRank.between(nextRank);
61
+ // Selected items get spread in below, so skip them here
62
+ if (selectedIds.includes(cur._id)) {
63
+ return {
64
+ all: acc.all,
65
+ selected: acc.selected
66
+ };
93
67
  }
94
68
 
69
+ // Drop seleced items in
70
+ if (curIndex === endIndex) {
71
+ var _entities$prevIndex, _entities$prevIndex2, _entities$nextIndex, _entities$nextIndex2;
72
+ var prevIndex = curIndex - 1;
73
+ var prevRank = (_entities$prevIndex = entities[prevIndex]) !== null && _entities$prevIndex !== void 0 && _entities$prevIndex[_constants.ORDER_FIELD_NAME] ? _lexorank.LexoRank.parse((_entities$prevIndex2 = entities[prevIndex]) === null || _entities$prevIndex2 === void 0 ? void 0 : _entities$prevIndex2[_constants.ORDER_FIELD_NAME]) : _lexorank.LexoRank.min();
74
+ var curRank = _lexorank.LexoRank.parse(entities[curIndex][_constants.ORDER_FIELD_NAME]);
75
+ var nextIndex = curIndex + 1;
76
+ var nextRank = (_entities$nextIndex = entities[nextIndex]) !== null && _entities$nextIndex !== void 0 && _entities$nextIndex[_constants.ORDER_FIELD_NAME] ? _lexorank.LexoRank.parse((_entities$nextIndex2 = entities[nextIndex]) === null || _entities$nextIndex2 === void 0 ? void 0 : _entities$nextIndex2[_constants.ORDER_FIELD_NAME]) : _lexorank.LexoRank.max();
77
+ var betweenRank = isMovingUp ? prevRank.between(curRank) : curRank.between(nextRank);
78
+
79
+ // For each selected item, assign a new orderRank between now and next
80
+ for (var selectedIndex = 0; selectedIndex < selectedItems.length; selectedIndex += 1) {
81
+ selectedItems[selectedIndex][_constants.ORDER_FIELD_NAME] = betweenRank.value;
82
+ betweenRank = isMovingUp ? betweenRank.between(curRank) : betweenRank.between(nextRank);
83
+ }
84
+ return {
85
+ // The `all` array gets sorted by order field later anyway
86
+ // so that this probably isn't necessary ¯\_(ツ)_/¯
87
+ all: isMovingUp ? [...acc.all, ...selectedItems, cur] : [...acc.all, cur, ...selectedItems],
88
+ selected: selectedItems
89
+ };
90
+ }
95
91
  return {
96
- // The `all` array gets sorted by order field later anyway
97
- // so that this probably isn't necessary ¯\_(ツ)_/¯
98
- all: isMovingUp ? [...acc.all, ...selectedItems, cur] : [...acc.all, cur, ...selectedItems],
99
- selected: selectedItems
92
+ all: [...acc.all, cur],
93
+ selected: acc.selected
100
94
  };
101
- }
102
-
103
- return {
104
- all: [...acc.all, cur],
105
- selected: acc.selected
106
- };
107
- }, {
108
- all: [],
109
- selected: []
110
- }),
111
- all = _entities$reduce.all,
112
- selected = _entities$reduce.selected;
113
-
95
+ }, {
96
+ all: [],
97
+ selected: []
98
+ }),
99
+ all = _entities$reduce.all,
100
+ selected = _entities$reduce.selected;
114
101
  var patches = selected.map(doc => {
115
102
  return [doc._id, {
116
103
  set: {
117
104
  [_constants.ORDER_FIELD_NAME]: doc[_constants.ORDER_FIELD_NAME]
118
105
  }
119
106
  }];
120
- }); // Safety-check to make sure everything is in order
107
+ });
121
108
 
109
+ // Safety-check to make sure everything is in order
122
110
  var allSorted = all.sort(lexicographicalSort);
123
111
  return {
124
112
  newOrder: allSorted,
@@ -126,6 +114,5 @@ var reorderDocuments = _ref2 => {
126
114
  message
127
115
  };
128
116
  };
129
-
130
117
  exports.reorderDocuments = reorderDocuments;
131
118
  //# sourceMappingURL=reorderDocuments.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reorderDocuments.js","names":["lexicographicalSort","a","b","ORDER_FIELD_NAME","createManifest","entities","selectedItems","isMovingUp","curIndex","nextIndex","prevIndex","table","name","title","order","map","item","itemIndex","length","sort","reorderDocuments","selectedIds","source","destination","debug","startIndex","index","endIndex","filter","includes","_id","message","join","reduce","acc","cur","all","selected","prevRank","LexoRank","parse","min","curRank","nextRank","max","betweenRank","between","selectedIndex","value","patches","doc","set","allSorted","newOrder"],"sources":["../../src/helpers/reorderDocuments.js"],"sourcesContent":["import {LexoRank} from 'lexorank'\nimport {ORDER_FIELD_NAME} from './constants'\n\nfunction lexicographicalSort(a, b) {\n if (a[ORDER_FIELD_NAME] < b[ORDER_FIELD_NAME]) {\n return -1\n }\n if (a[ORDER_FIELD_NAME] > b[ORDER_FIELD_NAME]) {\n return 1\n }\n return 0\n}\n\n// In lieu of actual *tests*, this is a table\n// to visualise the new order which if correct, shows:\n// 1. The `before` field (or start of the list)\n// 2. The inserted fields, in order\n// 3. The `after` document (or end of the list)\n// eslint-disable-next-line no-unused-vars\nfunction createManifest({entities, selectedItems, isMovingUp, curIndex, nextIndex, prevIndex}) {\n const table = [\n {\n name: `Before`,\n title:\n curIndex === 0 ? `<<Start of List>>` : entities[isMovingUp ? prevIndex : curIndex]?.title,\n order: curIndex === 0 ? `000` : entities[isMovingUp ? prevIndex : curIndex][ORDER_FIELD_NAME],\n },\n ...selectedItems.map((item, itemIndex) => ({\n name: itemIndex,\n title: item?.title,\n order: item[ORDER_FIELD_NAME],\n })),\n {\n name: `After`,\n title:\n curIndex === entities.length - 1\n ? `<<End of List>>`\n : entities[isMovingUp ? curIndex : nextIndex]?.title,\n order:\n curIndex === entities.length - 1\n ? `zzz`\n : entities[isMovingUp ? curIndex : nextIndex][ORDER_FIELD_NAME],\n },\n ]\n\n return table.sort(lexicographicalSort)\n}\n\nexport const reorderDocuments = ({entities, selectedIds, source, destination, debug = false}) => {\n const startIndex = source.index\n const endIndex = destination.index\n const isMovingUp = startIndex > endIndex\n const selectedItems = entities.filter((item) => selectedIds.includes(item._id))\n const message = [\n `Moved`,\n selectedItems.length === 1 ? `1 Document` : `${selectedItems.length} Documents`,\n isMovingUp ? `up` : `down`,\n `from position`,\n `${startIndex + 1} to ${endIndex + 1}`,\n ].join(' ')\n\n const {all, selected} = entities.reduce(\n (acc, cur, curIndex) => {\n // Selected items get spread in below, so skip them here\n if (selectedIds.includes(cur._id)) {\n return {all: acc.all, selected: acc.selected}\n }\n\n // Drop seleced items in\n if (curIndex === endIndex) {\n const prevIndex = curIndex - 1\n const prevRank = entities[prevIndex]?.[ORDER_FIELD_NAME]\n ? LexoRank.parse(entities[prevIndex]?.[ORDER_FIELD_NAME])\n : LexoRank.min()\n\n const curRank = LexoRank.parse(entities[curIndex][ORDER_FIELD_NAME])\n\n const nextIndex = curIndex + 1\n const nextRank = entities[nextIndex]?.[ORDER_FIELD_NAME]\n ? LexoRank.parse(entities[nextIndex]?.[ORDER_FIELD_NAME])\n : LexoRank.max()\n\n let betweenRank = isMovingUp ? prevRank.between(curRank) : curRank.between(nextRank)\n\n // For each selected item, assign a new orderRank between now and next\n for (let selectedIndex = 0; selectedIndex < selectedItems.length; selectedIndex += 1) {\n selectedItems[selectedIndex][ORDER_FIELD_NAME] = betweenRank.value\n betweenRank = isMovingUp ? betweenRank.between(curRank) : betweenRank.between(nextRank)\n }\n\n return {\n // The `all` array gets sorted by order field later anyway\n // so that this probably isn't necessary ¯\\_(ツ)_/¯\n all: isMovingUp\n ? [...acc.all, ...selectedItems, cur]\n : [...acc.all, cur, ...selectedItems],\n selected: selectedItems,\n }\n }\n\n return {all: [...acc.all, cur], selected: acc.selected}\n },\n {all: [], selected: []}\n )\n\n const patches = selected.map((doc) => {\n return [\n doc._id,\n {\n set: {\n [ORDER_FIELD_NAME]: doc[ORDER_FIELD_NAME],\n },\n },\n ]\n })\n\n // Safety-check to make sure everything is in order\n const allSorted = all.sort(lexicographicalSort)\n\n return {newOrder: allSorted, patches, message}\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEA,SAASA,mBAAT,CAA6BC,CAA7B,EAAgCC,CAAhC,EAAmC;EACjC,IAAID,CAAC,CAACE,2BAAD,CAAD,GAAsBD,CAAC,CAACC,2BAAD,CAA3B,EAA+C;IAC7C,OAAO,CAAC,CAAR;EACD;;EACD,IAAIF,CAAC,CAACE,2BAAD,CAAD,GAAsBD,CAAC,CAACC,2BAAD,CAA3B,EAA+C;IAC7C,OAAO,CAAP;EACD;;EACD,OAAO,CAAP;AACD,C,CAED;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,cAAT,OAA+F;EAAA;;EAAA,IAAtEC,QAAsE,QAAtEA,QAAsE;EAAA,IAA5DC,aAA4D,QAA5DA,aAA4D;EAAA,IAA7CC,UAA6C,QAA7CA,UAA6C;EAAA,IAAjCC,QAAiC,QAAjCA,QAAiC;EAAA,IAAvBC,SAAuB,QAAvBA,SAAuB;EAAA,IAAZC,SAAY,QAAZA,SAAY;EAC7F,IAAMC,KAAK,GAAG,CACZ;IACEC,IAAI,UADN;IAEEC,KAAK,EACHL,QAAQ,KAAK,CAAb,sCAAuCH,QAAQ,CAACE,UAAU,GAAGG,SAAH,GAAeF,QAA1B,CAA/C,8CAAuC,UAA6CK,KAHxF;IAIEC,KAAK,EAAEN,QAAQ,KAAK,CAAb,WAA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AACjB,IAAJ,CAASnB,mBAAT,CAAlB;EAEA,OAAO;IAACqD,QAAQ,EAAED,SAAX;IAAsBH,OAAtB;IAA+BlB;EAA/B,CAAP;AACD,CAxEM"}
1
+ {"version":3,"file":"reorderDocuments.js","names":["lexicographicalSort","a","b","ORDER_FIELD_NAME","createManifest","entities","selectedItems","isMovingUp","curIndex","nextIndex","prevIndex","table","name","title","order","map","item","itemIndex","length","sort","reorderDocuments","selectedIds","source","destination","debug","startIndex","index","endIndex","filter","includes","_id","message","join","reduce","acc","cur","all","selected","prevRank","LexoRank","parse","min","curRank","nextRank","max","betweenRank","between","selectedIndex","value","patches","doc","set","allSorted","newOrder"],"sources":["../../src/helpers/reorderDocuments.js"],"sourcesContent":["import {LexoRank} from 'lexorank'\nimport {ORDER_FIELD_NAME} from './constants'\n\nfunction lexicographicalSort(a, b) {\n if (a[ORDER_FIELD_NAME] < b[ORDER_FIELD_NAME]) {\n return -1\n }\n if (a[ORDER_FIELD_NAME] > b[ORDER_FIELD_NAME]) {\n return 1\n }\n return 0\n}\n\n// In lieu of actual *tests*, this is a table\n// to visualise the new order which if correct, shows:\n// 1. The `before` field (or start of the list)\n// 2. The inserted fields, in order\n// 3. The `after` document (or end of the list)\n// eslint-disable-next-line no-unused-vars\nfunction createManifest({entities, selectedItems, isMovingUp, curIndex, nextIndex, prevIndex}) {\n const table = [\n {\n name: `Before`,\n title:\n curIndex === 0 ? `<<Start of List>>` : entities[isMovingUp ? prevIndex : curIndex]?.title,\n order: curIndex === 0 ? `000` : entities[isMovingUp ? prevIndex : curIndex][ORDER_FIELD_NAME],\n },\n ...selectedItems.map((item, itemIndex) => ({\n name: itemIndex,\n title: item?.title,\n order: item[ORDER_FIELD_NAME],\n })),\n {\n name: `After`,\n title:\n curIndex === entities.length - 1\n ? `<<End of List>>`\n : entities[isMovingUp ? curIndex : nextIndex]?.title,\n order:\n curIndex === entities.length - 1\n ? `zzz`\n : entities[isMovingUp ? curIndex : nextIndex][ORDER_FIELD_NAME],\n },\n ]\n\n return table.sort(lexicographicalSort)\n}\n\nexport const reorderDocuments = ({entities, selectedIds, source, destination, debug = false}) => {\n const startIndex = source.index\n const endIndex = destination.index\n const isMovingUp = startIndex > endIndex\n const selectedItems = entities.filter((item) => selectedIds.includes(item._id))\n const message = [\n `Moved`,\n selectedItems.length === 1 ? `1 Document` : `${selectedItems.length} Documents`,\n isMovingUp ? `up` : `down`,\n `from position`,\n `${startIndex + 1} to ${endIndex + 1}`,\n ].join(' ')\n\n const {all, selected} = entities.reduce(\n (acc, cur, curIndex) => {\n // Selected items get spread in below, so skip them here\n if (selectedIds.includes(cur._id)) {\n return {all: acc.all, selected: acc.selected}\n }\n\n // Drop seleced items in\n if (curIndex === endIndex) {\n const prevIndex = curIndex - 1\n const prevRank = entities[prevIndex]?.[ORDER_FIELD_NAME]\n ? LexoRank.parse(entities[prevIndex]?.[ORDER_FIELD_NAME])\n : LexoRank.min()\n\n const curRank = LexoRank.parse(entities[curIndex][ORDER_FIELD_NAME])\n\n const nextIndex = curIndex + 1\n const nextRank = entities[nextIndex]?.[ORDER_FIELD_NAME]\n ? LexoRank.parse(entities[nextIndex]?.[ORDER_FIELD_NAME])\n : LexoRank.max()\n\n let betweenRank = isMovingUp ? prevRank.between(curRank) : curRank.between(nextRank)\n\n // For each selected item, assign a new orderRank between now and next\n for (let selectedIndex = 0; selectedIndex < selectedItems.length; selectedIndex += 1) {\n selectedItems[selectedIndex][ORDER_FIELD_NAME] = betweenRank.value\n betweenRank = isMovingUp ? betweenRank.between(curRank) : betweenRank.between(nextRank)\n }\n\n return {\n // The `all` array gets sorted by order field later anyway\n // so that this probably isn't necessary ¯\\_(ツ)_/¯\n all: isMovingUp\n ? [...acc.all, ...selectedItems, cur]\n : [...acc.all, cur, ...selectedItems],\n selected: selectedItems,\n }\n }\n\n return {all: [...acc.all, cur], selected: acc.selected}\n },\n {all: [], selected: []}\n )\n\n const patches = selected.map((doc) => {\n return [\n doc._id,\n {\n set: {\n [ORDER_FIELD_NAME]: doc[ORDER_FIELD_NAME],\n },\n },\n ]\n })\n\n // Safety-check to make sure everything is in order\n const allSorted = all.sort(lexicographicalSort)\n\n return {newOrder: allSorted, patches, message}\n}\n"],"mappings":";;;;;;AAAA;AACA;AAEA,SAASA,mBAAmB,CAACC,CAAC,EAAEC,CAAC,EAAE;EACjC,IAAID,CAAC,CAACE,2BAAgB,CAAC,GAAGD,CAAC,CAACC,2BAAgB,CAAC,EAAE;IAC7C,OAAO,CAAC,CAAC;EACX;EACA,IAAIF,CAAC,CAACE,2BAAgB,CAAC,GAAGD,CAAC,CAACC,2BAAgB,CAAC,EAAE;IAC7C,OAAO,CAAC;EACV;EACA,OAAO,CAAC;AACV;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,cAAc,OAAwE;EAAA;EAAA,IAAtEC,QAAQ,QAARA,QAAQ;IAAEC,aAAa,QAAbA,aAAa;IAAEC,UAAU,QAAVA,UAAU;IAAEC,QAAQ,QAARA,QAAQ;IAAEC,SAAS,QAATA,SAAS;IAAEC,SAAS,QAATA,SAAS;EAC1F,IAAMC,KAAK,GAAG,CACZ;IACEC,IAAI,UAAU;IACdC,KAAK,EACHL,QAAQ,KAAK,CAAC,sCAAyBH,QAAQ,CAACE,UAAU,GAAGG,SAAS,GAAGF,QAAQ,CAAC,8CAA3C,UAA6CK,KAAK;IAC3FC,KAAK,EAAEN,QAAQ,KAAK,CAAC,WAAWH,QAAQ,CAACE,UAAU,GAAGG,SAAS,GAAGF,QAAQ,CAAC,CAACL,2BAAgB;EAC9F,CAAC,EACD,GAAGG,aAAa,CAACS,GAAG,CAAC,CAACC,IAAI,EAAEC,SAAS,MAAM;IACzCL,IAAI,EAAEK,SAAS;IACfJ,KAAK,EAAEG,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEH,KAAK;IAClBC,KAAK,EAAEE,IAAI,CAACb,2BAAgB;EAC9B,CAAC,CAAC,CAAC,EACH;IACES,IAAI,SAAS;IACbC,KAAK,EACH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C;QACzF;QAEA,OAAO;UACL;UACA;UACAP,GAAG,EAAE7B,UAAU,GACX,CAAC,GAAG2B,GAAG,CAACE,GAAG,EAAE,GAAG9B,aAAa,EAAE6B,GAAG,CAAC,GACnC,CAAC,GAAGD,GAAG,CAACE,GAAG,EAAED,GAAG,EAAE,GAAG7B,aAAa,CAAC;UACvC+B,QAAQ,EAAE/B;QACZ,CAAC;MACH;MAEA,OAAO;QAAC8B,GAAG,EAAE,CAAC,GAAGF,GAAG,CAACE,GAAG,EAAED,GAAG,CAAC;QAAEE,QAAQ,EAAEH,GAAG,CAACG;MAAQ,CAAC;IACzD,CAAC,EACD;MAACD,GAAG,EAAE,EAAE;MAAEC,QAAQ,EAAE;IAAE,CAAC,CACxB;IA1CMD,GAAG,oBAAHA,GAAG;IAAEC,QAAQ,oBAARA,QAAQ;EA4CpB,IAAMY,OAAO,GAAGZ,QAAQ,CAACtB,GAAG,CAAEmC,GAAG,IAAK;IACpC,OAAO,CACLA,GAAG,CAACpB,GAAG,EACP;MACEqB,GAAG,EAAE;QACH,CAAChD,2BAAgB,GAAG+C,GAAG,CAAC/C,2BAAgB;MAC1C;IACF,CAAC,CACF;EACH,CAAC,CAAC;;EAEF;EACA,IAAMiD,SAAS,GAAGhB,GAAG,CAACjB,IAAI,CAACnB,mBAAmB,CAAC;EAE/C,OAAO;IAACqD,QAAQ,EAAED,SAAS;IAAEH,OAAO;IAAElB;EAAO,CAAC;AAChD,CAAC;AAAA"}
@@ -4,29 +4,21 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.resetOrder = resetOrder;
7
-
8
7
  var _lexorank = require("lexorank");
9
-
10
8
  var _client = _interopRequireDefault(require("part:@sanity/base/client"));
11
-
12
9
  var _constants = require("./constants");
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
11
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
17
-
18
12
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
19
-
20
13
  var client = _client.default.withConfig({
21
14
  apiVersion: '2021-09-01'
22
- }); // Function to wipe and re-do ordering with LexoRank
23
- // Will at least attempt to start with the current order
24
-
15
+ });
25
16
 
17
+ // Function to wipe and re-do ordering with LexoRank
18
+ // Will at least attempt to start with the current order
26
19
  function resetOrder() {
27
20
  return _resetOrder.apply(this, arguments);
28
21
  }
29
-
30
22
  function _resetOrder() {
31
23
  _resetOrder = _asyncToGenerator(function* () {
32
24
  var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
@@ -36,15 +28,11 @@ function _resetOrder() {
36
28
  order: _constants.ORDER_FIELD_NAME
37
29
  };
38
30
  var documents = yield client.fetch(query, queryParams);
39
-
40
31
  if (!documents.length) {
41
32
  return null;
42
33
  }
43
-
44
34
  var transaction = client.transaction();
45
-
46
35
  var aLexoRank = _lexorank.LexoRank.min();
47
-
48
36
  for (var index = 0; index < documents.length; index += 1) {
49
37
  // Generate next rank before even the first document so there's room to move!
50
38
  aLexoRank = aLexoRank.genNext().genNext();
@@ -54,7 +42,6 @@ function _resetOrder() {
54
42
  }
55
43
  });
56
44
  }
57
-
58
45
  return transaction.commit().then(update => update).catch(err => err);
59
46
  });
60
47
  return _resetOrder.apply(this, arguments);
@@ -1 +1 @@
1
- {"version":3,"file":"resetOrder.js","names":["client","sanityClient","withConfig","apiVersion","resetOrder","type","query","queryParams","order","ORDER_FIELD_NAME","documents","fetch","length","transaction","aLexoRank","LexoRank","min","index","genNext","patch","set","value","commit","then","update","catch","err"],"sources":["../../src/helpers/resetOrder.js"],"sourcesContent":["import {LexoRank} from 'lexorank'\nimport sanityClient from 'part:@sanity/base/client'\nimport {ORDER_FIELD_NAME} from './constants'\n\nconst client = sanityClient.withConfig({\n apiVersion: '2021-09-01',\n})\n\n// Function to wipe and re-do ordering with LexoRank\n// Will at least attempt to start with the current order\nexport async function resetOrder(type = ``) {\n const query = `*[_type == $type]|order(@[$order] asc)._id`\n const queryParams = {type, order: ORDER_FIELD_NAME}\n const documents = await client.fetch(query, queryParams)\n\n if (!documents.length) {\n return null\n }\n\n const transaction = client.transaction()\n let aLexoRank = LexoRank.min()\n\n for (let index = 0; index < documents.length; index += 1) {\n // Generate next rank before even the first document so there's room to move!\n aLexoRank = aLexoRank.genNext().genNext()\n\n transaction.patch(documents[index], {\n set: {[ORDER_FIELD_NAME]: aLexoRank.value},\n })\n }\n\n return transaction\n .commit()\n .then((update) => update)\n .catch((err) => err)\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;;;;;AAEA,IAAMA,MAAM,GAAGC,eAAA,CAAaC,UAAb,CAAwB;EACrCC,UAAU,EAAE;AADyB,CAAxB,CAAf,C,CAIA;AACA;;;SACsBC,U;;;;;kCAAf,aAAqC;IAAA,IAAXC,IAAW;IAC1C,IAAMC,KAAK,+CAAX;IACA,IAAMC,WAAW,GAAG;MAACF,IAAD;MAAOG,KAAK,EAAEC;IAAd,CAApB;IACA,IAAMC,SAAS,SAASV,MAAM,CAACW,KAAP,CAAaL,KAAb,EAAoBC,WAApB,CAAxB;;IAEA,IAAI,CAACG,SAAS,CAACE,MAAf,EAAuB;MACrB,OAAO,IAAP;IACD;;IAED,IAAMC,WAAW,GAAGb,MAAM,CAACa,WAAP,EAApB;;IACA,IAAIC,SAAS,GAAGC,kBAAA,CAASC,GAAT,EAAhB;;IAEA,KAAK,IAAIC,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGP,SAAS,CAACE,MAAtC,EAA8CK,KAAK,IAAI,CAAvD,EAA0D;MACxD;MACAH,SAAS,GAAGA,SAAS,CAACI,OAAV,GAAoBA,OAApB,EAAZ;MAEAL,WAAW,CAACM,KAAZ,CAAkBT,SAAS,CAACO,KAAD,CAA3B,EAAoC;QAClCG,GAAG,EAAE;UAAC,CAACX,2BAAD,GAAoBK,SAAS,CAACO;QAA/B;MAD6B,CAApC;IAGD;;IAED,OAAOR,WAAW,CACfS,MADI,GAEJC,IAFI,CAEEC,MAAD,IAAYA,MAFb,EAGJC,KAHI,CAGGC,GAAD,IAASA,GAHX,CAAP;EAID,C"}
1
+ {"version":3,"file":"resetOrder.js","names":["client","sanityClient","withConfig","apiVersion","resetOrder","type","query","queryParams","order","ORDER_FIELD_NAME","documents","fetch","length","transaction","aLexoRank","LexoRank","min","index","genNext","patch","set","value","commit","then","update","catch","err"],"sources":["../../src/helpers/resetOrder.js"],"sourcesContent":["import {LexoRank} from 'lexorank'\nimport sanityClient from 'part:@sanity/base/client'\nimport {ORDER_FIELD_NAME} from './constants'\n\nconst client = sanityClient.withConfig({\n apiVersion: '2021-09-01',\n})\n\n// Function to wipe and re-do ordering with LexoRank\n// Will at least attempt to start with the current order\nexport async function resetOrder(type = ``) {\n const query = `*[_type == $type]|order(@[$order] asc)._id`\n const queryParams = {type, order: ORDER_FIELD_NAME}\n const documents = await client.fetch(query, queryParams)\n\n if (!documents.length) {\n return null\n }\n\n const transaction = client.transaction()\n let aLexoRank = LexoRank.min()\n\n for (let index = 0; index < documents.length; index += 1) {\n // Generate next rank before even the first document so there's room to move!\n aLexoRank = aLexoRank.genNext().genNext()\n\n transaction.patch(documents[index], {\n set: {[ORDER_FIELD_NAME]: aLexoRank.value},\n })\n }\n\n return transaction\n .commit()\n .then((update) => update)\n .catch((err) => err)\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AAA4C;AAAA;AAAA;AAE5C,IAAMA,MAAM,GAAGC,eAAY,CAACC,UAAU,CAAC;EACrCC,UAAU,EAAE;AACd,CAAC,CAAC;;AAEF;AACA;AAAA,SACsBC,UAAU;EAAA;AAAA;AAAA;EAAA,gCAAzB,aAAqC;IAAA,IAAXC,IAAI;IACnC,IAAMC,KAAK,+CAA+C;IAC1D,IAAMC,WAAW,GAAG;MAACF,IAAI;MAAEG,KAAK,EAAEC;IAAgB,CAAC;IACnD,IAAMC,SAAS,SAASV,MAAM,CAACW,KAAK,CAACL,KAAK,EAAEC,WAAW,CAAC;IAExD,IAAI,CAACG,SAAS,CAACE,MAAM,EAAE;MACrB,OAAO,IAAI;IACb;IAEA,IAAMC,WAAW,GAAGb,MAAM,CAACa,WAAW,EAAE;IACxC,IAAIC,SAAS,GAAGC,kBAAQ,CAACC,GAAG,EAAE;IAE9B,KAAK,IAAIC,KAAK,GAAG,CAAC,EAAEA,KAAK,GAAGP,SAAS,CAACE,MAAM,EAAEK,KAAK,IAAI,CAAC,EAAE;MACxD;MACAH,SAAS,GAAGA,SAAS,CAACI,OAAO,EAAE,CAACA,OAAO,EAAE;MAEzCL,WAAW,CAACM,KAAK,CAACT,SAAS,CAACO,KAAK,CAAC,EAAE;QAClCG,GAAG,EAAE;UAAC,CAACX,2BAAgB,GAAGK,SAAS,CAACO;QAAK;MAC3C,CAAC,CAAC;IACJ;IAEA,OAAOR,WAAW,CACfS,MAAM,EAAE,CACRC,IAAI,CAAEC,MAAM,IAAKA,MAAM,CAAC,CACxBC,KAAK,CAAEC,GAAG,IAAKA,GAAG,CAAC;EACxB,CAAC;EAAA;AAAA"}
package/lib/index.js CHANGED
@@ -21,10 +21,7 @@ Object.defineProperty(exports, "orderableDocumentListDeskItem", {
21
21
  return _orderableDocumentListDeskItem.orderableDocumentListDeskItem;
22
22
  }
23
23
  });
24
-
25
24
  var _orderRankField = require("./fields/orderRankField");
26
-
27
25
  var _orderRankOrdering = require("./fields/orderRankOrdering");
28
-
29
26
  var _orderableDocumentListDeskItem = require("./desk-structure/orderableDocumentListDeskItem");
30
27
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.js"],"sourcesContent":["import {orderRankField} from './fields/orderRankField'\nimport {orderRankOrdering} from './fields/orderRankOrdering'\nimport {orderableDocumentListDeskItem} from './desk-structure/orderableDocumentListDeskItem'\n\nexport {orderRankField, orderRankOrdering, orderableDocumentListDeskItem}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.js"],"sourcesContent":["import {orderRankField} from './fields/orderRankField'\nimport {orderRankOrdering} from './fields/orderRankOrdering'\nimport {orderableDocumentListDeskItem} from './desk-structure/orderableDocumentListDeskItem'\n\nexport {orderRankField, orderRankOrdering, orderableDocumentListDeskItem}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA"}
package/package.json CHANGED
@@ -1,32 +1,36 @@
1
1
  {
2
2
  "name": "@sanity/orderable-document-list",
3
- "version": "0.0.9",
3
+ "version": "0.1.0",
4
4
  "description": "Drag-and-drop Document Ordering without leaving the Editing surface",
5
+ "keywords": [
6
+ "sanity",
7
+ "sanity-plugin"
8
+ ],
9
+ "homepage": "https://github.com/sanity-io/sanity-plugin-orderable-document-list#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/sanity-io/sanity-plugin-orderable-document-list/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+ssh://git@github.com/sanity-io/sanity-plugin-orderable-document-list"
16
+ },
17
+ "license": "MIT",
18
+ "author": "Sanity.io <hello@sanity.io>",
5
19
  "main": "lib/index.js",
6
20
  "scripts": {
7
21
  "build": "sanipack build",
8
- "watch": "sanipack build --watch",
9
22
  "_postinstall": "husky install",
23
+ "lint": "eslint .",
24
+ "lint:fix": "eslint . --fix",
10
25
  "prepublishOnly": "pinst --disable && sanipack build && sanipack verify",
11
26
  "postpublish": "pinst --enable",
12
- "lint": "eslint .",
13
- "lint:fix": "eslint . --fix"
27
+ "watch": "sanipack build --watch"
14
28
  },
15
29
  "husky": {
16
30
  "hooks": {
17
31
  "pre-commit": "npm run lint:fix"
18
32
  }
19
33
  },
20
- "repository": {
21
- "type": "git",
22
- "url": "git+ssh://git@github.com/sanity-io/sanity-plugin-orderable-document-list"
23
- },
24
- "keywords": [
25
- "sanity",
26
- "sanity-plugin"
27
- ],
28
- "author": "Sanity.io <hello@sanity.io>",
29
- "license": "MIT",
30
34
  "dependencies": {
31
35
  "@sanity/icons": "^1.2.1",
32
36
  "@sanity/ui": "^0.37.6",
@@ -35,6 +39,10 @@
35
39
  "react-beautiful-dnd": "^13.1.0"
36
40
  },
37
41
  "devDependencies": {
42
+ "@commitlint/cli": "^17.1.2",
43
+ "@commitlint/config-conventional": "^17.1.0",
44
+ "@sanity/desk-tool": "^2.29.0",
45
+ "@sanity/semantic-release-preset": "^2.0.1",
38
46
  "@typescript-eslint/eslint-plugin": "^4.32.0",
39
47
  "@typescript-eslint/parser": "^4.32.0",
40
48
  "autoprefixer": "^10.3.6",
@@ -53,14 +61,11 @@
53
61
  "husky": "^7.0.2",
54
62
  "pinst": "^2.1.6",
55
63
  "prettier": "^2.4.1",
56
- "sanipack": "^2.1.0"
64
+ "sanipack": "^2.1.0",
65
+ "react": "^17.0.2"
57
66
  },
58
67
  "peerDependencies": {
59
68
  "@sanity/desk-tool": "^2.29.0",
60
69
  "react": "^17.0.2"
61
- },
62
- "bugs": {
63
- "url": "https://github.com/sanity-io/sanity-plugin-orderable-document-list/issues"
64
- },
65
- "homepage": "https://github.com/sanity-io/sanity-plugin-orderable-document-list#readme"
70
+ }
66
71
  }
@@ -1,8 +1,7 @@
1
1
  import PropTypes from 'prop-types'
2
- import React, {useMemo, useEffect} from 'react'
2
+ import React, {useEffect, useMemo} from 'react'
3
3
  import schema from 'part:@sanity/base/schema'
4
4
  import {useToast} from '@sanity/ui'
5
- import {PaneRouterContext} from '@sanity/desk-tool'
6
5
 
7
6
  import DocumentListQuery from './DocumentListQuery'
8
7
  import {OrderableContext} from './OrderableContext'
@@ -53,7 +52,7 @@ export default function DocumentListWrapper({
53
52
  if (!typeSchema.fields.some((field) => field?.name === ORDER_FIELD_NAME)) {
54
53
  return (
55
54
  <>
56
- Schema <code>{type}</code> must have an <code>order</code> field of type{' '}
55
+ Schema <code>{type}</code> must have an <code>{ORDER_FIELD_NAME}</code> field of type{' '}
57
56
  <code>string</code>
58
57
  </>
59
58
  )
@@ -13,10 +13,10 @@ export function orderableDocumentListDeskItem(config = {}) {
13
13
  `)
14
14
  }
15
15
 
16
- const {type, filter, params, title, icon} = config
16
+ const {type, filter, params, title, icon, id} = config
17
17
 
18
18
  const listTitle = title ?? `Orderable ${type}`
19
- const listId = `orderable-${type}`
19
+ const listId = id ?? `orderable-${type}`
20
20
  const listIcon = icon ?? SortIcon
21
21
  const typeTitle = schema.get(type)?.title ?? type
22
22