@zipify/wysiwyg 1.3.0-1 → 1.3.1

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/dist/wysiwyg.mjs CHANGED
@@ -23082,7 +23082,7 @@ const FontFamily = Mark.create({
23082
23082
  },
23083
23083
  parseHTML() {
23084
23084
  const getAttrs = (input) => {
23085
- const parsed = input.replace(/"/g, "");
23085
+ const parsed = input.replace(/["']/g, "");
23086
23086
  const isExists = this.options.fonts.some((font) => font.name === parsed);
23087
23087
  const value = isExists ? parsed : unref(this.options.defaultPreset).common.font_family;
23088
23088
  return { value };
@@ -0,0 +1,34 @@
1
+ export class Command {
2
+ name;
3
+ argument;
4
+ options = [];
5
+
6
+ doCommand() {
7
+ throw new Error('Command "doCommand" is required');
8
+ }
9
+
10
+ install(program) {
11
+ if (!this.name) {
12
+ throw new Error('Command "name" is required');
13
+ }
14
+
15
+ let building = program.command(this.name);
16
+
17
+ if (this.argument) {
18
+ building = building.argument(this.argument);
19
+ }
20
+
21
+ if (this.options.length) {
22
+ for (const option of this.options) {
23
+ building = building.option(option.flags, option.description, option.default);
24
+ }
25
+ }
26
+
27
+ building.action(this.doCommand.bind(this));
28
+ }
29
+
30
+ output(data) {
31
+ // eslint-disable-next-line no-console
32
+ console.log(data);
33
+ }
34
+ }
@@ -0,0 +1,45 @@
1
+ import { resolve } from 'path';
2
+ import { ContentSerializer } from '../ContentSerializer';
3
+ import { Command } from './Command';
4
+
5
+ export class ToJsonCommand extends Command {
6
+ name = 'to-json';
7
+ argument = '<html>';
8
+
9
+ options = [
10
+ {
11
+ flags: '--config <path>',
12
+ description: 'Generator config',
13
+ // Relative to dist folder
14
+ default: resolve(__dirname, '../bin/zp.config.json')
15
+ }
16
+ ];
17
+
18
+ doCommand(html, { config }) {
19
+ const configPath = resolve(process.cwd(), config);
20
+ const serializer = ContentSerializer.build(require(configPath).editor);
21
+ const json = serializer.toJSON(this.#formatInputHtml(html));
22
+
23
+ this.output(this.#formatOutputJson(json));
24
+ }
25
+
26
+ #formatInputHtml(html) {
27
+ return html
28
+ .replace(/\\(["'])/g, '$1')
29
+ .replace(/rgba\(\d{1,3}, ?\d{1,3}, ?\d{1,3}, (\d{1,2}%)\)/g, (substring, alpha) => {
30
+ return substring.replace(alpha, parseFloat(alpha) / 100);
31
+ });
32
+ }
33
+
34
+ #formatOutputJson(object) {
35
+ const skipNullValue = (_, value) => value === null ? undefined : value;
36
+ const json = JSON.stringify(object, skipNullValue, 2);
37
+
38
+ return json
39
+ .replace(/\\"/g, '"')
40
+ .replace(/font-family: ?'(.+)'/g, 'font-family: "$1"')
41
+ .replace(/'/g, '\\\'')
42
+ .replace(/^[\t ]*"[^:\n\r]+(?<!\\)":/gm, (match) => match.replace(/"/g, ''))
43
+ .replace(/: "(.+)"([,\n])/g, ': \'$1\'$2');
44
+ }
45
+ }
@@ -0,0 +1 @@
1
+ export { ToJsonCommand } from './ToJsonCommand';
package/lib/cli/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export { ContentSerializer } from './ContentSerializer';
2
+ export * from './commands';
package/lib/entry-cli.js CHANGED
@@ -1,29 +1,14 @@
1
- import { resolve } from 'path';
2
1
  import { Command } from 'commander';
3
- import { ContentSerializer } from './cli';
2
+ import { ToJsonCommand } from './cli';
4
3
 
5
4
  const program = new Command();
6
5
 
7
- function rubifyJSON(object) {
8
- const skipNullValue = (_, value) => value === null ? undefined : value;
9
- const json = JSON.stringify(object, skipNullValue, 2);
6
+ const commands = [
7
+ ToJsonCommand
8
+ ];
10
9
 
11
- return json
12
- .replace(/'/g, '\'')
13
- .replace(/^[\t ]*"[^:\n\r]+(?<!\\)":/gm, (match) => match.replace(/"/g, ''))
14
- .replace(/: "(.+)"([,\n])/g, ': \'$1\'$2');
10
+ for (const CommandClass of commands) {
11
+ new CommandClass().install(program);
15
12
  }
16
13
 
17
- program.command('to-json')
18
- .argument('<html>')
19
- .option('--config <path>', 'generator config', resolve(__dirname, '../bin/zp.config.json'))
20
- .action((html, { config }) => {
21
- const configPath = resolve(process.cwd(), config);
22
- const serializer = ContentSerializer.build(require(configPath).editor);
23
- const json = rubifyJSON(serializer.toJSON(html.replace(/\\"/g, '"')));
24
-
25
- // eslint-disable-next-line no-console
26
- console.log(json);
27
- });
28
-
29
14
  program.parse();
@@ -62,7 +62,7 @@ export const FontFamily = Mark.create({
62
62
 
63
63
  parseHTML() {
64
64
  const getAttrs = (input) => {
65
- const parsed = input.replace(/"/g, '');
65
+ const parsed = input.replace(/["']/g, '');
66
66
  const isExists = this.options.fonts.some((font) => font.name === parsed);
67
67
  const value = isExists ? parsed : unref(this.options.defaultPreset).common.font_family;
68
68
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zipify/wysiwyg",
3
- "version": "1.3.0-1",
3
+ "version": "1.3.1",
4
4
  "description": "Zipify modification of TipTap text editor",
5
5
  "main": "dist/wysiwyg.mjs",
6
6
  "bin": {
@@ -20,7 +20,8 @@
20
20
  "lib:build": "vite build --config config/build/lib.config.js",
21
21
  "lib:pre-release": "run-s lint:js lint:css test:unit",
22
22
  "lib:release": "export $(cat ./.env | xargs) && run-s lib:pre-release lib:build cli:build && release-it",
23
- "cli:build": "rollup --config config/build/cli.config.js",
23
+ "cli:build": "NODE_ENV=production rollup --config config/build/cli.config.js",
24
+ "cli:dev": "NODE_ENV=development rollup --config config/build/cli.config.js --watch",
24
25
  "example:start": "NODE_ENV=development vite serve --config config/build/example.config.js",
25
26
  "example:build": "NODE_ENV=production vite build --config config/build/example.config.js",
26
27
  "test:unit": "jest .",