sample-ui-component-library 0.0.61-dev → 0.0.62-dev

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sample-ui-component-library",
3
- "version": "0.0.61-dev",
3
+ "version": "0.0.62-dev",
4
4
  "description": "A library which contains sample UI elements that can be used for populating layouts.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -14,6 +14,8 @@ import { useEditor } from "../Editor";
14
14
 
15
15
  import EDITOR_MODES from "../EDITOR_MODES";
16
16
 
17
+ import { OverlayRow } from "./OverlayRow/OverlayRow";
18
+
17
19
  import Editor from "@monaco-editor/react";
18
20
 
19
21
  import "./MonacoInstance.scss";
@@ -44,30 +46,36 @@ export const MonacoInstance = forwardRef(({ onSelectAbstraction }, ref) => {
44
46
 
45
47
  // Update overlays for mapping mode.
46
48
  const updateOverlays = useCallback(() => {
47
- if (state.mode !== EDITOR_MODES.MAPPING || !editorRef.current || !activeTabRef?.current?.mapping) {
49
+ if (!editorRef.current) return;
50
+ if (state.mode !== EDITOR_MODES.MAPPING || !activeTabRef?.current?.mapping) {
51
+ editorRef.current.updateOptions({stickyScroll: { enabled: true }});
48
52
  setOverlayDivs(null);
49
53
  return;
50
54
  };
51
- const mapping = activeTabRef.current.mapping;
52
- const lineCount = editorRef.current.getModel().getLineCount();
53
- const lineHeight = editorRef.current.getOption(monaco.editor.EditorOption.lineHeight);
55
+ const _editor = editorRef.current;
56
+ _editor.updateOptions({stickyScroll: { enabled: false }});
57
+ const lineCount = _editor.getModel().getLineCount();
58
+ const lineHeight = _editor.getOption(monaco.editor.EditorOption.lineHeight);
54
59
  const divs = [];
55
60
 
56
- mapping.forEach((entry) => {
57
- const top = editorRef.current.getTopForLineNumber(entry.start_line) - editorRef.current.getScrollTop();
58
- let bottom = editorRef.current.getTopForLineNumber(entry.end_line + 1) - editorRef.current.getScrollTop();
61
+ activeTabRef.current.mapping.forEach((entry) => {
62
+ const top = _editor.getTopForLineNumber(entry.start_line) - _editor.getScrollTop();
63
+ let bottom = _editor.getTopForLineNumber(entry.end_line + 1) - _editor.getScrollTop();
59
64
  if (entry.end_line >= lineCount) {
60
65
  bottom = bottom + lineHeight;
61
66
  }
62
-
63
- const style= {};
64
- style["top"] = top + "px";
65
- style["height"] = (bottom - top) + "px";
66
-
67
- divs.push(<div className="line-block-overlay" onClick={(e) => onSelectAbstraction(entry)} style={style}></div>);
67
+ divs.push(
68
+ <OverlayRow
69
+ key={entry.uid}
70
+ entry={entry}
71
+ top={top}
72
+ bottom={bottom}
73
+ onSelectAbstraction={onSelectAbstraction}
74
+ />
75
+ );
68
76
  });
69
77
  setOverlayDivs(divs);
70
- }, [editorRef, state.activeTab, state.mode]);
78
+ }, [editorRef, state.activeTab, state.mode, onSelectAbstraction]);
71
79
 
72
80
  // Scroll the editor and update overlays on wheel event in mapping mode.
73
81
  const handleWheel = useCallback((e) => {
@@ -17,21 +17,9 @@
17
17
  }
18
18
 
19
19
  .overlay-layer {
20
- position: absolute;
21
- left: 0;
22
- right: 20px;
23
- inset: 0;
24
- overflow:hidden;
25
- }
26
-
27
- .line-block-overlay {
28
- z-index: 999;
29
20
  position: absolute;
30
- left: 0;
31
- right: 0;
32
- }
33
-
34
- .line-block-overlay:hover {
35
- background-color: rgba(255, 166, 0, 0.3);
36
- cursor: pointer;
21
+ inset:0;
22
+ left: 65px;
23
+ right: 14px;
24
+ overflow:hidden;
37
25
  }
@@ -0,0 +1,36 @@
1
+ import React from "react";
2
+ import PropTypes from "prop-types";
3
+
4
+ import "./OverlayRow.scss";
5
+
6
+ export const OverlayRow =({ entry, top, bottom, onSelectAbstraction }) => {
7
+ // Set background color if it exists, otherwise transperant
8
+ const style= {
9
+ "top": top + "px",
10
+ "height": (bottom - top) + "px",
11
+ "backgroundColor": entry?.backgroundColor || "none"
12
+ };
13
+
14
+ // If entry doesn't have background color, add hover effect.
15
+ let className = "line-block-overlay";
16
+ if (!entry.backgroundColor) {
17
+ className += " line-block-overlay-hover";
18
+ }
19
+
20
+ const selectRow = (e) => {
21
+ e.preventDefault();
22
+ e.stopPropagation();
23
+ onSelectAbstraction(entry);
24
+ }
25
+
26
+ return (
27
+ <div className={className} style={style} onClick={selectRow}></div>
28
+ );
29
+ };
30
+
31
+ OverlayRow.propTypes = {
32
+ entry: PropTypes.object.isRequired,
33
+ top: PropTypes.number.isRequired,
34
+ bottom: PropTypes.number.isRequired,
35
+ onSelectAbstraction: PropTypes.func.isRequired,
36
+ };
@@ -0,0 +1,11 @@
1
+ .line-block-overlay {
2
+ z-index: 999;
3
+ position: absolute;
4
+ left: 0px;
5
+ right: 0px;
6
+ }
7
+
8
+ .line-block-overlay-hover:hover {
9
+ background-color: rgba(123, 255, 0, 0.2);
10
+ cursor: pointer;
11
+ }
@@ -1 +1,332 @@
1
- [{"name":"library_manager.py","path":"library_manager.py","content":"import sys\r\nimport uuid\r\nimport json\r\n\r\ndef place_books_on_shelf_from_basket(book_shelf, basket):\r\n '''\r\n This function checks to see if there are books in the\r\n basket and places it on the shelf. It continues until\r\n there are no more books left.\r\n \r\n :param book_shelf: Object representing the bookshelf.\r\n :param basket: Array representing the basket.\r\n '''\r\n while len(basket[\"value\"]) > 0:\r\n book = basket[\"value\"].pop()\r\n print(f\"Accepted book: {book['value']['name']} (Genre: {book['value']['genre']})\")\r\n \r\n firstLetter = book[\"value\"]['name'][0]\r\n\r\n if (firstLetter not in book_shelf[\"value\"]):\r\n book_shelf[\"value\"][firstLetter] = []\r\n\r\n book_shelf[\"value\"][firstLetter].append(book)\r\n\r\n return book_shelf\r\n\r\ndef accept_book():\r\n '''\r\n This function accepts the book from the user.\r\n '''\r\n print(\"\\nEnter book details:\") \r\n name = input(\"Book name: \")\r\n genre = input(\"Genre: \")\r\n book_details = {\"uid\": str(uuid.uuid4()), \"value\": {\"name\": name, \"genre\":genre}}\r\n return book_details\r\n\r\ndef library_manager():\r\n '''\r\n This function serves the library manager. \r\n\r\n It provides a menu that lets users add books to a basket and \r\n place the books from the basket onto the shelf. It also allows\r\n the user to display the contents of the library and finally, it\r\n allows the user to exit the library.\r\n '''\r\n\r\n book_shelf = {\"uid\": str(uuid.uuid4()), \"value\":{}}\r\n\r\n basket = {\"uid\": str(uuid.uuid4()), \"value\":[]}\r\n\r\n while True:\r\n \r\n response = input(\r\n \"\\n==========================\\n\"\\\r\n \" Menu:\\n\" \\\r\n \"==========================\\n\"\\\r\n \"Enter a: Add book.\\n\" \\\r\n \"Enter p: Place books on shelf and continue.\\n\" \\\r\n \"Enter d: Display contents of basket and book shelf.\\n\" \\\r\n \"Enter any other key: Exit\\n\" \\\r\n \"\\nResponse:\"\r\n ).lower()\r\n\r\n if response == \"a\":\r\n book_details = accept_book()\r\n basket[\"value\"].append(book_details)\r\n\r\n elif response == \"p\":\r\n if (len(basket) > 5):\r\n raise Exception(\"Basket is too heavy, I can't bring it to the shelf.\")\r\n book_shelf = place_books_on_shelf_from_basket(book_shelf, basket)\r\n\r\n elif response == \"d\":\r\n audit = {\"uid\": str(uuid.uuid4()), \"value\":{\"Book Shelf\": book_shelf, \"Basket\": basket}}\r\n print(\"\\nLibrary Audit:\", json.dumps(audit[\"value\"], indent=2))\r\n\r\n else: \r\n break\r\n\r\nif __name__ == \"__main__\":\r\n sys.exit(library_manager())\r\n ","updatedContent":"import sys\r\nimport uuid\r\nimport json\r\n\r\ndef place_books_on_shelf_from_basket(book_shelf, basket):\r\n '''\r\n This function checks to see if there are books in the\r\n basket and places it on the shelf. It continues until\r\n there are no more books left.\r\n \r\n :param book_shelf: Object representing the bookshelf.\r\n :param basket: Array representing the basket.\r\n '''\r\n while len(basket[\"value\"]) > 0:\r\n book = basket[\"value\"].pop()\r\n print(f\"Accepted book: {book['value']['name']} (Genre: {book['value']['genre']})\")\r\n \r\n firstLetter = book[\"value\"]['name'][0]\r\n\r\n if (firstLetter not in book_shelf[\"value\"]):\r\n book_shelf[\"value\"][firstLetter] = []\r\n\r\n book_shelf[\"value\"][firstLetter].append(book)\r\n\r\n return book_shelf\r\n\r\ndef accept_book():\r\n '''\r\n This function accepts the book from the user.\r\n '''\r\n print(\"\\nEnter book details:\") \r\n name = input(\"Book name: \")\r\n genre = input(\"Genre: \")\r\n book_details = {\"uid\": str(uuid.uuid4()), \"value\": {\"name\": name, \"genre\":genre}}\r\n return book_details\r\n\r\ndef library_manager():\r\n '''\r\n This function serves the library manager. \r\n\r\n It provides a menu that lets users add books to a basket and \r\n place the books from the basket onto the shelf. It also allows\r\n the user to display the contents of the library and finally, it\r\n allows the user to exit the library.\r\n '''\r\n\r\n book_shelf = {\"uid\": str(uuid.uuid4()), \"value\":{}}\r\n\r\n basket = {\"uid\": str(uuid.uuid4()), \"value\":[]}\r\n\r\n while True:\r\n \r\n response = input(\r\n \"\\n==========================\\n\"\\\r\n \" Menu:\\n\" \\\r\n \"==========================\\n\"\\\r\n \"Enter a: Add book.\\n\" \\\r\n \"Enter p: Place books on shelf and continue.\\n\" \\\r\n \"Enter d: Display contents of basket and book shelf.\\n\" \\\r\n \"Enter any other key: Exit\\n\" \\\r\n \"\\nResponse:\"\r\n ).lower()\r\n\r\n if response == \"a\":\r\n book_details = accept_book()\r\n basket[\"value\"].append(book_details)\r\n\r\n elif response == \"p\":\r\n if (len(basket) > 5):\r\n raise Exception(\"Basket is too heavy, I can't bring it to the shelf.\")\r\n book_shelf = place_books_on_shelf_from_basket(book_shelf, basket)\r\n\r\n elif response == \"d\":\r\n audit = {\"uid\": str(uuid.uuid4()), \"value\":{\"Book Shelf\": book_shelf, \"Basket\": basket}}\r\n print(\"\\nLibrary Audit:\", json.dumps(audit[\"value\"], indent=2))\r\n\r\n else: \r\n break\r\n\r\nif __name__ == \"__main__\":\r\n sys.exit(library_manager())\r\n ","type":"file","uid":"9f7368cb-7972-4516-8f60-3f7b75f575c3","level":0,"collapsed":false,"isDirty":false,"mapping":[{"type":"Import","source_path":null,"uid":"b308ce7a-8b78-4f84-a7df-97fc150167e8","start_line":1,"end_line":1,"source":"import sys"},{"type":"Import","source_path":null,"uid":"ec8a3226-785d-44ac-ae07-b688f158aa58","start_line":2,"end_line":2,"source":"import uuid"},{"type":"Import","source_path":null,"uid":"0c1e1aef-b698-4396-bfc6-fdd57f186797","start_line":3,"end_line":3,"source":"import json"},{"type":"Expr","source_path":null,"uid":"35d89687-bf11-4b0c-8597-b92b3af5c316","start_line":6,"end_line":13,"source":"'''\r\n This function checks to see if there are books in the\r\n basket and places it on the shelf. It continues until\r\n there are no more books left.\r\n \r\n :param book_shelf: Object representing the bookshelf.\r\n :param basket: Array representing the basket.\r\n '''"},{"type":"While","source_path":null,"uid":"b7222c08-4d4b-40d2-b7da-3333086bc1a5","start_line":14,"end_line":14,"source":[" while len(basket[\"value\"]) > 0:"]},{"type":"Assign","source_path":null,"uid":"3059ee92-68a6-4696-ade6-a7491d363654","start_line":15,"end_line":15,"source":"book = basket[\"value\"].pop()"},{"type":"Expr","source_path":null,"uid":"08059761-6bd4-4e05-b737-be5469892978","start_line":16,"end_line":16,"source":"print(f\"Accepted book: {book['value']['name']} (Genre: {book['value']['genre']})\")"},{"type":"Assign","source_path":null,"uid":"f303481d-2a2b-45b1-aebc-bbd23168c3aa","start_line":18,"end_line":18,"source":"firstLetter = book[\"value\"]['name'][0]"},{"type":"If","source_path":null,"uid":"7b15a438-1601-4cd7-a4a6-b364a587aa7e","start_line":20,"end_line":20,"source":[" if (firstLetter not in book_shelf[\"value\"]):"]},{"type":"Assign","source_path":null,"uid":"8f60ac1a-c220-4140-bea1-0426aca1cfab","start_line":21,"end_line":21,"source":"book_shelf[\"value\"][firstLetter] = []"},{"type":"Expr","source_path":null,"uid":"9edb7b1b-efda-41f4-bb63-dc8aa1d1fa1d","start_line":23,"end_line":23,"source":"book_shelf[\"value\"][firstLetter].append(book)"},{"type":"Return","source_path":null,"uid":"3f9a5d2a-3aa4-4984-8dcc-190121bb73a8","start_line":25,"end_line":25,"source":"return book_shelf"},{"type":"Expr","source_path":null,"uid":"ca556739-e968-49f5-a36c-e10a06ebc617","start_line":28,"end_line":30,"source":"'''\r\n This function accepts the book from the user.\r\n '''"},{"type":"Expr","source_path":null,"uid":"f91e1c8b-e34f-46c3-925e-1e5b4a8fa95b","start_line":31,"end_line":31,"source":"print(\"\\nEnter book details:\")"},{"type":"Assign","source_path":null,"uid":"5e5f568d-bc06-47b5-b3e8-d1cfde0afe93","start_line":32,"end_line":32,"source":"name = input(\"Book name: \")"},{"type":"Assign","source_path":null,"uid":"649e0c60-a132-4c6b-9d72-ac290a5041c9","start_line":33,"end_line":33,"source":"genre = input(\"Genre: \")"},{"type":"Assign","source_path":null,"uid":"af6c7457-516c-4d39-8813-d744b1223515","start_line":34,"end_line":34,"source":"book_details = {\"uid\": str(uuid.uuid4()), \"value\": {\"name\": name, \"genre\":genre}}"},{"type":"Return","source_path":null,"uid":"0623dcb5-296e-45c0-b1fa-0818ecc94c62","start_line":35,"end_line":35,"source":"return book_details"},{"type":"Expr","source_path":null,"uid":"968e3d32-232d-450c-88ce-eb1d4b97ae64","start_line":38,"end_line":45,"source":"'''\r\n This function serves the library manager. \r\n\r\n It provides a menu that lets users add books to a basket and \r\n place the books from the basket onto the shelf. It also allows\r\n the user to display the contents of the library and finally, it\r\n allows the user to exit the library.\r\n '''"},{"type":"Assign","source_path":null,"uid":"e72691b6-e418-44af-8924-26b856f4996d","start_line":47,"end_line":47,"source":"book_shelf = {\"uid\": str(uuid.uuid4()), \"value\":{}}"},{"type":"Assign","source_path":null,"uid":"8a95a24c-62d7-47ee-b3ec-7886f6e7db37","start_line":49,"end_line":49,"source":"basket = {\"uid\": str(uuid.uuid4()), \"value\":[]}"},{"type":"While","source_path":null,"uid":"71544ac9-3c6c-45f5-9a53-d1abd3e47d84","start_line":51,"end_line":51,"source":[" while True:"]},{"type":"Assign","source_path":null,"uid":"90d619ec-708d-4ada-8d62-c70e03fa755b","start_line":53,"end_line":62,"source":"response = input(\r\n \"\\n==========================\\n\"\\\r\n \" Menu:\\n\" \\\r\n \"==========================\\n\"\\\r\n \"Enter a: Add book.\\n\" \\\r\n \"Enter p: Place books on shelf and continue.\\n\" \\\r\n \"Enter d: Display contents of basket and book shelf.\\n\" \\\r\n \"Enter any other key: Exit\\n\" \\\r\n \"\\nResponse:\"\r\n ).lower()"},{"type":"If","source_path":null,"uid":"2aa8eb4c-fdf8-4674-acac-281759d42509","start_line":64,"end_line":64,"source":[" if response == \"a\":"]},{"type":"Assign","source_path":null,"uid":"6fd18da6-4edd-4956-92aa-5ee50a970377","start_line":65,"end_line":65,"source":"book_details = accept_book()"},{"type":"Expr","source_path":null,"uid":"d0b0a744-5ac1-4f64-ae75-b2af0f468d1f","start_line":66,"end_line":66,"source":"basket[\"value\"].append(book_details)"},{"type":"If","source_path":null,"uid":"4a1d0ef6-3b30-4177-b556-e72c28dacbb8","start_line":68,"end_line":68,"source":[" elif response == \"p\":"]},{"type":"If","source_path":null,"uid":"a7c808f7-e44d-465f-b2df-415e19862a18","start_line":69,"end_line":69,"source":[" if (len(basket) > 5):"]},{"type":"Raise","source_path":null,"uid":"3579c14b-016c-4f9d-9ed7-f474f450e2f3","start_line":70,"end_line":70,"source":"raise Exception(\"Basket is too heavy, I can't bring it to the shelf.\")"},{"type":"Assign","source_path":null,"uid":"915ae10a-aab9-4003-9dbc-45772015b366","start_line":71,"end_line":71,"source":"book_shelf = place_books_on_shelf_from_basket(book_shelf, basket)"},{"type":"If","source_path":null,"uid":"f8690f15-63a4-4839-ae67-369f01ff7f83","start_line":73,"end_line":73,"source":[" elif response == \"d\":"]},{"type":"Assign","source_path":null,"uid":"15bc2199-2234-47e1-a8a0-84e16728aa1e","start_line":74,"end_line":74,"source":"audit = {\"uid\": str(uuid.uuid4()), \"value\":{\"Book Shelf\": book_shelf, \"Basket\": basket}}"},{"type":"Expr","source_path":null,"uid":"f9fff770-f748-407e-99ac-e94246a9d4d3","start_line":75,"end_line":75,"source":"print(\"\\nLibrary Audit:\", json.dumps(audit[\"value\"], indent=2))"},{"type":"Break","source_path":null,"uid":"c8123785-c38f-4085-858f-18ec19a09f75","start_line":78,"end_line":78,"source":"break"},{"type":"If","source_path":null,"uid":"75bef5bd-c735-4d91-9fbb-3021089ac938","start_line":80,"end_line":80,"source":["if __name__ == \"__main__\":"]},{"type":"Expr","source_path":null,"uid":"b12c3697-642d-46aa-902e-8c0a563eefa3","start_line":81,"end_line":81,"source":"sys.exit(library_manager())"}]},{"name":"README.md","path":"README.md","content":"- The files in the workspace are loaded from the implementation contained in the engine. \r\n\r\n- The implementation realizes the design contained in the engines graphs. \r\n\r\n- Anytime that the implementation is saved, the program will be parsed to extract the mappable statements, allowing the design to be mapped onto the implementation in the workbench.\r\n\r\n- The mapping will be instrumented onto the implementation, executed and the resulting trace will be transformed back into the behavior of the design, allowing it to be automatically debugged.","updatedContent":"- The files in the workspace are loaded from the implementation contained in the engine. \r\n\r\n- The implementation realizes the design contained in the engines graphs. \r\n\r\n- Anytime that the implementation is saved, the program will be parsed to extract the mappable statements, allowing the design to be mapped onto the implementation in the workbench.\r\n\r\n- The mapping will be instrumented onto the implementation, executed and the resulting trace will be transformed back into the behavior of the design, allowing it to be automatically debugged.","type":"file","uid":"2c5385dd-7c17-4216-b564-47c941e9a623","level":0,"collapsed":false,"isDirty":true}]
1
+ [
2
+ {
3
+ "name": "library_manager.py",
4
+ "path": "library_manager.py",
5
+ "content": "import sys\r\nimport uuid\r\nimport json\r\n\r\ndef place_books_on_shelf_from_basket(book_shelf, basket):\r\n '''\r\n This function checks to see if there are books in the\r\n basket and places it on the shelf. It continues until\r\n there are no more books left.\r\n \r\n :param book_shelf: Object representing the bookshelf.\r\n :param basket: Array representing the basket.\r\n '''\r\n while len(basket[\"value\"]) > 0:\r\n book = basket[\"value\"].pop()\r\n print(f\"Accepted book: {book['value']['name']} (Genre: {book['value']['genre']})\")\r\n \r\n firstLetter = book[\"value\"]['name'][0]\r\n\r\n if (firstLetter not in book_shelf[\"value\"]):\r\n book_shelf[\"value\"][firstLetter] = []\r\n\r\n book_shelf[\"value\"][firstLetter].append(book)\r\n\r\n return book_shelf\r\n\r\ndef accept_book():\r\n '''\r\n This function accepts the book from the user.\r\n '''\r\n print(\"\\nEnter book details:\") \r\n name = input(\"Book name: \")\r\n genre = input(\"Genre: \")\r\n book_details = {\"uid\": str(uuid.uuid4()), \"value\": {\"name\": name, \"genre\":genre}}\r\n return book_details\r\n\r\ndef library_manager():\r\n '''\r\n This function serves the library manager. \r\n\r\n It provides a menu that lets users add books to a basket and \r\n place the books from the basket onto the shelf. It also allows\r\n the user to display the contents of the library and finally, it\r\n allows the user to exit the library.\r\n '''\r\n\r\n book_shelf = {\"uid\": str(uuid.uuid4()), \"value\":{}}\r\n\r\n basket = {\"uid\": str(uuid.uuid4()), \"value\":[]}\r\n\r\n while True:\r\n \r\n response = input(\r\n \"\\n==========================\\n\"\\\r\n \" Menu:\\n\" \\\r\n \"==========================\\n\"\\\r\n \"Enter a: Add book.\\n\" \\\r\n \"Enter p: Place books on shelf and continue.\\n\" \\\r\n \"Enter d: Display contents of basket and book shelf.\\n\" \\\r\n \"Enter any other key: Exit\\n\" \\\r\n \"\\nResponse:\"\r\n ).lower()\r\n\r\n if response == \"a\":\r\n book_details = accept_book()\r\n basket[\"value\"].append(book_details)\r\n\r\n elif response == \"p\":\r\n if (len(basket) > 5):\r\n raise Exception(\"Basket is too heavy, I can't bring it to the shelf.\")\r\n book_shelf = place_books_on_shelf_from_basket(book_shelf, basket)\r\n\r\n elif response == \"d\":\r\n audit = {\"uid\": str(uuid.uuid4()), \"value\":{\"Book Shelf\": book_shelf, \"Basket\": basket}}\r\n print(\"\\nLibrary Audit:\", json.dumps(audit[\"value\"], indent=2))\r\n\r\n else: \r\n break\r\n\r\nif __name__ == \"__main__\":\r\n sys.exit(library_manager())\r\n ",
6
+ "updatedContent": "import sys\r\nimport uuid\r\nimport json\r\n\r\ndef place_books_on_shelf_from_basket(book_shelf, basket):\r\n '''\r\n This function checks to see if there are books in the\r\n basket and places it on the shelf. It continues until\r\n there are no more books left.\r\n \r\n :param book_shelf: Object representing the bookshelf.\r\n :param basket: Array representing the basket.\r\n '''\r\n while len(basket[\"value\"]) > 0:\r\n book = basket[\"value\"].pop()\r\n print(f\"Accepted book: {book['value']['name']} (Genre: {book['value']['genre']})\")\r\n \r\n firstLetter = book[\"value\"]['name'][0]\r\n\r\n if (firstLetter not in book_shelf[\"value\"]):\r\n book_shelf[\"value\"][firstLetter] = []\r\n\r\n book_shelf[\"value\"][firstLetter].append(book)\r\n\r\n return book_shelf\r\n\r\ndef accept_book():\r\n '''\r\n This function accepts the book from the user.\r\n '''\r\n print(\"\\nEnter book details:\") \r\n name = input(\"Book name: \")\r\n genre = input(\"Genre: \")\r\n book_details = {\"uid\": str(uuid.uuid4()), \"value\": {\"name\": name, \"genre\":genre}}\r\n return book_details\r\n\r\ndef library_manager():\r\n '''\r\n This function serves the library manager. \r\n\r\n It provides a menu that lets users add books to a basket and \r\n place the books from the basket onto the shelf. It also allows\r\n the user to display the contents of the library and finally, it\r\n allows the user to exit the library.\r\n '''\r\n\r\n book_shelf = {\"uid\": str(uuid.uuid4()), \"value\":{}}\r\n\r\n basket = {\"uid\": str(uuid.uuid4()), \"value\":[]}\r\n\r\n while True:\r\n \r\n response = input(\r\n \"\\n==========================\\n\"\\\r\n \" Menu:\\n\" \\\r\n \"==========================\\n\"\\\r\n \"Enter a: Add book.\\n\" \\\r\n \"Enter p: Place books on shelf and continue.\\n\" \\\r\n \"Enter d: Display contents of basket and book shelf.\\n\" \\\r\n \"Enter any other key: Exit\\n\" \\\r\n \"\\nResponse:\"\r\n ).lower()\r\n\r\n if response == \"a\":\r\n book_details = accept_book()\r\n basket[\"value\"].append(book_details)\r\n\r\n elif response == \"p\":\r\n if (len(basket) > 5):\r\n raise Exception(\"Basket is too heavy, I can't bring it to the shelf.\")\r\n book_shelf = place_books_on_shelf_from_basket(book_shelf, basket)\r\n\r\n elif response == \"d\":\r\n audit = {\"uid\": str(uuid.uuid4()), \"value\":{\"Book Shelf\": book_shelf, \"Basket\": basket}}\r\n print(\"\\nLibrary Audit:\", json.dumps(audit[\"value\"], indent=2))\r\n\r\n else: \r\n break\r\n\r\nif __name__ == \"__main__\":\r\n sys.exit(library_manager())\r\n ",
7
+ "type": "file",
8
+ "uid": "9f7368cb-7972-4516-8f60-3f7b75f575c3",
9
+ "level": 0,
10
+ "collapsed": false,
11
+ "isDirty": false,
12
+ "mapping": [
13
+ {
14
+ "type": "Import",
15
+ "source_path": null,
16
+ "uid": "b308ce7a-8b78-4f84-a7df-97fc150167e8",
17
+ "start_line": 1,
18
+ "end_line": 1,
19
+ "source": "import sys"
20
+ },
21
+ {
22
+ "type": "Import",
23
+ "source_path": null,
24
+ "uid": "ec8a3226-785d-44ac-ae07-b688f158aa58",
25
+ "start_line": 2,
26
+ "end_line": 2,
27
+ "source": "import uuid"
28
+ },
29
+ {
30
+ "type": "Import",
31
+ "source_path": null,
32
+ "uid": "0c1e1aef-b698-4396-bfc6-fdd57f186797",
33
+ "start_line": 3,
34
+ "end_line": 3,
35
+ "source": "import json"
36
+ },
37
+ {
38
+ "type": "Expr",
39
+ "source_path": null,
40
+ "uid": "35d89687-bf11-4b0c-8597-b92b3af5c316",
41
+ "start_line": 6,
42
+ "end_line": 13,
43
+ "source": "'''\r\n This function checks to see if there are books in the\r\n basket and places it on the shelf. It continues until\r\n there are no more books left.\r\n \r\n :param book_shelf: Object representing the bookshelf.\r\n :param basket: Array representing the basket.\r\n '''"
44
+ },
45
+ {
46
+ "type": "While",
47
+ "source_path": null,
48
+ "uid": "b7222c08-4d4b-40d2-b7da-3333086bc1a5",
49
+ "start_line": 14,
50
+ "end_line": 14,
51
+ "source": [
52
+ " while len(basket[\"value\"]) > 0:"
53
+ ]
54
+ },
55
+ {
56
+ "type": "Assign",
57
+ "source_path": null,
58
+ "uid": "3059ee92-68a6-4696-ade6-a7491d363654",
59
+ "start_line": 15,
60
+ "end_line": 15,
61
+ "source": "book = basket[\"value\"].pop()"
62
+ },
63
+ {
64
+ "type": "Expr",
65
+ "source_path": null,
66
+ "uid": "08059761-6bd4-4e05-b737-be5469892978",
67
+ "start_line": 16,
68
+ "end_line": 16,
69
+ "source": "print(f\"Accepted book: {book['value']['name']} (Genre: {book['value']['genre']})\")"
70
+ },
71
+ {
72
+ "type": "Assign",
73
+ "source_path": null,
74
+ "uid": "f303481d-2a2b-45b1-aebc-bbd23168c3aa",
75
+ "start_line": 18,
76
+ "end_line": 18,
77
+ "source": "firstLetter = book[\"value\"]['name'][0]"
78
+ },
79
+ {
80
+ "type": "If",
81
+ "source_path": null,
82
+ "uid": "7b15a438-1601-4cd7-a4a6-b364a587aa7e",
83
+ "start_line": 20,
84
+ "end_line": 20,
85
+ "source": [
86
+ " if (firstLetter not in book_shelf[\"value\"]):"
87
+ ]
88
+ },
89
+ {
90
+ "type": "Assign",
91
+ "source_path": null,
92
+ "uid": "8f60ac1a-c220-4140-bea1-0426aca1cfab",
93
+ "start_line": 21,
94
+ "end_line": 21,
95
+ "source": "book_shelf[\"value\"][firstLetter] = []"
96
+ },
97
+ {
98
+ "type": "Expr",
99
+ "source_path": null,
100
+ "uid": "9edb7b1b-efda-41f4-bb63-dc8aa1d1fa1d",
101
+ "start_line": 23,
102
+ "end_line": 23,
103
+ "source": "book_shelf[\"value\"][firstLetter].append(book)"
104
+ },
105
+ {
106
+ "type": "Return",
107
+ "source_path": null,
108
+ "uid": "3f9a5d2a-3aa4-4984-8dcc-190121bb73a8",
109
+ "start_line": 25,
110
+ "end_line": 25,
111
+ "source": "return book_shelf"
112
+ },
113
+ {
114
+ "type": "Expr",
115
+ "source_path": null,
116
+ "uid": "ca556739-e968-49f5-a36c-e10a06ebc617",
117
+ "start_line": 28,
118
+ "end_line": 30,
119
+ "source": "'''\r\n This function accepts the book from the user.\r\n '''"
120
+ },
121
+ {
122
+ "type": "Expr",
123
+ "source_path": null,
124
+ "uid": "f91e1c8b-e34f-46c3-925e-1e5b4a8fa95b",
125
+ "start_line": 31,
126
+ "end_line": 31,
127
+ "source": "print(\"\\nEnter book details:\")"
128
+ },
129
+ {
130
+ "type": "Assign",
131
+ "source_path": null,
132
+ "uid": "5e5f568d-bc06-47b5-b3e8-d1cfde0afe93",
133
+ "start_line": 32,
134
+ "end_line": 32,
135
+ "source": "name = input(\"Book name: \")"
136
+ },
137
+ {
138
+ "type": "Assign",
139
+ "source_path": null,
140
+ "uid": "649e0c60-a132-4c6b-9d72-ac290a5041c9",
141
+ "start_line": 33,
142
+ "end_line": 33,
143
+ "source": "genre = input(\"Genre: \")"
144
+ },
145
+ {
146
+ "type": "Assign",
147
+ "source_path": null,
148
+ "uid": "af6c7457-516c-4d39-8813-d744b1223515",
149
+ "start_line": 34,
150
+ "end_line": 34,
151
+ "source": "book_details = {\"uid\": str(uuid.uuid4()), \"value\": {\"name\": name, \"genre\":genre}}"
152
+ },
153
+ {
154
+ "type": "Return",
155
+ "source_path": null,
156
+ "uid": "0623dcb5-296e-45c0-b1fa-0818ecc94c62",
157
+ "start_line": 35,
158
+ "end_line": 35,
159
+ "source": "return book_details"
160
+ },
161
+ {
162
+ "type": "Expr",
163
+ "source_path": null,
164
+ "uid": "968e3d32-232d-450c-88ce-eb1d4b97ae64",
165
+ "start_line": 38,
166
+ "end_line": 45,
167
+ "source": "'''\r\n This function serves the library manager. \r\n\r\n It provides a menu that lets users add books to a basket and \r\n place the books from the basket onto the shelf. It also allows\r\n the user to display the contents of the library and finally, it\r\n allows the user to exit the library.\r\n '''"
168
+ },
169
+ {
170
+ "type": "Assign",
171
+ "source_path": null,
172
+ "uid": "e72691b6-e418-44af-8924-26b856f4996d",
173
+ "start_line": 47,
174
+ "end_line": 47,
175
+ "source": "book_shelf = {\"uid\": str(uuid.uuid4()), \"value\":{}}"
176
+ },
177
+ {
178
+ "type": "Assign",
179
+ "source_path": null,
180
+ "uid": "8a95a24c-62d7-47ee-b3ec-7886f6e7db37",
181
+ "start_line": 49,
182
+ "end_line": 49,
183
+ "source": "basket = {\"uid\": str(uuid.uuid4()), \"value\":[]}"
184
+ },
185
+ {
186
+ "type": "While",
187
+ "source_path": null,
188
+ "uid": "71544ac9-3c6c-45f5-9a53-d1abd3e47d84",
189
+ "start_line": 51,
190
+ "end_line": 51,
191
+ "source": [
192
+ " while True:"
193
+ ]
194
+ },
195
+ {
196
+ "type": "Assign",
197
+ "source_path": null,
198
+ "uid": "90d619ec-708d-4ada-8d62-c70e03fa755b",
199
+ "start_line": 53,
200
+ "end_line": 62,
201
+ "source": "response = input(\r\n \"\\n==========================\\n\"\\\r\n \" Menu:\\n\" \\\r\n \"==========================\\n\"\\\r\n \"Enter a: Add book.\\n\" \\\r\n \"Enter p: Place books on shelf and continue.\\n\" \\\r\n \"Enter d: Display contents of basket and book shelf.\\n\" \\\r\n \"Enter any other key: Exit\\n\" \\\r\n \"\\nResponse:\"\r\n ).lower()"
202
+ },
203
+ {
204
+ "type": "If",
205
+ "source_path": null,
206
+ "uid": "2aa8eb4c-fdf8-4674-acac-281759d42509",
207
+ "start_line": 64,
208
+ "end_line": 64,
209
+ "source": [
210
+ " if response == \"a\":"
211
+ ]
212
+ },
213
+ {
214
+ "type": "Assign",
215
+ "source_path": null,
216
+ "uid": "6fd18da6-4edd-4956-92aa-5ee50a970377",
217
+ "start_line": 65,
218
+ "end_line": 65,
219
+ "source": "book_details = accept_book()"
220
+ },
221
+ {
222
+ "type": "Expr",
223
+ "source_path": null,
224
+ "uid": "d0b0a744-5ac1-4f64-ae75-b2af0f468d1f",
225
+ "start_line": 66,
226
+ "end_line": 66,
227
+ "source": "basket[\"value\"].append(book_details)"
228
+ },
229
+ {
230
+ "type": "If",
231
+ "source_path": null,
232
+ "uid": "4a1d0ef6-3b30-4177-b556-e72c28dacbb8",
233
+ "start_line": 68,
234
+ "end_line": 68,
235
+ "source": [
236
+ " elif response == \"p\":"
237
+ ]
238
+ },
239
+ {
240
+ "type": "If",
241
+ "source_path": null,
242
+ "uid": "a7c808f7-e44d-465f-b2df-415e19862a18",
243
+ "start_line": 69,
244
+ "end_line": 69,
245
+ "source": [
246
+ " if (len(basket) > 5):"
247
+ ]
248
+ },
249
+ {
250
+ "type": "Raise",
251
+ "source_path": null,
252
+ "uid": "3579c14b-016c-4f9d-9ed7-f474f450e2f3",
253
+ "start_line": 70,
254
+ "end_line": 70,
255
+ "source": "raise Exception(\"Basket is too heavy, I can't bring it to the shelf.\")"
256
+ },
257
+ {
258
+ "type": "Assign",
259
+ "source_path": null,
260
+ "uid": "915ae10a-aab9-4003-9dbc-45772015b366",
261
+ "start_line": 71,
262
+ "end_line": 71,
263
+ "source": "book_shelf = place_books_on_shelf_from_basket(book_shelf, basket)"
264
+ },
265
+ {
266
+ "type": "If",
267
+ "source_path": null,
268
+ "uid": "f8690f15-63a4-4839-ae67-369f01ff7f83",
269
+ "start_line": 73,
270
+ "end_line": 73,
271
+ "source": [
272
+ " elif response == \"d\":"
273
+ ]
274
+ },
275
+ {
276
+ "type": "Assign",
277
+ "source_path": null,
278
+ "uid": "15bc2199-2234-47e1-a8a0-84e16728aa1e",
279
+ "start_line": 74,
280
+ "end_line": 74,
281
+ "hover": true,
282
+ "source": "audit = {\"uid\": str(uuid.uuid4()), \"value\":{\"Book Shelf\": book_shelf, \"Basket\": basket}}"
283
+ },
284
+ {
285
+ "type": "Expr",
286
+ "source_path": null,
287
+ "uid": "f9fff770-f748-407e-99ac-e94246a9d4d3",
288
+ "start_line": 75,
289
+ "end_line": 75,
290
+ "backgroundColor": "#33000033",
291
+ "source": "print(\"\\nLibrary Audit:\", json.dumps(audit[\"value\"], indent=2))"
292
+ },
293
+ {
294
+ "type": "Break",
295
+ "source_path": null,
296
+ "uid": "c8123785-c38f-4085-858f-18ec19a09f75",
297
+ "start_line": 78,
298
+ "end_line": 78,
299
+ "source": "break"
300
+ },
301
+ {
302
+ "type": "If",
303
+ "source_path": null,
304
+ "uid": "75bef5bd-c735-4d91-9fbb-3021089ac938",
305
+ "start_line": 80,
306
+ "end_line": 80,
307
+ "source": [
308
+ "if __name__ == \"__main__\":"
309
+ ]
310
+ },
311
+ {
312
+ "type": "Expr",
313
+ "source_path": null,
314
+ "uid": "b12c3697-642d-46aa-902e-8c0a563eefa3",
315
+ "start_line": 81,
316
+ "end_line": 81,
317
+ "source": "sys.exit(library_manager())"
318
+ }
319
+ ]
320
+ },
321
+ {
322
+ "name": "README.md",
323
+ "path": "README.md",
324
+ "content": "- The files in the workspace are loaded from the implementation contained in the engine. \r\n\r\n- The implementation realizes the design contained in the engines graphs. \r\n\r\n- Anytime that the implementation is saved, the program will be parsed to extract the mappable statements, allowing the design to be mapped onto the implementation in the workbench.\r\n\r\n- The mapping will be instrumented onto the implementation, executed and the resulting trace will be transformed back into the behavior of the design, allowing it to be automatically debugged.",
325
+ "updatedContent": "- The files in the workspace are loaded from the implementation contained in the engine. \r\n\r\n- The implementation realizes the design contained in the engines graphs. \r\n\r\n- Anytime that the implementation is saved, the program will be parsed to extract the mappable statements, allowing the design to be mapped onto the implementation in the workbench.\r\n\r\n- The mapping will be instrumented onto the implementation, executed and the resulting trace will be transformed back into the behavior of the design, allowing it to be automatically debugged.",
326
+ "type": "file",
327
+ "uid": "2c5385dd-7c17-4216-b564-47c941e9a623",
328
+ "level": 0,
329
+ "collapsed": false,
330
+ "isDirty": true
331
+ }
332
+ ]