useblocks-cli 1.3.4 → 1.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +5 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -403,9 +403,9 @@ var DEFAULT_EXTENSIONS_API_PACKAGE = "useblocks-extensions-api";
403
403
  var DEFAULT_EXTENSIONS_REACT_PACKAGE = "useblocks-extensions-react";
404
404
  var DEFAULT_EXTENSIONS_SANDBOX_PACKAGE = "useblocks-extensions-sandbox";
405
405
  var DEFAULT_CLI_PACKAGE = "useblocks-cli";
406
- var DEFAULT_VERSION = "1.3.4";
407
- var DEFAULT_UI_KIT_VERSION = "1.3.4";
408
- var DEFAULT_CLI_VERSION = "1.3.4";
406
+ var DEFAULT_VERSION = "1.3.8";
407
+ var DEFAULT_UI_KIT_VERSION = "1.3.8";
408
+ var DEFAULT_CLI_VERSION = "1.3.8";
409
409
  var DEFAULT_OPENAPI_BASE_URL = "https://app.useblocks.io/api";
410
410
  var DEFAULT_CDN_URL = "https://cdn.useblocks.io";
411
411
  var DEFAULT_BACKEND_DOMAIN = "api.useblocks.io";
@@ -3575,9 +3575,9 @@ var rawTemplateModules = /* #__PURE__ */ Object.assign({
3575
3575
  "../../project-templates/plugin/shared-base/src/sandbox/index.ts.eta": "<% if (it.isMinimal) { %><%~ include('plugin-sandbox-minimal', it) %><% } else { %><%~ include('plugin-sandbox-advanced', it) %><% } %>\n",
3576
3576
  "../../project-templates/plugin/shared-base/src/types.d.ts.eta": "<%~ include('plugin-types-dts', it) %>\n",
3577
3577
  "../../project-templates/plugin/shared-base/tsconfig.json": "{\n \"compilerOptions\": {\n \"target\": \"ES2020\",\n \"module\": \"ESNext\",\n \"moduleResolution\": \"Bundler\",\n \"jsx\": \"react-jsx\",\n \"strict\": true,\n \"esModuleInterop\": true,\n \"allowSyntheticDefaultImports\": true,\n \"skipLibCheck\": true,\n \"forceConsistentCasingInFileNames\": true,\n \"types\": []\n },\n \"include\": [\"src/**/*\", \"src/types.d.ts\"]\n}\n",
3578
- "../../project-templates/plugin/shell/src/app/__PLUGIN_CLASS_NAME__.tsx.eta": "<% const ns = it.pluginKey.charAt(0).toLowerCase() + it.pluginKey.slice(1); %>import {\n defineCommand,\n defineView,\n err,\n pluginRegistry,\n type CommandsOf,\n type IDisposable,\n type ViewsOf,\n} from '<%= it.packageConfig.extensionsApiPackageName %>';\nimport { BarChart03Icon, SendOutlined, SettingOutlined } from '<%= it.packageConfig.uiKitPackageName %>/icons';\nimport type { IPlugin, Instance } from '<%= it.packageConfig.packageName %>';\nimport { Dialog } from './ui/Dialog';\nimport { Panel } from './ui/Panel';\n\n/**\n * commands are the commands of the plugin: menus, other plugins and the agent can run them too. Their types come\n * from the handlers; the commands are made per plugin instance, because the handlers use its state.\n */\nexport const commands = (plugin: <%= it.pluginClassName %>) => ({\n '<%= ns %>.measure': defineCommand({\n title: 'Measure document',\n description: 'Reads the open document and returns the size of its HTML.',\n icon: SendOutlined,\n agent: true,\n when: { documentOpen: true },\n run: async (_args, context) => {\n const snapshot = await context.run('document.getSnapshot');\n if (!snapshot.ok) {\n return snapshot;\n }\n const length = snapshot.value.content.length;\n // A toolbar button has no place of its own for the result, so the command reports it over the canvas.\n plugin.report(`HTML size: ${length}`);\n return { length };\n },\n }),\n '<%= ns %>.configure': defineCommand({\n title: 'Configure plugin',\n description: 'Asks the user for a label in a dialog and keeps it for this editor.',\n icon: SettingOutlined,\n run: async () => {\n const answer = await plugin.editor.use('Ui').open('<%= ns %>.dialog', { label: plugin.label });\n if (!answer.ok) {\n return answer.error.code === 'cancelled' ? err('aborted') : err('internal', answer.error.message);\n }\n plugin.label = answer.value.label;\n },\n }),\n});\n\n/** views are the places the plugin occupies in the editor: a sidebar panel and a dialog. */\nexport const views = {\n '<%= ns %>.panel': defineView({ location: 'sidebar', title: '<%= it.pluginClassName %>', icon: BarChart03Icon }),\n // A dialog names its input and output as type arguments.\n '<%= ns %>.dialog': defineView<{ label: string }, { label: string }>({ location: 'dialog', title: 'Configure plugin' }),\n};\n\ndeclare module '<%= it.packageConfig.extensionsApiPackageName %>' {\n interface CommandMap extends CommandsOf<ReturnType<typeof commands>> {}\n interface ViewMap extends ViewsOf<typeof views> {}\n}\n\n/** <%= it.pluginClassName %> adds a toolbar button, a sidebar panel and a dialog. */\nexport class <%= it.pluginClassName %> implements IPlugin {\n label = '<%= it.pluginClassName %>';\n /** notice is the last result shown over the canvas; a new measure replaces it. */\n private notice: IDisposable | undefined;\n\n constructor(readonly editor: Instance) {}\n\n init() {\n const ui = this.editor.use('Ui');\n\n this.editor.use('Commands').register(commands(this));\n\n ui.addViews(views, {\n '<%= ns %>.panel': Panel,\n '<%= ns %>.dialog': Dialog,\n });\n\n ui.addItem({ location: 'toolbar', command: '<%= ns %>.measure' });\n ui.addItem({ location: 'menu:document', command: '<%= ns %>.configure' });\n }\n\n /** report shows a result over the canvas in place of the previous one. */\n report(title: string) {\n this.notice?.dispose();\n this.notice = this.editor.use('Ui').addItem({ location: 'notices', severity: 'info', title });\n }\n\n dispose() {\n this.notice?.dispose();\n }\n}\n\npluginRegistry.add(<%~ it.pluginKeyLiteral %>, <%= it.pluginClassName %>);\n",
3578
+ "../../project-templates/plugin/shell/src/app/__PLUGIN_CLASS_NAME__.tsx.eta": "<% const ns = it.pluginKey.charAt(0).toLowerCase() + it.pluginKey.slice(1); %>import {\n defineCommand,\n defineView,\n err,\n pluginRegistry,\n type CommandsOf,\n type IDisposable,\n type IPlugin,\n type Instance,\n type ViewsOf,\n} from '<%= it.packageConfig.extensionsApiPackageName %>';\nimport { BarChart03Icon, SendOutlined, SettingOutlined } from '<%= it.packageConfig.uiKitPackageName %>/icons';\nimport { Dialog } from './ui/Dialog';\nimport { Panel } from './ui/Panel';\n\n/**\n * commands are the commands of the plugin: menus, other plugins and the agent can run them too. Their types come\n * from the handlers; the commands are made per plugin instance, because the handlers use its state.\n */\nexport const commands = (plugin: <%= it.pluginClassName %>) => ({\n '<%= ns %>.measure': defineCommand({\n title: 'Measure document',\n description: 'Reads the open document and returns the size of its HTML.',\n icon: SendOutlined,\n agent: true,\n when: { documentOpen: true },\n run: async (_args, context) => {\n const snapshot = await context.run('document.getSnapshot');\n if (!snapshot.ok) {\n return snapshot;\n }\n const length = snapshot.value.content.length;\n // A toolbar button has no place of its own for the result, so the command reports it over the canvas.\n plugin.report(`HTML size: ${length}`);\n return { length };\n },\n }),\n '<%= ns %>.configure': defineCommand({\n title: 'Configure plugin',\n description: 'Asks the user for a label in a dialog and keeps it for this editor.',\n icon: SettingOutlined,\n run: async () => {\n const answer = await plugin.editor.use('Ui').open('<%= ns %>.dialog', { label: plugin.label });\n if (!answer.ok) {\n return answer.error.code === 'cancelled' ? err('aborted') : err('internal', answer.error.message);\n }\n plugin.label = answer.value.label;\n },\n }),\n});\n\n/** views are the places the plugin occupies in the editor: a sidebar panel and a dialog. */\nexport const views = {\n '<%= ns %>.panel': defineView({ location: 'sidebar', title: '<%= it.pluginClassName %>', icon: BarChart03Icon }),\n // A dialog names its input and output as type arguments.\n '<%= ns %>.dialog': defineView<{ label: string }, { label: string }>({ location: 'dialog', title: 'Configure plugin' }),\n};\n\ndeclare module '<%= it.packageConfig.extensionsApiPackageName %>' {\n interface CommandMap extends CommandsOf<ReturnType<typeof commands>> {}\n interface ViewMap extends ViewsOf<typeof views> {}\n}\n\n/** <%= it.pluginClassName %> adds a toolbar button, a sidebar panel and a dialog. */\nexport class <%= it.pluginClassName %> implements IPlugin {\n label = '<%= it.pluginClassName %>';\n /** notice is the last result shown over the canvas; a new measure replaces it. */\n private notice: IDisposable | undefined;\n\n constructor(readonly editor: Instance) {}\n\n init() {\n const ui = this.editor.use('Ui');\n\n this.editor.use('Commands').register(commands(this));\n\n ui.addViews(views, {\n '<%= ns %>.panel': Panel,\n '<%= ns %>.dialog': Dialog,\n });\n\n ui.addItem({ location: 'toolbar', command: '<%= ns %>.measure' });\n ui.addItem({ location: 'menu:document', command: '<%= ns %>.configure' });\n }\n\n /** report shows a result over the canvas in place of the previous one. */\n report(title: string) {\n this.notice?.dispose();\n this.notice = this.editor.use('Ui').addItem({ location: 'notices', severity: 'info', title });\n }\n\n dispose() {\n this.notice?.dispose();\n }\n}\n\npluginRegistry.add(<%~ it.pluginKeyLiteral %>, <%= it.pluginClassName %>);\n",
3579
3579
  "../../project-templates/plugin/shell/src/app/ui/Dialog.tsx.eta": "<% const ns = it.pluginKey.charAt(0).toLowerCase() + it.pluginKey.slice(1); %>import { useCallback, useState, type ChangeEvent, type FormEvent } from 'react';\nimport type { ViewProps } from '<%= it.packageConfig.extensionsReactPackageName %>';\nimport { Button, Flex, Input } from '<%= it.packageConfig.uiKitPackageName %>';\n\n/** Dialog asks for a label and closes with it as the dialog result. */\nexport function Dialog({ context }: ViewProps<'<%= ns %>.dialog'>) {\n const [label, setLabel] = useState(context.input.label);\n\n const onSubmit = useCallback(\n (event: FormEvent) => {\n event.preventDefault();\n context.close({ label });\n },\n [context, label],\n );\n const onChange = useCallback((event: ChangeEvent<HTMLInputElement>) => setLabel(event.target.value), []);\n\n return (\n <form onSubmit={onSubmit}>\n <Flex gap={8}>\n <Input value={label} onChange={onChange} autoFocus />\n <Button type=\"primary\" htmlType=\"submit\">\n Save\n </Button>\n </Flex>\n </form>\n );\n}\n",
3580
- "../../project-templates/plugin/shell/src/app/ui/Panel.tsx.eta": "<% const ns = it.pluginKey.charAt(0).toLowerCase() + it.pluginKey.slice(1); %>import { useCallback, useState } from 'react';\nimport { useCommand, useEditor, type ViewProps } from '<%= it.packageConfig.extensionsReactPackageName %>';\nimport { Button, Card, Flex, PanelForm, Text } from '<%= it.packageConfig.uiKitPackageName %>';\n\n/** Panel shows the size of the open document and lets the user name the report in the plugin's dialog. */\nexport function Panel(_props: ViewProps<'<%= ns %>.panel'>) {\n const measure = useCommand('<%= ns %>.measure');\n const ui = useEditor().use('Ui');\n const [length, setLength] = useState<number>();\n const [label, setLabel] = useState('Report');\n\n const onMeasure = useCallback(() => {\n void measure().then((result) => {\n if (result.ok) {\n setLength(result.value.length);\n }\n });\n }, [measure]);\n\n // A view opens another view through the editor and gets its output back; a command alone cannot do that.\n const onRename = useCallback(() => {\n void ui.open('<%= ns %>.dialog', { label }).then((answer) => {\n if (answer.ok) {\n setLabel(answer.value.label);\n }\n });\n }, [ui, label]);\n\n // PanelForm is the frame of the editor's own panels: a header with a divider and a padded body.\n return (\n <PanelForm>\n <PanelForm.Header title=\"<%= it.pluginClassName %>\" />\n <PanelForm.Body>\n <Flex vertical gap={12}>\n <Flex gap={8}>\n <Button type=\"primary\" onClick={onMeasure} loading={measure.running}>\n Measure\n </Button>\n <Button onClick={onRename}>Rename</Button>\n </Flex>\n {length !== undefined && (\n <Card size=\"small\">\n <Text>\n {label}: HTML size {length}\n </Text>\n </Card>\n )}\n </Flex>\n </PanelForm.Body>\n </PanelForm>\n );\n}\n",
3580
+ "../../project-templates/plugin/shell/src/app/ui/Panel.tsx.eta": "<% const ns = it.pluginKey.charAt(0).toLowerCase() + it.pluginKey.slice(1); %>import { useCallback, useState } from 'react';\nimport { useCommand, useInstance, type ViewProps } from '<%= it.packageConfig.extensionsReactPackageName %>';\nimport { Button, Card, Flex, PanelForm, Text } from '<%= it.packageConfig.uiKitPackageName %>';\n\n/** Panel shows the size of the open document and lets the user name the report in the plugin's dialog. */\nexport function Panel(_props: ViewProps<'<%= ns %>.panel'>) {\n const measure = useCommand('<%= ns %>.measure');\n const ui = useInstance().use('Ui');\n const [length, setLength] = useState<number>();\n const [label, setLabel] = useState('Report');\n\n const onMeasure = useCallback(() => {\n void measure().then((result) => {\n if (result.ok) {\n setLength(result.value.length);\n }\n });\n }, [measure]);\n\n // A view opens another view through the editor and gets its output back; a command alone cannot do that.\n const onRename = useCallback(() => {\n void ui.open('<%= ns %>.dialog', { label }).then((answer) => {\n if (answer.ok) {\n setLabel(answer.value.label);\n }\n });\n }, [ui, label]);\n\n // PanelForm is the frame of the editor's own panels: a header with a divider and a padded body.\n return (\n <PanelForm>\n <PanelForm.Header title=\"<%= it.pluginClassName %>\" />\n <PanelForm.Body>\n <Flex vertical gap={12}>\n <Flex gap={8}>\n <Button type=\"primary\" onClick={onMeasure} loading={measure.running}>\n Measure\n </Button>\n <Button onClick={onRename}>Rename</Button>\n </Flex>\n {length !== undefined && (\n <Card size=\"small\">\n <Text>\n {label}: HTML size {length}\n </Text>\n </Card>\n )}\n </Flex>\n </PanelForm.Body>\n </PanelForm>\n );\n}\n",
3581
3581
  "../../project-templates/plugin/shell/src/dev/hostApp.tsx.eta": "<%~ include('plugin-dev-host-app-minimal', it) %>\n",
3582
3582
  "../../project-templates/plugin/shell/src/sandbox/index.ts.eta": "<%~ include('plugin-sandbox-minimal', it) %>\n",
3583
3583
  "../../project-templates/plugin/templating/src/app/__PLUGIN_CLASS_NAME__.tsx.eta": "import { pluginRegistry, createComponentIdentifier, type SettingsPanelApi } from '<%= it.packageConfig.extensionsApiPackageName %>';\nimport { ComponentRegistry } from '<%= it.packageConfig.extensionsReactPackageName %>';\nimport type { IPlugin, Instance } from '<%= it.packageConfig.packageName %>';\nimport type { <%= it.pluginClassName %>Options } from '../public-types';\nimport {\n <%= it.pluginClassName %>TemplateDataPanel,\n type <%= it.pluginClassName %>TemplateDataPanelProps,\n} from './ui/<%= it.pluginClassName %>Panel';\nimport {\n OPEN_TEMPLATE_DATA_PANEL_MESSAGE,\n PREVIEW_STATES,\n TEMPLATE_DATA_MESSAGE,\n TEMPLATE_DATA_META_KEY,\n TWIG_RUNTIME_URL,\n clonePreviewData,\n type PreviewTemplateData,\n} from '../interfaces';\n\nconst <%= it.pluginClassName %>TemplateDataPanelId =\n createComponentIdentifier<<%= it.pluginClassName %>TemplateDataPanelProps>('<%= it.pluginClassName %>TemplateDataPanel');\n\nComponentRegistry.add(<%= it.pluginClassName %>TemplateDataPanelId, <%= it.pluginClassName %>TemplateDataPanel);\n\nfunction normalizePublicPath(value?: string): string | undefined {\n if (!value) {\n return undefined;\n }\n\n const trimmed = value.replace(/\\/+$/, '');\n return `${trimmed}/`;\n}\n\nconst AUTO_PUBLIC_PATH = (() => {\n if (typeof document === 'undefined') {\n return undefined;\n }\n\n const currentScript = document.currentScript as HTMLScriptElement | null;\n if (!currentScript?.src) {\n return undefined;\n }\n\n return normalizePublicPath(currentScript.src.replace(/[^/]*$/, ''));\n})();\n\nfunction getDefaultPreviewData(): PreviewTemplateData {\n return clonePreviewData(PREVIEW_STATES[0]?.data ?? {});\n}\n\nexport class <%= it.pluginClassName %> implements IPlugin {\n private _previewData: PreviewTemplateData = getDefaultPreviewData();\n private _matcherReadyPromise: Promise<void> = Promise.resolve();\n private readonly _disposables: Array<{ dispose(): void }> = [];\n private _settingsPanel?: SettingsPanelApi;\n\n constructor(\n private readonly _editor: Instance,\n private readonly _options: <%= it.pluginClassName %>Options = {},\n ) {}\n\n init() {\n const sandboxApi = this._editor.use('SandboxScriptApi');\n const settingsPanel = this._editor.use('SettingsPanelApi');\n const messageService = this._editor.use('MessageService');\n this._settingsPanel = settingsPanel;\n\n const publicPath = normalizePublicPath(this._options.publicPath) || AUTO_PUBLIC_PATH;\n const twigRuntimeHandle = sandboxApi.registerSandboxScript(TWIG_RUNTIME_URL);\n\n if (publicPath) {\n this._matcherReadyPromise = twigRuntimeHandle.ready\n .then(() => sandboxApi.registerSandboxScript(publicPath + 'sandbox.js').ready)\n .then(() => undefined);\n } else {\n this._matcherReadyPromise = twigRuntimeHandle.ready.then(() => undefined);\n }\n\n this._trackDisposable(messageService.addListener(OPEN_TEMPLATE_DATA_PANEL_MESSAGE, () => {\n this._openTemplateDataPanel(this._settingsPanel);\n }));\n\n this._trackDisposable(this._editor.handleEmailInit?.((email) => {\n void this._hydratePreviewData(email);\n }));\n }\n\n afterInit() {\n void this._hydratePreviewData();\n }\n\n dispose() {\n while (this._disposables.length > 0) {\n this._disposables.pop()?.dispose();\n }\n }\n\n private _trackDisposable(value: { dispose(): void } | (() => void) | void) {\n if (!value) {\n return;\n }\n\n if (typeof value === 'function') {\n this._disposables.push({ dispose: value });\n return;\n }\n\n if (typeof value.dispose === 'function') {\n this._disposables.push(value);\n }\n }\n\n private _readPreviewDataFromEmail(email: unknown): PreviewTemplateData {\n const emailMeta = (email as { meta?: Record<string, unknown> } | undefined)?.meta;\n const storedData = emailMeta?.[TEMPLATE_DATA_META_KEY];\n if (storedData && typeof storedData === 'object') {\n return clonePreviewData(storedData as PreviewTemplateData);\n }\n\n return getDefaultPreviewData();\n }\n\n private async _hydratePreviewData(email?: unknown) {\n const sourceEmail = email ?? await this._editor.getEmail?.();\n this._previewData = this._readPreviewDataFromEmail(sourceEmail);\n await this._sendPreviewData();\n }\n\n private _persistPreviewData(nextData: PreviewTemplateData) {\n this._previewData = clonePreviewData(nextData);\n this._editor.setEmailMeta?.({\n [TEMPLATE_DATA_META_KEY]: clonePreviewData(nextData),\n });\n }\n\n private _openTemplateDataPanel(settingsPanel: SettingsPanelApi | undefined) {\n if (!settingsPanel) {\n return;\n }\n\n settingsPanel.showSettingsPanel({\n caption: 'Template data JSON',\n deletable: false,\n content: {\n type: <%= it.pluginClassName %>TemplateDataPanelId,\n props: {\n initialValue: JSON.stringify(this._previewData ?? {}, null, 2),\n onValidJson: (nextData: PreviewTemplateData) => {\n this._persistPreviewData(nextData);\n void this._sendPreviewData();\n },\n },\n },\n });\n }\n\n private async _sendPreviewData() {\n const messageService = this._editor.use('MessageService');\n await this._matcherReadyPromise;\n messageService.send(TEMPLATE_DATA_MESSAGE, this._previewData);\n }\n}\n\npluginRegistry.add(<%~ it.pluginKeyLiteral %>, <%= it.pluginClassName %>);\n",
package/package.json CHANGED
@@ -16,5 +16,5 @@
16
16
  "yargs": "^17.5.1"
17
17
  },
18
18
  "name": "useblocks-cli",
19
- "version": "1.3.4"
19
+ "version": "1.3.8"
20
20
  }