Skip to content

Instantly share code, notes, and snippets.

@ivansglazunov
Last active November 29, 2022 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivansglazunov/718cbb3054609571f216f4456d9f3c4e to your computer and use it in GitHub Desktop.
Save ivansglazunov/718cbb3054609571f216f4456d9f3c4e to your computer and use it in GitHub Desktop.
@deep-foundation/deepcase
{"package":{"name":"@deep-foundation/deepcase","version":"0.0.0"},"data":[{"package":{"dependencyId":0,"containValue":"SyncTextFile"},"id":1},{"package":{"dependencyId":0,"containValue":"Handler"},"id":2},{"package":{"dependencyId":0,"containValue":"clientSupportsJs"},"id":3},{"package":{"dependencyId":0,"containValue":"HandleClient"},"id":4},{"package":{"dependencyId":1,"containValue":"TSX"},"id":5},{"package":{"dependencyId":0,"containValue":"GeneratedFrom"},"id":6},{"package":{"dependencyId":0,"containValue":"Type"},"id":7},{"package":{"dependencyId":0,"containValue":"Any"},"id":8},{"package":{"dependencyId":0,"containValue":"Query"},"id":9},{"package":{"dependencyId":0,"containValue":"Symbol"},"id":10},{"package":{"dependencyId":0,"containValue":"Join"},"id":11},{"package":{"dependencyId":0,"containValue":"Package"},"id":12},{"package":{"dependencyId":0,"containValue":"PackageQuery"},"id":13},{"package":{"dependencyId":0,"containValue":"Contain"},"id":14},{"id":"stringClientHandlerGenerated","type":1,"value":{"value":"var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\n({ deep, require }) => {\n const React = require('react');\n const { useState } = React;\n const json5 = require('json5');\n const { Input } = require('@chakra-ui/react');\n const { useHotkeys } = require('react-hotkeys-hook');\n const { useDebounceCallback } = require('@react-hook/debounce');\n const { useContainer } = require('@deep-foundation/deepcase');\n return ({ fillSize, style, link, onClose }) => {\n var _a;\n const currentValue = deep.stringify((_a = link === null || link === void 0 ? void 0 : link.value) === null || _a === void 0 ? void 0 : _a.value) || '';\n const [value, setValue] = useState(currentValue);\n const ref = useHotkeys('enter', (e) => __awaiter(void 0, void 0, void 0, function* () {\n if (!link.value)\n yield deep.insert({\n link_id: link.id, value: value,\n }, { table: 'strings' });\n deep.update({ link_id: link.id }, { value: value }, { table: 'strings' });\n onClose && onClose();\n }), { enableOnTags: [\"INPUT\"] });\n return React.createElement(\"div\", { style: Object.assign(Object.assign({ width: 300 }, style), { position: 'relative' }) },\n React.createElement(Input, { ref: ref, autoFocus: true, type: \"text\", variant: 'filled', bg: '#19202B', _hover: { bg: '#19202B' }, _focus: { bg: '#19202B' }, sx: {\n width: '100%',\n }, onChange: (e) => {\n setValue(e.target.value);\n }, value: value }));\n };\n};\n//# sourceMappingURL=module.js.map"}},{"id":"editorClientHandlerGenerated","type":1,"value":{"value":"({ deep, require }) => {\n const React = require('react');\n const { useState } = React;\n const json5 = require('json5');\n const { useContainer, CytoEditorPreview } = require('@deep-foundation/deepcase');\n const { Box, SimpleGrid } = require('@chakra-ui/react');\n return ({ fillSize, style, link }) => {\n var _a;\n const currentValue = deep.stringify((_a = link === null || link === void 0 ? void 0 : link.value) === null || _a === void 0 ? void 0 : _a.value) || '';\n const [value, setValue] = useState(currentValue);\n const isSaved = value == currentValue;\n const [container] = useContainer();\n const { data } = deep.useDeepSubscription({\n type_id: { _in: [\n deep.idLocal('@deep-foundation/core', 'Active'),\n deep.idLocal('@deep-foundation/core', 'Contain'),\n ] },\n to_id: { _eq: link.id },\n });\n const contain = data === null || data === void 0 ? void 0 : data.find(l => l.type_id === deep.idLocal('@deep-foundation/core', 'Contain'));\n const active = data === null || data === void 0 ? void 0 : data.find(l => l.type_id === deep.idLocal('@deep-foundation/core', 'Active'));\n return React.createElement(\"div\", { style: Object.assign(Object.assign({ width: 600, height: 600 }, style), { position: 'relative' }) },\n React.createElement(CytoEditorPreview, { link: link, compact: true }));\n };\n};\n//# sourceMappingURL=module.js.map"}},{"id":"editorHandler","type":2,"from":3,"to":"editorClientHandlerGenerated"},{"id":"editorHandleClientSyncTextFile","type":4,"from":5,"to":"editorHandler"},{"id":"editorClientHandler","type":5,"value":{"value":"({ deep, require }) => {\n const React = require('react');\n const { useState } = React;\n const json5 = require('json5');\n const { useContainer, CytoEditorPreview } = require('@deep-foundation/deepcase');\n const { Box, SimpleGrid } = require('@chakra-ui/react');\n // Only objects editor.\n return ({ fillSize, style, link }) => {\n const currentValue = deep.stringify(link?.value?.value) || '';\n const [value, setValue] = useState(currentValue);\n const isSaved = value == currentValue;\n const [container] = useContainer();\n const { data } = deep.useDeepSubscription({\n type_id: { _in: [\n deep.idLocal('@deep-foundation/core', 'Active'),\n deep.idLocal('@deep-foundation/core', 'Contain'),\n ] },\n to_id: { _eq: link.id },\n });\n const contain = data?.find(l => l.type_id === deep.idLocal('@deep-foundation/core', 'Contain'))\n const active = data?.find(l => l.type_id === deep.idLocal('@deep-foundation/core', 'Active'))\n return <div\n style={{\n width: 600,\n height: 600,\n ...style,\n position: 'relative',\n }}\n >\n <CytoEditorPreview link={link} compact/>\n </div>;\n }\n}"}},{"id":"editorClientHandlerGeneratedFrom","type":6,"from":"editorClientHandlerGenerated","to":"editorClientHandler"},{"id":"stringClientHandler","type":5,"value":{"value":"({ deep, require }) => {\n const React = require('react');\n const { useState } = React;\n const json5 = require('json5');\n const { Input } = require('@chakra-ui/react');\n const { useHotkeys } = require('react-hotkeys-hook');\n const { useDebounceCallback } = require('@react-hook/debounce');\n const { useContainer } = require('@deep-foundation/deepcase');\n // Only string editor.\n return ({ fillSize, style, link, onClose }) => {\n const currentValue = deep.stringify(link?.value?.value) || '';\n const [value, setValue] = useState(currentValue);\n const ref = useHotkeys('enter', async e => {\n if (!link.value) await deep.insert({\n link_id: link.id, value: value,\n }, { table: 'strings' });\n deep.update({ link_id: link.id }, { value: value }, { table: 'strings' });\n onClose && onClose();\n }, { enableOnTags: [\"INPUT\"] });\n return <div\n style={{\n width: 300,\n ...style,\n position: 'relative',\n }}\n >\n <Input\n ref={ref}\n autoFocus\n type=\"text\"\n variant='filled'\n bg='#19202B'\n _hover={{bg: '#19202B'}}\n _focus={{bg: '#19202B'}}\n sx={{\n width: '100%',\n }}\n onChange={(e) => {\n setValue(e.target.value);\n }}\n value={value}\n />\n </div>;\n }\n }"}},{"id":"Traveler","type":7,"from":8,"to":9},{"id":"travelerSymbol","type":10,"from":"Traveler","to":"Traveler","value":{"value":"🧳"}},{"id":"stringHandler","type":2,"from":3,"to":"stringClientHandlerGenerated"},{"id":"stringJoinHandleClient","type":4,"from":11,"to":"stringHandler"},{"id":"stringPackageHandleClient","type":4,"from":12,"to":"stringHandler"},{"id":"stringPackageQueryHandleClient","type":4,"from":13,"to":"stringHandler"},{"id":"stringContainHandleClient","type":4,"from":14,"to":"stringHandler"},{"id":"editorHandleClientTSX","type":4,"from":1,"to":"editorHandler"},{"id":"queryClientHandlerGenerated","type":1,"value":{"value":"var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\n({ deep, require }) => {\n const React = require('react');\n const { useState } = React;\n const json5 = require('json5');\n const { useContainer } = require('@deep-foundation/deepcase');\n return ({ fillSize, style, link }) => {\n var _a;\n const currentValue = deep.stringify((_a = link === null || link === void 0 ? void 0 : link.value) === null || _a === void 0 ? void 0 : _a.value) || '';\n const [value, setValue] = useState(currentValue);\n const isSaved = value == currentValue;\n const [container] = useContainer();\n const { data } = deep.useDeepSubscription({\n type_id: { _in: [\n deep.idLocal('@deep-foundation/core', 'Active'),\n deep.idLocal('@deep-foundation/core', 'Contain'),\n ] },\n to_id: { _eq: link.id },\n });\n const contain = data === null || data === void 0 ? void 0 : data.find(l => l.type_id === deep.idLocal('@deep-foundation/core', 'Contain'));\n const active = data === null || data === void 0 ? void 0 : data.find(l => l.type_id === deep.idLocal('@deep-foundation/core', 'Active'));\n return React.createElement(\"div\", { style: Object.assign(Object.assign({ width: 300, height: 200 }, style), { position: 'relative' }) },\n React.createElement(\"textarea\", { style: {\n width: '100%',\n height: '100%',\n }, onChange: (e) => {\n setValue(e.target.value);\n }, value: value }),\n React.createElement(\"button\", { disabled: isSaved, style: {\n position: 'absolute',\n top: 0, right: 0,\n opacity: isSaved ? 0.2 : 1\n }, onClick: () => {\n try {\n const _value = json5.parse(value);\n if (!link.value)\n deep.insert({\n link_id: link.id, value: _value,\n }, { table: 'objects' });\n deep.update({ link_id: link.id }, { value: _value }, { table: 'objects' });\n }\n catch (error) { }\n } }, \"save\"),\n !!contain && React.createElement(\"button\", { style: {\n position: 'absolute',\n bottom: 0, right: 0,\n }, onClick: () => __awaiter(void 0, void 0, void 0, function* () {\n if (active) {\n yield deep.delete({\n _or: [{\n id: { _eq: active.id },\n }, {\n type_id: deep.idLocal('@deep-foundation/core', 'Contain'),\n from_id: link.id,\n to_id: active.id,\n }],\n });\n }\n else {\n yield deep.insert({\n type_id: deep.idLocal('@deep-foundation/core', 'Active'),\n from_id: contain.from_id,\n to_id: contain.to_id,\n in: { data: {\n type_id: deep.idLocal('@deep-foundation/core', 'Contain'),\n from_id: link.id,\n } },\n });\n }\n }) }, active ? 'deactive' : 'active'));\n };\n};\n//# sourceMappingURL=module.js.map"}},{"id":"queryHandler","type":2,"from":3,"to":"queryClientHandlerGenerated"},{"id":"queryHandleClient","type":4,"from":9,"to":"queryHandler"},{"id":"queryClientHandler","type":5,"value":{"value":"({ deep, require }) => {\n const React = require('react');\n const { useState } = React;\n const json5 = require('json5');\n const { useContainer } = require('@deep-foundation/deepcase');\n // Only objects editor.\n return ({ fillSize, style, link }) => {\n const currentValue = deep.stringify(link?.value?.value) || '';\n const [value, setValue] = useState(currentValue);\n const isSaved = value == currentValue;\n const [container] = useContainer();\n const { data } = deep.useDeepSubscription({\n type_id: { _in: [\n deep.idLocal('@deep-foundation/core', 'Active'),\n deep.idLocal('@deep-foundation/core', 'Contain'),\n ] },\n to_id: { _eq: link.id },\n });\n const contain = data?.find(l => l.type_id === deep.idLocal('@deep-foundation/core', 'Contain'))\n const active = data?.find(l => l.type_id === deep.idLocal('@deep-foundation/core', 'Active'))\n return <div\n style={{\n width: 300,\n height: 200,\n ...style,\n position: 'relative',\n }}\n >\n <textarea\n style={{\n width: '100%',\n height: '100%',\n }}\n onChange={(e) => {\n setValue(e.target.value);\n }}\n value={value}\n />\n <button\n disabled={isSaved}\n style={{\n position: 'absolute',\n top: 0, right: 0,\n opacity: isSaved ? 0.2 : 1\n }}\n onClick={() => {\n try {\n const _value = json5.parse(value);\n if (!link.value) deep.insert({\n link_id: link.id, value: _value,\n }, { table: 'objects' });\n deep.update({ link_id: link.id }, { value: _value }, { table: 'objects' });\n } catch(error) {}\n }}\n >\n save\n </button>\n {!!contain && <button\n style={{\n position: 'absolute',\n bottom: 0, right: 0,\n }}\n onClick={async () => {\n if (active) {\n await deep.delete({\n _or: [{\n id: { _eq: active.id },\n }, {\n type_id: deep.idLocal('@deep-foundation/core', 'Contain'),\n from_id: link.id,\n to_id: active.id,\n }],\n });\n } else {\n await deep.insert({\n type_id: deep.idLocal('@deep-foundation/core', 'Active'),\n from_id: contain.from_id,\n to_id: contain.to_id,\n in: { data: {\n type_id: deep.idLocal('@deep-foundation/core', 'Contain'),\n from_id: link.id,\n } },\n });\n }\n }}\n >\n {active ? 'deactive' : 'active'}\n </button>}\n </div>;\n }\n }"}},{"id":"queryClientHandlerGeneratedFrom","type":6,"from":"queryClientHandlerGenerated","to":"queryClientHandler"},{"id":"stringClientHandlerGeneratedFrom","type":6,"from":"stringClientHandlerGenerated","to":"stringClientHandler"}],"errors":[],"dependencies":[{"name":"@deep-foundation/core"},{"name":"@deep-foundation/tsx"}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment