solid-ui 2.4.14-842f7f26 → 2.4.14-bbf45639

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 (260) hide show
  1. package/LICENSE.md +0 -0
  2. package/README.md +0 -0
  3. package/lib/acl/access-controller.d.ts +0 -0
  4. package/lib/acl/access-controller.d.ts.map +0 -0
  5. package/lib/acl/access-controller.js +334 -441
  6. package/lib/acl/access-controller.js.map +1 -1
  7. package/lib/acl/access-groups.d.ts +1 -2
  8. package/lib/acl/access-groups.d.ts.map +1 -1
  9. package/lib/acl/access-groups.js +348 -492
  10. package/lib/acl/access-groups.js.map +1 -1
  11. package/lib/acl/acl-control.d.ts +0 -0
  12. package/lib/acl/acl-control.d.ts.map +0 -0
  13. package/lib/acl/acl-control.js +168 -198
  14. package/lib/acl/acl-control.js.map +1 -1
  15. package/lib/acl/acl.d.ts +1 -2
  16. package/lib/acl/acl.d.ts.map +1 -1
  17. package/lib/acl/acl.js +446 -459
  18. package/lib/acl/acl.js.map +1 -1
  19. package/lib/acl/add-agent-buttons.d.ts +0 -0
  20. package/lib/acl/add-agent-buttons.d.ts.map +0 -0
  21. package/lib/acl/add-agent-buttons.js +318 -515
  22. package/lib/acl/add-agent-buttons.js.map +1 -1
  23. package/lib/acl/index.d.ts +0 -0
  24. package/lib/acl/index.d.ts.map +0 -0
  25. package/lib/acl/index.js +27 -35
  26. package/lib/acl/index.js.map +1 -1
  27. package/lib/acl/styles.d.ts +0 -0
  28. package/lib/acl/styles.d.ts.map +0 -0
  29. package/lib/acl/styles.js +84 -90
  30. package/lib/acl/styles.js.map +1 -1
  31. package/lib/acl/types.d.ts +0 -0
  32. package/lib/acl/types.d.ts.map +0 -0
  33. package/lib/acl/types.js +5 -4
  34. package/lib/acl/types.js.map +1 -1
  35. package/lib/authn/authSession.d.ts +0 -0
  36. package/lib/authn/authSession.d.ts.map +0 -0
  37. package/lib/authn/authSession.js +14 -21
  38. package/lib/authn/authSession.js.map +1 -1
  39. package/lib/authn/authn.d.ts +0 -0
  40. package/lib/authn/authn.d.ts.map +0 -0
  41. package/lib/authn/authn.js +1391 -1935
  42. package/lib/authn/authn.js.map +1 -1
  43. package/lib/authn/config-default.js +0 -0
  44. package/lib/authn/config-default.js.map +0 -0
  45. package/lib/authn/index.d.ts +0 -0
  46. package/lib/authn/index.d.ts.map +0 -0
  47. package/lib/authn/index.js +26 -37
  48. package/lib/authn/index.js.map +1 -1
  49. package/lib/authn/signup.js +0 -0
  50. package/lib/authn/signup.js.map +0 -0
  51. package/lib/authn/types.d.ts +0 -0
  52. package/lib/authn/types.d.ts.map +0 -0
  53. package/lib/authn/types.js +1 -4
  54. package/lib/authn/types.js.map +1 -1
  55. package/lib/chat/bookmarks.js +0 -0
  56. package/lib/chat/bookmarks.js.map +0 -0
  57. package/lib/chat/dateFolder.js +0 -0
  58. package/lib/chat/dateFolder.js.map +0 -0
  59. package/lib/chat/infinite.js +0 -0
  60. package/lib/chat/infinite.js.map +0 -0
  61. package/lib/chat/message.js +0 -0
  62. package/lib/chat/message.js.map +0 -0
  63. package/lib/chat/messageTools.js +0 -0
  64. package/lib/chat/messageTools.js.map +0 -0
  65. package/lib/chat/thread.js +0 -0
  66. package/lib/chat/thread.js.map +0 -0
  67. package/lib/create/create.d.ts +0 -0
  68. package/lib/create/create.d.ts.map +0 -0
  69. package/lib/create/create.js +209 -214
  70. package/lib/create/create.js.map +1 -1
  71. package/lib/create/index.d.ts +0 -0
  72. package/lib/create/index.d.ts.map +0 -0
  73. package/lib/create/index.js +4 -10
  74. package/lib/create/index.js.map +1 -1
  75. package/lib/create/types.d.ts +0 -0
  76. package/lib/create/types.d.ts.map +0 -0
  77. package/lib/create/types.js +1 -4
  78. package/lib/create/types.js.map +1 -1
  79. package/lib/debug.d.ts +0 -0
  80. package/lib/debug.d.ts.map +0 -0
  81. package/lib/debug.js +30 -28
  82. package/lib/debug.js.map +1 -1
  83. package/lib/folders.js +0 -0
  84. package/lib/folders.js.map +0 -0
  85. package/lib/footer/index.d.ts +20 -0
  86. package/lib/footer/index.d.ts.map +1 -0
  87. package/lib/footer/index.js +130 -0
  88. package/lib/footer/index.js.map +1 -0
  89. package/lib/footer/styleMap.d.ts +8 -0
  90. package/lib/footer/styleMap.d.ts.map +1 -0
  91. package/lib/footer/styleMap.js +11 -0
  92. package/lib/footer/styleMap.js.map +1 -0
  93. package/lib/header/empty-profile.d.ts +0 -0
  94. package/lib/header/empty-profile.d.ts.map +0 -0
  95. package/lib/header/empty-profile.js +2 -6
  96. package/lib/header/empty-profile.js.map +1 -1
  97. package/lib/header/index.d.ts +11 -8
  98. package/lib/header/index.d.ts.map +1 -1
  99. package/lib/header/index.js +291 -355
  100. package/lib/header/index.js.map +1 -1
  101. package/lib/header/styleMap.d.ts +0 -2
  102. package/lib/header/styleMap.d.ts.map +1 -1
  103. package/lib/header/styleMap.js +116 -136
  104. package/lib/header/styleMap.js.map +1 -1
  105. package/lib/iconBase.d.ts +0 -0
  106. package/lib/iconBase.d.ts.map +0 -0
  107. package/lib/iconBase.js +23 -30
  108. package/lib/iconBase.js.map +1 -1
  109. package/lib/icons/solid_logo.d.ts +0 -0
  110. package/lib/icons/solid_logo.d.ts.map +0 -0
  111. package/lib/icons/solid_logo.js +0 -0
  112. package/lib/icons/solid_logo.js.map +1 -1
  113. package/lib/index.d.ts +3 -2
  114. package/lib/index.d.ts.map +1 -1
  115. package/lib/index.js +103 -198
  116. package/lib/index.js.map +1 -1
  117. package/lib/jss/index.d.ts +0 -0
  118. package/lib/jss/index.d.ts.map +0 -0
  119. package/lib/jss/index.js +21 -30
  120. package/lib/jss/index.js.map +1 -1
  121. package/lib/log.d.ts +0 -0
  122. package/lib/log.d.ts.map +0 -0
  123. package/lib/log.js +83 -131
  124. package/lib/log.js.map +1 -1
  125. package/lib/logic.d.ts +2 -2
  126. package/lib/logic.d.ts.map +1 -1
  127. package/lib/logic.js +82 -69
  128. package/lib/logic.js.map +1 -1
  129. package/lib/matrix/index.d.ts +0 -0
  130. package/lib/matrix/index.d.ts.map +0 -0
  131. package/lib/matrix/index.js +4 -10
  132. package/lib/matrix/index.js.map +1 -1
  133. package/lib/matrix/matrix.d.ts +0 -0
  134. package/lib/matrix/matrix.d.ts.map +0 -0
  135. package/lib/matrix/matrix.js +210 -237
  136. package/lib/matrix/matrix.js.map +1 -1
  137. package/lib/matrix/types.d.ts +0 -0
  138. package/lib/matrix/types.d.ts.map +0 -0
  139. package/lib/matrix/types.js +1 -4
  140. package/lib/matrix/types.js.map +1 -1
  141. package/lib/media/index.d.ts +0 -0
  142. package/lib/media/index.d.ts.map +0 -0
  143. package/lib/media/index.js +5 -11
  144. package/lib/media/index.js.map +1 -1
  145. package/lib/media/media-capture.d.ts +0 -0
  146. package/lib/media/media-capture.d.ts.map +0 -0
  147. package/lib/media/media-capture.js +187 -181
  148. package/lib/media/media-capture.js.map +1 -1
  149. package/lib/messageArea.js +0 -0
  150. package/lib/messageArea.js.map +0 -0
  151. package/lib/noun_Camera_1618446_000000.js +0 -0
  152. package/lib/noun_Camera_1618446_000000.js.map +0 -0
  153. package/lib/ns.js +0 -0
  154. package/lib/ns.js.map +0 -0
  155. package/lib/pad.d.ts +0 -0
  156. package/lib/pad.d.ts.map +0 -0
  157. package/lib/pad.js +794 -954
  158. package/lib/pad.js.map +1 -1
  159. package/lib/participation.d.ts +0 -0
  160. package/lib/participation.d.ts.map +0 -0
  161. package/lib/participation.js +170 -199
  162. package/lib/participation.js.map +1 -1
  163. package/lib/preferences.js +0 -0
  164. package/lib/preferences.js.map +0 -0
  165. package/lib/stories/decorators.js +0 -0
  166. package/lib/stories/decorators.js.map +0 -0
  167. package/lib/style.js +0 -0
  168. package/lib/style.js.map +0 -0
  169. package/lib/table.js +0 -0
  170. package/lib/table.js.map +0 -0
  171. package/lib/tabs.d.ts +0 -0
  172. package/lib/tabs.d.ts.map +0 -0
  173. package/lib/tabs.js +235 -342
  174. package/lib/tabs.js.map +1 -1
  175. package/lib/typings.d.js +0 -0
  176. package/lib/typings.d.js.map +0 -0
  177. package/lib/{header/headerHelpers.d.ts → utils/headerFooterHelpers.d.ts} +11 -3
  178. package/lib/utils/headerFooterHelpers.d.ts.map +1 -0
  179. package/lib/utils/headerFooterHelpers.js +164 -0
  180. package/lib/utils/headerFooterHelpers.js.map +1 -0
  181. package/lib/utils/index.js +0 -0
  182. package/lib/utils/index.js.map +0 -0
  183. package/lib/utils/label.d.ts +0 -0
  184. package/lib/utils/label.d.ts.map +0 -0
  185. package/lib/utils/label.js +121 -113
  186. package/lib/utils/label.js.map +1 -1
  187. package/lib/versionInfo.d.ts +0 -0
  188. package/lib/versionInfo.d.ts.map +0 -0
  189. package/lib/versionInfo.js +23 -28
  190. package/lib/versionInfo.js.map +1 -1
  191. package/lib/webpack-bundle.js +689 -310
  192. package/lib/webpack-bundle.js.map +1 -1
  193. package/lib/widgets/buttons/iconLinks.d.ts +0 -0
  194. package/lib/widgets/buttons/iconLinks.d.ts.map +0 -0
  195. package/lib/widgets/buttons/iconLinks.js +19 -30
  196. package/lib/widgets/buttons/iconLinks.js.map +1 -1
  197. package/lib/widgets/buttons.d.ts +0 -0
  198. package/lib/widgets/buttons.d.ts.map +0 -0
  199. package/lib/widgets/buttons.js +935 -1113
  200. package/lib/widgets/buttons.js.map +1 -1
  201. package/lib/widgets/dragAndDrop.js +0 -0
  202. package/lib/widgets/dragAndDrop.js.map +0 -0
  203. package/lib/widgets/error.d.ts +0 -0
  204. package/lib/widgets/error.d.ts.map +0 -0
  205. package/lib/widgets/error.js +18 -24
  206. package/lib/widgets/error.js.map +1 -1
  207. package/lib/widgets/forms/autocomplete/autocompleteBar.d.ts +0 -0
  208. package/lib/widgets/forms/autocomplete/autocompleteBar.d.ts.map +0 -0
  209. package/lib/widgets/forms/autocomplete/autocompleteBar.js +234 -325
  210. package/lib/widgets/forms/autocomplete/autocompleteBar.js.map +1 -1
  211. package/lib/widgets/forms/autocomplete/autocompleteField.d.ts +0 -0
  212. package/lib/widgets/forms/autocomplete/autocompleteField.d.ts.map +0 -0
  213. package/lib/widgets/forms/autocomplete/autocompleteField.js +249 -276
  214. package/lib/widgets/forms/autocomplete/autocompleteField.js.map +1 -1
  215. package/lib/widgets/forms/autocomplete/autocompletePicker.d.ts +0 -0
  216. package/lib/widgets/forms/autocomplete/autocompletePicker.d.ts.map +0 -0
  217. package/lib/widgets/forms/autocomplete/autocompletePicker.js +317 -497
  218. package/lib/widgets/forms/autocomplete/autocompletePicker.js.map +1 -1
  219. package/lib/widgets/forms/autocomplete/language.d.ts +0 -0
  220. package/lib/widgets/forms/autocomplete/language.d.ts.map +0 -0
  221. package/lib/widgets/forms/autocomplete/language.js +160 -212
  222. package/lib/widgets/forms/autocomplete/language.js.map +1 -1
  223. package/lib/widgets/forms/autocomplete/publicData.d.ts +0 -0
  224. package/lib/widgets/forms/autocomplete/publicData.d.ts.map +0 -0
  225. package/lib/widgets/forms/autocomplete/publicData.js +489 -718
  226. package/lib/widgets/forms/autocomplete/publicData.js.map +1 -1
  227. package/lib/widgets/forms/basic.d.ts +0 -0
  228. package/lib/widgets/forms/basic.d.ts.map +0 -0
  229. package/lib/widgets/forms/basic.js +208 -239
  230. package/lib/widgets/forms/basic.js.map +1 -1
  231. package/lib/widgets/forms/comment.d.ts +0 -0
  232. package/lib/widgets/forms/comment.d.ts.map +0 -0
  233. package/lib/widgets/forms/comment.js +48 -48
  234. package/lib/widgets/forms/comment.js.map +1 -1
  235. package/lib/widgets/forms/fieldFunction.d.ts +0 -0
  236. package/lib/widgets/forms/fieldFunction.d.ts.map +0 -0
  237. package/lib/widgets/forms/fieldFunction.js +31 -50
  238. package/lib/widgets/forms/fieldFunction.js.map +1 -1
  239. package/lib/widgets/forms/fieldParams.d.ts +0 -0
  240. package/lib/widgets/forms/fieldParams.d.ts.map +0 -0
  241. package/lib/widgets/forms/fieldParams.js +102 -81
  242. package/lib/widgets/forms/fieldParams.js.map +1 -1
  243. package/lib/widgets/forms/formStyle.d.ts +0 -0
  244. package/lib/widgets/forms/formStyle.d.ts.map +0 -0
  245. package/lib/widgets/forms/formStyle.js +52 -50
  246. package/lib/widgets/forms/formStyle.js.map +1 -1
  247. package/lib/widgets/forms.js +0 -0
  248. package/lib/widgets/forms.js.map +0 -0
  249. package/lib/widgets/index.js +0 -0
  250. package/lib/widgets/index.js.map +0 -0
  251. package/lib/widgets/peoplePicker.js +0 -0
  252. package/lib/widgets/peoplePicker.js.map +0 -0
  253. package/lib/widgets/widgetHelpers.d.ts +0 -0
  254. package/lib/widgets/widgetHelpers.d.ts.map +0 -0
  255. package/lib/widgets/widgetHelpers.js +18 -30
  256. package/lib/widgets/widgetHelpers.js.map +1 -1
  257. package/package.json +7 -6
  258. package/lib/header/headerHelpers.d.ts.map +0 -1
  259. package/lib/header/headerHelpers.js +0 -96
  260. package/lib/header/headerHelpers.js.map +0 -1
package/lib/pad.js CHANGED
@@ -1,154 +1,95 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
- Object.defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
- exports.getChunks = getChunks;
11
- exports.lightColorHash = lightColorHash;
12
- Object.defineProperty(exports, "manageParticipation", {
13
- enumerable: true,
14
- get: function get() {
15
- return _participation.manageParticipation;
16
- }
17
- });
18
- exports.notepad = notepad;
19
- exports.notepadToHTML = notepadToHTML;
20
- Object.defineProperty(exports, "participationObject", {
21
- enumerable: true,
22
- get: function get() {
23
- return _participation.participationObject;
24
- }
25
- });
26
- Object.defineProperty(exports, "recordParticipation", {
27
- enumerable: true,
28
- get: function get() {
29
- return _participation.recordParticipation;
30
- }
31
- });
32
- Object.defineProperty(exports, "renderPartipants", {
33
- enumerable: true,
34
- get: function get() {
35
- return _participation.renderPartipants;
36
- }
2
+ /** **************
3
+ * Notepad Widget
4
+ */
5
+ var __extends = (this && this.__extends) || (function () {
6
+ var extendStatics = function (d, b) {
7
+ extendStatics = Object.setPrototypeOf ||
8
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
9
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
10
+ return extendStatics(d, b);
11
+ };
12
+ return function (d, b) {
13
+ if (typeof b !== "function" && b !== null)
14
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
15
+ extendStatics(d, b);
16
+ function __() { this.constructor = d; }
17
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
18
+ };
19
+ })();
20
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
23
+ }) : (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ o[k2] = m[k];
26
+ }));
27
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
28
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
29
+ }) : function(o, v) {
30
+ o["default"] = v;
37
31
  });
38
- exports.xmlEncode = xmlEncode;
39
-
40
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
41
-
42
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
43
-
44
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
45
-
46
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
47
-
48
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
49
-
50
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
51
-
52
- var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
53
-
54
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
55
-
56
- var ns = _interopRequireWildcard(require("./ns"));
57
-
58
- var _rdflib = require("rdflib");
59
-
60
- var _widgets = require("./widgets");
61
-
62
- var _utils = require("./utils");
63
-
64
- var _debug = require("./debug");
65
-
66
- var _logic = require("./logic");
67
-
68
- var _participation = require("./participation");
69
-
70
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
71
-
72
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
73
-
74
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
75
-
76
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
77
-
78
- var store = _logic.solidLogicSingleton.store;
79
- var PAD = (0, _rdflib.Namespace)('http://www.w3.org/ns/pim/pad#');
80
-
32
+ var __importStar = (this && this.__importStar) || function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.notepadToHTML = exports.xmlEncode = exports.getChunks = exports.notepad = exports.lightColorHash = exports.recordParticipation = exports.manageParticipation = exports.participationObject = exports.renderPartipants = void 0;
41
+ /** @module pad
42
+ */
43
+ var ns = __importStar(require("./ns"));
44
+ var rdflib_1 = require("rdflib");
45
+ var widgets_1 = require("./widgets");
46
+ var utils_1 = require("./utils");
47
+ var debug_1 = require("./debug");
48
+ var logic_1 = require("./logic");
49
+ var participation_1 = require("./participation");
50
+ Object.defineProperty(exports, "renderPartipants", { enumerable: true, get: function () { return participation_1.renderPartipants; } });
51
+ Object.defineProperty(exports, "participationObject", { enumerable: true, get: function () { return participation_1.participationObject; } });
52
+ Object.defineProperty(exports, "manageParticipation", { enumerable: true, get: function () { return participation_1.manageParticipation; } });
53
+ Object.defineProperty(exports, "recordParticipation", { enumerable: true, get: function () { return participation_1.recordParticipation; } });
54
+ var store = logic_1.solidLogicSingleton.store;
55
+ var PAD = (0, rdflib_1.Namespace)('http://www.w3.org/ns/pim/pad#');
81
56
  /**
82
57
  * @ignore
83
58
  */
84
- var NotepadElement = /*#__PURE__*/function (_HTMLElement) {
85
- (0, _inherits2["default"])(NotepadElement, _HTMLElement);
86
-
87
- var _super = _createSuper(NotepadElement);
88
-
89
- function NotepadElement() {
90
- var _this;
91
-
92
- (0, _classCallCheck2["default"])(this, NotepadElement);
93
-
94
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
95
- args[_key] = arguments[_key];
59
+ var NotepadElement = /** @class */ (function (_super) {
60
+ __extends(NotepadElement, _super);
61
+ function NotepadElement() {
62
+ return _super !== null && _super.apply(this, arguments) || this;
96
63
  }
97
-
98
- _this = _super.call.apply(_super, [this].concat(args));
99
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "subject", void 0);
100
- return _this;
101
- }
102
-
103
- return (0, _createClass2["default"])(NotepadElement);
104
- }( /*#__PURE__*/(0, _wrapNativeSuper2["default"])(HTMLElement));
64
+ return NotepadElement;
65
+ }(HTMLElement));
105
66
  /**
106
67
  * @ignore
107
68
  */
108
-
109
-
110
- var NotepadPart = /*#__PURE__*/function (_HTMLElement2) {
111
- (0, _inherits2["default"])(NotepadPart, _HTMLElement2);
112
-
113
- var _super2 = _createSuper(NotepadPart);
114
-
115
- function NotepadPart() {
116
- var _this2;
117
-
118
- (0, _classCallCheck2["default"])(this, NotepadPart);
119
-
120
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
121
- args[_key2] = arguments[_key2];
69
+ var NotepadPart = /** @class */ (function (_super) {
70
+ __extends(NotepadPart, _super);
71
+ function NotepadPart() {
72
+ return _super !== null && _super.apply(this, arguments) || this;
122
73
  }
123
-
124
- _this2 = _super2.call.apply(_super2, [this].concat(args));
125
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "subject", void 0);
126
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "value", void 0);
127
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "state", void 0);
128
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "lastSent", void 0);
129
- return _this2;
130
- }
131
-
132
- return (0, _createClass2["default"])(NotepadPart);
133
- }( /*#__PURE__*/(0, _wrapNativeSuper2["default"])(HTMLElement));
74
+ return NotepadPart;
75
+ }(HTMLElement));
134
76
  /** Figure out a random color from my webid
135
77
  *
136
78
  * @param {NamedNode} author - The author of text being displayed
137
79
  * @returns {String} The CSS color generated, constrained to be light for a background color
138
80
  */
139
-
140
-
141
81
  function lightColorHash(author) {
142
- var hash = function hash(x) {
143
- return x.split('').reduce(function (a, b) {
144
- a = (a << 5) - a + b.charCodeAt(0);
145
- return a & a;
146
- }, 0);
147
- };
148
-
149
- return author && author.uri ? '#' + (hash(author.uri) & 0xffffff | 0xc0c0c0).toString(16) : '#ffffff'; // c0c0c0 forces pale
82
+ var hash = function (x) {
83
+ return x.split('').reduce(function (a, b) {
84
+ a = (a << 5) - a + b.charCodeAt(0);
85
+ return a & a;
86
+ }, 0);
87
+ };
88
+ return author && author.uri
89
+ ? '#' + ((hash(author.uri) & 0xffffff) | 0xc0c0c0).toString(16)
90
+ : '#ffffff'; // c0c0c0 forces pale
150
91
  } // no id -> white
151
-
92
+ exports.lightColorHash = lightColorHash;
152
93
  /** notepad
153
94
  *
154
95
  * @param {HTMLDocument} dom - the web page of the browser
@@ -157,863 +98,762 @@ function lightColorHash(author) {
157
98
  * @param {NamedNode} me - person who is logged into the pod
158
99
  * @param {notepadOptions} options - the options that can be passed in consist of statusArea, exists
159
100
  */
160
-
161
-
162
101
  function notepad(dom, padDoc, subject, me, options) {
163
- options = options || {};
164
- var exists = options.exists;
165
- var table = dom.createElement('table');
166
- var kb = store;
167
- if (me && !me.uri) throw new Error('UI.pad.notepad: Invalid userid');
168
- var updater = store.updater;
169
- var PAD = (0, _rdflib.Namespace)('http://www.w3.org/ns/pim/pad#');
170
- table.setAttribute('style', 'padding: 1em; overflow: auto; resize: horizontal; min-width: 40em;');
171
- var upstreamStatus = null;
172
- var downstreamStatus = null;
173
-
174
- if (options.statusArea) {
175
- var t = options.statusArea.appendChild(dom.createElement('table'));
176
- var tr = t.appendChild(dom.createElement('tr'));
177
- upstreamStatus = tr.appendChild(dom.createElement('td'));
178
- downstreamStatus = tr.appendChild(dom.createElement('td'));
179
-
180
- if (upstreamStatus) {
181
- upstreamStatus.setAttribute('style', 'width:50%');
182
- }
183
-
184
- if (downstreamStatus) {
185
- downstreamStatus.setAttribute('style', 'width:50%');
186
- }
187
- }
188
- /* @@ TODO want to look into this, it seems upstream should be a boolean and default to false ?
189
- *
190
- */
191
-
192
-
193
- var complain = function complain(message) {
194
- var upstream = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
195
- (0, _debug.log)(message);
196
-
197
- if (options.statusArea) {
198
- ;
199
- (upstream ? upstreamStatus : downstreamStatus).appendChild((0, _widgets.errorMessageBlock)(dom, message, 'pink'));
200
- }
201
- }; // @@ TODO need to refactor so that we don't have to type cast
202
-
203
-
204
- var clearStatus = function clearStatus(_upsteam) {
102
+ options = options || {};
103
+ var exists = options.exists;
104
+ var table = dom.createElement('table');
105
+ var kb = store;
106
+ if (me && !me.uri)
107
+ throw new Error('UI.pad.notepad: Invalid userid');
108
+ var updater = store.updater;
109
+ var PAD = (0, rdflib_1.Namespace)('http://www.w3.org/ns/pim/pad#');
110
+ table.setAttribute('style', 'padding: 1em; overflow: auto; resize: horizontal; min-width: 40em;');
111
+ var upstreamStatus = null;
112
+ var downstreamStatus = null;
205
113
  if (options.statusArea) {
206
- options.statusArea.innerHTML = '';
207
- }
208
- };
209
-
210
- var setPartStyle = function setPartStyle(part, colors, pending) {
211
- var chunk = part.subject;
212
- colors = colors || '';
213
- var baseStyle = 'font-size: 100%; font-family: monospace; width: 100%; border: none; white-space: pre-wrap;';
214
- var headingCore = 'font-family: sans-serif; font-weight: bold; border: none;';
215
- var headingStyle = ['font-size: 110%; padding-top: 0.5em; padding-bottom: 0.5em; width: 100%;', 'font-size: 120%; padding-top: 1em; padding-bottom: 1em; width: 100%;', 'font-size: 150%; padding-top: 1em; padding-bottom: 1em; width: 100%;'];
216
- var author = kb.any(chunk, ns.dc('author'));
217
-
218
- if (!colors && author) {
219
- // Hash the user webid for now -- later allow user selection!
220
- var bgcolor = lightColorHash(author);
221
- colors = 'color: ' + (pending ? '#888' : 'black') + '; background-color: ' + bgcolor + ';';
222
- } // @@ TODO Need to research when this can be an object with the indent stored in value
223
- // and when the indent is stored as a Number itself, not in an object.
224
-
225
-
226
- var indent = kb.any(chunk, PAD('indent'));
227
- indent = indent ? indent.value : 0;
228
- var style = indent >= 0 ? baseStyle + 'text-indent: ' + indent * 3 + 'em;' : headingCore + headingStyle[-1 - indent]; // ? baseStyle + 'padding-left: ' + (indent * 3) + 'em;'
229
-
230
- part.setAttribute('style', style + colors);
231
- };
232
-
233
- var removePart = function removePart(part) {
234
- var chunk = part.subject;
235
- if (!chunk) throw new Error('No chunk for line to be deleted!'); // just in case
236
-
237
- var prev = kb.any(undefined, PAD('next'), chunk);
238
- var next = kb.any(chunk, PAD('next'));
239
-
240
- if (prev.sameTerm(subject) && next.sameTerm(subject)) {
241
- // Last one
242
- (0, _debug.log)("You can't delete the only line.");
243
- return;
244
- }
245
-
246
- var del = kb.statementsMatching(chunk, undefined, undefined, padDoc).concat(kb.statementsMatching(undefined, undefined, chunk, padDoc));
247
- var ins = [(0, _rdflib.st)(prev, PAD('next'), next, padDoc)]; // @@ TODO what should we do if chunk is not a NamedNode should we
248
- // assume then it is a string?
249
-
250
- if (chunk instanceof _rdflib.NamedNode) {
251
- var label = chunk.uri.slice(-4);
252
- (0, _debug.log)('Deleting line ' + label);
253
- }
254
-
255
- if (!updater) {
256
- throw new Error('have no updater');
257
- } // @@ TODO below you can see that before is redefined and not a boolean
258
-
259
-
260
- updater.update(del, ins, function (uri, ok, errorMessage, response) {
261
- if (ok) {
262
- var row = part.parentNode;
263
-
264
- if (row) {
265
- var before = row.previousSibling;
266
-
267
- if (row.parentNode) {
268
- row.parentNode.removeChild(row);
269
- } // console.log(' deleted line ' + label + ' ok ' + part.value)
270
-
271
-
272
- if (before && before.firstChild) {
273
- // @@ TODO IMPORTANT FOCUS ISN'T A PROPERTY ON A CHILDNODE
274
- before.firstChild.focus();
275
- }
276
- }
277
- } else if (response && response.status === 409) {
278
- // Conflict
279
- setPartStyle(part, 'color: black; background-color: #ffd;'); // yellow
280
-
281
- part.state = 0; // Needs downstream refresh
282
-
283
- (0, _utils.beep)(0.5, 512); // Ooops clash with other person
284
-
285
- setTimeout(function () {
286
- // Ideally, beep! @@
287
- reloadAndSync(); // Throw away our changes and
288
- // updater.requestDownstreamAction(padDoc, reloadAndSync)
289
- }, 1000);
290
- } else {
291
- (0, _debug.log)(' removePart FAILED ' + chunk + ': ' + errorMessage);
292
- (0, _debug.log)(" removePart was deleteing :'" + del);
293
- setPartStyle(part, 'color: black; background-color: #fdd;'); // failed
294
-
295
- var res = response ? response.status : ' [no response field] ';
296
- complain('Error ' + res + ' saving changes: ' + errorMessage["true"]); // upstream,
297
- // updater.requestDownstreamAction(padDoc, reloadAndSync);
298
- }
299
- });
300
- }; // removePart
301
-
302
-
303
- var changeIndent = function changeIndent(part, chunk, delta) {
304
- var del = kb.statementsMatching(chunk, PAD('indent'));
305
- var current = del.length ? Number(del[0].object.value) : 0;
306
- if (current + delta < -3) return; // limit negative indent
307
-
308
- var newIndent = current + delta;
309
- var ins = (0, _rdflib.st)(chunk, PAD('indent'), newIndent, padDoc);
310
-
311
- if (!updater) {
312
- throw new Error('no updater');
114
+ var t = options.statusArea.appendChild(dom.createElement('table'));
115
+ var tr = t.appendChild(dom.createElement('tr'));
116
+ upstreamStatus = tr.appendChild(dom.createElement('td'));
117
+ downstreamStatus = tr.appendChild(dom.createElement('td'));
118
+ if (upstreamStatus) {
119
+ upstreamStatus.setAttribute('style', 'width:50%');
120
+ }
121
+ if (downstreamStatus) {
122
+ downstreamStatus.setAttribute('style', 'width:50%');
123
+ }
313
124
  }
314
-
315
- updater.update(del, ins, function (uri, ok, errorBody) {
316
- if (!ok) {
317
- (0, _debug.log)("Indent change FAILED '" + newIndent + "' for " + padDoc + ': ' + errorBody);
318
- setPartStyle(part, 'color: black; background-color: #fdd;'); // failed
319
-
320
- updater.requestDownstreamAction(padDoc, reloadAndSync);
321
- } else {
322
- setPartStyle(part); // Implement the indent
125
+ /* @@ TODO want to look into this, it seems upstream should be a boolean and default to false ?
126
+ *
127
+ */
128
+ var complain = function (message, upstream) {
129
+ if (upstream === void 0) { upstream = false; }
130
+ (0, debug_1.log)(message);
131
+ if (options.statusArea) {
132
+ ;
133
+ (upstream ? upstreamStatus : downstreamStatus).appendChild((0, widgets_1.errorMessageBlock)(dom, message, 'pink'));
134
+ }
135
+ };
136
+ // @@ TODO need to refactor so that we don't have to type cast
137
+ var clearStatus = function (_upsteam) {
138
+ if (options.statusArea) {
139
+ options.statusArea.innerHTML = '';
140
+ }
141
+ };
142
+ var setPartStyle = function (part, colors, pending) {
143
+ var chunk = part.subject;
144
+ colors = colors || '';
145
+ var baseStyle = 'font-size: 100%; font-family: monospace; width: 100%; border: none; white-space: pre-wrap;';
146
+ var headingCore = 'font-family: sans-serif; font-weight: bold; border: none;';
147
+ var headingStyle = [
148
+ 'font-size: 110%; padding-top: 0.5em; padding-bottom: 0.5em; width: 100%;',
149
+ 'font-size: 120%; padding-top: 1em; padding-bottom: 1em; width: 100%;',
150
+ 'font-size: 150%; padding-top: 1em; padding-bottom: 1em; width: 100%;'
151
+ ];
152
+ var author = kb.any(chunk, ns.dc('author'));
153
+ if (!colors && author) {
154
+ // Hash the user webid for now -- later allow user selection!
155
+ var bgcolor = lightColorHash(author);
156
+ colors =
157
+ 'color: ' +
158
+ (pending ? '#888' : 'black') +
159
+ '; background-color: ' +
160
+ bgcolor +
161
+ ';';
162
+ }
163
+ // @@ TODO Need to research when this can be an object with the indent stored in value
164
+ // and when the indent is stored as a Number itself, not in an object.
165
+ var indent = kb.any(chunk, PAD('indent'));
166
+ indent = indent ? indent.value : 0;
167
+ var style = indent >= 0
168
+ ? baseStyle + 'text-indent: ' + indent * 3 + 'em;'
169
+ : headingCore + headingStyle[-1 - indent];
170
+ // ? baseStyle + 'padding-left: ' + (indent * 3) + 'em;'
171
+ part.setAttribute('style', style + colors);
172
+ };
173
+ var removePart = function (part) {
174
+ var chunk = part.subject;
175
+ if (!chunk)
176
+ throw new Error('No chunk for line to be deleted!'); // just in case
177
+ var prev = kb.any(undefined, PAD('next'), chunk);
178
+ var next = kb.any(chunk, PAD('next'));
179
+ if (prev.sameTerm(subject) && next.sameTerm(subject)) {
180
+ // Last one
181
+ (0, debug_1.log)("You can't delete the only line.");
182
+ return;
183
+ }
184
+ var del = kb
185
+ .statementsMatching(chunk, undefined, undefined, padDoc)
186
+ .concat(kb.statementsMatching(undefined, undefined, chunk, padDoc));
187
+ var ins = [(0, rdflib_1.st)(prev, PAD('next'), next, padDoc)];
188
+ // @@ TODO what should we do if chunk is not a NamedNode should we
189
+ // assume then it is a string?
190
+ if (chunk instanceof rdflib_1.NamedNode) {
191
+ var label = chunk.uri.slice(-4);
192
+ (0, debug_1.log)('Deleting line ' + label);
193
+ }
194
+ if (!updater) {
195
+ throw new Error('have no updater');
196
+ }
197
+ // @@ TODO below you can see that before is redefined and not a boolean
198
+ updater.update(del, ins, function (uri, ok, errorMessage, response) {
199
+ if (ok) {
200
+ var row = part.parentNode;
201
+ if (row) {
202
+ var before = row.previousSibling;
203
+ if (row.parentNode) {
204
+ row.parentNode.removeChild(row);
205
+ }
206
+ // console.log(' deleted line ' + label + ' ok ' + part.value)
207
+ if (before && before.firstChild) {
208
+ // @@ TODO IMPORTANT FOCUS ISN'T A PROPERTY ON A CHILDNODE
209
+ before.firstChild.focus();
210
+ }
211
+ }
212
+ }
213
+ else if (response && response.status === 409) {
214
+ // Conflict
215
+ setPartStyle(part, 'color: black; background-color: #ffd;'); // yellow
216
+ part.state = 0; // Needs downstream refresh
217
+ (0, utils_1.beep)(0.5, 512); // Ooops clash with other person
218
+ setTimeout(function () {
219
+ // Ideally, beep! @@
220
+ reloadAndSync(); // Throw away our changes and
221
+ // updater.requestDownstreamAction(padDoc, reloadAndSync)
222
+ }, 1000);
223
+ }
224
+ else {
225
+ (0, debug_1.log)(' removePart FAILED ' + chunk + ': ' + errorMessage);
226
+ (0, debug_1.log)(" removePart was deleteing :'" + del);
227
+ setPartStyle(part, 'color: black; background-color: #fdd;'); // failed
228
+ var res = response ? response.status : ' [no response field] ';
229
+ complain('Error ' + res + ' saving changes: ' + errorMessage.true); // upstream,
230
+ // updater.requestDownstreamAction(padDoc, reloadAndSync);
231
+ }
232
+ });
233
+ }; // removePart
234
+ var changeIndent = function (part, chunk, delta) {
235
+ var del = kb.statementsMatching(chunk, PAD('indent'));
236
+ var current = del.length ? Number(del[0].object.value) : 0;
237
+ if (current + delta < -3)
238
+ return; // limit negative indent
239
+ var newIndent = current + delta;
240
+ var ins = (0, rdflib_1.st)(chunk, PAD('indent'), newIndent, padDoc);
241
+ if (!updater) {
242
+ throw new Error('no updater');
243
+ }
244
+ updater.update(del, ins, function (uri, ok, errorBody) {
245
+ if (!ok) {
246
+ (0, debug_1.log)("Indent change FAILED '" +
247
+ newIndent +
248
+ "' for " +
249
+ padDoc +
250
+ ': ' +
251
+ errorBody);
252
+ setPartStyle(part, 'color: black; background-color: #fdd;'); // failed
253
+ updater.requestDownstreamAction(padDoc, reloadAndSync);
254
+ }
255
+ else {
256
+ setPartStyle(part); // Implement the indent
257
+ }
258
+ });
259
+ };
260
+ // Use this sort of code to split the line when return pressed in the middle @@
261
+ /*
262
+ function doGetCaretPosition doGetCaretPosition (oField) {
263
+ var iCaretPos = 0
264
+ // IE Support
265
+ if (document.selection) {
266
+ // Set focus on the element to avoid IE bug
267
+ oField.focus()
268
+ // To get cursor position, get empty selection range
269
+ var oSel = document.selection.createRange()
270
+ // Move selection start to 0 position
271
+ oSel.moveStart('character', -oField.value.length)
272
+ // The caret position is selection length
273
+ iCaretPos = oSel.text.length
274
+ // Firefox suppor
275
+ } else if (oField.selectionStart || oField.selectionStart === '0') {
276
+ iCaretPos = oField.selectionStart
323
277
  }
324
- });
325
- }; // Use this sort of code to split the line when return pressed in the middle @@
326
-
327
- /*
328
- function doGetCaretPosition doGetCaretPosition (oField) {
329
- var iCaretPos = 0
330
- // IE Support
331
- if (document.selection) {
332
- // Set focus on the element to avoid IE bug
333
- oField.focus()
334
- // To get cursor position, get empty selection range
335
- var oSel = document.selection.createRange()
336
- // Move selection start to 0 position
337
- oSel.moveStart('character', -oField.value.length)
338
- // The caret position is selection length
339
- iCaretPos = oSel.text.length
340
- // Firefox suppor
341
- } else if (oField.selectionStart || oField.selectionStart === '0') {
342
- iCaretPos = oField.selectionStart
278
+ // Return results
279
+ return (iCaretPos)
343
280
  }
344
- // Return results
345
- return (iCaretPos)
346
- }
347
- */
348
-
349
-
350
- var addListeners = function addListeners(part, chunk) {
351
- part.addEventListener('keydown', function (event) {
352
- if (!updater) {
353
- throw new Error('no updater');
354
- }
355
-
356
- var queueProperty, queue; // up 38; down 40; left 37; right 39 tab 9; shift 16; escape 27
357
-
358
- switch (event.keyCode) {
359
- case 13:
360
- // Return
361
- {
362
- var before = event.shiftKey;
363
- (0, _debug.log)('enter'); // Shift-return inserts before -- only way to add to top of pad.
364
-
365
- if (before) {
366
- queue = kb.any(undefined, PAD('next'), chunk);
367
- queueProperty = 'newlinesAfter';
368
- } else {
369
- queue = kb.any(chunk, PAD('next'));
370
- queueProperty = 'newlinesBefore';
371
- }
372
-
373
- queue[queueProperty] = queue[queueProperty] || 0;
374
- queue[queueProperty] += 1;
375
-
376
- if (queue[queueProperty] > 1) {
377
- (0, _debug.log)(' queueing newline queue = ' + queue[queueProperty]);
378
- return;
379
- }
380
-
381
- (0, _debug.log)(' go ahead line before ' + queue[queueProperty]);
382
- newChunk(part, before); // was document.activeElement
383
-
384
- break;
385
- }
386
-
387
- case 8:
388
- // Delete
389
- if (part.value.length === 0) {
390
- (0, _debug.log)('Delete key line ' + chunk.uri.slice(-4) + ' state ' + part.state);
391
-
281
+ */
282
+ var addListeners = function (part, chunk) {
283
+ part.addEventListener('keydown', function (event) {
284
+ if (!updater) {
285
+ throw new Error('no updater');
286
+ }
287
+ var queueProperty, queue;
288
+ // up 38; down 40; left 37; right 39 tab 9; shift 16; escape 27
289
+ switch (event.keyCode) {
290
+ case 13: // Return
291
+ {
292
+ var before = event.shiftKey;
293
+ (0, debug_1.log)('enter'); // Shift-return inserts before -- only way to add to top of pad.
294
+ if (before) {
295
+ queue = kb.any(undefined, PAD('next'), chunk);
296
+ queueProperty = 'newlinesAfter';
297
+ }
298
+ else {
299
+ queue = kb.any(chunk, PAD('next'));
300
+ queueProperty = 'newlinesBefore';
301
+ }
302
+ queue[queueProperty] = queue[queueProperty] || 0;
303
+ queue[queueProperty] += 1;
304
+ if (queue[queueProperty] > 1) {
305
+ (0, debug_1.log)(' queueing newline queue = ' + queue[queueProperty]);
306
+ return;
307
+ }
308
+ (0, debug_1.log)(' go ahead line before ' + queue[queueProperty]);
309
+ newChunk(part, before); // was document.activeElement
310
+ break;
311
+ }
312
+ case 8: // Delete
313
+ if (part.value.length === 0) {
314
+ (0, debug_1.log)('Delete key line ' + chunk.uri.slice(-4) + ' state ' + part.state);
315
+ switch (part.state) {
316
+ case 1: // contents being sent
317
+ case 2: // contents need to be sent again
318
+ part.state = 4; // delete me
319
+ return;
320
+ case 3: // being deleted already
321
+ case 4: // already deleme state
322
+ return;
323
+ case undefined:
324
+ case 0:
325
+ part.state = 3; // being deleted
326
+ removePart(part);
327
+ event.preventDefault();
328
+ break; // continue
329
+ default:
330
+ throw new Error('pad: Unexpected state ' + part);
331
+ }
332
+ }
333
+ break;
334
+ case 9: // Tab
335
+ {
336
+ var delta = event.shiftKey ? -1 : 1;
337
+ changeIndent(part, chunk, delta);
338
+ event.preventDefault(); // default is to highlight next field
339
+ break;
340
+ }
341
+ case 27: // ESC
342
+ (0, debug_1.log)('escape');
343
+ updater.requestDownstreamAction(padDoc, reloadAndSync);
344
+ event.preventDefault();
345
+ break;
346
+ case 38: // Up
347
+ if (part.parentNode.previousSibling) {
348
+ part.parentNode.previousSibling.firstChild.focus();
349
+ event.preventDefault();
350
+ }
351
+ break;
352
+ case 40: // Down
353
+ if (part.parentNode.nextSibling) {
354
+ part.parentNode.nextSibling.firstChild.focus();
355
+ event.preventDefault();
356
+ }
357
+ break;
358
+ default:
359
+ }
360
+ });
361
+ var updateStore = function (part) {
362
+ var chunk = part.subject;
363
+ setPartStyle(part, undefined, true);
364
+ var old = kb.any(chunk, ns.sioc('content')).value;
365
+ var del = [(0, rdflib_1.st)(chunk, ns.sioc('content'), old, padDoc)];
366
+ var ins;
367
+ if (part.value) {
368
+ ins = [(0, rdflib_1.st)(chunk, ns.sioc('content'), part.value, padDoc)];
369
+ }
370
+ var newOne = part.value;
371
+ // DEBUGGING ONLY
372
+ if (part.lastSent) {
373
+ if (old !== part.lastSent) {
374
+ throw new Error("Out of order, last sent expected '" +
375
+ old +
376
+ "' but found '" +
377
+ part.lastSent +
378
+ "'");
379
+ }
380
+ }
381
+ part.lastSent = newOne;
382
+ /* console.log(
383
+ ' Patch proposed to ' +
384
+ chunk.uri.slice(-4) +
385
+ " '" +
386
+ old +
387
+ "' -> '" +
388
+ newOne +
389
+ "' "
390
+ ) */
391
+ if (!updater) {
392
+ throw new Error('no updater');
393
+ }
394
+ updater.update(del, ins, function (uri, ok, errorBody, xhr) {
395
+ if (!ok) {
396
+ // alert("clash " + errorBody);
397
+ (0, debug_1.log)(' patch FAILED ' +
398
+ xhr.status +
399
+ " for '" +
400
+ old +
401
+ "' -> '" +
402
+ newOne +
403
+ "': " +
404
+ errorBody);
405
+ if (xhr.status === 409) {
406
+ // Conflict - @@ we assume someone else
407
+ setPartStyle(part, 'color: black; background-color: #fdd;');
408
+ part.state = 0; // Needs downstream refresh
409
+ (0, utils_1.beep)(0.5, 512); // Ooops clash with other person
410
+ setTimeout(function () {
411
+ updater.requestDownstreamAction(padDoc, reloadAndSync);
412
+ }, 1000);
413
+ }
414
+ else {
415
+ setPartStyle(part, 'color: black; background-color: #fdd;'); // failed pink
416
+ part.state = 0;
417
+ complain(' Error ' + xhr.status + ' sending data: ' + errorBody, true);
418
+ (0, utils_1.beep)(1.0, 128); // Other
419
+ // @@@ Do soemthing more serious with other errors eg auth, etc
420
+ }
421
+ }
422
+ else {
423
+ clearStatus(true); // upstream
424
+ setPartStyle(part); // synced
425
+ (0, debug_1.log)(" Patch ok '" + old + "' -> '" + newOne + "' ");
426
+ if (part.state === 4) {
427
+ // delete me
428
+ part.state = 3;
429
+ removePart(part);
430
+ }
431
+ else if (part.state === 3) {
432
+ // being deleted
433
+ // pass
434
+ }
435
+ else if (part.state === 2) {
436
+ part.state = 1; // pending: lock
437
+ updateStore(part);
438
+ }
439
+ else {
440
+ part.state = 0; // clear lock
441
+ }
442
+ }
443
+ });
444
+ };
445
+ part.addEventListener('input', function inputChangeListener(_event) {
446
+ // debug.log("input changed "+part.value);
447
+ setPartStyle(part, undefined, true); // grey out - not synced
448
+ (0, debug_1.log)('Input event state ' + part.state + " value '" + part.value + "'");
392
449
  switch (part.state) {
393
- case 1: // contents being sent
394
-
395
- case 2:
396
- // contents need to be sent again
397
- part.state = 4; // delete me
398
-
399
- return;
400
-
401
- case 3: // being deleted already
402
-
403
- case 4:
404
- // already deleme state
405
- return;
406
-
407
- case undefined:
408
- case 0:
409
- part.state = 3; // being deleted
410
-
411
- removePart(part);
412
- event.preventDefault();
450
+ case 3: // being deleted
451
+ return;
452
+ case 4: // needs to be deleted
453
+ return;
454
+ case 2: // needs content updating, we know
455
+ return;
456
+ case 1:
457
+ part.state = 2; // lag we need another patch
458
+ return;
459
+ case 0:
460
+ case undefined:
461
+ part.state = 1; // being upadted
462
+ updateStore(part);
463
+ }
464
+ }); // listener
465
+ }; // addlisteners
466
+ // @@ TODO Need to research before as it appears to be used as an Element and a boolean
467
+ var newPartAfter = function (tr1, chunk, before) {
468
+ // @@ take chunk and add listeners
469
+ var text = kb.any(chunk, ns.sioc('content'));
470
+ text = text ? text.value : '';
471
+ var tr = dom.createElement('tr');
472
+ if (before) {
473
+ table.insertBefore(tr, tr1);
474
+ }
475
+ else {
476
+ // after
477
+ if (tr1 && tr1.nextSibling) {
478
+ table.insertBefore(tr, tr1.nextSibling);
479
+ }
480
+ else {
481
+ table.appendChild(tr);
482
+ }
483
+ }
484
+ var part = tr.appendChild(dom.createElement('input'));
485
+ part.subject = chunk;
486
+ part.setAttribute('type', 'text');
487
+ part.value = text;
488
+ if (me) {
489
+ setPartStyle(part, '');
490
+ addListeners(part, chunk);
491
+ }
492
+ else {
493
+ setPartStyle(part, 'color: #222; background-color: #fff');
494
+ (0, debug_1.log)("Note can't add listeners - not logged in");
495
+ }
496
+ return part;
497
+ };
498
+ /* @@ TODO we need to look at indent, it can be a Number or an Object this doesn't seem correct.
499
+ */
500
+ var newChunk = function (ele, before) {
501
+ // element of chunk being split
502
+ var kb = store;
503
+ var indent = 0;
504
+ var queueProperty = null;
505
+ var here, prev, next, queue, tr1;
506
+ if (ele) {
507
+ if (ele.tagName.toLowerCase() !== 'input') {
508
+ (0, debug_1.log)('return pressed when current document is: ' + ele.tagName);
509
+ }
510
+ here = ele.subject;
511
+ indent = kb.any(here, PAD('indent'));
512
+ indent = indent ? Number(indent.value) : 0;
513
+ if (before) {
514
+ prev = kb.any(undefined, PAD('next'), here);
515
+ next = here;
516
+ queue = prev;
517
+ queueProperty = 'newlinesAfter';
518
+ }
519
+ else {
520
+ prev = here;
521
+ next = kb.any(here, PAD('next'));
522
+ queue = next;
523
+ queueProperty = 'newlinesBefore';
524
+ }
525
+ tr1 = ele.parentNode;
526
+ }
527
+ else {
528
+ prev = subject;
529
+ next = subject;
530
+ tr1 = undefined;
531
+ }
532
+ var chunk = (0, widgets_1.newThing)(padDoc);
533
+ var label = chunk.uri.slice(-4);
534
+ var del = [(0, rdflib_1.st)(prev, PAD('next'), next, padDoc)];
535
+ var ins = [
536
+ (0, rdflib_1.st)(prev, PAD('next'), chunk, padDoc),
537
+ (0, rdflib_1.st)(chunk, PAD('next'), next, padDoc),
538
+ (0, rdflib_1.st)(chunk, ns.dc('author'), me, padDoc),
539
+ (0, rdflib_1.st)(chunk, ns.sioc('content'), '', padDoc)
540
+ ];
541
+ if (indent > 0) {
542
+ // Do not inherit
543
+ ins.push((0, rdflib_1.st)(chunk, PAD('indent'), indent, padDoc));
544
+ }
545
+ (0, debug_1.log)(' Fresh chunk ' + label + ' proposed');
546
+ if (!updater) {
547
+ throw new Error('no updater');
548
+ }
549
+ updater.update(del, ins, function (uri, ok, errorBody, _xhr) {
550
+ if (!ok) {
551
+ // alert("Error writing new line " + label + ": " + errorBody);
552
+ (0, debug_1.log)(' ERROR writing new line ' + label + ': ' + errorBody);
553
+ }
554
+ else {
555
+ var newPart = newPartAfter(tr1, chunk, before);
556
+ setPartStyle(newPart);
557
+ newPart.focus(); // Note this is delayed
558
+ if (queueProperty) {
559
+ (0, debug_1.log)(' Fresh chunk ' +
560
+ label +
561
+ ' updated, queue = ' +
562
+ queue[queueProperty]);
563
+ queue[queueProperty] -= 1;
564
+ if (queue[queueProperty] > 0) {
565
+ (0, debug_1.log)(' Implementing queued newlines = ' + next.newLinesBefore);
566
+ newChunk(newPart, before);
567
+ }
568
+ }
569
+ }
570
+ });
571
+ };
572
+ var consistencyCheck = function () {
573
+ var found = {};
574
+ var failed = 0;
575
+ function complain2(msg) {
576
+ complain(msg);
577
+ failed++;
578
+ }
579
+ if (!kb.the(subject, PAD('next'))) {
580
+ complain2('No initial next pointer');
581
+ return false; // can't do linked list
582
+ }
583
+ // var chunk = kb.the(subject, PAD('next'))
584
+ var prev = subject;
585
+ var chunk;
586
+ for (;;) {
587
+ chunk = kb.the(prev, PAD('next'));
588
+ if (!chunk) {
589
+ complain2('No next pointer from ' + prev);
590
+ }
591
+ if (chunk.sameTerm(subject)) {
413
592
  break;
414
- // continue
415
-
416
- default:
417
- throw new Error('pad: Unexpected state ' + part);
418
- }
419
- }
420
-
421
- break;
422
-
423
- case 9:
424
- // Tab
425
- {
426
- var delta = event.shiftKey ? -1 : 1;
427
- changeIndent(part, chunk, delta);
428
- event.preventDefault(); // default is to highlight next field
429
-
430
- break;
431
- }
432
-
433
- case 27:
434
- // ESC
435
- (0, _debug.log)('escape');
436
- updater.requestDownstreamAction(padDoc, reloadAndSync);
437
- event.preventDefault();
438
- break;
439
-
440
- case 38:
441
- // Up
442
- if (part.parentNode.previousSibling) {
443
- part.parentNode.previousSibling.firstChild.focus();
444
- event.preventDefault();
445
- }
446
-
447
- break;
448
-
449
- case 40:
450
- // Down
451
- if (part.parentNode.nextSibling) {
452
- part.parentNode.nextSibling.firstChild.focus();
453
- event.preventDefault();
454
- }
455
-
456
- break;
457
-
458
- default:
459
- }
460
- });
461
-
462
- var updateStore = function updateStore(part) {
463
- var chunk = part.subject;
464
- setPartStyle(part, undefined, true);
465
- var old = kb.any(chunk, ns.sioc('content')).value;
466
- var del = [(0, _rdflib.st)(chunk, ns.sioc('content'), old, padDoc)];
467
- var ins;
468
-
469
- if (part.value) {
470
- ins = [(0, _rdflib.st)(chunk, ns.sioc('content'), part.value, padDoc)];
471
- }
472
-
473
- var newOne = part.value; // DEBUGGING ONLY
474
-
475
- if (part.lastSent) {
476
- if (old !== part.lastSent) {
477
- throw new Error("Out of order, last sent expected '" + old + "' but found '" + part.lastSent + "'");
593
+ }
594
+ prev = chunk;
595
+ var label = chunk.uri.split('#')[1];
596
+ if (found[chunk.uri]) {
597
+ complain2('Loop!');
598
+ return false;
599
+ }
600
+ found[chunk.uri] = true;
601
+ var k = kb.each(chunk, PAD('next')).length;
602
+ if (k !== 1) {
603
+ complain2('Should be 1 not ' + k + ' next pointer for ' + label);
604
+ }
605
+ k = kb.each(chunk, PAD('indent')).length;
606
+ if (k > 1) {
607
+ complain2('Should be 0 or 1 not ' + k + ' indent for ' + label);
608
+ }
609
+ k = kb.each(chunk, ns.sioc('content')).length;
610
+ if (k !== 1) {
611
+ complain2('Should be 1 not ' + k + ' contents for ' + label);
612
+ }
613
+ k = kb.each(chunk, ns.dc('author')).length;
614
+ if (k !== 1) {
615
+ complain2('Should be 1 not ' + k + ' author for ' + label);
616
+ }
617
+ var sts = kb.statementsMatching(undefined, ns.sioc('contents'));
618
+ sts.forEach(function (st) {
619
+ if (!found[st.subject.value]) {
620
+ complain2('Loose chunk! ' + st.subject.value);
621
+ }
622
+ });
478
623
  }
479
- }
480
-
481
- part.lastSent = newOne;
482
- /* console.log(
483
- ' Patch proposed to ' +
484
- chunk.uri.slice(-4) +
485
- " '" +
486
- old +
487
- "' -> '" +
488
- newOne +
489
- "' "
490
- ) */
491
-
492
- if (!updater) {
493
- throw new Error('no updater');
494
- }
495
-
496
- updater.update(del, ins, function (uri, ok, errorBody, xhr) {
497
- if (!ok) {
498
- // alert("clash " + errorBody);
499
- (0, _debug.log)(' patch FAILED ' + xhr.status + " for '" + old + "' -> '" + newOne + "': " + errorBody);
500
-
501
- if (xhr.status === 409) {
502
- // Conflict - @@ we assume someone else
503
- setPartStyle(part, 'color: black; background-color: #fdd;');
504
- part.state = 0; // Needs downstream refresh
505
-
506
- (0, _utils.beep)(0.5, 512); // Ooops clash with other person
507
-
508
- setTimeout(function () {
509
- updater.requestDownstreamAction(padDoc, reloadAndSync);
510
- }, 1000);
511
- } else {
512
- setPartStyle(part, 'color: black; background-color: #fdd;'); // failed pink
513
-
514
- part.state = 0;
515
- complain(' Error ' + xhr.status + ' sending data: ' + errorBody, true);
516
- (0, _utils.beep)(1.0, 128); // Other
517
- // @@@ Do soemthing more serious with other errors eg auth, etc
518
- }
519
- } else {
520
- clearStatus(true); // upstream
521
-
522
- setPartStyle(part); // synced
523
-
524
- (0, _debug.log)(" Patch ok '" + old + "' -> '" + newOne + "' ");
525
-
526
- if (part.state === 4) {
527
- // delete me
528
- part.state = 3;
529
- removePart(part);
530
- } else if (part.state === 3) {// being deleted
531
- // pass
532
- } else if (part.state === 2) {
533
- part.state = 1; // pending: lock
534
-
535
- updateStore(part);
536
- } else {
537
- part.state = 0; // clear lock
538
- }
539
- }
540
- });
624
+ return !failed;
541
625
  };
542
-
543
- part.addEventListener('input', function inputChangeListener(_event) {
544
- // debug.log("input changed "+part.value);
545
- setPartStyle(part, undefined, true); // grey out - not synced
546
-
547
- (0, _debug.log)('Input event state ' + part.state + " value '" + part.value + "'");
548
-
549
- switch (part.state) {
550
- case 3:
551
- // being deleted
552
- return;
553
-
554
- case 4:
555
- // needs to be deleted
556
- return;
557
-
558
- case 2:
559
- // needs content updating, we know
560
- return;
561
-
562
- case 1:
563
- part.state = 2; // lag we need another patch
564
-
565
- return;
566
-
567
- case 0:
568
- case undefined:
569
- part.state = 1; // being upadted
570
-
571
- updateStore(part);
572
- }
573
- }); // listener
574
- }; // addlisteners
575
- // @@ TODO Need to research before as it appears to be used as an Element and a boolean
576
-
577
-
578
- var newPartAfter = function newPartAfter(tr1, chunk, before) {
579
- // @@ take chunk and add listeners
580
- var text = kb.any(chunk, ns.sioc('content'));
581
- text = text ? text.value : '';
582
- var tr = dom.createElement('tr');
583
-
584
- if (before) {
585
- table.insertBefore(tr, tr1);
586
- } else {
587
- // after
588
- if (tr1 && tr1.nextSibling) {
589
- table.insertBefore(tr, tr1.nextSibling);
590
- } else {
591
- table.appendChild(tr);
592
- }
593
- }
594
-
595
- var part = tr.appendChild(dom.createElement('input'));
596
- part.subject = chunk;
597
- part.setAttribute('type', 'text');
598
- part.value = text;
599
-
600
- if (me) {
601
- setPartStyle(part, '');
602
- addListeners(part, chunk);
603
- } else {
604
- setPartStyle(part, 'color: #222; background-color: #fff');
605
- (0, _debug.log)("Note can't add listeners - not logged in");
606
- }
607
-
608
- return part;
609
- };
610
- /* @@ TODO we need to look at indent, it can be a Number or an Object this doesn't seem correct.
611
- */
612
-
613
-
614
- var newChunk = function newChunk(ele, before) {
615
- // element of chunk being split
616
- var kb = store;
617
- var indent = 0;
618
- var queueProperty = null;
619
- var here, prev, next, queue, tr1;
620
-
621
- if (ele) {
622
- if (ele.tagName.toLowerCase() !== 'input') {
623
- (0, _debug.log)('return pressed when current document is: ' + ele.tagName);
624
- }
625
-
626
- here = ele.subject;
627
- indent = kb.any(here, PAD('indent'));
628
- indent = indent ? Number(indent.value) : 0;
629
-
630
- if (before) {
631
- prev = kb.any(undefined, PAD('next'), here);
632
- next = here;
633
- queue = prev;
634
- queueProperty = 'newlinesAfter';
635
- } else {
636
- prev = here;
637
- next = kb.any(here, PAD('next'));
638
- queue = next;
639
- queueProperty = 'newlinesBefore';
640
- }
641
-
642
- tr1 = ele.parentNode;
643
- } else {
644
- prev = subject;
645
- next = subject;
646
- tr1 = undefined;
647
- }
648
-
649
- var chunk = (0, _widgets.newThing)(padDoc);
650
- var label = chunk.uri.slice(-4);
651
- var del = [(0, _rdflib.st)(prev, PAD('next'), next, padDoc)];
652
- var ins = [(0, _rdflib.st)(prev, PAD('next'), chunk, padDoc), (0, _rdflib.st)(chunk, PAD('next'), next, padDoc), (0, _rdflib.st)(chunk, ns.dc('author'), me, padDoc), (0, _rdflib.st)(chunk, ns.sioc('content'), '', padDoc)];
653
-
654
- if (indent > 0) {
655
- // Do not inherit
656
- ins.push((0, _rdflib.st)(chunk, PAD('indent'), indent, padDoc));
657
- }
658
-
659
- (0, _debug.log)(' Fresh chunk ' + label + ' proposed');
660
-
661
- if (!updater) {
662
- throw new Error('no updater');
663
- }
664
-
665
- updater.update(del, ins, function (uri, ok, errorBody, _xhr) {
666
- if (!ok) {
667
- // alert("Error writing new line " + label + ": " + errorBody);
668
- (0, _debug.log)(' ERROR writing new line ' + label + ': ' + errorBody);
669
- } else {
670
- var newPart = newPartAfter(tr1, chunk, before);
671
- setPartStyle(newPart);
672
- newPart.focus(); // Note this is delayed
673
-
674
- if (queueProperty) {
675
- (0, _debug.log)(' Fresh chunk ' + label + ' updated, queue = ' + queue[queueProperty]);
676
- queue[queueProperty] -= 1;
677
-
678
- if (queue[queueProperty] > 0) {
679
- (0, _debug.log)(' Implementing queued newlines = ' + next.newLinesBefore);
680
- newChunk(newPart, before);
681
- }
626
+ // Ensure that the display matches the current state of the
627
+ // @@ TODO really need to refactor this so that we don't need to cast types
628
+ var sync = function () {
629
+ // var first = kb.the(subject, PAD('next'))
630
+ if (kb.each(subject, PAD('next')).length !== 1) {
631
+ var msg = 'Pad: Inconsistent data - NEXT pointers: ' +
632
+ kb.each(subject, PAD('next')).length;
633
+ (0, debug_1.log)(msg);
634
+ if (options.statusArea) {
635
+ options.statusArea.textContent += msg;
636
+ }
637
+ return;
682
638
  }
683
- }
684
- });
685
- };
686
-
687
- var consistencyCheck = function consistencyCheck() {
688
- var found = {};
689
- var failed = 0;
690
-
691
- function complain2(msg) {
692
- complain(msg);
693
- failed++;
694
- }
695
-
696
- if (!kb.the(subject, PAD('next'))) {
697
- complain2('No initial next pointer');
698
- return false; // can't do linked list
699
- } // var chunk = kb.the(subject, PAD('next'))
700
-
701
-
702
- var prev = subject;
703
- var chunk;
704
-
705
- for (;;) {
706
- chunk = kb.the(prev, PAD('next'));
707
-
708
- if (!chunk) {
709
- complain2('No next pointer from ' + prev);
710
- }
711
-
712
- if (chunk.sameTerm(subject)) {
713
- break;
714
- }
715
-
716
- prev = chunk;
717
- var label = chunk.uri.split('#')[1];
718
-
719
- if (found[chunk.uri]) {
720
- complain2('Loop!');
721
- return false;
722
- }
723
-
724
- found[chunk.uri] = true;
725
- var k = kb.each(chunk, PAD('next')).length;
726
-
727
- if (k !== 1) {
728
- complain2('Should be 1 not ' + k + ' next pointer for ' + label);
729
- }
730
-
731
- k = kb.each(chunk, PAD('indent')).length;
732
-
733
- if (k > 1) {
734
- complain2('Should be 0 or 1 not ' + k + ' indent for ' + label);
735
- }
736
-
737
- k = kb.each(chunk, ns.sioc('content')).length;
738
-
739
- if (k !== 1) {
740
- complain2('Should be 1 not ' + k + ' contents for ' + label);
741
- }
742
-
743
- k = kb.each(chunk, ns.dc('author')).length;
744
-
745
- if (k !== 1) {
746
- complain2('Should be 1 not ' + k + ' author for ' + label);
747
- }
748
-
749
- var sts = kb.statementsMatching(undefined, ns.sioc('contents'));
750
- sts.forEach(function (st) {
751
- if (!found[st.subject.value]) {
752
- complain2('Loose chunk! ' + st.subject.value);
639
+ // var last = kb.the(undefined, PAD('previous'), subject)
640
+ // var chunk = first // = kb.the(subject, PAD('next'));
641
+ var row;
642
+ // First see which of the logical chunks have existing physical manifestations
643
+ var manif = [];
644
+ // Find which lines correspond to existing chunks
645
+ for (var chunk = kb.the(subject, PAD('next')); !chunk.sameTerm(subject); chunk = kb.the(chunk, PAD('next'))) {
646
+ for (var i = 0; i < table.children.length; i++) {
647
+ var tr = table.children[i];
648
+ if (tr.firstChild) {
649
+ if (tr.firstChild.subject.sameTerm(chunk)) {
650
+ manif[chunk.uri] = tr.firstChild;
651
+ }
652
+ }
653
+ }
753
654
  }
754
- });
755
- }
756
-
757
- return !failed;
758
- }; // Ensure that the display matches the current state of the
759
- // @@ TODO really need to refactor this so that we don't need to cast types
760
-
761
-
762
- var sync = function sync() {
763
- // var first = kb.the(subject, PAD('next'))
764
- if (kb.each(subject, PAD('next')).length !== 1) {
765
- var msg = 'Pad: Inconsistent data - NEXT pointers: ' + kb.each(subject, PAD('next')).length;
766
- (0, _debug.log)(msg);
767
-
768
- if (options.statusArea) {
769
- options.statusArea.textContent += msg;
770
- }
771
-
772
- return;
773
- } // var last = kb.the(undefined, PAD('previous'), subject)
774
- // var chunk = first // = kb.the(subject, PAD('next'));
775
-
776
-
777
- var row; // First see which of the logical chunks have existing physical manifestations
778
-
779
- var manif = []; // Find which lines correspond to existing chunks
780
-
781
- for (var chunk = kb.the(subject, PAD('next')); !chunk.sameTerm(subject); chunk = kb.the(chunk, PAD('next'))) {
782
- for (var i = 0; i < table.children.length; i++) {
783
- var _tr = table.children[i];
784
-
785
- if (_tr.firstChild) {
786
- if (_tr.firstChild.subject.sameTerm(chunk)) {
787
- manif[chunk.uri] = _tr.firstChild;
788
- }
655
+ // Remove any deleted lines
656
+ for (var i = table.children.length - 1; i >= 0; i--) {
657
+ row = table.children[i];
658
+ if (!manif[row.firstChild.subject.uri]) {
659
+ table.removeChild(row);
660
+ }
661
+ }
662
+ // Insert any new lines and update old ones
663
+ row = table.firstChild; // might be null
664
+ for (var chunk = kb.the(subject, PAD('next')); !chunk.sameTerm(subject); chunk = kb.the(chunk, PAD('next'))) {
665
+ var text = kb.any(chunk, ns.sioc('content')).value;
666
+ // superstitious -- don't mess with unchanged input fields
667
+ // which may be selected by the user
668
+ if (row && manif[chunk.uri]) {
669
+ var part = row.firstChild;
670
+ if (text !== part.value) {
671
+ part.value = text;
672
+ }
673
+ setPartStyle(part);
674
+ part.state = 0; // Clear the state machine
675
+ delete part.lastSent; // DEBUG ONLY
676
+ row = row.nextSibling;
677
+ }
678
+ else {
679
+ newPartAfter(row, chunk, true); // actually before
680
+ }
789
681
  }
790
- }
791
- } // Remove any deleted lines
792
-
793
-
794
- for (var _i = table.children.length - 1; _i >= 0; _i--) {
795
- row = table.children[_i];
796
-
797
- if (!manif[row.firstChild.subject.uri]) {
798
- table.removeChild(row);
799
- }
800
- } // Insert any new lines and update old ones
801
-
802
-
803
- row = table.firstChild; // might be null
804
-
805
- for (var _chunk = kb.the(subject, PAD('next')); !_chunk.sameTerm(subject); _chunk = kb.the(_chunk, PAD('next'))) {
806
- var text = kb.any(_chunk, ns.sioc('content')).value; // superstitious -- don't mess with unchanged input fields
807
- // which may be selected by the user
808
-
809
- if (row && manif[_chunk.uri]) {
810
- var part = row.firstChild;
811
-
812
- if (text !== part.value) {
813
- part.value = text;
814
- }
815
-
816
- setPartStyle(part);
817
- part.state = 0; // Clear the state machine
818
-
819
- delete part.lastSent; // DEBUG ONLY
820
-
821
- row = row.nextSibling;
822
- } else {
823
- newPartAfter(row, _chunk, true); // actually before
824
- }
825
- }
826
- }; // Refresh the DOM tree
827
-
828
-
829
- var refreshTree = function refreshTree(root) {
830
- if (root.refresh) {
831
- root.refresh();
832
- return;
833
- }
834
-
835
- for (var i = 0; i < root.children.length; i++) {
836
- refreshTree(root.children[i]);
837
- }
838
- };
839
-
840
- var reloading = false;
841
-
842
- var checkAndSync = function checkAndSync() {
843
- (0, _debug.log)(' reloaded OK');
844
- clearStatus();
845
-
846
- if (!consistencyCheck()) {
847
- complain('CONSITENCY CHECK FAILED');
848
- } else {
849
- refreshTree(table);
850
- }
851
- };
852
-
853
- var reloadAndSync = function reloadAndSync() {
854
- if (reloading) {
855
- (0, _debug.log)(' Already reloading - stop');
856
- return; // once only needed
857
- }
858
-
859
- reloading = true;
860
- var retryTimeout = 1000; // ms
861
-
862
- var tryReload = function tryReload() {
863
- (0, _debug.log)('try reload - timeout = ' + retryTimeout);
864
-
865
- if (!updater) {
866
- throw new Error('no updater');
867
- }
868
-
869
- updater.reload(updater.store, padDoc, function (ok, message, xhr) {
870
- reloading = false;
871
-
872
- if (ok) {
873
- checkAndSync();
874
- } else {
875
- if (xhr.status === 0) {
876
- complain('Network error refreshing the pad. Retrying in ' + retryTimeout / 1000);
877
- reloading = true;
878
- retryTimeout = retryTimeout * 2;
879
- setTimeout(tryReload, retryTimeout);
880
- } else {
881
- complain('Error ' + xhr.status + 'refreshing the pad:' + message + '. Stopped. ' + padDoc);
882
- }
883
- }
884
- });
885
682
  };
886
-
887
- tryReload();
888
- };
889
-
890
- table.refresh = sync; // Catch downward propagating refresh events
891
-
892
- table.reloadAndSync = reloadAndSync;
893
- if (!me) (0, _debug.log)('Warning: must be logged in for pad to be edited');
894
-
895
- if (exists) {
896
- (0, _debug.log)('Existing pad.');
897
-
898
- if (consistencyCheck()) {
899
- sync();
900
-
901
- if (kb.holds(subject, PAD('next'), subject)) {
902
- // Empty list untenable
903
- newChunk(); // require at least one line
904
- }
905
- } else {
906
- (0, _debug.log)(table.textContent = 'Inconsistent data. Abort');
683
+ // Refresh the DOM tree
684
+ var refreshTree = function (root) {
685
+ if (root.refresh) {
686
+ root.refresh();
687
+ return;
688
+ }
689
+ for (var i = 0; i < root.children.length; i++) {
690
+ refreshTree(root.children[i]);
691
+ }
692
+ };
693
+ var reloading = false;
694
+ var checkAndSync = function () {
695
+ (0, debug_1.log)(' reloaded OK');
696
+ clearStatus();
697
+ if (!consistencyCheck()) {
698
+ complain('CONSITENCY CHECK FAILED');
699
+ }
700
+ else {
701
+ refreshTree(table);
702
+ }
703
+ };
704
+ var reloadAndSync = function () {
705
+ if (reloading) {
706
+ (0, debug_1.log)(' Already reloading - stop');
707
+ return; // once only needed
708
+ }
709
+ reloading = true;
710
+ var retryTimeout = 1000; // ms
711
+ var tryReload = function () {
712
+ (0, debug_1.log)('try reload - timeout = ' + retryTimeout);
713
+ if (!updater) {
714
+ throw new Error('no updater');
715
+ }
716
+ updater.reload(updater.store, padDoc, function (ok, message, xhr) {
717
+ reloading = false;
718
+ if (ok) {
719
+ checkAndSync();
720
+ }
721
+ else {
722
+ if (xhr.status === 0) {
723
+ complain('Network error refreshing the pad. Retrying in ' +
724
+ retryTimeout / 1000);
725
+ reloading = true;
726
+ retryTimeout = retryTimeout * 2;
727
+ setTimeout(tryReload, retryTimeout);
728
+ }
729
+ else {
730
+ complain('Error ' +
731
+ xhr.status +
732
+ 'refreshing the pad:' +
733
+ message +
734
+ '. Stopped. ' +
735
+ padDoc);
736
+ }
737
+ }
738
+ });
739
+ };
740
+ tryReload();
741
+ };
742
+ table.refresh = sync; // Catch downward propagating refresh events
743
+ table.reloadAndSync = reloadAndSync;
744
+ if (!me)
745
+ (0, debug_1.log)('Warning: must be logged in for pad to be edited');
746
+ if (exists) {
747
+ (0, debug_1.log)('Existing pad.');
748
+ if (consistencyCheck()) {
749
+ sync();
750
+ if (kb.holds(subject, PAD('next'), subject)) {
751
+ // Empty list untenable
752
+ newChunk(); // require at least one line
753
+ }
754
+ }
755
+ else {
756
+ (0, debug_1.log)((table.textContent = 'Inconsistent data. Abort'));
757
+ }
907
758
  }
908
- } else {
909
- // Make new pad
910
- (0, _debug.log)('No pad exists - making new one.');
911
- var insertables = [(0, _rdflib.st)(subject, ns.rdf('type'), PAD('Notepad'), padDoc), (0, _rdflib.st)(subject, ns.dc('author'), me, padDoc), (0, _rdflib.st)(subject, ns.dc('created'), new Date(), padDoc), (0, _rdflib.st)(subject, PAD('next'), subject, padDoc)];
912
-
913
- if (!updater) {
914
- throw new Error('no updater');
759
+ else {
760
+ // Make new pad
761
+ (0, debug_1.log)('No pad exists - making new one.');
762
+ var insertables = [
763
+ (0, rdflib_1.st)(subject, ns.rdf('type'), PAD('Notepad'), padDoc),
764
+ (0, rdflib_1.st)(subject, ns.dc('author'), me, padDoc),
765
+ (0, rdflib_1.st)(subject, ns.dc('created'), new Date(), padDoc),
766
+ (0, rdflib_1.st)(subject, PAD('next'), subject, padDoc)
767
+ ];
768
+ if (!updater) {
769
+ throw new Error('no updater');
770
+ }
771
+ updater.update([], insertables, function (uri, ok, errorBody) {
772
+ if (!ok) {
773
+ complain(errorBody || '');
774
+ }
775
+ else {
776
+ (0, debug_1.log)('Initial pad created');
777
+ newChunk(); // Add a first chunck
778
+ // getResults();
779
+ }
780
+ });
915
781
  }
916
-
917
- updater.update([], insertables, function (uri, ok, errorBody) {
918
- if (!ok) {
919
- complain(errorBody || '');
920
- } else {
921
- (0, _debug.log)('Initial pad created');
922
- newChunk(); // Add a first chunck
923
- // getResults();
924
- }
925
- });
926
- }
927
-
928
- return table;
782
+ return table;
929
783
  }
784
+ exports.notepad = notepad;
930
785
  /**
931
786
  * Get the chunks of the notepad
932
787
  * They are stored in a RDF linked list
933
788
  */
934
789
  // @ignore exporting this only for the unit test
935
-
936
-
937
790
  function getChunks(subject, kb) {
938
- var chunks = [];
939
-
940
- for (var chunk = kb.the(subject, PAD('next')); !chunk.sameTerm(subject); chunk = kb.the(chunk, PAD('next'))) {
941
- chunks.push(chunk);
942
- }
943
-
944
- return chunks;
791
+ var chunks = [];
792
+ for (var chunk = kb.the(subject, PAD('next')); !chunk.sameTerm(subject); chunk = kb.the(chunk, PAD('next'))) {
793
+ chunks.push(chunk);
794
+ }
795
+ return chunks;
945
796
  }
797
+ exports.getChunks = getChunks;
946
798
  /**
947
799
  * Encode content to be put in XML or HTML elements
948
800
  */
949
801
  // @ignore exporting this only for the unit test
950
-
951
-
952
802
  function xmlEncode(str) {
953
- return str.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;');
803
+ return str.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;');
954
804
  }
805
+ exports.xmlEncode = xmlEncode;
955
806
  /**
956
807
  * Convert a notepad to HTML
957
808
  * @param { } pad - the notepad
958
809
  * @param {store} pad - the data store
959
810
  */
960
-
961
-
962
811
  function notepadToHTML(pad, kb) {
963
- var chunks = getChunks(pad, kb);
964
- var html = '<html>\n <head>\n';
965
- var title = kb.anyValue(pad, ns.dct('title'));
966
-
967
- if (title) {
968
- html += " <title>".concat(xmlEncode(title), "</title>\n");
969
- }
970
-
971
- html += ' </head>\n <body>\n';
972
- var level = 0;
973
-
974
- function increaseLevel(indent) {
975
- for (; level < indent; level++) {
976
- html += '<ul>\n';
812
+ var chunks = getChunks(pad, kb);
813
+ var html = '<html>\n <head>\n';
814
+ var title = kb.anyValue(pad, ns.dct('title'));
815
+ if (title) {
816
+ html += " <title>".concat(xmlEncode(title), "</title>\n");
977
817
  }
978
- }
979
-
980
- function decreaseLevel(indent) {
981
- for (; level > indent; level--) {
982
- html += '</ul>\n';
818
+ html += ' </head>\n <body>\n';
819
+ var level = 0;
820
+ function increaseLevel(indent) {
821
+ for (; level < indent; level++) {
822
+ html += '<ul>\n';
823
+ }
983
824
  }
984
- }
985
-
986
- chunks.forEach(function (chunk) {
987
- var indent = kb.anyJS(chunk, PAD('indent'));
988
- var rawContent = kb.anyJS(chunk, ns.sioc('content'));
989
- if (!rawContent) return; // seed chunk is dummy
990
-
991
- var content = xmlEncode(rawContent);
992
-
993
- if (indent < 0) {
994
- // negative indent levels represent heading levels
995
- decreaseLevel(0);
996
- var h = indent >= -3 ? 4 + indent : 1; // -1 -> h4, -2 -> h3
997
-
998
- html += "\n<h".concat(h, ">").concat(content, "</h").concat(h, ">\n");
999
- } else {
1000
- // >= 0
1001
- if (indent > 0) {
1002
- // Lists
1003
- decreaseLevel(indent);
1004
- increaseLevel(indent);
1005
- html += "<li>".concat(content, "</li>\n");
1006
- } else {
1007
- // indent 0
1008
- decreaseLevel(indent);
1009
- html += "<p>".concat(content, "</p>\n");
1010
- }
825
+ function decreaseLevel(indent) {
826
+ for (; level > indent; level--) {
827
+ html += '</ul>\n';
828
+ }
1011
829
  }
1012
- }); // foreach chunk
1013
- // At the end decreaseLevel any open ULs
1014
-
1015
- decreaseLevel(0);
1016
- html += ' </body>\n</html>\n';
1017
- return html;
830
+ chunks.forEach(function (chunk) {
831
+ var indent = kb.anyJS(chunk, PAD('indent'));
832
+ var rawContent = kb.anyJS(chunk, ns.sioc('content'));
833
+ if (!rawContent)
834
+ return; // seed chunk is dummy
835
+ var content = xmlEncode(rawContent);
836
+ if (indent < 0) { // negative indent levels represent heading levels
837
+ decreaseLevel(0);
838
+ var h = indent >= -3 ? 4 + indent : 1; // -1 -> h4, -2 -> h3
839
+ html += "\n<h".concat(h, ">").concat(content, "</h").concat(h, ">\n");
840
+ }
841
+ else { // >= 0
842
+ if (indent > 0) { // Lists
843
+ decreaseLevel(indent);
844
+ increaseLevel(indent);
845
+ html += "<li>".concat(content, "</li>\n");
846
+ }
847
+ else { // indent 0
848
+ decreaseLevel(indent);
849
+ html += "<p>".concat(content, "</p>\n");
850
+ }
851
+ }
852
+ }); // foreach chunk
853
+ // At the end decreaseLevel any open ULs
854
+ decreaseLevel(0);
855
+ html += ' </body>\n</html>\n';
856
+ return html;
1018
857
  }
858
+ exports.notepadToHTML = notepadToHTML;
1019
859
  //# sourceMappingURL=pad.js.map