@hyperbook/markdown 0.37.1 → 0.38.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.
@@ -0,0 +1,63 @@
1
+ hyperbook.textinput = (function () {
2
+ // Debounce helper to reduce database writes
3
+ const debounce = (func, wait) => {
4
+ let timeout;
5
+ return function executedFunction(...args) {
6
+ const later = () => {
7
+ clearTimeout(timeout);
8
+ func(...args);
9
+ };
10
+ clearTimeout(timeout);
11
+ timeout = setTimeout(later, wait);
12
+ };
13
+ };
14
+
15
+ const init = (root) => {
16
+ let allTextInputs = root.querySelectorAll(".directive-textinput textarea[data-id]");
17
+
18
+ allTextInputs.forEach((textarea) => {
19
+ const id = textarea.getAttribute("data-id");
20
+
21
+ // Load saved text from store
22
+ store.textinput.get(id).then((result) => {
23
+ if (result && result.text) {
24
+ textarea.value = result.text;
25
+ }
26
+ }).catch((error) => {
27
+ console.error("Failed to load textinput from store:", error);
28
+ });
29
+
30
+ // Save text to store on input with debouncing
31
+ const saveToStore = debounce(() => {
32
+ store.textinput.put({
33
+ id: id,
34
+ text: textarea.value,
35
+ }).catch((error) => {
36
+ console.error("Failed to save textinput to store:", error);
37
+ });
38
+ }, 500);
39
+
40
+ textarea.addEventListener("input", saveToStore);
41
+ });
42
+ };
43
+
44
+ init(document.body);
45
+
46
+ // Observe for new textinputs added to the DOM
47
+ const observer = new MutationObserver((mutations) => {
48
+ mutations.forEach((mutation) => {
49
+ mutation.addedNodes.forEach((node) => {
50
+ if (node.nodeType === 1) {
51
+ // Element node
52
+ init(node);
53
+ }
54
+ });
55
+ });
56
+ });
57
+
58
+ observer.observe(document.body, { childList: true, subtree: true });
59
+
60
+ return {
61
+ init,
62
+ };
63
+ })();
@@ -0,0 +1,27 @@
1
+ .directive-textinput {
2
+ margin: 1rem 0;
3
+ }
4
+
5
+ .directive-textinput textarea {
6
+ width: 100%;
7
+ padding: 0.75rem;
8
+ font-family: inherit;
9
+ font-size: 1rem;
10
+ border: 1px solid var(--color-nav-border, #ccc);
11
+ border-radius: 4px;
12
+ resize: vertical;
13
+ box-sizing: border-box;
14
+ transition: border-color 0.2s;
15
+ background-color: var(--color-background, white);
16
+ color: var(--color-text, black);
17
+ }
18
+
19
+ .directive-textinput textarea:focus {
20
+ outline: none;
21
+ border-color: var(--color-brand, #007864);
22
+ }
23
+
24
+ .directive-textinput textarea::placeholder {
25
+ color: var(--color-text-deactivated, #999);
26
+ opacity: 1;
27
+ }
@@ -27,6 +27,7 @@ store.version(1).stores({
27
27
  h5p: `id,userData`,
28
28
  geogebra: `id,state`,
29
29
  learningmap: `id,nodes,x,y,zoom`,
30
+ textinput: `id,text`,
30
31
  });
31
32
  var sqlIdeDB = new Dexie("SQL-IDE");
32
33
  sqlIdeDB.version(0.1).stores({
package/dist/index.js CHANGED
@@ -61379,7 +61379,7 @@ var remarkDirectiveSqlIde_default = (ctx) => () => {
61379
61379
  children: [
61380
61380
  {
61381
61381
  type: "raw",
61382
- value: `{'id': '${id}', 'databaseURL': '${ctx.makeUrl(db || "", "public")}'}`
61382
+ value: `{'id': '${id}', 'databaseURL': '${ctx.makeUrl(db || "", "public", ctx.navigation.current || void 0)}'}`
61383
61383
  },
61384
61384
  ...codes,
61385
61385
  {
@@ -62560,7 +62560,7 @@ var rehypeHtmlStructure_default = (ctx) => () => {
62560
62560
  properties: {
62561
62561
  rel: "icon",
62562
62562
  type: "image/x-icon",
62563
- href: makeUrl(["favicon.ico"], "public")
62563
+ href: makeUrl(["/favicon.ico"], "public")
62564
62564
  },
62565
62565
  children: []
62566
62566
  },
@@ -64025,7 +64025,11 @@ var remarkImage_default = (ctx) => () => {
64025
64025
  tagName: "img",
64026
64026
  properties: {
64027
64027
  ...figureProps,
64028
- src: node3.url,
64028
+ src: ctx.makeUrl(
64029
+ node3.url,
64030
+ "public",
64031
+ ctx.navigation.current || void 0
64032
+ ),
64029
64033
  alt: node3.alt,
64030
64034
  onclick: `hyperbook.toggleLightbox(this)`
64031
64035
  },
@@ -78648,6 +78652,44 @@ var remarkDirectiveLearningmap_default = (ctx) => () => {
78648
78652
  };
78649
78653
  };
78650
78654
 
78655
+ // src/remarkDirectiveTextinput.ts
78656
+ var remarkDirectiveTextinput_default = (ctx) => () => {
78657
+ const name = "textinput";
78658
+ return (tree, file) => {
78659
+ visit(tree, function(node3) {
78660
+ if (isDirective(node3)) {
78661
+ if (node3.name !== name) return;
78662
+ const data = node3.data || (node3.data = {});
78663
+ expectLeafDirective(node3, file, name);
78664
+ registerDirective(file, name, ["client.js"], ["style.css"], []);
78665
+ const {
78666
+ placeholder = "",
78667
+ height = "200px",
78668
+ id = hash(node3)
78669
+ } = node3.attributes || {};
78670
+ data.hName = "div";
78671
+ data.hProperties = {
78672
+ class: "directive-textinput",
78673
+ "data-id": id
78674
+ };
78675
+ data.hChildren = [
78676
+ {
78677
+ type: "element",
78678
+ tagName: "textarea",
78679
+ properties: {
78680
+ class: "textinput",
78681
+ "data-id": id,
78682
+ placeholder,
78683
+ style: `height: ${height}`
78684
+ },
78685
+ children: []
78686
+ }
78687
+ ];
78688
+ }
78689
+ });
78690
+ };
78691
+ };
78692
+
78651
78693
  // src/process.ts
78652
78694
  var remark = (ctx) => {
78653
78695
  i18n.init(ctx.config.language || "en");
@@ -78691,6 +78733,7 @@ var remark = (ctx) => {
78691
78733
  remarkDirectiveJSXGraph_default(ctx),
78692
78734
  remarkDirectiveMultievent_default(ctx),
78693
78735
  remarkDirectiveLearningmap_default(ctx),
78736
+ remarkDirectiveTextinput_default(ctx),
78694
78737
  remarkCode_default(ctx),
78695
78738
  remarkMath,
78696
78739
  /* needs to be last directive */