@fc3/mmcadi 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +673 -0
- package/README.md +5 -0
- package/bin/compile +63 -0
- package/bin/copy-static-files +13 -0
- package/bin/install +5 -0
- package/bin/precompile +55 -0
- package/bin/prepublish +7 -0
- package/bin/remap-paths +113 -0
- package/bin/test +9 -0
- package/config/tsconfig.json +37 -0
- package/package.json +33 -0
- package/src/bootstrap/start.ts +12 -0
- package/src/client/bootstrap.ts +5 -0
- package/src/client/client.ts +54 -0
- package/src/client/enum/key-code.ts +34 -0
- package/src/client/enum/page-type.ts +19 -0
- package/src/client/factory/page.ts +61 -0
- package/src/client/page/confirm-delete-block.ts +30 -0
- package/src/client/page/create-block.ts +6 -0
- package/src/client/page/day.ts +8 -0
- package/src/client/page/edit-block.ts +43 -0
- package/src/client/page/edit-custom.ts +16 -0
- package/src/client/page/home.ts +8 -0
- package/src/client/page/login.ts +8 -0
- package/src/client/page/logout.ts +8 -0
- package/src/client/page/month.ts +8 -0
- package/src/client/page/move-block.ts +8 -0
- package/src/client/page/select-block-type.ts +56 -0
- package/src/client/page/settings.ts +8 -0
- package/src/client/page/view-custom.ts +665 -0
- package/src/client/page/week.ts +8 -0
- package/src/client/page/year.ts +8 -0
- package/src/client/page.ts +128 -0
- package/src/client/shim/execute.ts +5 -0
- package/src/client/shim/logger.ts +44 -0
- package/src/client/utility/get-meta-value.ts +23 -0
- package/src/common/builder/block/background.ts +25 -0
- package/src/common/builder/block/folder.ts +43 -0
- package/src/common/builder/block/header.ts +15 -0
- package/src/common/builder/block/link.ts +32 -0
- package/src/common/builder/block/multicolumn.ts +16 -0
- package/src/common/builder/block/note.ts +13 -0
- package/src/common/builder/block/whitespace.ts +13 -0
- package/src/common/utility/get-parent-path.ts +29 -0
- package/src/constant/month-names.ts +16 -0
- package/src/enum/action-type.ts +11 -0
- package/src/enum/block-type.ts +18 -0
- package/src/enum/calendar-view-mode.ts +9 -0
- package/src/enum/color.ts +15 -0
- package/src/enum/default-role.ts +6 -0
- package/src/enum/directory-item-type.ts +6 -0
- package/src/enum/emoji.ts +94 -0
- package/src/enum/field-type.ts +8 -0
- package/src/enum/header-size.ts +7 -0
- package/src/enum/permission-type.ts +8 -0
- package/src/enum/time-place-visibility.ts +8 -0
- package/src/enum/tool-type.ts +14 -0
- package/src/index.ts +8 -0
- package/src/interface/hydration-callback.ts +7 -0
- package/src/interface/provider.ts +8 -0
- package/src/interface/repository.ts +12 -0
- package/src/lib/array/add.ts +10 -0
- package/src/lib/array/assert-is-empty.ts +23 -0
- package/src/lib/array/clone.ts +5 -0
- package/src/lib/array/difference.ts +8 -0
- package/src/lib/array/empty.ts +6 -0
- package/src/lib/array/equal.ts +24 -0
- package/src/lib/array/get-first-value.ts +5 -0
- package/src/lib/array/get-last-value.ts +5 -0
- package/src/lib/array/get-max-value.ts +5 -0
- package/src/lib/array/get-value-after.ts +23 -0
- package/src/lib/array/get-value-before.ts +23 -0
- package/src/lib/array/get-values-between.ts +18 -0
- package/src/lib/array/index.ts +5 -0
- package/src/lib/array/is-empty.ts +6 -0
- package/src/lib/array/remove.ts +19 -0
- package/src/lib/array/sum.ts +11 -0
- package/src/lib/array/unique.ts +13 -0
- package/src/lib/environment/bootstrap.ts +1 -0
- package/src/lib/environment/enum/environment-type.ts +8 -0
- package/src/lib/environment/enum/service-type.ts +5 -0
- package/src/lib/environment/index.ts +7 -0
- package/src/lib/environment/utility/get-environment-type.ts +28 -0
- package/src/lib/environment/utility/is-browser.ts +5 -0
- package/src/lib/environment/utility/is-development.ts +10 -0
- package/src/lib/environment/utility/is-production-or-staging.ts +8 -0
- package/src/lib/environment/utility/is-production.ts +10 -0
- package/src/lib/environment/utility/is-staging.ts +10 -0
- package/src/lib/errors/enum/error-type.ts +13 -0
- package/src/lib/errors/error/base.ts +40 -0
- package/src/lib/errors/error/conflict.ts +16 -0
- package/src/lib/errors/error/generic.ts +23 -0
- package/src/lib/errors/error/invalid.ts +14 -0
- package/src/lib/errors/error/invariant-violation.ts +5 -0
- package/src/lib/errors/error/not-allowed.ts +14 -0
- package/src/lib/errors/error/not-found.ts +16 -0
- package/src/lib/errors/error/not-implemented.ts +20 -0
- package/src/lib/errors/error/omitted.ts +14 -0
- package/src/lib/errors/error/timeout.ts +14 -0
- package/src/lib/errors/error/unauthorized.ts +14 -0
- package/src/lib/errors/index.ts +18 -0
- package/src/lib/errors/sugar/invariant.ts +7 -0
- package/src/lib/errors/type/coded-error.ts +7 -0
- package/src/lib/errors/type/error-data.ts +11 -0
- package/src/lib/errors/utility/create-error-for-error-type.ts +60 -0
- package/src/lib/errors/utility/create-error-from-ambiguous-json-data.ts +26 -0
- package/src/lib/errors/utility/error-matches.ts +28 -0
- package/src/lib/errors/utility/get-error-type-for-posix-error-code.ts +37 -0
- package/src/lib/errors/utility/get-error-type-for-status-code.ts +38 -0
- package/src/lib/errors/utility/get-message-for-error-type.ts +29 -0
- package/src/lib/errors/utility/matches-posix-error-code.ts +11 -0
- package/src/lib/errors/utility/wrap-error.ts +39 -0
- package/src/lib/event-emitter/index.ts +63 -0
- package/src/lib/execution-context/execution-context.ts +90 -0
- package/src/lib/execution-context/index.ts +8 -0
- package/src/lib/execution-context/type/session.ts +7 -0
- package/src/lib/feature/feature.ts +108 -0
- package/src/lib/feature/index.ts +3 -0
- package/src/lib/filesystem/bootstrap.ts +1 -0
- package/src/lib/filesystem/enum/file-extension.ts +19 -0
- package/src/lib/filesystem/index.ts +4 -0
- package/src/lib/filesystem/utility/exists.ts +21 -0
- package/src/lib/filesystem/utility/get-extension-for-filepath.ts +20 -0
- package/src/lib/filesystem/utility/strip-extension.ts +26 -0
- package/src/lib/grammar/index.ts +3 -0
- package/src/lib/grammar/noun-inflector.ts +104 -0
- package/src/lib/grammar/utility/get-words-from-identifier.ts +9 -0
- package/src/lib/grammar/verb-inflector.ts +344 -0
- package/src/lib/http/buffer-stream.ts +76 -0
- package/src/lib/http/enum/content-type.ts +19 -0
- package/src/lib/http/enum/cookie-attribute.ts +11 -0
- package/src/lib/http/enum/header.ts +29 -0
- package/src/lib/http/enum/method.ts +11 -0
- package/src/lib/http/enum/same-site-policy.ts +7 -0
- package/src/lib/http/enum/status-code.ts +9 -0
- package/src/lib/http/factory/body-parser.ts +55 -0
- package/src/lib/http/index.ts +24 -0
- package/src/lib/http/interface/client-request.ts +15 -0
- package/src/lib/http/interface/incoming-message.ts +24 -0
- package/src/lib/http/interface/network-library.ts +9 -0
- package/src/lib/http/interface/request-callback.ts +7 -0
- package/src/lib/http/isomorphic/request.ts +77 -0
- package/src/lib/http/isomorphic/response.ts +77 -0
- package/src/lib/http/isomorphic.ts +20 -0
- package/src/lib/http/parser/accept-header.ts +35 -0
- package/src/lib/http/parser/basic-auth-header.ts +48 -0
- package/src/lib/http/parser/body/json.ts +14 -0
- package/src/lib/http/parser/body/multipart.ts +89 -0
- package/src/lib/http/parser/body/url-encoded.ts +16 -0
- package/src/lib/http/parser/body.ts +44 -0
- package/src/lib/http/parser/cookie.ts +114 -0
- package/src/lib/http/parser/querystring.ts +92 -0
- package/src/lib/http/parser/url.ts +76 -0
- package/src/lib/http/request/incoming.ts +299 -0
- package/src/lib/http/request/outgoing.ts +276 -0
- package/src/lib/http/request.ts +26 -0
- package/src/lib/http/response/incoming.ts +243 -0
- package/src/lib/http/response/outgoing.ts +160 -0
- package/src/lib/http/response.ts +74 -0
- package/src/lib/http/serializer/basic-auth-header.ts +27 -0
- package/src/lib/http/serializer/cookie.ts +90 -0
- package/src/lib/http/serializer/query-data.ts +54 -0
- package/src/lib/http/transaction.ts +320 -0
- package/src/lib/http/type/basic-auth-credentials.ts +6 -0
- package/src/lib/http/type/header-map.ts +5 -0
- package/src/lib/http/type/log-attributes.ts +12 -0
- package/src/lib/http/type/path-parameters.ts +5 -0
- package/src/lib/http/type/query-data.ts +7 -0
- package/src/lib/http/type/query-value.ts +11 -0
- package/src/lib/http/type/request-options.ts +16 -0
- package/src/lib/http/type/transaction-data.ts +4 -0
- package/src/lib/http/utility/get-content-type-for-extension.ts +47 -0
- package/src/lib/http/utility/get-library-for-protocol.ts +25 -0
- package/src/lib/http/utility/get-status-code-for-error-type.ts +37 -0
- package/src/lib/http/utility/get-status-code-for-error.ts +13 -0
- package/src/lib/http/utility/is-client-error-status.ts +15 -0
- package/src/lib/http/utility/is-error-status.ts +9 -0
- package/src/lib/http/utility/is-server-error-status.ts +7 -0
- package/src/lib/http/utility/is-success-status.ts +7 -0
- package/src/lib/http/utility/proxy-request.ts +58 -0
- package/src/lib/http/utility/serialize-request-options.ts +9 -0
- package/src/lib/http/utility/slug-generator.ts +20 -0
- package/src/lib/key-generator/index.ts +3 -0
- package/src/lib/key-generator/key-generator.ts +7 -0
- package/src/lib/logger/enum/ansi-escape-code.ts +14 -0
- package/src/lib/logger/enum/log-level.ts +8 -0
- package/src/lib/logger/formatter.ts +59 -0
- package/src/lib/logger/index.ts +7 -0
- package/src/lib/logger/interface/error-reporter.ts +7 -0
- package/src/lib/logger/interface/logger.ts +13 -0
- package/src/lib/logger/logger.ts +239 -0
- package/src/lib/logger/type/error-parameters.ts +9 -0
- package/src/lib/logger/type/loggable-data.ts +5 -0
- package/src/lib/logger/type/loggable-value.ts +1 -0
- package/src/lib/metrics/dispatcher.ts +264 -0
- package/src/lib/metrics/enum/dispatch-mode.ts +6 -0
- package/src/lib/metrics/index.ts +2 -0
- package/src/lib/metrics/settings-hydrator.ts +51 -0
- package/src/lib/metrics/type/dispatcher-settings.ts +12 -0
- package/src/lib/metrics/type/tag-map.ts +5 -0
- package/src/lib/network/bootstrap.ts +1 -0
- package/src/lib/network/enum/connection-status.ts +14 -0
- package/src/lib/network/enum/http-status-code.ts +75 -0
- package/src/lib/network/enum/network-protocol.ts +10 -0
- package/src/lib/network/event-emitter.ts +63 -0
- package/src/lib/network/index.ts +7 -0
- package/src/lib/network/interface/socket.ts +42 -0
- package/src/lib/network/type/socket-options.ts +6 -0
- package/src/lib/network/utility/get-protocol-from-url.ts +15 -0
- package/src/lib/operation/index.ts +6 -0
- package/src/lib/operation/operation/auto-logging.ts +94 -0
- package/src/lib/operation/operation/silent.ts +17 -0
- package/src/lib/operation/operation.ts +80 -0
- package/src/lib/process/bootstrap.ts +1 -0
- package/src/lib/process/enum/posix-error-code.ts +138 -0
- package/src/lib/process/enum/process-signal.ts +68 -0
- package/src/lib/process/error.ts +6 -0
- package/src/lib/process/execute.ts +77 -0
- package/src/lib/process/index.ts +4 -0
- package/src/lib/process/type/command-options.ts +9 -0
- package/src/lib/process/utility/bind-process-lifespan-to.ts +10 -0
- package/src/lib/promise-wrapper/index.ts +3 -0
- package/src/lib/promise-wrapper/promise-wrapper.ts +51 -0
- package/src/lib/random/chance.ts +5 -0
- package/src/lib/random/element.ts +7 -0
- package/src/lib/random/elements.ts +12 -0
- package/src/lib/random/enum.ts +34 -0
- package/src/lib/random/enums.ts +11 -0
- package/src/lib/random/index.ts +3 -0
- package/src/lib/random/number.ts +8 -0
- package/src/lib/server/base.ts +194 -0
- package/src/lib/server/enum/server-event.ts +5 -0
- package/src/lib/server/enum/server-status.ts +10 -0
- package/src/lib/server/http/endpoint/ping.ts +21 -0
- package/src/lib/server/http/endpoint.ts +345 -0
- package/src/lib/server/http/interface/endpoint-constructor.ts +12 -0
- package/src/lib/server/http/interface/result-serializer.ts +5 -0
- package/src/lib/server/http/middleware.ts +18 -0
- package/src/lib/server/http/result-serializer/html.ts +92 -0
- package/src/lib/server/http/result-serializer/json.ts +23 -0
- package/src/lib/server/http/route.ts +104 -0
- package/src/lib/server/http/router.ts +125 -0
- package/src/lib/server/http/type/session-resolver.ts +8 -0
- package/src/lib/server/http/utility/create-server.ts +34 -0
- package/src/lib/server/http/utility/path-parser.ts +49 -0
- package/src/lib/server/http/utility/standardize-html-indentation.ts +54 -0
- package/src/lib/server/http/websocket-wrapper.ts +83 -0
- package/src/lib/server/http.ts +301 -0
- package/src/lib/server/index.ts +5 -0
- package/src/lib/server/tcp.ts +53 -0
- package/src/lib/server/type/server-options.ts +10 -0
- package/src/lib/string/calculate-length.ts +17 -0
- package/src/lib/string/capitalize.ts +8 -0
- package/src/lib/string/create-slug.ts +14 -0
- package/src/lib/string/enum/ansi-escape-code.ts +14 -0
- package/src/lib/string/enum/string-encoding.ts +9 -0
- package/src/lib/string/hyphenate.ts +5 -0
- package/src/lib/string/index.ts +3 -0
- package/src/lib/string/pad.ts +14 -0
- package/src/lib/string/trim-multiline.ts +21 -0
- package/src/lib/string/trim.ts +8 -0
- package/src/lib/tcp/channel.ts +13 -0
- package/src/lib/tcp/connection/incoming.ts +72 -0
- package/src/lib/tcp/connection/outgoing.ts +219 -0
- package/src/lib/tcp/connection.ts +360 -0
- package/src/lib/tcp/enum/connection-event.ts +12 -0
- package/src/lib/tcp/enum/message-type.ts +9 -0
- package/src/lib/tcp/index.ts +1 -0
- package/src/lib/tcp/type/connection-parameters.ts +6 -0
- package/src/lib/tcp/type/message/channel-close.ts +9 -0
- package/src/lib/tcp/type/message/channel-open.ts +9 -0
- package/src/lib/tcp/type/message.ts +10 -0
- package/src/lib/test/index.ts +2 -0
- package/src/lib/test/utility/build-config.ts +17 -0
- package/src/lib/test/utility/build-execution-context.ts +11 -0
- package/src/lib/time/bootstrap.ts +1 -0
- package/src/lib/time/enum/time-interval.ts +12 -0
- package/src/lib/time/index.ts +4 -0
- package/src/lib/time/utility/format-duration.ts +139 -0
- package/src/lib/time/utility/format-relative-duration.ts +22 -0
- package/src/lib/time/utility/sleep.ts +9 -0
- package/src/operation.ts +18 -0
- package/src/server/endpoint/abstract-page.ts +126 -0
- package/src/server/endpoint/action/create.ts +545 -0
- package/src/server/endpoint/action/get.ts +231 -0
- package/src/server/endpoint/base.ts +51 -0
- package/src/server/endpoint/day.ts +13 -0
- package/src/server/endpoint/generic-page.ts +14 -0
- package/src/server/endpoint/index.ts +11 -0
- package/src/server/endpoint/login.ts +45 -0
- package/src/server/endpoint/logout.ts +38 -0
- package/src/server/endpoint/month.ts +35 -0
- package/src/server/endpoint/robots.ts +18 -0
- package/src/server/endpoint/session/create.ts +62 -0
- package/src/server/endpoint/settings/get.ts +40 -0
- package/src/server/endpoint/settings/update.ts +44 -0
- package/src/server/endpoint/today.ts +15 -0
- package/src/server/endpoint/week.ts +34 -0
- package/src/server/endpoint/year.ts +34 -0
- package/src/server/enum/custom-page-type.ts +10 -0
- package/src/server/factory/block-result-serializer.ts +115 -0
- package/src/server/middleware/base.ts +6 -0
- package/src/server/middleware/error-handler.ts +177 -0
- package/src/server/middleware/static-file.ts +83 -0
- package/src/server/operation/add-block.ts +110 -0
- package/src/server/operation/create-session.ts +43 -0
- package/src/server/operation/delete-block.ts +96 -0
- package/src/server/operation/demote-block.ts +108 -0
- package/src/server/operation/destroy-session.ts +26 -0
- package/src/server/operation/load-account.ts +30 -0
- package/src/server/operation/load-block.ts +48 -0
- package/src/server/operation/load-directory-items.ts +75 -0
- package/src/server/operation/load-page.ts +368 -0
- package/src/server/operation/promote-block.ts +104 -0
- package/src/server/operation/save-page.ts +60 -0
- package/src/server/operation/update-account-settings.ts +52 -0
- package/src/server/operation/update-block.ts +124 -0
- package/src/server/repository/memory.ts +112 -0
- package/src/server/result-serializer/action.ts +939 -0
- package/src/server/result-serializer/base.ts +1267 -0
- package/src/server/result-serializer/block/audio.ts +33 -0
- package/src/server/result-serializer/block/background.ts +20 -0
- package/src/server/result-serializer/block/calendar.ts +148 -0
- package/src/server/result-serializer/block/directory.ts +57 -0
- package/src/server/result-serializer/block/ephemeral.ts +14 -0
- package/src/server/result-serializer/block/folder.ts +106 -0
- package/src/server/result-serializer/block/header.ts +31 -0
- package/src/server/result-serializer/block/image.ts +46 -0
- package/src/server/result-serializer/block/link.ts +40 -0
- package/src/server/result-serializer/block/list.ts +140 -0
- package/src/server/result-serializer/block/multi-column.ts +97 -0
- package/src/server/result-serializer/block/note.ts +44 -0
- package/src/server/result-serializer/block/todo.ts +78 -0
- package/src/server/result-serializer/block/whitespace.ts +15 -0
- package/src/server/result-serializer/block.ts +248 -0
- package/src/server/result-serializer/common/time-place-options.ts +33 -0
- package/src/server/result-serializer/login.ts +58 -0
- package/src/server/result-serializer/month.ts +170 -0
- package/src/server/result-serializer/page.ts +548 -0
- package/src/server/result-serializer/settings.ts +85 -0
- package/src/server/result-serializer/week.ts +195 -0
- package/src/server/result-serializer/year.ts +160 -0
- package/src/server/utility/accepts-content-type.ts +16 -0
- package/src/server/utility/accepts-html.ts +9 -0
- package/src/server/utility/accepts-json.ts +9 -0
- package/src/server/utility/add-days.ts +11 -0
- package/src/server/utility/create-date.ts +23 -0
- package/src/server/utility/create-index-path.ts +5 -0
- package/src/server/utility/create-slug.ts +9 -0
- package/src/server/utility/create-toast-path.ts +19 -0
- package/src/server/utility/date-less-than.ts +5 -0
- package/src/server/utility/date-occurs-before.ts +22 -0
- package/src/server/utility/date-to-key.ts +7 -0
- package/src/server/utility/date-to-label.ts +5 -0
- package/src/server/utility/date-to-path.ts +9 -0
- package/src/server/utility/dates-are-equal.ts +22 -0
- package/src/server/utility/dates-are-in-order.ts +9 -0
- package/src/server/utility/dates-are-on-the-same-day.ts +9 -0
- package/src/server/utility/dates-in-same-month.ts +8 -0
- package/src/server/utility/day-to-date.ts +40 -0
- package/src/server/utility/decrement-date.ts +11 -0
- package/src/server/utility/get-block-at-index-path.ts +32 -0
- package/src/server/utility/get-block-permissions.ts +15 -0
- package/src/server/utility/get-compact-label-for-date.ts +8 -0
- package/src/server/utility/get-custom-page-type-for-path.ts +37 -0
- package/src/server/utility/get-element-id-for-block.ts +15 -0
- package/src/server/utility/get-emoji-for-block-type.ts +39 -0
- package/src/server/utility/get-emoji-for-tool-type.ts +20 -0
- package/src/server/utility/get-end-of-month.ts +13 -0
- package/src/server/utility/get-end-of-week.ts +13 -0
- package/src/server/utility/get-filepath-for-folder-block.ts +23 -0
- package/src/server/utility/get-hex-for-color.ts +31 -0
- package/src/server/utility/get-label-for-time-place-visibility.ts +23 -0
- package/src/server/utility/get-month-name.ts +18 -0
- package/src/server/utility/get-next-day.ts +7 -0
- package/src/server/utility/get-next-month.ts +12 -0
- package/src/server/utility/get-next-week.ts +12 -0
- package/src/server/utility/get-next-year.ts +13 -0
- package/src/server/utility/get-ordinal-label-for-week.ts +11 -0
- package/src/server/utility/get-ordinal-of-week-within-month.ts +15 -0
- package/src/server/utility/get-padded-date.ts +11 -0
- package/src/server/utility/get-parent-index-path.ts +18 -0
- package/src/server/utility/get-path-for-folder-block.ts +25 -0
- package/src/server/utility/get-path-from-url.ts +13 -0
- package/src/server/utility/get-previous-index-path.ts +27 -0
- package/src/server/utility/get-previous-month.ts +12 -0
- package/src/server/utility/get-previous-week.ts +11 -0
- package/src/server/utility/get-previous-year.ts +13 -0
- package/src/server/utility/get-random-emoji-for-date.ts +109 -0
- package/src/server/utility/get-short-label-for-date.ts +11 -0
- package/src/server/utility/get-short-month-name.ts +9 -0
- package/src/server/utility/get-short-ordinal.ts +26 -0
- package/src/server/utility/get-siblings-and-index-for-index-path.ts +67 -0
- package/src/server/utility/get-start-of-month.ts +11 -0
- package/src/server/utility/get-start-of-week.ts +12 -0
- package/src/server/utility/get-start-of-year.ts +12 -0
- package/src/server/utility/get-weekday-name.ts +24 -0
- package/src/server/utility/increment-date.ts +15 -0
- package/src/server/utility/is-index-path.ts +5 -0
- package/src/server/utility/key-to-date.ts +25 -0
- package/src/server/utility/month-has-week-containing-date.ts +13 -0
- package/src/server/utility/month-to-date.ts +28 -0
- package/src/server/utility/month-to-path.ts +10 -0
- package/src/server/utility/months-are-equal.ts +8 -0
- package/src/server/utility/parse-index-path.ts +23 -0
- package/src/server/utility/path-is-date.ts +13 -0
- package/src/server/utility/path-to-date.ts +24 -0
- package/src/server/utility/subtract-days.ts +7 -0
- package/src/server/utility/validate-month.ts +10 -0
- package/src/server/utility/validate-page.ts +46 -0
- package/src/server/utility/validate-path.ts +9 -0
- package/src/server/utility/validate-url.ts +12 -0
- package/src/server/utility/week-greater-than.ts +10 -0
- package/src/server/utility/week-to-date.ts +8 -0
- package/src/server/utility/week-to-path.ts +12 -0
- package/src/server/utility/weeks-are-equal.ts +8 -0
- package/src/server/utility/year-to-date.ts +26 -0
- package/src/server/utility/year-to-path.ts +7 -0
- package/src/server/utility/years-are-equal.ts +8 -0
- package/src/server.ts +140 -0
- package/src/test.ts +195 -0
- package/src/type/account-settings.ts +9 -0
- package/src/type/account.ts +11 -0
- package/src/type/action/add-block.ts +74 -0
- package/src/type/action/complete-block.ts +10 -0
- package/src/type/action/delete-block.ts +11 -0
- package/src/type/action/demote-block.ts +9 -0
- package/src/type/action/edit-block.ts +11 -0
- package/src/type/action/promote-block.ts +9 -0
- package/src/type/action.ts +9 -0
- package/src/type/block/audio.ts +8 -0
- package/src/type/block/background.ts +10 -0
- package/src/type/block/directory.ts +18 -0
- package/src/type/block/ephemeral.ts +9 -0
- package/src/type/block/folder.ts +14 -0
- package/src/type/block/header.ts +11 -0
- package/src/type/block/image.ts +8 -0
- package/src/type/block/link.ts +12 -0
- package/src/type/block/list.ts +24 -0
- package/src/type/block/multi-column.ts +10 -0
- package/src/type/block/note.ts +9 -0
- package/src/type/block/todo.ts +10 -0
- package/src/type/block/whitespace.ts +9 -0
- package/src/type/block-metadata.ts +14 -0
- package/src/type/block.ts +18 -0
- package/src/type/day.ts +5 -0
- package/src/type/field-definition.ts +8 -0
- package/src/type/field-value.ts +5 -0
- package/src/type/file.ts +6 -0
- package/src/type/month.ts +5 -0
- package/src/type/page.ts +8 -0
- package/src/type/price.ts +11 -0
- package/src/type/resource.ts +5 -0
- package/src/type/runtime-config.ts +13 -0
- package/src/type/server-settings.ts +17 -0
- package/src/type/toast.ts +8 -0
- package/src/type/week.ts +5 -0
- package/src/type/year.ts +5 -0
- package/test/unit/index.ts +11 -0
- package/test/unit/server/operation/promote-block.ts +84 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import Month from 'type/month';
|
|
2
|
+
import Color from 'enum/color';
|
|
3
|
+
import datesAreEqual from 'server/utility/dates-are-equal';
|
|
4
|
+
import datesInSameMonth from 'server/utility/dates-in-same-month';
|
|
5
|
+
import PageType from 'client/enum/page-type';
|
|
6
|
+
import BaseResultSerializer from 'server/result-serializer/base';
|
|
7
|
+
import monthToDate from 'server/utility/month-to-date';
|
|
8
|
+
import dateLessThan from 'server/utility/date-less-than';
|
|
9
|
+
import Emoji from 'enum/emoji';
|
|
10
|
+
import createDate from 'server/utility/create-date';
|
|
11
|
+
import dateToPath from 'server/utility/date-to-path';
|
|
12
|
+
import getEndOfWeek from 'server/utility/get-end-of-week';
|
|
13
|
+
import getEndOfMonth from 'server/utility/get-end-of-month';
|
|
14
|
+
import getStartOfMonth from 'server/utility/get-start-of-month';
|
|
15
|
+
import getShortMonthName from 'server/utility/get-short-month-name';
|
|
16
|
+
import getNextMonth from 'server/utility/get-next-month';
|
|
17
|
+
import getPreviousMonth from 'server/utility/get-previous-month';
|
|
18
|
+
import monthToPath from 'server/utility/month-to-path';
|
|
19
|
+
import weekToPath from 'server/utility/week-to-path';
|
|
20
|
+
import yearToPath from 'server/utility/year-to-path';
|
|
21
|
+
import getStartOfYear from 'server/utility/get-start-of-year';
|
|
22
|
+
import getMonthName from 'server/utility/get-month-name';
|
|
23
|
+
import getStartOfWeek from 'server/utility/get-start-of-week';
|
|
24
|
+
import weekGreaterThan from 'server/utility/week-greater-than';
|
|
25
|
+
import incrementDate from 'server/utility/increment-date';
|
|
26
|
+
import createToastPath from 'server/utility/create-toast-path';
|
|
27
|
+
|
|
28
|
+
class MonthResultSerializer extends BaseResultSerializer<Month> {
|
|
29
|
+
public serializeSections(): string {
|
|
30
|
+
const target_date = this.getTargetDate();
|
|
31
|
+
const start_of_month = getStartOfMonth(target_date);
|
|
32
|
+
const end_of_month = getEndOfMonth(target_date);
|
|
33
|
+
const end_date = incrementDate(getEndOfWeek(end_of_month), 1);
|
|
34
|
+
const serialized_rows: string[] = [];
|
|
35
|
+
const reticule = '<div class="focus-reticule scaling"></div>';
|
|
36
|
+
const today = createDate();
|
|
37
|
+
|
|
38
|
+
let current_week = getStartOfWeek(start_of_month);
|
|
39
|
+
let current_date = current_week;
|
|
40
|
+
let current_row: string[] = [];
|
|
41
|
+
|
|
42
|
+
while (dateLessThan(current_date, end_date)) {
|
|
43
|
+
if (datesInSameMonth(current_date, target_date)) {
|
|
44
|
+
const base_path = dateToPath(current_date);
|
|
45
|
+
const date_is_today = datesAreEqual(current_date, today);
|
|
46
|
+
|
|
47
|
+
const day_path = (() => {
|
|
48
|
+
if (date_is_today) {
|
|
49
|
+
return createToastPath(base_path, {
|
|
50
|
+
message: `${Emoji.SUNSHINE} today ${Emoji.SUNSHINE}`,
|
|
51
|
+
color: Color.YELLOW
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
return base_path;
|
|
55
|
+
}
|
|
56
|
+
})();
|
|
57
|
+
|
|
58
|
+
const reticule_markup = date_is_today ? reticule : '';
|
|
59
|
+
const utc_date = current_date.getUTCDate();
|
|
60
|
+
const date_label = date_is_today ? Emoji.SUNSHINE : utc_date;
|
|
61
|
+
|
|
62
|
+
current_row.push(`
|
|
63
|
+
<td class="focus-reticule-container">
|
|
64
|
+
<a href="${day_path}" class="biglink">
|
|
65
|
+
${reticule_markup}
|
|
66
|
+
${date_label}
|
|
67
|
+
</a>
|
|
68
|
+
</td>
|
|
69
|
+
`);
|
|
70
|
+
} else {
|
|
71
|
+
current_row.push('<td></td>');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
current_date = incrementDate(current_date, 1);
|
|
75
|
+
|
|
76
|
+
if (weekGreaterThan(current_date, current_week)) {
|
|
77
|
+
const week_path = weekToPath(current_week);
|
|
78
|
+
const serialized_row = current_row.join('\n');
|
|
79
|
+
|
|
80
|
+
serialized_rows.push(`
|
|
81
|
+
<tr>
|
|
82
|
+
<td>
|
|
83
|
+
<a class="biglink" href="${week_path}">
|
|
84
|
+
↳
|
|
85
|
+
</a>
|
|
86
|
+
</td>
|
|
87
|
+
${serialized_row}
|
|
88
|
+
</tr>
|
|
89
|
+
`);
|
|
90
|
+
|
|
91
|
+
current_row = [];
|
|
92
|
+
current_week = getStartOfWeek(current_date);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const target_month = getStartOfMonth(target_date);
|
|
97
|
+
const target_month_name = getMonthName(target_month);
|
|
98
|
+
const target_year = getStartOfYear(target_month);
|
|
99
|
+
const year_name = target_year.getUTCFullYear();
|
|
100
|
+
const year_path = yearToPath(target_year);
|
|
101
|
+
const previous_month = getPreviousMonth(target_month);
|
|
102
|
+
const previous_month_path = monthToPath(previous_month);
|
|
103
|
+
const previous_month_name = getShortMonthName(previous_month);
|
|
104
|
+
const next_month = getNextMonth(target_month);
|
|
105
|
+
const next_month_path = monthToPath(next_month);
|
|
106
|
+
const next_month_name = getShortMonthName(next_month);
|
|
107
|
+
|
|
108
|
+
return `
|
|
109
|
+
<table>
|
|
110
|
+
<thead>
|
|
111
|
+
<tr>
|
|
112
|
+
<th class="no-background">
|
|
113
|
+
</th>
|
|
114
|
+
<th>
|
|
115
|
+
<a class="biglink mb-8" href="${year_path}">
|
|
116
|
+
${Emoji.UP_ARROW_UNICODE} ${year_name} ${Emoji.UP_ARROW_UNICODE}
|
|
117
|
+
</a>
|
|
118
|
+
</th>
|
|
119
|
+
<th class="no-background">
|
|
120
|
+
</th>
|
|
121
|
+
</tr>
|
|
122
|
+
</thead>
|
|
123
|
+
<tbody>
|
|
124
|
+
<tr>
|
|
125
|
+
<td class="biglink-container">
|
|
126
|
+
<a class="biglink stretch" href="${previous_month_path}">${Emoji.LEFT_ARROW_UNICODE} ${previous_month_name}</a>
|
|
127
|
+
</td>
|
|
128
|
+
<td>
|
|
129
|
+
<h2>${target_month_name}</h2>
|
|
130
|
+
<table class="fixed">
|
|
131
|
+
<thead>
|
|
132
|
+
<th></th>
|
|
133
|
+
<th>s</th>
|
|
134
|
+
<th>m</th>
|
|
135
|
+
<th>t</th>
|
|
136
|
+
<th>w</th>
|
|
137
|
+
<th>t</th>
|
|
138
|
+
<th>f</th>
|
|
139
|
+
<th>s</th>
|
|
140
|
+
</thead>
|
|
141
|
+
<tbody>
|
|
142
|
+
${serialized_rows.join('\n')}
|
|
143
|
+
</tbody>
|
|
144
|
+
</table>
|
|
145
|
+
</td>
|
|
146
|
+
<td class="biglink-container">
|
|
147
|
+
<a class="biglink stretch" href="${next_month_path}">${next_month_name} ${Emoji.RIGHT_ARROW_UNICODE}</a>
|
|
148
|
+
</td>
|
|
149
|
+
</tr>
|
|
150
|
+
</tbody>
|
|
151
|
+
</table>
|
|
152
|
+
`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
protected getTitle(): string {
|
|
156
|
+
return 'xxx';
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
protected getPageType(): PageType {
|
|
160
|
+
return PageType.MONTH;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private getTargetDate(): Date {
|
|
164
|
+
const month = this.getResult();
|
|
165
|
+
|
|
166
|
+
return monthToDate(month);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export default MonthResultSerializer;
|
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
import {Session} from 'lib/execution-context';
|
|
2
|
+
import {InvariantViolation} from 'lib/errors';
|
|
3
|
+
|
|
4
|
+
import Page from 'type/page';
|
|
5
|
+
import BlockType from 'enum/block-type';
|
|
6
|
+
import createDate from 'server/utility/create-date';
|
|
7
|
+
import Color from 'enum/color';
|
|
8
|
+
import createToastPath from 'server/utility/create-toast-path';
|
|
9
|
+
import CustomPageType from 'server/enum/custom-page-type';
|
|
10
|
+
import dateToPath from 'server/utility/date-to-path';
|
|
11
|
+
import isIndexPath from 'server/utility/is-index-path';
|
|
12
|
+
import getHexForColor from 'server/utility/get-hex-for-color';
|
|
13
|
+
import ToolType from 'enum/tool-type';
|
|
14
|
+
import Block from 'type/block';
|
|
15
|
+
import getEmojiForToolType from 'server/utility/get-emoji-for-tool-type';
|
|
16
|
+
import pathToDate from 'server/utility/path-to-date';
|
|
17
|
+
import Account from 'type/account';
|
|
18
|
+
import PageType from 'client/enum/page-type';
|
|
19
|
+
import pathIsDate from 'server/utility/path-is-date';
|
|
20
|
+
import datesAreEqual from 'server/utility/dates-are-equal';
|
|
21
|
+
import createIndexPath from 'server/utility/create-index-path';
|
|
22
|
+
import HeaderBlock from 'type/block/header';
|
|
23
|
+
import Emoji from 'enum/emoji';
|
|
24
|
+
import BaseResultSerializer from 'server/result-serializer/base';
|
|
25
|
+
import ActionType from 'enum/action-type';
|
|
26
|
+
import BlockResultSerializerFactory from 'server/factory/block-result-serializer';
|
|
27
|
+
import Toast from 'type/toast';
|
|
28
|
+
|
|
29
|
+
export interface PageMetadata {
|
|
30
|
+
readonly editing: boolean;
|
|
31
|
+
readonly target_index_path: string | null;
|
|
32
|
+
readonly toast: Toast | null;
|
|
33
|
+
readonly roles: string[];
|
|
34
|
+
readonly account: Account | null;
|
|
35
|
+
readonly custom_page_type: CustomPageType;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class PageResultSerializer extends BaseResultSerializer<Page> {
|
|
39
|
+
private metadata: PageMetadata;
|
|
40
|
+
|
|
41
|
+
public constructor(
|
|
42
|
+
result: Page,
|
|
43
|
+
metadata: PageMetadata,
|
|
44
|
+
path: string,
|
|
45
|
+
referrer_url: string,
|
|
46
|
+
session: Session
|
|
47
|
+
) {
|
|
48
|
+
super(result, path, referrer_url, session);
|
|
49
|
+
|
|
50
|
+
this.metadata = metadata;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected getBodyClass(): string {
|
|
54
|
+
if (this.isEditing()) {
|
|
55
|
+
return 'editing';
|
|
56
|
+
} else {
|
|
57
|
+
return super.getBodyClass();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected getPageType(): PageType {
|
|
62
|
+
if (this.isEditing()) {
|
|
63
|
+
return PageType.EDIT_CUSTOM;
|
|
64
|
+
} else {
|
|
65
|
+
return PageType.VIEW_CUSTOM;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
protected isHome(): boolean {
|
|
70
|
+
const {path} = this.getResult();
|
|
71
|
+
|
|
72
|
+
return isIndexPath(path);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
protected isToday(): boolean {
|
|
76
|
+
const {path} = this.getResult();
|
|
77
|
+
|
|
78
|
+
if (path === '/today') {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const is_date = pathIsDate(path);
|
|
83
|
+
|
|
84
|
+
if (!is_date) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const date = pathToDate(path);
|
|
89
|
+
const today = createDate();
|
|
90
|
+
|
|
91
|
+
return datesAreEqual(date, today);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
protected getTitle(): string {
|
|
95
|
+
const {blocks, path} = this.getResult();
|
|
96
|
+
|
|
97
|
+
let index = 0;
|
|
98
|
+
|
|
99
|
+
while (index < blocks.length) {
|
|
100
|
+
const block = blocks[index++];
|
|
101
|
+
|
|
102
|
+
if (!block) {
|
|
103
|
+
throw new InvariantViolation(`
|
|
104
|
+
Tried to read block at index ${index}, but it was not set
|
|
105
|
+
`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const {block_type} = block;
|
|
109
|
+
|
|
110
|
+
switch (block_type) {
|
|
111
|
+
case BlockType.HEADER:
|
|
112
|
+
const {title} = block as HeaderBlock;
|
|
113
|
+
|
|
114
|
+
return title;
|
|
115
|
+
|
|
116
|
+
default:
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return path;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
protected serializeBreadcrumbs(): string {
|
|
125
|
+
const {path} = this.getResult();
|
|
126
|
+
|
|
127
|
+
const prefix = (() => {
|
|
128
|
+
const query_index = path.indexOf('?');
|
|
129
|
+
|
|
130
|
+
if (query_index !== -1) {
|
|
131
|
+
return path.slice(0, query_index);
|
|
132
|
+
} else {
|
|
133
|
+
return path;
|
|
134
|
+
}
|
|
135
|
+
})();
|
|
136
|
+
|
|
137
|
+
const parts = prefix.split('/').filter((part) => {
|
|
138
|
+
return part !== '';
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
if (parts.length === 0) {
|
|
142
|
+
return '';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const last_part = parts.pop();
|
|
146
|
+
const segments: string[] = [];
|
|
147
|
+
|
|
148
|
+
let current_path = '';
|
|
149
|
+
|
|
150
|
+
segments.push('<a href="/">home</a>');
|
|
151
|
+
|
|
152
|
+
parts.forEach((part) => {
|
|
153
|
+
current_path += '/' + part;
|
|
154
|
+
segments.push(`<a href="${current_path}">${part}</a>`);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
segments.push(`<span>${last_part}</span>`);
|
|
158
|
+
|
|
159
|
+
return `
|
|
160
|
+
<nav class="mb-16 text-smaller">
|
|
161
|
+
${segments.join(' / ')}
|
|
162
|
+
</nav>
|
|
163
|
+
`;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private serializeToast(): string {
|
|
167
|
+
const {toast} = this.getMetadata();
|
|
168
|
+
|
|
169
|
+
if (toast === null) {
|
|
170
|
+
return '';
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const {color} = toast;
|
|
174
|
+
const color_hex = getHexForColor(color);
|
|
175
|
+
|
|
176
|
+
return `
|
|
177
|
+
<input type="checkbox" class="toast-toggle" autocomplete="off" />
|
|
178
|
+
<div class="toast">
|
|
179
|
+
<div class="toast-wrapper" style="background:${color_hex}">
|
|
180
|
+
<div class="toast-background"></div>
|
|
181
|
+
<div class="toast-message">
|
|
182
|
+
${toast.message}
|
|
183
|
+
</div>
|
|
184
|
+
</div>
|
|
185
|
+
</div>
|
|
186
|
+
`
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
protected serializeHeader(): string {
|
|
190
|
+
const toast = this.serializeToast();
|
|
191
|
+
|
|
192
|
+
if (!this.isLoggedIn()) {
|
|
193
|
+
return `
|
|
194
|
+
${toast}
|
|
195
|
+
`;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const {account} = this.getMetadata();
|
|
199
|
+
|
|
200
|
+
if (account === null) {
|
|
201
|
+
throw new InvariantViolation(`
|
|
202
|
+
Tried to read account for logged-in user,
|
|
203
|
+
but it was null
|
|
204
|
+
`);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const {settings} = account;
|
|
208
|
+
const {tool_types} = settings;
|
|
209
|
+
|
|
210
|
+
const serialized_tools = tool_types.map((tool_type) => {
|
|
211
|
+
return this.serializeToolType(tool_type);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
return `
|
|
215
|
+
${toast}
|
|
216
|
+
|
|
217
|
+
<header>
|
|
218
|
+
<div class="section-wrapper">
|
|
219
|
+
<section>
|
|
220
|
+
<table class="fixed" style="width:auto;min-width:180px;margin:0 auto;">
|
|
221
|
+
<tbody>
|
|
222
|
+
<tr>
|
|
223
|
+
${serialized_tools.join('\n')}
|
|
224
|
+
</tr>
|
|
225
|
+
</tbody>
|
|
226
|
+
</table>
|
|
227
|
+
</section>
|
|
228
|
+
</div>
|
|
229
|
+
</header>
|
|
230
|
+
`;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private serializeToolType(tool_type: ToolType): string {
|
|
234
|
+
switch (tool_type) {
|
|
235
|
+
case ToolType.LOCK:
|
|
236
|
+
return this.serializeLockTool();
|
|
237
|
+
|
|
238
|
+
case ToolType.HOME:
|
|
239
|
+
return this.serializeHomeTool();
|
|
240
|
+
|
|
241
|
+
case ToolType.TODAY:
|
|
242
|
+
return this.serializeTodayTool();
|
|
243
|
+
|
|
244
|
+
case ToolType.NOTE:
|
|
245
|
+
return this.serializeNoteTool();
|
|
246
|
+
|
|
247
|
+
case ToolType.AUDIO:
|
|
248
|
+
return this.serializeAudioTool();
|
|
249
|
+
|
|
250
|
+
case ToolType.IMAGE:
|
|
251
|
+
return this.serializeImageTool();
|
|
252
|
+
|
|
253
|
+
case ToolType.FOLDER:
|
|
254
|
+
return this.serializeFolderTool();
|
|
255
|
+
|
|
256
|
+
case ToolType.TODO:
|
|
257
|
+
return this.serializeTodoTool();
|
|
258
|
+
|
|
259
|
+
case ToolType.SETTINGS:
|
|
260
|
+
return this.serializeSettingsTool();
|
|
261
|
+
|
|
262
|
+
default:
|
|
263
|
+
throw new InvariantViolation(`Unsupported tool type: ${tool_type}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
private serializeLockTool(): string {
|
|
268
|
+
const {path} = this.getResult();
|
|
269
|
+
const editing = this.isEditing();
|
|
270
|
+
|
|
271
|
+
const editing_path = (() => {
|
|
272
|
+
if (editing) {
|
|
273
|
+
return createToastPath(path, {
|
|
274
|
+
message: `${Emoji.LOCKED} locked`,
|
|
275
|
+
color: Color.GREEN
|
|
276
|
+
});
|
|
277
|
+
} else {
|
|
278
|
+
return createToastPath(`${path}?editing=true`, {
|
|
279
|
+
message: `${Emoji.UNLOCKED} unlocked`,
|
|
280
|
+
color: Color.YELLOW
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
})();
|
|
284
|
+
|
|
285
|
+
const editing_emoji = editing ? Emoji.UNLOCKED : Emoji.LOCKED;
|
|
286
|
+
|
|
287
|
+
return `
|
|
288
|
+
<td>
|
|
289
|
+
<a href="${editing_path}" class="squarelink">
|
|
290
|
+
${editing_emoji}
|
|
291
|
+
</a>
|
|
292
|
+
</td>
|
|
293
|
+
`;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
private serializeHomeTool(): string {
|
|
297
|
+
const {path} = this.getResult();
|
|
298
|
+
const is_index = isIndexPath(path);
|
|
299
|
+
const index_label = `${Emoji.HOUSE} home ${Emoji.HOUSE}`;
|
|
300
|
+
const index_disabled_class = is_index ? 'disabled' : '';
|
|
301
|
+
|
|
302
|
+
const toasted_index_path = (() => {
|
|
303
|
+
if (is_index) {
|
|
304
|
+
return createToastPath('/', {
|
|
305
|
+
message: `already ${index_label}`,
|
|
306
|
+
color: Color.FUSCHIA
|
|
307
|
+
});
|
|
308
|
+
} else {
|
|
309
|
+
return createToastPath('/', {
|
|
310
|
+
message: index_label,
|
|
311
|
+
color: Color.BLUE
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
})();
|
|
315
|
+
|
|
316
|
+
return `
|
|
317
|
+
<td>
|
|
318
|
+
<a href="${toasted_index_path}" class="squarelink ${index_disabled_class}">
|
|
319
|
+
${Emoji.HOUSE}
|
|
320
|
+
</a>
|
|
321
|
+
</td>
|
|
322
|
+
`;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
private serializeTodayTool(): string {
|
|
326
|
+
const {path} = this.getResult();
|
|
327
|
+
const today = createDate();
|
|
328
|
+
const today_path = dateToPath(today);
|
|
329
|
+
const is_today = path === today_path;
|
|
330
|
+
const today_label = `${Emoji.SUNSHINE} today ${Emoji.SUNSHINE}`;
|
|
331
|
+
const today_disabled_class = is_today ? 'disabled' : '';
|
|
332
|
+
|
|
333
|
+
const toasted_today_path = (() => {
|
|
334
|
+
if (is_today) {
|
|
335
|
+
return createToastPath(path, {
|
|
336
|
+
message: `already ${today_label}`,
|
|
337
|
+
color: Color.FUSCHIA
|
|
338
|
+
});
|
|
339
|
+
} else {
|
|
340
|
+
return createToastPath(today_path, {
|
|
341
|
+
message: today_label,
|
|
342
|
+
color: Color.YELLOW
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
})();
|
|
346
|
+
|
|
347
|
+
return `
|
|
348
|
+
<td>
|
|
349
|
+
<a href="${toasted_today_path}" class="squarelink ${today_disabled_class}">
|
|
350
|
+
${Emoji.SUNSHINE}
|
|
351
|
+
</a>
|
|
352
|
+
</td>
|
|
353
|
+
`;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
private serializeNoteTool(): string {
|
|
357
|
+
const {path} = this.getResult();
|
|
358
|
+
const editing = this.isEditing();
|
|
359
|
+
const index_path = this.getInsertionIndexPath();
|
|
360
|
+
const emoji = getEmojiForToolType(ToolType.NOTE);
|
|
361
|
+
|
|
362
|
+
return `
|
|
363
|
+
<td>
|
|
364
|
+
<a href="/actions?path=${path}&editing=${editing}&action_type=${ActionType.ADD_BLOCK}&block_type=${BlockType.NOTE}&index_path=${index_path}" class="squarelink">
|
|
365
|
+
${emoji}
|
|
366
|
+
</a>
|
|
367
|
+
</td>
|
|
368
|
+
`;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
private serializeAudioTool(): string {
|
|
372
|
+
const {path} = this.getResult();
|
|
373
|
+
const editing = this.isEditing();
|
|
374
|
+
const index_path = this.getInsertionIndexPath();
|
|
375
|
+
const emoji = getEmojiForToolType(ToolType.AUDIO);
|
|
376
|
+
|
|
377
|
+
return `
|
|
378
|
+
<td>
|
|
379
|
+
<a href="/actions?path=${path}&editing=${editing}&action_type=${ActionType.ADD_BLOCK}&block_type=${BlockType.AUDIO}&index_path=${index_path}" class="squarelink">
|
|
380
|
+
${emoji}
|
|
381
|
+
</a>
|
|
382
|
+
</td>
|
|
383
|
+
`;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
private serializeImageTool(): string {
|
|
387
|
+
const {path} = this.getResult();
|
|
388
|
+
const editing = this.isEditing();
|
|
389
|
+
const index_path = this.getInsertionIndexPath();
|
|
390
|
+
const emoji = getEmojiForToolType(ToolType.IMAGE);
|
|
391
|
+
|
|
392
|
+
return `
|
|
393
|
+
<td>
|
|
394
|
+
<a href="/actions?path=${path}&editing=${editing}&action_type=${ActionType.ADD_BLOCK}&block_type=${BlockType.IMAGE}&index_path=${index_path}" class="squarelink">
|
|
395
|
+
${emoji}
|
|
396
|
+
</a>
|
|
397
|
+
</td>
|
|
398
|
+
`;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
private serializeFolderTool(): string {
|
|
402
|
+
const {path} = this.getResult();
|
|
403
|
+
const editing = this.isEditing();
|
|
404
|
+
const index_path = this.getInsertionIndexPath();
|
|
405
|
+
const emoji = getEmojiForToolType(ToolType.FOLDER);
|
|
406
|
+
|
|
407
|
+
return `
|
|
408
|
+
<td>
|
|
409
|
+
<a href="/actions?path=${path}&editing=${editing}&action_type=${ActionType.ADD_BLOCK}&block_type=${BlockType.FOLDER}&index_path=${index_path}" class="squarelink">
|
|
410
|
+
${emoji}
|
|
411
|
+
</a>
|
|
412
|
+
</td>
|
|
413
|
+
`;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
private serializeTodoTool(): string {
|
|
417
|
+
const {path} = this.getResult();
|
|
418
|
+
const editing = this.isEditing();
|
|
419
|
+
const index_path = this.getInsertionIndexPath();
|
|
420
|
+
const emoji = getEmojiForToolType(ToolType.TODO);
|
|
421
|
+
|
|
422
|
+
return `
|
|
423
|
+
<td>
|
|
424
|
+
<a href="/actions?path=${path}&editing=${editing}&action_type=${ActionType.ADD_BLOCK}&block_type=${BlockType.TODO}&index_path=${index_path}" class="squarelink">
|
|
425
|
+
${emoji}
|
|
426
|
+
</a>
|
|
427
|
+
</td>
|
|
428
|
+
`;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
private serializeSettingsTool(): string {
|
|
432
|
+
return `
|
|
433
|
+
<td>
|
|
434
|
+
<a href="/settings" class="squarelink">
|
|
435
|
+
${Emoji.GEAR}
|
|
436
|
+
</a>
|
|
437
|
+
</td>
|
|
438
|
+
`;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
protected serializeSections(): string {
|
|
442
|
+
const page = this.getResult();
|
|
443
|
+
const {path, blocks} = page;
|
|
444
|
+
|
|
445
|
+
const elements: string[] = [];
|
|
446
|
+
const editing = this.isEditing();
|
|
447
|
+
const hidden_class = editing ? '' : 'hidden';
|
|
448
|
+
|
|
449
|
+
elements.push(`
|
|
450
|
+
<a data-role="add_block_link" class="biglink grey mt-16 mb-16 ${hidden_class}" href="/actions?path=${path}&editing=${editing}&action_type=${ActionType.ADD_BLOCK}&index_path=0">+</a>
|
|
451
|
+
`);
|
|
452
|
+
|
|
453
|
+
blocks.forEach((block, index) => {
|
|
454
|
+
if (block.hidden && !editing) {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const serialized_block = this.serializeBlock(block, index);
|
|
459
|
+
|
|
460
|
+
elements.push(serialized_block);
|
|
461
|
+
|
|
462
|
+
elements.push(`
|
|
463
|
+
<a data-role="add_block_link" class="biglink grey mt-16 mb-16 ${hidden_class}" href="/actions?path=${path}&editing=${editing}&action_type=${ActionType.ADD_BLOCK}&index_path=${index + 1}">+</a>
|
|
464
|
+
`);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
if (this.shouldPrintRawConfig()) {
|
|
468
|
+
const raw_page = JSON.stringify(page, null, 2);
|
|
469
|
+
|
|
470
|
+
elements.push(`
|
|
471
|
+
<section class="grey">
|
|
472
|
+
<details>
|
|
473
|
+
<summary>raw config:</summary>
|
|
474
|
+
<pre>${raw_page}</pre>
|
|
475
|
+
</details>
|
|
476
|
+
</section>
|
|
477
|
+
`);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
return elements.join('\n');
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
private getInsertionIndexPath(): string {
|
|
484
|
+
const {blocks} = this.getResult();
|
|
485
|
+
|
|
486
|
+
let index = 0;
|
|
487
|
+
|
|
488
|
+
while (index < blocks.length) {
|
|
489
|
+
const block = blocks[index];
|
|
490
|
+
const {block_type} = block;
|
|
491
|
+
|
|
492
|
+
if (block_type !== BlockType.HEADER) {
|
|
493
|
+
break;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
index++;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
return createIndexPath([index]);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
private shouldPrintRawConfig(): boolean {
|
|
503
|
+
if (!this.isLoggedIn()) {
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
private serializeBlock(block: Block, index: number): string {
|
|
511
|
+
const editing = this.isEditing();
|
|
512
|
+
const {path} = this.getResult();
|
|
513
|
+
const {target_index_path, roles, account} = this.getMetadata();
|
|
514
|
+
const referrer_url = this.getReferrerUrl();
|
|
515
|
+
const index_path = createIndexPath([index]);
|
|
516
|
+
const creator_username = '0xfc3';
|
|
517
|
+
|
|
518
|
+
const block_metadata = {
|
|
519
|
+
editing,
|
|
520
|
+
page_path: path,
|
|
521
|
+
roles,
|
|
522
|
+
account,
|
|
523
|
+
index,
|
|
524
|
+
referrer_url,
|
|
525
|
+
index_path,
|
|
526
|
+
target_index_path,
|
|
527
|
+
creator_username
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
const session = this.getSession();
|
|
531
|
+
const factory = new BlockResultSerializerFactory(block, block_metadata, session);
|
|
532
|
+
const serializer = factory.create();
|
|
533
|
+
|
|
534
|
+
return serializer.serializeContent();
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
private isEditing(): boolean {
|
|
538
|
+
const {editing} = this.getMetadata();
|
|
539
|
+
|
|
540
|
+
return editing;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
private getMetadata(): PageMetadata {
|
|
544
|
+
return this.metadata;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
export default PageResultSerializer;
|